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_charge_tasks_id: props?.item?.id },
              sort,
              Apis.HouseCharage.HouseChargeTaskDetails.List,
            )
          }
          options={false}
          columns={[
            MyColumns.ID(),
            {
              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: ['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.HouseCharage.HouseChargeTaskDetails.CreateHouseBill({
                        id: item.id,
                      }).then(() => action?.reload())
                    }
                  />
                </Space>
              ),
            }),
          ]}
        />
      }
    />
  );
}
