<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.AgentStripView"
             x:DataType="vm:DetailsIslandViewModel">
  <Border Classes="agent-strip"
          Classes.running="{Binding IsRunning}"
          Margin="18,8,18,0">
    <StackPanel Margin="12,10" Spacing="6">

      <!-- Row 1: pulsing dot · status label · model · stop button -->
      <Grid ColumnDefinitions="Auto,Auto,*,Auto">
        <Ellipse Grid.Column="0"
                 Width="8" Height="8"
                 Fill="{DynamicResource MossBrush}"
                 VerticalAlignment="Center"
                 Classes.status-pulse="{Binding IsRunning}"
                 Margin="0,0,6,0"/>
        <TextBlock Grid.Column="1"
                   Text="{Binding AgentStatusLabel}"
                   FontFamily="{DynamicResource MonoFont}"
                   FontSize="10"
                   LetterSpacing="1.2"
                   Foreground="{DynamicResource TextDimBrush}"
                   VerticalAlignment="Center"
                   Margin="0,0,8,0"/>
        <TextBlock Grid.Column="2"
                   Text="{Binding Model}"
                   FontFamily="{DynamicResource MonoFont}"
                   FontSize="10"
                   Foreground="{DynamicResource TextFaintBrush}"
                   VerticalAlignment="Center"
                   TextTrimming="CharacterEllipsis"
                   IsVisible="{Binding Model, Converter={x:Static ObjectConverters.IsNotNull}}"/>
        <!-- Stop button — only when running -->
        <Button Grid.Column="3"
                Classes="icon-btn"
                Command="{Binding StopCommand}"
                IsVisible="{Binding IsRunning}"
                ToolTip.Tip="Stop agent"
                VerticalAlignment="Center">
          <PathIcon Data="{StaticResource Icon.X}" Width="12" Height="12"
                    Foreground="{DynamicResource BloodBrush}"/>
        </Button>
        <!-- Hand off button — only when idle -->
        <Button Grid.Column="3"
                Classes="btn accent"
                Content="Hand off"
                Command="{Binding RunNowCommand}"
                IsVisible="{Binding !IsRunning}"
                ToolTip.Tip="Hand task off to Claude"
                VerticalAlignment="Center"
                Padding="10,4"/>
      </Grid>

      <!-- Row 2: WORKTREE label + path + copy button -->
      <Grid ColumnDefinitions="Auto,*,Auto"
            IsVisible="{Binding WorktreePath, Converter={x:Static ObjectConverters.IsNotNull}}">
        <TextBlock Grid.Column="0"
                   Text="WORKTREE"
                   FontFamily="{DynamicResource MonoFont}" FontSize="9"
                   LetterSpacing="1.2"
                   Foreground="{DynamicResource TextFaintBrush}"
                   VerticalAlignment="Center"
                   Margin="0,0,8,0"/>
        <TextBlock Grid.Column="1"
                   Text="{Binding WorktreePath}"
                   FontFamily="{DynamicResource MonoFont}" FontSize="10"
                   Foreground="{DynamicResource TextDimBrush}"
                   TextTrimming="CharacterEllipsis"
                   VerticalAlignment="Center"/>
        <Button Grid.Column="2"
                Classes="icon-btn"
                ToolTip.Tip="Copy path"
                VerticalAlignment="Center">
          <PathIcon Data="{StaticResource Icon.Copy}" Width="11" Height="11"/>
        </Button>
      </Grid>

      <!-- Row 3: Branch line — icon + branch ← main + commits chip -->
      <StackPanel Orientation="Horizontal" Spacing="6"
                  IsVisible="{Binding BranchLine, Converter={x:Static ObjectConverters.IsNotNull}}">
        <PathIcon Data="{StaticResource Icon.GitBranch}" Width="11" Height="11"
                  Foreground="{DynamicResource AccentBrush}"
                  VerticalAlignment="Center"/>
        <TextBlock Text="{Binding BranchLine}"
                   FontFamily="{DynamicResource MonoFont}" FontSize="10"
                   Foreground="{DynamicResource TextDimBrush}"
                   VerticalAlignment="Center"/>
        <Border Classes="chip"
                IsVisible="{Binding CommitsOnBranch}"
                Padding="5,1" CornerRadius="4">
          <TextBlock Text="{Binding CommitsOnBranch, StringFormat='{}{0}c'}"
                     FontFamily="{DynamicResource MonoFont}" FontSize="9"
                     Foreground="{DynamicResource TextFaintBrush}"/>
        </Border>
      </StackPanel>

      <!-- Row 4: DIFF label + +add −del + meter bar -->
      <Grid ColumnDefinitions="Auto,Auto,Auto,*">
        <TextBlock Grid.Column="0"
                   Text="DIFF"
                   FontFamily="{DynamicResource MonoFont}" FontSize="9"
                   LetterSpacing="1.2"
                   Foreground="{DynamicResource TextFaintBrush}"
                   VerticalAlignment="Center"
                   Margin="0,0,8,0"/>
        <TextBlock Grid.Column="1"
                   Text="{Binding DiffAdditions, StringFormat='+{0}'}"
                   Classes="diff-add"
                   VerticalAlignment="Center"
                   Margin="0,0,4,0"/>
        <TextBlock Grid.Column="2"
                   Text="{Binding DiffDeletions, StringFormat='−{0}'}"
                   Classes="diff-del"
                   VerticalAlignment="Center"
                   Margin="0,0,8,0"/>
        <!-- Slim 4px meter: track + fill using a Grid overlay -->
        <Grid Grid.Column="3" VerticalAlignment="Center">
          <Border Classes="diff-meter-track"/>
          <Rectangle Classes="diff-meter-fill"
                     Width="{Binding DiffMeterRatio}"
                     HorizontalAlignment="Left"
                     RenderTransformOrigin="0,0.5">
            <Rectangle.RenderTransform>
              <ScaleTransform ScaleX="{Binding $parent[Grid].Bounds.Width}"/>
            </Rectangle.RenderTransform>
          </Rectangle>
        </Grid>
      </Grid>

      <!-- Action buttons -->
      <StackPanel Orientation="Horizontal" Spacing="6" Margin="0,4,0,0">
        <Button Classes="btn" Content="Open diff" Command="{Binding OpenDiffCommand}"/>
        <Button Classes="btn" Command="{Binding OpenWorktreeCommand}"
                ToolTip.Tip="Open worktree in file explorer">
          <StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
            <PathIcon Data="{StaticResource Icon.ArrowOut}"
                      Width="11" Height="11"
                      Foreground="{DynamicResource TextDimBrush}"/>
            <TextBlock Text="Worktree" VerticalAlignment="Center"/>
          </StackPanel>
        </Button>
        <Button Classes="btn accent"
                Content="Continue"
                Command="{Binding ContinueCommand}"
                IsVisible="{Binding ShowFailedActions}"
                ToolTip.Tip="Resume the task from where it failed"
                Padding="10,4"/>
        <Button Classes="btn"
                Content="Reset"
                Command="{Binding ResetCommand}"
                IsVisible="{Binding ShowFailedActions}"
                ToolTip.Tip="Discard the worktree and move the task back to Manual"
                Padding="10,4"/>
      </StackPanel>

    </StackPanel>
  </Border>
</UserControl>
