import type { DateInputProps } from "$/types/InputTypes";
import clsx from "clsx";
import moment from "moment";


export default function DateInput({
	id,
	className,
	defaultValue,
	value,
	onChange
}: DateInputProps){
	return (
		<input
			type="date"
			id={id}
			className={clsx(
				"border rounded-lg px-2 py-1",
				className
			)}
			defaultValue={defaultValue ? moment(defaultValue).format("YYYY-MM-DD") : undefined}
			value={value ? moment(value).format("YYYY-MM-DD") : undefined}
			onChange={(e) => onChange?.(new Date(moment(e.target.value, "YYYY-MM-DD").toDate()))}
		/>
	);
}
