<?xml version="1.0" encoding="UTF-8" ?>
<Window
    x:Class="LlamaApp.Views.OverlayWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Microsoft.UI.Xaml.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <!--
        Spotlight-style prompt overlay. Borderless Mica backdrop, centered on
        the active monitor. A header (brand + model chip) followed by a WebView2
        that hosts the running llama server's WebUI for the currently loaded
        model — the WebUI provides its own prompt + streaming chat, so the old
        native composer/response widgets are gone. Esc (or losing focus)
        dismisses it.

        The overlay grows to ~60% × ~70% of the active monitor's work area to
        give the embedded WebUI room to breathe. Summoning refreshes the URL
        (so a newly-loaded model is picked up) without reloading when the URL
        is unchanged (so an in-flight chat isn't reset).
    -->
    <Window.SystemBackdrop>
        <MicaBackdrop Kind="Base" />
    </Window.SystemBackdrop>

    <!-- Esc dismisses the overlay (the old input box key handler is gone).
         KeyboardAccelerators live on Control, not Window, so the Grid is wrapped
         in a UserControl. Window-level accelerators defined here are processed by
         the input system regardless of focus — they fire even when focus is inside
         the nested WebView2 (a separate HWND), which a Grid/Window KeyDown handler
         would miss. -->
    <UserControl>
        <UserControl.KeyboardAccelerators>
            <KeyboardAccelerator Key="Escape" Invoked="EscapeAccelerator_Invoked" />
        </UserControl.KeyboardAccelerators>

    <Grid Padding="18" RowSpacing="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" /> <!-- Header (title bar) -->
            <RowDefinition Height="*" />    <!-- WebView2 hosting the model WebUI -->
            <RowDefinition Height="Auto" /> <!-- Footer hint -->
        </Grid.RowDefinitions>

        <!-- ============ Header: brand + model chip ============ -->
        <Grid Grid.Row="0" ColumnSpacing="10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <!-- Brand: logo + wordmark -->
            <StackPanel Grid.Column="0"
                        Orientation="Horizontal"
                        Spacing="6"
                        VerticalAlignment="Center">
                <Image Source="{ThemeResource BrandLogoSource}"
                       Width="18" Height="18"
                       Stretch="Uniform"
                       VerticalAlignment="Center" />
                <StackPanel Orientation="Horizontal"
                            Spacing="1"
                            VerticalAlignment="Center">
                    <TextBlock Text="llama"
                               FontSize="13"
                               FontWeight="SemiBold"
                               Foreground="{ThemeResource TextFillColorPrimaryBrush}"
                               VerticalAlignment="Center" />
                    <TextBlock Text=".app"
                               FontSize="13"
                               FontWeight="SemiBold"
                               Foreground="{StaticResource BrandAccentBrush}"
                               VerticalAlignment="Center" />
                </StackPanel>
            </StackPanel>

            <!-- Spacer -->

            <!-- Model chip: status dot + model name (or "No model"). -->
            <Border Grid.Column="2"
                    CornerRadius="12"
                    Padding="10,4"
                    Background="{ThemeResource ControlFillColorSecondaryBrush}"
                    BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
                    BorderThickness="1"
                    VerticalAlignment="Center">
                <StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
                    <!-- Status dot: green when a model is loaded, amber otherwise.
                         Fill is flipped in RefreshModelBadge(). -->
                    <Ellipse x:Name="StatusDot"
                             Width="8" Height="8"
                             Fill="#3FB950" />
                    <TextBlock x:Name="ModelBadge"
                               FontSize="12"
                               TextTrimming="CharacterEllipsis"
                               TextWrapping="NoWrap"
                               MaxWidth="560"
                               VerticalAlignment="Center" />
                </StackPanel>
            </Border>
        </Grid>

        <!-- ============ WebView2: hosts the llama server WebUI for the loaded model ============ -->
        <!-- DefaultBackgroundColor transparent lets the Mica backdrop show through
             while the page is blank/loading. Source is assigned in Summon() from
             BuildModelUri(); only re-navigated when the URL actually changes so a
             re-summon during a chat doesn't reset it. -->
        <controls:WebView2 x:Name="ModelWebUi"
                            Grid.Row="1"
                            DefaultBackgroundColor="Transparent"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch" />

        <!-- ============ Footer: keyboard hint ============ -->
        <TextBlock Grid.Row="2"
                   HorizontalAlignment="Center"
                   FontSize="11"
                   Foreground="{ThemeResource TextFillColorTertiaryBrush}">
            <Run Text="Esc" FontWeight="SemiBold" />
            <Run Text=" to dismiss" />
        </TextBlock>
    </Grid>
    </UserControl>
</Window>