// 充值记录mock数据
export const rechargeMockData = {
  // 充值记录列表
  list: [
    {
      id: 1,
      order_no: 'RC202501150001',
      username: 'john_doe',
      phone: '13800138001',
      channel: 'TKPAY',
      channel_text: 'TKPAY',
      currency: 'BDT',
      amount: 1000,
      status: 'processing',
      status_text: '处理中',
      create_time: '2025-01-15 10:30:00',
      success_time: '',
      user_id: 1001,
      // 详情页面额外字段
      bank_name: 'BKASH',
      account_name: 'John Doe',
      recharge_account: '8806422510008',
      account_balance: '2,500',
      profit_balance: '1,500',
      recharge_balance: '1,000',
    },
    {
      id: 2,
      order_no: 'RC202501150002',
      username: 'jane_smith',
      phone: '13800138002',
      channel: '3QPAY',
      channel_text: '3QPAY',
      currency: 'BDT',
      amount: 2500,
      status: 'success',
      status_text: '充值成功',
      create_time: '2025-01-15 09:15:00',
      success_time: '2025-01-15 09:16:30',
      user_id: 1002,
      // 详情页面额外字段
      bank_name: 'BKASH',
      account_name: 'Jane Smith',
      recharge_account: '8806422510009',
      account_balance: '5,000',
      profit_balance: '2,500',
      recharge_balance: '2,500',
    },
    {
      id: 3,
      order_no: 'RC202501150003',
      username: 'mike_wilson',
      phone: '13800138003',
      channel: 'TKPAY',
      channel_text: 'TKPAY',
      currency: 'BDT',
      amount: 500,
      status: 'failed',
      status_text: '充值失败',
      create_time: '2025-01-15 08:45:00',
      success_time: '',
      user_id: 1003,
    },
    {
      id: 4,
      order_no: 'RC202501150004',
      username: 'sarah_johnson',
      phone: '13800138004',
      channel: '3QPAY',
      channel_text: '3QPAY',
      currency: 'BDT',
      amount: 3000,
      status: 'success',
      status_text: '充值成功',
      create_time: '2025-01-15 07:20:00',
      success_time: '2025-01-15 07:21:15',
      user_id: 1004,
    },
    {
      id: 5,
      order_no: 'RC202501150005',
      username: 'david_brown',
      phone: '13800138005',
      channel: 'TKPAY',
      channel_text: 'TKPAY',
      currency: 'BDT',
      amount: 1500,
      status: 'processing',
      status_text: '处理中',
      create_time: '2025-01-15 06:10:00',
      success_time: '',
      user_id: 1005,
    },
    {
      id: 6,
      order_no: 'RC202501140006',
      username: 'lisa_davis',
      phone: '13800138006',
      channel: '3QPAY',
      channel_text: '3QPAY',
      currency: 'BDT',
      amount: 800,
      status: 'failed',
      status_text: '充值失败',
      create_time: '2025-01-14 22:30:00',
      success_time: '',
      user_id: 1006,
    },
    {
      id: 7,
      order_no: 'RC202501140007',
      username: 'tom_anderson',
      phone: '13800138007',
      channel: 'TKPAY',
      channel_text: 'TKPAY',
      currency: 'BDT',
      amount: 2000,
      status: 'success',
      status_text: '充值成功',
      create_time: '2025-01-14 20:15:00',
      success_time: '2025-01-14 20:16:45',
      user_id: 1007,
    },
    {
      id: 8,
      order_no: 'RC202501140008',
      username: 'emma_taylor',
      phone: '13800138008',
      channel: '3QPAY',
      channel_text: '3QPAY',
      currency: 'BDT',
      amount: 1200,
      status: 'processing',
      status_text: '处理中',
      create_time: '2025-01-14 18:45:00',
      success_time: '',
      user_id: 1008,
    },
  ],

  // 状态统计
  statusCount: {
    all: 8,
    processing: 3,
    success: 3,
    failed: 2,
  },

  // 分页查询方法
  getList: (params) => {
    let filteredList = [...rechargeMockData.list];

    // 搜索过滤
    if (params.username) {
      filteredList = filteredList.filter((item) =>
        item.username.toLowerCase().includes(params.username.toLowerCase()),
      );
    }

    if (params.phone) {
      filteredList = filteredList.filter((item) => item.phone.includes(params.phone));
    }

    if (params.order_no) {
      filteredList = filteredList.filter((item) =>
        item.order_no.toLowerCase().includes(params.order_no.toLowerCase()),
      );
    }

    if (params.status && params.status !== 'all') {
      filteredList = filteredList.filter((item) => item.status === params.status);
    }

    if (params.channel) {
      filteredList = filteredList.filter((item) => item.channel === params.channel);
    }

    // 时间范围过滤
    if (params.start_time && params.end_time) {
      filteredList = filteredList.filter((item) => {
        const createTime = new Date(item.create_time);
        const startTime = new Date(params.start_time);
        const endTime = new Date(params.end_time);
        return createTime >= startTime && createTime <= endTime;
      });
    }

    // 分页
    const page = parseInt(params.page) || 1;
    const listRows = parseInt(params.size) || 10;
    const total = filteredList.length;
    const start = (page - 1) * listRows;
    const end = start + listRows;
    const data = filteredList.slice(start, end);

    return {
      code: '200',
      message: '操作成功',
      data: {
        list: data,
        total: total,
        pageNum: page,
        pageSize: listRows,
        pages: Math.ceil(total / listRows),
        size: data.length,
        startRow: start + 1,
        endRow: start + data.length,
        hasNextPage: page < Math.ceil(total / listRows),
        hasPreviousPage: page > 1,
        isFirstPage: page === 1,
        isLastPage: page >= Math.ceil(total / listRows),
        firstPage: 1,
        lastPage: Math.ceil(total / listRows),
        navigatePages: 8,
        navigatepageNums: [],
        navigateFirstPage: 1,
        navigateLastPage: Math.ceil(total / listRows),
        nextPage: page < Math.ceil(total / listRows) ? page + 1 : 0,
        prePage: page > 1 ? page - 1 : 0,
      },
    };
  },

  // 获取详情
  getDetail: (id) => {
    const item = rechargeMockData.list.find((item) => item.id == id);
    return item
      ? { code: '200', message: '操作成功', data: { ...item } }
      : { code: '500', message: '记录不存在', data: null };
  },

  // 导出记录
  export: (params) => {
    // 模拟导出功能
    return {
      code: '200',
      message: '导出成功',
      data: {
        download_url: 'https://example.com/export/recharge_records.xlsx',
        filename: `充值记录_${new Date().toISOString().slice(0, 10)}.xlsx`,
      },
    };
  },
};
