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

export interface CreditCardListBottomSheetProps {
  creditCardListBottomSheetOn: boolean;
  setCreditCardListBottomSheetOn: (creditCardListBottomSheetOn: boolean) => void;
};

export const CreditCardListBottomSheet = ({
  creditCardListBottomSheetOn,
  setCreditCardListBottomSheetOn
}: CreditCardListBottomSheetProps) => {
  const { t } = useTranslation();
  const cardList = useStore.getState().CommonStore.creditCardList;

  const [selectedCard, setSelectedCard] = useState<string>(cardList[0].desc1);

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

  return (
    <>
      { creditCardListBottomSheetOn &&
      <div className="bg-dim"></div>
      }
      <motion.div 
        className="bottomsheet"
        initial="hidden"
        animate={ (creditCardListBottomSheetOn)? 'visible': 'hidden' }
        variants={ BottomSheetMotionVaiants }
        transition={ BottomSheetMotionDuration }
      >
        <div className="bottomsheet-header">
          <div className="bottomsheet-title">
            <h2>{t('payment.cardCompany')}</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="card-list">
            {
              cardList.map((value, index) => (
                <div className={ `card-option ${(value.desc1 === selectedCard)? 'selected': ''}` }>
                  <span className="name">{ value.desc1 }</span>
                  <i className="check"></i>
                </div>
              ))
            }
          </div>
        </div>

        <div className="bottomsheet-footer">
          <button
            className="btn-50 btn-blue flex-1"
            type="button"
          >{t('common.confirm')}</button>
        </div>
      </motion.div>
    </>
  );
};