import { MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  HouseOccupantsHouseRelationEnum,
  HouseOccupantsRelationWithOwnerEnum,
  HouseOccupantsStatusEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useEffect, useRef } from 'react';
import OccupantsUpdate from './modals/OccupantsUpdate';

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,
              asset_houses_id: rest.item?.asset_houses_id,
              status: 'Unbound',
            },
            sort,
            Apis.Archive.HouseOccupants.List,
          )
        }
        // toolBarRender={(action) => [
        //   <AddOwner
        //     key="add"
        //     item={rest.item}
        //     reload={action?.reload}
        //     title="添加产权人"
        //   />,

        // ]}
        search={false}
        columns={[
          MyColumns.EnumTag({
            title: '房客关系',
            dataIndex: 'house_relation',
            valueEnum: HouseOccupantsHouseRelationEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '关系说明',
            dataIndex: 'relation_with_owner',
            valueEnum: HouseOccupantsRelationWithOwnerEnum,
            search: false,
          }),
          {
            title: '姓名',
            dataIndex: 'name',
          },
          {
            title: '电话',
            dataIndex: 'phone',
          },

          {
            title: '是否入住',
            dataIndex: 'is_live_in',
            render(_, record) {
              return `${record?.is_live_in ? '是' : '-'} `;
            },
          },
          {
            title: '入住日期',
            dataIndex: 'is_live_in',
            render(_, record) {
              return `${record?.move_in_date || '-'}`;
            },
          },
          MyColumns.EnumTag({
            title: '状态',
            dataIndex: 'status',
            valueEnum: HouseOccupantsStatusEnum,
            search: false,
          }),
          // MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                {item?.house_relation !== 'Owner' && (
                  <OccupantsUpdate item={item} reload={action?.reload} />
                )}
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
