<UserControl x:Class="AxCopilot.Views.Controls.AgentSidebarView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Width="270">

    <!-- Phase 17-UI-D: 좌측 사이드바 UserControl
         기존 SidebarPanel Grid를 대체. ChatWindow 프록시 패턴으로 기존 코드와 호환.
         탭 세그먼트(Chat/Cowork/Code) + 카테고리 필터 + 대화 목록 + 사용자 계정. -->

    <Border Background="{DynamicResource ItemBackground}"
            BorderBrush="{DynamicResource BorderColor}"
            BorderThickness="0,0,1,0">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="54"/>   <!-- 0: 헤더 (로고 + 새 대화) -->
                <RowDefinition Height="Auto"/> <!-- 1: 탭 세그먼트 (Chat/Cowork/Code) -->
                <RowDefinition Height="Auto"/> <!-- 2: 검색 -->
                <RowDefinition Height="Auto"/> <!-- 3: 카테고리 드롭다운 -->
                <RowDefinition Height="*"/>    <!-- 4: 대화 목록 -->
                <RowDefinition Height="Auto"/> <!-- 5: 하단 삭제 버튼 -->
                <RowDefinition Height="52"/>   <!-- 6: 사용자 계정 -->
            </Grid.RowDefinitions>

            <!-- Row 0: 헤더 — 로고 + 새 대화 버튼 -->
            <Grid Grid.Row="0" Margin="16,0">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <Border Background="{DynamicResource AccentColor}" CornerRadius="6"
                            Width="24" Height="24">
                        <TextBlock Text="&#xE8BD;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                   Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                    <TextBlock Text="AX Agent" FontSize="14" FontWeight="Bold"
                               Foreground="{DynamicResource PrimaryText}"
                               VerticalAlignment="Center" Margin="10,0,0,0"/>
                </StackPanel>
                <Button x:Name="BtnNewChat" Style="{DynamicResource GhostBtn}"
                        HorizontalAlignment="Right" VerticalAlignment="Center"
                        Click="BtnNewChat_Click" ToolTip="새 대화 (Ctrl+N)"
                        WindowChrome.IsHitTestVisibleInChrome="True">
                    <TextBlock Text="&#xE710;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                               Foreground="{DynamicResource SecondaryText}"/>
                </Button>
            </Grid>

            <!-- Row 1: 탭 세그먼트 (Chat | Cowork | Code) — Claude.ai 인라인 탭 -->
            <Border Grid.Row="1" Margin="12,0,12,8"
                    Background="{DynamicResource HintBackground}"
                    CornerRadius="8" Padding="3">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Border x:Name="SidebarTabChat" Grid.Column="0" CornerRadius="6" Padding="0,6"
                            Cursor="Hand" MouseLeftButtonUp="SidebarTabChat_Click">
                        <TextBlock Text="Chat" FontSize="12" FontWeight="Medium"
                                   HorizontalAlignment="Center"
                                   Foreground="{DynamicResource PrimaryText}"/>
                    </Border>
                    <Border x:Name="SidebarTabCowork" Grid.Column="1" CornerRadius="6" Padding="0,6"
                            Cursor="Hand" MouseLeftButtonUp="SidebarTabCowork_Click">
                        <TextBlock Text="Cowork" FontSize="12" FontWeight="Medium"
                                   HorizontalAlignment="Center"
                                   Foreground="{DynamicResource PrimaryText}"/>
                    </Border>
                    <Border x:Name="SidebarTabCode" Grid.Column="2" CornerRadius="6" Padding="0,6"
                            Cursor="Hand" MouseLeftButtonUp="SidebarTabCode_Click">
                        <TextBlock Text="Code" FontSize="12" FontWeight="Medium"
                                   HorizontalAlignment="Center"
                                   Foreground="{DynamicResource PrimaryText}"/>
                    </Border>
                </Grid>
            </Border>

            <!-- Row 2: 검색 -->
            <Border Grid.Row="2" Background="{DynamicResource HintBackground}"
                    CornerRadius="10" Margin="12,0,12,8" Padding="10,7">
                <Grid>
                    <TextBlock Text="&#xE721;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                               Foreground="{DynamicResource SecondaryText}" VerticalAlignment="Center"/>
                    <TextBox x:Name="SearchBox" Background="Transparent" BorderThickness="0"
                             Foreground="{DynamicResource PrimaryText}"
                             CaretBrush="{DynamicResource AccentColor}" FontSize="12"
                             VerticalAlignment="Center" Margin="22,0,0,0"
                             TextChanged="SearchBox_TextChanged"/>
                </Grid>
            </Border>

            <!-- Row 3: 카테고리 드롭다운 -->
            <Border Grid.Row="3" Margin="12,0,12,6">
                <Border x:Name="BtnCategoryDrop" Cursor="Hand" Padding="10,6"
                        CornerRadius="8" MouseLeftButtonUp="BtnCategoryDrop_Click">
                    <Border.Style>
                        <Style TargetType="Border">
                            <Setter Property="Background" Value="Transparent"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Background" Value="{DynamicResource ItemHoverBackground}"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                    <Grid>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock x:Name="CategoryIcon" Text="&#xE8BD;"
                                       FontFamily="Segoe MDL2 Assets" FontSize="12"
                                       Foreground="{DynamicResource AccentColor}"
                                       VerticalAlignment="Center" Margin="0,0,8,0"/>
                            <TextBlock x:Name="CategoryLabel" Text="모든 주제"
                                       FontSize="12" FontWeight="SemiBold"
                                       Foreground="{DynamicResource PrimaryText}"
                                       VerticalAlignment="Center"/>
                        </StackPanel>
                        <TextBlock Text="&#xE70D;" FontFamily="Segoe MDL2 Assets" FontSize="9"
                                   Foreground="{DynamicResource SecondaryText}"
                                   HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    </Grid>
                </Border>
            </Border>

            <!-- Row 4: 대화 목록 (x:Name="ConversationPanel" — ChatWindow 프록시 대상) -->
            <ScrollViewer Grid.Row="4" VerticalScrollBarVisibility="Auto"
                          HorizontalScrollBarVisibility="Disabled">
                <StackPanel x:Name="ConversationPanel" Margin="6,0"/>
            </ScrollViewer>

            <!-- Row 5: 전체 삭제 -->
            <Border Grid.Row="5" BorderBrush="{DynamicResource SeparatorColor}" BorderThickness="0,1,0,0"
                    Padding="0,4">
                <Button x:Name="BtnDeleteAll" Style="{DynamicResource GhostBtn}"
                        HorizontalAlignment="Center" VerticalAlignment="Center"
                        Click="BtnDeleteAll_Click">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="&#xE74D;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                   Foreground="#AA5555" VerticalAlignment="Center" Margin="0,0,6,0"/>
                        <TextBlock Text="전체 삭제" FontSize="11" Foreground="#AA5555"/>
                    </StackPanel>
                </Button>
            </Border>

            <!-- Row 6: 사용자 계정 (x:Name 요소들 — ChatWindow SetupUserInfo()에서 직접 접근) -->
            <Border Grid.Row="6" Margin="12,0,12,8">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Border Grid.Column="0" Width="34" Height="34" CornerRadius="17"
                            Background="{DynamicResource AccentColor}" Margin="0,0,10,0">
                        <TextBlock x:Name="UserInitialSidebar" Text="U" FontSize="14" FontWeight="Bold"
                                   Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                    <StackPanel Grid.Column="1" VerticalAlignment="Center">
                        <TextBlock x:Name="UserNameText" Text="" FontSize="12" FontWeight="SemiBold"
                                   Foreground="{DynamicResource PrimaryText}"
                                   TextTrimming="CharacterEllipsis"/>
                        <TextBlock x:Name="UserPcText" Text="" FontSize="10"
                                   Foreground="{DynamicResource SecondaryText}"/>
                    </StackPanel>
                </Grid>
            </Border>
        </Grid>
    </Border>
</UserControl>
