"use client"; import * as React from "react"; import { cn } from "@/lib/utils"; import { formatMoneyGrouped, parseMoneyInput, toRialInteger } from "@/lib/utils"; export function Select({ className, children, ...props }: React.SelectHTMLAttributes) { return ( ); } export function FormField({ label, error, hint, children, className, }: { label?: string; error?: string; hint?: string; children: React.ReactNode; className?: string; }) { return (
{label ? : null} {children} {hint && !error ?

{hint}

: null} {error ?

{error}

: null}
); } export function Checkbox({ label, className, ...props }: React.InputHTMLAttributes & { label?: string }) { return ( ); } /** * Money field with live thousand separators. * RHF value stays as plain integer Rial digits (e.g. "1500000"); display shows "1,500,000". * No decimal places — Iranian Rial. */ export const MoneyInput = React.forwardRef< HTMLInputElement, Omit, "type"> >(function MoneyInput({ className, value, defaultValue, onChange, onBlur, ...props }, ref) { const isControlled = value !== undefined; const [inner, setInner] = React.useState(() => toRialInteger(defaultValue != null ? String(defaultValue) : "") ); const raw = isControlled ? toRialInteger(value == null ? "" : String(value)) : inner; const display = formatMoneyGrouped(raw); return ( { // Keep typing fluid; strip non-digits / separators, then integerize. const parsed = toRialInteger(parseMoneyInput(e.target.value)); if (!isControlled) setInner(parsed); // Clone event target value so RHF watch/Controller always sees digits (not display commas). const next = { ...e, target: { ...e.target, value: parsed, name: (props.name as string) || e.target.name }, currentTarget: { ...e.currentTarget, value: parsed, name: (props.name as string) || e.currentTarget.name, }, } as typeof e; onChange?.(next); }} onBlur={(e) => { const parsed = toRialInteger(parseMoneyInput(e.target.value)); if (!isControlled) setInner(parsed); const next = { ...e, target: { ...e.target, value: parsed, name: (props.name as string) || e.target.name }, currentTarget: { ...e.currentTarget, value: parsed, name: (props.name as string) || e.currentTarget.name, }, } as typeof e; onBlur?.(next); }} /> ); });