{"version":3,"sources":["../../../../../../src/shared/lib/router/utils/get-segment-param.tsx"],"sourcesContent":["import { INTERCEPTION_ROUTE_MARKERS } from './interception-routes'\nimport type { DynamicParamTypes } from '../../app-router-types'\n\nexport type SegmentParam = {\n  paramName: string\n  paramType: DynamicParamTypes\n}\n\n/**\n * Parse dynamic route segment to type of parameter\n */\nexport function getSegmentParam(segment: string): SegmentParam | null {\n  const interceptionMarker = INTERCEPTION_ROUTE_MARKERS.find((marker) =>\n    segment.startsWith(marker)\n  )\n\n  // if an interception marker is part of the path segment, we need to jump ahead\n  // to the relevant portion for param parsing\n  if (interceptionMarker) {\n    segment = segment.slice(interceptionMarker.length)\n  }\n\n  if (segment.startsWith('[[...') && segment.endsWith(']]')) {\n    return {\n      // TODO-APP: Optional catchall does not currently work with parallel routes,\n      // so for now aren't handling a potential interception marker.\n      paramType: 'optional-catchall',\n      paramName: segment.slice(5, -2),\n    }\n  }\n\n  if (segment.startsWith('[...') && segment.endsWith(']')) {\n    return {\n      paramType: interceptionMarker\n        ? `catchall-intercepted-${interceptionMarker}`\n        : 'catchall',\n      paramName: segment.slice(4, -1),\n    }\n  }\n\n  if (segment.startsWith('[') && segment.endsWith(']')) {\n    return {\n      paramType: interceptionMarker\n        ? `dynamic-intercepted-${interceptionMarker}`\n        : 'dynamic',\n      paramName: segment.slice(1, -1),\n    }\n  }\n\n  return null\n}\n\nexport function isCatchAll(\n  type: DynamicParamTypes\n): type is\n  | 'catchall'\n  | 'catchall-intercepted-(..)(..)'\n  | 'catchall-intercepted-(.)'\n  | 'catchall-intercepted-(..)'\n  | 'catchall-intercepted-(...)'\n  | 'optional-catchall' {\n  return (\n    type === 'catchall' ||\n    type === 'catchall-intercepted-(..)(..)' ||\n    type === 'catchall-intercepted-(.)' ||\n    type === 'catchall-intercepted-(..)' ||\n    type === 'catchall-intercepted-(...)' ||\n    type === 'optional-catchall'\n  )\n}\n\nexport function getParamProperties(paramType: DynamicParamTypes): {\n  repeat: boolean\n  optional: boolean\n} {\n  let repeat = false\n  let optional = false\n\n  switch (paramType) {\n    case 'catchall':\n    case 'catchall-intercepted-(..)(..)':\n    case 'catchall-intercepted-(.)':\n    case 'catchall-intercepted-(..)':\n    case 'catchall-intercepted-(...)':\n      repeat = true\n      break\n    case 'optional-catchall':\n      repeat = true\n      optional = true\n      break\n    case 'dynamic':\n    case 'dynamic-intercepted-(..)(..)':\n    case 'dynamic-intercepted-(.)':\n    case 'dynamic-intercepted-(..)':\n    case 'dynamic-intercepted-(...)':\n      break\n    default:\n      paramType satisfies never\n  }\n\n  return { repeat, optional }\n}\n"],"names":["INTERCEPTION_ROUTE_MARKERS","getSegmentParam","segment","interceptionMarker","find","marker","startsWith","slice","length","endsWith","paramType","paramName","isCatchAll","type","getParamProperties","repeat","optional"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,wBAAuB;AAQlE;;CAEC,GACD,OAAO,SAASC,gBAAgBC,OAAe;IAC7C,MAAMC,qBAAqBH,2BAA2BI,IAAI,CAAC,CAACC,SAC1DH,QAAQI,UAAU,CAACD;IAGrB,+EAA+E;IAC/E,4CAA4C;IAC5C,IAAIF,oBAAoB;QACtBD,UAAUA,QAAQK,KAAK,CAACJ,mBAAmBK,MAAM;IACnD;IAEA,IAAIN,QAAQI,UAAU,CAAC,YAAYJ,QAAQO,QAAQ,CAAC,OAAO;QACzD,OAAO;YACL,4EAA4E;YAC5E,8DAA8D;YAC9DC,WAAW;YACXC,WAAWT,QAAQK,KAAK,CAAC,GAAG,CAAC;QAC/B;IACF;IAEA,IAAIL,QAAQI,UAAU,CAAC,WAAWJ,QAAQO,QAAQ,CAAC,MAAM;QACvD,OAAO;YACLC,WAAWP,qBACP,CAAC,qBAAqB,EAAEA,oBAAoB,GAC5C;YACJQ,WAAWT,QAAQK,KAAK,CAAC,GAAG,CAAC;QAC/B;IACF;IAEA,IAAIL,QAAQI,UAAU,CAAC,QAAQJ,QAAQO,QAAQ,CAAC,MAAM;QACpD,OAAO;YACLC,WAAWP,qBAC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