import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import { HouseChargeTaskDetailsStatusEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';

interface TaskShowProps extends MyBetaModalFormProps {
  open?: boolean;
  setOpen?: (open: boolean) => void;
  item?: any;
}

export default function TaskShow(props: TaskShowProps) {
  return (
    <MyModal
      title={props.title || '查看'}
      type="primary"
      width="1000px"
      mode="modal"
      open={props.open}
      onCancel={() => props.setOpen?.(false)}
      node={
        <ProTable
          {...MyProTableProps.props}
          request={async (params, sort) =>
            MyProTableProps.request(
              { ...params, house_charge_tasks_id: props?.item?.id },
              sort,
              Apis.HouseCharge.HouseChargeTaskDetails.List,
            )
          }
          options={false}
          columns={[
            MyColumns.ID({ search: false }),
            MyColumns.EnumTag({
              title: '状态',
              dataIndex: 'status',
              valueEnum: HouseChargeTaskDetailsStatusEnum,
            }),
            {
              title: '关联房屋',
              dataIndex: 'full_name',
              // render: (_, record) => {
              //   return record.asset_houses_id ? (
              //     <MyButtons.View
              //       title={`${record.asset_house.full_name}`}
              //       type="link"
              //       onClick={() => {
              //         record.asset_houses_id
              //           ? navigate(
              //               `/bills/summary/show/${record.asset_houses_id}`,
              //             )
              //           : '';
              //       }}
              //     />
              //   ) : (
              //     '车位｜ ' + record.asset_car_port.full_name
              //   );
              // },
              search: { transform: (value) => ({ full_name: value }) },
            },
            {
              title: '执行标准',
              dataIndex: ['house_charge_task', 'house_charge_standard', 'name'],
              search: false,
            },
            {
              title: '账单月份',
              render: (_, record) => {
                return `${record.year}-${String(record.month).padStart(
                  2,
                  '0',
                )}`;
              },
              search: false,
            },
            {
              title: '计费周期',
              render: (_, record) => {
                return `${record.house_charge_task.start_date} 至 ${String(
                  record.house_charge_task.end_date,
                ).padStart(2, '0')}`;
              },
              search: false,
            },
            {
              title: '生成时间',
              dataIndex: 'processed_time',
              search: false,
            },
            MyColumns.Option({
              render: (_, item: any, index, action) => (
                <Space key={index}>
                  <MyButtons.Default
                    title="重新执行"
                    type="link"
                    color="primary"
                    isConfirm
                    description="确认执行此任务吗？"
                    onConfirm={() =>
                      Apis.HouseCharge.HouseChargeTaskDetails.CreateHouseBill({
                        id: item.id,
                      }).then(() => action?.reload())
                    }
                  />
                </Space>
              ),
            }),
          ]}
        />
      }
    />
  );
}
