import '@das-fed/upf-ui/packages/components/popup-mask/style.css';
import { defineComponent as I, mergeModels as b, ref as s, computed as O, useModel as S, watch as _, nextTick as P, onMounted as N, onUnmounted as T, openBlock as r, createBlock as $, Teleport as z, createVNode as h, Transition as H, withCtx as D, createElementBlock as C, normalizeClass as L, normalizeStyle as V, withModifiers as g, createElementVNode as Y, renderSlot as w, createCommentVNode as u, unref as Z } from "vue";
import { withInstall as q } from "@das-fed/upf-utils/with-install/index";
import { useZIndex as U } from "@das-fed/upf-utils/hooks/popup-manager/use-zindex";
import { hasClass as W, getStyle as B, addClass as j, removeClass as A } from "@das-fed/upf-utils/style";
import "@das-fed/upf-ui/packages/components/icon/index";
import { DasIconClose2 as F } from "@das-fed/upf-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(t, { emit: n }) {
    const o = t, a = n, d = s(), M = O(() => {
      let e = "das-ui-popup-mask";
      return o.maskClass && (e = `${e} ${o.maskClass}`), e;
    }), i = S(t, "visible"), f = s(2e3), l = s(!1), p = s("0"), m = s(0), x = () => {
      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;
    };
    _(
      () => i.value,
      (e) => {
        e ? (f.value = U().nextZIndex(), P(() => {
          x();
        })) : v(), a("update:visible", e), a("visible-change", e);
      }
    );
    const c = () => {
      i.value = !1, v();
    }, R = () => {
      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: !t.appendToBody
    }, [
      h(
        H,
        {
          ref_key: "popupMaskRef",
          ref: d,
          name: "fade"
        },
        {
          default: D(() => [
            i.value ? (r(), C(
              "div",
              {
                key: 0,
                class: L(M.value),
                style: V({ "z-index": f.value }),
                onClick: g(R, ["self"])
              },
              [
                Y("div", G, [
                  e.$slots.default ? w(e.$slots, "default", { key: 0 }, void 0, !0) : u("v-if", !0)
                ]),
                t.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 = (t, n) => {
  const o = t.__vccOpts || t;
  for (const [a, d] of n)
    o[a] = d;
  return o;
}, Q = /* @__PURE__ */ K(J, [["__scopeId", "data-v-67ba9d27"]]), ae = () => s(null), ne = q(Q);
export {
  ne as DasPopupMask,
  ae as DasPopupMaskRef,
  ne as default
};
