import { o as B } from "./rolldown-runtime.js";
import { i as _, t as q } from "./vendor/react.js";
import { t as s } from "./utils.js";
import { t as w } from "./create-safe-context.js";
var u = /* @__PURE__ */ B(_(), 1), r = q();
function f(t) {
  switch (t) {
    case "success":
      return "text-success/80";
    case "destructive":
      return "text-destructive/80";
    default:
      return "text-muted-foreground/80";
  }
}
function I(t) {
  switch (t) {
    case "success":
      return "text-success";
    case "destructive":
      return "text-destructive";
    default:
      return "text-secondary-foreground";
  }
}
var [F, T] = w("Field");
function n() {
  return u.useContext(F);
}
function D() {
  const t = n();
  if (!t) return {};
  const e = [t.descriptionId, t.state === "destructive" ? t.errorId : null].filter(Boolean).join(" ") || void 0;
  return {
    id: t.id,
    "aria-invalid": t.state === "destructive" ? !0 : void 0,
    "aria-describedby": e,
    "aria-required": t.required ? !0 : void 0,
    disabled: t.disabled,
    required: t.required,
    state: t.state
  };
}
function m({ layout: t = "stacked", state: e = "default", disabled: i, required: o, className: l, children: a, ...c }) {
  const d = `field-${u.useId()}`, p = `${d}-description`, x = `${d}-error`, R = u.useMemo(() => ({
    id: d,
    descriptionId: p,
    errorId: x,
    state: e,
    disabled: i,
    required: o,
    layout: t
  }), [
    d,
    p,
    x,
    e,
    i,
    o,
    t
  ]);
  return /* @__PURE__ */ (0, r.jsx)(F.Provider, {
    value: R,
    children: /* @__PURE__ */ (0, r.jsx)("div", {
      "data-slot": "field",
      "data-layout": t,
      "data-state": e,
      "data-disabled": i || void 0,
      className: s("flex w-full transition-opacity motion-reduce:transition-none", t === "stacked" && "flex-col gap-1.5", t === "inline" && "flex-row items-start gap-2", i && "opacity-50", l),
      ...c,
      children: a
    })
  });
}
m.displayName = "Field";
function g({ className: t, children: e, ...i }) {
  return /* @__PURE__ */ (0, r.jsx)("div", {
    "data-slot": "field-top",
    className: s("flex items-center justify-between gap-2", t),
    ...i,
    children: e
  });
}
g.displayName = "FieldTop";
function v({ className: t, children: e, ...i }) {
  return /* @__PURE__ */ (0, r.jsx)("span", {
    "data-slot": "field-top-right",
    className: s("text-xs leading-5 transition-colors motion-reduce:transition-none", f(n()?.state), t),
    ...i,
    children: e
  });
}
v.displayName = "FieldTopRight";
function N({ className: t, required: e, labelIcon: i, children: o, ...l }) {
  const a = n(), c = e || a?.required;
  return /* @__PURE__ */ (0, r.jsxs)("label", {
    "data-slot": "field-label",
    htmlFor: a?.id,
    className: s("text-sm font-medium leading-5 transition-colors motion-reduce:transition-none", I(a?.state), t),
    ...l,
    children: [
      o,
      c && /* @__PURE__ */ (0, r.jsx)("span", {
        className: "text-destructive ms-0.5",
        "aria-hidden": "true",
        children: "*"
      }),
      i && /* @__PURE__ */ (0, r.jsx)("span", {
        className: "text-muted-foreground ms-1 inline-flex align-middle",
        children: i
      })
    ]
  });
}
N.displayName = "FieldLabel";
function j({ children: t }) {
  return T(), t(D());
}
j.displayName = "FieldControl";
function h({ className: t, children: e, ...i }) {
  return /* @__PURE__ */ (0, r.jsx)("div", {
    "data-slot": "field-bottom",
    className: s("flex items-center justify-between gap-2", t),
    ...i,
    children: e
  });
}
h.displayName = "FieldBottom";
function b({ className: t, children: e, ...i }) {
  return /* @__PURE__ */ (0, r.jsx)("span", {
    "data-slot": "field-bottom-right",
    className: s("text-xs leading-5 transition-colors motion-reduce:transition-none", f(n()?.state), t),
    ...i,
    children: e
  });
}
b.displayName = "FieldBottomRight";
function y({ className: t, children: e, ...i }) {
  const o = n();
  return /* @__PURE__ */ (0, r.jsx)("p", {
    id: o?.descriptionId,
    "data-slot": "field-description",
    className: s("text-sm leading-5 transition-colors motion-reduce:transition-none", f(o?.state), t),
    ...i,
    children: e
  });
}
y.displayName = "FieldDescription";
function C({ className: t, children: e, ...i }) {
  const o = n();
  return e ? /* @__PURE__ */ (0, r.jsx)("span", {
    id: o?.errorId,
    "data-slot": "field-error",
    role: "alert",
    className: s("text-destructive text-sm font-normal", "animate-in fade-in-0 slide-in-from-top-1 duration-200 motion-reduce:animate-none", t),
    ...i,
    children: e
  }) : null;
}
C.displayName = "FieldError";
var k = Object.assign(m, {
  Root: m,
  Top: g,
  Label: N,
  TopRight: v,
  Control: j,
  Bottom: h,
  Description: y,
  BottomRight: b,
  Error: C
});
export {
  y as a,
  g as c,
  D as d,
  j as i,
  v as l,
  h as n,
  C as o,
  b as r,
  N as s,
  k as t,
  n as u
};

//# sourceMappingURL=Field.js.map