/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, getCurrentInstance, inject, ref, toRefs, computed } from '@vue/composition-api';
import { Loading } from '../loading/index.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import getRenderAlign from './utils.js';
import TimelineItemProps from './timeline-item-props.js';
import '../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/transfer-dom.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';
import '../utils/mixins.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../config-provider/useConfig.js';
import '../_common/js/log/log.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 DEFAULT_THEME = ["primary", "warning", "error", "default"];
var _TimelineItem = defineComponent({
  name: "TTimelineItem",
  components: {
    TLoading: Loading
  },
  props: _objectSpread({}, TimelineItemProps),
  setup: function setup(props, context) {
    var instance = getCurrentInstance();
    var classPrefix = usePrefixClass();
    var timelineProvider = inject("TTimeline", {
      layout: "vertical",
      reverse: false,
      theme: void 0,
      labelAlign: "left",
      mode: "alternate",
      uidArr: ref([])
    });
    var layout = timelineProvider.layout,
      reverse = timelineProvider.reverse,
      theme = timelineProvider.theme,
      labelAlign = timelineProvider.labelAlign,
      mode = timelineProvider.mode,
      uidArr = timelineProvider.uidArr;
    var _toRefs = toRefs(props),
      dotColor = _toRefs.dotColor,
      itemLabelAlign = _toRefs.labelAlign,
      loading = _toRefs.loading;
    var timelineItemAlign = computed(function () {
      var _itemLabelAlign$value;
      return (_itemLabelAlign$value = itemLabelAlign.value) !== null && _itemLabelAlign$value !== void 0 ? _itemLabelAlign$value : getRenderAlign(labelAlign === null || labelAlign === void 0 ? void 0 : labelAlign.value, layout === null || layout === void 0 ? void 0 : layout.value);
    });
    var currentIndex = computed(function () {
      var index = 0;
      uidArr.value.forEach(function (item, itemIndex) {
        if (item === instance.uid) index = itemIndex;
      });
      return index;
    });
    var positionClassName = computed(function () {
      var left = (layout === null || layout === void 0 ? void 0 : layout.value) === "horizontal" ? "top" : "left";
      var right = (layout === null || layout === void 0 ? void 0 : layout.value) === "horizontal" ? "bottom" : "right";
      if (timelineItemAlign.value === "alternate") {
        return currentIndex.value % 2 === 0 ? "".concat(classPrefix.value, "-timeline-item-").concat(left) : "".concat(classPrefix.value, "-timeline-item-").concat(right);
      }
      if (timelineItemAlign.value === "left" || timelineItemAlign.value === "top") return "".concat(classPrefix.value, "-timeline-item-").concat(left);
      if (timelineItemAlign.value === "right" || timelineItemAlign.value === "bottom") return "".concat(classPrefix.value, "-timeline-item-").concat(right);
      return "";
    });
    var getItemClassName = computed(function () {
      var isLastChildren = uidArr.value.length - 1 === currentIndex.value;
      var lastClassName = isLastChildren ? "".concat(classPrefix.value, "-timeline-item--last") : "";
      return "".concat(classPrefix.value, "-timeline-item ").concat(positionClassName.value, " ").concat(lastClassName);
    });
    var tailClassName = computed(function () {
      var statusClassName = reverse ? "".concat(classPrefix.value, "-timeline-item__tail--status-").concat(dotColor === null || dotColor === void 0 ? void 0 : dotColor.value) : "";
      return "".concat(classPrefix.value, "-timeline-item__tail ").concat(classPrefix.value, "-timeline-item__tail--theme-").concat(theme === null || theme === void 0 ? void 0 : theme.value, " ").concat(statusClassName);
    });
    var dotElement = computed(function () {
      return Boolean(context.slots.dot || props.dot);
    });
    var dotClassName = computed(function () {
      var dotCustomClassName = !!dotElement.value || !dotElement.value && loading !== null && loading !== void 0 && loading.value ? "".concat(classPrefix.value, "-timeline-item__dot--custom") : "";
      var docColorClassName = DEFAULT_THEME.includes(dotColor === null || dotColor === void 0 ? void 0 : dotColor.value) ? "".concat(classPrefix.value, "-timeline-item__dot--").concat(dotColor === null || dotColor === void 0 ? void 0 : dotColor.value) : "";
      return "".concat(classPrefix.value, "-timeline-item__dot ").concat(dotCustomClassName, " ").concat(docColorClassName);
    });
    var labelClassName = computed(function () {
      return "".concat(classPrefix.value, "-timeline-item__label ").concat(classPrefix.value, "-timeline-item__label--").concat(mode === null || mode === void 0 ? void 0 : mode.value);
    });
    return {
      mode: mode,
      currentIndex: currentIndex,
      tailClassName: tailClassName,
      dotClassName: dotClassName,
      labelClassName: labelClassName,
      getItemClassName: getItemClassName,
      classPrefix: classPrefix
    };
  },
  render: function render() {
    var _dotElement$;
    var h = arguments[0];
    var dotColor = this.dotColor,
      dotClassName = this.dotClassName,
      _this$style = this.style,
      style = _this$style === void 0 ? {} : _this$style,
      labelClassName = this.labelClassName,
      mode = this.mode,
      loading = this.loading,
      tailClassName = this.tailClassName,
      getItemClassName = this.getItemClassName,
      _this$classPrefix = this.classPrefix,
      classPrefix = _this$classPrefix === void 0 ? "t" : _this$classPrefix;
    var dotElement = renderTNodeJSX(this, "dot");
    var labelNode = renderTNodeJSX(this, "label");
    var dotContentClass = "".concat(classPrefix, "-timeline-item__dot-content");
    if (Array.isArray(dotElement) && (_dotElement$ = dotElement[0]) !== null && _dotElement$ !== void 0 && _dotElement$.data) {
      var classes = dotElement[0].data["class"];
      dotElement[0].data["class"] = classes ? [classes, dotContentClass].join(" ") : dotContentClass;
    }
    return h("li", {
      "class": getItemClassName,
      "style": style
    }, [mode === "alternate" && labelNode && h("div", {
      "class": labelClassName
    }, [labelNode]), h("div", {
      "class": "".concat(classPrefix, "-timeline-item__wrapper")
    }, [h("div", {
      "class": dotClassName,
      "style": {
        borderColor: !DEFAULT_THEME.includes(dotColor) && dotColor
      }
    }, [!dotElement && loading && h(Loading, {
      "attrs": {
        "size": "12px"
      },
      "class": dotContentClass
    }), dotElement]), h("div", {
      "class": tailClassName
    })]), h("div", {
      "class": "".concat(classPrefix, "-timeline-item__content")
    }, [renderContent(this, "content", "default"), mode === "same" && labelNode && h("div", {
      "class": labelClassName
    }, [labelNode])])]);
  }
});

export { _TimelineItem as default };
//# sourceMappingURL=timeline-item.js.map
