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

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

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

  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>다운로드 방식을 선택하세요</h2>
            <button
              className="close-btn"
              type="button"
            >
              <img
                src={ IMAGE_ROOT + '/ico_close.svg' }
                alt="닫기"
                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="이미지"
                />
              </div>
              <span className="label-text">이미지 저장</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='메일'
                />
              </div>
              <span className="label-text">메일로 받기</span>
            </div>
          </div>
        </div>
      </motion.div>
    </>
  );
};
