import l, { useState as w, useMemo as u, useCallback as h } from "react";
import V from "../utils/isValidAddonChild.js";
import N from "../utils/warnInvalidChild.js";
function R({ children: c, onFocus: o, onBlur: r }) {
  const [m, p] = w(!1), g = u(() => {
    const n = [], t = /* @__PURE__ */ new Set();
    return l.Children.forEach(c, (e) => {
      var i, s;
      if (l.isValidElement(e))
        if (V(e, ["InputGroupAddon", "InputGroupInput"])) {
          if (((i = e.type) == null ? void 0 : i.displayName) === "InputGroupAddon") {
            const f = ((s = e.props) == null ? void 0 : s.align) || "inline-right";
            {
              if (t.has(f)) {
                console.warn(
                  `[InputGroup] Duplicate InputGroupAddon with align="${f}" detected. Each align variant can only appear once. This duplicate will be ignored.`
                );
                return;
              }
              t.add(f);
            }
          }
          n.push(e);
        } else
          N(e, ["InputGroupAddon", "InputGroupInput"], "InputGroup");
    }), n;
  }, [c]), { outlineAddons: a, inlineContent: A, hasOutlineAddon: I } = u(() => {
    const n = [], t = [];
    let e = !1;
    return l.Children.forEach(g, (i) => {
      var d;
      if (!l.isValidElement(i))
        return;
      const s = (d = i.props) == null ? void 0 : d.align;
      s === "outline-left" || s === "outline-right" ? (n.push(i), e = !0) : t.push(i);
    }), { outlineAddons: n, inlineContent: t, hasOutlineAddon: e };
  }, [g]), G = h(
    (n) => {
      p(!0), o == null || o(n);
    },
    [o]
  ), C = h(
    (n) => {
      n.currentTarget.contains(n.relatedTarget) || (p(!1), r == null || r(n));
    },
    [r]
  ), E = u(
    () => a.filter((n) => {
      var t;
      return l.isValidElement(n) && ((t = n.props) == null ? void 0 : t.align) === "outline-left";
    }),
    [a]
  ), y = u(
    () => a.filter((n) => {
      var t;
      return l.isValidElement(n) && ((t = n.props) == null ? void 0 : t.align) === "outline-right";
    }),
    [a]
  );
  return {
    isFocused: m,
    outlineAddons: a,
    inlineContent: A,
    hasOutlineAddon: I,
    handleFocus: G,
    handleBlur: C,
    setIsFocused: p,
    outlineLeftAddons: E,
    outlineRightAddons: y
  };
}
export {
  R as default
};
//# sourceMappingURL=useInputGroup.js.map
