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 {
	ProcessResult
} from "../../../model/types";
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 { LinkPaymentHistoryFilterProps, LinkPaymentPaymentStatus, LinkPaymentSearchCl, LinkPaymentSendMethod, LinkPaymentSendStatus } from '@/entities/additional-service/model/link-pay/types';
import { FilterSelectMid } from '@/shared/ui/filter/select-mid';

export const LinkPaymentHistoryFilter = ({
	filterOn,
	setFilterOn,
	mid,
	searchCl,
	searchValue,
	fromDate,
	toDate,
	paymentStatus,
	sendStatus,
	sendMethod,
	setMid,
	setSearchType,
	setSearchKeyword,
	setStartDate,
	setEndDate,
	setPaymentStatus,
	setSendStatus,
	setSendMethod
}: LinkPaymentHistoryFilterProps) => {


	const [filterMid, setFilterMid] = useState<string>(mid);
	const [filterSearchCl, setFilterSearchCl] = useState<LinkPaymentSearchCl>(searchCl);
	const [filterSearchValue, setFilterSearchValue] = useState<string>(searchValue);
	const [filterStartDate, setFilterStartDate] = useState<string>(fromDate);
	const [filterEndDate, setFilterEndDate] = useState<string>(toDate);
	const [filterTransactionStatus, setFilterTransactionStatus] = useState<LinkPaymentPaymentStatus>(paymentStatus)
	const [filterSendStatus, setFilterSendStatus] = useState<LinkPaymentSendStatus>(sendStatus);
	const [filterSendMethod, setFilterSendMethod] = useState<LinkPaymentSendMethod>(sendMethod);

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

	let transactionStatusOption = [
		{ name: '전체', value: LinkPaymentPaymentStatus.ALL },
		{ name: '미완료/활성화', value: LinkPaymentPaymentStatus.ACTIVATE },
		{ name: '입금요청', value: LinkPaymentPaymentStatus.DEPOSIT_REQUEST },
		{ name: '결제완료', value: LinkPaymentPaymentStatus.PAYMENT_COMPLETE },
		{ name: '결제실패', value: LinkPaymentPaymentStatus.PAYMENT_FAIL },
		{ name: '결제중단/비활성화', value: LinkPaymentPaymentStatus.INACTIVE },
	];

	let processResultOption = [
		{ name: '전체', value: LinkPaymentSendStatus.ALL },
		{ name: '성공', value: LinkPaymentSendStatus.SUCCESS },
		{ name: '실패', value: LinkPaymentSendStatus.FAIL },
	];

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

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

	const onClickToSetFilter = () => {
		setMid(filterMid);
		setSearchType(filterSearchCl);
		setSearchKeyword(filterSearchValue);
		setStartDate(filterStartDate);
		setEndDate(filterEndDate);
		setPaymentStatus(filterTransactionStatus);
		setSendStatus(filterSendStatus);
		setSendMethod(filterSendMethod);
		onClickToClose();
	};

	useEffect(() => {
		setFilterTransactionStatus(paymentStatus);
	}, [paymentStatus]);
	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">
						<FilterSelectMid
							title='가맹점'
							selectSetter={setFilterMid}
							showType={'GID'}
						></FilterSelectMid>

						<FilterSelectInput
							title='휴대폰번호/이메일'
							selectValue={filterSearchCl}
							selectSetter={setFilterSearchCl}
							selectOptions={searchTypeOption}
							inputValue={searchValue}
							inputSetter={setFilterSearchValue}
						></FilterSelectInput>
						<FilterCalendar
							startDate={filterStartDate}
							endDate={filterEndDate}
							setStartDate={setFilterStartDate}
							setEndDate={setFilterEndDate}
						></FilterCalendar>

						<FilterButtonGroups
							title='거래상태'
							activeValue={filterTransactionStatus}
							btnGroups={transactionStatusOption}
							setter={setFilterTransactionStatus}
						></FilterButtonGroups>

						<FilterButtonGroups
							title='전송결과'
							activeValue={filterSendStatus}
							btnGroups={processResultOption}
							setter={setFilterSendStatus}
						></FilterButtonGroups>

						<FilterButtonGroups
							title='발송수단'
							activeValue={filterSendMethod}
							btnGroups={sendMethodOption}
							setter={setFilterSendMethod}
						></FilterButtonGroups>
					</div>
					<div className="apply-row">
						<button
							className="btn-50 btn-blue flex-1"
							onClick={() => onClickToSetFilter()}
						>적용</button>
					</div>
				</div>
			</motion.div>
		</>
	)
}