/*
 * @Author: 赵伟
 * @Date: 2024-04-18 18:35:41
 * @Description: 服务运行状态
 */
import { ServiceRunStatus } from '@/enums';
import styles from './index.less';

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

export const statusInfo: Record<ServiceRunStatus, ServiceRunStatusInfo> = {
  [ServiceRunStatus.Init]: {
    text: '启动中',
    classname: styles['model-deployment-status-cell'],
  },
  [ServiceRunStatus.Running]: {
    classname: styles['model-deployment-status-cell--running'],
    text: '运行中',
  },
  [ServiceRunStatus.Stopped]: {
    classname: styles['model-deployment-status-cell--stopped'],
    text: '已停止',
  },
  [ServiceRunStatus.Failed]: {
    classname: styles['model-deployment-status-cell--error'],
    text: '失败',
  },
  [ServiceRunStatus.Pending]: {
    classname: styles['model-deployment-status-cell--pending'],
    text: '挂起中',
  },
};

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

export default ServiceRunStatusCell;
