<Window x:Class="AxCopilot.Views.AgentStatsDashboardWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="에이전트 실행 통계"
        Width="780" Height="580"
        WindowStyle="None" AllowsTransparency="True"
        Background="Transparent"
        WindowStartupLocation="CenterScreen"
        ResizeMode="CanResizeWithGrip">
    <Border Background="{DynamicResource LauncherBackground}" CornerRadius="12"
            BorderBrush="{DynamicResource BorderColor}" BorderThickness="1">
        <Border.Effect>
            <DropShadowEffect BlurRadius="20" ShadowDepth="4" Opacity="0.3" Color="Black"/>
        </Border.Effect>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="44"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <!-- ── 타이틀바 ── -->
            <Border Grid.Row="0" CornerRadius="12,12,0,0" Background="{DynamicResource ItemBackground}"
                    MouseLeftButtonDown="TitleBar_MouseLeftButtonDown">
                <Grid>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="16,0,0,0">
                        <TextBlock Text="&#xE9D9;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                   Foreground="#A78BFA" VerticalAlignment="Center" Margin="0,0,8,0"/>
                        <TextBlock Text="에이전트 실행 통계" FontSize="14" FontWeight="SemiBold"
                                   Foreground="{DynamicResource PrimaryText}" VerticalAlignment="Center"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,12,0">
                        <Border x:Name="BtnClose" Width="28" Height="28" CornerRadius="6" Cursor="Hand"
                                MouseLeftButtonUp="BtnClose_Click">
                            <Border.Style>
                                <Style TargetType="Border">
                                    <Setter Property="Background" Value="Transparent"/>
                                    <Style.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="Background" Value="#33FF4444"/>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                            <TextBlock Text="&#xE8BB;" FontFamily="Segoe MDL2 Assets" FontSize="10"
                                       Foreground="{DynamicResource SecondaryText}"
                                       HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                    </StackPanel>
                </Grid>
            </Border>

            <!-- ── 기간 필터 탭 ── -->
            <Border Grid.Row="1" Padding="16,10,16,0">
                <StackPanel Orientation="Horizontal">
                    <Border x:Name="FilterToday" Tag="1" CornerRadius="8" Padding="14,5" Margin="0,0,6,0"
                            Background="#4B5EFC" Cursor="Hand" MouseLeftButtonUp="Filter_Click">
                        <TextBlock Text="오늘" FontSize="12" FontWeight="SemiBold" Foreground="White"/>
                    </Border>
                    <Border x:Name="Filter7d" Tag="7" CornerRadius="8" Padding="14,5" Margin="0,0,6,0"
                            Background="{DynamicResource ItemBackground}" Cursor="Hand" MouseLeftButtonUp="Filter_Click">
                        <TextBlock Text="7일" FontSize="12" FontWeight="SemiBold" Foreground="{DynamicResource SecondaryText}"/>
                    </Border>
                    <Border x:Name="Filter30d" Tag="30" CornerRadius="8" Padding="14,5" Margin="0,0,6,0"
                            Background="{DynamicResource ItemBackground}" Cursor="Hand" MouseLeftButtonUp="Filter_Click">
                        <TextBlock Text="30일" FontSize="12" FontWeight="SemiBold" Foreground="{DynamicResource SecondaryText}"/>
                    </Border>
                    <Border x:Name="FilterAll" Tag="0" CornerRadius="8" Padding="14,5"
                            Background="{DynamicResource ItemBackground}" Cursor="Hand" MouseLeftButtonUp="Filter_Click">
                        <TextBlock Text="전체" FontSize="12" FontWeight="SemiBold" Foreground="{DynamicResource SecondaryText}"/>
                    </Border>
                    <Border Width="1" Background="{DynamicResource BorderColor}" Margin="14,2" VerticalAlignment="Stretch"/>
                    <Border CornerRadius="8" Padding="14,5" Background="{DynamicResource ItemBackground}"
                            Cursor="Hand" MouseLeftButtonUp="BtnClearStats_Click">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="&#xE74D;" FontFamily="Segoe MDL2 Assets" FontSize="11"
                                       Foreground="#F87171" VerticalAlignment="Center" Margin="0,0,5,0"/>
                            <TextBlock Text="초기화" FontSize="12" Foreground="#F87171"/>
                        </StackPanel>
                    </Border>
                </StackPanel>
            </Border>

            <!-- ── 메인 콘텐츠 ── -->
            <ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto" Padding="16,10,16,0">
                <StackPanel>
                    <!-- 요약 카드 4종 -->
                    <UniformGrid x:Name="SummaryCards" Columns="4" Margin="0,0,0,12"/>

                    <!-- 일별 활동 차트 -->
                    <Border Background="{DynamicResource ItemBackground}" CornerRadius="10"
                            Padding="16,12" Margin="0,0,0,10">
                        <StackPanel>
                            <TextBlock x:Name="DailyChartTitle" Text="일별 실행 횟수"
                                       FontSize="12" FontWeight="SemiBold"
                                       Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,10"/>
                            <Canvas x:Name="DailyBarChart" Height="100" ClipToBounds="True"/>
                            <Canvas x:Name="DailyBarLabels" Height="18" ClipToBounds="True" Margin="0,2,0,0"/>
                        </StackPanel>
                    </Border>

                    <!-- 도구 사용 빈도 TOP 10 + 모델 분포 -->
                    <Grid Margin="0,0,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="200"/>
                        </Grid.ColumnDefinitions>

                        <!-- 도구 TOP 10 -->
                        <Border Grid.Column="0" Background="{DynamicResource ItemBackground}"
                                CornerRadius="10" Padding="16,12" Margin="0,0,8,0">
                            <StackPanel>
                                <TextBlock Text="도구 사용 TOP 10" FontSize="12" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,10"/>
                                <StackPanel x:Name="ToolFreqPanel"/>
                            </StackPanel>
                        </Border>

                        <!-- 모델 / 탭 분포 -->
                        <Border Grid.Column="1" Background="{DynamicResource ItemBackground}"
                                CornerRadius="10" Padding="16,12">
                            <StackPanel>
                                <TextBlock Text="탭별 실행" FontSize="12" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,10"/>
                                <StackPanel x:Name="TabBreakPanel"/>
                                <TextBlock Text="모델별" FontSize="12" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,10,0,8"/>
                                <StackPanel x:Name="ModelBreakPanel"/>
                            </StackPanel>
                        </Border>
                    </Grid>
                </StackPanel>
            </ScrollViewer>

            <!-- ── 상태바 ── -->
            <Border Grid.Row="3" BorderBrush="{DynamicResource BorderColor}" BorderThickness="0,1,0,0"
                    Padding="16,8" CornerRadius="0,0,12,12">
                <TextBlock x:Name="StatusText" FontSize="11"
                           Foreground="{DynamicResource SecondaryText}"
                           Text="데이터를 불러오는 중..."/>
            </Border>
        </Grid>
    </Border>
</Window>
