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 { FilterCalendar } from '@/shared/ui/filter/calendar';
import { FilterButtonGroups } from '@/shared/ui/filter/button-groups';
import { AccountHolderAuthFilterProps, AuthAndTransferStatus } from '@/entities/additional-service/model/types';
import { authStatusBtnGroup } from '@/entities/additional-service/model/account-holder-auth/constant';
import { FilterMotionDuration, FilterMotionStyle, FilterMotionVariants } from '@/entities/common/model/constant';

export const AccountHolderAuthFilter = ({
	filterOn,
	setFilterOn,
	mid,
	startDate,
	endDate,
	authStatus,
	setMid,
	setStartDate,
	setEndDate,
	setAuthStatus
}: AccountHolderAuthFilterProps) => {

	const [filterMid, setFilterMid] = useState<string>(mid);
	const [filterStartDate, setFilterStartDate] = useState<string>(moment(startDate).format('YYYY.MM.DD'));
	const [filterEndDate, setFilterEndDate] = useState<string>(moment(endDate).format('YYYY.MM.DD'));
	const [filterAuthStatus, setFilterAuthStatus] = useState<AuthAndTransferStatus>(authStatus);

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

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

	const onClickToSetFilter = () => {
		setMid(filterMid);
		setStartDate(filterStartDate);
		setEndDate(filterEndDate);
		setAuthStatus(filterAuthStatus);
		onClickToClose();
	};

	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>

						<FilterCalendar
							startDate={filterStartDate}
							endDate={filterEndDate}
							setStartDate={setFilterStartDate}
							setEndDate={setFilterEndDate}
						></FilterCalendar>

						<FilterButtonGroups
							title='지급상태'
							activeValue={filterAuthStatus}
							btnGroups={authStatusBtnGroup}
							setter={setFilterAuthStatus}
						></FilterButtonGroups>
					</div>
					<div className="apply-row">
						<button
							className="btn-50 btn-blue flex-1"
							onClick={() => onClickToSetFilter()}
						>적용</button>
					</div>
				</div>
			</motion.div>
		</>
	);
}
