import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  AssetProjectsPropertyTypeEnum,
  AssetProjectsStatusEnum,
} from '@/gen/Enums';
import AssetCreate from '@/pages/asset/list/modals/AssetCreate';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useNavigate } from 'react-router-dom';

export default function Index(props: MyBetaModalFormProps) {
  const navigate = useNavigate();

  return (
    <>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            { ...params, companies_id: props?.item?.id },
            sort,
            Apis.Asset.AssetProjects.List,
          )
        }
        toolBarRender={(action) => [
          <AssetCreate
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="项目"
          />,
        ]}
        // search={false}
        // options={false}
        columns={[
          MyColumns.ID(),
          {
            title: '项目名称',
            dataIndex: 'name',
          },
          MyColumns.EnumTag({
            title: '项目类型',
            dataIndex: 'property_type',
            valueEnum: AssetProjectsPropertyTypeEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '项目状态',
            dataIndex: 'status',
            valueEnum: AssetProjectsStatusEnum,
            search: false,
          }),
          {
            title: '所在城市',
            render: (_, i: any) => {
              return `${i?.province || ''}${i?.city || ''}`;
            },
            search: false,
          },
          {
            title: '地址',
            render: (_, i: any) => {
              return `${i?.province || ''}${i?.city || ''}${i?.district || ''}${
                i?.address || ''
              }`;
            },
            search: false,
          },
          MyColumns.SoftDelete({
            title: '启/禁用',
            onRestore: Apis.Asset.AssetProjects.Restore,
            onSoftDelete: Apis.Asset.AssetProjects.SoftDelete,
            search: false,
          }),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.View
                  title="查看｜配置"
                  onClick={() => {
                    navigate(`/asset/list/show/${item.id}`);
                  }}
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
