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

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

type UseDeleteSignatureDialogProps = {
  index: number;
  onDelete: () => void;
};

const useDeleteSignatureDialog = ({
  index,
  onDelete,
}: UseDeleteSignatureDialogProps) => {
  const { t } = useLokaliseTranslation('learning');
  const { openDialog, closeDialog } = useDialogLayer();

  const dialogId = `certificate-delete-signature-${index}`;

  const handleClose = () => closeDialog(dialogId);

  const handleConfirm = () => {
    handleClose();
    onDelete();
  };

  const openDeleteSignatureDialog = () => {
    openDialog(
      {
        content: (
          <Dialog
            onClose={handleClose}
            title={t('settings.certificates.create_flow.delete_signature')}
            textBody={t(
              'settings.certificates.create_flow.delete_signature_description',
            )}
            primaryButtonProps={{
              children: t('general:delete'),
              onClick: handleConfirm,
            }}
            secondaryButtonProps={{
              children: t('general:cancel'),
              onClick: handleClose,
            }}
          />
        ),
      },
      dialogId,
    );
  };

  return { openDeleteSignatureDialog };
};

export default useDeleteSignatureDialog;
