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 { useNavigate } from '@umijs/max';
import { Space } from 'antd';

export default function TaskShow(props: MyBetaModalFormProps) {
  const navigate = useNavigate();
  return (
    <MyModal
      title={props.title || '查看'}
      type={props.item?.type || 'primary'}
      width="1000px"
      node={
        <ProTable
          {...MyProTableProps.props}
          request={async (params, sort) =>
            MyProTableProps.request(
              {
                ...params,
                house_meter_task_id: props?.item?.house_meter_task_id,
              },
              sort,
              Apis.Meter.HouseMeterTaskDetails.List,
            )
          }
          options={false}
          columns={[
            MyColumns.ID(),
            {
              title: '仪表编号',
              dataIndex: ['meter_data', 'name'],
              search: false,
            },
            {
              title: '关联房屋',
              dataIndex: 'full_name',
              search: false,
              render: (_, record) => (
                <MyButtons.View
                  title={record.full_name}
                  type="link"
                  onClick={() => {
                    navigate(`/bills/summary/show/${record.asset_houses_id}`);
                  }}
                />
              ),
            },
            MyColumns.EnumTag({
              title: '状态',
              dataIndex: 'status',
              valueEnum: HouseChargeTaskDetailsStatusEnum,
            }),

            {
              title: '收费标准',
              dataIndex: ['charge_standard', 'name'],
              render: (_, record) => {
                return `【${record.charge_standard.id}】${record.charge_standard.name}`;
              },
              search: false,
            },
            {
              title: '账单月份',
              render: (_, record) => {
                return `${record.year}-${String(record.month).padStart(
                  2,
                  '0',
                )}`;
              },
              search: false,
            },
            {
              title: '完成时间',
              dataIndex: 'processed_time',
              search: false,
            },
            {
              title: '失败原因',
              dataIndex: ['error_message', 'message'],
              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>
              ),
            }),
          ]}
        />
      }
    />
  );
}
