<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
             x:Class="ClaudeDo.Ui.Views.Islands.SessionTerminalView"
             x:DataType="vm:DetailsIslandViewModel">
  <Border Classes="terminal" Margin="18,8,18,0">
    <DockPanel LastChildFill="True">

      <!-- ── Terminal header bar ── -->
      <Grid DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto"
            Background="{DynamicResource Surface2Brush}"
            Height="28">
        <!-- Session label -->
        <TextBlock Grid.Column="1"
                   Text="{Binding BranchLine, StringFormat='claude-session · {0}'}"
                   FontFamily="{DynamicResource MonoFont}" FontSize="10"
                   LetterSpacing="0.8"
                   Foreground="{DynamicResource TextMuteBrush}"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"/>
        <!-- LIVE chip -->
        <Border Grid.Column="2" Classes="live-chip pulsing"
                IsVisible="{Binding IsRunning}"
                Margin="0,0,8,0" VerticalAlignment="Center">
          <StackPanel Orientation="Horizontal" Spacing="5" VerticalAlignment="Center">
            <Ellipse VerticalAlignment="Center"/>
            <TextBlock Text="LIVE" VerticalAlignment="Center"/>
          </StackPanel>
        </Border>
        <!-- DONE chip -->
        <Border Grid.Column="2" Classes="live-chip done"
                IsVisible="{Binding IsDone}"
                Margin="0,0,8,0" VerticalAlignment="Center">
          <StackPanel Orientation="Horizontal" Spacing="5" VerticalAlignment="Center">
            <Ellipse VerticalAlignment="Center" Fill="{DynamicResource MossBrush}"/>
            <TextBlock Text="DONE" VerticalAlignment="Center"
                       Foreground="{DynamicResource MossBrush}"/>
          </StackPanel>
        </Border>
        <!-- FAILED chip -->
        <Border Grid.Column="2" Classes="live-chip failed"
                IsVisible="{Binding IsFailed}"
                Margin="0,0,8,0" VerticalAlignment="Center">
          <StackPanel Orientation="Horizontal" Spacing="5" VerticalAlignment="Center">
            <Ellipse VerticalAlignment="Center" Fill="{DynamicResource BloodBrush}"/>
            <TextBlock Text="FAILED" VerticalAlignment="Center"
                       Foreground="{DynamicResource BloodBrush}"/>
          </StackPanel>
        </Border>
      </Grid>

      <!-- ── Log output ── -->
      <ScrollViewer Name="LogScroll"
                    VerticalScrollBarVisibility="Visible"
                    AllowAutoHide="False"
                    Padding="10,8,10,12">
        <ItemsControl ItemsSource="{Binding Log}">
          <ItemsControl.ItemTemplate>
            <DataTemplate DataType="vm:LogLineViewModel">
              <Grid ColumnDefinitions="60,*" Margin="0,1">
                <!-- Timestamp -->
                <TextBlock Grid.Column="0"
                           Classes="log-ts"
                           Text="{Binding TimestampFormatted}"/>
                <!-- Message text — selectable so the user can copy raw output -->
                <SelectableTextBlock Grid.Column="1"
                                     Text="{Binding Text}" Tag="{Binding ClassName}"
                                     FontFamily="{DynamicResource MonoFont}" FontSize="11"
                                     Foreground="{DynamicResource TextDimBrush}"
                                     TextWrapping="Wrap"/>
              </Grid>
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
      </ScrollViewer>

    </DockPanel>
  </Border>
</UserControl>
