import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  CooperationSuggestionEnum,
  InfoVerificationEnum,
  QualificationEvaluationEnum,
  RiskLevelEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import AddSurvey from '../modals/AddSurvey';
import SurveyShow from './modals/SurveyShow';
import SurveyUpdate from './modals/SurveyUpdate';

export default function Survey({ ...rest }) {
  return (
    <>
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              supplier_id: rest.item?.company_suppliers_id,
            },
            sort,
            Apis.CompanySupplier.SupplierFieldReports.List,
          )
        }
        search={false}
        toolBarRender={(action) => [
          <AddSurvey
            key="AddSurvey"
            item={{ ...rest.item, size: 'middle' }}
            reload={action?.reload}
            title="添加实地调查报告"
          />,
        ]}
        columns={[
          MyColumns.EnumTag({
            title: '信息核实',
            dataIndex: 'info_verification',
            valueEnum: InfoVerificationEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '资质评价',
            dataIndex: 'qualification_evaluation',
            valueEnum: QualificationEvaluationEnum,
            search: false,
          }),

          MyColumns.EnumTag({
            title: '风险等级',
            dataIndex: 'risk_level',
            valueEnum: RiskLevelEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '合作建议',
            dataIndex: 'cooperation_suggestion',
            valueEnum: CooperationSuggestionEnum,
            search: false,
          }),

          {
            title: '调查开始日期',
            dataIndex: 'investigation_start_date',
            search: false,
            valueType: 'date',
          },
          {
            title: '调查结束日期',
            dataIndex: 'investigation_end_date',
            search: false,
            valueType: 'date',
          },
          {
            title: '出具日期',
            dataIndex: 'issue_date',
            search: false,
            valueType: 'date',
          },
          {
            title: '调查人',
            dataIndex: 'investigator',
            search: false,
          },
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={`item_${index}`}>
                <SurveyShow item={item} reload={action?.reload} title="查看" />
                <SurveyUpdate
                  item={item}
                  reload={action?.reload}
                  title="编辑"
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
