"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlaceholderComponent = exports.getComponentFactory = exports.registerComponentFactory = exports.DefaultComponentNames = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var error_1 = require("../../components/error");
var i18n_1 = require("../i18n");
/**
 * The default set of component names
 *
 * @export
 * @class DefaultComponentNames
 */
var DefaultComponentNames;
(function (DefaultComponentNames) {
    DefaultComponentNames["Legend"] = "Legend";
    DefaultComponentNames["SelectionPanel"] = "SelectionPanel";
    DefaultComponentNames["Map"] = "Map";
    DefaultComponentNames["Navigator"] = "Navigator";
    DefaultComponentNames["MouseCoordinates"] = "MouseCoordinates";
    DefaultComponentNames["ScaleDisplay"] = "ScaleDisplay";
    DefaultComponentNames["SelectedFeatureCount"] = "SelectedFeatureCount";
    DefaultComponentNames["PoweredByMapGuide"] = "PoweredByMapGuide";
    DefaultComponentNames["TaskPane"] = "TaskPane";
    DefaultComponentNames["About"] = "About";
    DefaultComponentNames["SessionExpired"] = "SessionExpired";
    DefaultComponentNames["Measure"] = "Measure";
    DefaultComponentNames["ViewerOptions"] = "ViewerOptions";
    DefaultComponentNames["QuickPlot"] = "QuickPlot";
    DefaultComponentNames["BaseMapSwitcher"] = "BaseMapSwitcher";
    DefaultComponentNames["MapMenu"] = "MapMenu";
    DefaultComponentNames["ViewSize"] = "ViewSize";
    DefaultComponentNames["CoordinateTracker"] = "CoordinateTracker";
    DefaultComponentNames["AddManageLayers"] = "AddManageLayers";
    DefaultComponentNames["ShareLinkToView"] = "ShareLinkToView";
})(DefaultComponentNames = exports.DefaultComponentNames || (exports.DefaultComponentNames = {}));
var components = {};
/**
 * Registers a react component factory function for the given component id
 *
 * @export
 * @param {string} id
 * @param {ComponentFactory} factory
 */
function registerComponentFactory(id, factory) {
    components[id] = factory;
}
exports.registerComponentFactory = registerComponentFactory;
/**
 * Gets the registered component factory function for the given component id
 *
 * @export
 * @param {string} id
 * @returns {ComponentFactory}
 */
function getComponentFactory(id) {
    return components[id];
}
exports.getComponentFactory = getComponentFactory;
/**
 * A component placeholder
 *
 * @export
 * @class PlaceholderComponent
 * @extends {React.Component<IPlaceholderComponentProps, any>}
 */
var PlaceholderComponent = /** @class */ (function (_super) {
    tslib_1.__extends(PlaceholderComponent, _super);
    function PlaceholderComponent(props) {
        return _super.call(this, props) || this;
    }
    PlaceholderComponent.prototype.render = function () {
        var _a = this.props, id = _a.id, componentProps = _a.componentProps;
        var factory = getComponentFactory(id);
        if (factory) {
            return factory(componentProps);
        }
        else {
            return React.createElement(error_1.Error, { error: (0, i18n_1.tr)("ERR_UNREGISTERED_COMPONENT", this.props.locale, { componentId: id }) });
        }
    };
    return PlaceholderComponent;
}(React.Component));
exports.PlaceholderComponent = PlaceholderComponent;
//# sourceMappingURL=component.js.map