import { __assign, __rest } from "tslib";
import React, { useContext, useEffect, useState } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { StepsContext } from './steps-context';
var Steps = React.forwardRef(function (props, ref) {
    var _a = props.defaultCurrent, defaultCurrent = _a === void 0 ? 0 : _a, _b = props.status, status = _b === void 0 ? 'process' : _b, _c = props.direction, direction = _c === void 0 ? 'horizontal' : _c, _d = props.labelPlacement, labelPlacement = _d === void 0 ? 'vertical' : _d, onChange = props.onChange, className = props.className, children = props.children, customisedCls = props.prefixCls, otherProps = __rest(props, ["defaultCurrent", "status", "direction", "labelPlacement", "onChange", "className", "children", "prefixCls"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('steps', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, prefixCls + "_" + direction);
    var _e = useState('current' in props ? props.current : defaultCurrent), current = _e[0], setCurrent = _e[1];
    var itemOnClick = function (curr) {
        !('current' in props) && setCurrent(curr);
        onChange && onChange(curr);
    };
    useEffect(function () {
        'current' in props && setCurrent(props.current);
    }, [props]);
    return (React.createElement(StepsContext.Provider, { value: {
            current: current,
            labelPlacement: labelPlacement,
            status: status,
            clickable: 'onChange' in props,
            onClick: itemOnClick,
        } },
        React.createElement("div", __assign({}, otherProps, { ref: ref, className: cls }), React.Children.map(children, function (child, idx) {
            var childElement = child;
            if (childElement.type.displayName === 'StepsItem') {
                var childProps = {
                    stepIndex: idx,
                };
                return React.cloneElement(childElement, childProps);
            }
            else {
                console.warn('Steps has a child that is not a Step component.');
                return null;
            }
        }))));
});
Steps.displayName = 'Steps';
export default Steps;
//# sourceMappingURL=steps.js.map