<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
             xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
             xmlns:loc="using:ClaudeDo.Ui.Localization"
             x:Class="ClaudeDo.Ui.Views.Islands.Detail.TaskHeaderBar"
             x:DataType="vm:DetailsIslandViewModel">

  <Grid ColumnDefinitions="*,Auto,Auto,Auto">

    <!-- Column 0: id badge + editable title -->
    <StackPanel Grid.Column="0" Spacing="0">
      <TextBlock Classes="meta"
                 Text="{Binding TaskIdBadge}"
                 Margin="0,0,0,4"
                 Cursor="Hand"
                 ToolTip.Tip="{loc:Tr details.copyTaskIdTip}"
                 Tapped="OnTaskIdTapped"/>
      <TextBox Text="{Binding EditableTitle, Mode=TwoWay}"
               Background="Transparent"
               BorderThickness="0"
               FontSize="{StaticResource FontSizeTaskTitle}"
               FontWeight="Medium"
               Foreground="{DynamicResource TextBrush}"
               TextWrapping="Wrap"
               AcceptsReturn="False"
               Padding="0"/>
    </StackPanel>

    <!-- Column 1: pick up in terminal (review / failed) -->
    <Button Grid.Column="1" Classes="icon-btn"
            Command="{Binding PickUpInTerminalCommand}"
            ToolTip.Tip="{loc:Tr details.pickUpInTerminalTip}"
            IsVisible="{Binding CanPickUpInTerminal}"
            VerticalAlignment="Top"
            Margin="6,0,0,0">
      <PathIcon Data="{StaticResource Icon.ArrowOut}" Width="14" Height="14"/>
    </Button>

    <!-- Column 2: trash button (not running) -->
    <Button Grid.Column="2" Classes="icon-btn"
            Command="{Binding DeleteTaskCommand}"
            ToolTip.Tip="{loc:Tr details.deleteTaskTip}"
            IsVisible="{Binding !IsRunning}"
            VerticalAlignment="Top"
            Margin="6,0,0,0">
      <PathIcon Data="{StaticResource Icon.Trash}" Width="14" Height="14"
                Foreground="{DynamicResource BloodBrush}"/>
    </Button>

    <!-- Column 2: skull button (running) -->
    <Button Grid.Column="2" Classes="icon-btn"
            Command="{Binding StopCommand}"
            ToolTip.Tip="{loc:Tr details.killSessionTip}"
            IsVisible="{Binding IsRunning}"
            VerticalAlignment="Top"
            Margin="6,0,0,0">
      <PathIcon Data="{StaticResource Icon.Skull}" Width="14" Height="14"
                Foreground="{DynamicResource BloodBrush}"/>
    </Button>

    <!-- Column 3: gear button with agent settings flyout -->
    <Button Grid.Column="3" Classes="icon-btn"
            ToolTip.Tip="{loc:Tr details.agentSettingsTip}"
            IsEnabled="{Binding AgentSettings.IsEnabled}"
            VerticalAlignment="Top"
            Margin="6,0,0,0">
      <TextBlock Text="⚙" FontSize="{StaticResource FontSizeTaskTitle}"/>
      <Button.Flyout>
        <Flyout Placement="BottomEdgeAlignedRight" ShowMode="Standard">
          <StackPanel Width="340" Spacing="10" Margin="4">
            <TextBlock Text="{loc:Tr details.agentSettingsHeading}" FontWeight="SemiBold"/>
            <ctl:AgentConfigEditor DataContext="{Binding AgentSettings}"/>
          </StackPanel>
        </Flyout>
      </Button.Flyout>
    </Button>

  </Grid>
</UserControl>
