import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  HouseCollectionRecordsStatusEnum,
  HouseCollectionTasksChannelEnum,
} from '@/gen/Enums';
import BannerShow from '@/pages/banner/modals/BannerShow';
import BannerUpdate from '@/pages/banner/modals/BannerUpdate';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useEffect, useRef } from 'react';

export default function Index({ ...rest }) {
  const actionLooks = useRef<any>();
  useEffect(() => {
    actionLooks?.current.reloadAndRest();
  }, [rest.loadmore]);

  return (
    <>
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        actionRef={actionLooks}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              collection_tasks_id: rest.item?.collection_tasks_id,
            },
            sort,
            Apis.Collcetion.HouseCollectionRecords.List,
          )
        }
        // toolBarRender={(action) => [
        //   <BannerCreate
        //     key="AddOccupant"
        //     item={rest.item}
        //     reload={action?.reload}
        //     title="添加住户"
        //   />,
        // ]}
        // search={false}
        options={false}
        columns={[
          MyColumns.ID(),
          {
            title: '房屋名称',
            dataIndex: ['asset_house', 'full_name'],
            search: {
              transform: (value) => {
                return { full_name: value };
              },
            },
          },
          MyColumns.EnumTag({
            title: '通知方式',
            dataIndex: 'channel',
            valueEnum: HouseCollectionTasksChannelEnum,
            search: false,
          }),
          {
            title: '未缴金额',
            dataIndex: 'total_unpaid_amount',
            search: false,
          },
          {
            title: '通知时间',
            dataIndex: 'notified_time',
            valueType: 'dateTime',
            search: false,
          },
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: HouseCollectionRecordsStatusEnum,
            search: false,
          }),
          {
            title: '失败原因',
            dataIndex: 'failed_reason',
            search: false,
          },
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <BannerShow item={item} reload={action?.reload} />
                <BannerUpdate item={item} reload={action?.reload} />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
