<Window x:Class="AxCopilot.Views.SkillEditorWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="스킬 편집기"
        Width="780" Height="660"
        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="*"/>
                <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="&#xE70F;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                   Foreground="#4B5EFC" VerticalAlignment="Center" Margin="0,0,8,0"/>
                        <TextBlock x:Name="TitleText" Text="새 스킬 만들기" FontSize="14" FontWeight="SemiBold"
                                   Foreground="{DynamicResource PrimaryText}" VerticalAlignment="Center"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,12,0">
                        <Border 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>

            <!-- ── 메인 콘텐츠 ── -->
            <Grid Grid.Row="1" Margin="16,10,16,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="260"/>
                </Grid.ColumnDefinitions>

                <!-- ═══ 좌측: 편집 폼 ═══ -->
                <ScrollViewer Grid.Column="0" VerticalScrollBarVisibility="Auto" Margin="0,0,12,0">
                    <StackPanel>
                        <!-- 이름 + 레이블 -->
                        <Grid Margin="0,0,0,10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Margin="0,0,6,0">
                                <TextBlock Text="이름 (영문, 슬래시 명령)" FontSize="11" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,4"/>
                                <TextBox x:Name="TxtName" FontSize="13" Padding="10,8,10,8"
                                         Background="{DynamicResource ItemBackground}"
                                         Foreground="{DynamicResource PrimaryText}"
                                         BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
                                         MaxLength="40">
                                    <TextBox.Resources>
                                        <Style TargetType="Border"><Setter Property="CornerRadius" Value="8"/></Style>
                                    </TextBox.Resources>
                                </TextBox>
                            </StackPanel>
                            <StackPanel Grid.Column="1" Margin="6,0,0,0">
                                <TextBlock Text="표시 이름 (한글)" FontSize="11" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,4"/>
                                <TextBox x:Name="TxtLabel" FontSize="13" Padding="10,8,10,8"
                                         Background="{DynamicResource ItemBackground}"
                                         Foreground="{DynamicResource PrimaryText}"
                                         BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
                                         MaxLength="60">
                                    <TextBox.Resources>
                                        <Style TargetType="Border"><Setter Property="CornerRadius" Value="8"/></Style>
                                    </TextBox.Resources>
                                </TextBox>
                            </StackPanel>
                        </Grid>

                        <!-- 설명 -->
                        <StackPanel Margin="0,0,0,10">
                            <TextBlock Text="설명" FontSize="11" FontWeight="SemiBold"
                                       Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,4"/>
                            <TextBox x:Name="TxtDescription" FontSize="13" Padding="10,8,10,8"
                                     Background="{DynamicResource ItemBackground}"
                                     Foreground="{DynamicResource PrimaryText}"
                                     BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
                                     MaxLength="200">
                                <TextBox.Resources>
                                    <Style TargetType="Border"><Setter Property="CornerRadius" Value="8"/></Style>
                                </TextBox.Resources>
                            </TextBox>
                        </StackPanel>

                        <!-- 아이콘 + 런타임 요구사항 -->
                        <Grid Margin="0,0,0,10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Margin="0,0,12,0">
                                <TextBlock Text="아이콘" FontSize="11" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,4"/>
                                <StackPanel x:Name="IconSelectorPanel" Orientation="Horizontal"/>
                            </StackPanel>
                            <StackPanel Grid.Column="1">
                                <TextBlock Text="런타임 요구사항" FontSize="11" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,4"/>
                                <StackPanel Orientation="Horizontal">
                                    <ComboBox x:Name="CmbRequires" Width="160" VerticalAlignment="Center"
                                              SelectedIndex="0">
                                        <ComboBoxItem Content="없음 (기본)" Tag=""/>
                                        <ComboBoxItem Content="Python" Tag="python"/>
                                        <ComboBoxItem Content="Node.js" Tag="node"/>
                                        <ComboBoxItem Content="Python + Node.js" Tag="python,node"/>
                                    </ComboBox>
                                </StackPanel>
                            </StackPanel>
                        </Grid>

                        <!-- 지시사항 (마크다운 편집) -->
                        <StackPanel Margin="0,0,0,6">
                            <Grid Margin="0,0,0,4">
                                <TextBlock Text="지시사항 (마크다운)" FontSize="11" FontWeight="SemiBold"
                                           Foreground="{DynamicResource SecondaryText}"/>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                    <Border x:Name="BtnInsertToolList" CornerRadius="4" Padding="8,2,8,2"
                                            Background="{DynamicResource ItemBackground}" Cursor="Hand"
                                            MouseLeftButtonUp="BtnInsertTemplate_Click" Tag="tools"
                                            Margin="0,0,4,0">
                                        <TextBlock Text="도구 목록 삽입" FontSize="10"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Border>
                                    <Border x:Name="BtnInsertFormat" CornerRadius="4" Padding="8,2,8,2"
                                            Background="{DynamicResource ItemBackground}" Cursor="Hand"
                                            MouseLeftButtonUp="BtnInsertTemplate_Click" Tag="format"
                                            Margin="0,0,4,0">
                                        <TextBlock Text="출력 형식 삽입" FontSize="10"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Border>
                                    <Border CornerRadius="4" Padding="8,2,8,2"
                                            Background="{DynamicResource ItemBackground}" Cursor="Hand"
                                            MouseLeftButtonUp="BtnInsertTemplate_Click" Tag="steps">
                                        <TextBlock Text="단계별 삽입" FontSize="10"
                                                   Foreground="{DynamicResource SecondaryText}"/>
                                    </Border>
                                </StackPanel>
                            </Grid>
                            <TextBox x:Name="TxtInstructions" FontSize="12.5" Padding="10,8,10,8"
                                     AcceptsReturn="True" AcceptsTab="True"
                                     VerticalScrollBarVisibility="Auto"
                                     Height="220"
                                     FontFamily="Consolas, Cascadia Code, Segoe UI"
                                     Background="{DynamicResource ItemBackground}"
                                     Foreground="{DynamicResource PrimaryText}"
                                     BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
                                     TextWrapping="Wrap"
                                     TextChanged="TxtInstructions_TextChanged">
                                <TextBox.Resources>
                                    <Style TargetType="Border"><Setter Property="CornerRadius" Value="8"/></Style>
                                </TextBox.Resources>
                            </TextBox>
                        </StackPanel>
                    </StackPanel>
                </ScrollViewer>

                <!-- ═══ 우측: 도구 선택 + 미리보기 ═══ -->
                <Grid Grid.Column="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <!-- 도구 체크리스트 -->
                    <Border Grid.Row="0" Background="{DynamicResource ItemBackground}"
                            CornerRadius="10" Padding="12,10,12,10">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Text="사용할 도구 (allowed-tools)"
                                       FontSize="11" FontWeight="SemiBold"
                                       Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,8"/>
                            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                                <StackPanel x:Name="ToolCheckListPanel"/>
                            </ScrollViewer>
                        </Grid>
                    </Border>

                    <!-- 미리보기 정보 -->
                    <Border Grid.Row="1" Background="{DynamicResource ItemBackground}"
                            CornerRadius="10" Padding="12,10,12,10" Margin="0,8,0,0">
                        <StackPanel>
                            <TextBlock Text="미리보기" FontSize="11" FontWeight="SemiBold"
                                       Foreground="{DynamicResource SecondaryText}" Margin="0,0,0,6"/>
                            <TextBlock x:Name="PreviewTokens" FontSize="11"
                                       Foreground="{DynamicResource SecondaryText}"/>
                            <TextBlock x:Name="PreviewFileName" FontSize="10.5" FontFamily="Consolas"
                                       Foreground="{DynamicResource SecondaryText}" Margin="0,4,0,0"/>
                        </StackPanel>
                    </Border>
                </Grid>
            </Grid>

            <!-- ── 하단 버튼 ── -->
            <Border Grid.Row="2" BorderBrush="{DynamicResource BorderColor}" BorderThickness="0,1,0,0"
                    Padding="16,10,16,10" CornerRadius="0,0,12,12">
                <Grid>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                        <TextBlock x:Name="StatusText" FontSize="11"
                                   Foreground="{DynamicResource SecondaryText}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                        <Border CornerRadius="8" Padding="18,8,18,8" Margin="0,0,8,0"
                                Background="{DynamicResource ItemBackground}" Cursor="Hand"
                                MouseLeftButtonUp="BtnCancel_Click">
                            <TextBlock Text="취소" FontSize="12.5"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Border>
                        <Border CornerRadius="8" Padding="18,8,18,8" Margin="0,0,8,0"
                                Background="{DynamicResource ItemBackground}" Cursor="Hand"
                                MouseLeftButtonUp="BtnPreview_Click">
                            <TextBlock Text="미리보기" FontSize="12.5"
                                       Foreground="{DynamicResource SecondaryText}"/>
                        </Border>
                        <Border CornerRadius="8" Padding="22,8,22,8"
                                Background="#4B5EFC" Cursor="Hand"
                                MouseLeftButtonUp="BtnSave_Click">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="&#xE74E;" FontFamily="Segoe MDL2 Assets" FontSize="12"
                                           Foreground="White" VerticalAlignment="Center" Margin="0,0,6,0"/>
                                <TextBlock Text="저장" FontSize="12.5" FontWeight="SemiBold" Foreground="White"/>
                            </StackPanel>
                        </Border>
                    </StackPanel>
                </Grid>
            </Border>
        </Grid>
    </Border>
</Window>
