"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WmsCapabilitiesPanel = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var i18n_1 = require("../../api/i18n");
var core_1 = require("@blueprintjs/core");
function extractWmsLayers(caps) {
    var _a, _b;
    var layers = [];
    var _c = caps.Capability.Layer, Layer = _c.Layer, rootLayer = tslib_1.__rest(_c, ["Layer"]);
    if (rootLayer.Name) { //Must have name to be considered
        layers.push([rootLayer, (_a = rootLayer.Style) !== null && _a !== void 0 ? _a : []]);
    }
    if (caps.Capability.Layer.Layer) {
        for (var _i = 0, _d = caps.Capability.Layer.Layer; _i < _d.length; _i++) {
            var layer = _d[_i];
            layers.push([layer, (_b = layer.Style) !== null && _b !== void 0 ? _b : []]);
        }
    }
    return layers;
}
var WmsCapabilitiesPanel = function (props) {
    var locale = props.locale, onAddLayer = props.onAddLayer;
    var caps = props.capabilities;
    var layers = extractWmsLayers(caps);
    return React.createElement(React.Fragment, null,
        React.createElement(core_1.Card, null,
            React.createElement("h5", { className: "bp3-heading" },
                React.createElement("a", { href: "#" }, (0, i18n_1.tr)("WMS_SERVICE_INFO", locale))),
            React.createElement("p", null, (0, i18n_1.tr)("WMS_VERSION", locale, { version: caps.version })),
            React.createElement("p", null, (0, i18n_1.tr)("OWS_SERVICE_NAME", locale, { name: caps.Service.Name })),
            React.createElement("p", null, (0, i18n_1.tr)("OWS_SERVICE_TITLE", locale, { title: caps.Service.Title })),
            React.createElement("p", null, (0, i18n_1.tr)("OWS_SERVICE_ABSTRACT", locale, { abstract: caps.Service.Abstract }))),
        React.createElement(core_1.Card, { style: { marginBottom: 10 } },
            React.createElement("h5", { className: "bp3-heading" },
                React.createElement("a", { href: "#" }, (0, i18n_1.tr)("WMS_AVAILABLE_LAYERS", locale))),
            layers.map(function (_a) {
                var layer = _a[0], styles = _a[1];
                var otherActions = React.createElement(React.Fragment, null);
                return React.createElement(core_1.Card, { key: layer.Name, style: { padding: 15, paddingTop: 5 } },
                    React.createElement("h4", null,
                        React.createElement(core_1.Icon, { icon: "layer" }),
                        " ",
                        layer.Name),
                    React.createElement("p", null, (0, i18n_1.tr)("OWS_LAYER_TITLE", locale, { title: layer.Title })),
                    (function () {
                        if (styles.length) {
                            return styles.map(function (st) { return React.createElement(core_1.ButtonGroup, { key: st.Name, vertical: true, fill: true, alignText: "left" },
                                React.createElement(core_1.Button, { onClick: function () { var _a, _b; return onAddLayer(layer.Name, layer.queryable, false, st, (_b = (_a = st.LegendURL) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.OnlineResource); }, intent: core_1.Intent.PRIMARY, icon: "new-layer" }, (0, i18n_1.tr)("ADD_LAYER_WITH_WMS_STYLE", locale, { style: st.Name })),
                                React.createElement(core_1.Button, { onClick: function () { var _a, _b; return onAddLayer(layer.Name, layer.queryable, true, st, (_b = (_a = st.LegendURL) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.OnlineResource); }, intent: core_1.Intent.PRIMARY, icon: "new-layer" }, (0, i18n_1.tr)("ADD_LAYER_WITH_WMS_STYLE_TILED", locale, { style: st.Name })),
                                otherActions); });
                        }
                        else {
                            return React.createElement(core_1.ButtonGroup, { vertical: true, fill: true, alignText: "left" },
                                React.createElement(core_1.Button, { onClick: function () { return onAddLayer(layer.Name, layer.queryable, false, undefined); }, intent: core_1.Intent.PRIMARY, icon: "new-layer" }, (0, i18n_1.tr)("ADD_LAYER", locale)),
                                React.createElement(core_1.Button, { onClick: function () { return onAddLayer(layer.Name, layer.queryable, true, undefined); }, intent: core_1.Intent.PRIMARY, icon: "new-layer" }, (0, i18n_1.tr)("ADD_LAYER_TILED", locale)),
                                otherActions);
                        }
                    })());
            })));
};
exports.WmsCapabilitiesPanel = WmsCapabilitiesPanel;
//# sourceMappingURL=wms-capabilities-panel.js.map