import React, { useRef } from 'react'; import { CalendarDaysIcon, XMarkIcon } from '@heroicons/react/24/outline'; import { formatDate } from '../../lib/utils'; interface Props { value: string; onChange: (v: string) => void; placeholder?: string; min?: string; max?: string; style?: React.CSSProperties; className?: string; } export default function PersianDateInput({ value, onChange, placeholder = 'انتخاب تاریخ', min, max, style, className }: Props) { const hiddenRef = useRef(null); const open = () => { const el = hiddenRef.current; if (!el) return; if (typeof el.showPicker === 'function') { try { el.showPicker(); } catch { el.focus(); } } else { el.focus(); } }; return (
{/* visible text layer */}
{value ? formatDate(value) : placeholder} {value && ( { e.stopPropagation(); onChange(''); }} style={{ display: 'flex', alignItems: 'center', cursor: 'pointer', color: 'var(--text-3)' }} > )}
{/* hidden native input — opens picker on click */} onChange(e.target.value)} style={{ position: 'absolute', opacity: 0, pointerEvents: 'none', width: 1, height: 1, top: 0, left: 0, }} tabIndex={-1} />
); }