import { BottomSheetMotionDuration, BottomSheetMotionVaiants } from '@/entities/common/model/constant';
import { IMAGE_ROOT } from '@/shared/constants/common';
import { checkGrant } from '@/shared/lib/check-grant';
import { showAlert } from '@/widgets/show-alert';
import { motion } from 'framer-motion';
import { useTranslation } from 'react-i18next';

export interface CashReceitPurposeUpdateBottomSheetProps {
  bottomSheetOn: boolean;
  setBottomSheetOn: (bottomSheetOn: boolean) => void;
  callPurposeUpdate: () => void;
};

const menuId = 32;
export const CashReceitPurposeUpdateBottomSheet = ({
  bottomSheetOn,
  setBottomSheetOn,
  callPurposeUpdate
}: CashReceitPurposeUpdateBottomSheetProps) => {
  const { t } = useTranslation();

  const onClickToClose = () => {
    setBottomSheetOn(false);
  };
  const onCliickToPurposeUpdate = () => {
    if(checkGrant(menuId, 'X')){
      callPurposeUpdate();
    }
    else{
      showAlert(t('common.nopermission'));
    }
  };

  return (
    <>
      { (bottomSheetOn) &&
        <div className="bg-dim"
          style={{ zIndex: 1020 }}
        ></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('transaction.bottomSheet.cashReceiptPurposeUpdate.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="bottom-section">
            <p>{ t('transaction.bottomSheet.cashReceiptPurposeUpdate.description') } </p>
            <ul className="list-style-circle">
              <li>{ t('transaction.bottomSheet.cashReceiptPurposeUpdate.expenseToIncome') }</li>
              <li>{ t('transaction.bottomSheet.cashReceiptPurposeUpdate.incomeToExpense') }</li>
            </ul>
          </div>
        </div>

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