<template>
  <view :class="tabbarItemClass" :style="tabbarItemStyle" @click="onClick">
    <slot>
      <view :class="bem.e('icon')">
        <slot name="icon">
          <sar-icon :name="icon" :family="iconFamily" :size="iconSize" />
        </slot>
        <sar-badge v-if="badge || dot" :value="badge" :dot="dot" fixed />
      </view>
      <view :class="bem.e('text')">
        {{ text }}
      </view>
    </slot>
  </view>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { computed, inject } from "vue";
import { classNames, stringifyStyle, createBem } from "../utils";
import {
  tabbarContextSymbol,
  tabbarItemProps
} from "../tabbar/common";
import SarIcon from "../icon/icon.vue";
import SarBadge from "../badge/badge.vue";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "tabbar-item",
  props: tabbarItemProps,
  emits: ["click"],
  setup(__props, { expose: __expose, emit: __emit }) {
    __expose();
    const props = __props;
    const emit = __emit;
    const bem = createBem("tabbar");
    const context = inject(tabbarContextSymbol);
    if (!context) {
      throw new Error("TabbarItem must be included in Tabbar.");
    }
    const isCurrent = computed(() => {
      return context.current === props.name;
    });
    const onClick = (event) => {
      if (props.name !== void 0) {
        context.select(props.name);
      }
      emit("click", event);
    };
    const tabbarItemClass = computed(() => {
      return classNames(
        bem.e("item"),
        bem.em("item", "current", isCurrent.value),
        props.rootClass
      );
    });
    const tabbarItemStyle = computed(() => {
      return stringifyStyle(
        {
          color: isCurrent.value ? context.activeColor : context.color
        },
        props.rootStyle
      );
    });
    const __returned__ = { props, emit, bem, context, isCurrent, onClick, tabbarItemClass, tabbarItemStyle, SarIcon, SarBadge };
    return __returned__;
  }
});
</script>

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