import { MyBetaModalFormProps, renderTextHelper } from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import {
  AssetProjectsChargeEnum,
  AssetProjectsEntrustTypeEnum,
  AssetProjectsOwnershipTypeEnum,
  AssetProjectsPropertyTypeEnum,
  AssetProjectsStatusEnum,
} from '@/gen/Enums';
import { ProCard, ProDescriptions } from '@ant-design/pro-components';
import { Space, Spin } from 'antd';
import { useState } from 'react';

export default function AssetInfo(props: MyBetaModalFormProps) {
  const [loading, setLoading] = useState(true);
  const [data, setData] = useState<any>({});

  return (
    <MyModal
      title={props.title || '查看'}
      type={props.item?.type || 'primary'}
      width="800px"
      onOpen={() => {
        if (props?.item?.id) {
          setLoading(true);
          Apis.Asset.AssetProjects.Show({ id: props.item.id })
            .then((res) => {
              setData(res?.data || {});
            })
            .finally(() => {
              setLoading(false);
            });
        }
      }}
      node={
        <Space direction="vertical" style={{ width: '100%' }}>
          <ProCard extra={props.extra}>
            <Spin spinning={loading}>
              <ProDescriptions column={3}>
                <ProDescriptions.Item label="项目名称" span={1}>
                  <Space size="large">
                    <div>
                      {data?.name}
                      {data?.alias_name ? `（${data?.alias_name}）` : ''}
                    </div>
                  </Space>
                </ProDescriptions.Item>
                <ProDescriptions.Item label="所在城市">
                  {data?.province || ''}
                  {data?.city || ''}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="项目地址" span={2}>
                  {data?.district || ''}
                  {data?.address || ''}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="项目类型">
                  <renderTextHelper.Tag
                    Enums={AssetProjectsPropertyTypeEnum}
                    value={data?.property_type}
                    key="property_type"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="项目状态">
                  <renderTextHelper.Tag
                    Enums={AssetProjectsStatusEnum}
                    value={data?.status}
                    key="status"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="委托类型">
                  <renderTextHelper.Tag
                    Enums={AssetProjectsEntrustTypeEnum}
                    value={data?.entrust_type}
                    key="entrust_type"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="收费方式">
                  <renderTextHelper.Tag
                    Enums={AssetProjectsChargeEnum}
                    value={data?.charge}
                    key="charge"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="业权类型">
                  <renderTextHelper.Tag
                    Enums={AssetProjectsOwnershipTypeEnum}
                    value={data?.ownership_type}
                    key="ownership_type"
                  />
                </ProDescriptions.Item>

                <ProDescriptions.Item label="接管日期">
                  {data?.takeover_date}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="封园日期">
                  {data?.closure_date}
                </ProDescriptions.Item>
                {/* <ProDescriptions.Item label="退出日期">
                  {data?.exit_date}
                </ProDescriptions.Item> */}
                <ProDescriptions.Item label="容积率">
                  {data?.plot_ratio}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="项目总期数">
                  {data?.project_phase_number}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="规划总户数">
                  {data?.total_households}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="接管总户数">
                  {data?.takeover_households}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="规划车位数">
                  {data?.total_parking_spaces}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="接管车位数">
                  {data?.takeover_parking_spaces}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="合同建筑面积(㎡)">
                  {data?.contract_building_area}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="占地面积(㎡)">
                  {data?.land_area}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="接管建筑面积(㎡)">
                  {data?.takeover_building_area}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="物业面积(㎡)">
                  {data?.property_area}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="绿化面积(㎡)">
                  {data?.green_area}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="成立业委会">
                  {data?.is_owners_committee ? '是' : '否'}
                </ProDescriptions.Item>
                {data?.is_owners_committee && (
                  <>
                    <ProDescriptions.Item label="第几届业委会">
                      {data?.owners_committee_number}
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="业委会开始日期">
                      {data?.owners_committee_start_date}
                    </ProDescriptions.Item>
                    <ProDescriptions.Item label="业委会结束日期">
                      {data?.owners_committee_end_date}
                    </ProDescriptions.Item>
                  </>
                )}
                {data?.latitude && data?.longitude ? (
                  <ProDescriptions.Item label="经纬度">
                    {data?.latitude}，{data?.longitude}
                  </ProDescriptions.Item>
                ) : (
                  <ProDescriptions.Item label="经纬度">
                    暂未配置
                  </ProDescriptions.Item>
                )}
                <ProDescriptions.Item label="物业品牌">
                  {data?.company_property_brand?.name || '-'}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="创建日期">
                  {data?.created_at}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="最近修改">
                  {data?.updated_at}
                </ProDescriptions.Item>
              </ProDescriptions>
            </Spin>
          </ProCard>
        </Space>
      }
    />
  );
}
