import { useCallback } from 'react';

import { useDialogLayer } from '@material-hu/components/layers/Dialogs';

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

type UseGoalWeightsModalsProps = {
  onConfirmSave: () => void;
  onConfirmExit: () => void;
};

export const useGoalWeightsModals = ({
  onConfirmSave,
  onConfirmExit,
}: UseGoalWeightsModalsProps) => {
  const { t } = useLokaliseTranslation('goals');
  const { openDialog, closeDialog } = useDialogLayer();

  const showSaveConfirm = useCallback(() => {
    openDialog({
      title: t('weights.save_and_approve_title'),
      textBody: t('weights.save_and_approve_description'),
      onClose: () => closeDialog(),
      primaryButtonProps: {
        children: t('general:save'),
        onClick: () => {
          closeDialog();
          onConfirmSave();
        },
      },
      secondaryButtonProps: {
        children: t('general:cancel'),
        onClick: () => closeDialog(),
      },
    });
  }, [openDialog, closeDialog, t, onConfirmSave]);

  const showExitConfirm = useCallback(() => {
    openDialog({
      title: t('weights.exit_without_saving_title'),
      textBody: t('weights.exit_without_saving_description'),
      onClose: () => closeDialog(),
      primaryButtonProps: {
        children: t('weights.exit_without_saving'),
        onClick: () => {
          closeDialog();
          onConfirmExit();
        },
      },
      secondaryButtonProps: {
        children: t('general:cancel'),
        onClick: () => closeDialog(),
      },
    });
  }, [openDialog, closeDialog, t, onConfirmExit]);

  return {
    showSaveConfirm,
    showExitConfirm,
  };
};
