{"version":3,"sources":["../../../../../src/shared/lib/router/utils/resolve-param-value.ts"],"sourcesContent":["import type { Params } from '../../../../server/request/params'\nimport type { DynamicParamTypes } from '../../app-router-types'\nimport { InvariantError } from '../../invariant-error'\nimport type {\n  NormalizedAppRoute,\n  NormalizedAppRouteSegment,\n} from '../routes/app'\nimport { interceptionPrefixFromParamType } from './interception-prefix-from-param-type'\n\n/**\n * Extracts the param value from a path segment, handling interception markers\n * based on the expected param type.\n *\n * @param pathSegment - The path segment to extract the value from\n * @param params - The current params object for resolving dynamic param references\n * @param paramType - The expected param type which may include interception marker info\n * @returns The extracted param value\n */\nfunction getParamValueFromSegment(\n  pathSegment: NormalizedAppRouteSegment,\n  params: Params,\n  paramType: DynamicParamTypes\n): string {\n  // If the segment is dynamic, resolve it from the params object\n  if (pathSegment.type === 'dynamic') {\n    return params[pathSegment.param.paramName] as string\n  }\n\n  // If the paramType indicates this is an intercepted param, strip the marker\n  // that matches the interception marker in the param type\n  const interceptionPrefix = interceptionPrefixFromParamType(paramType)\n  if (interceptionPrefix === pathSegment.interceptionMarker) {\n    return pathSegment.name.replace(pathSegment.interceptionMarker, '')\n  }\n\n  // For static segments, use the name\n  return pathSegment.name\n}\n\n/**\n * Resolves a route parameter value from the route segments at the given depth.\n * This shared logic is used by both extractPathnameRouteParamSegmentsFromLoaderTree\n * and resolveRouteParamsFromTree.\n *\n * @param paramName - The parameter name to resolve\n * @param paramType - The parameter type (dynamic, catchall, etc.)\n * @param depth - The current depth in the route tree\n * @param route - The normalized route containing segments\n * @param params - The current params object (used to resolve embedded param references)\n * @param options - Configuration options\n * @returns The resolved parameter value, or undefined if it cannot be resolved\n */\nexport function resolveParamValue(\n  paramName: string,\n  paramType: DynamicParamTypes,\n  depth: number,\n  route: NormalizedAppRoute,\n  params: Params\n): string | string[] | undefined {\n  switch (paramType) {\n    case 'catchall':\n    case 'optional-catchall':\n    case 'catchall-intercepted-(..)(..)':\n    case 'catchall-intercepted-(.)':\n    case 'catchall-intercepted-(..)':\n    case 'catchall-intercepted-(...)':\n      // For catchall routes, derive from pathname using depth to determine\n      // which segments to use\n      const processedSegments: string[] = []\n\n      // Process segments to handle any embedded dynamic params\n      for (let index = depth; index < route.segments.length; index++) {\n        const pathSegment = route.segments[index]\n\n        if (pathSegment.type === 'static') {\n          let value = pathSegment.name\n\n          // For intercepted catch-all params, strip the marker from the first segment\n          const interceptionPrefix = interceptionPrefixFromParamType(paramType)\n          if (\n            interceptionPrefix &&\n            index === depth &&\n            interceptionPrefix === pathSegment.interceptionMarker\n          ) {\n            // Strip the interception marker from the value\n            value = value.replace(pathSegment.interceptionMarker, '')\n          }\n\n          processedSegments.push(value)\n        } else {\n          // If the segment is a param placeholder, check if we have its value\n          if (!params.hasOwnProperty(pathSegment.param.paramName)) {\n            // If the segment is an optional catchall, we can break out of the\n            // loop because it's optional!\n            if (pathSegment.param.paramType === 'optional-catchall') {\n              break\n            }\n\n            // Unknown param placeholder in pathname - can't derive full value\n            return undefined\n          }\n\n          // If the segment matches a param, use the param value\n          // We don't encode values here as that's handled during retrieval.\n          const paramValue = params[pathSegment.param.paramName]\n          if (Array.isArray(paramValue)) {\n            processedSegments.push(...paramValue)\n          } else {\n            processedSegments.push(paramValue as string)\n          }\n        }\n      }\n\n      if (processedSegments.length > 0) {\n        return processedSegments\n      } else if (paramType === 'optional-catchall') {\n        return undefined\n      } else {\n        // We shouldn't be able to match a catchall segment without any path\n        // segments if it's not an optional catchall\n        throw new InvariantError(\n          `Unexpected empty path segments match for a route \"${route.pathname}\" with param \"${paramName}\" of type \"${paramType}\"`\n        )\n      }\n    case 'dynamic':\n    case 'dynamic-intercepted-(..)(..)':\n    case 'dynamic-intercepted-(.)':\n    case 'dynamic-intercepted-(..)':\n    case 'dynamic-intercepted-(...)':\n      // For regular dynamic parameters, take the segment at this depth\n      if (depth < route.segments.length) {\n        const pathSegment = route.segments[depth]\n\n        // Check if the segment at this depth is a placeholder for an unknown param\n        if (\n          pathSegment.type === 'dynamic' &&\n          !params.hasOwnProperty(pathSegment.param.paramName)\n        ) {\n          // The segment is a placeholder like [category] and we don't have the value\n          return undefined\n        }\n\n        // If the segment matches a param, use the param value from params object\n        // Otherwise it's a static segment, just use it directly\n        // We don't encode values here as that's handled during retrieval\n        return getParamValueFromSegment(pathSegment, params, paramType)\n      }\n\n      return undefined\n\n    default:\n      paramType satisfies never\n  }\n}\n"],"names":["resolveParamValue","getParamValueFromSegment","pathSegment","params","paramType","type","param","paramName","interceptionPrefix","interceptionPrefixFromParamType","interceptionMarker","name","replace","depth","route","processedSegments","index","segments","length","value","push","hasOwnProperty","undefined","paramValue","Array","isArray","InvariantError","pathname"],"mappings":";;;;+BAoDgBA;;;eAAAA;;;gCAlDe;iDAKiB;AAEhD;;;;;;;;CAQC,GACD,SAASC,yBACPC,WAAsC,EACtCC,MAAc,EACdC,SAA4B;IAE5B,+DAA+D;IAC/D,IAAIF,YAAYG,IAAI,KAAK,WAAW;QAClC,OAAOF,MAAM,CAACD,YAAYI,KAAK,CAACC,SAAS,CAAC;IAC5C;IAEA,4EAA4E;IAC5E,yDAAyD;IACzD,MAAMC,qBAAqBC,IAAAA,gEAA+B,EAACL;IAC3D,IAAII,uBAAuBN,YAAYQ,kBAAkB,EAAE;QACzD,OAAOR,YAAYS,IAAI,CAACC,OAAO,CAACV,YAAYQ,kBAAkB,EAAE;IAClE;IAEA,oCAAoC;IACpC,OAAOR,YAAYS,IAAI;AACzB;AAeO,SAASX,kBACdO,SAAiB,EACjBH,SAA4B,EAC5BS,KAAa,EACbC,KAAyB,EACzBX,MAAc;IAEd,OAAQC;QACN,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACH,qEAAqE;YACrE,wBAAwB;YACxB,MAAMW,oBAA8B,EAAE;YAEtC,yDAAyD;YACzD,IAAK,IAAIC,QAAQH,OAAOG,QAAQF,MAAMG,QAAQ,CAACC,MAAM,EAAEF,QAAS;gBAC9D,MAAMd,cAAcY,MAAMG,QAA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