<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:ClaudeDo.Ui.ViewModels.Modals"
        xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
        xmlns:converters="using:ClaudeDo.Ui.Converters"
        xmlns:loc="using:ClaudeDo.Ui.Localization"
        x:Class="ClaudeDo.Ui.Views.Modals.LogVisualizerView"
        x:DataType="vm:LogVisualizerViewModel"
        Title="{loc:Tr modals.logVisualizer.title}"
        Width="760" Height="520"
        WindowDecorations="None"
        ExtendClientAreaToDecorationsHint="True"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource SurfaceBrush}">
  <Window.Resources>
    <converters:WorkerLogLevelToBrushConverter x:Key="WorkerLogLevelToBrush"/>
  </Window.Resources>
  <Window.KeyBindings>
    <KeyBinding Gesture="Escape" Command="{Binding CloseCommand}"/>
  </Window.KeyBindings>

  <ctl:ModalShell Title="{loc:Tr modals.logVisualizer.title}" CloseCommand="{Binding CloseCommand}">
    <DockPanel LastChildFill="True">
      <!-- Toolbar: filter · status · refresh -->
      <Grid DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto" Margin="14,10">
        <CheckBox Grid.Column="0"
                  Content="{loc:Tr modals.logVisualizer.warnErrorOnly}"
                  IsChecked="{Binding WarnErrorOnly}"
                  VerticalAlignment="Center"/>
        <TextBlock Grid.Column="1" Classes="meta"
                   Text="{Binding StatusText}"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   Foreground="{DynamicResource TextMuteBrush}"/>
        <Button Grid.Column="2" Classes="btn"
                Content="{loc:Tr modals.logVisualizer.refresh}"
                Command="{Binding RefreshCommand}"/>
      </Grid>

      <!-- Last 30 min, oldest-first -->
      <Border Classes="terminal" Margin="14,0,14,14">
        <ScrollViewer VerticalScrollBarVisibility="Visible" AllowAutoHide="False" Padding="10,8">
          <ItemsControl ItemsSource="{Binding Rows}">
            <ItemsControl.ItemTemplate>
              <DataTemplate DataType="vm:LogVisualizerRow">
                <Grid ColumnDefinitions="64,*" Margin="0,1">
                  <TextBlock Grid.Column="0" Classes="log-ts" Text="{Binding Time}"/>
                  <SelectableTextBlock Grid.Column="1"
                                       Text="{Binding Message}"
                                       Foreground="{Binding Level, Converter={StaticResource WorkerLogLevelToBrush}}"
                                       TextWrapping="Wrap"/>
                </Grid>
              </DataTemplate>
            </ItemsControl.ItemTemplate>
          </ItemsControl>
        </ScrollViewer>
      </Border>
    </DockPanel>
  </ctl:ModalShell>
</Window>
