import { defineComponent, ref, createVNode, Transition, Teleport, withDirectives, mergeProps, vShow } from "vue";
import { useEventListener } from "../../../@vant/use/dist/index.esm.mjs";
import { useLazyRender } from "../composables/use-lazy-render.mjs";
import { getZIndexStyle } from "../utils/format.mjs";
import { truthProp, unknownProp, numericProp } from "../utils/props.mjs";
import { createNamespace } from "../utils/create.mjs";
import { preventDefault } from "../utils/dom.mjs";
import { extend, isDef } from "../utils/basic.mjs";
const [name, bem] = createNamespace("overlay");
const overlayProps = {
  show: Boolean,
  zIndex: numericProp,
  duration: numericProp,
  className: unknownProp,
  lockScroll: truthProp,
  lazyRender: truthProp,
  customStyle: Object,
  teleport: [String, Object]
};
var stdin_default = defineComponent({
  name,
  inheritAttrs: false,
  props: overlayProps,
  setup(props, {
    attrs,
    slots
  }) {
    const root = ref();
    const lazyRender = useLazyRender(() => props.show || !props.lazyRender);
    const onTouchMove = (event) => {
      if (props.lockScroll) {
        preventDefault(event, true);
      }
    };
    const renderOverlay = lazyRender(() => {
      var _a;
      const style = extend(getZIndexStyle(props.zIndex), props.customStyle);
      if (isDef(props.duration)) {
        style.animationDuration = `${props.duration}s`;
      }
      return withDirectives(createVNode("div", mergeProps({
        "ref": root,
        "style": style,
        "class": [bem(), props.className]
      }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots)]), [[vShow, props.show]]);
    });
    useEventListener("touchmove", onTouchMove, {
      target: root
    });
    return () => {
      const Content = createVNode(Transition, {
        "name": "van-fade",
        "appear": true
      }, {
        default: renderOverlay
      });
      if (props.teleport) {
        return createVNode(Teleport, {
          "to": props.teleport
        }, {
          default: () => [Content]
        });
      }
      return Content;
    };
  }
});
export {
  stdin_default as default,
  overlayProps
};
