/*
支付成功：39a4ff
未支付：ff6060
退款：32dc86
失败：666666
*/
const label = {
  PAID: "已支付",
  UNPAID: "未支付",
  FAIL: "失败",
  REFUND: "退款"
};

const color = {
  PAID: "#39a4ff",
  UNPAID: "#ff6060",
  FAIL: "#666666",
  REFUND: "#32dc86"
};

export function recordFormat(list) {
  return list.map(item => {
    item.color = color[item.status];
    item.label = label[item.status];
    return item;
  });
}

export function bookListFormat(list) {
  return list.map(bookFormat);
}
export function bookFormat(book) {
  book.name = book.book_name;
  book.cover = book.cover_url;
  book.intro = book.book_summary;
  book.author = book.book_author;
  return book;
}

export function urlFormat(urlObj) {
  if (!urlObj) return null;
  let url = "";
  if (urlObj.host) url += urlObj.host;
  if (urlObj.pathname) url += urlObj.pathname;
  if (urlObj.query) {
    url += "?";
    for (let i in urlObj.query) {
      url += i;
      if (urlObj.query[i]) url += "=" + urlObj.query[i];
      url += "&";
    }
    return (url = url.slice(0, -1));
  }
  return encodeURI(url);
}

export function contentFormat(r) {
  r.name = r.chapter_name;
  r.content = r.chapter_content;
  r.sequence = r.chapter_sequence;
  delete r.chapter_sequence;
  delete r.chapter_content;
  delete r.chapter_content;
  return r;
}

export function shelfFormat(r) {
  return r.map(book => {
    book.name = book.book_name;
    return book;
  });
}
