<!-- PRE-GENERATED (design session). AI 관리: 활성 모델 선택 + 로컬 런타임 설치 + 모델 다운로드 + 저장공간 경고. -->
<ui:FluentWindow x:Class="DansoriEQ.App.AiManagerWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
        Title="AI 관리" Height="680" Width="640"
        WindowStartupLocation="CenterOwner"
        ExtendsContentIntoTitleBar="True" WindowBackdropType="Mica"
        Background="#1B1B1F" Foreground="#F2F3F5"
        FontFamily="Segoe UI Variable, Segoe UI" FontSize="14">
    <Window.Resources>
        <SolidColorBrush x:Key="Card"   Color="#26262B"/>
        <SolidColorBrush x:Key="Card2"  Color="#2D2D33"/>
        <SolidColorBrush x:Key="Stroke" Color="#3A3A42"/>
        <SolidColorBrush x:Key="Dim"    Color="#A8ABB4"/>
        <SolidColorBrush x:Key="Mute"   Color="#767A83"/>
        <SolidColorBrush x:Key="Accent" Color="#4CC2FF"/>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ui:TitleBar Grid.Row="0" Title="AI 관리" Foreground="#F2F3F5" Padding="14,6"/>

        <Border Grid.Row="1" Style="{StaticResource NeonPopup}">
    <DockPanel Margin="20">
        <TextBlock DockPanel.Dock="Top" Text="AI 관리" FontSize="21" FontWeight="Bold" Margin="0,0,0,14"/>
        <Button DockPanel.Dock="Bottom" Content="닫기" Click="Close_Click" HorizontalAlignment="Right"
                Height="36" Padding="18,0" Margin="0,14,0,0"
                Background="{StaticResource Card}" Foreground="{StaticResource Dim}" BorderBrush="{StaticResource Stroke}"/>

        <ScrollViewer VerticalScrollBarVisibility="Auto">
            <StackPanel>

                <!-- 1. 활성 AI -->
                <Border Background="{StaticResource Card}" BorderBrush="{StaticResource Stroke}" BorderThickness="1" CornerRadius="12" Padding="16" Margin="0,0,0,14">
                    <StackPanel>
                        <TextBlock Text="활성 AI 선택" FontWeight="Bold" Foreground="{StaticResource Dim}" Margin="0,0,0,10"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/><ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/><ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="제공자" VerticalAlignment="Center" Foreground="{StaticResource Dim}" Margin="0,0,8,0"/>
                            <ComboBox x:Name="ProviderCombo" Grid.Column="1" SelectionChanged="Provider_Changed" Background="#2D2D33" Foreground="#F2F3F5" Margin="0,0,12,0">
                                <ComboBoxItem>Claude (클라우드)</ComboBoxItem>
                                <ComboBoxItem>ChatGPT · OpenAI (클라우드)</ComboBoxItem>
                                <ComboBoxItem>Gemini (클라우드)</ComboBoxItem>
                                <ComboBoxItem>Ollama (로컬)</ComboBoxItem>
                            </ComboBox>
                            <TextBlock Text="모델" Grid.Column="2" VerticalAlignment="Center" Foreground="{StaticResource Dim}" Margin="0,0,8,0"/>
                            <ComboBox x:Name="ModelCombo" Grid.Column="3" IsEditable="True" SelectionChanged="Model_Changed" Background="#2D2D33" Foreground="#F2F3F5"/>
                        </Grid>
                        <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                            <Button Content="🔄 계정 모델 불러오기" Click="RefreshModels_Click" Height="30" Padding="12,0"
                                    Background="{StaticResource Card2}" Foreground="{StaticResource Dim}" BorderBrush="{StaticResource Stroke}"/>
                            <Button Content="🔌 연결 테스트" Click="TestConnection_Click" Height="30" Padding="12,0" Margin="8,0,0,0"
                                    Background="{StaticResource Card2}" Foreground="{StaticResource Dim}" BorderBrush="{StaticResource Stroke}"/>
                            <TextBlock x:Name="ModelStatus" VerticalAlignment="Center" Foreground="{StaticResource Mute}" FontSize="12" Margin="10,0,0,0"/>
                        </StackPanel>
                        <TextBlock Foreground="{StaticResource Mute}" FontSize="12" Margin="0,8,0,0" TextWrapping="Wrap"
                                   Text="클라우드는 API 키가 있으면 '계정에서 사용 가능한 모델'을 불러오고, 없으면 기본 목록을 씁니다. 직접 입력도 가능하며, 로컬(Ollama)은 다운로드된 모델만 표시됩니다."/>
                    </StackPanel>
                </Border>

                <!-- 2. 로컬 런타임 설치 -->
                <Border Background="{StaticResource Card}" BorderBrush="{StaticResource Stroke}" BorderThickness="1" CornerRadius="12" Padding="16" Margin="0,0,0,14">
                    <StackPanel>
                        <TextBlock Text="로컬 AI 런타임 (자동 설치)" FontWeight="Bold" Foreground="{StaticResource Dim}" Margin="0,0,0,4"/>
                        <TextBlock x:Name="WingetNote" Foreground="{StaticResource Mute}" FontSize="12" Margin="0,0,0,10"
                                   Text="winget으로 자동 설치합니다."/>

                        <Grid Margin="0,0,0,8">
                            <Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0"><TextBlock Text="Ollama" FontWeight="SemiBold"/><TextBlock Text="OpenAI 호환 · per-user(무권한·무재부팅)" Foreground="{StaticResource Mute}" FontSize="12"/></StackPanel>
                            <TextBlock x:Name="OllamaStatus" Grid.Column="1" VerticalAlignment="Center" Foreground="{StaticResource Dim}" FontSize="12" Margin="0,0,10,0" Text="확인 중…"/>
                            <Button Grid.Column="2" Content="설치" Tag="Ollama.Ollama" Click="Install_Click" Height="30" Padding="16,0" Background="{StaticResource Accent}" Foreground="#04222F" FontWeight="Bold" BorderThickness="0"/>
                        </Grid>
                        <TextBlock Foreground="{StaticResource Mute}" FontSize="12" Margin="0,8,0,0" TextWrapping="Wrap"
                                   Text="※ 현재 무인 자동설치가 확실한 로컬 런타임은 Ollama뿐입니다. LM Studio·GPT4All 등은 검증 후 추가 예정."/>
                    </StackPanel>
                </Border>

                <!-- 3. Ollama 모델 다운로드 -->
                <Border Background="{StaticResource Card}" BorderBrush="{StaticResource Stroke}" BorderThickness="1" CornerRadius="12" Padding="16" Margin="0,0,0,14">
                    <StackPanel>
                        <TextBlock Text="로컬 모델 (Ollama)" FontWeight="Bold" Foreground="{StaticResource Dim}" Margin="0,0,0,10"/>
                        <Grid>
                            <Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
                            <ComboBox x:Name="OllamaModelCombo" Grid.Column="0" IsEditable="True" Background="#2D2D33" Foreground="#F2F3F5">
                                <ComboBoxItem>phi3.5</ComboBoxItem>
                                <ComboBoxItem>llama3.2</ComboBoxItem>
                                <ComboBoxItem>qwen2.5:3b</ComboBoxItem>
                                <ComboBoxItem>gemma2:2b</ComboBoxItem>
                            </ComboBox>
                            <Button x:Name="PullBtn" Grid.Column="1" Content="⬇ 다운로드" Click="Pull_Click" Height="32" Padding="14,0" Margin="8,0,0,0" Background="{StaticResource Accent}" Foreground="#04222F" FontWeight="Bold" BorderThickness="0"/>
                        </Grid>
                        <Grid Margin="0,10,0,0">
                            <Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
                            <ProgressBar x:Name="PullProgress" Grid.Column="0" Height="8" Minimum="0" Maximum="100" Background="#2D2D33" Foreground="{StaticResource Accent}" BorderThickness="0"/>
                            <TextBlock x:Name="PullStatus" Grid.Column="1" VerticalAlignment="Center" Foreground="{StaticResource Mute}" FontSize="12" Margin="10,0,0,0" Text="대기"/>
                        </Grid>
                        <TextBlock Text="설치된 모델" Foreground="{StaticResource Mute}" FontSize="12" Margin="0,12,0,4"/>
                        <ListBox x:Name="InstalledList" Height="80" BorderThickness="0" Background="#2D2D33" Foreground="{StaticResource Dim}"/>
                    </StackPanel>
                </Border>

                <!-- 4. 저장공간 경고 -->
                <Border Background="#2A2420" BorderBrush="#5a4a30" BorderThickness="1" CornerRadius="12" Padding="16">
                    <StackPanel>
                        <TextBlock Text="⚠️ 저장 공간 안내" FontWeight="Bold" Foreground="#FFB454"/>
                        <TextBlock Foreground="{StaticResource Dim}" FontSize="13" TextWrapping="Wrap" Margin="0,8,0,0"
                                   Text="로컬 AI 모델은 개당 약 2~8GB이며, 여러 모델을 받거나 큰 모델(수십B급)을 쓰면 전체적으로 수십~수백 GB가 필요할 수 있습니다. 넉넉한 여유 공간(최소 20GB 이상, 여러 모델 사용 시 100GB+)을 권장합니다."/>
                        <TextBlock x:Name="DiskText" Foreground="#FFB454" FontWeight="SemiBold" Margin="0,10,0,0" Text="여유 공간 확인 중…"/>
                    </StackPanel>
                </Border>

            </StackPanel>
        </ScrollViewer>
    </DockPanel>
    </Border>
    </Grid>
</ui:FluentWindow>
