import moment from 'moment';
import { useTranslation } from 'react-i18next';
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';
import { FullMenuClose } from '@/entities/common/ui/full-menu-close';
export const SmsPaymentFilter = ({
  filterOn,
  setFilterOn,
  mid,
  searchCl,
  searchValue,
  fromDate,
  toDate,
  smsCl,
  setMid,
  setSearchCl,
  setSearchValue,
  setFromDate,
  setToDate,
  setSmsCl
}: SmsPaymentFilterProps) => {
  const { t } = useTranslation();

  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: t('transaction.fields.buyerName'), value: SmsPaymentSearchCl.BUYER_NAME },
    { name: t('additionalService.sms.receivePhoneNumber'), value: SmsPaymentSearchCl.RECEIVE_PHONE_NUMBER },
  ]

  let smsTypeOption = [
    { name: t('additionalService.sms.all'), value: SmsCl.ALL },
    { name: t('additionalService.sms.virtualAccountReqShort'), value: SmsCl.VACCOUNT_REQ },
    { name: t('additionalService.sms.virtualAccountReqDepositShort'), 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">{t('filter.filter')}</div>
            <div className="full-menu-actions">
              <FullMenuClose
                addClass='full-menu-close'
                onClickToCallback={ onClickToClose }
              ></FullMenuClose>
            </div>
          </div>

          <div className="option-list pt-16 pb-86">
            <FilterSelectMid
              title={t('filter.merchant')}
              selectSetter={setFilterMid}
              showType={'GID'}
            ></FilterSelectMid>

            <FilterSelectInput
              title={t('additionalService.sms.buyerReceiveNumber')}
              selectValue={searchCl}
              selectSetter={setSearchCl}
              selectOptions={searchTypeOption}
              inputValue={searchValue}
              inputSetter={setSearchValue}
            ></FilterSelectInput>
            <FilterCalendar
              startDate={filterFromDate}
              endDate={filterToDate}
              setStartDate={setFilterFromDate}
              setEndDate={setFilterToDate}
            ></FilterCalendar>
            <FilterButtonGroups
              title={t('additionalService.sms.queryResult')}
              activeValue={filterSmsCl}
              btnGroups={smsTypeOption}
              setter={setFilterSmsCl}
            ></FilterButtonGroups>
          </div>
          <div className="apply-row">
            <button
              className="btn-50 btn-blue flex-1"
              onClick={() => onClickToSetFilter()}
            >{t('filter.apply')}</button>
          </div>
        </div>
      </motion.div>
    </>
  );
};