import { jsx as c } from "react/jsx-runtime";
import f, { useMemo as i, useCallback as p } from "react";
import { InputGroupAddonProvider as I } from "../../context/InputGroupAddonContext.js";
import { VALID_ADDON_CHILDREN as h } from "../../constants/index.js";
import { c as o } from "../../../../index-BtlgVD4m.js";
import g from "../../hooks/useInputGroupContext.js";
import D from "../../utils/isValidAddonChild.js";
import w from "../../utils/warnInvalidChild.js";
import G from "../../utils/getAlignOrder.js";
const l = "flex items-center shrink-0", N = {
  "outline-left": {
    base: o(
      l,
      // External addons have their own border and background
      "[&>*]:rounded-l-[var(--border-radius-md)] [&>*]:rounded-r-none"
    ),
    default: "",
    sm: "",
    xs: ""
  },
  "inline-left": {
    base: o(l, "text-[var(--base-muted-foreground)]"),
    default: "",
    sm: "",
    xs: ""
  },
  "inline-right": {
    base: o(l, "text-[var(--base-muted-foreground)]"),
    default: "",
    sm: "",
    xs: ""
  },
  "outline-right": {
    base: o(
      l,
      // External addons have their own border and background
      "[&>*]:rounded-r-[var(--border-radius-md)] [&>*]:rounded-l-none"
    ),
    default: "",
    sm: "",
    xs: ""
  }
}, E = ({ children: u, align: e = "inline-right" }) => {
  const { size: a, disabled: b, inputRef: d } = g(), s = i(() => N[e], [e]), x = i(() => s[a] || s.default, [s, a]), m = p((n) => n.includes("outline") ? 1 : 2, []), v = i(() => {
    const n = [], r = m(e);
    if (f.Children.forEach(u, (t) => {
      f.isValidElement(t) && (D(t, h) ? n.push(t) : w(t, h, "InputGroupAddon"));
    }), n.length > r) {
      if (process.env.NODE_ENV === "development") {
        const t = e.includes("outline") ? "outline" : "inline";
        console.warn(
          `[InputGroupAddon] Too many children for ${t} addon (align="${e}"). Maximum allowed: ${r}, found: ${n.length}. Only the first ${r} component(s) will be rendered.`
        );
      }
      return n.slice(0, r);
    }
    return n;
  }, [u, e, m]), C = i(
    () => ({ side: e.includes("left") ? "left" : "right", inline: e.includes("inline") }),
    [e]
  ), A = p(
    (n) => {
      var t;
      !e.includes("inline") || n.target.closest('button, [role="button"], select, a[href], input, textarea') || (n.preventDefault(), (t = d == null ? void 0 : d.current) == null || t.focus());
    },
    [e, d]
  ), y = o(
    s.base,
    x,
    // Add gap between elements in addon
    "gap-[var(--spacing-2)]"
  );
  return /* @__PURE__ */ c(I, { value: C, children: /* @__PURE__ */ c(
    "div",
    {
      className: y,
      style: { order: G(e) },
      "data-align": e,
      "data-disabled": b || void 0,
      onMouseDown: A,
      children: v
    }
  ) });
};
E.displayName = "InputGroupAddon";
export {
  E as default
};
//# sourceMappingURL=InputGroupAddon.js.map
