import { type SxProps, type Theme } from '@mui/material';
import {
  IconAlertTriangle,
  IconCircleCheck,
  IconCircleX,
  IconInfoCircle,
  IconWifiOff,
} from '@tabler/icons-react';

import { type StateCardVariant } from './types';

/** Normalises an `sx` prop into an array so it can be spread when composing styles. */
export const toSxArray = (sx: SxProps<Theme> | undefined) => {
  if (!sx) return [];
  if (Array.isArray(sx)) return sx;
  return [sx];
};

export const getDefaultIcon = (variant: StateCardVariant) => {
  switch (variant) {
    case 'success':
      return IconCircleCheck;
    case 'error':
      return IconCircleX;
    case 'warning':
      return IconAlertTriangle;
    case 'wifi-off':
      return IconWifiOff;
    default:
      return IconInfoCircle;
  }
};

export const getColor = (variant: StateCardVariant) => {
  switch (variant) {
    case 'wifi-off':
      return 'warning';
    default:
      return variant;
  }
};
