"use client"; import { clsx } from "clsx"; import { DateInput } from "~/components/ui/DateInput.js"; import { FieldType } from "@capakraken/shared"; import type { BlueprintFieldDefinition } from "@capakraken/shared"; interface Props { fieldDefs: BlueprintFieldDefinition[]; values: Record; onChange: (key: string, value: unknown) => void; errors?: Record; className?: string; } const INPUT_BASE = "w-full px-3 py-2 border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 transition-colors"; const INPUT_NORMAL = "border-gray-300 bg-white text-gray-900 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100"; const INPUT_ERROR = "border-red-400 bg-red-50 text-gray-900 dark:border-red-500 dark:text-gray-100"; function inputClass(hasError: boolean) { return clsx(INPUT_BASE, hasError ? INPUT_ERROR : INPUT_NORMAL); } interface FieldInputProps { fieldDef: BlueprintFieldDefinition; value: unknown; onChange: (key: string, value: unknown) => void; hasError: boolean; } function FieldInput({ fieldDef, value, onChange, hasError }: FieldInputProps) { const { key, type, placeholder, validation, options } = fieldDef; switch (type) { case FieldType.TEXT: return ( onChange(key, e.target.value)} className={inputClass(hasError)} /> ); case FieldType.TEXTAREA: return (