"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePolygon = void 0;
var react_1 = require("react");
var react_google_maps_1 = require("@vis.gl/react-google-maps");
var usePolygon = function (props) {
    var onInit = props.onInit, onDragEnd = props.onDragEnd, onMouseUp = props.onMouseUp, options = props.options;
    var polygon = (0, react_1.useMemo)(function () { return new google.maps.Polygon(); }, []);
    (0, react_1.useEffect)(function () {
        polygon.setOptions(options);
    }, [polygon, options]);
    var map = (0, react_google_maps_1.useMap)();
    (0, react_1.useEffect)(function () {
        if (!map)
            return;
        polygon.setMap(map);
        if (onInit) {
            onInit(polygon);
        }
        return function () {
            polygon.setMap(null);
        };
    }, [map]);
    (0, react_1.useEffect)(function () {
        if (!polygon)
            return;
        if (onDragEnd) {
            google.maps.event.addListener(polygon, 'dragend', onDragEnd);
        }
        if (onMouseUp) {
            google.maps.event.addListener(polygon, 'mouseup', onMouseUp);
        }
        return function () {
            google.maps.event.clearInstanceListeners(polygon);
        };
    }, [polygon, onDragEnd, onMouseUp]);
    return polygon;
};
exports.usePolygon = usePolygon;
