<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="using:ClawdDotNet.Desktop.ViewModels"
             xmlns:svc="using:ClawdDotNet.App.Services"
             xmlns:ctrl="using:ClawdDotNet.Desktop.Controls"
             xmlns:conv="using:ClawdDotNet.Desktop.Converters"
             mc:Ignorable="d" d:DesignWidth="1100" d:DesignHeight="700"
             x:Class="ClawdDotNet.Desktop.Views.LogPageView"
             x:DataType="vm:LogPageViewModel">

  <DockPanel>

    <!-- Werkzeugleiste -->
    <StackPanel DockPanel.Dock="Top" Classes="toolbar">

      <TextBlock Text="Modul:" FontSize="12.5" VerticalAlignment="Center" />
      <ComboBox ItemsSource="{Binding Modules}" SelectedItem="{Binding SelectedModule}"
                Width="180" MinHeight="30" Padding="8,3" />

      <TextBlock Text="Stufe:" FontSize="12.5" VerticalAlignment="Center" Margin="6,0,0,0" />
      <ComboBox ItemsSource="{Binding Levels}" SelectedItem="{Binding SelectedLevel}"
                Width="120" MinHeight="30" Padding="8,3" />

      <Border Classes="sep" />

      <Button Classes="toolbar" Command="{Binding RefreshModulesCommand}">
        <StackPanel Orientation="Horizontal" Spacing="6">
          <ctrl:StrokeIcon Data="{StaticResource IconRefresh}" Width="14" Height="14" />
          <TextBlock Text="Aktualisieren" />
        </StackPanel>
      </Button>

      <Button Classes="toolbar" Command="{Binding ClearCommand}">
        <StackPanel Orientation="Horizontal" Spacing="6">
          <ctrl:StrokeIcon Data="{StaticResource IconTrash}" Width="14" Height="14" />
          <TextBlock Text="Leeren" />
        </StackPanel>
      </Button>

      <Button Classes="toolbar" Command="{Binding OpenFolderCommand}">
        <StackPanel Orientation="Horizontal" Spacing="6">
          <ctrl:StrokeIcon Data="{StaticResource IconFolder}" Width="14" Height="14" />
          <TextBlock Text="Ordner öffnen" />
        </StackPanel>
      </Button>

      <CheckBox Content="Mitlaufen" IsChecked="{Binding FollowTail}"
                VerticalAlignment="Center" Margin="8,0,0,0" />
    </StackPanel>

    <!--
      SelectableTextBlock je Zeile statt eines grossen TextBlocks: So laesst sich eine
      einzelne Zeile herauskopieren, und die Virtualisierung des ItemsControl haelt auch
      bei 2000 Zeilen die Darstellung fluessig.
    -->
    <Border Classes="console">
      <ScrollViewer Name="Scroller" VerticalScrollBarVisibility="Auto"
                    HorizontalScrollBarVisibility="Auto">
        <ItemsControl ItemsSource="{Binding Lines}">

          <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
              <VirtualizingStackPanel />
            </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>

          <ItemsControl.ItemTemplate>
            <DataTemplate DataType="svc:LogLine">
              <!-- Nur Warnung und Fehler werden hervorgehoben. Alles einzufärben macht
                   die Ansicht unruhig und lenkt von genau den Zeilen ab, die auffallen
                   sollen; der Rest behält die Vordergrundfarbe des Themas. -->
              <SelectableTextBlock Classes="mono"
                                   Classes.warn="{Binding Level,
                                       Converter={x:Static conv:StringEqualsConverter.Instance},
                                       ConverterParameter=WRN}"
                                   Classes.err="{Binding Level,
                                       Converter={x:Static conv:StringEqualsConverter.Instance},
                                       ConverterParameter=ERR}"
                                   Classes.ftl="{Binding Level,
                                       Converter={x:Static conv:StringEqualsConverter.Instance},
                                       ConverterParameter=FTL}"
                                   Text="{Binding Text}"
                                   LineHeight="21"
                                   TextWrapping="NoWrap" />
            </DataTemplate>
          </ItemsControl.ItemTemplate>

        </ItemsControl>
      </ScrollViewer>
    </Border>

  </DockPanel>

</UserControl>
