"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* @flow */
const React = __importStar(require("react"));
{
    WizardStepsProps;
}
from;
'./types';
const classnames_1 = __importDefault(require("classnames"));
const lodash_1 = __importDefault(require("lodash"));
const prop_types_1 = __importDefault(require("prop-types"));
const withStyles_1 = __importDefault(require("components/hoc/withStyles"));
const ErrorBoundary_1 = __importDefault(require("components/hoc/ErrorBoundary"));
const styles_1 = __importDefault(require("./styles"));
class WizardSteps extends React.Component {
    constructor() {
        super(...arguments);
        this._getActiveStep = () => {
            const { steps } = this.props;
            return lodash_1.default.find(steps, { active: true });
        };
        this._renderStepComponent = () => {
            const activeStep = this._getActiveStep();
            if (!activeStep) {
                return null;
            }
            return activeStep.component;
        };
    }
    _renderSteps() {
        const { classes, steps, onStepClick } = this.props;
        return (React.createElement("div", { className: classes.steps }, steps.map((step, index) => {
            const isLastStep = steps.length - 1 === index;
            const stepClasses = classnames_1.default(classes.step, {
                [classes.lastStep]: isLastStep,
                active: step.active,
                visited: step.visited,
            });
            return (React.createElement("div", { className: stepClasses, key: index, onClick: () => {
                    if (onStepClick) {
                        onStepClick(step, index);
                    }
                } },
                React.createElement("div", { className: classes.barWrapper },
                    React.createElement("div", { className: classes.stepCircle },
                        React.createElement("div", { className: classes.stepNumber }, index + 1),
                        React.createElement("div", { className: classes.stepLabel }, step.label)),
                    !isLastStep && React.createElement("div", { className: classes.stepBar }))));
        })));
    }
    render() {
        let { classes } = this.props;
        return (React.createElement(ErrorBoundary_1.default, null,
            React.createElement("div", { className: classes.component },
                React.createElement("div", { className: classes.wrapper },
                    this._renderSteps(),
                    this._renderStepComponent()))));
    }
}
WizardSteps.propTypes = {
    steps: prop_types_1.default.arrayOf(prop_types_1.default.shape({
        visited: prop_types_1.default.bool,
        active: prop_types_1.default.bool,
        label: prop_types_1.default.string.isRequired,
        component: prop_types_1.default.node.isRequired,
    })),
    activeColor: prop_types_1.default.string,
    visitedColor: prop_types_1.default.string,
    onStepClick: prop_types_1.default.func,
    classes: prop_types_1.default.object,
};
WizardSteps.defaultProps = {
    onStepClick: () => { },
};
exports.default = withStyles_1.default(styles_1.default)(WizardSteps);
//# sourceMappingURL=index.js.map