"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = StepSelectorModal;
const contexts_1 = require("../../contexts/index.js");
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const react_i18next_1 = require("react-i18next");
const react_router_dom_1 = require("react-router-dom");
const Translation_1 = require("translations/Translation");
const Icon_1 = __importStar(require("../generic/Icon/Icon"));
const SimpleModal_1 = __importDefault(require("../generic/modal/SimpleModal"));
const Text_1 = __importDefault(require("../generic/Text"));
const Color_1 = require("../../util/Color");
const StepManager_1 = __importDefault(require("../../util/StepManager"));
function StepSelectorModal(props) {
    const { currentStep } = (0, react_1.useContext)(contexts_1.FullPageEngineContext);
    const basketContext = (0, react_1.useContext)(contexts_1.BasketContext);
    const location = (0, react_router_dom_1.useLocation)();
    const { t } = (0, react_i18next_1.useTranslation)();
    const steps = StepManager_1.default.getSteps().filter((step) => (step.shouldShowOnNavigation() ? step : null));
    const onModalClose = () => {
        return props.onClose ? props.onClose() : null;
    };
    const currentStepIndex = StepManager_1.default.getStepIndex(currentStep.getName());
    return (react_1.default.createElement(SimpleModal_1.default, { open: props.isOpen, title: t(Translation_1.Translation.Navigation.SelectStep), onClose: onModalClose },
        react_1.default.createElement("ul", { className: "step-selector --horizontal" }, steps.map((step, stepIndex) => {
            const stepName = t(step.getStepTranslation());
            const prettyStep = stepIndex + 1;
            const isPrevStep = currentStepIndex > prettyStep;
            let stepNumber;
            if (isPrevStep) {
                stepNumber = react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Check, color: Color_1.Color.White, size: "24px" });
            }
            else {
                stepNumber = (react_1.default.createElement(Text_1.default, null,
                    react_1.default.createElement("strong", null, '0' + prettyStep)));
            }
            let isClickable = false;
            if (step) {
                const stepValidator = step.getValidator();
                if (stepValidator && stepValidator.isValid(basketContext)) {
                    isClickable = true;
                }
            }
            const stepClassNames = (0, classnames_1.default)('step-selector__item', {
                'is-current': currentStepIndex === prettyStep,
                'is-valid': isClickable,
                'is-complete': isPrevStep,
                'is-disabled': !isPrevStep && currentStepIndex !== prettyStep && !isClickable,
            });
            const closeOnClick = () => {
                var _a;
                (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
            };
            return (react_1.default.createElement("li", { className: stepClassNames, key: stepIndex, onClick: closeOnClick },
                react_1.default.createElement("span", { className: "step-selector__count" }, stepNumber),
                react_1.default.createElement("div", null,
                    react_1.default.createElement(Text_1.default, null,
                        react_1.default.createElement("strong", null, stepName))),
                react_1.default.createElement(react_router_dom_1.Link, { to: {
                        pathname: step.getStepUrl(),
                        search: location.search,
                    } })));
        }))));
}
//# sourceMappingURL=StepSelectorModal.js.map