import moment from 'moment';
import { IMAGE_ROOT } from '@/shared/constants/common';
import { motion } from 'framer-motion';
import { useState } from 'react';
import { FilterSelect } from '@/shared/ui/filter/select';
import { FilterSelectInput } from '@/shared/ui/filter/select-input';
import { FilterDateOptions } from '@/entities/common/model/types';
import { FilterCalendar } from '@/shared/ui/filter/calendar';
import { FilterButtonGroups } from '@/shared/ui/filter/button-groups';
import { SmsPaymentFilterProps, SmsPaymentSearchCl, SmsCl } from '../../model/sms-payment/types';
import { useStore } from '@/shared/model/store';
import { FilterMotionDuration, FilterMotionStyle, FilterMotionVariants } from '@/entities/common/model/constant';
import { FilterSelectMid } from '@/shared/ui/filter/select-mid';
export const SmsPaymentFilter = ({
  filterOn,
  setFilterOn,
  mid,
  searchCl,
  searchValue,
  fromDate,
  toDate,
  smsCl,
  setMid,
  setSearchCl,
  setSearchValue,
  setFromDate,
  setToDate,
  setSmsCl
}: SmsPaymentFilterProps) => {

  const [filterMid, setFilterMid] = useState<string>(mid);
  const [filterSearchCl, setFilterSearchCl] = useState<SmsPaymentSearchCl>(searchCl);
  const [filterSearchValue, setFilterSearchValue] = useState<string>(searchValue);
  const [filterFromDate, setFilterFromDate] = useState<string>(moment(fromDate).format('YYYYMMDD'));
  const [filterToDate, setFilterToDate] = useState<string>(moment(toDate).format('YYYYMMDD'));
  const [filterSmsCl, setFilterSmsCl] = useState<SmsCl>(smsCl);

  const onClickToSetFilter = () => {
    setMid(filterMid);
    setSearchCl(filterSearchCl);
    setSearchValue(filterSearchValue);
    setFromDate(filterFromDate);
    setToDate(filterToDate);
    setSmsCl(filterSmsCl);
    onClickToClose();
  };

  let MidOptions = [
    { name: 'nictest00m', value: 'nictest00m' },
    { name: 'nictest002m', value: 'nictest002m' }
  ];

  let searchTypeOption = [
    { name: '주문자', value: SmsPaymentSearchCl.BUYER_NAME },
    { name: '수신번호', value: SmsPaymentSearchCl.RECEIVE_PHONE_NUMBER },
  ]

  let smsTypeOption = [
    { name: '전체', value: SmsCl.ALL },
    { name: '가상계좌\n요청', value: SmsCl.VACCOUNT_REQ },
    { name: '가상계좌\n요청+입금', value: SmsCl.VACCOUNT_REQ_DEPOSIT },
  ]

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

  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
                id="closeFullMenu"
                className="full-menu-close"
              >
                <img
                  src={IMAGE_ROOT + '/ico_close.svg'}
                  alt="닫기"
                  onClick={() => onClickToClose()}
                />
              </button>
            </div>
          </div>

          <div className="option-list pt-16 pb-86">
            <FilterSelectMid
              title='가맹점'
              selectSetter={setFilterMid}
              showType={'GID'}
            ></FilterSelectMid>

            <FilterSelectInput
              title='주문자,수신번호'
              selectValue={searchCl}
              selectSetter={setSearchCl}
              selectOptions={searchTypeOption}
              inputValue={searchValue}
              inputSetter={setSearchValue}
            ></FilterSelectInput>
            <FilterCalendar
              startDate={filterFromDate}
              endDate={filterToDate}
              setStartDate={setFilterFromDate}
              setEndDate={setFilterToDate}
            ></FilterCalendar>
            <FilterButtonGroups
              title='조회결과'
              activeValue={filterSmsCl}
              btnGroups={smsTypeOption}
              setter={setFilterSmsCl}
            ></FilterButtonGroups>
          </div>
          <div className="apply-row">
            <button
              className="btn-50 btn-blue flex-1"
              onClick={() => onClickToSetFilter()}
            >적용</button>
          </div>
        </div>
      </motion.div>
    </>
  );
};