"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectionPanelContainer = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var selection_panel_1 = require("../components/selection-panel");
var runtime_1 = require("../api/runtime");
var i18n_1 = require("../api/i18n");
var core_1 = require("@blueprintjs/core");
var context_1 = require("../components/context");
var hooks_1 = require("./hooks");
var map_1 = require("../actions/map");
var hooks_mapguide_1 = require("./hooks-mapguide");
var context_2 = require("../components/map-providers/context");
var composite_selection_1 = require("../api/composite-selection");
var SelectionPanelContainer = function (props) {
    var maxHeight = props.maxHeight, selectedFeatureRenderer = props.selectedFeatureRenderer;
    var locale = (0, hooks_1.useViewerLocale)();
    var map = (0, hooks_mapguide_1.useActiveMapState)();
    var selection = (0, hooks_1.useActiveMapSelectionSet)();
    var clientSelection = (0, hooks_1.useActiveMapClientSelectionSet)();
    var dispatch = (0, context_2.useReduxDispatch)();
    var activeMapName = (0, hooks_1.useActiveMapName)();
    var setCurrentViewAction = function (view) { return dispatch((0, map_1.setCurrentView)(view)); };
    var showSelectedFeatureAction = function (mapName, layerId, selectionKey) { return dispatch((0, map_1.showSelectedFeature)(mapName, layerId, selectionKey)); };
    var appContext = React.useContext(context_1.AppContext);
    var onZoomToSelectedFeature = function (feature) {
        if (feature.Bounds) {
            var bbox = feature.Bounds.split(" ").map(function (s) { return parseFloat(s); });
            var viewer = (0, runtime_1.getViewer)();
            if (viewer) {
                var view = viewer.getViewForExtent(bbox);
                setCurrentViewAction(view);
            }
        }
    };
    var resolveLayerLabel = function (layerId, _) {
        var _a, _b, _c;
        var layer = (_c = (_b = (_a = map === null || map === void 0 ? void 0 : map.Layer) === null || _a === void 0 ? void 0 : _a.filter) === null || _b === void 0 ? void 0 : _b.call(_a, function (l) { return l.ObjectId == layerId; })) === null || _c === void 0 ? void 0 : _c[0];
        if (layer) {
            return layer.LegendLabel;
        }
    };
    var onShowSelectedFeature = function (layerId, selectionKey) {
        if (activeMapName) {
            showSelectedFeatureAction(activeMapName, layerId, selectionKey);
        }
    };
    var compSel = new composite_selection_1.CompositeSelection(selection === null || selection === void 0 ? void 0 : selection.SelectedFeatures, clientSelection);
    if ((selection === null || selection === void 0 ? void 0 : selection.SelectedFeatures) != null || clientSelection) {
        var allowHtmlValues = appContext.allowHtmlValuesInSelection();
        var cleaner = appContext.getHTMLCleaner();
        return React.createElement(selection_panel_1.SelectionPanel, { locale: locale, onResolveLayerLabel: resolveLayerLabel, allowHtmlValues: allowHtmlValues, cleanHTML: cleaner, selection: compSel, onRequestZoomToFeature: onZoomToSelectedFeature, onShowSelectedFeature: onShowSelectedFeature, selectedFeatureRenderer: selectedFeatureRenderer, maxHeight: maxHeight });
    }
    else {
        return React.createElement(core_1.Callout, { intent: core_1.Intent.PRIMARY, icon: "info-sign" },
            React.createElement("p", { className: "selection-panel-no-selection" }, (0, i18n_1.tr)("NO_SELECTED_FEATURES", locale)));
    }
};
exports.SelectionPanelContainer = SelectionPanelContainer;
//# sourceMappingURL=selection-panel.js.map