import { defineComponent, useSlots, ref, computed, watchEffect, openBlock, createBlock, unref, createSlots, withCtx, renderSlot, createElementVNode } from "vue";
import { Popover } from "vant";
const __default__ = {
  name: "WlPopover"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    actions: { default: null },
    modelValue: { type: Boolean, default: false }
  },
  emits: ["update:modelValue", "onSelect"],
  setup(__props, { emit }) {
    const props = __props;
    const slots = useSlots();
    const hasDefault = ref(slots.default !== void 0);
    const slotName = computed(() => hasDefault.value ? "default" : "content");
    const popoverVisible = ref(false);
    const onTogglePopover = (bool) => {
      popoverVisible.value = bool;
      emit("update:modelValue", bool);
    };
    const onSelect = (val) => {
      emit("onSelect", val);
      onTogglePopover(false);
    };
    watchEffect(() => {
      popoverVisible.value = props.modelValue;
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Popover), {
        show: popoverVisible.value,
        "onUpdate:show": _cache[1] || (_cache[1] = ($event) => popoverVisible.value = $event),
        actions: __props.actions,
        onSelect
      }, createSlots({
        reference: withCtx(() => [
          renderSlot(_ctx.$slots, "reference")
        ]),
        _: 2
      }, [
        hasDefault.value ? {
          name: unref(slotName),
          fn: withCtx(() => [
            createElementVNode("div", {
              onClick: _cache[0] || (_cache[0] = ($event) => popoverVisible.value = false)
            }, [
              renderSlot(_ctx.$slots, "default")
            ])
          ])
        } : void 0
      ]), 1032, ["show", "actions"]);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
