import React, { useState, useRef } from 'react';
import Table, { ProColumns, ActionType } from '@/components/Table';
import { getUserList } from '@/services/user/user';
import { fetchTableData } from '@/utils/table';
import moment from 'moment';

const UserManageList = () => {
  const tableRef = useRef<ActionType>();
  const columns: ProColumns<any>[] = [
    {
      title: '钱包地址',
      dataIndex: 'address',
      ellipsis: true,
    },
    {
      title: '注册时间',
      dataIndex: 'create_time',
      hideInSearch: true,
      ellipsis: true,
    },
    {
      title: '登陆时间',
      dataIndex: 'last_time',
      hideInSearch: true,
      ellipsis: true,
    },
  ];
  return (
    <Table
      columns={columns}
      rowKey="address"
      actionRef={tableRef}
      request={async (params) => {
        const res = await fetchTableData(getUserList, params);
        console.log('res = ', res);
        for (const key in res.data) {
          if (Object.prototype.hasOwnProperty.call(res.data, key)) {
            const element = res.data[key];
            if (
              element.create_time != '' &&
              element.create_time != undefined &&
              element.create_time != null
            ) {
              element.create_time = moment(element.create_time * 1000).format(
                'YYYY-MM-DD HH:mm:ss',
              );
            }
            if (
              element.last_time != '' &&
              element.last_time != undefined &&
              element.last_time != null
            ) {
              element.last_time = moment(element.last_time * 1000).format('YYYY-MM-DD HH:mm:ss');
            }
          }
        }
        if (res.data == null) {
          return [];
        }
        return res;
      }}
    />
  );
};

export default UserManageList;
