/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-b6ac6e96.js';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseIcon } from '@ldesign/icons-vue';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js';
import { emitEvent } from '../utils/event.js';
import props from './props.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 '../_chunks/dep-2cb61c79.js';
import 'dayjs';
import '@vue/composition-api';
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: "TTag",
  props: _objectSpread({}, props),
  computed: {
    tagClass: function tagClass() {
      var _ref;
      return ["".concat(this.componentName), "".concat(this.componentName, "--").concat(this.theme), "".concat(this.componentName, "--").concat(this.variant), this.shape !== "square" && "".concat(this.componentName, "--").concat(this.shape), (_ref = {}, _defineProperty(_ref, this.commonSizeClassName[this.size], this.size !== "medium"), _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)];
    },
    textStyle: function textStyle() {
      if (this.maxWidth) {
        return {
          maxWidth: isNaN(Number(this.maxWidth)) ? this.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 title = typeof tagContent === "string" ? tagContent : "";
    var titleAttribute = title && this.maxWidth ? {
      title: title
    } : void 0;
    var icon = renderTNodeJSX(this, "icon");
    return h("span", {
      "class": this.tagClass,
      "on": {
        "click": this.handleClick
      }
    }, [icon, h("span", helper([{
      "class": this.maxWidth ? "".concat(this.componentName, "--text") : void 0,
      "style": this.textStyle
    }, {
      "attrs": titleAttribute
    }]), [tagContent]), !this.disabled ? closeIcon : void 0]);
  }
});

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