import React, { useEffect } from 'react';
import { Modal, Descriptions,Button } from 'antd';
import { DictValueEnumObj } from '@/components/DictTag';

export type DetailModalProps = {
  onCancel: () => void;
  open: boolean;
  values?: Partial<API.ManagementList.Manage>;
  educationEnum?: DictValueEnumObj;
  experienceEnum?: DictValueEnumObj;
  areaEnum?: DictValueEnumObj;
};

const DetailModal: React.FC<DetailModalProps> = (props) => {
  const { values } = props;
  
  // 可以在这里获取字典数据，如果传入的话
  // 或者通过 useEffect 请求
  
  // 如果没有传入字典数据，可以在这里获取
  useEffect(() => {
    if (props.open && !props.educationEnum) {
      // 这里可以获取字典数据
      // getDictValueEnum('education', true, true).then(setEducationEnum);
    }
  }, [props.open]);
  
  const handleCancel = () => {
    props.onCancel();
  };
  
  // 如果没有数据，显示加载状态
  if (!values) {
    return null;
  }
  
  return (
    <Modal
      title="岗位详情"
      open={props.open}
      width={800}
      onCancel={handleCancel}
      footer={[
        <Button key="close" onClick={handleCancel}>
          关闭
        </Button>
      ]}
      destroyOnHidden
    >
      <Descriptions column={2} bordered>
        <Descriptions.Item label="岗位名称" span={2}>
          {values.jobTitle || '-'}
        </Descriptions.Item>
        
        <Descriptions.Item label="公司名称">
          {values.companyName || '-'}
        </Descriptions.Item>
        
        <Descriptions.Item label="薪资范围">
          {`${values.minSalary || 0} - ${values.maxSalary || 0} 元/月`}
        </Descriptions.Item>
        
        <Descriptions.Item label="学历要求">
          {props.educationEnum ? (
            <span>{props.educationEnum[values.education as string] || values.education || '-'}</span>
          ) : (
            values.education || '-'
          )}
        </Descriptions.Item>
        
        <Descriptions.Item label="工作经验">
          {props.experienceEnum ? (
            <span>{props.experienceEnum[values.experience as string] || values.experience || '-'}</span>
          ) : (
            values.experience || '-'
          )}
        </Descriptions.Item>
        
        <Descriptions.Item label="工作区县">
          {props.areaEnum ? (
            <span>{props.areaEnum[values.jobLocationAreaCode as string] || values.jobLocationAreaCode || '-'}</span>
          ) : (
            values.jobLocationAreaCode || '-'
          )}
        </Descriptions.Item>
        
        <Descriptions.Item label="招聘人数">
          {values.vacancies || 0} 人
        </Descriptions.Item>
        
        <Descriptions.Item label="工作地点" span={2}>
          {values.jobLocation || '-'}
        </Descriptions.Item>
        
        <Descriptions.Item label="岗位描述" span={2}>
          <div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
            {values.description || '-'}
          </div>
        </Descriptions.Item>
        
        <Descriptions.Item label="浏览量">
          {values.view || 0}
        </Descriptions.Item>
        
        <Descriptions.Item label="发布时间">
          {values.createTime || '-'}
        </Descriptions.Item>
        
        {values.isPublish !== undefined && (
          <Descriptions.Item label="发布状态">
            {values.isPublish === 1 ? '已发布' : '未发布'}
          </Descriptions.Item>
        )}
      </Descriptions>
    </Modal>
  );
};

export default DetailModal;