"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDrawingManager = void 0;
var react_google_maps_1 = require("@vis.gl/react-google-maps");
var react_1 = require("react");
var useDrawingManager = function (_a) {
    var drawingMode = _a.drawingMode, onPolygonComplete = _a.onPolygonComplete, onCircleComplete = _a.onCircleComplete, options = _a.options;
    var map = (0, react_google_maps_1.useMap)();
    var drawing = (0, react_google_maps_1.useMapsLibrary)('drawing');
    var _b = (0, react_1.useState)(null), drawingManager = _b[0], setDrawingManager = _b[1];
    (0, react_1.useEffect)(function () {
        if (!map || !drawing)
            return;
        var newDrawingManager = new drawing.DrawingManager(__assign({ map: map, drawingMode: drawingMode }, options));
        if (onPolygonComplete) {
            newDrawingManager.addListener('polygoncomplete', onPolygonComplete);
        }
        if (onCircleComplete) {
            newDrawingManager.addListener('circlecomplete', onCircleComplete);
        }
        setDrawingManager(newDrawingManager);
        return function () {
            google.maps.event.clearInstanceListeners(newDrawingManager);
            newDrawingManager.setMap(null);
        };
    }, [drawing, map, options, drawingMode, onPolygonComplete, onCircleComplete]);
    return drawingManager;
};
exports.useDrawingManager = useDrawingManager;
