import React, { useMemo } from "react";
import { NeighborhoodMatchProvider } from "./context";
import { Content } from "./components/Content";
import { schema } from "./schema";
import { useStateManagerContext } from "~/context/stateManager";
import useIsMobile from "~/hooks/useIsMobile";
// TODO Move this import to sdks/sdks-app/src/App.tsx once all SDKs are migrated
import "~/assets/styles/globals.css";
import { TrackingProvider, initializeAnalytics } from "~/tracking";
import { LocalLogicProvider } from "~/context/LocalLogicProvider";
import { ANALYTICS_SETTINGS } from "~/constants/analytics";
import ResizeWrapper from "~/components/ResizeWrapper";
import { ValidateOptions } from "~/components/ValidateOptions";
import { ProductNames } from "~/types";
initializeAnalytics(ANALYTICS_SETTINGS.neighborhoodMatch.key);
const NeighborhoodMatch = () => {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    const { sdkState } = useStateManagerContext();
    const isMobile = useIsMobile();
    const locale = ((_a = sdkState.globalOptions) === null || _a === void 0 ? void 0 : _a.locale) || "en";
    const location = useMemo(() => {
        var _a, _b, _c, _d;
        if ((_a = sdkState.options) === null || _a === void 0 ? void 0 : _a.geographyId) {
            return {
                geographyId: (_b = sdkState.options) === null || _b === void 0 ? void 0 : _b.geographyId,
            };
        }
        return {
            lat: (_c = sdkState.options) === null || _c === void 0 ? void 0 : _c.lat,
            lng: (_d = sdkState.options) === null || _d === void 0 ? void 0 : _d.lng,
        };
    }, [
        (_b = sdkState.options) === null || _b === void 0 ? void 0 : _b.lat,
        (_c = sdkState.options) === null || _c === void 0 ? void 0 : _c.lng,
        (_d = sdkState.options) === null || _d === void 0 ? void 0 : _d.geographyId,
    ]);
    return (React.createElement(ResizeWrapper, null,
        React.createElement(ValidateOptions, { sdk: "Neighborhood Match", schema: schema, options: sdkState.options },
            React.createElement(LocalLogicProvider, { environment: (_f = (_e = sdkState.globalOptions) === null || _e === void 0 ? void 0 : _e.environment) === null || _f === void 0 ? void 0 : _f.api, apiKey: sdkState.apiKey, appearance: (_g = sdkState.globalOptions) === null || _g === void 0 ? void 0 : _g.appearance, locale: (_h = sdkState.globalOptions) === null || _h === void 0 ? void 0 : _h.locale, product: ProductNames.NEIGHBORHOOD_MATCH },
                React.createElement(TrackingProvider, { trackingPipelineSettings: {
                        apiKey: sdkState.apiKey || "",
                    }, analyticsSettings: ANALYTICS_SETTINGS.neighborhoodMatch, meta: {
                        clientId: sdkState.clientId,
                        productName: ProductNames.NEIGHBORHOOD_MATCH,
                        productVersion: FULL_APP_VERSION,
                    }, attributes: {
                        location,
                        host: sdkState.location,
                        host_url: document.referrer,
                        locale,
                        isMobile,
                    }, flags: {
                        isDebugMode: import.meta.env.VITE_TRACKING_PIPELINE_DEBUG === "true",
                    } },
                    React.createElement(NeighborhoodMatchProvider, null,
                        React.createElement(Content, null)))))));
};
export default NeighborhoodMatch;
//# sourceMappingURL=index.js.map