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';
import { useTranslation } from 'react-i18next';

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

  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>{t('home.biometricRegistration.title')}</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="text-section">
            <div>
              {t('home.biometricRegistration.description').split('\n').map((line, index) => (
                <span key={index}>
                  {line}
                  {index === 0 && <br />}
                </span>
              ))}
            </div>
          </div>
        </div>
        <div className="bottomsheet-footer">
          <button
            className="btn-50 btn-darkgray flex-1"
            type="button"
            onClick={ () => onClickToClose() }
          >{t('home.biometricRegistration.later')}</button>
          <button
            className="btn-50 btn-blue flex-2"
            type="button"
            onClick={ () => onClickToRegister() }
          >{t('home.biometricRegistration.registerNow')}</button>
        </div>
      </motion.div>
    </>
  );
};
