import { MyColumns, MyPageContainer, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  ApprovalInstancesStatusEnum,
  ApprovalTemplatesTypeEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';
import Audit from '../pending/modals/Audit';

export default function Index({ title = '待我审批' }) {
  const navigate = useNavigate();
  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="approval_instances"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              status: 'Pending',
              ...params,
            },
            sort,
            Apis.Approval.ApprovalInstances.PendingList,
          )
        }
        headerTitle="待我审批"
        columns={[
          MyColumns.ID({ search: false }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: ApprovalInstancesStatusEnum,
          }),
          MyColumns.EnumTag({
            dataIndex: ['approval_instance', 'type'],
            title: '类型',
            valueEnum: ApprovalTemplatesTypeEnum,
            search: false,
          }),
          {
            title: '申请事项',
            dataIndex: ['approval_instance', 'title'],
            search: false,
          },
          {
            title: '关联项目',
            dataIndex: ['approval_instance', 'asset_project', 'name'],
            search: false,
          },

          {
            title: '申请人',
            dataIndex: 'approver_name',
          },

          // {
          //   title: '有效期',
          //   search: false,
          //   render: (_, item: any) => {
          //     return `${dayjs(
          //       item?.approval_instance?.model?.start_time,
          //     ).format('YYYY-MM-DD')}至${dayjs(
          //       item?.approval_instance?.model?.end_time,
          //     ).format('YYYY-MM-DD')}`;
          //   },
          // },
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <Audit item={item} reload={action?.reload} title={title} />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
