11import type { Dataset } from "./data/dataset" ;
2+ import { SNCF_PROFILE , parseCard , profileForCard , type DatasetProfile } from "./data/profile" ;
23import { StationRegistry } from "./data/stations" ;
3- import type { SearchQuery , SearchMode , MaxTrain , Journey , SortKey , CalendarDay , StayChoice } from "./types" ;
4+ import type { CardType , SearchQuery , SearchMode , MaxTrain , Journey , SortKey , CalendarDay , StayChoice } from "./types" ;
45import { stayNights , stayFromNights } from "./core/roundtrip" ;
56import {
67 reachableDestinations ,
@@ -44,11 +45,12 @@ import {
4445 modalPopstate ,
4546} from "./ui/modals" ;
4647import { generateBookingUrl } from "./util/booking" ;
47- import { t , setLang , getLang , isLang } from "./i18n" ;
48+ import { t , setLang , getLang , isLang , setSeatUnknown } from "./i18n" ;
4849import * as store from "./state/store" ;
4950import {
5051 MAX_JEUNE_URL ,
5152 MAX_SENIOR_URL ,
53+ INTERRAIL_FRANCE_URL ,
5254 GITHUB_URL ,
5355 GITHUB_ISSUES_URL ,
5456 OVERNIGHT_MAX_CONNECTION_MIN ,
@@ -61,6 +63,8 @@ import { notify } from "./pwa/register";
6163interface Deps {
6264 trains : MaxTrain [ ] ;
6365 meta : Dataset [ "meta" ] ;
66+ /** The dataset's profile: which pass's trains are loaded. */
67+ profile : DatasetProfile ;
6468 registry : StationRegistry ;
6569}
6670
@@ -609,7 +613,8 @@ async function promptInstall(): Promise<void> {
609613}
610614
611615export function initApp ( root : HTMLElement , dataset : Dataset , registry : StationRegistry ) : void {
612- deps = { trains : dataset . trains , meta : dataset . meta , registry } ;
616+ deps = { trains : dataset . trains , meta : dataset . meta , profile : dataset . profile ?? SNCF_PROFILE , registry } ;
617+ setSeatUnknown ( ! deps . profile . seatKnown ) ;
613618 rootRef = root ;
614619 settings = store . loadSettings ( ) ;
615620 const urlLang = new URLSearchParams ( location . search ) . get ( "lang" ) ;
@@ -664,6 +669,7 @@ export function initApp(root: HTMLElement, dataset: Dataset, registry: StationRe
664669 window . addEventListener ( "popstate" , ( ev ) => {
665670 if ( modalPopstate ( ev . state ) ) return ; // Back closed a dialog; the page under it stays
666671 const searched = queryFromUrl ( ) ;
672+ if ( reloadForPass ( searched . card ) ) return ;
667673 const state = entryState ( ) ;
668674 // Restore the FORM and tab from this entry's snapshot (the bare landing's is landingForm
669675 // when set), then the RESULTS from the URL; an entry with no snapshot uses the URL.
@@ -681,6 +687,17 @@ export function initApp(root: HTMLElement, dataset: Dataset, registry: StationRe
681687 } ) ;
682688}
683689
690+ /**
691+ * A pass whose trains aren't the ones loaded (MAX ↔ Interrail) needs the other snapshot:
692+ * open the page again so boot loads it for the URL's card. A navigation, not a reload,
693+ * so the results show straight away. Returns true when it is under way.
694+ */
695+ function reloadForPass ( card : CardType ) : boolean {
696+ if ( profileForCard ( card ) . id === deps . profile . id ) return false ;
697+ location . assign ( location . href ) ;
698+ return true ;
699+ }
700+
684701/**
685702 * Parse the query from the URL, resolve its station names, snap its dates back into the
686703 * bookable window, and correct the address bar to match. The date <input> is clamped
@@ -1070,7 +1087,7 @@ function readQueryFromForm(): SearchQuery {
10701087 . filter ( ( l ) => l . from && l . to )
10711088 : undefined ,
10721089 date : refs . date . value || query . date ,
1073- card : refs . card . value === "senior" ? "senior" : "jeune" ,
1090+ card : parseCard ( refs . card . value ) ,
10741091 departAfter : refs . departAfter . value || undefined ,
10751092 departBefore : refs . departBefore . value || undefined ,
10761093 arriveBefore : refs . arriveBefore . value || undefined ,
@@ -1874,6 +1891,10 @@ function renderSearch(): void {
18741891
18751892 // MAX SENIOR free tickets are weekday-only — flag a weekend outbound, and (round trip)
18761893 // a weekend RETURN on a later day, since either leg must be booked free.
1894+ // No open data says whether an Interrail seat is left: say so above every result.
1895+ if ( ! deps . profile . seatKnown ) {
1896+ refs . results . append ( el ( "p" , { class : "notice" , text : t ( "interrail_seat_notice" ) } ) ) ;
1897+ }
18771898 if ( query . card === "senior" ) {
18781899 if ( isWeekend ( query . date ) ) {
18791900 refs . results . append ( el ( "p" , { class : "notice" , text : t ( "senior_weekend_warn" ) } ) ) ;
@@ -3810,6 +3831,7 @@ function buildLayout(root: HTMLElement): void {
38103831 overnightMaxConnectionMin : OVERNIGHT_MAX_CONNECTION_MIN ,
38113832 jeuneUrl : MAX_JEUNE_URL ,
38123833 seniorUrl : MAX_SENIOR_URL ,
3834+ interrailUrl : INTERRAIL_FRANCE_URL ,
38133835 resolveStation,
38143836 stationLabel : ( id ) => deps . registry . label ( id ) ,
38153837 mode : ( ) => query . mode ,
@@ -3860,6 +3882,7 @@ function buildLayout(root: HTMLElement): void {
38603882 store . saveSettings ( settings ) ;
38613883 query = { ...query , card } ;
38623884 store . updateUrl ( query ) ;
3885+ if ( reloadForPass ( card ) ) return ;
38633886 runSearch ( ) ;
38643887 } ,
38653888 onShare : ( onCopied ) => void shareCurrentUrl ( onCopied ) ,
0 commit comments