import '@das-fed/ui/packages/components/popup-mask/style.css';
import { defineComponent as I, mergeModels as b, ref as t, computed as x, useModel as O, watch as S, nextTick as P, onMounted as N, onUnmounted as T, createBlock as $, openBlock as r, Teleport as z, createVNode as h, Transition as H, withCtx as D, createElementBlock as C, createCommentVNode as u, withModifiers as g, normalizeStyle as L, normalizeClass as V, createElementVNode as Y, renderSlot as w, unref as Z } from "vue";
import { withInstall as q } from "@das-fed/utils/with-install/index";
import { useZIndex as U } from "@das-fed/utils/hooks/popup-manager/use-zindex";
import { hasClass as W, getStyle as B, addClass as j, removeClass as A } from "@das-fed/utils/style";
import { DasIconClose2 as F } from "@das-fed/ui/packages/icons/close-2/index";
const G = { class: "mask-content" }, J = /* @__PURE__ */ I({
  __name: "Index",
  props: /* @__PURE__ */ b({
    visible: { type: Boolean, default: !1 },
    maskClass: {},
    appendToBody: { type: Boolean, default: !1 },
    lockScroll: { type: Boolean, default: !0 },
    showClose: { type: Boolean, default: !0 },
    closeOnClickModal: { type: Boolean, default: !1 },
    closeOnPressEscape: { type: Boolean, default: !0 }
  }, {
    visible: { type: Boolean, default: !1 },
    visibleModifiers: {}
  }),
  emits: /* @__PURE__ */ b(["update:visible", "visible-change"], ["update:visible"]),
  setup(s, { emit: n }) {
    const o = s, a = n, d = t(), M = x(() => {
      let e = "das-ui-popup-mask";
      return o.maskClass && (e = `${e} ${o.maskClass}`), e;
    }), i = O(s, "visible"), f = t(2e3), l = t(!1), p = t("0"), m = t(0), R = () => {
      if (!o.lockScroll) return;
      l.value = !W(document.body, "overflow-hide"), l.value && (p.value = document.body.style.paddingRight, m.value = parseInt(B(document.body, "paddingRight"), 10));
      const e = 10;
      let k = document.documentElement.clientHeight < document.body.scrollHeight, E = B(document.body, "overflowY");
      (k || E === "scroll") && l.value && (document.body.style.paddingRight = m.value + e + "px"), j(document.body, "overflow-hide");
    }, v = () => {
      l.value && (document.body.style.paddingRight = p.value, A(document.body, "overflow-hide")), l.value = !0;
    };
    S(
      () => i.value,
      (e) => {
        e ? (f.value = U().nextZIndex(), P(() => {
          R();
        })) : v(), a("update:visible", e), a("visible-change", e);
      }
    );
    const c = () => {
      i.value = !1, v();
    }, _ = () => {
      o.closeOnClickModal && c();
    }, y = (e) => {
      e.key === "Escape" && o.closeOnPressEscape && c();
    };
    return N(() => {
      window.addEventListener("keydown", y);
    }), T(() => {
      window.removeEventListener("keydown", y);
    }), (e, k) => (r(), $(z, {
      to: "body",
      disabled: !e.appendToBody
    }, [
      h(
        H,
        {
          ref_key: "popupMaskRef",
          ref: d,
          name: "fade"
        },
        {
          default: D(() => [
            i.value ? (r(), C(
              "div",
              {
                key: 0,
                class: V(M.value),
                style: L({ "z-index": f.value }),
                onClick: g(_, ["self"])
              },
              [
                Y("div", G, [
                  e.$slots.default ? w(e.$slots, "default", { key: 0 }, void 0, !0) : u("v-if", !0)
                ]),
                e.showClose ? (r(), C("div", {
                  key: 0,
                  class: "close-icon",
                  onClick: g(c, ["stop"])
                }, [
                  w(e.$slots, "close-icon", {}, () => [
                    h(Z(F), { iconColor: "#ffffff" })
                  ], !0)
                ])) : u("v-if", !0)
              ],
              6
              /* CLASS, STYLE */
            )) : u("v-if", !0)
          ]),
          _: 3
          /* FORWARDED */
        },
        512
        /* NEED_PATCH */
      )
    ], 8, ["disabled"]));
  }
}), K = (s, n) => {
  const o = s.__vccOpts || s;
  for (const [a, d] of n)
    o[a] = d;
  return o;
}, Q = /* @__PURE__ */ K(J, [["__scopeId", "data-v-563102b2"]]), le = () => t(null), ae = q(Q);
export {
  ae as DasPopupMask,
  le as DasPopupMaskRef,
  ae as default
};
