{"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(_ref) {\n  var router = _ref.router,\n    getState = _ref.getState,\n    setState = _ref.setState,\n    key = _ref.key,\n    actionListeners = _ref.actionListeners,\n    beforeRemoveListeners = _ref.beforeRemoveListeners,\n    routerConfigOptions = _ref.routerConfigOptions,\n    emitter = _ref.emitter;\n  var _React$useContext = React.useContext(NavigationBuilderContext),\n    onActionParent = _React$useContext.onAction,\n    onRouteFocusParent = _React$useContext.onRouteFocus,\n    addListenerParent = _React$useContext.addListener,\n    onDispatchAction = _React$useContext.onDispatchAction;\n  var navigationInChildEnabled = React.useContext(DeprecatedNavigationInChildContext);\n  var routerConfigOptionsRef = React.useRef(routerConfigOptions);\n  React.useEffect(function () {\n    routerConfigOptionsRef.current = routerConfigOptions;\n  });\n  var onAction = React.useCallback(function (action) {\n    var visitedNavigators = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();\n    var 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      var 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          var 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          var 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 (var i = actionListeners.length - 1; i >= 0; i--) {\n        var 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: getState,\n    emitter: emitter,\n    beforeRemoveListeners: beforeRemoveListeners\n  });\n  React.useEffect(function () {\n    return addListenerParent == null ? void 0 : addListenerParent('action', onAction);\n  }, [addListenerParent, onAction]);\n  return onAction;\n}","map":{"version":3,"names":["React","DeprecatedNavigationInChildContext","NavigationBuilderContext","shouldPreventRemove","useOnPreventRemove","useOnAction","_ref","router","getState","setState","key","actionListeners","beforeRemoveListeners","routerConfigOptions","emitter","_React$useContext","useContext","onActionParent","onAction","onRouteFocusParent","onRouteFocus","addListenerParent","addListener","onDispatchAction","navigationInChildEnabled","routerConfigOptionsRef","useRef","useEffect","current","useCallback","action","visitedNavigators","arguments","length","undefined","Set","state","has","add","target","result","getStateForAction","isPrevented","routes","shouldFocus","shouldActionChangeFocus","type","i","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,CAAAC,IAAA,EASf;EAAA,IARVC,MAAM,GAAAD,IAAA,CAANC,MAAM;IACNC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IACRC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACR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