import { type Theme } from '@mui/material';

export const getHelperColor = (
  theme: Theme,
  error: boolean | undefined,
  success: boolean | undefined,
  disabled: boolean | undefined,
): string | undefined => {
  if (error) {
    return theme.palette.new?.text.feedback.error;
  }
  if (success) {
    return theme.palette.new?.text.feedback.success;
  }
  if (disabled) {
    return theme.palette.new?.action.button.text.disabled.darker;
  }
  return theme.palette.new?.text.neutral.lighter;
};

export const getCounterColor = (
  theme: Theme,
  error: boolean | undefined,
  success: boolean | undefined,
): string | undefined => {
  if (error) {
    return theme.palette.new?.text.feedback.error;
  }
  if (success) {
    return theme.palette.new?.text.feedback.success;
  }
  return theme.palette.new?.text.neutral.lighter;
};

export const shouldShowHelperText = (
  hasCounter: boolean | undefined,
  helperText: string | undefined,
  error: boolean | undefined,
): boolean => {
  return !!(hasCounter || helperText || error);
};

export const getCounterValue = (
  value: string | undefined,
  maxLength: number | undefined,
): string => {
  const length = value?.length || 0;
  return `${length}/${maxLength || 0}`;
};
