import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import React, { useCallback, useContext, useMemo } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { DataContext } from "../steps/context";
import { ComponentDefaults } from "../../utils/typings";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    title: '',
    description: '',
    value: 0,
    icon: null
});
export var Step = function(props) {
    var _$_object_spread = _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 = useContext(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 = useMemo(function() {
        if ([
            'default',
            'business'
        ].includes(status)) {
            return status;
        }
        if (value < +parentValue) return 'finish';
        return value === +parentValue ? 'process' : 'wait';
    }, [
        value,
        parentValue,
        status
    ]);
    var handleClickStep = useCallback(function() {
        onStepClick === null || onStepClick === void 0 ? void 0 : onStepClick(value);
    }, [
        onStepClick,
        value
    ]);
    var classPrefix = "nut-step";
    // className计算
    var classes = useMemo(function() {
        var _obj;
        return classNames(classPrefix, (_obj = {}, _define_property(_obj, "".concat(classPrefix, "-").concat(currentStatus), true), _define_property(_obj, "".concat(classPrefix, "-").concat(type || parentType), true), _define_property(_obj, "".concat(classPrefix, "-special"), description), _obj), className);
    }, [
        currentStatus,
        type,
        className,
        description,
        classPrefix,
        parentType
    ]);
    // 头部渲染
    var renderHeadType = useMemo(function() {
        switch(type || parentType){
            case 'text':
                return /*#__PURE__*/ React.createElement(View, {
                    className: "".concat(classPrefix, "-head-text")
                }, value);
            case 'dot':
                return /*#__PURE__*/ React.createElement(View, {
                    className: "".concat(classPrefix, "-head-dot")
                });
            case 'icon':
                return /*#__PURE__*/ React.createElement(View, {
                    className: "".concat(classPrefix, "-head-icon")
                }, icon || parentIcon);
            default:
                return null;
        }
    }, [
        type,
        value,
        icon,
        parentIcon,
        parentType,
        classPrefix
    ]);
    // 内容渲染
    var renderContent = useMemo(function() {
        if (!title && !description) return null;
        return /*#__PURE__*/ React.createElement(View, {
            className: "".concat(classPrefix, "-main")
        }, title && /*#__PURE__*/ React.createElement(View, {
            className: "".concat(classPrefix, "-title")
        }, title), description && /*#__PURE__*/ React.createElement(View, {
            className: "".concat(classPrefix, "-description")
        }, description));
    }, [
        title,
        description,
        classPrefix
    ]);
    return /*#__PURE__*/ React.createElement(View, {
        className: classes,
        style: style,
        onClick: handleClickStep
    }, /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-head")
    }, /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-head-").concat(type || parentType, "-wrap")
    }, renderHeadType)), /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-line")
    }, /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-line-inner")
    })), renderContent);
};
Step.displayName = 'NutStep';
