"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useActiveMapState = exports.useActiveMapFiniteScales = exports.useActiveMapSessionId = exports.useActiveMapSelectableLayerNames = exports.useActiveMapActiveSelectedFeature = exports.useActiveMapLayerTransparency = exports.useActiveMapHideLayers = exports.useActiveMapHideGroups = exports.useActiveMapShowLayers = exports.useActiveMapShowGroups = exports.useActiveMapSelectableLayers = exports.useActiveMapExpandedGroups = exports.useActiveMapProjectionUnits = exports.useActiveMapProjection = exports.useActiveMapMetersPerUnit = exports.useActiveMapIsArbitraryCoordSys = void 0;
var common_1 = require("../api/common");
var hooks_1 = require("./hooks");
var context_1 = require("../components/map-providers/context");
var units_1 = require("../utils/units");
/**
 * @since 0.14.3
 */
function useActiveMapIsArbitraryCoordSys() {
    return (0, context_1.useAppState)(function (state) {
        var _a, _b, _c;
        var arbCs = false;
        if (state.config.activeMapName) {
            var ms = state.mapState[state.config.activeMapName];
            if ((_a = ms.mapguide) === null || _a === void 0 ? void 0 : _a.runtimeMap) {
                arbCs = (0, units_1.tryParseArbitraryCs)(ms.mapguide.runtimeMap.CoordinateSystem.MentorCode) != null;
            }
            else if ((_b = ms.generic) === null || _b === void 0 ? void 0 : _b.subject) {
                arbCs = (0, units_1.tryParseArbitraryCs)((_c = ms.generic.subject.meta) === null || _c === void 0 ? void 0 : _c.projection) != null;
            }
        }
        return arbCs;
    });
}
exports.useActiveMapIsArbitraryCoordSys = useActiveMapIsArbitraryCoordSys;
function useActiveMapMetersPerUnit() {
    return (0, context_1.useAppState)(function (state) {
        var _a;
        var mpu = 1.0;
        if (state.config.activeMapName) {
            var ms = state.mapState[state.config.activeMapName];
            if ((_a = ms.mapguide) === null || _a === void 0 ? void 0 : _a.runtimeMap) {
                mpu = ms.mapguide.runtimeMap.CoordinateSystem.MetersPerUnit;
            }
        }
        return mpu;
    });
}
exports.useActiveMapMetersPerUnit = useActiveMapMetersPerUnit;
function useActiveMapProjection() {
    return (0, context_1.useAppState)(function (state) {
        var _a, _b, _c;
        var proj;
        if (state.config.activeMapName) {
            var map = (_a = state.mapState[state.config.activeMapName].mapguide) === null || _a === void 0 ? void 0 : _a.runtimeMap;
            var subject = (_b = state.mapState[state.config.activeMapName].generic) === null || _b === void 0 ? void 0 : _b.subject;
            if (map) {
                proj = "EPSG:".concat(map.CoordinateSystem.EpsgCode);
            }
            else if (subject) {
                proj = (_c = subject.meta) === null || _c === void 0 ? void 0 : _c.projection;
            }
        }
        return proj;
    });
}
exports.useActiveMapProjection = useActiveMapProjection;
/**
 * @since 0.14.3
 */
function useActiveMapProjectionUnits() {
    return (0, context_1.useAppState)(function (state) {
        var _a, _b, _c, _d, _e;
        var arbUnits;
        if (state.config.activeMapName) {
            var map = (_a = state.mapState[state.config.activeMapName].mapguide) === null || _a === void 0 ? void 0 : _a.runtimeMap;
            var subject = (_b = state.mapState[state.config.activeMapName].generic) === null || _b === void 0 ? void 0 : _b.subject;
            if (map) {
                arbUnits = (_c = (0, units_1.tryParseArbitraryCs)(map.CoordinateSystem.MentorCode)) === null || _c === void 0 ? void 0 : _c.units;
            }
            else if (subject) {
                arbUnits = (_e = (0, units_1.tryParseArbitraryCs)((_d = subject.meta) === null || _d === void 0 ? void 0 : _d.projection)) === null || _e === void 0 ? void 0 : _e.units;
            }
        }
        return arbUnits;
    });
}
exports.useActiveMapProjectionUnits = useActiveMapProjectionUnits;
function useActiveMapExpandedGroups() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.expandedGroups; });
}
exports.useActiveMapExpandedGroups = useActiveMapExpandedGroups;
function useActiveMapSelectableLayers() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.selectableLayers; });
}
exports.useActiveMapSelectableLayers = useActiveMapSelectableLayers;
function useActiveMapShowGroups() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.showGroups; });
}
exports.useActiveMapShowGroups = useActiveMapShowGroups;
function useActiveMapShowLayers() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.showLayers; });
}
exports.useActiveMapShowLayers = useActiveMapShowLayers;
function useActiveMapHideGroups() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.hideGroups; });
}
exports.useActiveMapHideGroups = useActiveMapHideGroups;
function useActiveMapHideLayers() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.hideLayers; });
}
exports.useActiveMapHideLayers = useActiveMapHideLayers;
function useActiveMapLayerTransparency() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.layerTransparency; });
}
exports.useActiveMapLayerTransparency = useActiveMapLayerTransparency;
function useActiveMapActiveSelectedFeature() {
    return (0, context_1.useAppState)(function (state) { var _a, _b; return (_b = (_a = (0, hooks_1.getActiveMapBranch)(state)) === null || _a === void 0 ? void 0 : _a.mapguide) === null || _b === void 0 ? void 0 : _b.activeSelectedFeature; });
}
exports.useActiveMapActiveSelectedFeature = useActiveMapActiveSelectedFeature;
function useActiveMapSelectableLayerNames() {
    var _a;
    var map = useActiveMapState();
    var selectableLayers = useActiveMapSelectableLayers();
    if (map) {
        var selectableLayerNames = ((_a = map.Layer) !== null && _a !== void 0 ? _a : [])
            .filter(function (layer) { return layer.Selectable && selectableLayers[layer.ObjectId] !== false; })
            .map(function (layer) { return layer.Name; });
        return selectableLayerNames;
    }
    return [];
}
exports.useActiveMapSelectableLayerNames = useActiveMapSelectableLayerNames;
function useActiveMapSessionId() {
    return (0, context_1.useAppState)(function (state) { var _a; return (_a = (0, common_1.getRuntimeMap)(state)) === null || _a === void 0 ? void 0 : _a.SessionId; });
}
exports.useActiveMapSessionId = useActiveMapSessionId;
function useActiveMapFiniteScales() {
    return (0, context_1.useAppState)(function (state) {
        var map = (0, common_1.getRuntimeMap)(state);
        return map != null ? map.FiniteDisplayScale : undefined;
    });
}
exports.useActiveMapFiniteScales = useActiveMapFiniteScales;
function useActiveMapState() {
    return (0, context_1.useAppState)(function (state) { return (0, common_1.getRuntimeMap)(state); });
}
exports.useActiveMapState = useActiveMapState;
//# sourceMappingURL=hooks-mapguide.js.map