import { MyButtons, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { RenovationAppliesStatusEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import Review from '../modals/Review';

export default function Index() {
  return (
    <ProTable<Record<any, any>>
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(
          params,
          sort,
          Apis.Renovation.RenovationApplies.List,
        )
      }
      params={{
        status: 'Pending',
      }}
      headerTitle="装修审核列表"
      columns={[
        MyColumns.ID({
          search: false,
        }),
        MyColumns.EnumTag({
          title: '登记状态',
          dataIndex: 'status',
          valueEnum: RenovationAppliesStatusEnum,
          search: false,
        }),
        {
          title: '关联项目',
          dataIndex: ['asset_project', 'name'],
          search: false,
        },
        {
          title: '房屋',
          dataIndex: ['asset_house', 'full_name'],
          search: {
            transform: (value) => {
              return { full_name: value };
            },
          },
        },
        {
          title: '装修人',
          dataIndex: 'owner_name',
        },
        {
          title: '装修公司',
          dataIndex: 'company_name',
          search: false,
        },
        {
          title: '施工负责人',
          dataIndex: 'construction_principal_name',
          search: false,
        },
        {
          title: '施工时间',
          search: false,
          render: (_, item: any) => {
            return (
              <div>
                {item?.construction_start_date || ''} 至
                {item?.construction_end_date || ''}
              </div>
            );
          },
        },
        MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>
              <Review
                key="Review"
                item={item}
                reload={action?.reload}
              />
            </Space>
          ),
        }),
      ]}
    />
  );
}
