1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3    if (k2 === undefined) k2 = k;
4    var desc = Object.getOwnPropertyDescriptor(m, k);
5    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6      desc = { enumerable: true, get: function() { return m[k]; } };
7    }
8    Object.defineProperty(o, k2, desc);
9}) : (function(o, m, k, k2) {
10    if (k2 === undefined) k2 = k;
11    o[k2] = m[k];
12}));
13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14    Object.defineProperty(o, "default", { enumerable: true, value: v });
15}) : function(o, v) {
16    o["default"] = v;
17});
18var __importStar = (this && this.__importStar) || function (mod) {
19    if (mod && mod.__esModule) return mod;
20    var result = {};
21    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22    __setModuleDefault(result, mod);
23    return result;
24};
25var __importDefault = (this && this.__importDefault) || function (mod) {
26    return (mod && mod.__esModule) ? mod : { "default": mod };
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29// Forked from React Navigation in order to use a custom `useLinking` -> `extractPathFromURL` function.
30// https://github.com/react-navigation/react-navigation/blob/main/packages/native/src/NavigationContainer.tsx
31const core_1 = require("@react-navigation/core");
32const native_1 = require("@react-navigation/native");
33const useBackButton_1 = __importDefault(require("@react-navigation/native/src/useBackButton"));
34const useDocumentTitle_1 = __importDefault(require("@react-navigation/native/src/useDocumentTitle"));
35const useThenable_1 = __importDefault(require("@react-navigation/native/src/useThenable"));
36const React = __importStar(require("react"));
37const useLinking_1 = __importDefault(require("./useLinking"));
38global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
39/**
40 * Container component which holds the navigation state designed for React Native apps.
41 * This should be rendered at the root wrapping the whole app.
42 *
43 * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).
44 * @param props.onReady Callback which is called after the navigation tree mounts.
45 * @param props.onStateChange Callback which is called with the latest navigation state when it changes.
46 * @param props.theme Theme object for the navigators.
47 * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.
48 * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.
49 * @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`.
50 * @param props.children Child elements to render the content.
51 * @param props.ref Ref object which refers to the navigation object containing helper methods.
52 */
53function NavigationContainerInner({ theme = native_1.DefaultTheme, linking, fallback = null, documentTitle, onReady, ...rest }, ref) {
54    const isLinkingEnabled = linking ? linking.enabled !== false : false;
55    if (linking?.config) {
56        (0, core_1.validatePathConfig)(linking.config);
57    }
58    const refContainer = React.useRef(null);
59    (0, useBackButton_1.default)(refContainer);
60    (0, useDocumentTitle_1.default)(refContainer, documentTitle);
61    const { getInitialState } = (0, useLinking_1.default)(refContainer, {
62        // independent: rest.independent,
63        enabled: isLinkingEnabled,
64        prefixes: [],
65        ...linking,
66    });
67    // Add additional linking related info to the ref
68    // This will be used by the devtools
69    React.useEffect(() => {
70        if (refContainer.current) {
71            REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
72                get linking() {
73                    return {
74                        ...linking,
75                        enabled: isLinkingEnabled,
76                        prefixes: linking?.prefixes ?? [],
77                        getStateFromPath: linking?.getStateFromPath ?? core_1.getStateFromPath,
78                        getPathFromState: linking?.getPathFromState ?? core_1.getPathFromState,
79                        getActionFromState: linking?.getActionFromState ?? core_1.getActionFromState,
80                    };
81                },
82            });
83        }
84    });
85    const [isResolved, initialState] = (0, useThenable_1.default)(getInitialState);
86    React.useImperativeHandle(ref, () => refContainer.current);
87    const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);
88    const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
89    const onReadyRef = React.useRef(onReady);
90    React.useEffect(() => {
91        onReadyRef.current = onReady;
92    });
93    React.useEffect(() => {
94        if (isReady) {
95            onReadyRef.current?.();
96        }
97    }, [isReady]);
98    if (!isReady) {
99        // This is temporary until we have Suspense for data-fetching
100        // Then the fallback will be handled by a parent `Suspense` component
101        return fallback;
102    }
103    return (React.createElement(native_1.LinkingContext.Provider, { value: linkingContext },
104        React.createElement(native_1.ThemeProvider, { value: theme },
105            React.createElement(core_1.BaseNavigationContainer, { ...rest, initialState: rest.initialState == null ? initialState : rest.initialState, ref: refContainer }))));
106}
107const NavigationContainer = React.forwardRef(NavigationContainerInner);
108exports.default = NavigationContainer;
109//# sourceMappingURL=NavigationContainer.native.js.map