import {
  Heading
} from "./chunk-BESTU2AY.js";
import {
  Typo
} from "./chunk-PMJIFLDT.js";
import {
  __objRest,
  __spreadProps,
  __spreadValues
} from "./chunk-CRTRMMJ7.js";

// src/molecules/form/form.tsx
import * as RadixForm from "@radix-ui/react-form";
import { createContext, forwardRef, useContext, useMemo } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var Root2 = forwardRef(
  (_a, ref) => {
    var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]);
    return /* @__PURE__ */ jsx(
      RadixForm.Root,
      __spreadProps(__spreadValues({}, rest), {
        className: `FormRoot ${className || ""}`,
        ref,
        children
      })
    );
  }
);
Root2.displayName = "FORM_ROOT";
var FieldContext = createContext({
  name: ""
});
var Field2 = forwardRef(
  (_a, ref) => {
    var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]);
    return /* @__PURE__ */ jsx(
      RadixForm.Field,
      __spreadProps(__spreadValues({}, rest), {
        className: `FormField ${className || ""}`,
        ref,
        children: /* @__PURE__ */ jsx(FieldContext.Provider, { value: rest, children })
      })
    );
  }
);
Field2.displayName = "FORM_FIELD";
function HeadingLabel(props) {
  return /* @__PURE__ */ jsx(Heading, __spreadProps(__spreadValues({ variant: "heading5" }, props), { children: props.children }));
}
function CaptionLabel(props) {
  return /* @__PURE__ */ jsx(Typo, __spreadProps(__spreadValues({ color: "gray", variant: "caption" }, props), { children: props.children }));
}
var Label2 = forwardRef(
  (_a, ref) => {
    var _b = _a, { children, className, variant } = _b, rest = __objRest(_b, ["children", "className", "variant"]);
    const Comp = useMemo(() => {
      switch (variant) {
        case "title":
          return HeadingLabel;
        case "caption":
          return CaptionLabel;
        case "body":
        default:
          return Typo;
      }
    }, [variant]);
    const fieldProps = useContext(FieldContext);
    return /* @__PURE__ */ jsx(
      RadixForm.Label,
      __spreadProps(__spreadValues({}, rest), {
        asChild: true,
        className: `FormLabel ${className || ""}`,
        ref,
        children: /* @__PURE__ */ jsxs(Comp, { children: [
          children,
          fieldProps.required ? /* @__PURE__ */ jsx(Typo, { as: "span", color: "tomato", children: ` *` }) : null
        ] })
      })
    );
  }
);
Label2.displayName = "FORM_Label";
var Message2 = forwardRef(
  (_a, ref) => {
    var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]);
    return /* @__PURE__ */ jsx(
      RadixForm.Message,
      __spreadProps(__spreadValues({}, rest), {
        asChild: true,
        className: `FormMessage ${className || ""}`,
        ref,
        children: /* @__PURE__ */ jsx(Typo, { color: "red", children })
      })
    );
  }
);
Message2.displayName = "FORM_Message";
var Control2 = forwardRef(
  (_a, ref) => {
    var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
    const fieldProps = useContext(FieldContext);
    return /* @__PURE__ */ jsx(
      RadixForm.Control,
      __spreadProps(__spreadValues({}, rest), {
        className: `FormControl ${className || ""}`,
        ref,
        required: fieldProps.required
      })
    );
  }
);
Control2.displayName = "FORM_Control";
function FormItem(_a) {
  var _b = _a, {
    label,
    labelVariant,
    children,
    errorMessage
  } = _b, fieldProps = __objRest(_b, [
    "label",
    "labelVariant",
    "children",
    "errorMessage"
  ]);
  return /* @__PURE__ */ jsxs(Form.Field, __spreadProps(__spreadValues({}, fieldProps), { children: [
    /* @__PURE__ */ jsx(Form.Label, { variant: labelVariant, children: label }),
    children,
    /* @__PURE__ */ jsx(Form.Message, { forceMatch: Boolean(errorMessage), children: errorMessage })
  ] }));
}
var Form = {
  Root: Root2,
  Field: Field2,
  Label: Label2,
  Message: Message2,
  Control: RadixForm.Control,
  Submit: RadixForm.Submit,
  FormItem
};

export {
  FormItem,
  Form
};
//# sourceMappingURL=chunk-2OMSNCRH.js.map