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

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

  const handleOpenModal = () => {
    if (props?.item?.id) {
      setLoading(true);
      Apis.Contract.ContractSealLogs.Show({ id: props.item.id })
        .then((res) => {
          setData(res?.data || {});
        })
        .finally(() => {
          setLoading(false);
        });
    }
  };
  return (
    <MyModal
      title={props.title || '查看'}
      type={props.item?.type || 'primary'}
      width="800px"
      onOpen={handleOpenModal}
      node={
        <Space direction="vertical" style={{ width: '100%' }}>
          <ProCard extra={props.extra}>
            <Spin spinning={loading}>
              <ProDescriptions column={3}>
                {/* 基本信息 */}
                <ProDescriptions.Item label="合同ID" span={1}>
                  {data?.contracts_id}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="用印人">
                  {data?.seal_person || data?.company_employee?.name || '-'}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="用印时间">
                  {data?.use_seal_time}
                </ProDescriptions.Item>

                {/* 用印详情 */}
                <ProDescriptions.Item label="合同份数">
                  {data?.number_contract_copies}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="是否用印">
                  {/* <renderTextHelper.Tag
                    Enums={{
                      1: { text: '是', color: '#52c41a', value: 1 },
                      0: { text: '否', color: '#ff4d4f', value: 0 },
                    }}
                    value={data?.is_use_seal}
                    key="is_use_seal"
                  /> */}
                  {data?.is_use_seal ? '是' : '否'}
                </ProDescriptions.Item>
                {/* <ProDescriptions.Item label="是否外出用印">
                  <renderTextHelper.Tag
                    Enums={{
                      '1': { text: '是', color: '#52c41a' },
                      '0': { text: '否', color: '#ff4d4f' },
                    }}
                    value={data?.is_external_seal_usage?.toString()}
                    key="is_external_seal_usage"
                  />
                </ProDescriptions.Item> */}

                {/* 印章信息 */}
                <ProDescriptions.Item label="印章类型" span={3}>
                  {data?.seal_ids?.map((sealId: string, index: number) => (
                    <span key={index} style={{ marginRight: 16 }}>
                      <renderTextHelper.Tag
                        Enums={CompanySealsTypeEnum}
                        value={sealId}
                        key={`seal_id_${index}`}
                      />
                    </span>
                  )) || '-'}
                </ProDescriptions.Item>

                {/* 其他信息 */}
                <ProDescriptions.Item label="备注" span={3}>
                  {data?.remarks || '-'}
                </ProDescriptions.Item>

                {/* 时间信息 */}
                <ProDescriptions.Item label="创建日期">
                  {data?.created_at}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="最近修改">
                  {data?.updated_at}
                </ProDescriptions.Item>
              </ProDescriptions>
            </Spin>
          </ProCard>
        </Space>
      }
    />
  );
}
