import { Label as e } from "../../ui/label.js";
import { Textarea as t } from "../../ui/textarea.js";
import { buildTextValidationRules as n } from "./utils/text-validation-utils.js";
import { useFieldConfig as r } from "../hooks/useFieldConfig.js";
import { BaseFieldWrapper as i } from "./BaseFieldWrapper.js";
import "react";
import { jsx as a, jsxs as o } from "react/jsx-runtime";
import { Controller as s } from "react-hook-form";
//#region src/components/dynamic-form/fields/TextareaField.tsx
var c = ({ name: c, schema: l, ui: u, required: d, form: f, disabled: p, viewOnly: m }) => {
	let h = r(c, l, u, p), g = u, _ = g?.placeholder || l.placeholder || l.examples?.[0] || "", v = g?.rows || l.rows || 4, y = n(l, d);
	return m ? /* @__PURE__ */ o("div", {
		className: "mb-4 block",
		children: [/* @__PURE__ */ a(e, {
			className: "text-muted-foreground mb-1 block text-sm",
			children: h.fieldLabel
		}), /* @__PURE__ */ a(s, {
			name: c,
			control: f.control,
			defaultValue: h.defaultValue || "",
			render: ({ field: e }) => /* @__PURE__ */ a("div", {
				className: "text-sm whitespace-pre-wrap",
				children: e.value || "—"
			})
		})]
	}) : /* @__PURE__ */ a(s, {
		name: c,
		control: f.control,
		defaultValue: h.defaultValue || "",
		rules: y,
		render: ({ field: e }) => /* @__PURE__ */ a(i, {
			name: c,
			label: h.fieldLabel,
			required: d,
			error: h.error,
			helpText: h.helpText,
			description: h.description,
			children: /* @__PURE__ */ a(t, {
				...e,
				id: c,
				onChange: h.isReadOnly ? void 0 : e.onChange,
				rows: v,
				placeholder: _,
				disabled: h.isDisabled,
				readOnly: h.isReadOnly,
				maxLength: l.maxLength,
				className: h.error ? "border-destructive focus-visible:ring-destructive" : "",
				style: {
					minHeight: v ? `${v * 1.5}em` : void 0,
					resize: v ? "vertical" : "none"
				},
				...h.getAriaProps()
			})
		})
	});
};
//#endregion
export { c as TextareaField };
