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

export default function Index({ title = '任务结果' }) {
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'charge_task_details',
    tabLabel: title,
  });

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="bills"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.HouseCharage.HouseChargeTaskDetails.List,
          )
        }
        // toolBarRender={(action) => [
        //   <ChargeTasksCreate
        //     key="Create"
        //     reload={action?.reload}
        //     title={title}
        //   />,
        // ]}
        columns={[
          {
            title: '任务ID',
            dataIndex: 'house_charge_tasks_id',
            search: false,
          },
          MyColumns.ID(),
          MyColumns.EnumTag({
            title: '任务状态',
            dataIndex: 'status',
            valueEnum: HouseChargeTaskDetailsStatusEnum,
          }),
          {
            title: '账单月份',
            render: (_, record) => {
              return `${record.year}-${String(record.month).padStart(2, '0')}`;
            },
          },
          {
            title: '计费开始日期',
            dataIndex: 'start_date',
            search: false,
          },
          {
            title: '计费结束日期',
            dataIndex: 'end_date',
            search: false,
          },
          MyColumns.UpdatedAt(),
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.HouseCharage.HouseChargeTaskDetails.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
