"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NavigatorContainer = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var navigator_1 = require("../components/navigator");
var command_1 = require("../api/registry/command");
var hooks_1 = require("./hooks");
var map_1 = require("../actions/map");
var hooks_mapguide_1 = require("./hooks-mapguide");
var context_1 = require("../components/map-providers/context");
var NavigatorContainer = function (props) {
    var style = props.style;
    var dispatch = (0, context_1.useReduxDispatch)();
    var locale = (0, hooks_1.useViewerLocale)();
    var finiteScales = (0, hooks_mapguide_1.useActiveMapFiniteScales)();
    var view = (0, hooks_1.useActiveMapView)();
    var busyCount = (0, hooks_1.useViewerBusyCount)();
    var activeMapName = (0, hooks_1.useActiveMapName)();
    var setScaleAction = function (mapName, scale) { return dispatch((0, map_1.setScale)(mapName, scale)); };
    var invokeCommandAction = function (cmd, parameters) { return dispatch((0, map_1.invokeCommand)(cmd, parameters)); };
    var onZoom = function (direction) {
        var cmd;
        switch (direction) {
            case navigator_1.ZoomDirection.In:
                cmd = (0, command_1.getCommand)(command_1.DefaultCommands.ZoomIn);
                break;
            case navigator_1.ZoomDirection.Out:
                cmd = (0, command_1.getCommand)(command_1.DefaultCommands.ZoomOut);
                break;
        }
        if (cmd) {
            invokeCommandAction(cmd);
        }
    };
    var onPan = function (direction) {
        var cmd;
        switch (direction) {
            case navigator_1.PanDirection.East:
                cmd = (0, command_1.getCommand)(command_1.DefaultCommands.PanRight);
                break;
            case navigator_1.PanDirection.West:
                cmd = (0, command_1.getCommand)(command_1.DefaultCommands.PanLeft);
                break;
            case navigator_1.PanDirection.North:
                cmd = (0, command_1.getCommand)(command_1.DefaultCommands.PanUp);
                break;
            case navigator_1.PanDirection.South:
                cmd = (0, command_1.getCommand)(command_1.DefaultCommands.PanDown);
                break;
        }
        if (cmd) {
            invokeCommandAction(cmd);
        }
    };
    var onRequestZoomToScale = function (scale) {
        if (activeMapName) {
            setScaleAction(activeMapName, scale);
        }
    };
    if (view) {
        return React.createElement(navigator_1.Navigator, { style: style, scale: view.scale, finiteScaleList: finiteScales, locale: locale, busy: busyCount > 0, onRequestZoomToScale: onRequestZoomToScale, onPan: onPan, onZoom: onZoom });
    }
    else {
        return React.createElement("div", null);
    }
};
exports.NavigatorContainer = NavigatorContainer;
//# sourceMappingURL=navigator.js.map