import { useModal } from '@material-hu/hooks/useModal';

import HuDialog from '@material-hu/components/design-system/Dialog';

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

type UseSingleAssignmentConfirmModalParams = {
  selectedAgentFullName: string;
  currentAgentFullName: string;
  hasCurrentAssignee: boolean;
  onConfirm: () => void;
  onDismiss: () => void;
  isLoading: boolean;
};

export const useSingleAssignmentConfirmModal = ({
  selectedAgentFullName,
  currentAgentFullName,
  hasCurrentAssignee,
  onConfirm,
  onDismiss,
  isLoading,
}: UseSingleAssignmentConfirmModalParams) => {
  const { t } = useLokaliseTranslation('service_management');

  const {
    modal: singleAssignmentConfirmationModal,
    showModal: openSingleAssignmentConfirmationModal,
    closeModal: closeSingleAssignmentConfirmationModal,
  } = useModal(
    () => (
      <HuDialog
        title={t('confirm_agent_selection_modal_title', {
          agentName: selectedAgentFullName,
        })}
        textBody={
          hasCurrentAssignee
            ? t('confirm_agent_selection_modal_description', {
                currentAgentName: currentAgentFullName,
                newAgentName: selectedAgentFullName,
              })
            : t('confirm_agent_selection_modal_description_no_current', {
                newAgentName: selectedAgentFullName,
              })
        }
        primaryButtonProps={{
          color: 'primary',
          children: t('assign'),
          onClick: onConfirm,
          loading: isLoading,
        }}
        secondaryButtonProps={{
          color: 'primary',
          children: t('cancel'),
          disabled: isLoading,
          onClick: closeSingleAssignmentConfirmationModal,
        }}
        onClose={() => {
          closeSingleAssignmentConfirmationModal();
          onDismiss();
        }}
      />
    ),
    { fullWidth: true },
  );

  return {
    singleAssignmentConfirmationModal,
    openSingleAssignmentConfirmationModal,
    closeSingleAssignmentConfirmationModal,
  };
};
