{"ast":null,"code":"\"use strict\";\n\nimport * as React from 'react';\nimport { NavigationBuilderContext } from \"./NavigationBuilderContext.js\";\nimport { NavigationRouteContext } from \"./NavigationRouteContext.js\";\nconst VISITED_ROUTE_KEYS = Symbol('VISITED_ROUTE_KEYS');\nexport const shouldPreventRemove = (emitter, beforeRemoveListeners, currentRoutes, nextRoutes, action) => {\n  const nextRouteKeys = nextRoutes.map(route => route.key);\n  const removedRoutes = currentRoutes.filter(route => !nextRouteKeys.includes(route.key)).reverse();\n  const visitedRouteKeys = action[VISITED_ROUTE_KEYS] ?? new Set();\n  const beforeRemoveAction = Object.assign({}, action, {\n    [VISITED_ROUTE_KEYS]: visitedRouteKeys\n  });\n  for (const route of removedRoutes) {\n    if (visitedRouteKeys.has(route.key)) {\n      continue;\n    }\n    const isPrevented = beforeRemoveListeners[route.key]?.(beforeRemoveAction);\n    if (isPrevented) {\n      return true;\n    }\n    visitedRouteKeys.add(route.key);\n    const event = emitter.emit({\n      type: 'beforeRemove',\n      target: route.key,\n      data: {\n        action: beforeRemoveAction\n      },\n      canPreventDefault: true\n    });\n    if (event.defaultPrevented) {\n      return true;\n    }\n  }\n  return false;\n};\nexport function useOnPreventRemove({\n  getState,\n  emitter,\n  beforeRemoveListeners\n}) {\n  const {\n    addKeyedListener\n  } = React.useContext(NavigationBuilderContext);\n  const route = React.useContext(NavigationRouteContext);\n  const routeKey = route?.key;\n  React.useEffect(() => {\n    if (routeKey) {\n      return addKeyedListener?.('beforeRemove', routeKey, action => {\n        const state = getState();\n        return shouldPreventRemove(emitter, beforeRemoveListeners, state.routes, [], action);\n      });\n    }\n  }, [addKeyedListener, beforeRemoveListeners, emitter, getState, routeKey]);\n}","map":{"version":3,"names":["React","NavigationBuilderContext","NavigationRouteContext","VISITED_ROUTE_KEYS","Symbol","shouldPreventRemove","emitter","beforeRemoveListeners","currentRoutes","nextRoutes","action","nextRouteKeys","map","route","key","removedRoutes","filter","includes","reverse","visitedRouteKeys","Set","beforeRemoveAction","Object","assign","has","isPrevented","add","event","emit","type","target","data","canPreventDefault","defaultPrevented","useOnPreventRemove","getState","addKeyedListener","useContext","routeKey","useEffect","state","routes"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/core/src/useOnPreventRemove.tsx"],"sourcesContent":["import type {\n  NavigationAction,\n  NavigationState,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport {\n  type ChildBeforeRemoveListener,\n  NavigationBuilderContext,\n} from './NavigationBuilderContext';\nimport { NavigationRouteContext } from './NavigationRouteContext';\nimport type { EventMapCore } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options = {\n  getState: () => NavigationState;\n  emitter: NavigationEventEmitter<EventMapCore<any>>;\n  beforeRemoveListeners: Record<string, ChildBeforeRemoveListener | undefined>;\n};\n\nconst VISITED_ROUTE_KEYS = Symbol('VISITED_ROUTE_KEYS');\n\nexport const shouldPreventRemove = (\n  emitter: NavigationEventEmitter<EventMapCore<any>>,\n  beforeRemoveListeners: Record<string, ChildBeforeRemoveListener | undefined>,\n  currentRoutes: { key: string }[],\n  nextRoutes: { key?: string | undefined }[],\n  action: NavigationAction\n) => {\n  const nextRouteKeys = nextRoutes.map((route) => route.key);\n\n  // Call these in reverse order so last screens handle the event first\n  const removedRoutes = currentRoutes\n    .filter((route) => !nextRouteKeys.includes(route.key))\n    .reverse();\n\n  const visitedRouteKeys: Set<string> =\n    // @ts-expect-error: add this property to mark that we've already emitted this action\n    action[VISITED_ROUTE_KEYS] ?? new Set<string>();\n\n  const beforeRemoveAction = {\n    ...action,\n    [VISITED_ROUTE_KEYS]: visitedRouteKeys,\n  };\n\n  for (const route of removedRoutes) {\n    if (visitedRouteKeys.has(route.key)) {\n      // Skip if we've already emitted this action for this screen\n      continue;\n    }\n\n    // First, we need to check if any child screens want to prevent it\n    const isPrevented = beforeRemoveListeners[route.key]?.(beforeRemoveAction);\n\n    if (isPrevented) {\n      return true;\n    }\n\n    visitedRouteKeys.add(route.key);\n\n    const event = emitter.emit({\n      type: 'beforeRemove',\n      target: route.key,\n      data: { action: beforeRemoveAction },\n      canPreventDefault: true,\n    });\n\n    if (event.defaultPrevented) {\n      return true;\n    }\n  }\n\n  return false;\n};\n\nexport function useOnPreventRemove({\n  getState,\n  emitter,\n  beforeRemoveListeners,\n}: Options) {\n  const { addKeyedListener } = React.useContext(NavigationBuilderContext);\n  const route = React.useContext(NavigationRouteContext);\n  const routeKey = route?.key;\n\n  React.useEffect(() => {\n    if (routeKey) {\n      return addKeyedListener?.('beforeRemove', routeKey, (action) => {\n        const state = getState();\n\n        return shouldPreventRemove(\n          emitter,\n          beforeRemoveListeners,\n          state.routes,\n          [],\n          action\n        );\n      });\n    }\n  }, [addKeyedListener, beforeRemoveListeners, emitter, getState, routeKey]);\n}\n"],"mappings":";;AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAEEC,wBAAwB;AAE1B,SAASC,sBAAsB;AAU/B,MAAMC,kBAAkB,GAAGC,MAAM,CAAC,oBAAoB,CAAC;AAEvD,OAAO,MAAMC,mBAAmB,GAAGA,CACjCC,OAAkD,EAClDC,qBAA4E,EAC5EC,aAAgC,EAChCC,UAA0C,EAC1CC,MAAwB,KACrB;EACH,MAAMC,aAAa,GAAGF,UAAU,CAACG,GAAG,CAAEC,KAAK,IAAKA,KAAK,CAACC,GAAG,CAAC;EAG1D,MAAMC,aAAa,GAAGP,aAAa,CAChCQ,MAAM,CAAEH,KAAK,IAAK,CAACF,aAAa,CAACM,QAAQ,CAACJ,KAAK,CAACC,GAAG,CAAC,CAAC,CACrDI,OAAO,CAAC,CAAC;EAEZ,MAAMC,gBAA6B,GAEjCT,MAAM,CAACP,kBAAkB,CAAC,IAAI,IAAIiB,GAAG,CAAS,CAAC;EAEjD,MAAMC,kBAAkB,GAAAC,MAAA,CAAAC,MAAA,KACnBb,MAAM;IACT,CAACP,kBAAkB,GAAGgB;EAAA,EACvB;EAED,KAAK,MAAMN,KAAK,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