/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var helper = require('../../chunks/helper.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var iconsVue = require('@ldesign/icons-vue');
var components_tooltip_index = require('../tooltip/index.js');
var components_breadcrumb_props = require('./props.js');
var utils_dom = require('../../utils/dom.js');
var components_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('../../chunks/set-style.js');
require('../../utils/render-node.js');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../popup/container.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/map-props.js');
require('../../utils/with-install.js');
require('../../config.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 localLBreadcrumbOrigin = {
  separator: "",
  theme: "light",
  $slots: {
    separator: ""
  },
  maxItemWidth: void 0
};
var _BreadcrumbItem = utils_mixins["default"](components_configProvider_configReceiver.getClassPrefixMixins("breadcrumb"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LBreadcrumbItem",
  props: _objectSpread({}, components_breadcrumb_props.BreadcrumbItemProps),
  inject: ["LBreadcrumb"],
  data: function data() {
    return {
      localTBreadcrumb: localLBreadcrumbOrigin,
      themeClassName: "",
      $router: null,
      isCutOff: false
    };
  },
  components: {
    LTooltip: components_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: {
    LBreadcrumb: {
      immediate: true,
      handler: function handler(v) {
        this.localTBreadcrumb = v;
      }
    }
  },
  created: function created() {
    var LBreadcrumb = this.localTBreadcrumb;
    this.themeClassName = LBreadcrumb.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: iconsVue.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("l-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
