/**
 * ldesign v0.4.2
 * (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 isFunction = require('lodash/isFunction');
var tooltip_index = require('../tooltip/index.js');
var utils_dom = require('../utils/dom.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_tnode = require('../hooks/tnode.js');
var breadcrumb_breadcrumbItemProps = require('./breadcrumb-item-props.js');
require('../utils/withInstall.js');
require('../tooltip/tooltip.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/omit');
require('../popup/props.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('lodash/isObject');
require('lodash/isString');
require('../hooks/useVModel.js');
require('lodash/kebabCase');
require('../_common/js/utils/set-style.js');
require('../popup/container.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isArray');
require('../hooks/useResizeObserver.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
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-7f0559c3.js');
require('dayjs');
require('../utils/easing.js');
require('lodash/camelCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('../tooltip/util.js');
require('../tooltip/props.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

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__default["default"](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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var localTBreadcrumbOrigin = {
  separator: "",
  theme: "light",
  slots: {
    separator: ""
  },
  maxItemWidth: void 0
};
var _BreadcrumbItem = vue.defineComponent({
  name: "TBreadcrumbItem",
  inheritAttrs: false,
  props: _objectSpread({}, breadcrumb_breadcrumbItemProps["default"]),
  setup: function setup(props2, _ref) {
    var _localTBreadcrumb$slo;
    var slots = _ref.slots,
      attrs = _ref.attrs;
    var breadcrumbText = vue.ref();
    var localTBreadcrumb = vue.inject("tBreadcrumb", localTBreadcrumbOrigin);
    var themeClassName = vue.ref(localTBreadcrumb === null || localTBreadcrumb === void 0 ? void 0 : localTBreadcrumb.theme);
    var isCutOff = vue.ref(false);
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("breadcrumb__item");
    var separatorClass = hooks_useConfig.usePrefixClass("breadcrumb__separator");
    var disableClass = hooks_useConfig.usePrefixClass("is-disabled");
    var linkClass = hooks_useConfig.usePrefixClass("link");
    var maxLengthClass = hooks_useConfig.usePrefixClass("breadcrumb__inner");
    var textFlowClass = hooks_useConfig.usePrefixClass("breadcrumb--text-overflow");
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        ChevronRightIcon: iconsVueNext.ChevronRightIcon
      }),
      ChevronRightIcon = _useGlobalIcon.ChevronRightIcon;
    var maxWithStyle = vue.computed(function () {
      var maxItemWidth = localTBreadcrumb === null || localTBreadcrumb === void 0 ? void 0 : localTBreadcrumb.maxItemWidth;
      var maxWith = props2.maxWidth || maxItemWidth || "120";
      return {
        maxWidth: "".concat(maxWith, "px")
      };
    });
    vue.onMounted(function () {
      isCutOff.value = utils_dom.isNodeOverflow(breadcrumbText.value);
    });
    vue.onBeforeUpdate(function () {
      isCutOff.value = utils_dom.isNodeOverflow(breadcrumbText.value);
    });
    var separatorPropContent = localTBreadcrumb === null || localTBreadcrumb === void 0 ? void 0 : localTBreadcrumb.separator;
    var separatorSlot = localTBreadcrumb === null || localTBreadcrumb === void 0 ? void 0 : (_localTBreadcrumb$slo = localTBreadcrumb.slots) === null || _localTBreadcrumb$slo === void 0 ? void 0 : _localTBreadcrumb$slo.separator;
    var separatorContent = separatorPropContent || separatorSlot || vue.createVNode(ChevronRightIcon, {
      color: "rgba(0,0,0,.3)"
    }, null);
    var _getCurrentInstance = vue.getCurrentInstance(),
      proxy = _getCurrentInstance.proxy;
    var bindEvent = function bindEvent(e) {
      if (!props2.disabled) {
        e.preventDefault();
        if (props2.href) window.location.href = props2.href;
        var router = props2.router || proxy.$root.$router;
        if (props2.to && router) props2.replace ? router.replace(props2.to) : router.push(props2.to);
      }
    };
    return function () {
      var renderTNodeJSX = hooks_tnode.useTNodeJSX();
      var itemClass = [COMPONENT_NAME.value, themeClassName.value];
      var textClass = [textFlowClass.value];
      if (props2.disabled) textClass.push(disableClass.value);
      var listeners = {
        onClick: function onClick(e) {
          var _props2$onClick;
          if (props2.disabled) {
            e.stopPropagation();
            return;
          }
          (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, {
            e: e
          });
        }
      };
      var textContent = vue.createVNode("span", {
        "class": maxLengthClass.value,
        style: maxWithStyle.value
      }, [renderTNodeJSX("icon"), vue.createVNode("span", {
        "ref": breadcrumbText,
        "class": "".concat(maxLengthClass.value, "-text")
      }, [renderTNodeJSX("default")])]);
      var itemContent = vue.createVNode("span", _objectSpread({
        "class": textClass
      }, listeners), [textContent]);
      if ((props2.href || props2.to) && !props2.disabled) {
        textClass.push(linkClass.value);
        itemContent = vue.createVNode("a", vue.mergeProps({
          "class": textClass,
          "href": props2.href,
          "target": props2.target
        }, listeners, {
          "onClick": bindEvent
        }), [textContent]);
      }
      return vue.createVNode("div", vue.mergeProps({
        "class": itemClass
      }, attrs), [isCutOff.value ? vue.createVNode(tooltip_index.Tooltip, {
        "content": function content() {
          return slots === null || slots === void 0 ? void 0 : slots["default"]();
        }
      }, _isSlot(itemContent) ? itemContent : {
        "default": function _default() {
          return [itemContent];
        }
      }) : itemContent, vue.createVNode("span", {
        "class": separatorClass.value
      }, [isFunction__default["default"](separatorContent) ? separatorContent() : separatorContent])]);
    };
  }
});

exports["default"] = _BreadcrumbItem;
//# sourceMappingURL=breadcrumb-item.js.map
