/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-1ec74b8b.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { ChevronRightIcon } from 'tdesign-icons-vue';
import { prefix } from '../config.js';
import { Tooltip } from '../tooltip/index.js';
import props from './breadcrumb-item-props.js';
import { isNodeOverflow } from '../utils/dom.js';
import '../tooltip/tooltip.js';
import '../tooltip/props.js';
import '../popup/props.js';
import '../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import '../utils/classnames.js';
import '../utils/render-tnode.js';
import 'lodash/isObject';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../_common/js/utils/set-style.js';
import '../popup/container.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../tooltip/type.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';

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 name = "".concat(prefix, "-breadcrumb__item");
var separatorClass = "".concat(prefix, "-breadcrumb__separator");
var disableClass = "".concat(prefix, "-is-disabled");
var linkClass = "".concat(prefix, "-link");
var maxLengthClass = "".concat(prefix, "-breadcrumb__inner");
var textFlowClass = "".concat(prefix, "-breadcrumb--text-overflow");
var gestureClass = "".concat(prefix, "-gestureClass");
var localTBreadcrumbOrigin = {
  separator: "",
  theme: "light",
  $slots: {
    separator: ""
  },
  maxItemWidth: void 0
};
var _BreadcrumbItem = Vue.extend({
  name: "TBreadcrumbItem",
  props: _objectSpread({}, props),
  inject: ["tBreadcrumb"],
  data: function data() {
    return {
      localTBreadcrumb: localTBreadcrumbOrigin,
      themeClassName: "",
      $router: null,
      isCutOff: false
    };
  },
  components: {
    Tooltip: 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 = isNodeOverflow(this.$refs.breadcrumbText);
  },
  beforeUpdate: function beforeUpdate() {
    this.isCutOff = 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 separator = localTBreadcrumb.separator;
    var separatorSlot = localTBreadcrumb.$slots.separator;
    var separatorPropContent = typeof separator === "function" ? separator() : separator;
    var separatorContent = separatorPropContent || separatorSlot || h(ChevronRightIcon);
    var itemClass = [name, this.themeClassName];
    var textClass = [textFlowClass];

    if (disabled) {
      textClass.push(disableClass);
    }

    if (this.$listeners.click) {
      textClass.push(gestureClass);
    }

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

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

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

export { _BreadcrumbItem as default };
//# sourceMappingURL=breadcrumb-item.js.map
