import { motion } from 'framer-motion';
import { IMAGE_ROOT } from '@/shared/constants/common';
import { VatReturnReceiptType, VatReturnTargetType } from '../../model/types';
import { FilterMotionDuration, FilterMotionStyle, FilterMotionVariants } from '@/entities/common/model/constant';
import { FilterSelect } from '@/shared/ui/filter/select';
import { useState } from 'react';
import { FilterButtonGroups } from '@/shared/ui/filter/button-groups';
import { VatReturnReceiptTypeBtnGroup, VatReturnTargetTypeBtnGroup } from '../../model/contant';
import { FilterCalendarMonth } from '@/shared/ui/filter/calendar-month';

export interface ListFilterProps {
  filterOn: boolean;
  setFilterOn: (filterOn: boolean) => void;
  mid: string;
  startDate: string;
  endDate: string;
  receiptType: VatReturnReceiptType;
  targetType: VatReturnTargetType;
  setMid: (mid: string) => void;
  setStartDate: (date: string) => void;
  setEndDate: (date: string) => void;
  setReceiptType: (receiptType: VatReturnReceiptType) => void;
  setTargetType: (targetType: VatReturnTargetType) => void;
};

export const ListFilter = ({
  filterOn,
  setFilterOn,
  mid,
  startDate,
  endDate,
  receiptType,
  targetType,
  setMid,
  setStartDate,
  setEndDate,
  setReceiptType,
  setTargetType
}: ListFilterProps) => {

  const [filterMid, setFilterMid] = useState<string>(mid);
  const [filterStartDate, setFilterStartDate] = useState<string>(startDate);
  const [filterEndDate, setFilterEndDate] = useState<string>(endDate);
  const [filterReceiptType, setFIlterReceiptType] = useState<VatReturnReceiptType>(receiptType);
  const [filterTargetType, setFilterTargetType] = useState<VatReturnTargetType>(targetType);
  
  const onClickToClose = () => {
    setFilterOn(false);
  };

   const onClickToSetFilter = () => {
    setMid(filterMid);
    setStartDate(filterStartDate);
    setEndDate(filterEndDate);
    setReceiptType(filterReceiptType);
    setTargetType(filterTargetType);
    onClickToClose();
  };

  let MidOptions = [
    {name: 'nictest001m', value: 'nictest001m'}
  ];
  
  return (
    <>
      <motion.div 
        className="full-menu-modal" 
        initial="hidden"
        animate={ (filterOn)? 'visible': 'hidden' }
        variants={ FilterMotionVariants }
        transition={ FilterMotionDuration }
        style={ FilterMotionStyle }
      >
        <div className="full-menu-container">
          <div className="full-menu-header">
            <div className="full-menu-title center">필터</div>
            <div className="full-menu-actions">
              <button 
                className="full-menu-close"
                onClick={ () => onClickToClose() }
              >
                <img 
                  src={ IMAGE_ROOT + '/ico_close.svg' }
                  alt="닫기"
                />
              </button>
            </div>
          </div>
    
          <div className="option-list pt-16">
            <FilterSelect
              title='가맹점'
              selectValue={ filterMid }
              selectSetter={ setFilterMid }
              selectOptions={ MidOptions }
            ></FilterSelect>
            <FilterCalendarMonth
              title='발행월'
              startMonth={ filterStartDate }
              endMonth={ filterEndDate }
              setStartMonth={ setFilterStartDate }
              setEndMonth={ setFilterEndDate }
            ></FilterCalendarMonth>
            <FilterButtonGroups
              title='영수구분'
              activeValue={ filterReceiptType }
              btnGroups={ VatReturnReceiptTypeBtnGroup }
              setter={ setFIlterReceiptType }
            ></FilterButtonGroups>
            <FilterButtonGroups
              title='발행대상'
              activeValue={ filterTargetType }
              btnGroups={ VatReturnTargetTypeBtnGroup }
              setter={ setFilterTargetType }
            ></FilterButtonGroups>
          </div>
          <div className="apply-row">
            <button 
              className="btn-50 btn-blue flex-1"
              onClick={ onClickToSetFilter }
            >적용</button>
          </div>
        </div>
      </motion.div>
    </>
  );
};