import { Select as e, SelectContent as t, SelectItem as n, SelectTrigger as r, SelectValue as i } from "../../ui/select.js";
import { useFieldConfig as a } from "../hooks/useFieldConfig.js";
import { BaseFieldWrapper as o } from "./BaseFieldWrapper.js";
import "react";
import { jsx as s, jsxs as c } from "react/jsx-runtime";
import { Controller as l } from "react-hook-form";
//#region src/components/dynamic-form/fields/SelectField.tsx
var u = ({ name: u, schema: d, ui: f, required: p, form: m, disabled: h }) => {
	let g = a(u, d, f, h), _ = f, v = _?.enumOptions ?? d.enumOptions, y = v && v.length > 0 ? v : d.enum || [], b = y.map((e) => typeof e == "string" || typeof e == "number" ? e : e.label), x = y.map((e) => typeof e == "string" || typeof e == "number" ? e : e.value), S = _?.placeholder || d.placeholder || `Select ${g.fieldLabel}`;
	return /* @__PURE__ */ s(l, {
		name: u,
		control: m.control,
		defaultValue: g.defaultValue || "",
		rules: { required: p ? "This field is required" : void 0 },
		render: ({ field: a }) => /* @__PURE__ */ s(o, {
			name: u,
			label: g.fieldLabel,
			required: p,
			error: g.error,
			helpText: g.helpText,
			description: g.description,
			children: /* @__PURE__ */ c(e, {
				value: String(a.value ?? ""),
				onValueChange: g.isReadOnly ? void 0 : (e) => a.onChange(e),
				disabled: g.isDisabled,
				required: p,
				children: [/* @__PURE__ */ s(r, {
					id: u,
					className: g.error ? "border-destructive" : "",
					...g.getAriaProps(),
					children: /* @__PURE__ */ s(i, { placeholder: S })
				}), /* @__PURE__ */ s(t, { children: x.map((e, t) => /* @__PURE__ */ s(n, {
					value: e.toString(),
					disabled: g.isDisabled,
					children: b[t]?.toString() || e.toString()
				}, `${e}-${t}`)) })]
			})
		})
	});
};
//#endregion
export { u as SelectField };
