'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');

function useSelectTriggerControl(refs, open, triggerOpen) {
  function onGlobalMouseDown(event) {
    var _a, _b, _c;
    let target = event.target;
    if (target.shadowRoot && event.composed)
      target = event.composedPath()[0] || target;
    const elements = [(_a = refs[0]) == null ? void 0 : _a.value, (_c = (_b = refs[1]) == null ? void 0 : _b.value) == null ? void 0 : _c.getPopupElement()];
    if (open.value && elements.every((element) => element && !element.contains(target) && element !== target)) {
      triggerOpen(false);
    }
  }
  vue.onMounted(() => {
    window.addEventListener("mousedown", onGlobalMouseDown);
  });
  vue.onBeforeUnmount(() => {
    window.removeEventListener("mousedown", onGlobalMouseDown);
  });
}

exports.default = useSelectTriggerControl;
//# sourceMappingURL=useSelectTriggerControl.cjs.map
