import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/select.js";
import { useFieldConfig } from "../hooks/useFieldConfig.js";
import { BaseFieldWrapper } from "./BaseFieldWrapper.js";
import { c } from "react/compiler-runtime";
import React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { Controller } from "react-hook-form";
const SelectField = (m) => {
	let h = c(22), { name: g, schema: _, ui: v, required: y, form: b, disabled: x } = m, S = useFieldConfig(g, _, v, x), C;
	h[0] !== _.enum || h[1] !== _.enumOptions ? (C = _.enumOptions && _.enumOptions.length > 0 ? _.enumOptions : _.enum || [], h[0] = _.enum, h[1] = _.enumOptions, h[2] = C) : C = h[2];
	let w = C, T;
	h[3] === w ? T = h[4] : (T = w.map(_temp), h[3] = w, h[4] = T);
	let E = T, D;
	h[5] === w ? D = h[6] : (D = w.map(_temp2), h[5] = w, h[6] = D);
	let O = D, k = _.placeholder || `Select ${S.fieldLabel}`, A = S.defaultValue || "", j = y ? "This field is required" : void 0, M;
	h[7] === j ? M = h[8] : (M = { required: j }, h[7] = j, h[8] = M);
	let N;
	h[9] !== S || h[10] !== E || h[11] !== O || h[12] !== g || h[13] !== k || h[14] !== y ? (N = (f) => {
		let { field: p } = f;
		return /* @__PURE__ */ jsx(BaseFieldWrapper, {
			name: g,
			label: S.fieldLabel,
			required: y,
			error: S.error,
			helpText: S.helpText,
			description: S.description,
			children: /* @__PURE__ */ jsxs(Select, {
				value: String(p.value ?? ""),
				onValueChange: S.isReadOnly ? void 0 : (t) => p.onChange(t),
				disabled: S.isDisabled,
				required: y,
				children: [/* @__PURE__ */ jsx(SelectTrigger, {
					id: g,
					className: S.error ? "border-destructive" : "",
					...S.getAriaProps(),
					children: /* @__PURE__ */ jsx(SelectValue, { placeholder: k })
				}), /* @__PURE__ */ jsx(SelectContent, { children: O.map((t, d) => /* @__PURE__ */ jsx(SelectItem, {
					value: t.toString(),
					disabled: S.isDisabled,
					children: E[d]?.toString() || t.toString()
				}, `${t}-${d}`)) })]
			})
		});
	}, h[9] = S, h[10] = E, h[11] = O, h[12] = g, h[13] = k, h[14] = y, h[15] = N) : N = h[15];
	let P;
	return h[16] !== b.control || h[17] !== g || h[18] !== A || h[19] !== M || h[20] !== N ? (P = /* @__PURE__ */ jsx(Controller, {
		name: g,
		control: b.control,
		defaultValue: A,
		rules: M,
		render: N
	}), h[16] = b.control, h[17] = g, h[18] = A, h[19] = M, h[20] = N, h[21] = P) : P = h[21], P;
};
function _temp(t) {
	return typeof t == "string" || typeof t == "number" ? t : t.label;
}
function _temp2(t) {
	return typeof t == "string" || typeof t == "number" ? t : t.value;
}
export { SelectField };
