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

import DeleteCertificateDialog from './DeleteCertificateDialog';

const getDeleteDialogId = (certificateId: number) =>
  `certificate-delete-${certificateId}`;

export const useDeleteCertificateDialog = () => {
  const { openDialog, closeDialog } = useDialogLayer();

  const openDeleteDialog = ({
    certificateId,
    certificateName,
  }: {
    certificateId: number;
    certificateName: string;
  }) => {
    const dialogId = getDeleteDialogId(certificateId);
    const handleClose = () => closeDialog(dialogId);

    openDialog(
      {
        content: (
          <DeleteCertificateDialog
            certificateId={certificateId}
            certificateName={certificateName}
            onClose={handleClose}
          />
        ),
      },
      dialogId,
    );
  };

  return { openDeleteDialog };
};
