<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:conv="using:ClawdDotNet.Desktop.Converters"
             mc:Ignorable="d" d:DesignWidth="1100" d:DesignHeight="700"
             x:Class="ClawdDotNet.Desktop.Views.AgentChatsPageView"
             x:DataType="vm:AgentChatsPageViewModel">

  <DockPanel MaxWidth="820" HorizontalAlignment="Left">

    <!-- Wer mit wem -->
    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="10"
                Margin="0,0,0,16" VerticalAlignment="Center">
      <TextBlock Text="Agent A:" FontWeight="SemiBold" VerticalAlignment="Center" />
      <ComboBox Width="220" ItemsSource="{Binding Agents}" SelectedItem="{Binding AgentA}" />

      <TextBlock Text="Agent B:" FontWeight="SemiBold" VerticalAlignment="Center"
                 Margin="8,0,0,0" />
      <ComboBox Width="220" ItemsSource="{Binding Agents}" SelectedItem="{Binding AgentB}" />
    </StackPanel>

    <!-- Leerzustand: erklärt, warum hier noch nichts steht -->
    <Border Classes="card" DockPanel.Dock="Top" VerticalAlignment="Top"
            IsVisible="{Binding IsEmpty}">
      <TextBlock Classes="muted" Text="{Binding EmptyText}" TextWrapping="Wrap" />
    </Border>

    <!-- Verlauf -->
    <ScrollViewer VerticalScrollBarVisibility="Auto" IsVisible="{Binding !IsEmpty}">
      <ItemsControl ItemsSource="{Binding Messages}">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <StackPanel Spacing="10" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
          <DataTemplate DataType="vm:AgentMessageItem">
            <Border Classes="card" MaxWidth="560"
                    Classes.accent="{Binding !IsFromAgentA}"
                    HorizontalAlignment="{Binding !IsFromAgentA,
                        Converter={x:Static conv:ChatAlignmentConverter.Instance}}">
              <StackPanel Spacing="4">
                <DockPanel>
                  <TextBlock FontSize="12" FontWeight="SemiBold" Text="{Binding SenderName}" />
                  <TextBlock Classes="caption" DockPanel.Dock="Right" HorizontalAlignment="Right"
                             Text="{Binding Time, StringFormat='{}{0:dd.MM. HH:mm}'}" />
                </DockPanel>
                <SelectableTextBlock FontSize="13.5" TextWrapping="Wrap" Text="{Binding Text}" />
              </StackPanel>
            </Border>
          </DataTemplate>
        </ItemsControl.ItemTemplate>
      </ItemsControl>
    </ScrollViewer>

  </DockPanel>

</UserControl>
