import React from 'react';
import { isEmpty } from '../utils/vehicle';
import { ExpireDate } from './ExpireDate';

interface DetailExpireFieldProps {
  date: string;
  onClickNotUploaded?: () => void;
}

/** 详情证照类日期：空为可点「未上传」，有值展示日期与剩余/已过期天数 */
export function DetailExpireField({ date, onClickNotUploaded }: DetailExpireFieldProps) {
  if (isEmpty(date)) {
    if (onClickNotUploaded) {
      return (
        <button
          type="button"
          className="vm-link"
          onClick={onClickNotUploaded}
          title="前往证照管理维护"
        >
          未上传
        </button>
      );
    }
    return <span>未上传</span>;
  }
  return <ExpireDate date={date} alwaysShowRemainder />;
}
