"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 = StepSelector;
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 Text_1 = __importStar(require("../generic/Text"));
const StepSelectorModal_1 = __importDefault(require("./StepSelectorModal"));
const useNextStepAction_1 = require("../../hooks/useNextStepAction");
const Color_1 = require("../../util/Color");
const ScreenSize_1 = __importDefault(require("../../util/ScreenSize"));
const StepManager_1 = __importDefault(require("../../util/StepManager"));
const LinkWithNextStepConfirmationDialog = (0, useNextStepAction_1.withNextStepConfirmationDialog)((props) => react_1.default.createElement("a", Object.assign({}, props, { style: { cursor: 'pointer' } })));
function StepSelector() {
    const { screenSize } = (0, react_1.useContext)(contexts_1.BookingEngineContext);
    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 navigate = (0, react_router_dom_1.useNavigate)();
    const { t } = (0, react_i18next_1.useTranslation)();
    const [modalOpen, setModalOpen] = (0, react_1.useState)(false);
    const steps = StepManager_1.default.getSteps().filter((step) => (step.shouldShowOnNavigation() ? step : null));
    const onDropdownClick = () => {
        screenSize <= ScreenSize_1.default.Medium ? setModalOpen(true) : null;
    };
    const closeModal = () => {
        setModalOpen(false);
    };
    const currentStepIndex = StepManager_1.default.getStepIndex(currentStep.getName());
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement("div", { className: "step-dropdown", onClick: onDropdownClick },
            react_1.default.createElement("div", { className: "step-container" },
                react_1.default.createElement("span", { className: "step-container-dropdown" },
                    react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Dropdown })),
                react_1.default.createElement("div", { className: "step-awards" },
                    react_1.default.createElement("img", { alt: "", style: { width: '80px' } })),
                react_1.default.createElement("ul", { className: "step-selector" }, 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, { type: Text_1.TextType.Small },
                            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,
                    });
                    return (react_1.default.createElement("li", { className: stepClassNames, key: prettyStep },
                        react_1.default.createElement("span", { className: "step-selector__count" }, stepNumber),
                        react_1.default.createElement("div", null,
                            react_1.default.createElement("span", { className: "step-selector__step-count-mobile" },
                                react_1.default.createElement(Text_1.default, { type: Text_1.TextType.Small, color: Color_1.Color.Navy },
                                    react_1.default.createElement("strong", null, t(Translation_1.Translation.Navigation.Steps.StepProgress, { step: prettyStep, maxSteps: StepManager_1.default.getSteps().length })))),
                            react_1.default.createElement(Text_1.default, null,
                                react_1.default.createElement("strong", null, stepName))),
                        react_1.default.createElement(LinkWithNextStepConfirmationDialog, { onClick: () => {
                                const newLocation = Object.assign(Object.assign({}, location), { pathname: step.getStepUrl() });
                                navigate(newLocation);
                            } })));
                })))),
        screenSize <= ScreenSize_1.default.Medium && react_1.default.createElement(StepSelectorModal_1.default, { isOpen: modalOpen, onClose: closeModal })));
}
//# sourceMappingURL=StepSelector.js.map