"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var azure_maps_control_1 = require("azure-maps-control");
var AzureMapContext_1 = require("../contexts/AzureMapContext");
var AzureMapDataSourceContext_1 = require("../contexts/AzureMapDataSourceContext");
var useCheckRef_1 = require("./useCheckRef");
exports.constructLayer = function (_a, dataSourceRef) {
    var id = _a.id, options = _a.options, type = _a.type;
    switch (type) {
        case 'SymbolLayer':
            return new azure_maps_control_1.default.layer.SymbolLayer(dataSourceRef, id, options);
        case 'HeatLayer':
            return new azure_maps_control_1.default.layer.HeatMapLayer(dataSourceRef, id, options);
        case 'ImageLayer':
            return new azure_maps_control_1.default.layer.ImageLayer(options, id);
        case 'LineLayer':
            return new azure_maps_control_1.default.layer.LineLayer(dataSourceRef, id, options);
        case 'PolygonExtrusionLayer':
            return new azure_maps_control_1.default.layer.PolygonExtrusionLayer(dataSourceRef, id, options);
        case 'PolygonLayer':
            return new azure_maps_control_1.default.layer.PolygonLayer(dataSourceRef, id, options);
        case 'TitleLayer':
            return new azure_maps_control_1.default.layer.TileLayer(options, id);
        case 'BubbleLayer':
            return new azure_maps_control_1.default.layer.BubbleLayer(dataSourceRef, id, options);
        default:
            return null;
    }
};
exports.useAzureMapLayer = function (_a) {
    var id = _a.id, options = _a.options, type = _a.type, events = _a.events, lifecycleEvents = _a.lifecycleEvents;
    var mapRef = react_1.useContext(AzureMapContext_1.AzureMapsContext).mapRef;
    var dataSourceRef = react_1.useContext(AzureMapDataSourceContext_1.AzureMapDataSourceContext).dataSourceRef;
    var _b = react_1.useState(null), layerRef = _b[0], setLayerRef = _b[1];
    useCheckRef_1.useCheckRef(!layerRef, dataSourceRef, function () {
        var _a = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            _a[_i] = arguments[_i];
        }
        var ref = _a[1];
        var layer = exports.constructLayer({ id: id, options: options, type: type }, ref);
        setLayerRef(layer);
    });
    useCheckRef_1.useCheckRef(mapRef, layerRef, function (mref, lref) {
        for (var eventType in events) {
            mref.events.add(eventType, lref, events[eventType]);
        }
        for (var event_1 in lifecycleEvents) {
            mref.events.add(event_1, lref, lifecycleEvents[event_1]);
        }
        mref.layers.add(lref);
        return function () {
            mref.layers.remove(lref);
        };
    });
    return {
        layerRef: layerRef
    };
};
//# sourceMappingURL=useAzureMapLayer.js.map