import { MyColumns, MyPageContainer, MyProTableProps } from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import {
  ApprovalInstancesStatusEnum,
  ApprovalTemplatesTypeEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import AuditShow from '../common_info/AuditShow';

export default function Index({ title = '审批列表' }) {
  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="all_approval_instances"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Approval.ApprovalInstances.List,
          )
        }
        headerTitle={title}
        columns={[
          MyColumns.ID({ search: false }),
          Selects?.AssetProjects({
            title: '选择项目',
            key: 'asset_projects_id',
            hidden: true,
          }),
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: ApprovalInstancesStatusEnum,
          }),
          MyColumns.EnumTag({
            dataIndex: 'type',
            title: '类型',
            valueEnum: ApprovalTemplatesTypeEnum,
            search: false,
          }),
          {
            title: '申请事项',
            dataIndex: 'title',
            search: false,
          },
          {
            title: '关联项目',
            dataIndex: ['asset_project', 'name'],
            search: false,
          },
          {
            title: '申请人',
            dataIndex: ['applicant', 'name'],
            search: false,
          },
          {
            title: '当前审批人',
            dataIndex: ['approval_records', 'approver_name'],
            search: false,
            render: (_, item: any) =>
              `${item?.approval_records?.[0]?.company_employee?.name || ''}-${
                item?.approval_records?.[0]?.company_employee?.phone || ''
              }`,
          },
          {
            title: '申请人',
            dataIndex: 'applicant_name',
            hidden: true,
          },
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <AuditShow item={item} reload={action?.reload} title={title} />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
