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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var iconsVue = require('@ldesign/icons-vue');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_renderNode = require('../../utils/render-node.js');
var utils_event = require('../../utils/event.js');
var components_tag_props = require('./props.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/helper.js');
require('lodash/camelCase');

var _Tag = utils_mixins["default"](components_configProvider_configReceiver["default"]("tag"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LTag",
  props: {
    ...components_tag_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;
      utils_event.emitEvent(this, "close", {
        e
      });
    },
    handleClick(e) {
      if (this.disabled) return;
      utils_event.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
      } = this.useGlobalIcon({
        CloseIcon: iconsVue.CloseIcon
      });
      return h(CloseIcon, {
        "nativeOn": {
          "click": this.handleClose
        },
        "class": iconClassName
      });
    }
  },
  render() {
    const h = arguments[0];
    const closeIcon = this.getCloseIcon();
    const tagContent = utils_renderNode.renderContent(this, "default", "content");
    const tagContentWithMaxWidth = h("span", {
      "style": this.tagStyle,
      "class": `${this.componentName}--text`
    }, [tagContent]);
    const icon = utils_renderNode.renderLNodeJSX(this, "icon");
    return h("span", {
      "class": this.tagClass,
      "on": {
        "click": this.handleClick
      }
    }, [icon, this.maxWidth ? tagContentWithMaxWidth : tagContent, closeIcon]);
  }
});

exports["default"] = _Tag;
//# sourceMappingURL=tag.js.map
