{"version":3,"file":"withEmbraceRoutingLegacy.cjs","names":["getNavigationInstrumentation","React"],"sources":["../../../../../../src/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withEmbraceRoutingLegacy.ts"],"sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\nimport { EMB_NAVIGATION_INSTRUMENTATIONS } from '../../../../../constants/index.ts';\nimport { getNavigationInstrumentation } from '../../index.ts';\nimport type {\n  RouteComponentProps,\n  SwitchedRouteComponentProps,\n} from './types.ts';\n\nexport const withEmbraceRoutingLegacy = <P extends RouteComponentProps>(\n  WrappedComponent: React.ComponentType<P>,\n) => {\n  const navigationInstrumentation = getNavigationInstrumentation();\n  navigationInstrumentation.setInstrumentationType(\n    EMB_NAVIGATION_INSTRUMENTATIONS.DeclarativeLegacy,\n  );\n\n  const RouteWithEmbraceRoutingLegacy: React.FC<P> = (props: P) => {\n    // Make sure this is Route component\n    if (props.path) {\n      // Routes get injected with computedMatch when they are children of a <Switch> but the types do not reflect that\n      // Manually setting the type here.\n      const routeProps = props as SwitchedRouteComponentProps;\n\n      // Depends on this internal behaviour\n      // https://github.com/remix-run/react-router/blob/v5.3.4/packages/react-router/modules/Switch.js#L40\n      // It shouldn't change as this version is legacy, and it's not being actively worked on\n      if (routeProps.computedMatch) {\n        navigationInstrumentation.setCurrentRoute({\n          path: routeProps.computedMatch.path,\n          url: routeProps.computedMatch.url,\n        });\n      }\n    }\n\n    return React.createElement<P>(WrappedComponent, props);\n  };\n\n  // Keep wrapped component metadata\n  RouteWithEmbraceRoutingLegacy.displayName = `withEmbraceRoutingLegacy(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;\n  hoistNonReactStatics(RouteWithEmbraceRoutingLegacy, WrappedComponent);\n\n  return RouteWithEmbraceRoutingLegacy;\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,4BACX,qBACG;CACH,MAAM,4BAA4BA,uEAAAA,8BAA8B;AAChE,2BAA0B,uBAAA,kCAEzB;CAED,MAAM,iCAA8C,UAAa;AAE/D,MAAI,MAAM,MAAM;GAGd,MAAM,aAAa;AAKnB,OAAI,WAAW,cACb,2BAA0B,gBAAgB;IACxC,MAAM,WAAW,cAAc;IAC/B,KAAK,WAAW,cAAc;IAC/B,CAAC;;AAIN,SAAOC,MAAM,cAAiB,kBAAkB,MAAM;;AAIxD,+BAA8B,cAAc,4BAA4B,iBAAiB,eAAe,iBAAiB,QAAQ,YAAY;AAC7I,EAAA,GAAA,wBAAA,SAAqB,+BAA+B,iBAAiB;AAErE,QAAO"}