import { useDrawerV2 } from '@material-hu/hooks/useDrawerV2';
import { IconCopy } from '@material-hu/icons/tabler';

import { type Article } from 'src/pages/dashboard/HuLibraries/types';
import { useLokaliseTranslation } from 'src/utils/i18n';

import DuplicateArticleDrawer from '../components/DuplicateArticleDrawer';

export const useDuplicateActions = (
  article: Article,
  disableUnsavedWarning: () => void,
  resetUnsavedWarning: () => void,
) => {
  const { t } = useLokaliseTranslation('libraries');

  const {
    drawer: duplicateArticleDrawer,
    showDrawer: showDuplicateArticleDrawer,
  } = useDrawerV2(DuplicateArticleDrawer);

  const handleDuplicateArticle = () =>
    showDuplicateArticleDrawer({
      article,
      disableUnsavedWarning,
      resetUnsavedWarning,
    });

  const actions = [
    {
      when: true,
      action: {
        key: 'duplicate-article',
        title: t('article.duplicate.title'),
        onClick: handleDuplicateArticle,
        avatar: { Icon: IconCopy },
      },
    },
  ];

  return {
    actions,
    components: duplicateArticleDrawer,
  };
};
