import { Input as e } from "../../ui/input.js";
import { Label as t } from "../../ui/label.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/InputField.tsx
var c = (e) => {
	if (e.format) switch (e.format) {
		case "email": return "email";
		case "url": return "url";
		case "date": return "date";
		case "time": return "time";
		case "datetime": return "datetime-local";
		case "phone": return "tel";
		case "password": return "password";
	}
	switch (e.type) {
		case "integer":
		case "number": return "number";
		default: return "text";
	}
}, l = (e) => e.type === "number" || e.type === "integer", u = ({ name: u, schema: d, ui: f, required: p, form: m, disabled: h, viewOnly: g }) => {
	let _ = r(u, d, f, h), v = c(d), y = f?.placeholder || d.placeholder || d.examples?.[0]?.toString() || "", b = n(d, p), x = l(d);
	return g ? /* @__PURE__ */ o("div", {
		className: "mb-4 block",
		children: [/* @__PURE__ */ a(t, {
			className: "text-muted-foreground mb-1 block text-sm",
			children: _.fieldLabel
		}), /* @__PURE__ */ a(s, {
			name: u,
			control: m.control,
			defaultValue: _.defaultValue ?? "",
			render: ({ field: e }) => /* @__PURE__ */ a("div", {
				className: "text-sm",
				children: e.value ?? "—"
			})
		})]
	}) : /* @__PURE__ */ a(s, {
		name: u,
		control: m.control,
		defaultValue: _.defaultValue ?? (x ? void 0 : ""),
		rules: b,
		render: ({ field: t }) => /* @__PURE__ */ a(i, {
			name: u,
			label: _.fieldLabel,
			required: p,
			error: _.error,
			helpText: _.helpText,
			description: _.description,
			children: /* @__PURE__ */ a(e, {
				...t,
				id: u,
				onChange: (e) => {
					if (!_.isReadOnly) if (x) {
						let n = e.target.value;
						t.onChange(n === "" ? void 0 : Number(n));
					} else t.onChange(e);
				},
				value: t.value ?? "",
				type: v,
				placeholder: y,
				disabled: _.isDisabled,
				readOnly: _.isReadOnly,
				min: d.minimum,
				max: d.maximum,
				step: v === "number" && d.multipleOf ? d.multipleOf : void 0,
				maxLength: d.maxLength,
				className: _.error ? "border-destructive focus-visible:ring-destructive" : "",
				..._.getAriaProps()
			})
		})
	});
};
//#endregion
export { u as InputField };
