{"version":3,"file":"messaging-route-state-CNGwjtJz.mjs","names":[],"sources":["../src/screens/messaging-route-state.ts"],"sourcesContent":["import type { MessagingRoute } from \"@fluid-app/messaging-ui/app\";\nimport {\n  decodeSlugSegment,\n  encodeSlugSegment,\n  splitSlug,\n} from \"./screen-route-slug-utils\";\n\nfunction parsePositiveInteger(value: string | undefined): number | null {\n  if (!value) return null;\n  const parsed = Number(value);\n  if (!Number.isSafeInteger(parsed) || parsed <= 0) return null;\n  return parsed;\n}\n\nexport function getMessagingBaseSlug(currentSlug: string): string {\n  return splitSlug(currentSlug)[0] ?? \"messaging\";\n}\n\nexport function resolveMessagingRouteFromSlug(\n  currentSlug: string,\n): MessagingRoute {\n  const [, rawSection, rawConversationId, rawNestedSection, rawNestedId] =\n    splitSlug(currentSlug).map(decodeSlugSegment);\n\n  switch (rawSection) {\n    case undefined:\n      return { view: \"index\" };\n    case \"new\":\n      return { view: \"new\" };\n    case \"scheduled\":\n      return { view: \"scheduled\" };\n    case \"conversation\":\n    case \"conversations\": {\n      const conversationId = parsePositiveInteger(rawConversationId);\n      if (!conversationId) {\n        return { view: \"index\" };\n      }\n\n      switch (rawNestedSection) {\n        case undefined:\n          return { view: \"conversation\", conversationId };\n        case \"pins\":\n          return { view: \"pins\", conversationId };\n        case \"messages\":\n          return rawNestedId\n            ? { view: \"message\", conversationId, messageId: rawNestedId }\n            : { view: \"conversation\", conversationId };\n        case \"at\":\n          return rawNestedId\n            ? { view: \"at\", conversationId, at: rawNestedId }\n            : { view: \"conversation\", conversationId };\n        case \"scheduled\": {\n          const editScheduledId = parsePositiveInteger(rawNestedId);\n          return editScheduledId\n            ? { view: \"conversation\", conversationId, editScheduledId }\n            : { view: \"conversation\", conversationId };\n        }\n        default:\n          return { view: \"conversation\", conversationId };\n      }\n    }\n    default:\n      return { view: \"index\" };\n  }\n}\n\nexport function buildMessagingSlugFromRoute(\n  baseSlug: string,\n  route: MessagingRoute,\n): string {\n  const normalizedBaseSlug = getMessagingBaseSlug(baseSlug);\n\n  switch (route.view) {\n    case \"index\":\n      return normalizedBaseSlug;\n    case \"new\":\n      return `${normalizedBaseSlug}/new`;\n    case \"scheduled\":\n      return `${normalizedBaseSlug}/scheduled`;\n    case \"conversation\":\n      if (route.editScheduledId !== undefined) {\n        return `${normalizedBaseSlug}/conversations/${encodeSlugSegment(\n          route.conversationId,\n        )}/scheduled/${encodeSlugSegment(route.editScheduledId)}`;\n      }\n      return `${normalizedBaseSlug}/conversations/${encodeSlugSegment(\n        route.conversationId,\n      )}`;\n    case \"pins\":\n      return `${normalizedBaseSlug}/conversations/${encodeSlugSegment(\n        route.conversationId,\n      )}/pins`;\n    case \"message\":\n      return `${normalizedBaseSlug}/conversations/${encodeSlugSegment(\n        route.conversationId,\n      )}/messages/${encodeSlugSegment(route.messageId)}`;\n    case \"at\":\n      return `${normalizedBaseSlug}/conversations/${encodeSlugSegment(\n        route.conversationId,\n      )}/at/${encodeSlugSegment(route.at)}`;\n    default: {\n      const _exhaustive: never = route;\n      return normalizedBaseSlug;\n    }\n  }\n}\n"],"mappings":";;AAOA,SAAS,qBAAqB,OAA0C;AACtE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,SAAS,OAAO,MAAM;AAC5B,KAAI,CAAC,OAAO,cAAc,OAAO,IAAI,UAAU,EAAG,QAAO;AACzD,QAAO;;AAGT,SAAgB,qBAAqB,aAA6B;AAChE,QAAO,UAAU,YAAY,CAAC,MAAM;;AAGtC,SAAgB,8BACd,aACgB;CAChB,MAAM,GAAG,YAAY,mBAAmB,kBAAkB,eACxD,UAAU,YAAY,CAAC,IAAI,kBAAkB;AAE/C,SAAQ,YAAR;EACE,KAAK,KAAA,EACH,QAAO,EAAE,MAAM,SAAS;EAC1B,KAAK,MACH,QAAO,EAAE,MAAM,OAAO;EACxB,KAAK,YACH,QAAO,EAAE,MAAM,aAAa;EAC9B,KAAK;EACL,KAAK,iBAAiB;GACpB,MAAM,iBAAiB,qBAAqB,kBAAkB;AAC9D,OAAI,C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