// SPDX-License-Identifier: GPL-3.0-or-later
//
// Eydos OS first-run installer.

// Pull every YAML under `locales/` into the rust-i18n runtime
// registry. ltk runs its own `i18n!()` invocation; the two registries
// merge at runtime, so widget strings and installer copy share the same
// `t!()` namespace.
rust_i18n::i18n!( "locales", fallback = "en" );

mod app;
mod assets;
mod cli;
mod compositor;
mod daemon;
mod disks;
mod firstboot;
mod flow;
mod fs;
mod i18n;
mod install;
mod ipc;
mod network;
mod platform;
mod screens;
mod state;
mod ui;

use ltk::ThemeMode;

fn main()
{
	let args = cli::parse();

	if args.firstboot
	{
		firstboot::run();
		return;
	}

	if args.daemon
	{
		if let Err( e ) = daemon::run()
		{
			eprintln!( "eydos-installer daemon: {e}" );
			std::process::exit( 1 );
		}
		return;
	}

	// Scenario: --install / --configure win; otherwise the marker a
	// finished install leaves behind selects the first-boot flow.
	let mode = args.mode.unwrap_or_else( ||
	{
		if std::path::Path::new( install::CONFIGURE_PENDING ).exists()
		{
			state::WizardMode::Configure
		}
		else
		{
			state::WizardMode::Install
		}
	} );

	// Load the on-disk default theme. ltk has no in-code fallback: the
	// `ltk-theme-default` package (or a dev-time `LTK_THEMES_DIR` env)
	// must provide `default/theme.json`.
	let doc = ltk::ThemeDocument::find( "default" )
		.expect( "ltk: the `default` theme is required (install `ltk-theme-default` or set `LTK_THEMES_DIR`)" );
	ltk::set_active_document( doc );
	ltk::set_active_mode( ThemeMode::Light );

	// Default locale until the user picks one on screen 02.
	i18n::set_locale( i18n::DEFAULT );

	compositor::set_kiosk( true );
	ltk::run( app::InstallerApp::new( args.window_size, args.test, mode ) );
	compositor::set_kiosk( false );
}
