/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var isFunction = require('lodash/isFunction');
var iconsVue = require('@ldesign/icons-vue');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_steps_props = require('./props.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

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

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

var _StepItem = utils_mixins["default"](components_configProvider_configReceiver["default"]("steps"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LStepItem",
  props: {
    ...components_steps_props.StepsItemProps,
    index: Number
  },
  inject: {
    steps: {
      default: void 0
    }
  },
  computed: {
    current() {
      return this.steps && this.steps.current;
    },
    baseClass() {
      return [`${this.componentName}-item`, {
        [`${this.componentName}-item--${this.status}`]: this.status
      }];
    },
    iconClass() {
      return [`${this.componentName}-item__icon`, {
        [`${this.componentName}-item--${this.status}`]: this.status
      }];
    },
    canClick() {
      var _this$steps;
      return this.status !== "process" && !((_this$steps = this.steps) !== null && _this$steps !== void 0 && _this$steps.readonly);
    }
  },
  methods: {
    renderIcon() {
      const h = this.$createElement;
      let defaultIcon;
      if (this.steps.theme === "default") {
        let icon = "";
        const {
          CheckIcon,
          CloseIcon
        } = this.useGlobalIcon({
          CheckIcon: iconsVue.CheckIcon,
          CloseIcon: iconsVue.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": `${this.componentName}-item__icon--number`
        }, [icon]);
      }
      return utils_renderNode.renderLNodeJSX(this, "icon", defaultIcon);
    },
    onStepClick(e) {
      if (!this.canClick) return;
      const val = this.value === void 0 ? this.index : this.value;
      this.steps.handleChange(val, this.current, e);
    }
  },
  render() {
    const h = arguments[0];
    const content = utils_renderNode.renderContent(this, "default", "content");
    return h("div", {
      "class": this.baseClass
    }, [h("div", {
      "class": `${this.componentName}-item__inner ${this.canClick ? `${this.componentName}-item--clickable` : ""}`,
      "on": {
        "click": this.onStepClick
      }
    }, [h("div", {
      "class": this.iconClass
    }, [this.renderIcon()]), h("div", {
      "class": `${this.componentName}-item__content`
    }, [h("div", {
      "class": `${this.componentName}-item__title`
    }, [utils_renderNode.renderLNodeJSX(this, "title")]), h("div", {
      "class": `${this.componentName}-item__description`
    }, [content]), h("div", {
      "class": `${this.componentName}-item__extra`
    }, [utils_renderNode.renderLNodeJSX(this, "extra")])])])]);
  }
});

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