1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4import { Alert, Box, Snackbar } from '@mui/material';
5import { listen } from '@tauri-apps/api/event';
6import React, { useEffect, useState } from 'react';
7import AppRail from '@/components/AppRail';
8import RawLogDrawer from '@/components/RawLogDrawer';
9import SettingsDialog from '@/components/SettingsDialog';
10import { type FersLogEntry, useFersLogStore } from '@/stores/fersLogStore';
11import { useScenarioStore } from '@/stores/scenarioStore';
12import { AssetLibraryView } from '@/views/AssetLibraryView';
13import { ScenarioView } from '@/views/ScenarioView';
14import { SimulationView } from '@/views/SimulationView';
16export function MainLayout() {
17 const [activeView, setActiveView] = useState('scenario');
18 const [settingsOpen, setSettingsOpen] = useState(false);
19 const logOpen = useFersLogStore((state) => state.isOpen);
20 const appendLog = useFersLogStore((state) => state.appendLog);
21 const { open, message, severity } = useScenarioStore(
22 (state) => state.notificationSnackbar
24 const hideNotification = useScenarioStore(
25 (state) => state.hideNotification
27 const advanceNotification = useScenarioStore(
28 (state) => state.advanceNotification
33 let unlistenLog: (() => void) | undefined;
35 listen<FersLogEntry>('fers-log', (event) => {
36 appendLog(event.payload);
37 }).then((unlisten) => {
39 unlistenLog = unlisten;
58 position: 'fixed', // Ensure it stays in viewport
64 activeView={activeView}
65 onViewChange={setActiveView}
66 onSettingsClick={() => setSettingsOpen(true)}
68 {logOpen && <RawLogDrawer />}
73 minWidth: 0, // Allow shrinking below content size
75 overflow: 'hidden', // Prevent overflow
79 {/* Render all views but only display the active one */}
82 display: activeView === 'scenario' ? 'flex' : 'none',
87 <ScenarioView isActive={activeView === 'scenario'} />
91 display: activeView === 'assets' ? 'block' : 'none',
100 display: activeView === 'simulation' ? 'block' : 'none',
110 onClose={() => setSettingsOpen(false)}
114 autoHideDuration={6000}
115 onClose={hideNotification}
116 anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
117 TransitionProps={{ onExited: advanceNotification }}
120 onClose={hideNotification}
123 sx={{ width: '100%' }}