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

import { useArticleId } from 'src/pages/dashboard/HuLibraries/hooks/useArticleId';
import { useUpdateArticleStatus } from 'src/pages/dashboard/HuLibraries/hooks/useUpdateArticleStatus';
import {
  type Article,
  ArticleStatus,
} from 'src/pages/dashboard/HuLibraries/types';
import { useLokaliseTranslation } from 'src/utils/i18n';

export type ActivateArticleModalProps = {
  article: Article;
  onClose: () => void;
};

const ActivateArticleModal = ({
  article,
  onClose,
}: ActivateArticleModalProps) => {
  const { t } = useLokaliseTranslation('libraries');
  const { rootId } = useArticleId();

  const updateArticleStatus = useUpdateArticleStatus();

  const handleConfirm = () => {
    updateArticleStatus.mutate(
      { article, rootId, status: ArticleStatus.ENABLED },
      { onSuccess: onClose },
    );
  };

  return (
    <Dialog
      onClose={onClose}
      title={t('article.activate.confirm.title')}
      textBody={t('article.activate.confirm.description')}
      primaryButtonProps={{
        loading: updateArticleStatus.isLoading,
        disabled: updateArticleStatus.isLoading,
        children: t('article.activate.title'),
        onClick: handleConfirm,
      }}
      secondaryButtonProps={{
        children: t('general:cancel'),
        disabled: updateArticleStatus.isLoading,
        onClick: onClose,
      }}
    />
  );
};

export default ActivateArticleModal;
