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

export const AuthRegister = ({
  setAuthRegisterOn,
  authRegisterOn,
}: AuthRegisterProps) => {
  const { registerBiometric, closeBiometricRegistrationPopup } = useAppBridge();

  const onClickToClose = () => {
    closeBiometricRegistrationPopup();
    setAuthRegisterOn(false);
  };
  const onClickToRegister = () => {
    registerBiometric();
    setAuthRegisterOn(false);
  };
  
  return (
    <>
      { (authRegisterOn) && 
        <div className="bg-dim"></div>
      }
      <motion.div 
        className="bottomsheet"
        initial="hidden"
        animate={ (authRegisterOn)? '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="text-section">
            <div>
              간편 인증 등록 한번으로,<br/>
              비밀번호 없이 편리하게 로그인하세요.
            </div>
          </div>
        </div>
        <div className="bottomsheet-footer">
          <button 
            className="btn-50 btn-darkgray flex-1" 
            type="button"
            onClick={ () => onClickToClose() }
          >다음에</button>
          <button 
            className="btn-50 btn-blue flex-2" 
            type="button"
            onClick={ () => onClickToRegister() }
          >지금 등록하기</button>
        </div>
      </motion.div>
    </>
  );
};
