import { MyBetaModalFormProps } from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import { ProCard, ProDescriptions } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useState } from 'react';

export default function Info(props: MyBetaModalFormProps) {
  const [getShow, setDataShow] = useState<any>({});

  return (
    <MyModal
      title={props.title || '查看'}
      width="600px"
      onOpen={(e: boolean) => {
        if (e) {
          return Apis.Grid.Grids.Show({
            id: props?.item?.id,
          })
            .then((res) => {
              console.log(res);
              setDataShow(JSON.parse(JSON.stringify(res?.data)));
              return false;
            })
            .catch(() => false);
        }
        console.log(e);
      }}
      node={
        <>
          <ProCard extra={props.extra}>
            <ProDescriptions bordered column={1}>
              <ProDescriptions.Item label="板块名称">
                <Space>{getShow?.name}</Space>
              </ProDescriptions.Item>

              <ProDescriptions.Item label="楼栋单元">
                {getShow?.grid_ranges
                  ?.map(
                    (item: any) =>
                      item?.asset_building?.name + item?.asset_unit?.name,
                  )
                  .join('；')}
              </ProDescriptions.Item>

              <ProDescriptions.Item label="创建时间">
                {getShow?.created_at}
              </ProDescriptions.Item>
              <ProDescriptions.Item label="最近修改">
                {getShow?.updated_at}
              </ProDescriptions.Item>
            </ProDescriptions>
          </ProCard>
        </>
      }
    />
  );
}
