use std::{cell::RefCell, rc::Rc};

use evdev::Device;
use gtk::{glib, pango, prelude::*};

use super::{
    devices::{CameraMode, DeviceCatalog},
    diagnostics::DiagnosticsLog,
    preview::{LauncherPreview, PreviewBinding, PreviewSurface},
    state::{
        BreakoutSizeChoice, BreakoutSizePreset, CaptureSizeChoice, CaptureSizePreset,
        FeedSourceChoice, FeedSourcePreset, LauncherState,
    },
};

include!("ui_components/types.rs");
include!("ui_components/build_contexts.rs");
include!("ui_components/style.rs");
include!("ui_components/panel_chips.rs");
include!("ui_components/combo_helpers.rs");
include!("ui_components/control_buttons.rs");
include!("ui_components/display_pane.rs");
include!("ui_components/scale_reset.rs");

pub fn build_launcher_view(
    app: &gtk::Application,
    server_addr: &str,
    catalog: &DeviceCatalog,
    state: &LauncherState,
) -> LauncherView {
    let LauncherShellContext {
        window,
        root,
        staging_row,
        operations,
        left_pane,
        right_pane,
        relay_light,
        relay_value,
        routing_light,
        routing_value,
        gpio_light,
        gpio_value,
        shortcut_value,
    } = include!("ui_components/build_shell.rs");

    let DeviceControlsContext {
        device_refresh_button,
        camera_combo,
        camera_quality_combo,
        microphone_combo,
        speaker_combo,
        keyboard_combo,
        mouse_combo,
        camera_channel_toggle,
        microphone_channel_toggle,
        audio_channel_toggle,
        audio_gain_scale,
        audio_gain_value,
        mic_gain_scale,
        mic_gain_value,
        audio_check_detail,
        audio_check_meter,
        devices_panel,
        preview_panel,
        camera_preview_stack,
        camera_preview_frame,
        camera_preview,
        camera_mirror_button,
        camera_mirror_revealer,
        camera_status,
        camera_test_button,
        microphone_test_button,
        microphone_replay_button,
        speaker_test_button,
    } = include!("ui_components/build_device_controls.rs");

    let OperationsRailContext {
        server_entry,
        start_button,
        clipboard_button,
        probe_button,
        usb_recover_button,
        power_auto_button,
        power_on_button,
        power_off_button,
        power_detail,
        input_toggle_button,
        swap_key_button,
        diagnostics_copy_button,
        diagnostics_popout_button,
        diagnostics_log,
        diagnostics_label,
        diagnostics_scroll,
        console_copy_button,
        console_popout_button,
        console_level_combo,
        session_log_level,
        status_label,
        session_log_buffer,
        session_log_view,
        preview,
    } = include!("ui_components/build_operations_rail.rs");

    include!("ui_components/assemble_view.rs")
}

#[cfg(test)]
#[path = "tests/ui_components_scale.rs"]
mod tests;
