import dayjs from 'dayjs';
import Mock from 'mockjs';
import type { GetParams } from '@/types/global';
import { parseUrlQuery } from '@/utils/parse-url-query';
import setupMock, { successResponseWrap } from '@/mocks/setup';

const textList = [
  {
    key: 1,
    clickNumber: '346.3w+',
    title: '\u7ecf\u6d4e\u65e5\u62a5\uff1a\u8d22\u653f\u653f\u7b56\u8981\u7cbe\u51c6\u63d0\u5347\u2026',
    increases: 35,
  },
  {
    key: 2,
    clickNumber: '324.2w+',
    title: '\u53cc12\u9047\u51b7\uff0c\u6d88\u8d39\u8005\u538c\u5026\u4e86\u7535\u5546\u5e73\u2026',
    increases: 22,
  },
  {
    key: 3,
    clickNumber: '318.9w+',
    title:
      '\u81f4\u656c\u575a\u5b88\u6218\u201c\u75ab\u201d\u4e00\u7ebf\u7684\u793e\u533a\u5de5\u4f5c\u2026',
    increases: 9,
  },
  {
    key: 4,
    clickNumber: '257.9w+',
    title: '\u666e\u9ad8\u8fd8\u662f\u804c\u9ad8\uff1f\u5bb6\u957f\u4eec\u9677\u5165\u9009\u62e9\u2026',
    increases: 17,
  },
  {
    key: 5,
    clickNumber: '124.2w+',
    title:
      '\u4eba\u6c11\u5feb\u8bc4\uff1a\u6ca1\u60f3\u5230\u201c\u6d53\u7709\u5927\u773c\u201d\u7684\u2026',
    increases: 37,
  },
];
const imageList = [
  {
    key: 1,
    clickNumber: '15.3w+',
    title:
      '\u6768\u6d9b\u63a5\u66ff\u9646\u6177\u51fa\u4efb\u5916\u4ea4\u90e8\u7f8e\u5927\u53f8\u2026',
    increases: 15,
  },
  {
    key: 2,
    clickNumber: '12.2w+',
    title: '\u56fe\u96c6\uff1a\u9f99\u5377\u98ce\u88ad\u51fb\u7f8e\u56fd\u591a\u5dde\u623f\u5c4b\u2026',
    increases: 26,
  },
  {
    key: 3,
    clickNumber: '18.9w+',
    title: '52\u5c81\u5927\u59d0\u8d34\u94b1\u7167\u987e\u81ea\u95ed\u75c7\u513f\u7ae5\u516b\u2026',
    increases: 9,
  },
  {
    key: 4,
    clickNumber: '7.9w+',
    title: '\u676d\u5dde\u4e00\u5bb6\u4e09\u53e3\u516c\u56ed\u5bbf\u8425\u53d6\u6696\u4e2d\u6bd2',
    increases: 0,
  },
  {
    key: 5,
    clickNumber: '5.2w+',
    title: '\u6d3e\u51fa\u6240\u526f\u6240\u957f\u5a01\u80c1\u5e02\u6c11\uff1f\u8b66\u65b9\u8c03\u2026',
    increases: 4,
  },
];
const videoList = [
  {
    key: 1,
    clickNumber: '367.6w+',
    title: '\u8fd9\u662f\u4eca\u65e510\u70b9\u7684\u5357\u4eac',
    increases: 5,
  },
  {
    key: 2,
    clickNumber: '352.2w+',
    title:
      '\u7acb\u9676\u5b9b\u4e0d\u65ad\u6311\u8845\u81f4\u7ecf\u6d4e\u53d7\u635f\u6c11\u4f17\u2026',
    increases: 17,
  },
  {
    key: 3,
    clickNumber: '348.9w+',
    title: '\u97e9\u56fd\u827a\u4eba\u5218\u5728\u77f3\u786e\u8bca\u65b0\u51a0',
    increases: 30,
  },
  {
    key: 4,
    clickNumber: '346.3w+',
    title: '\u5173\u4e8e\u5317\u4eac\u51ac\u5965\u4f1a\uff0c\u6587\u5728\u5bc9\u8868\u6001',
    increases: 12,
  },
  {
    key: 5,
    clickNumber: '271.2w+',
    title: '95\u540e\u73b0\u5f79\u519b\u4eba\u8363\u7acb\u4e00\u7b49\u529f',
    increases: 2,
  },
];

setupMock({
  setup() {
    Mock.mock(/\/api\/content-data/, () => {
      const presetData = [58, 81, 53, 90, 64, 88, 49, 79];
      const getLineData = () => {
        const count = 8;
        return new Array(count).fill(0).map((el, idx) => ({
          x: dayjs()
            .day(idx - 2)
            .format('YYYY-MM-DD'),
          y: presetData[idx],
        }));
      };
      return successResponseWrap([...getLineData()]);
    });
    Mock.mock(/\/api\/popular\/list/, (params: GetParams) => {
      const { type = 'text' } = parseUrlQuery(params.url);
      if (type === 'image') {
        return successResponseWrap([...videoList]);
      }
      if (type === 'video') {
        return successResponseWrap([...imageList]);
      }
      return successResponseWrap([...textList]);
    });
  },
});
