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);
};
import { useEffect, useRef } from 'react';
export var usePreviewPolylines = function (map, previewPolylineOptionsRef, isActive) {
    var polylineRef = useRef(null);
    var rubberBandPolylineRef = useRef(null);
    var handleZIndexRef = useRef(4);
    useEffect(function () {
        var _a;
        if (!map || !isActive) {
            return undefined;
        }
        var options = previewPolylineOptionsRef.current;
        var polyline = new google.maps.Polyline(__assign(__assign({ map: map, path: [] }, options), { clickable: false, draggable: false, editable: false }));
        var previewBandZ = ((_a = options.zIndex) !== null && _a !== void 0 ? _a : 2) + 1;
        var rubberBandPolyline = new google.maps.Polyline(__assign(__assign({ map: map, path: [] }, options), { clickable: false, draggable: false, editable: false, zIndex: previewBandZ, strokeOpacity: Math.min(1, typeof options.strokeOpacity === 'number' ? options.strokeOpacity * 0.65 : 0.65) }));
        handleZIndexRef.current = previewBandZ + 2;
        polylineRef.current = polyline;
        rubberBandPolylineRef.current = rubberBandPolyline;
        return function () {
            polyline.setMap(null);
            rubberBandPolyline.setMap(null);
            polylineRef.current = null;
            rubberBandPolylineRef.current = null;
        };
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [map, isActive]);
    return { polylineRef: polylineRef, rubberBandPolylineRef: rubberBandPolylineRef, handleZIndexRef: handleZIndexRef };
};
