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

import { _ as _slicedToArray } from '../_chunks/dep-84acf3c2.mjs';
import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, toRefs, provide, reactive, ref, createVNode, mergeProps, computed } from 'vue';
import { i as isObject_1 } from '../_chunks/dep-a8bcacea.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import useVModel from '../hooks/useVModel.mjs';
import '../hooks/index.mjs';
import props from './props.mjs';
import stepItemProps from './step-item-props.mjs';
import _StepItem from './step-item.mjs';
import { useChildComponentSlots } from '../hooks/slot.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../hooks/icon.mjs';
import '../hooks/tnode.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDefaultValue.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '@ldesign/icons-vue-next';
import '../hooks/useGlobalIcon.mjs';

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 _Steps = defineComponent({
  name: "TSteps",
  props: _objectSpread({}, props),
  setup: function setup(props2) {
    var COMPONENT_NAME = usePrefixClass("steps");
    var _toRefs = toRefs(props2),
      current = _toRefs.current,
      modelValue = _toRefs.modelValue;
    var _useVModel = useVModel(current, modelValue, props2.defaultCurrent, props2.onChange, "current"),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      innerCurrent = _useVModel2[0],
      setInnerCurrent = _useVModel2[1];
    provide("StepsState", reactive({
      current: innerCurrent,
      setCurrent: setInnerCurrent
    }));
    provide("StepsProps", props2);
    var indexMap = ref({});
    var handleStatus = function handleStatus(itemProps, index) {
      if (itemProps.status && itemProps.status !== "default") return itemProps.status;
      if (innerCurrent.value === "FINISH") return "finish";
      if (itemProps.value === void 0 && index < innerCurrent.value) return "finish";
      if (itemProps.value !== void 0) {
        var matchIndex = indexMap.value[innerCurrent.value];
        if (matchIndex === void 0) {
          console.warn("TDesign Steps Warn: The current `value` is not exist.");
          return "default";
        }
        if (props2.sequence === "positive" && index < matchIndex) return "finish";
        if (props2.sequence === "reverse" && index > matchIndex) return "finish";
      }
      var key = itemProps.value === void 0 ? index : itemProps.value;
      if (key === innerCurrent.value) return "process";
      return "default";
    };
    var getChildComponentByName = useChildComponentSlots();
    var getOptionListBySlots = function getOptionListBySlots(nodes) {
      var arr = [];
      nodes === null || nodes === void 0 ? void 0 : nodes.forEach(function (node) {
        var option = (node === null || node === void 0 ? void 0 : node.props) || {};
        var children = node === null || node === void 0 ? void 0 : node.children;
        if (!option && !children) return;
        if (children && isObject_1(children)) {
          for (var key in children) {
            if (key in stepItemProps && !option[key]) option[key] = children[key];
          }
        }
        props2.sequence === "reverse" ? arr.unshift(option) : arr.push(option);
      });
      return arr;
    };
    var getOptions = function getOptions() {
      var _props2$options;
      var options;
      if ((_props2$options = props2.options) !== null && _props2$options !== void 0 && _props2$options.length) {
        options = props2.sequence === "reverse" ? props2.options.slice().reverse() : props2.options;
      } else {
        var nodes = getChildComponentByName("StepItem");
        options = getOptionListBySlots(nodes);
      }
      (options || []).forEach(function (item, index) {
        if (item.value !== void 0) indexMap.value[item.value] = index;
      });
      return options;
    };
    var renderContent = function renderContent() {
      var options = getOptions();
      return options.map(function (item, index) {
        var stepIndex = props2.sequence === "reverse" ? options.length - index - 1 : index;
        index = item.value !== void 0 ? index : stepIndex;
        return createVNode(_StepItem, mergeProps(item, {
          "index": stepIndex,
          "status": handleStatus(item, index),
          "key": item.value || index
        }), null);
      });
    };
    var handleTheme = function handleTheme() {
      var theme = props2.theme;
      var options = getOptions();
      options.forEach(function (item) {
        if ((item === null || item === void 0 ? void 0 : item.icon) !== void 0) {
          theme = "default";
        }
      });
      return theme;
    };
    var baseClass = computed(function () {
      return [COMPONENT_NAME.value, "".concat(COMPONENT_NAME.value, "--").concat(props2.layout), "".concat(COMPONENT_NAME.value, "--").concat(handleTheme(), "-anchor"), "".concat(COMPONENT_NAME.value, "--").concat(props2.sequence), "".concat(COMPONENT_NAME.value, "--").concat(props2.separator, "-separator")];
    });
    return function () {
      return createVNode("div", {
        "class": baseClass.value
      }, [renderContent()]);
    };
  }
});

export { _Steps as default };
//# sourceMappingURL=steps.mjs.map
