'use client';

// src/components/Form/components/index.tsx
import * as React3 from "react";
import { cn as cn3 } from "@paalan/react-shared/lib";
import { Slot } from "@radix-ui/react-slot";
import { Controller, FormProvider, useFormContext } from "react-hook-form";

// src/components/Label/Label.tsx
import * as React2 from "react";
import { InfoOutlineIcon } from "@paalan/react-icons";
import { cn as cn2 } from "@paalan/react-shared/lib";
import * as LabelPrimitive from "@radix-ui/react-label";
import { cva } from "class-variance-authority";

// src/components/Tooltip/Tooltip.tsx
import * as React from "react";
import { useControllableState } from "@paalan/react-hooks";
import { cn } from "@paalan/react-shared/lib";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { jsx, jsxs } from "react/jsx-runtime";
var TooltipProvider = TooltipPrimitive.Provider;
var TooltipRoot = TooltipPrimitive.Root;
var TooltipTrigger = TooltipPrimitive.Trigger;
var TooltipPortal = TooltipPrimitive.Portal;
var TooltipContent = React.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(
  TooltipPrimitive.Content,
  {
    ref,
    sideOffset,
    className: cn(
      "z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
      className
    ),
    ...props
  }
));
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
var Tooltip = React.forwardRef(
  ({
    className,
    trigger,
    asPortal,
    content,
    side = "top",
    align = "center",
    defaultOpen,
    open,
    onOpenChange,
    ...props
  }, ref) => {
    const TooltipPortalComponent = asPortal ? TooltipPortal : React.Fragment;
    const [localOpen, setLocalOpen] = useControllableState({
      defaultValue: defaultOpen,
      value: open,
      onChange: onOpenChange
    });
    return /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 100, children: /* @__PURE__ */ jsxs(TooltipRoot, { open: localOpen, onOpenChange: setLocalOpen, children: [
      /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: trigger }),
      /* @__PURE__ */ jsx(TooltipPortalComponent, { children: /* @__PURE__ */ jsxs(
        TooltipContent,
        {
          ref,
          className: cn("bg-secondary fill-secondary text-secondary-foreground", className),
          side,
          align,
          ...props,
          children: [
            content,
            /* @__PURE__ */ jsx(TooltipPrimitive.Arrow, { width: 11, height: 5 })
          ]
        }
      ) })
    ] }) });
  }
);

// src/components/Label/Label.tsx
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
var Label = React2.forwardRef(
  ({ className, required = false, labelDescription, text, isInvalid, children, disabled, ...props }, ref) => /* @__PURE__ */ jsxs2(
    LabelPrimitive.Root,
    {
      ref,
      className: cn2(labelVariants(), { "text-danger": isInvalid, "opacity-70": disabled }, className),
      ...props,
      children: [
        text || children,
        required && /* @__PURE__ */ jsx2("span", { className: "text-danger/70", children: "*" }),
        labelDescription && /* @__PURE__ */ jsx2(
          Tooltip,
          {
            trigger: /* @__PURE__ */ jsx2(InfoOutlineIcon, { className: "ml-1 text-muted-foreground", "aria-hidden": "true" }),
            content: labelDescription
          }
        )
      ]
    }
  )
);
Label.displayName = LabelPrimitive.Root.displayName;

// src/components/Form/components/index.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
var FormRoot = FormProvider;
var FormFieldContext = React3.createContext({});
var FormField = ({
  ...props
}) => {
  return /* @__PURE__ */ jsx3(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx3(Controller, { ...props }) });
};
var useFormField = () => {
  const fieldContext = React3.useContext(FormFieldContext);
  const itemContext = React3.useContext(FormItemContext);
  const { getFieldState, formState } = 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
  };
};
var FormItemContext = React3.createContext({});
var FormItem = React3.forwardRef(
  ({ className, ...props }, ref) => {
    const id = React3.useId();
    return /* @__PURE__ */ jsx3(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx3("div", { ref, className: cn3("space-y-2", className), ...props }) });
  }
);
FormItem.displayName = "FormItem";
var FormLabel = React3.forwardRef(
  ({ className, required, ...props }, ref) => {
    const { error, formItemId } = useFormField();
    return /* @__PURE__ */ jsx3(
      Label,
      {
        ref,
        className: cn3(error && "text-danger", className),
        htmlFor: formItemId,
        required,
        ...props,
        children: props.children
      }
    );
  }
);
FormLabel.displayName = "FormLabel";
var FormControl = React3.forwardRef(
  ({ ...props }, ref) => {
    const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
    return /* @__PURE__ */ jsx3(
      Slot,
      {
        ref,
        id: formItemId,
        "aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
        "aria-invalid": !!error,
        ...props
      }
    );
  }
);
FormControl.displayName = "FormControl";
var FormDescription = React3.forwardRef(
  ({ className, ...props }, ref) => {
    const { formDescriptionId } = useFormField();
    return /* @__PURE__ */ jsx3("p", { ref, id: formDescriptionId, className: cn3("text-[0.8rem] text-muted-foreground", className), ...props });
  }
);
FormDescription.displayName = "FormDescription";
var FormMessage = React3.forwardRef(
  ({ className, children, ...props }, ref) => {
    const { error, formMessageId } = useFormField();
    const body = error ? String(error?.message) : children;
    if (!body) {
      return null;
    }
    return /* @__PURE__ */ jsx3("p", { ref, id: formMessageId, className: cn3("text-[0.8rem] font-medium text-danger", className), ...props, children: body });
  }
);
FormMessage.displayName = "FormMessage";
export {
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
  FormRoot,
  useFormField
};
