import { jsxs as T, Fragment as H, jsx as t } from "react/jsx-runtime";
import { u as ne, o as se, e as re, f as ae, s as de, d as le } from "../vendor.js";
import { useState as b, useRef as ie, useMemo as ce, useCallback as x, useEffect as N } from "react";
import { n as pe, o as ue, c as fe, f as me, s as he, m as ge, a as we } from "../tools/tools.js";
import { D as K } from "./dropdown-divider.js";
import { D as V } from "./dropdown-header.js";
import { D as z } from "./dropdown-item-text.js";
import { D as O } from "./dropdown-item.js";
import { D as G } from "./dropdown-menu.js";
import { D as h } from "./dropdown-toggle.js";
const d = function(U) {
  const {
    as: _ = "div",
    autoClose: g = !0,
    btnGroup: k,
    buttonProps: E,
    center: D,
    children: q,
    className: R,
    customMenu: i,
    dropend: y,
    dropOldClass: I,
    dropstart: r,
    dropup: v,
    dropupCenter: C,
    menuProps: a,
    offset: J,
    options: Q,
    split: c,
    strategy: W = "absolute",
    style: L,
    toggle: M,
    toggleProps: s,
    variables: S,
    visible: w,
    ...X
  } = U, Y = (Q ?? []).map((e, n) => ({
    ...e,
    id: e.id ?? n
  })), [Z] = b(Y), [o, p] = b(w ?? !1), u = ie(pe()), [B, F] = b(), [j, A] = b(!1), { floatingStyles: $, refs: f } = ne({
    middleware: [
      se(() => J ?? 0, [o]),
      re((e) => e, [o]),
      ae((e) => e, [o]),
      de((e) => e, [o])
    ],
    onOpenChange: p,
    open: o,
    placement: ue(
      [
        ["bottom", D],
        ["bottom-end", B === "end"],
        ["bottom-start", B === "start"],
        ["left-start", r],
        ["right-start", y],
        ["top", C],
        ["top-start", v]
      ],
      "bottom-start"
    ),
    strategy: W,
    whileElementsMounted: le
  }), P = ce(() => {
    const e = fe(
      !I && me(
        ["btn-group", c || k],
        ["dropdown-center", D],
        ["dropup-center", C],
        ["dropdown", !0]
      ),
      v && "dropup",
      y && "dropend",
      r && "dropstart",
      R
    ), n = he((l, oe) => ({ tKey: we(oe) }), S, L);
    return {
      className: e,
      style: n
    };
  }, [k, D, R, I, y, r, v, C, c, L, S]), m = x(
    (e) => {
      var n;
      p(typeof e == "boolean" ? e : e ? !o : !1), (n = s == null ? void 0 : s.onClick) == null || n.call(
        s,
        e
      );
    },
    [o, s == null ? void 0 : s.onClick]
  ), ee = x(() => {
    i && A(!0);
  }, [i]), te = x(() => {
    i && A(!1);
  }, [i]);
  return N(() => {
    typeof w == "boolean" && p(w);
  }, [w]), N(() => {
    if (!g || j)
      return;
    const e = (n) => {
      const l = n.target;
      if (l.className.includes("dropdown")) {
        if (g === "outside")
          return;
        l.dataset.toggleId !== u.current && m();
      } else g !== "inside" && m();
    };
    return document.body.addEventListener("click", e), () => document.body.removeEventListener("click", e);
  }, [g, j, m]), N(() => {
    var n;
    if (!a || !((n = a.className) != null && n.includes("dropdown-menu-")))
      return;
    const e = f.floating.current;
    if (e) {
      const l = getComputedStyle(e).getPropertyValue("--bs-position");
      F(l || !1);
    }
  }, [a, f.floating]), /* @__PURE__ */ T(_, { ...X, ...P, children: [
    c ? /* @__PURE__ */ T(H, { children: [
      !(c && r) && /* @__PURE__ */ t(h, { dropOldClass: !0, ...E, children: M }),
      /* @__PURE__ */ t(
        h,
        {
          "aria-expanded": o ? "true" : "false",
          className: "dropdown-toggle-split",
          show: o,
          ...s,
          "data-toggle-id": u.current,
          onClick: m,
          onRef: f.setReference,
          children: /* @__PURE__ */ t("span", { className: "visually-hidden", children: "Toggle Dropdown" })
        }
      )
    ] }) : /* @__PURE__ */ T(
      h,
      {
        "aria-expanded": o ? "true" : "false",
        show: o,
        ...s,
        "data-toggle-id": u.current,
        onClick: m,
        onRef: f.setReference,
        children: [
          r && /* @__PURE__ */ t("span", { className: "dropdown-nbsp", "data-toggle-id": u.current, children: " " }),
          M,
          !r && /* @__PURE__ */ t("span", { className: "dropdown-nbsp", "data-toggle-id": u.current, children: " " })
        ]
      }
    ),
    /* @__PURE__ */ t(
      G,
      {
        ...ge(a, { style: { ...a == null ? void 0 : a.style, ...$ } }),
        onMouseEnter: ee,
        onMouseLeave: te,
        onRef: f.setFloating,
        show: o,
        children: i ? q : /* @__PURE__ */ t(H, { children: Z.map((e) => e.header ? /* @__PURE__ */ t(V, { children: e.header }, e.id) : e.itemText ? /* @__PURE__ */ t(z, { children: e.itemText }, e.id) : e.divider ? /* @__PURE__ */ t(K, {}, e.id) : e.as === "a" ? /* @__PURE__ */ t(O, { active: e.active, as: "a", disabled: e.disabled, href: e.href, children: e.item }, e.id) : /* @__PURE__ */ t(O, { active: e.active, as: "button", disabled: e.disabled, children: e.item }, e.id)) })
      }
    ),
    c && r && /* @__PURE__ */ t(h, { dropOldClass: !0, ...E, children: M })
  ] });
};
d.Toggle = h;
d.Item = O;
d.ItemText = z;
d.Menu = G;
d.Divider = K;
d.Header = V;
d.displayName = "BRL.Dropdown";
export {
  d as D
};
//# sourceMappingURL=dropdown.js.map
