<template>
  <view :class="dropdownClass" :style="dropdownStyle">
    <view :class="bem.e('shadow')" />
    <slot></slot>
  </view>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { computed, ref, provide, toRef, unref, toRaw, reactive } from "vue";
import { classNames, stringifyStyle, createBem } from "../utils";
import {
  dropdownContextSymbol,
  dropdownProps
} from "./common";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "dropdown",
  props: dropdownProps,
  setup(__props, { expose: __expose }) {
    __expose();
    const props = __props;
    const bem = createBem("dropdown");
    const items = ref(/* @__PURE__ */ new Map());
    const someVisible = computed(() => {
      return [...items.value.values()].some((item) => unref(item.visible));
    });
    const hideOthers = (instance) => {
      items.value.forEach((expose, ins) => {
        if (toRaw(ins) !== instance) {
          expose.hide();
        }
      });
    };
    const register = (instance, imperative) => {
      items.value.set(instance, imperative);
    };
    const unregister = (instance) => {
      items.value.delete(instance);
    };
    provide(
      dropdownContextSymbol,
      reactive({
        direction: toRef(props, "direction"),
        disabled: toRef(props, "disabled"),
        awayClosable: toRef(props, "awayClosable"),
        overlayClosable: toRef(props, "overlayClosable"),
        duration: toRef(props, "duration"),
        hideOthers,
        register,
        unregister
      })
    );
    const dropdownClass = computed(() => {
      return classNames(bem.b(), bem.m("show", someVisible.value), props.rootClass);
    });
    const dropdownStyle = computed(() => {
      return stringifyStyle(props.rootStyle);
    });
    const __returned__ = { props, bem, items, someVisible, hideOthers, register, unregister, dropdownClass, dropdownStyle };
    return __returned__;
  }
});
</script>

<style lang="scss">
@use './index.scss';
</style>