"use client";
"use client";
import { cn as e } from "../../../lib/utils.js";
import { Label as t } from "./label.js";
import * as n from "react";
import { jsx as r } from "react/jsx-runtime";
import { Controller as i, FormProvider as a, useFormContext as o, useFormState as s } from "react-hook-form";
//#region lib/components/ui/atoms/form.tsx
var c = a, l = n.createContext({}), u = ({ ...e }) => /* @__PURE__ */ r(l.Provider, {
	value: { name: e.name },
	children: /* @__PURE__ */ r(i, { ...e })
}), d = () => {
	let e = n.useContext(l), t = n.useContext(f), { getFieldState: r } = o(), i = s({ name: e.name }), a = r(e.name, i);
	if (!e) throw Error("useFormField should be used within <FormField>");
	let { id: c } = t;
	return {
		id: c,
		name: e.name,
		formItemId: `${c}-form-item`,
		formDescriptionId: `${c}-form-item-description`,
		formMessageId: `${c}-form-item-message`,
		...a
	};
}, f = n.createContext({});
function p({ className: t, ...i }) {
	let a = n.useId();
	return /* @__PURE__ */ r(f.Provider, {
		value: { id: a },
		children: /* @__PURE__ */ r("div", {
			className: e("grid gap-2.5", t),
			"data-slot": "form-item",
			...i
		})
	});
}
function m({ className: n, ...i }) {
	let { error: a, formItemId: o } = d();
	return /* @__PURE__ */ r(t, {
		className: e("data-[error=true]:text-destructive", n),
		"data-error": !!a,
		"data-slot": "form-label",
		htmlFor: o,
		...i
	});
}
function h({ children: e }) {
	let { error: t, formItemId: r, formDescriptionId: i, formMessageId: a } = d(), o = n.Children.only(e);
	return n.cloneElement(o, {
		id: r,
		"aria-describedby": t ? `${i} ${a}` : i,
		"aria-invalid": !!t,
		"data-slot": "form-control"
	});
}
function g({ className: t, ...n }) {
	let { formDescriptionId: i } = d();
	return /* @__PURE__ */ r("p", {
		className: e("text-muted-foreground text-sm", t),
		"data-slot": "form-description",
		id: i,
		...n
	});
}
function _({ className: t, ...n }) {
	let { error: i, formMessageId: a } = d(), o = i ? String(i?.message ?? "") : n.children;
	return o ? /* @__PURE__ */ r("p", {
		className: e("text-destructive text-sm", t),
		"data-slot": "form-message",
		id: a,
		...n,
		children: o
	}) : null;
}
//#endregion
export { c as Form, h as FormControl, g as FormDescription, u as FormField, p as FormItem, m as FormLabel, _ as FormMessage, d as useFormField };
