import { useLokaliseTranslation } from 'src/utils/i18n';

const getTranslationKey = (fieldName: string): string => {
  const fieldMapping: Record<string, string> = {
    startingValue: 'new.initial_measure',
    minValue: 'new.min_value',
    objectiveValue: 'new.target_measure',
    maxValue: 'new.max_value',
    currentValue: 'new.current_value',
  };

  return fieldMapping[fieldName] || fieldName;
};

export const useRangeTranslations = () => {
  const { t } = useLokaliseTranslation('goals');

  const translateField = (fieldName: string): string => {
    return t(getTranslationKey(fieldName));
  };

  const getRangeLabel = (
    startField: string,
    endField: string | null,
    totalRangeCount: number,
    isLast: boolean,
  ): string => {
    const startLabel = translateField(startField);
    let endLabel = '';

    if (endField) {
      endLabel = translateField(endField);
    } else if (totalRangeCount === 4) {
      endLabel = t('ranges.greater');
    }

    let formulaLabel = `${startLabel} ${t('ranges.to')} ${endLabel}`;

    if (totalRangeCount === 4 && isLast) {
      formulaLabel = `${endLabel} ${t('ranges.to')} ${startLabel}`;
    }

    return formulaLabel;
  };

  return {
    translateField,
    getRangeLabel,
  };
};
