{"ast":null,"code":"\"use strict\";\n\nimport * as React from 'react';\nimport { DeprecatedNavigationInChildContext } from \"./DeprecatedNavigationInChildContext.js\";\nimport { NavigationBuilderContext } from \"./NavigationBuilderContext.js\";\nimport { shouldPreventRemove, useOnPreventRemove } from \"./useOnPreventRemove.js\";\nexport function useOnAction({\n  router,\n  getState,\n  setState,\n  key,\n  actionListeners,\n  beforeRemoveListeners,\n  routerConfigOptions,\n  emitter\n}) {\n  const {\n    onAction: onActionParent,\n    onRouteFocus: onRouteFocusParent,\n    addListener: addListenerParent,\n    onDispatchAction\n  } = React.useContext(NavigationBuilderContext);\n  const navigationInChildEnabled = React.useContext(DeprecatedNavigationInChildContext);\n  const routerConfigOptionsRef = React.useRef(routerConfigOptions);\n  React.useEffect(() => {\n    routerConfigOptionsRef.current = routerConfigOptions;\n  });\n  const onAction = React.useCallback((action, visitedNavigators = new Set()) => {\n    const state = getState();\n    if (visitedNavigators.has(state.key)) {\n      return false;\n    }\n    visitedNavigators.add(state.key);\n    if (typeof action.target !== 'string' || action.target === state.key) {\n      let result = router.getStateForAction(state, action, routerConfigOptionsRef.current);\n      result = result === null && action.target === state.key ? state : result;\n      if (result !== null) {\n        onDispatchAction(action, state === result);\n        if (state !== result) {\n          const isPrevented = shouldPreventRemove(emitter, beforeRemoveListeners, state.routes, result.routes, action);\n          if (isPrevented) {\n            return true;\n          }\n          setState(result);\n        }\n        if (onRouteFocusParent !== undefined) {\n          const shouldFocus = router.shouldActionChangeFocus(action);\n          if (shouldFocus && key !== undefined) {\n            onRouteFocusParent(key);\n          }\n        }\n        return true;\n      }\n    }\n    if (onActionParent !== undefined) {\n      if (onActionParent(action, visitedNavigators)) {\n        return true;\n      }\n    }\n    if (typeof action.target === 'string' || action.type === 'NAVIGATE_DEPRECATED' || navigationInChildEnabled) {\n      for (let i = actionListeners.length - 1; i >= 0; i--) {\n        const listener = actionListeners[i];\n        if (listener(action, visitedNavigators)) {\n          return true;\n        }\n      }\n    }\n    return false;\n  }, [actionListeners, beforeRemoveListeners, emitter, getState, navigationInChildEnabled, key, onActionParent, onDispatchAction, onRouteFocusParent, router, setState]);\n  useOnPreventRemove({\n    getState,\n    emitter,\n    beforeRemoveListeners\n  });\n  React.useEffect(() => addListenerParent?.('action', onAction), [addListenerParent, onAction]);\n  return onAction;\n}","map":{"version":3,"names":["React","DeprecatedNavigationInChildContext","NavigationBuilderContext","shouldPreventRemove","useOnPreventRemove","useOnAction","router","getState","setState","key","actionListeners","beforeRemoveListeners","routerConfigOptions","emitter","onAction","onActionParent","onRouteFocus","onRouteFocusParent","addListener","addListenerParent","onDispatchAction","useContext","navigationInChildEnabled","routerConfigOptionsRef","useRef","useEffect","current","useCallback","action","visitedNavigators","Set","state","has","add","target","result","getStateForAction","isPrevented","routes","undefined","shouldFocus","shouldActionChangeFocus","type","i","length","listener"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/core/src/useOnAction.tsx"],"sourcesContent":["import type {\n  NavigationAction,\n  NavigationState,\n  PartialState,\n  Router,\n  RouterConfigOptions,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport { DeprecatedNavigationInChildContext } from './DeprecatedNavigationInChildContext';\nimport {\n  type ChildActionListener,\n  type ChildBeforeRemoveListener,\n  NavigationBuilderContext,\n} from './NavigationBuilderContext';\nimport type { EventMapCore } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\nimport { shouldPreventRemove, useOnPreventRemove } from './useOnPreventRemove';\n\ntype Options = {\n  router: Router<NavigationState, NavigationAction>;\n  key?: string;\n  getState: () => NavigationState;\n  setState: (state: NavigationState | PartialState<NavigationState>) => void;\n  actionListeners: ChildActionListener[];\n  beforeRemoveListeners: Record<string, ChildBeforeRemoveListener | undefined>;\n  routerConfigOptions: RouterConfigOptions;\n  emitter: NavigationEventEmitter<EventMapCore<any>>;\n};\n\n/**\n * Hook to handle actions for a navigator, including state updates and bubbling.\n *\n * Bubbling an action is achieved in 2 ways:\n * 1. To bubble action to parent, we expose the action handler in context and then access the parent context\n * 2. To bubble action to child, child adds event listeners subscribing to actions from parent\n *\n * When the action handler handles as action, it returns `true`, otherwise `false`.\n */\nexport function useOnAction({\n  router,\n  getState,\n  setState,\n  key,\n  actionListeners,\n  beforeRemoveListeners,\n  routerConfigOptions,\n  emitter,\n}: Options) {\n  const {\n    onAction: onActionParent,\n    onRouteFocus: onRouteFocusParent,\n    addListener: addListenerParent,\n    onDispatchAction,\n  } = React.useContext(NavigationBuilderContext);\n  const navigationInChildEnabled = React.useContext(\n    DeprecatedNavigationInChildContext\n  );\n\n  const routerConfigOptionsRef =\n    React.useRef<RouterConfigOptions>(routerConfigOptions);\n\n  React.useEffect(() => {\n    routerConfigOptionsRef.current = routerConfigOptions;\n  });\n\n  const onAction = React.useCallback(\n    (\n      action: NavigationAction,\n      visitedNavigators: Set<string> = new Set<string>()\n    ) => {\n      const state = getState();\n\n      // Since actions can bubble both up and down, they could come to the same navigator again\n      // We keep track of navigators which have already tried to handle the action and return if it's already visited\n      if (visitedNavigators.has(state.key)) {\n        return false;\n      }\n\n      visitedNavigators.add(state.key);\n\n      if (typeof action.target !== 'string' || action.target === state.key) {\n        let result = router.getStateForAction(\n          state,\n          action,\n          routerConfigOptionsRef.current\n        );\n\n        // If a target is specified and set to current navigator, the action shouldn't bubble\n        // So instead of `null`, we use the state object for such cases to signal that action was handled\n        result =\n          result === null && action.target === state.key ? state : result;\n\n        if (result !== null) {\n          onDispatchAction(action, state === result);\n\n          if (state !== result) {\n            const isPrevented = shouldPreventRemove(\n              emitter,\n              beforeRemoveListeners,\n              state.routes,\n              result.routes,\n              action\n            );\n\n            if (isPrevented) {\n              return true;\n            }\n\n            setState(result);\n          }\n\n          if (onRouteFocusParent !== undefined) {\n            // Some actions such as `NAVIGATE` also want to bring the navigated route to focus in the whole tree\n            // This means we need to focus all of the parent navigators of this navigator as well\n            const shouldFocus = router.shouldActionChangeFocus(action);\n\n            if (shouldFocus && key !== undefined) {\n              onRouteFocusParent(key);\n            }\n          }\n\n          return true;\n        }\n      }\n\n      if (onActionParent !== undefined) {\n        // Bubble action to the parent if the current navigator didn't handle it\n        if (onActionParent(action, visitedNavigators)) {\n          return true;\n        }\n      }\n\n      if (\n        typeof action.target === 'string' ||\n        // For backward compatibility\n        action.type === 'NAVIGATE_DEPRECATED' ||\n        navigationInChildEnabled\n      ) {\n        // If the action wasn't handled by current navigator or a parent navigator, let children handle it\n        // Handling this when target isn't specified is deprecated and will be removed in the future\n        for (let i = actionListeners.length - 1; i >= 0; i--) {\n          const listener = actionListeners[i];\n\n          if (listener(action, visitedNavigators)) {\n            return true;\n          }\n        }\n      }\n\n      return false;\n    },\n    [\n      actionListeners,\n      beforeRemoveListeners,\n      emitter,\n      getState,\n      navigationInChildEnabled,\n      key,\n      onActionParent,\n      onDispatchAction,\n      onRouteFocusParent,\n      router,\n      setState,\n    ]\n  );\n\n  useOnPreventRemove({\n    getState,\n    emitter,\n    beforeRemoveListeners,\n  });\n\n  React.useEffect(\n    () => addListenerParent?.('action', onAction),\n    [addListenerParent, onAction]\n  );\n\n  return onAction;\n}\n"],"mappings":";;AAOA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,kCAAkC;AAC3C,SAGEC,wBAAwB;AAI1B,SAASC,mBAAmB,EAAEC,kBAAkB;AAsBhD,OAAO,SAASC,WAAWA,CAAC;EAC1BC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,GAAG;EACHC,eAAe;EACfC,qBAAqB;EACrBC,mBAAmB;EACnBC;AACO,CAAC,EAAE;EACV,MAAM;IACJC,QAAQ,EAAEC,cAAc;IACxBC,YAAY,EAAEC,kBAAkB;IAChCC,WAAW,EAAEC,iBAAiB;IAC9BC;EACF,CAAC,GAAGpB,KAAK,CAACqB,UAAU,CAACnB,wBAAwB,CAAC;EAC9C,MAAMoB,wBAAwB,GAAGtB,KAAK,CAACqB,UAAU,CAC/CpB,kCACF,CAAC;EAED,MAAMsB,sBAAsB,GAC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