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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var loading_index = require('../loading/index.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var timeline_utils = require('./utils.js');
var timeline_timelineItemProps = require('./timeline-item-props.js');
require('../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../config.js');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../config-provider/config-receiver.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');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../config-provider/useConfig.js');
require('../_common/js/log/log.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 DEFAULT_THEME = ["primary", "warning", "error", "default"];
var _TimelineItem = VueCompositionAPI.defineComponent({
  name: "TTimelineItem",
  components: {
    TLoading: loading_index.Loading
  },
  props: _objectSpread({}, timeline_timelineItemProps["default"]),
  setup: function setup(props, context) {
    var instance = VueCompositionAPI.getCurrentInstance();
    var classPrefix = hooks_useConfig.usePrefixClass();
    var timelineProvider = VueCompositionAPI.inject("TTimeline", {
      layout: "vertical",
      reverse: false,
      theme: void 0,
      labelAlign: "left",
      mode: "alternate",
      uidArr: VueCompositionAPI.ref([])
    });
    var layout = timelineProvider.layout,
      reverse = timelineProvider.reverse,
      theme = timelineProvider.theme,
      labelAlign = timelineProvider.labelAlign,
      mode = timelineProvider.mode,
      uidArr = timelineProvider.uidArr;
    var _toRefs = VueCompositionAPI.toRefs(props),
      dotColor = _toRefs.dotColor,
      itemLabelAlign = _toRefs.labelAlign,
      loading = _toRefs.loading;
    var timelineItemAlign = VueCompositionAPI.computed(function () {
      var _itemLabelAlign$value;
      return (_itemLabelAlign$value = itemLabelAlign.value) !== null && _itemLabelAlign$value !== void 0 ? _itemLabelAlign$value : timeline_utils["default"](labelAlign === null || labelAlign === void 0 ? void 0 : labelAlign.value, layout === null || layout === void 0 ? void 0 : layout.value);
    });
    var currentIndex = VueCompositionAPI.computed(function () {
      var index = 0;
      uidArr.value.forEach(function (item, itemIndex) {
        if (item === instance.uid) index = itemIndex;
      });
      return index;
    });
    var positionClassName = VueCompositionAPI.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 = VueCompositionAPI.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 = VueCompositionAPI.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 = VueCompositionAPI.computed(function () {
      return Boolean(context.slots.dot || props.dot);
    });
    var dotClassName = VueCompositionAPI.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 = VueCompositionAPI.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 = utils_renderTnode.renderTNodeJSX(this, "dot");
    var labelNode = utils_renderTnode.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_index.Loading, {
      "attrs": {
        "size": "12px"
      },
      "class": dotContentClass
    }), dotElement]), h("div", {
      "class": tailClassName
    })]), h("div", {
      "class": "".concat(classPrefix, "-timeline-item__content")
    }, [utils_renderTnode.renderContent(this, "content", "default"), mode === "same" && labelNode && h("div", {
      "class": labelClassName
    }, [labelNode])])]);
  }
});

exports["default"] = _TimelineItem;
//# sourceMappingURL=timeline-item.js.map
