"use client";
'use strict';

var React = require('react');
var reactSlot = require('@radix-ui/react-slot');
var reactHookForm = require('react-hook-form');
var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var LabelPrimitive = require('@radix-ui/react-label');
var classVarianceAuthority = require('class-variance-authority');
var jsxRuntime = require('react/jsx-runtime');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);
var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespace(LabelPrimitive);

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
__name(cn, "cn");

// utils.ts
function cn2(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
__name(cn2, "cn");
var labelVariants = classVarianceAuthority.cva(
  "text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
);
var Label = /* @__PURE__ */ __name(({
  className,
  ...props
}) => /* @__PURE__ */ jsxRuntime.jsx(LabelPrimitive__namespace.Root, { className: cn(labelVariants(), className), ...props }), "Label");
Label.displayName = LabelPrimitive__namespace.Root.displayName;
var Form = reactHookForm.FormProvider;
var FormFieldContext = React__namespace.createContext(
  {}
);
var FormField = /* @__PURE__ */ __name(({
  ...props
}) => {
  return /* @__PURE__ */ jsxRuntime.jsx(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.Controller, { ...props }) });
}, "FormField");
var useFormField = /* @__PURE__ */ __name(() => {
  const fieldContext = React__namespace.useContext(FormFieldContext);
  const itemContext = React__namespace.useContext(FormItemContext);
  const { getFieldState, formState } = reactHookForm.useFormContext();
  const fieldState = getFieldState(fieldContext.name, formState);
  if (!fieldContext) {
    throw new Error("useFormField should be used within <FormField>");
  }
  const { id } = itemContext;
  return {
    id,
    name: fieldContext.name,
    formItemId: `${id}-form-item`,
    formDescriptionId: `${id}-form-item-description`,
    formMessageId: `${id}-form-item-message`,
    ...fieldState
  };
}, "useFormField");
var FormItemContext = React__namespace.createContext(
  {}
);
var FormItem = React__namespace.forwardRef(({ className, ...props }, ref) => {
  const id = React__namespace.useId();
  return /* @__PURE__ */ jsxRuntime.jsx(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn2("space-y-2", className), ...props }) });
});
FormItem.displayName = "FormItem";
var FormLabel = React__namespace.forwardRef(({ className, ...props }, ref) => {
  const { error, formItemId } = useFormField();
  return /* @__PURE__ */ jsxRuntime.jsx(
    Label,
    {
      ref,
      className: cn2(error && "text-destructive", className),
      htmlFor: formItemId,
      ...props
    }
  );
});
FormLabel.displayName = "FormLabel";
var FormControl = React__namespace.forwardRef(({ ...props }, ref) => {
  const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
  return /* @__PURE__ */ jsxRuntime.jsx(
    reactSlot.Slot,
    {
      ref,
      id: formItemId,
      "aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
      "aria-invalid": !!error,
      ...props
    }
  );
});
FormControl.displayName = "FormControl";
var FormDescription = React__namespace.forwardRef(({ className, ...props }, ref) => {
  const { formDescriptionId } = useFormField();
  return /* @__PURE__ */ jsxRuntime.jsx(
    "p",
    {
      ref,
      id: formDescriptionId,
      className: cn2("text-sm text-muted-foreground", className),
      ...props
    }
  );
});
FormDescription.displayName = "FormDescription";
var FormMessage = React__namespace.forwardRef(({ className, children, ...props }, ref) => {
  const { error, formMessageId } = useFormField();
  const body = error ? String(error?.message) : children;
  if (!body) {
    return null;
  }
  return /* @__PURE__ */ jsxRuntime.jsx(
    "p",
    {
      ref,
      id: formMessageId,
      className: cn2("text-sm font-medium text-destructive", className),
      ...props,
      children: body
    }
  );
});
FormMessage.displayName = "FormMessage";

exports.Form = Form;
exports.FormControl = FormControl;
exports.FormDescription = FormDescription;
exports.FormField = FormField;
exports.FormItem = FormItem;
exports.FormLabel = FormLabel;
exports.FormMessage = FormMessage;
exports.useFormField = useFormField;
