/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { CloseIcon } from '@ldesign/icons-vue';
import mixins from '../../utils/mixins.js';
import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.js';
import { renderContent, renderLNodeJSX } from '../../utils/render-node.js';
import { emitEvent } from '../../utils/event.js';
import { TagProps } from './props.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/helper.js';
import 'lodash/camelCase';

var _Tag = mixins(getConfigReceiverMixins("tag"), getGlobalIconMixins()).extend({
  name: "LTag",
  props: {
    ...TagProps
  },
  computed: {
    tagClass() {
      return [`${this.componentName}`, `${this.componentName}--${this.theme}`, this.commonSizeClassName[this.size], `${this.componentName}--${this.variant}`, this.shape !== "square" && `${this.componentName}--${this.shape}`, {
        [`${this.componentName}--ellipsis`]: this.maxWidth,
        [`${this.componentName}--close`]: this.closable,
        [`${this.classPrefix}-is-disabled`]: this.disabled,
        [`${this.componentName}--disabled`]: this.disabled
      }];
    },
    tagStyle() {
      if (this.maxWidth) return {
        maxWidth: `${this.maxWidth}px`
      };
      return {};
    }
  },
  methods: {
    handleClose(e) {
      if (this.disabled) return;
      emitEvent(this, "close", {
        e
      });
    },
    handleClick(e) {
      if (this.disabled) return;
      emitEvent(this, "click", {
        e
      });
    },
    getCloseIcon() {
      const h = this.$createElement;
      if (!this.closable) return null;
      const iconClassName = `${this.classPrefix}-tag__icon-close`;
      if (this.global.closeIcon) {
        return this.global.closeIcon((component, b) => {
          const tProps = typeof b === "object" && "attrs" in b ? b.attrs : {};
          return this.$createElement(component, {
            props: {
              ...tProps
            },
            class: iconClassName,
            nativeOn: {
              click: this.handleClose
            }
          });
        });
      }
      const {
        CloseIcon: CloseIcon$1
      } = this.useGlobalIcon({
        CloseIcon: CloseIcon
      });
      return h(CloseIcon$1, {
        "nativeOn": {
          "click": this.handleClose
        },
        "class": iconClassName
      });
    }
  },
  render() {
    const h = arguments[0];
    const closeIcon = this.getCloseIcon();
    const tagContent = renderContent(this, "default", "content");
    const tagContentWithMaxWidth = h("span", {
      "style": this.tagStyle,
      "class": `${this.componentName}--text`
    }, [tagContent]);
    const icon = renderLNodeJSX(this, "icon");
    return h("span", {
      "class": this.tagClass,
      "on": {
        "click": this.handleClick
      }
    }, [icon, this.maxWidth ? tagContentWithMaxWidth : tagContent, closeIcon]);
  }
});

export { _Tag as default };
//# sourceMappingURL=tag.js.map
