"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MouseCoordinatesContainer = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var common_1 = require("../api/common");
var mouse_coordinates_1 = require("../components/mouse-coordinates");
var olProj = tslib_1.__importStar(require("ol/proj"));
var units_1 = require("../utils/units");
var hooks_1 = require("./hooks");
var hooks_mapguide_1 = require("./hooks-mapguide");
var MouseCoordinatesContainer = function (props) {
    var style = props.style;
    var mapProjection = (0, hooks_mapguide_1.useActiveMapProjection)();
    var projection = (0, hooks_1.useConfiguredCoordinateProjection)();
    var decimals = (0, hooks_1.useConfiguredCoordinateDecimals)();
    var format = (0, hooks_1.useConfiguredCoordinateFormat)();
    var mouse = (0, hooks_1.useCurrentMouseCoordinates)();
    var locale = (0, hooks_1.useViewerLocale)();
    if (mouse) {
        var prj = olProj.get(projection !== null && projection !== void 0 ? projection : mapProjection);
        var units = void 0;
        if (prj) {
            units = prj.getUnits();
            switch (units) {
                case "degrees":
                    units = (0, units_1.getUnitOfMeasure)(common_1.UnitOfMeasure.Degrees).abbreviation(locale);
                    break;
                case "pixels":
                case "tile-pixels":
                    units = (0, units_1.getUnitOfMeasure)(common_1.UnitOfMeasure.Pixels).abbreviation(locale);
                    break;
                case "m":
                    units = (0, units_1.getUnitOfMeasure)(common_1.UnitOfMeasure.Meters).abbreviation(locale);
                    break;
                case "ft":
                case "us-ft":
                    units = (0, units_1.getUnitOfMeasure)(common_1.UnitOfMeasure.Feet).abbreviation(locale);
                    break;
            }
        }
        var coords = [mouse[0], mouse[1]];
        if (projection && mapProjection) {
            try {
                coords = olProj.transform(coords, mapProjection, projection);
            }
            catch (e) {
            }
        }
        return React.createElement(mouse_coordinates_1.MouseCoordinates, { units: units, coords: coords, style: style, decimals: decimals, format: format });
    }
    else {
        return React.createElement("div", null);
    }
};
exports.MouseCoordinatesContainer = MouseCoordinatesContainer;
//# sourceMappingURL=mouse-coordinates.js.map