<template>
  <view :class="tagClass" :style="tagStyle" @click="$emit('click', $event)">
    <slot></slot>
    <view
      v-if="closable"
      :class="iconClass"
      :style="iconStyle"
      @click="$emit('close', $event)"
    >
      <sar-icon name="close" />
    </view>
  </view>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { computed } from "vue";
import { classNames, stringifyStyle, createBem } from "../utils";
import SarIcon from "../icon/icon.vue";
import { tagProps } from "./common";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "tag",
  props: tagProps,
  emits: ["click", "close"],
  setup(__props, { expose: __expose }) {
    __expose();
    const props = __props;
    const bem = createBem("tag");
    const tagClass = computed(() => {
      return classNames(
        bem.b(),
        bem.m(props.theme),
        bem.m("plain", props.plain),
        bem.m(`${props.theme}-plain`, props.plain),
        bem.m(props.size),
        bem.m("round", props.round),
        bem.m("mark", props.mark),
        props.rootClass
      );
    });
    const tagStyle = computed(() => {
      return stringifyStyle(
        {
          color: props.plain ? props.color : props.textColor,
          borderColor: props.plain ? props.color : null,
          backgroundColor: !props.plain ? props.color : null
        },
        props.rootStyle
      );
    });
    const iconClass = computed(() => {
      return classNames(
        bem.e("close"),
        bem.em("close", props.theme),
        bem.em("close", `${props.theme}-plain`, props.plain)
      );
    });
    const iconStyle = computed(() => {
      return stringifyStyle({
        color: props.plain ? props.color : props.textColor
      });
    });
    const __returned__ = { props, bem, tagClass, tagStyle, iconClass, iconStyle, SarIcon };
    return __returned__;
  }
});
</script>

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