import React from 'react'; import WcsButton from '../components/WcsButton'; import sessionMemory from '../lib/sessionMemory'; import { getSourceFromPath } from '../services/railwayService'; export default function Displays({ onBack, navigate }) { const source = getSourceFromPath(window.location.pathname); const prefix = source === 'supabase' ? '/ferrovia' : ''; const types = [ { id: 'classiques', label: 'Classiques' }, { id: 'eva', label: 'EVA' }, { id: 'afl', label: 'AFL' }, { id: 'transilien', label: 'TRANSILIEN' } ]; // Nettoyage du chemin pour extraire la gare même avec /ferrovia const cleanPath = (typeof window !== 'undefined' ? window.location.pathname : '').replace(/^\/ferrovia/, ''); const parts = cleanPath.split('/').filter(Boolean); const typeIds = types.map(t => t.id); let gare = null; if (parts[0] === 'afficheurs' && parts[1] && !typeIds.includes(parts[1])) { try { gare = decodeURIComponent(parts.slice(1).join('/')); } catch (e) { gare = parts.slice(1).join('/'); } } else { const paramsForGare = new URLSearchParams(window.location.search || ''); const g = paramsForGare.get('gare'); if (g) { try { gare = decodeURIComponent(String(g).replace(/\+/g, ' ')).replace(/-/g, ' '); } catch (e) { gare = String(g).replace(/-/g, ' '); } } } // Déterminer le mode (departs/arrivees) const params = new URLSearchParams(window.location.search || ''); let mode = params.get('mode'); if (!mode) { try { const stored = sessionMemory.get('afficheurMode'); if (stored) mode = stored; } catch (e) {} } if (!mode) mode = 'departs'; return (

Choisissez un type d'afficheur

{source === 'supabase' ? '🗄️ BDD Ferrovia' : '🌐 SNCF (GTFS)'}
{gare &&

Gare sélectionnée : {gare}

}

Mode sélectionné : {mode === 'arrivees' ? 'Arrivées' : 'Départs'}

{types.map((t) => (
{ if (typeof navigate === 'function') { const kebab = gare ? String(gare).trim().replace(/\s+/g, '-').replace(/\//g, '/') : ''; navigate(`${prefix}/select-afficheur?gare=${encodeURIComponent(kebab)}&mode=${mode}&type=${t.id}`); return; } alert(`${t.label} pour ${gare || '—'}`); }} >

{t.label}

Afficher le style {t.label} pour la gare {gare || ''}.

))}
{ try { if (typeof onBack === 'function') { onBack(); return; } } catch (e) {} if (typeof window !== 'undefined' && window.history && window.history.length > 1) { window.history.back(); } else { window.location.href = prefix || '/'; } }} label="Retour" />
); }