/*
 * @Author: 赵伟
 * @Date: 2024-04-18 18:35:41
 * @Description: 镜像状态组件
 */
import { MirrorVersionStatus } from '@/enums';
import styles from './index.less';

export type MirrorVersionStatusInfo = {
  text: string;
  classname: string;
};

const statusInfo: Record<MirrorVersionStatus, MirrorVersionStatusInfo> = {
  [MirrorVersionStatus.Building]: {
    text: '构建中',
    classname: styles['mirror-status-cell'],
  },
  [MirrorVersionStatus.Available]: {
    classname: styles['mirror-status-cell--success'],
    text: '可用',
  },
  [MirrorVersionStatus.Failed]: {
    classname: styles['mirror-status-cell--error'],
    text: '构建失败',
  },
};

function MirrorStatusCell(status?: MirrorVersionStatus | null) {
  if (status === null || status === undefined || !statusInfo[status]) {
    return <span>--</span>;
  }
  return <span className={statusInfo[status].classname}>{statusInfo[status].text}</span>;
}

export default MirrorStatusCell;
