<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
             xmlns:islands="using:ClaudeDo.Ui.Views.Islands"
             xmlns:loc="using:ClaudeDo.Ui.Localization"
             x:DataType="vm:TaskMonitorViewModel"
             x:Class="ClaudeDo.Ui.Views.MissionControl.MonitorPaneView">
  <Border Classes="monitor-pane"
          DragDrop.AllowDrop="True"
          Classes.mon-review="{Binding IsWaitingForReview}"
          Classes.mon-done="{Binding IsDone}"
          Classes.mon-roadblock="{Binding HasRoadblock}"
          Classes.mon-failed="{Binding IsFailed}"
          BorderThickness="1" CornerRadius="10" ClipToBounds="True">
    <DockPanel LastChildFill="True">

      <!-- Header: per-task action icons -->
      <Border DockPanel.Dock="Top"
              Background="{DynamicResource Surface2Brush}"
              BorderBrush="{DynamicResource LineBrush}"
              BorderThickness="0,0,0,1" Padding="6,3"
              PointerPressed="OnHeaderPressed">
        <StackPanel Orientation="Horizontal" Spacing="2"
                    HorizontalAlignment="Right" VerticalAlignment="Center">
          <Button Classes="title-ctrl"
                  Command="{Binding OpenInAppCommand}"
                  ToolTip.Tip="{loc:Tr missionControl.openInApp}">
            <PathIcon Data="{StaticResource Icon.ArrowOut}" Width="12" Height="12"/>
          </Button>
          <Button Classes="title-ctrl"
                  Command="{Binding DetachCommand}"
                  ToolTip.Tip="{Binding DetachTooltip}">
            <PathIcon Data="{StaticResource Icon.WinMax}" Width="12" Height="12"/>
          </Button>
          <Button Classes="title-ctrl"
                  Command="{Binding CancelTaskCommand}"
                  IsVisible="{Binding IsRunning}"
                  ToolTip.Tip="{loc:Tr missionControl.cancel}">
            <PathIcon Data="{StaticResource Icon.WinClose}" Width="12" Height="12"/>
          </Button>
        </StackPanel>
      </Border>

      <!-- Roadblock banner (amber) -->
      <Border DockPanel.Dock="Top"
              IsVisible="{Binding HasRoadblock}"
              Background="{DynamicResource RoadblockTintBrush}"
              BorderBrush="{DynamicResource AmberBrush}"
              BorderThickness="0,0,0,1" Padding="12,6">
        <StackPanel Orientation="Horizontal" Spacing="8">
          <PathIcon Data="{StaticResource Icon.Warning}"
                    Foreground="{DynamicResource AmberBrush}"
                    Width="13" Height="13" VerticalAlignment="Center" />
          <TextBlock Classes="meta" Text="{Binding Roadblocks}"
                     Foreground="{DynamicResource AmberBrush}"
                     TextWrapping="Wrap" VerticalAlignment="Center" />
        </StackPanel>
      </Border>

      <!-- Failure banner (red) -->
      <Border DockPanel.Dock="Top"
              IsVisible="{Binding ShowRoadblock}"
              Background="{DynamicResource ErrorTintBrush}"
              BorderBrush="{DynamicResource BloodBrush}"
              BorderThickness="0,0,0,1" Padding="12,6">
        <StackPanel Orientation="Horizontal" Spacing="8">
          <PathIcon Data="{StaticResource Icon.Warning}"
                    Foreground="{DynamicResource BloodBrush}"
                    Width="13" Height="13" VerticalAlignment="Center" />
          <TextBlock Classes="meta" Text="{Binding RoadblockMessage}"
                     Foreground="{DynamicResource BloodBrush}"
                     TextWrapping="Wrap" VerticalAlignment="Center" />
        </StackPanel>
      </Border>

      <!-- Question prompt (AskUser): answer a running task's question inline -->
      <Border DockPanel.Dock="Top"
              IsVisible="{Binding HasPendingQuestion}"
              Background="{DynamicResource AccentSoftBrush}"
              BorderBrush="{DynamicResource AccentBrush}"
              BorderThickness="0,0,0,1" Padding="12,8">
        <StackPanel Spacing="6">
          <TextBlock Classes="meta"
                     Text="{loc:Tr missionControl.question.title}"
                     Foreground="{DynamicResource AccentBrush}" FontWeight="SemiBold" />
          <TextBlock Text="{Binding PendingQuestion}" TextWrapping="Wrap"
                     Foreground="{DynamicResource TextBrush}" />
          <Grid ColumnDefinitions="*,Auto" ColumnSpacing="6">
            <TextBox Grid.Column="0"
                     Text="{Binding AnswerDraft, UpdateSourceTrigger=PropertyChanged}"
                     PlaceholderText="{loc:Tr missionControl.question.placeholder}"
                     AcceptsReturn="False">
              <TextBox.KeyBindings>
                <KeyBinding Gesture="Enter" Command="{Binding SubmitAnswerCommand}" />
              </TextBox.KeyBindings>
            </TextBox>
            <Button Grid.Column="1"
                    Content="{loc:Tr missionControl.question.send}"
                    Command="{Binding SubmitAnswerCommand}" />
          </Grid>
        </StackPanel>
      </Border>

      <!-- Console body: reuse SessionTerminalView -->
      <islands:SessionTerminalView
          Entries="{Binding Log}"
          Label="{Binding DisplayTitle}"
          IsRunning="{Binding IsRunning}"
          IsDone="{Binding IsDone}"
          IsFailed="{Binding IsFailed}" />

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