/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseIcon } from '@ldesign/icons-vue';
import { TagProps } from './props.js';
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 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _Tag = mixins(getConfigReceiverMixins("tag"), getGlobalIconMixins()).extend({
  name: "LTag",
  props: _objectSpread({}, TagProps),
  computed: {
    tagClass: function tagClass() {
      var _ref;

      return ["".concat(this.componentName), "".concat(this.componentName, "--").concat(this.theme), this.commonSizeClassName[this.size], "".concat(this.componentName, "--").concat(this.variant), this.shape !== "square" && "".concat(this.componentName, "--").concat(this.shape), (_ref = {}, _defineProperty(_ref, "".concat(this.componentName, "--ellipsis"), this.maxWidth), _defineProperty(_ref, "".concat(this.componentName, "--close"), this.closable), _defineProperty(_ref, "".concat(this.classPrefix, "-is-disabled"), this.disabled), _defineProperty(_ref, "".concat(this.componentName, "--disabled"), this.disabled), _ref)];
    },
    tagStyle: function tagStyle() {
      if (this.maxWidth) return {
        maxWidth: "".concat(this.maxWidth, "px")
      };
      return {};
    }
  },
  methods: {
    handleClose: function handleClose(e) {
      if (this.disabled) return;
      emitEvent(this, "close", {
        e: e
      });
    },
    handleClick: function handleClick(e) {
      if (this.disabled) return;
      emitEvent(this, "click", {
        e: e
      });
    },
    getCloseIcon: function getCloseIcon() {
      var _this = this;

      var h = this.$createElement;
      if (!this.closable) return null;
      var iconClassName = "".concat(this.classPrefix, "-tag__icon-close");

      if (this.global.closeIcon) {
        return this.global.closeIcon(function (component, b) {
          var tProps = _typeof(b) === "object" && "attrs" in b ? b.attrs : {};
          return _this.$createElement(component, {
            props: _objectSpread({}, tProps),
            "class": iconClassName,
            nativeOn: {
              click: _this.handleClose
            }
          });
        });
      }

      var _this$useGlobalIcon = this.useGlobalIcon({
        CloseIcon: CloseIcon
      }),
          CloseIcon$1 = _this$useGlobalIcon.CloseIcon;

      return h(CloseIcon$1, {
        "nativeOn": {
          "click": this.handleClose
        },
        "class": iconClassName
      });
    }
  },
  render: function render() {
    var h = arguments[0];
    var closeIcon = this.getCloseIcon();
    var tagContent = renderContent(this, "default", "content");
    var tagContentWithMaxWidth = h("span", {
      "style": this.tagStyle,
      "class": "".concat(this.componentName, "--text")
    }, [tagContent]);
    var 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
