var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { useMemo } from "react";
import "@local-logic/maps/style.css";
import { LocalLogicMap } from "@local-logic/maps";
import { Layers } from "./Layers";
import { Markers } from "./Markers";
import { CenterPin } from "./CenterPin";
import { Popup } from "./Popup";
import * as styles from "./styles";
import { getMapProviderConfig } from "~/utils/map/getMapProviderConfig";
import { PaddingDebug } from "~/components/map/PaddingDebug";
import { DEFAULT_MIN_ZOOM, DEFAULT_MAX_ZOOM, MAP_PADDING, LAYOUT_MEASUREMENTS, } from "~/sdks/LocalContent/constants";
import { useResponsiveBreakpoints } from "~/hooks/useResponsiveBreakpoints";
import { useLocalContent } from "~/sdks/LocalContent/context";
export function Map(_a) {
    var _b, _c, _d;
    var { children } = _a, rest = __rest(_a, ["children"]);
    const breakpoints = useResponsiveBreakpoints();
    const { activeCategory, activeScore, isCommuteCalculatorOpen, isSidebarExpanded, location, locale, map, activeMarker, commuteData, } = useLocalContent();
    const mapProviderConfig = useMemo(() => {
        var _a, _b, _c;
        return getMapProviderConfig((_a = map.mapProvider) === null || _a === void 0 ? void 0 : _a.name, (_b = map.mapProvider) === null || _b === void 0 ? void 0 : _b.key, (_c = map.mapProvider) === null || _c === void 0 ? void 0 : _c.theme);
    }, [(_b = map.mapProvider) === null || _b === void 0 ? void 0 : _b.name, (_c = map.mapProvider) === null || _c === void 0 ? void 0 : _c.key, (_d = map.mapProvider) === null || _d === void 0 ? void 0 : _d.theme]);
    const mapPadding = useMemo(() => {
        const padding = breakpoints.sm ? MAP_PADDING.desktop : MAP_PADDING.mobile;
        // Making sure we don't override reference values
        let { top, bottom, left } = padding;
        if (breakpoints.sm) {
            // Desktop
            if (!isSidebarExpanded) {
                left -= LAYOUT_MEASUREMENTS.SIDEBAR_STATE_WIDTH_DIFFERENCE;
            }
            if (isCommuteCalculatorOpen && !commuteData) {
                top += LAYOUT_MEASUREMENTS.COMMUTE_CALCULATOR_NO_ROUTE_HEIGHT_DESKTOP;
            }
            if (isCommuteCalculatorOpen && commuteData) {
                top += LAYOUT_MEASUREMENTS.COMMUTE_CALCULATOR_WITH_ROUTE_HEIGHT_DESKTOP;
            }
        }
        else {
            // Mobile
            if (activeCategory) {
                top += LAYOUT_MEASUREMENTS.SCORE_BUTTONS_HEIGHT_MOBILE;
            }
            if (activeScore && !isCommuteCalculatorOpen) {
                // While the details slider can be expanded, we're not going to adjust the
                // value since the popup opens up
                bottom = LAYOUT_MEASUREMENTS.SCORE_DETAILS_HEIGHT_MOBILE;
            }
            if (isCommuteCalculatorOpen) {
                bottom = LAYOUT_MEASUREMENTS.COMMUTE_CALCULATOR_HEIGHT_MOBILE;
            }
        }
        return Object.assign(Object.assign({}, padding), { top,
            bottom,
            left });
    }, [
        breakpoints.sm,
        isCommuteCalculatorOpen,
        activeCategory,
        activeScore,
        isSidebarExpanded,
        commuteData,
    ]);
    // If location is not set or invalid, return a message
    // lat and lng values of 0 are considered invalid for this context
    if (!location || !location.lat || !location.lng) {
        return React.createElement("div", { className: styles.container }, "Location not set");
    }
    return (React.createElement("div", Object.assign({ className: styles.container }, rest),
        React.createElement(LocalLogicMap.Root, { mapProvider: mapProviderConfig, locale: locale, mapPadding: mapPadding, center: { latitude: location.lat, longitude: location.lng }, zoom: map.zoom, minZoom: DEFAULT_MIN_ZOOM, maxZoom: DEFAULT_MAX_ZOOM, zoomPosition: breakpoints.sm ? "bottom-right" : undefined, pitch: map.pitch, bearing: map.bearing, cooperativeGestures: map.cooperativeGestures, activeMarker: activeMarker },
            React.createElement(LocalLogicMap.BaseMap, null,
                React.createElement(Layers, null),
                React.createElement(Markers, null),
                React.createElement(CenterPin, null),
                React.createElement(Popup, null))),
        import.meta.env.VITE_MAP_PADDING_DEBUG === "true" && (React.createElement(PaddingDebug, { mapPadding: mapPadding })),
        children));
}
//# sourceMappingURL=index.js.map