/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-42d5c87e.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { prefix } from '../config.js';
import props from './props.js';
import _StepItem from './step-item.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import { emitEvent } from '../utils/event.js';
import 'lodash/isFunction';
import 'tdesign-icons-vue';
import './step-item-props.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import '../config-provider/zh_CN_config.js';
import '../config-provider/type.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';

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 name = "".concat(prefix, "-steps");
var _Steps = mixins(getConfigReceiverMixins("steps")).extend({
  name: "TSteps",
  components: {
    TStepItem: _StepItem
  },
  props: _objectSpread({}, props),
  data: function data() {
    return {
      stepChildren: [],
      indexMap: {}
    };
  },
  provide: function provide() {
    return {
      steps: this
    };
  },
  watch: {
    options: {
      immediate: true,
      handler: function handler() {
        var _this = this;

        if (!this.options) return;
        this.options.forEach(function (item, index) {
          if (item.value !== void 0) {
            _this.indexMap[item.value] = index;
          }
        });
      }
    }
  },
  computed: {
    baseClass: function baseClass() {
      if (this.direction) {
        console.warn("TDesign Steps Warn: `direction` is going to be deprecated. please use `layout` instead. ");
      }

      var layout = this.layout || this.direction || "horizontal";
      return [name, "".concat(name, "--").concat(layout), "".concat(name, "--").concat(this.handleTheme(), "-anchor"), _defineProperty({}, "".concat(name, "--").concat(this.sequence), layout === "vertical")];
    }
  },
  render: function render() {
    var _this2 = this;

    var h = arguments[0];
    var options = this.getOptions();
    var content = options.map(function (item, index) {
      return h("t-step-item", helper([{}, {
        "props": _objectSpread(_objectSpread({}, item), {}, {
          status: _this2.handleStatus(item, index)
        })
      }, {
        "key": item.value || index
      }]));
    });
    return h("div", {
      "class": this.baseClass
    }, [content]);
  },
  methods: {
    getOptions: function getOptions() {
      var options;

      if (this.options && this.options.length) {
        options = this.options;
      } else {
        var nodes = this.$scopedSlots["default"] && this.$scopedSlots["default"](null);
        options = this.getOptionListBySlots(nodes);
      }

      return options;
    },
    getOptionListBySlots: function getOptionListBySlots(nodes) {
      var arr = [];
      nodes === null || nodes === void 0 ? void 0 : nodes.forEach(function (node) {
        var _node$componentOption;

        var option = node === null || node === void 0 ? void 0 : (_node$componentOption = node.componentOptions) === null || _node$componentOption === void 0 ? void 0 : _node$componentOption.propsData;
        option && arr.push(option);
      });
      return arr;
    },
    handleTheme: function handleTheme() {
      var theme = this.theme;
      var options = this.getOptions();
      options.forEach(function (item) {
        if ((item === null || item === void 0 ? void 0 : item.icon) !== void 0) {
          theme = "default";
        }
      });
      return theme;
    },
    handleStatus: function handleStatus(item, index) {
      if (item.status && item.status !== "default") return item.status;
      if (this.current === "FINISH") return "finish";
      if (item.value === void 0 && index < this.current) return "finish";

      if (item.value !== void 0) {
        var matchIndex = this.indexMap[this.current];

        if (matchIndex === void 0) {
          console.warn("TDesign Steps Warn: The current `value` is not exist.");
          return "default";
        }

        if (index < matchIndex) return "finish";
      }

      var key = item.value === void 0 ? index : item.value;
      if (key === this.current) return "process";
      return "default";
    },
    addItem: function addItem(item) {
      var index = this.stepChildren.length;
      item.index = index;
      this.stepChildren.push(item);
    },
    removeItem: function removeItem(item) {
      this.stepChildren = this.stepChildren.filter(function (t) {
        return t !== item;
      });
    },
    handleChange: function handleChange(cur, prev, e) {
      emitEvent(this, "change", cur, prev, {
        e: e
      });
    }
  }
});

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