import { Label } from "../../ui/label.js";
import { Textarea } from "../../ui/textarea.js";
import { buildTextValidationRules } from "./utils/text-validation-utils.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 TextareaField = (d) => {
	let f = c(25), { name: p, schema: m, ui: h, required: g, form: _, disabled: v, viewOnly: y } = d, b = useFieldConfig(p, m, h, v), x = m.placeholder || m.examples?.[0] || "", S = m.rows || 4, C;
	f[0] !== g || f[1] !== m ? (C = buildTextValidationRules(m, g), f[0] = g, f[1] = m, f[2] = C) : C = f[2];
	let w = C;
	if (y) {
		let o;
		f[3] === b.fieldLabel ? o = f[4] : (o = /* @__PURE__ */ jsx(Label, {
			className: "text-muted-foreground mb-1 block text-sm",
			children: b.fieldLabel
		}), f[3] = b.fieldLabel, f[4] = o);
		let s = b.defaultValue || "", l;
		f[5] !== _.control || f[6] !== p || f[7] !== s ? (l = /* @__PURE__ */ jsx(Controller, {
			name: p,
			control: _.control,
			defaultValue: s,
			render: _temp
		}), f[5] = _.control, f[6] = p, f[7] = s, f[8] = l) : l = f[8];
		let u;
		return f[9] !== o || f[10] !== l ? (u = /* @__PURE__ */ jsxs("div", {
			className: "mt-4 mb-8 block",
			children: [o, l]
		}), f[9] = o, f[10] = l, f[11] = u) : u = f[11], u;
	}
	let T = b.defaultValue || "", E;
	f[12] !== b || f[13] !== p || f[14] !== x || f[15] !== g || f[16] !== S || f[17] !== m.maxLength ? (E = (r) => {
		let { field: s } = r;
		return /* @__PURE__ */ jsx(BaseFieldWrapper, {
			name: p,
			label: b.fieldLabel,
			required: g,
			error: b.error,
			helpText: b.helpText,
			description: b.description,
			children: /* @__PURE__ */ jsx(Textarea, {
				...s,
				id: p,
				onChange: b.isReadOnly ? void 0 : s.onChange,
				rows: S,
				placeholder: x,
				disabled: b.isDisabled,
				readOnly: b.isReadOnly,
				maxLength: m.maxLength,
				className: b.error ? "border-destructive focus-visible:ring-destructive" : "",
				style: {
					minHeight: S ? `${S * 1.5}em` : void 0,
					resize: S ? "vertical" : "none"
				},
				...b.getAriaProps()
			})
		});
	}, f[12] = b, f[13] = p, f[14] = x, f[15] = g, f[16] = S, f[17] = m.maxLength, f[18] = E) : E = f[18];
	let D;
	return f[19] !== _.control || f[20] !== p || f[21] !== T || f[22] !== E || f[23] !== w ? (D = /* @__PURE__ */ jsx(Controller, {
		name: p,
		control: _.control,
		defaultValue: T,
		rules: w,
		render: E
	}), f[19] = _.control, f[20] = p, f[21] = T, f[22] = E, f[23] = w, f[24] = D) : D = f[24], D;
};
function _temp(r) {
	let { field: o } = r;
	return /* @__PURE__ */ jsx("div", {
		className: "text-sm whitespace-pre-wrap",
		children: o.value || "—"
	});
}
export { TextareaField };
