import { BottomSheetMotionDuration, BottomSheetMotionVaiants } from '@/entities/common/model/constant';
import { IMAGE_ROOT } from '@/shared/constants/common';
import { motion } from 'framer-motion';
import { useTranslation } from 'react-i18next';

export interface DownloadTypeBottomSheetProps {
  bottomSheetOn: boolean;
  setBottomSheetOn: (bottomSheetOn: boolean) => void;
  onSelectType: (type: 'IMAGE' | 'EMAIL') => void;
}

export const DownloadTypeBottomSheet = ({
  bottomSheetOn,
  setBottomSheetOn,
  onSelectType
}: DownloadTypeBottomSheetProps) => {
  const { t } = useTranslation();

  const onClickToClose = () => {
    setBottomSheetOn(false);
  };

  const handleSelectType = (type: 'IMAGE' | 'EMAIL') => {
    onSelectType(type);
    setBottomSheetOn(false);
  };

  return (
    <>
      { (bottomSheetOn) &&
        <div className="bg-dim"></div>
      }
      <motion.div
        className="bottomsheet"
        initial="hidden"
        animate={ (bottomSheetOn)? 'visible': 'hidden' }
        variants={ BottomSheetMotionVaiants }
        transition={ BottomSheetMotionDuration }
      >
        <div className="bottomsheet-header">
          <div className="bottomsheet-title">
            <h2>{t('common.selectDownloadMethod')}</h2>
            <button
              className="close-btn"
              type="button"
            >
              <img
                src={ IMAGE_ROOT + '/ico_close.svg' }
                alt={t('common.close')}
                onClick={ () => onClickToClose() }
              />
            </button>
          </div>
        </div>

        <div className="bottomsheet-content">
          <div className="email-section">
            <div
              className="email-label mb-10"
              onClick={() => handleSelectType('IMAGE')}
              style={{ cursor: 'pointer' }}
            >
              <div className="mail-icon">
                <div className="mail-icon-bg"></div>
                <img
                  src={ IMAGE_ROOT + '/ico_pic.svg' }
                  alt={t('common.image')}
                />
              </div>
              <span className="label-text">{t('common.imageSave')}</span>
            </div>

            <div
              className="email-label"
              onClick={() => handleSelectType('EMAIL')}
              style={{ cursor: 'pointer' }}
            >
              <div className="mail-icon">
                <div className="mail-icon-bg"></div>
                <img
                  src={ IMAGE_ROOT + '/ico_email.svg' }
                  alt={t('common.mail')}
                />
              </div>
              <span className="label-text">{t('common.receiveByEmail')}</span>
            </div>
          </div>
        </div>
      </motion.div>
    </>
  );
};
