import React from 'react';
import { Chip, ChipProps } from '@mui/material';
import { 
  BuildStatus, 
  PackageStatus, 
  PublicationStatus, 
  StepStatus 
} from '../../types';

interface StatusChipProps extends Omit<ChipProps, 'color'> {
  status: BuildStatus | PackageStatus | PublicationStatus | StepStatus;
}

export const StatusChip: React.FC<StatusChipProps> = ({ status, ...props }) => {
  const getStatusColor = (status: string): ChipProps['color'] => {
    switch (status) {
      case BuildStatus.Success:
      case PackageStatus.Published:
      case PublicationStatus.Completed:
      case StepStatus.Completed:
        return 'success';
      
      case BuildStatus.Failure:
      case PackageStatus.Failed:
      case PublicationStatus.Failed:
      case StepStatus.Failed:
        return 'error';
      
      case BuildStatus.InProgress:
      case PackageStatus.Publishing:
      case PublicationStatus.InProgress:
      case StepStatus.InProgress:
        return 'info';
      
      case PackageStatus.Ready:
      case PublicationStatus.Queued:
      case StepStatus.Pending:
        return 'warning';
      
      case PackageStatus.Draft:
      case PublicationStatus.Cancelled:
      case StepStatus.Skipped:
        return 'default';
      
      default:
        return 'default';
    }
  };

  const getStatusIcon = (status: string) => {
    switch (status) {
      case BuildStatus.InProgress:
      case PackageStatus.Publishing:
      case PublicationStatus.InProgress:
      case StepStatus.InProgress:
        return '🔄';
      
      case BuildStatus.Success:
      case PackageStatus.Published:
      case PublicationStatus.Completed:
      case StepStatus.Completed:
        return '✅';
      
      case BuildStatus.Failure:
      case PackageStatus.Failed:
      case PublicationStatus.Failed:
      case StepStatus.Failed:
        return '❌';
      
      default:
        return undefined;
    }
  };

  const icon = getStatusIcon(status);

  return (
    <Chip
      label={`${icon ? icon + ' ' : ''}${status}`}
      color={getStatusColor(status)}
      size="small"
      {...props}
    />
  );
};