"use client" import { useState } from "react" import { CheckIcon, ChevronsUpDownIcon } from "lucide-react" import type { FieldError as HookFormFieldError, UseFormReturn, } from "react-hook-form" import { Controller, type Control, type UseFormRegister } from "react-hook-form" import { OptionCombobox } from "@/components/option-combobox" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command" import { Field, FieldContent, FieldError, FieldLabel, } from "@/components/ui/field" import { Input } from "@/components/ui/input" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Switch } from "@/components/ui/switch" import { Textarea } from "@/components/ui/textarea" import { useI18n } from "@/i18n/provider" import { cn } from "@/lib/utils" import type { DashboardCrudFormField, DashboardCrudFormInputValue, DashboardCrudFormOption, } from "./dashboard-crud-utils" export function DashboardCrudFieldControl({ field, control, form, register, error, }: { field: DashboardCrudFormField control: Control> form: UseFormReturn< Record, undefined, Record > register: UseFormRegister> error?: HookFormFieldError }) { const inputId = `dashboard-crud-field-${field.name}` if (field.type === "section" || field.type === "group") { return (
{field.label}
{field.description ? (
{field.description}
) : null}
) } return ( {field.label} {field.type === "select" ? ( ( )} /> ) : field.type === "multiSelect" ? ( ( )} /> ) : field.type === "switch" ? ( ( )} /> ) : field.type === "checkbox" ? ( ( )} /> ) : field.type === "custom" && field.render ? ( ( <> {field.render?.({ name: field.name, label: field.label, value: controllerField.value, values: form.watch(), setValue: (name, value) => form.setValue(name, value, { shouldDirty: true, shouldValidate: true, }), })} )} /> ) : field.type === "textarea" ? (