import { Checkbox } from "@repo/shadcn-ui/components/checkbox"; import { Input } from "@repo/shadcn-ui/components/input"; import { Label } from "@repo/shadcn-ui/components/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@repo/shadcn-ui/components/select"; import { Textarea } from "@repo/shadcn-ui/components/textarea"; import type { UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import type { AccessField } from "./access-fields"; import type { AccessFormValues } from "./access-form-values"; type Option = { value: string; label: string }; export function AccessFieldControl({ field, id, form, value, options, disabled, onSelected, }: { field: AccessField; id: string; form: UseFormReturn; value: string | boolean | string[] | undefined; options: readonly Option[]; disabled: boolean; onSelected: (value: string) => void; }) { const { t } = useTranslation("access"); if (field.type === "boolean") { return (
form.setValue(field.key, checked === true)} />
); } if (field.type === "permissions") { return (
{t(field.key)} {options.map((option) => (
{ const values = Array.isArray(value) ? value : []; form.setValue( field.key, checked ? [...values, option.value] : values.filter((item) => item !== option.value) ); }} />
))} {!options.length &&

{t("noPermissions")}

}
); } return (
{field.type === "note" ? (