/*
 * @Author: 赵伟
 * @Date: 2024-11-29 09:27:19
 * @Description: 用于 BasicInfoItem 的组件
 */

import { isEmpty } from '@/utils';
import { Link } from '@umijs/max';
import { Typography } from 'antd';

type BasicInfoItemValueProps = {
  /** 值是否显示省略号 */
  ellipsis?: boolean;
  /** 自定义类名前缀 */
  classPrefix: string;
  /** 值 */
  value?: string;
  /** 内部链接 */
  link?: string;
  /** 外部链接 */
  url?: string;
};

function BasicInfoItemValue({
  value,
  link,
  url,
  classPrefix,
  ellipsis = true,
}: BasicInfoItemValueProps) {
  const myClassName = `${classPrefix}__item__value`;
  let component = undefined;
  if (url && value) {
    component = (
      <a className={`${myClassName}__link`} href={url} target="_blank" rel="noopener noreferrer">
        {value}
      </a>
    );
  } else if (link && value) {
    component = (
      <Link to={link} className={`${myClassName}__link`}>
        {value}
      </Link>
    );
  } else {
    component = <span className={`${myClassName}__text`}>{!isEmpty(value) ? value : '--'}</span>;
  }

  return (
    <div className={myClassName}>
      <Typography.Text ellipsis={ellipsis !== false ? { tooltip: value } : false}>
        {component}
      </Typography.Text>
    </div>
  );
}

export default BasicInfoItemValue;
