/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseIcon } from 'tdesign-icons-vue';
import ClASSNAMES from '../utils/classnames.js';
import { prefix } from '../config.js';
import props from './props.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js';
import { emitEvent } from '../utils/event.js';
import 'vue';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import 'lodash/isObject';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';

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 name = "".concat(prefix, "-tag");
var _Tag = mixins(getConfigReceiverMixins("tag")).extend({
  name: "TTag",
  props: _objectSpread({}, props),
  computed: {
    tagClass: function tagClass() {
      var _ref;

      return ["".concat(name), "".concat(name, "--").concat(this.theme), ClASSNAMES.SIZE[this.size], "".concat(name, "--").concat(this.variant), this.shape !== "square" && "".concat(name, "--").concat(this.shape), (_ref = {}, _defineProperty(_ref, "".concat(name, "--ellipsis"), this.maxWidth), _defineProperty(_ref, "".concat(name, "--close"), this.closable), _defineProperty(_ref, "".concat(prefix, "-is-disabled"), this.disabled), _defineProperty(_ref, "".concat(name, "--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(prefix, "-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
            }
          });
        });
      }

      return h(CloseIcon, {
        "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(name, "--text")
    }, [tagContent]);
    var icon = renderTNodeJSX(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
