{"version":3,"file":"linking.mjs","sources":["../../../src/lib/routing/linking.tsx"],"sourcesContent":["import type { FocusEvent, MouseEvent } from 'react';\nimport { forwardRef, useCallback } from 'react';\nimport { Link, NavLink, type LinkProps, type NavLinkProps } from 'react-router-dom';\nimport { buildRoutePath } from './route-builder';\nimport { routeRegistry } from './route-registry';\n\n/* @refresh reset */\n\n// Re-export appRoutes from the separate file for backward compatibility\n// eslint-disable-next-line react-refresh/only-export-components -- Re-exporting routes object\nexport { appRoutes } from './app-routes';\n\n/**\n * Next.js-style <AppLink> component using typed routes.\n */\n\ntype AppLinkProps = Omit<LinkProps, 'to'> & {\n  /** Route path or dynamic route key */\n  to: string;\n  /** Parameters for dynamic routes */\n  params?: Record<string, string>;\n  /** Query parameters */\n  query?: Record<string, string | undefined>;\n  /** Prefetch on hover */\n  prefetch?: boolean;\n};\n\nexport const AppLink = forwardRef<HTMLAnchorElement, AppLinkProps>(\n  ({ to, params, query, prefetch = false, onMouseEnter, onFocus, ...props }, ref) => {\n    // Build the final path using canonical buildRoutePath\n    const path = buildRoutePath(to, params, query);\n\n    // Prefetch handler - triggers route component preloading\n    const triggerPrefetch = useCallback(() => {\n      if (prefetch) {\n        // Use route registry to prefetch the route component\n        routeRegistry.prefetchByPath(to).catch((error: unknown) => {\n          // Silently handle prefetch errors - they shouldn't break the UI\n          console.warn('[AppLink] Prefetch failed:', error);\n        });\n      }\n    }, [prefetch, to]);\n\n    const handleMouseEnter = (e: MouseEvent<HTMLAnchorElement>): void => {\n      triggerPrefetch();\n      onMouseEnter?.(e);\n    };\n\n    const handleFocus = (e: FocusEvent<HTMLAnchorElement>): void => {\n      triggerPrefetch();\n      onFocus?.(e);\n    };\n\n    return (\n      <Link ref={ref} to={path} onMouseEnter={handleMouseEnter} onFocus={handleFocus} {...props} />\n    );\n  }\n);\n\nAppLink.displayName = 'AppLink';\n\n/**\n * Next.js-style <AppNavLink> component using typed routes.\n * Includes active state styling.\n */\n\ntype AppNavLinkProps = Omit<NavLinkProps, 'to'> & {\n  /** Route path or dynamic route key */\n  to: string;\n  /** Parameters for dynamic routes */\n  params?: Record<string, string>;\n  /** Query parameters */\n  query?: Record<string, string | undefined>;\n  /** Active class name */\n  activeClassName?: string;\n};\n\nexport const AppNavLink = forwardRef<HTMLAnchorElement, AppNavLinkProps>(\n  ({ to, params, query, activeClassName = 'active', className, ...props }, ref) => {\n    // Build the final path using canonical buildRoutePath\n    const path = buildRoutePath(to, params, query);\n\n    return (\n      <NavLink\n        ref={ref}\n        to={path}\n        className={({ isActive }) => {\n          const baseClass =\n            typeof className === 'function'\n              ? className({ isActive, isPending: false, isTransitioning: false })\n              : className;\n          return isActive ? `${baseClass ?? ''} ${activeClassName}`.trim() : (baseClass ?? '');\n        }}\n        {...props}\n      />\n    );\n  }\n);\n\nAppNavLink.displayName = 'AppNavLink';\n"],"names":["AppLink","forwardRef","to","params","query","prefetch","onMouseEnter","onFocus","props","ref","path","buildRoutePath","triggerPrefetch","useCallback","routeRegistry","error","jsx","Link","AppNavLink","activeClassName","className","NavLink","isActive","baseClass"],"mappings":";;;;;AA2BO,MAAMA,IAAUC;AAAA,EACrB,CAAC,EAAE,IAAAC,GAAI,QAAAC,GAAQ,OAAAC,GAAO,UAAAC,IAAW,IAAO,cAAAC,GAAc,SAAAC,GAAS,GAAGC,EAAA,GAASC,MAAQ;AAEjF,UAAMC,IAAOC,EAAeT,GAAIC,GAAQC,CAAK,GAGvCQ,IAAkBC,EAAY,MAAM;AACxC,MAAIR,KAEFS,EAAc,eAAeZ,CAAE,EAAE,MAAM,CAACa,MAAmB;AAEzD,gBAAQ,KAAK,8BAA8BA,CAAK;AAAA,MAClD,CAAC;AAAA,IAEL,GAAG,CAACV,GAAUH,CAAE,CAAC;AAYjB,WACE,gBAAAc,EAACC,GAAA,EAAK,KAAAR,GAAU,IAAIC,GAAM,cAXH,CAAC,MAA2C;AACnE,MAAAE,EAAA,GACAN,IAAe,CAAC;AAAA,IAClB,GAQ4D,SANxC,CAAC,MAA2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