import moment from 'moment';
import { useEffect } from 'react';
import { IMAGE_ROOT } from '@/shared/constants/common';
import { motion } from 'framer-motion';
import { ChangeEvent, 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 { FilterMotionDuration, FilterMotionStyle, FilterMotionVariants } from '@/entities/common/model/constant';
import { useStore } from '@/shared/model/store';
import { LinkPaymentProcessStatus, LinkPaymentSearchCl, LinkPaymentSendMethod, LinkPaymentSendStatus, LinkPaymentWaitFilterProps } from '@/entities/additional-service/model/link-pay/types';
import { FilterSelectMid } from '@/shared/ui/filter/select-mid';

export const LinkPaymentWaitSendFilter = ({
	filterOn,
	setFilterOn,
	mid,
	searchCl,
	searchKeyword,
	startDate,
	endDate,
	sendMethod,
	processStatus,
	setMid,
	setSearchType,
	setSearchKeyword,
	setStartDate,
	setEndDate,
	setSendMethod,
	setProcessStatus
}: LinkPaymentWaitFilterProps) => {


	const [filterMid, setFilterMid] = useState<string>(mid);
	const [filterSearchType, setFilterSearchType] = useState<LinkPaymentSearchCl>(searchCl);
	const [filterSearchKeyword, setFilterSearchKeyword] = useState<string>(searchKeyword);
	const [filterStartDate, setFilterStartDate] = useState<string>(startDate);
	const [filterEndDate, setFilterEndDate] = useState<string>(endDate);
	const [filterSendMethod, setFilterSendMethod] = useState<LinkPaymentSendMethod>(sendMethod)
	const [filterProcessStatus, setFilterProcessStatus] = useState<LinkPaymentProcessStatus>(processStatus);

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

	const onClickToSetFilter = () => {
		setMid(filterMid);
		setSearchType(filterSearchType);
		setSearchKeyword(filterSearchKeyword);
		setStartDate(filterStartDate);
		setEndDate(filterEndDate);
		setSendMethod(filterSendMethod);
		setProcessStatus(filterProcessStatus);
		onClickToClose();
	};

	let searchTypeOption = [
		{ name: '휴대폰번호', value: LinkPaymentSearchCl.PHONE },
		{ name: '이메일', value: LinkPaymentSearchCl.EMAIL },
	];

	let sendMethodOption = [
		{ name: '전체', value: LinkPaymentSendMethod.ALL },
		{ name: 'SMS', value: LinkPaymentSendMethod.SMS },
		{ name: '이메일', value: LinkPaymentSendMethod.EMAIL },
		{ name: '카카오', value: LinkPaymentSendMethod.KAKAO },
	];

	let processStatusOption = [
		{ name: '전체', value: LinkPaymentProcessStatus.ALL },
		{ name: '발송요청', value: LinkPaymentProcessStatus.SEND_REQUEST },
		{ name: '발송취소', value: LinkPaymentProcessStatus.SEND_CANCEL },
	];

	useEffect(() => {
		setFilterProcessStatus(processStatus);
	}, [processStatus]);
	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={filterSearchType}
							selectSetter={setFilterSearchType}
							selectOptions={searchTypeOption}
							inputValue={filterSearchKeyword}
							inputSetter={setFilterSearchKeyword}
						></FilterSelectInput>
						<FilterCalendar
							startDate={filterStartDate}
							endDate={filterEndDate}
							setStartDate={setFilterStartDate}
							setEndDate={setFilterEndDate}
						></FilterCalendar>

						<FilterButtonGroups
							title='발송수단'
							activeValue={filterSendMethod}
							btnGroups={sendMethodOption}
							setter={setFilterSendMethod}
						></FilterButtonGroups>

						<FilterButtonGroups
							title='진행상태'
							activeValue={filterProcessStatus}
							btnGroups={processStatusOption}
							setter={setFilterProcessStatus}
						></FilterButtonGroups>
					</div>
					<div className="apply-row">
						<button
							className="btn-50 btn-blue flex-1"
							onClick={() => onClickToSetFilter()}
						>적용</button>
					</div>
				</div>
			</motion.div>
		</>
	)
}