import React, { useRef, useEffect, useState } from 'react';
import { Button, Space, message, Popconfirm } from 'antd';
import {
  PageContainer,
  ProTable,
} from '@ant-design/pro-components';

import AuthConsumer from '@/components/Authority';

import services from '@/services/admin';

const { adminActionLogsItems } = services.AdminActionLogsController;

export default () => {

  useEffect(() => {

  }, []);
  const actionRef = useRef();


  const columns = [
    {
      title: 'ID',
      dataIndex: 'id',
      search: false,
    },
    {
      title: '管理员',
      dataIndex: 'admin',
      search: false,
      render: (_, record) => {
        return record.admin.mobile;
      },
    },
    {
      title: '地址',
      dataIndex: 'uri',
      search: false,
    },
    {
      title: '备注',
      dataIndex: 'note',
      search: false,
    },
    {
      title: '参数',
      dataIndex: 'params',
      valueType: 'jsonCode',
      width: '100px',
      search: false,
      render: (_, record) => {
        return JSON.stringify(record.params);
      },
    },
    {
      title: '创建时间',
      dataIndex: 'created_at',
      search: false,
    },

  ];

  return (
    <PageContainer
      ghost
    >
      <>
        <ProTable
          actionRef={actionRef}
          rowKey="id"
          search={false}
          toolBarRender={() => [
            <AuthConsumer action={'admin/admin/create'} key="admin/admin/create">
              <Button
                type="primary"
                onClick={() => {

                }}
              >
                清除
              </Button>
            </AuthConsumer>
          ]}
          request={async (params, sorter, filter) => {
            const { data, success } = await adminActionLogsItems({
              ...params,
              sorter,
              filter,
            });
            return {
              data: data?.data || [],
              total: data?.total,
              success,
            };
          }}
          columns={columns}
          pagination={{
            showSizeChanger: true,
          }}
        />
      </>
    </PageContainer>
  );
};
