/**
 * tdesign v0.32.0
 * (c) 2021 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 config = require('../config.js');
var steps_stepItemProps = require('./step-item-props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
require('vue');
require('../config-provider/zh_CN_config.js');
require('@babel/runtime/helpers/typeof');

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 name = "".concat(config.prefix, "-steps-item");
var _StepItem = utils_mixins["default"](configProvider_configReceiver["default"]("steps")).extend({
  name: "TStepItem",
  props: _objectSpread({}, steps_stepItemProps["default"]),
  components: {
    TIconCheck: tdesignIconsVue.CheckIcon,
    TIconClose: tdesignIconsVue.CloseIcon
  },
  inject: {
    steps: {
      "default": void 0
    }
  },
  data: function data() {
    return {
      index: -1
    };
  },
  computed: {
    current: function current() {
      return this.steps && this.steps.current;
    },
    baseClass: function baseClass() {
      return [name, _defineProperty__default["default"]({}, "".concat(name, "--").concat(this.status), this.status)];
    },
    iconClass: function iconClass() {
      return ["".concat(name, "__icon"), _defineProperty__default["default"]({}, "".concat(name, "--").concat(this.status), this.status)];
    },
    canClick: function canClick() {
      return this.status !== "process";
    }
  },
  mounted: function mounted() {
    this.steps.addItem(this);
  },
  destroyed: function destroyed() {
    this.steps.removeItem(this);
  },
  methods: {
    renderIcon: function renderIcon() {
      var h = this.$createElement;
      var defaultIcon;

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

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

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

            break;

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

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

      return utils_renderTnode.renderTNodeJSX(this, "icon", defaultIcon);
    },
    onStepClick: function onStepClick(e) {
      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(name, "__inner ").concat(this.canClick ? "".concat(name, "--clickable") : ""),
      "on": {
        "click": this.onStepClick
      }
    }, [h("div", {
      "class": this.iconClass
    }, [this.renderIcon()]), h("div", {
      "class": "".concat(name, "__content")
    }, [h("div", {
      "class": "".concat(name, "__title")
    }, [utils_renderTnode.renderTNodeJSX(this, "title")]), h("div", {
      "class": "".concat(name, "__description")
    }, [content]), h("div", {
      "class": "".concat(name, "__extra")
    }, [utils_renderTnode.renderTNodeJSX(this, "extra")])])])]);
  }
});

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