"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Step", {
    enumerable: true,
    get: function() {
        return Step;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _define_property = require("@swc/helpers/_/_define_property");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _components = require("@tarojs/components");
var _context = require("../steps/context");
var _typings = require("../../utils/typings");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    title: '',
    description: '',
    value: 0,
    icon: null
});
var Step = function Step(props) {
    var _$_object_spread = (0, _object_spread._)({}, defaultProps, props), type = _$_object_spread.type, title = _$_object_spread.title, description = _$_object_spread.description, value = _$_object_spread.value, icon = _$_object_spread.icon, className = _$_object_spread.className, style = _$_object_spread.style;
    var parent = (0, _react.useContext)(_context.DataContext);
    var _parent_propSteps = parent.propSteps, parentType = _parent_propSteps.type, parentValue = _parent_propSteps.value, status = _parent_propSteps.status, parentIcon = _parent_propSteps.icon, onStepClick = _parent_propSteps.onStepClick;
    var currentStatus = (0, _react.useMemo)(function() {
        if ([
            'default',
            'business'
        ].includes(status)) {
            return status;
        }
        if (value < +parentValue) return 'finish';
        return value === +parentValue ? 'process' : 'wait';
    }, [
        value,
        parentValue,
        status
    ]);
    var handleClickStep = (0, _react.useCallback)(function() {
        onStepClick === null || onStepClick === void 0 ? void 0 : onStepClick(value);
    }, [
        onStepClick,
        value
    ]);
    var classPrefix = "nut-step";
    // className计算
    var classes = (0, _react.useMemo)(function() {
        var _obj;
        return (0, _classnames.default)(classPrefix, (_obj = {}, (0, _define_property._)(_obj, "".concat(classPrefix, "-").concat(currentStatus), true), (0, _define_property._)(_obj, "".concat(classPrefix, "-").concat(type || parentType), true), (0, _define_property._)(_obj, "".concat(classPrefix, "-special"), description), _obj), className);
    }, [
        currentStatus,
        type,
        className,
        description,
        classPrefix,
        parentType
    ]);
    // 头部渲染
    var renderHeadType = (0, _react.useMemo)(function() {
        switch(type || parentType){
            case 'text':
                return /*#__PURE__*/ _react.default.createElement(_components.View, {
                    className: "".concat(classPrefix, "-head-text")
                }, value);
            case 'dot':
                return /*#__PURE__*/ _react.default.createElement(_components.View, {
                    className: "".concat(classPrefix, "-head-dot")
                });
            case 'icon':
                return /*#__PURE__*/ _react.default.createElement(_components.View, {
                    className: "".concat(classPrefix, "-head-icon")
                }, icon || parentIcon);
            default:
                return null;
        }
    }, [
        type,
        value,
        icon,
        parentIcon,
        parentType,
        classPrefix
    ]);
    // 内容渲染
    var renderContent = (0, _react.useMemo)(function() {
        if (!title && !description) return null;
        return /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "".concat(classPrefix, "-main")
        }, title && /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "".concat(classPrefix, "-title")
        }, title), description && /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "".concat(classPrefix, "-description")
        }, description));
    }, [
        title,
        description,
        classPrefix
    ]);
    return /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: classes,
        style: style,
        onClick: handleClickStep
    }, /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-head")
    }, /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-head-").concat(type || parentType, "-wrap")
    }, renderHeadType)), /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-line")
    }, /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-line-inner")
    })), renderContent);
};
Step.displayName = 'NutStep';
