/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var helper = require('../_chunks/dep-d7a1e02c.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var tdesignIconsVue = require('tdesign-icons-vue');
var tooltip_index = require('../tooltip/index.js');
var breadcrumb_breadcrumbItemProps = require('./breadcrumb-item-props.js');
var utils_dom = require('../utils/dom.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
require('../tooltip/tooltip.js');
require('lodash/isFunction');
require('../tooltip/props.js');
require('../popup/props.js');
require('../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../utils/render-tnode.js');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../_common/js/utils/set-style.js');
require('../popup/container.js');
require('raf');
require('../utils/map-props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('lodash/isString');
require('../utils/easing.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');

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

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

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; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("breadcrumb");
var localTBreadcrumbOrigin = {
  separator: "",
  theme: "light",
  $slots: {
    separator: ""
  },
  maxItemWidth: void 0
};
var _BreadcrumbItem = utils_mixins["default"](classPrefixMixins, configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TBreadcrumbItem",
  props: _objectSpread({}, breadcrumb_breadcrumbItemProps["default"]),
  inject: ["tBreadcrumb"],
  data: function data() {
    return {
      localTBreadcrumb: localTBreadcrumbOrigin,
      themeClassName: "",
      $router: null,
      isCutOff: false
    };
  },
  components: {
    Tooltip: tooltip_index.Tooltip
  },
  computed: {
    maxWithStyle: function maxWithStyle() {
      var localTBreadcrumb = this.localTBreadcrumb;
      var maxItemWidth = localTBreadcrumb.maxItemWidth;
      var maxWith = this.maxWidth || maxItemWidth || "120";
      return {
        "max-width": "".concat(maxWith, "px")
      };
    }
  },
  watch: {
    tBreadcrumb: {
      immediate: true,
      handler: function handler(v) {
        this.localTBreadcrumb = v;
      }
    }
  },
  created: function created() {
    var tBreadcrumb = this.localTBreadcrumb;
    this.themeClassName = tBreadcrumb.theme;
  },
  mounted: function mounted() {
    this.isCutOff = utils_dom.isNodeOverflow(this.$refs.breadcrumbText);
  },
  beforeUpdate: function beforeUpdate() {
    this.isCutOff = utils_dom.isNodeOverflow(this.$refs.breadcrumbText);
  },
  methods: {
    bindEvent: function bindEvent() {
      var to = this.to;
      var router = this.router || this.$router;

      if (to && router) {
        this.replace ? router.replace(to) : router.push(to);
      }
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var localTBreadcrumb = this.localTBreadcrumb,
        href = this.href,
        target = this.target,
        to = this.to,
        disabled = this.disabled;

    var _this$useGlobalIcon = this.useGlobalIcon({
      ChevronRightIcon: tdesignIconsVue.ChevronRightIcon
    }),
        ChevronRightIcon = _this$useGlobalIcon.ChevronRightIcon;

    var separator = localTBreadcrumb.separator;
    var separatorSlot = localTBreadcrumb.$slots.separator;
    var separatorPropContent = typeof separator === "function" ? separator() : separator;
    var separatorContent = separatorPropContent || separatorSlot || h(ChevronRightIcon);
    var itemClass = ["".concat(this.componentName, "__item"), this.themeClassName];
    var textClass = ["".concat(this.componentName, "--text-overflow")];

    if (disabled) {
      textClass.push("".concat(this.classPrefix, "-is-disabled"));
    }

    if (this.$listeners.click) {
      textClass.push("".concat(this.classPrefix, "-gestureClass"));
    }

    var clickEvent = to && !disabled ? {
      on: {
        click: this.bindEvent
      }
    } : {};
    var textContent = h("span", {
      "ref": "breadcrumbText",
      "class": "".concat(this.componentName, "__inner"),
      "style": this.maxWithStyle
    }, [this.$slots["default"]]);
    var itemContent = h("span", helper.helper([{
      "class": textClass,
      "on": _objectSpread({}, this.$listeners)
    }, clickEvent]), [textContent]);

    if (href && !disabled) {
      textClass.push("".concat(this.classPrefix, "-link"));
      itemContent = h("a", {
        "class": textClass,
        "attrs": {
          "href": href,
          "target": target
        },
        "on": _objectSpread({}, this.$listeners)
      }, [textContent]);
    }

    return h("div", {
      "class": itemClass
    }, [this.isCutOff ? h(tooltip_index.Tooltip, {
      "attrs": {
        "content": function content() {
          return _this.$slots["default"];
        }
      }
    }, [itemContent]) : itemContent, h("span", {
      "class": "".concat(this.componentName, "__separator")
    }, [separatorContent])]);
  }
});

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