import { FC } from 'react';

import 'src/components/dashboard/chat/i18n';

import MenuItem from '@material-hu/mui/MenuItem';

import { Attachment } from 'src/types/attachments';
import { downloadUrl, getDownloadName } from 'src/utils/files';

import { useTranslation } from 'src/components/dashboard/chat/i18n';

export type DownloadImageOptionProps = {
  closeMenu: any;
  attachment: Attachment;
};

export const DownloadImageOption: FC<DownloadImageOptionProps> = props => {
  const { closeMenu, attachment } = props;

  const { t } = useTranslation();

  const handleDownload = e => {
    downloadUrl(attachment?.url, getDownloadName('humand_image_'));
    closeMenu(e);
  };

  return <MenuItem onClick={handleDownload}>{t('DOWNLOAD_IMAGE')}</MenuItem>;
};

export default DownloadImageOption;
