import { MyButtons, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import GridCreate from '../../grids/modals/GridCreate';
import GridMannger from '../../grids/modals/GridMannger';
import GridCreateUpdate from '../../grids/modals/GridUpdate';

export default function Index({ ...rest }) {
  // useEffect(() => {
  //   console.log(rest.item?.id, projectId, 'rest.item?.id');
  //   if (rest.item?.id && rest.item?.id !== projectId) {
  //     projectId = rest.item?.id;
  //     actionLooks?.current.reloadAndRest();
  //   }
  // }, [rest.item?.id]);

  return (
    <>
      <ProTable<Record<any, any>>
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(params, sort, Apis.Grid.Grids.List)
        }
        params={{ asset_projects_id: rest.item?.id }}
        toolBarRender={(action) => [
          <GridCreate
            key="Create"
            item={rest.item}
            reload={action?.reload}
            title="楼栋划分"
          />,
        ]}
        options={false}
        search={false}
        columns={[
          {
            title: 'ID',
            dataIndex: 'id',
          },
          {
            title: '板块名称',
            dataIndex: 'name',
          },
          {
            title: '板块标识',
            dataIndex: 'grid_mark',
          },
          {
            title: '管理员',
            dataIndex: ['company_employee', 'name'],
            render: (_, item: any) =>
              `${item?.company_employee?.name || ''}-${
                item?.company_employee?.phone || ''
              }`,
          },
          // MyColumns.CreatedAt(),
          MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <GridCreateUpdate item={item} reload={action?.reload} />
                <GridMannger item={item} reload={action?.reload} />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Grid.Grids.Delete({ id: item.id }).then(() =>
                      action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
