"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.refresh = exports.setLayerSelectable = exports.setGroupExpanded = exports.setLayerVisibility = exports.setGroupVisibility = void 0;
var tslib_1 = require("tslib");
var client_1 = require("../api/client");
var request_builder_1 = require("../api/request-builder");
var common_1 = require("../api/common");
var actions_1 = require("../constants/actions");
/**
 * Sets the visibility for the given map group
 *
 * @export
 * @param {string} mapName
 * @param {{ id: string, value: boolean }} options
 * @returns
 */
function setGroupVisibility(mapName, options) {
    return {
        type: actions_1.ActionType.LEGEND_SET_GROUP_VISIBILITY,
        payload: tslib_1.__assign(tslib_1.__assign({}, options), { mapName: mapName })
    };
}
exports.setGroupVisibility = setGroupVisibility;
/**
 * Sets the visibility for the given map layer
 *
 * @export
 * @param {string} mapName
 * @param {{ id: string, value: boolean }} options
 * @returns
 */
function setLayerVisibility(mapName, options) {
    return {
        type: actions_1.ActionType.LEGEND_SET_LAYER_VISIBILITY,
        payload: tslib_1.__assign(tslib_1.__assign({}, options), { mapName: mapName })
    };
}
exports.setLayerVisibility = setLayerVisibility;
/**
 * Sets the expanded/collapsed state of the given group
 *
 * @export
 * @param {string} mapName
 * @param {{ id: string, value: boolean }} options
 * @returns
 */
function setGroupExpanded(mapName, options) {
    return {
        type: actions_1.ActionType.LEGEND_SET_GROUP_EXPANDABLE,
        payload: tslib_1.__assign(tslib_1.__assign({}, options), { mapName: mapName })
    };
}
exports.setGroupExpanded = setGroupExpanded;
/**
 * Sets the selectability state for the given map layer
 *
 * @export
 * @param {string} mapName
 * @param {{ id: string, value: boolean }} options
 * @returns
 */
function setLayerSelectable(mapName, options) {
    return {
        type: actions_1.ActionType.LEGEND_SET_LAYER_SELECTABLE,
        payload: tslib_1.__assign(tslib_1.__assign({}, options), { mapName: mapName })
    };
}
exports.setLayerSelectable = setLayerSelectable;
/**
 * Perform a full refresh with a requery of the layer/group structure
 *
 * @export
 * @returns {ReduxThunkedAction}
 */
function refresh() {
    return function (dispatch, getState) {
        var state = getState();
        var args = state.config;
        if (!args.viewer.isStateless) {
            var map = (0, common_1.getRuntimeMap)(state);
            if (map && args.agentUri && args.agentKind) {
                var client = new client_1.Client(args.agentUri, args.agentKind);
                client.describeRuntimeMap({
                    mapname: map.Name,
                    session: map.SessionId,
                    requestedFeatures: request_builder_1.RuntimeMapFeatureFlags.LayerFeatureSources | request_builder_1.RuntimeMapFeatureFlags.LayerIcons | request_builder_1.RuntimeMapFeatureFlags.LayersAndGroups
                }).then(function (res) {
                    if (args.activeMapName) {
                        dispatch({
                            type: actions_1.ActionType.MAP_REFRESH,
                            payload: {
                                mapName: args.activeMapName,
                                map: res
                            }
                        });
                    }
                });
            }
        }
    };
}
exports.refresh = refresh;
//# sourceMappingURL=legend.js.map