import p, { useEffect as c } from "react";
import { useLabels as Y, useId as ee } from "../../utils/dist/module.es.js";
import { isElementInChildOfActiveScope as se } from "../../focus/dist/module.es.js";
import { useInteractOutside as re, useFocusWithin as te } from "../../interactions/dist/module.es.js";
import "react-dom";
import { VisuallyHidden as ie } from "../../visually-hidden/dist/module.es.js";
import { useLocalizedStringFormatter as ae } from "../../i18n/dist/real-module.es.js";
function oe(r) {
  return r && r.__esModule ? r.default : r;
}
const de = /* @__PURE__ */ new WeakMap(), i = [];
function be(r, s) {
  let { onClose: t, shouldCloseOnBlur: d, isOpen: a, isDismissable: o = !1, isKeyboardDismissDisabled: f = !1, shouldCloseOnInteractOutside: $ } = r;
  c(() => (a && i.push(s), () => {
    let e = i.indexOf(s);
    e >= 0 && i.splice(e, 1);
  }), [
    a,
    s
  ]);
  let n = () => {
    i[i.length - 1] === s && t && t();
  }, V = (e) => {
    (!$ || $(e.target)) && i[i.length - 1] === s && (e.stopPropagation(), e.preventDefault());
  }, J = (e) => {
    (!$ || $(e.target)) && (i[i.length - 1] === s && (e.stopPropagation(), e.preventDefault()), n());
  }, q = (e) => {
    e.key === "Escape" && !f && (e.stopPropagation(), e.preventDefault(), n());
  };
  re({
    ref: s,
    onInteractOutside: o ? J : null,
    onInteractOutsideStart: V
  });
  let { focusWithinProps: Q } = te({
    isDisabled: !d,
    onBlurWithin: (e) => {
      e.relatedTarget && se(e.relatedTarget) || (!$ || $(e.relatedTarget)) && t();
    }
  }), X = (e) => {
    e.target === e.currentTarget && e.preventDefault();
  };
  return {
    overlayProps: {
      onKeyDown: q,
      ...Q
    },
    underlayProps: {
      onPointerDown: X
    }
  };
}
function me(r, s, t) {
  let { type: d } = r, { isOpen: a } = s;
  c(() => {
    t && t.current && de.set(t.current, s.close);
  });
  let o;
  d === "menu" ? o = !0 : d === "listbox" && (o = "listbox");
  let f = ee();
  return {
    triggerProps: {
      "aria-haspopup": o,
      "aria-expanded": a,
      "aria-controls": a ? f : null,
      onPress: s.toggle
    },
    overlayProps: {
      id: f
    }
  };
}
var l = {}, u = {};
u = {
  dismiss: "\u062A\u062C\u0627\u0647\u0644"
};
var b = {};
b = {
  dismiss: "\u041E\u0442\u0445\u0432\u044A\u0440\u043B\u044F\u043D\u0435"
};
var m = {};
m = {
  dismiss: "Odstranit"
};
var v = {};
v = {
  dismiss: "Luk"
};
var x = {};
x = {
  dismiss: "Schlie\xDFen"
};
var O = {};
O = {
  dismiss: "\u0391\u03C0\u03CC\u03C1\u03C1\u03B9\u03C8\u03B7"
};
var g = {};
g = {
  dismiss: "Dismiss"
};
var D = {};
D = {
  dismiss: "Descartar"
};
var h = {};
h = {
  dismiss: "L\xF5peta"
};
var P = {};
P = {
  dismiss: "Hylk\xE4\xE4"
};
var y = {};
y = {
  dismiss: "Rejeter"
};
var I = {};
I = {
  dismiss: "\u05D4\u05EA\u05E2\u05DC\u05DD"
};
var E = {};
E = {
  dismiss: "Odbaci"
};
var k = {};
k = {
  dismiss: "Elutas\xEDt\xE1s"
};
var C = {};
C = {
  dismiss: "Ignora"
};
var S = {};
S = {
  dismiss: "\u9589\u3058\u308B"
};
var L = {};
L = {
  dismiss: "\uBB34\uC2DC"
};
var R = {};
R = {
  dismiss: "Atmesti"
};
var T = {};
T = {
  dismiss: "Ner\u0101d\u012Bt"
};
var K = {};
K = {
  dismiss: "Lukk"
};
var B = {};
B = {
  dismiss: "Negeren"
};
var H = {};
H = {
  dismiss: "Zignoruj"
};
var W = {};
W = {
  dismiss: "Descartar"
};
var w = {};
w = {
  dismiss: "Dispensar"
};
var A = {};
A = {
  dismiss: "Revocare"
};
var F = {};
F = {
  dismiss: "\u041F\u0440\u043E\u043F\u0443\u0441\u0442\u0438\u0442\u044C"
};
var N = {};
N = {
  dismiss: "Zru\u0161i\u0165"
};
var U = {};
U = {
  dismiss: "Opusti"
};
var _ = {};
_ = {
  dismiss: "Odbaci"
};
var j = {};
j = {
  dismiss: "Avvisa"
};
var z = {};
z = {
  dismiss: "Kapat"
};
var Z = {};
Z = {
  dismiss: "\u0421\u043A\u0430\u0441\u0443\u0432\u0430\u0442\u0438"
};
var G = {};
G = {
  dismiss: "\u53D6\u6D88"
};
var M = {};
M = {
  dismiss: "\u95DC\u9589"
};
l = {
  "ar-AE": u,
  "bg-BG": b,
  "cs-CZ": m,
  "da-DK": v,
  "de-DE": x,
  "el-GR": O,
  "en-US": g,
  "es-ES": D,
  "et-EE": h,
  "fi-FI": P,
  "fr-FR": y,
  "he-IL": I,
  "hr-HR": E,
  "hu-HU": k,
  "it-IT": C,
  "ja-JP": S,
  "ko-KR": L,
  "lt-LT": R,
  "lv-LV": T,
  "nb-NO": K,
  "nl-NL": B,
  "pl-PL": H,
  "pt-BR": W,
  "pt-PT": w,
  "ro-RO": A,
  "ru-RU": F,
  "sk-SK": N,
  "sl-SI": U,
  "sr-SP": _,
  "sv-SE": j,
  "tr-TR": z,
  "uk-UA": Z,
  "zh-CN": G,
  "zh-TW": M
};
function ve(r) {
  let { onDismiss: s, ...t } = r, d = ae(/* @__PURE__ */ oe(l)), a = Y(t, d.format("dismiss")), o = () => {
    s && s();
  };
  return /* @__PURE__ */ p.createElement(ie, null, /* @__PURE__ */ p.createElement("button", {
    ...a,
    tabIndex: -1,
    onClick: o
  }));
}
export {
  ve as DismissButton,
  be as useOverlay,
  me as useOverlayTrigger
};
//# sourceMappingURL=module.es.js.map
