"use client";
'use strict';

var reactSlot = require('@radix-ui/react-slot');
var React = require('react');
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");
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 = /* @__PURE__ */ __name(({
  className,
  ...props
}) => {
  const id = React__namespace.useId();
  return /* @__PURE__ */ jsxRuntime.jsx(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("relative", className), ...props }) });
}, "FormItem");
FormItem.displayName = "FormItem";
var FormLabel = /* @__PURE__ */ __name(({
  className,
  ...props
}) => {
  const { error, formItemId } = useFormField();
  return /* @__PURE__ */ jsxRuntime.jsx(
    Label,
    {
      className: cn(
        "text-text-secondary pointer-events-none absolute top-3 left-4 flex text-xs leading-tight font-medium transition-all select-none",
        // input
        "peer-placeholder-shown:text-text-tertiary z-[1] peer-placeholder-shown:text-base peer-placeholder-shown:leading-[2.3]",
        "peer-focus:text-text-secondary peer-disabled:peer-placeholder-shown:text-text-tertiary peer-disabled:text-text-tertiary peer-focus:text-xs peer-focus:leading-tight",
        // select
        "peer-data-[placeholder]/select:top-5 peer-data-[placeholder]/select:text-base",
        // adornment
        "peer-[.adornment]/adornment:text-xs",
        error && "text-red-500",
        className
      ),
      htmlFor: formItemId,
      ...props
    }
  );
}, "FormLabel");
FormLabel.displayName = "FormLabel";
var FormControl = /* @__PURE__ */ __name(({ ...props }) => {
  const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
  return /* @__PURE__ */ jsxRuntime.jsx(
    reactSlot.Slot,
    {
      "aria-describedby": error ? `${formDescriptionId} ${formMessageId}` : `${formDescriptionId}`,
      "aria-invalid": !!error,
      id: formItemId,
      ...props
    }
  );
}, "FormControl");
FormControl.displayName = "FormControl";
var FormDescription = /* @__PURE__ */ __name(({
  className,
  ...props
}) => {
  const { formDescriptionId } = useFormField();
  return /* @__PURE__ */ jsxRuntime.jsx(
    "p",
    {
      className: cn("text-text-secondary py-1 text-[0.75rem]", className),
      id: formDescriptionId,
      ...props
    }
  );
}, "FormDescription");
FormDescription.displayName = "FormDescription";
var FormMessage = /* @__PURE__ */ __name(({
  className,
  children,
  ...props
}) => {
  const { error, formMessageId } = useFormField();
  const body = error ? String(error?.message) : children;
  if (!body) {
    return null;
  }
  return /* @__PURE__ */ jsxRuntime.jsx(
    "p",
    {
      className: cn(
        "text-red text-[0.75rem] font-medium dark:text-red-900",
        className
      ),
      id: formMessageId,
      ...props,
      children: body
    }
  );
}, "FormMessage");
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;
