"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("./AzureMapContext");
var useCheckRef_1 = require("../hooks/useCheckRef");
var AzureMapDataSourceContext = react_1.createContext({
    dataSourceRef: null
});
exports.AzureMapDataSourceContext = AzureMapDataSourceContext;
var Provider = AzureMapDataSourceContext.Provider, AzureMapDataSourceConsumer = AzureMapDataSourceContext.Consumer;
exports.AzureMapDataSourceConsumer = AzureMapDataSourceConsumer;
var AzureMapDataSourceStatefulProvider = function (_a) {
    var id = _a.id, children = _a.children, options = _a.options, events = _a.events, dataFromUrl = _a.dataFromUrl;
    var dataSourceRef = react_1.useState(new azure_maps_control_1.default.source.DataSource(id, options))[0];
    var mapRef = react_1.useContext(AzureMapContext_1.AzureMapsContext).mapRef;
    useCheckRef_1.useCheckRef(mapRef, dataSourceRef, function (mref, dref) {
        for (var eventType in events || {}) {
            mref.events.add(eventType, dref, events[eventType]);
        }
        mref.sources.add(dref);
        if (dataFromUrl) {
            dref.importDataFromUrl(dataFromUrl);
        }
    });
    return (react_1.default.createElement(Provider, { value: {
            dataSourceRef: dataSourceRef
        } }, mapRef && children));
};
exports.AzureMapDataSourceProvider = AzureMapDataSourceStatefulProvider;
//# sourceMappingURL=AzureMapDataSourceContext.js.map