/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isFunction = require('lodash/isFunction');
var tdesignIconsVue = require('tdesign-icons-vue');
var utils_mixins = require('../utils/mixins.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var steps_stepItemProps = require('./step-item-props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
require('vue');
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('lodash/camelCase');
require('lodash/kebabCase');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

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 _StepItem = utils_mixins["default"](configProvider_configReceiver["default"]("steps"), configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TStepItem",
  props: _objectSpread(_objectSpread({}, steps_stepItemProps["default"]), {}, {
    index: Number
  }),
  inject: {
    steps: {
      "default": void 0
    }
  },
  computed: {
    current: function current() {
      return this.steps && this.steps.current;
    },
    baseClass: function baseClass() {
      return ["".concat(this.componentName, "-item"), _defineProperty__default["default"]({}, "".concat(this.componentName, "-item--").concat(this.status), this.status)];
    },
    iconClass: function iconClass() {
      return ["".concat(this.componentName, "-item__icon"), _defineProperty__default["default"]({}, "".concat(this.componentName, "-item--").concat(this.status), this.status)];
    },
    canClick: function canClick() {
      var _this$steps;

      return this.status !== "process" && !((_this$steps = this.steps) !== null && _this$steps !== void 0 && _this$steps.readonly);
    }
  },
  methods: {
    renderIcon: function renderIcon() {
      var h = this.$createElement;
      var defaultIcon;

      if (this.steps.theme === "default") {
        var icon = "";

        var _this$useGlobalIcon = this.useGlobalIcon({
          CheckIcon: tdesignIconsVue.CheckIcon,
          CloseIcon: tdesignIconsVue.CloseIcon
        }),
            CheckIcon = _this$useGlobalIcon.CheckIcon,
            CloseIcon = _this$useGlobalIcon.CloseIcon;

        switch (this.status) {
          case "finish":
            icon = h(CheckIcon);
            break;

          case "error":
            if (isFunction__default["default"](this.global.errorIcon)) {
              icon = this.global.errorIcon(this.$createElement);
            } else {
              icon = h(CloseIcon);
            }

            break;

          default:
            icon = String(this.index + 1);
            break;
        }

        defaultIcon = h("span", {
          "class": "".concat(this.componentName, "-item__icon--number")
        }, [icon]);
      }

      return utils_renderTnode.renderTNodeJSX(this, "icon", defaultIcon);
    },
    onStepClick: function onStepClick(e) {
      if (!this.canClick) return;
      var val = this.value === void 0 ? this.index : this.value;
      this.steps.handleChange(val, this.current, e);
    }
  },
  render: function render() {
    var h = arguments[0];
    var content = utils_renderTnode.renderContent(this, "default", "content");
    return h("div", {
      "class": this.baseClass
    }, [h("div", {
      "class": "".concat(this.componentName, "-item__inner ").concat(this.canClick ? "".concat(this.componentName, "-item--clickable") : ""),
      "on": {
        "click": this.onStepClick
      }
    }, [h("div", {
      "class": this.iconClass
    }, [this.renderIcon()]), h("div", {
      "class": "".concat(this.componentName, "-item__content")
    }, [h("div", {
      "class": "".concat(this.componentName, "-item__title")
    }, [utils_renderTnode.renderTNodeJSX(this, "title")]), h("div", {
      "class": "".concat(this.componentName, "-item__description")
    }, [content]), h("div", {
      "class": "".concat(this.componentName, "-item__extra")
    }, [utils_renderTnode.renderTNodeJSX(this, "extra")])])])]);
  }
});

exports["default"] = _StepItem;
//# sourceMappingURL=step-item.js.map
