<template>
  <view v-if="$slots.default" :class="bem.e('wrapper')">
    <slot></slot>
    <view :class="badgeClass" :style="badgeStyle">
      <slot name="value">
        {{ innerValue }}
      </slot>
    </view>
  </view>
  <view v-else :class="badgeClass" :style="badgeStyle">
    <slot name="value">
      {{ innerValue }}
    </slot>
  </view>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { computed, useSlots } from "vue";
import { classNames, stringifyStyle, createBem } from "../utils";
import { badgeProps } from "./common";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "badge",
  props: badgeProps,
  setup(__props, { expose: __expose }) {
    __expose();
    const props = __props;
    const bem = createBem("badge");
    const slots = useSlots();
    const zeroHide = computed(() => {
      return !props.dot && props.value === 0 && !props.showZero && !slots.value;
    });
    const innerValue = computed(() => {
      return props.dot ? "" : typeof props.value === "number" && props.value > props.max ? `${props.max}+` : props.value;
    });
    const badgeClass = computed(() => {
      return classNames(
        bem.b(),
        bem.m("fixed", props.fixed || !!slots.default),
        bem.m("zero-hide", zeroHide.value),
        bem.m("dot", props.dot),
        props.rootClass
      );
    });
    const badgeStyle = computed(() => {
      return stringifyStyle(
        {
          background: props.color,
          color: props.textColor
        },
        props.rootStyle
      );
    });
    const __returned__ = { props, bem, slots, zeroHide, innerValue, badgeClass, badgeStyle };
    return __returned__;
  }
});
</script>

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