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


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