import moment from 'moment';
import { IMAGE_ROOT } from '@/shared/constants/common';
import { motion } from 'framer-motion';
import { useState } from 'react';
import {
	AccountHolderSearchType,
	AccountHolderSearchFilterProps,
	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';

export const AccountHolderSearchFilter = ({
	filterOn,
	setFilterOn,
	mid,
	searchType,
	searchKeyword,
	startDate,
	endDate,
	bank,
	processResult,
	setMid,
	setSearchType,
	setSearchKeyword,
	setStartDate,
	setEndDate,
	setBank,
	setProcessResult
}: AccountHolderSearchFilterProps) => {

	const [filterMid, setFilterMid] = useState<string>(mid);
	const [filterSearchType, setFilterSearchType] = useState<AccountHolderSearchType>(searchType);
	const [filterSearchKeyword, setFilterSearchKeyword] = useState<string>(searchKeyword);
	const [filterStartDate, setFilterStartDate] = useState<string>(moment(startDate).format('YYYY.MM.DD'));
	const [filterEndDate, setFilterEndDate] = useState<string>(moment(endDate).format('YYYY.MM.DD'));
	const [filterBank, setFilterBank] = useState<string>(bank)
	const [filterProcessResult, setFilterProcessResult] = useState<ProcessResult>(processResult);

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

	const setNewDate = (newDate: any) => {
		console.log(newDate)
	};

	const onClickToSetFilter = () => {
		setMid(filterMid);
		setSearchType(filterSearchType);
		setSearchKeyword(filterSearchKeyword);
		setStartDate(filterStartDate);
		setEndDate(filterEndDate);
		setBank(filterBank);
		setProcessResult(filterProcessResult);
		onClickToClose();
	};

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

	let bankOptions = [
		{ name: '우리은행', value: '우리은행' },
		{ name: '토스뱅킹', value: '토스뱅킹' }
	];

	let searchTypeOption = [
		{ name: '예금주', value: AccountHolderSearchType.ACCOUNT_NAME },
		{ name: '계좌번호', value: AccountHolderSearchType.ACCOUNT_NO },
	];

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

	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">
						<FilterSelect
							title='가맹점'
							selectValue={mid}
							selectSetter={setMid}
							selectOptions={MidOptions}
						></FilterSelect>

						<FilterSelectInput
							title='예금주/계좌번호'
							selectValue={searchType}
							selectSetter={setSearchType}
							selectOptions={searchTypeOption}
							inputValue={searchKeyword}
							inputSetter={setSearchKeyword}
						></FilterSelectInput>
						<FilterCalendar
							startDate={filterStartDate}
							endDate={filterEndDate}
							setStartDate={setFilterStartDate}
							setEndDate={setFilterEndDate}
						></FilterCalendar>

						<FilterSelect
							title='은행'
							selectValue={bank}
							selectSetter={setBank}
							selectOptions={bankOptions}
						></FilterSelect>

						<FilterButtonGroups
							title='조회결과'
							activeValue={filterProcessResult}
							btnGroups={processResultBtnGroup}
							setter={setFilterProcessResult}
						></FilterButtonGroups>
					</div>
					<div className="apply-row">
						<button
							className="btn-50 btn-blue flex-1"
							onClick={() => onClickToSetFilter()}
						>적용</button>
					</div>
				</div>
			</motion.div>
		</>
	);
}