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

'use strict';

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

var helper = require('../_chunks/dep-33ee4bce.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var tdesignIconsVue = require('tdesign-icons-vue');
var config = require('../config.js');
var tooltip_index = require('../tooltip/index.js');
var breadcrumb_breadcrumbItemProps = require('./breadcrumb-item-props.js');
var utils_dom = require('../utils/dom.js');
require('../tooltip/tooltip.js');
require('../tooltip/props.js');
require('../popup/props.js');
require('../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../utils/classnames.js');
require('../utils/render-tnode.js');
require('lodash/isObject');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../_common/js/utils/set-style.js');
require('../popup/container.js');
require('../utils/map-props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('raf');
require('lodash/isString');
require('../utils/easing.js');

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

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

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 name = "".concat(config.prefix, "-breadcrumb__item");
var separatorClass = "".concat(config.prefix, "-breadcrumb__separator");
var disableClass = "".concat(config.prefix, "-is-disabled");
var linkClass = "".concat(config.prefix, "-link");
var maxLengthClass = "".concat(config.prefix, "-breadcrumb__inner");
var textFlowClass = "".concat(config.prefix, "-breadcrumb--text-overflow");
var gestureClass = "".concat(config.prefix, "-gestureClass");
var localTBreadcrumbOrigin = {
  separator: "",
  theme: "light",
  $slots: {
    separator: ""
  },
  maxItemWidth: void 0
};
var _BreadcrumbItem = Vue__default["default"].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 separator = localTBreadcrumb.separator;
    var separatorSlot = localTBreadcrumb.$slots.separator;
    var separatorPropContent = typeof separator === "function" ? separator() : separator;
    var separatorContent = separatorPropContent || separatorSlot || h(tdesignIconsVue.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.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_index.Tooltip, {
      "attrs": {
        "content": function content() {
          return _this.$slots["default"];
        }
      }
    }, [itemContent]) : itemContent, h("span", {
      "class": separatorClass
    }, [separatorContent])]);
  }
});

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