import { FC } from 'react';

import { IconSend } from '@material-hu/icons/tabler';

import HuListItem from '@material-hu/components/design-system/List/components/ListItem';
import HuMenuItem from '@material-hu/components/design-system/Menu/components/MenuItem';
import { MenuItemProps } from '@material-hu/components/design-system/Menu/components/MenuItem/types';

import { useMoreMenu } from 'src/contexts/MoreMenuContext';
import { useLokaliseTranslation as useTranslation } from 'src/utils/i18n';

export type PublishNowMenuItemProps = Omit<MenuItemProps, 'id'> & {
  handlePublishPostNow: () => void;
};

const PublishNowMenuItem: FC<PublishNowMenuItemProps> = props => {
  const { handlePublishPostNow, ...menuProps } = props;
  const { t } = useTranslation('post');
  const { closeMenu } = useMoreMenu();

  const handlePublish = () => {
    closeMenu();
    handlePublishPostNow();
  };

  return (
    <HuMenuItem
      {...menuProps}
      onClick={handlePublish}
      sx={{ p: 0 }}
    >
      <HuListItem
        sx={{ p: 0 }}
        avatar={{ Icon: IconSend }}
        text={{ title: t('send_post_now') }}
      />
    </HuMenuItem>
  );
};

export default PublishNowMenuItem;
