import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  AssetProjectsChargeEnum,
  AssetProjectsEntrustTypeEnum,
  AssetProjectsPropertyTypeEnum,
  AssetProjectsStatusEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useNavigate } from 'react-router-dom';
import Create from './modals/AssetCreate';

export default function Index({ title = '项目管理' }) {
  const navigate = useNavigate();
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        // search={false}
        request={async (params, sort) =>
          MyProTableProps.request(params, sort, Apis.Asset.AssetProjects.List)
        }
        toolBarRender={(action) => [
          <Create key="Create" reload={action?.reload} title={'项目'} />,
        ]}
        columns={[
          MyColumns.ID(),
          MyColumns.EnumTag({
            title: '项目类型',
            dataIndex: 'property_type',
            valueEnum: AssetProjectsPropertyTypeEnum,
            search: false,
          }),
          {
            title: '项目名称',
            dataIndex: 'name',
          },
          {
            title: '项目别名',
            dataIndex: 'alias_name',
          },
          // {
          //   title: '项目编码',
          //   dataIndex: 'code',
          //   search: false,
          // },
          {
            title: '地址',
            render: (_, i: any) => {
              return `${i?.province || ''}${i?.city || ''}${i?.district || ''}${
                i?.address || ''
              }`;
            },
            search: false,
          },
          MyColumns.EnumTag({
            title: '项目状态',
            dataIndex: 'status',
            valueEnum: AssetProjectsStatusEnum,
            search: false,
          }),

          MyColumns.EnumTag({
            title: '委托类型',
            dataIndex: 'entrust_type',
            valueEnum: AssetProjectsEntrustTypeEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '收费方式',
            dataIndex: 'charge',
            valueEnum: AssetProjectsChargeEnum,
            search: false,
          }),
          MyColumns.SoftDelete({
            title: '启/禁用',
            onRestore: Apis.Asset.AssetProjects.Restore,
            onSoftDelete: Apis.Asset.AssetProjects.SoftDelete,
            search: false,
          }),
          // {
          //   title: '接管日期',
          //   dataIndex: 'takeover_date',
          //   search:false,
          // },
          // {
          //   title: '封园日期',
          //   dataIndex: 'closure_date',
          //   search:false,
          // },
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.View
                  title="详情"
                  onClick={() => {
                    navigate(`/asset/asset_projects/${item.id}`);
                  }}
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Common.Admins.Delete({ id: item.id }).then(() =>
                      action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
