import type { LocalizedEndRoute } from "./LocalizedEndRoute"; import type { LocalizedRoute, SegmentRoute } from "./interfaces"; import type { LocaleType, SegmentRoutePath } from "./types"; export class LocalizedSegmentRoute implements SegmentRoute, LocalizedRoute { localizedPaths: Map; nestedRoutes: LocalizedRoute[] = []; defaultRoute: LocalizedEndRoute | undefined; constructor(localizedPaths: Map) { this.localizedPaths = localizedPaths; } freeze(): void { Object.freeze(this); Object.freeze(this.nestedRoutes); } getPath(locale?: Locales): SegmentRoutePath { if (!locale) throw new Error("Missing locale"); return this.localizedPaths.get(locale)!; } isSegment(): true { return true; } isLocalized(): true { return true; } toJSON(): unknown[] { return [...this.localizedPaths.entries()]; } toString(): string { return JSON.stringify(this.toJSON()); } }