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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, h } from 'vue';
import { CloseIcon } from '@ldesign/icons-vue-next';
import isString from 'lodash/isString';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import { useTNodeJSX, useContent } from '../hooks/tnode.js';
import props from './props.js';
import { useConfig } from '../config-provider/useConfig.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-e041f5b0.js';
import 'dayjs';

var _Tag = defineComponent({
  name: "TTag",
  props: props,
  setup: function setup(props2) {
    var _useConfig = useConfig("tag"),
      tagGlobalConfig = _useConfig.globalConfig;
    var COMPONENT_NAME = usePrefixClass("tag");
    var _useGlobalIcon = useGlobalIcon({
        CloseIcon: CloseIcon
      }),
      CloseIcon$1 = _useGlobalIcon.CloseIcon;
    var renderTNodeJSX = useTNodeJSX();
    var renderContent = useContent();
    var _useCommonClassName = useCommonClassName(),
      SIZE = _useCommonClassName.SIZE;
    var tagClass = 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(_ref, "".concat(COMPONENT_NAME.value, "--ellipsis"), props2.maxWidth), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--close"), props2.closable), _defineProperty(_ref, "".concat(COMPONENT_NAME.value, "--disabled"), props2.disabled), _defineProperty(_ref, SIZE.value[props2.size], props2.size !== "medium"), _ref), props2.shape !== "square" && "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)];
    });
    var tagStyle = 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 h(tagGlobalConfig.value.closeIcon(h), {
        "class": iconClassName
      });
      return createVNode(CloseIcon$1, {
        "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(tagContent) ? tagContent : "";
      var titleAttribute = title && props2.maxWidth ? title : void 0;
      return createVNode("span", {
        "class": tagClass.value,
        "style": tagStyle.value,
        "onClick": handleClick
      }, [icon, props2.maxWidth ? createVNode("span", {
        "class": _defineProperty({}, "".concat(COMPONENT_NAME.value, "--text"), props2.maxWidth),
        "title": titleAttribute
      }, [tagContent]) : tagContent, !props2.disabled && closeIcon]);
    };
  }
});

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