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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var isString = require('lodash/isString');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_tnode = require('../hooks/tnode.js');
var tag_props = require('./props.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);

var _Tag = vue.defineComponent({
  name: "TTag",
  props: tag_props["default"],
  setup: function setup(props2) {
    var _useConfig = configProvider_useConfig.useConfig("tag"),
      tagGlobalConfig = _useConfig.globalConfig;
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("tag");
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CloseIcon: iconsVueNext.CloseIcon
      }),
      CloseIcon = _useGlobalIcon.CloseIcon;
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var renderContent = hooks_tnode.useContent();
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      SIZE = _useCommonClassName.SIZE;
    var tagClass = vue.computed(function () {
      var _ref;
      return ["".concat(COMPONENT_NAME.value), "".concat(COMPONENT_NAME.value, "--").concat(props2.theme), "".concat(COMPONENT_NAME.value, "--").concat(props2.variant), (_ref = {}, _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--ellipsis"), props2.maxWidth), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--close"), props2.closable), _defineProperty__default["default"](_ref, "".concat(COMPONENT_NAME.value, "--disabled"), props2.disabled), _defineProperty__default["default"](_ref, SIZE.value[props2.size], props2.size !== "medium"), _ref), props2.shape !== "square" && "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)];
    });
    var tagStyle = vue.computed(function () {
      var maxWidth = props2.maxWidth;
      return props2.maxWidth ? {
        maxWidth: isNaN(Number(maxWidth)) ? String(maxWidth) : "".concat(maxWidth, "px")
      } : {};
    });
    var handleClick = function handleClick(e) {
      var _props2$onClick;
      if (props2.disabled) return;
      (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, {
        e: e
      });
    };
    var getCloseIcon = function getCloseIcon() {
      if (!props2.closable) return null;
      var iconClassName = "".concat(COMPONENT_NAME.value, "__icon-close");
      if (tagGlobalConfig.value.closeIcon) return vue.h(tagGlobalConfig.value.closeIcon(vue.h), {
        "class": iconClassName
      });
      return vue.createVNode(CloseIcon, {
        "onClick": function onClick(_ref2) {
          var _props2$onClose;
          var e = _ref2.e;
          e.stopPropagation();
          (_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 ? void 0 : _props2$onClose.call(props2, {
            e: e
          });
        },
        "class": iconClassName
      }, null);
    };
    return function () {
      var closeIcon = getCloseIcon();
      var tagContent = renderContent("default", "content");
      var icon = renderTNodeJSX("icon");
      var title = isString__default["default"](tagContent) ? tagContent : "";
      var titleAttribute = title && props2.maxWidth ? title : void 0;
      return vue.createVNode("span", {
        "class": tagClass.value,
        "style": tagStyle.value,
        "onClick": handleClick
      }, [icon, props2.maxWidth ? vue.createVNode("span", {
        "class": _defineProperty__default["default"]({}, "".concat(COMPONENT_NAME.value, "--text"), props2.maxWidth),
        "title": titleAttribute
      }, [tagContent]) : tagContent, !props2.disabled && closeIcon]);
    };
  }
});

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