(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../hooks/useStateProps", "./styles", "./components/StepItem"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var useStateProps_1 = require("../hooks/useStateProps");
    var styles_1 = require("./styles");
    var StepItem_1 = (0, tslib_1.__importDefault)(require("./components/StepItem"));
    var Steps = function (_a) {
        var size = _a.size, current = _a.current, onItemClick = _a.onItemClick, getItemDisabled = _a.getItemDisabled, getItemTitle = _a.getItemTitle, getItemStatus = _a.getItemStatus, onChangeCurrent = _a.onChangeCurrent, getItemKey = _a.getItemKey, getItemOnClick = _a.getItemOnClick, className = _a.className, classNameItem = _a.classNameItem, width = _a.width, height = _a.height, _b = _a.direction, direction = _b === void 0 ? "horizontal" : _b, steps = _a.steps, otherProps = (0, tslib_1.__rest)(_a, ["size", "current", "onItemClick", "getItemDisabled", "getItemTitle", "getItemStatus", "onChangeCurrent", "getItemKey", "getItemOnClick", "className", "classNameItem", "width", "height", "direction", "steps"]);
        var _c = (0, tslib_1.__read)((0, useStateProps_1.useStateProps)(Math.min(Math.max(current, 1), steps.length)), 2), _current = _c[0], _setCurrent = _c[1];
        var isInitialMount = (0, react_1.useRef)(true);
        (0, react_1.useEffect)(function () {
            if (!isInitialMount.current) {
                var item = steps.slice(_current - 1)[0];
                item && (onChangeCurrent === null || onChangeCurrent === void 0 ? void 0 : onChangeCurrent(item));
            }
            else {
                isInitialMount.current = false;
            }
        }, [_current]);
        var getNewProps = function (item, _index) {
            var _a, _b;
            var stepNumber = _index + 1;
            var status = (_a = getItemStatus === null || getItemStatus === void 0 ? void 0 : getItemStatus(item)) !== null && _a !== void 0 ? _a : (item.status || (stepNumber < current && "completed") || "waiting");
            var isDisabled = (_b = getItemDisabled === null || getItemDisabled === void 0 ? void 0 : getItemDisabled(item)) !== null && _b !== void 0 ? _b : item.isDisabled;
            var title = (getItemTitle === null || getItemTitle === void 0 ? void 0 : getItemTitle(item)) || item.title;
            var stepOnClick = function (event) {
                var _a;
                getItemOnClick
                    ? (_a = getItemOnClick(item)) === null || _a === void 0 ? void 0 : _a(event, item)
                    : onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(event, item);
            };
            var _onChangeCurrent = function () {
                _setCurrent(stepNumber);
            };
            return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, item), { size: size, stepOnClick: stepOnClick, status: status, isCurrent: stepNumber === _current, direction: direction, stepNumber: stepNumber, title: title, isLast: stepNumber === (steps === null || steps === void 0 ? void 0 : steps.length), isDisabled: isDisabled || (!item.status && stepNumber > current), onChangeCurrent: _onChangeCurrent });
        };
        return (react_1.default.createElement(styles_1.StepWrapper, (0, tslib_1.__assign)({ direction: direction, height: height, className: className, width: width }, otherProps), (steps === null || steps === void 0 ? void 0 : steps.length) > 0 &&
            steps.map(function (step, index) {
                var props = getNewProps(step, index);
                return (react_1.default.createElement(react_1.default.Fragment, { key: (getItemKey === null || getItemKey === void 0 ? void 0 : getItemKey(step)) || step.key },
                    react_1.default.createElement(StepItem_1.default, (0, tslib_1.__assign)({ className: classNameItem }, props))));
            })));
    };
    exports.default = Steps;
});
