"""GUI management stubs for test purposes.

This module provides minimal GUI infrastructure for testing without full rendering backend.

References:
----------
        Based on swkotor.exe GUI structure:
        - CSWGuiPanel::StartLoadFromLayout @ 0x0040a680 - Loads GUI panel from layout file
        - CSWGuiControl::Load @ 0x00418800 - Loads GUI control from GFF structure
        - CSWGuiExtent::Load @ 0x00409dc0 - Loads GUI extent (position/size) from GFF
        - CSWGuiLabel::Load @ 0x0041b960 - Loads GUI label from GFF structure
        - CSWGuiListBox::Load @ 0x0041d5b0 - Loads GUI listbox from GFF structure
        Derivations and Other Implementations:
        ----------
        https://github.com/th3w1zard1/KotOR.js/tree/master/src/gui/


    Note: This is a minimal stub for testing; full GUI implementation would use a rendering backend
"""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Dict, Optional


@dataclass
class GUI:
    """Lightweight GUI representation for tests."""

    name: str
    visible: bool = True
    metadata: Dict[str, str] = field(default_factory=dict)


class GUIManager:
    """Minimal GUI manager used by the GUI tests."""

    def __init__(self) -> None:
        self._guis: Dict[str, GUI] = {}
        self._active_dialogue: Optional[str] = None

    def load_gui(self, name: str) -> GUI:
        """Load (or retrieve) a GUI by name."""
        if not name:
            raise ValueError("GUI name cannot be empty.")
        gui = self._guis.get(name)
        if gui is None:
            gui = GUI(name=name)
            self._guis[name] = gui
        gui.visible = True
        return gui

    def hide_gui(self, gui: GUI) -> None:
        """Hide a GUI instance."""
        gui.visible = False

    def show_gui(self, gui: GUI) -> None:
        """Show a GUI instance."""
        gui.visible = True

    def start_dialogue(self, dialogue_id: str) -> None:
        """Mark a dialogue sequence as active."""
        if not dialogue_id:
            raise ValueError("Dialogue identifier cannot be empty.")
        self._active_dialogue = dialogue_id

    def end_dialogue(self, dialogue_id: str) -> None:
        """Finalize a dialogue sequence."""
        if self._active_dialogue != dialogue_id:
            raise ValueError(f"Dialogue {dialogue_id!r} is not active.")
        self._active_dialogue = None

    def remove_gui(self, gui: GUI) -> None:
        """Remove a GUI instance from management."""
        self._guis.pop(gui.name, None)
