<Window x:Class="PerformanceMonitorLite.Windows.EditCredentialProfileDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Credential Profile"
        SizeToContent="Height" Width="440"
        WindowStartupLocation="CenterOwner"
        ResizeMode="NoResize"
        Icon="/EDD.ico"
        Background="{DynamicResource BackgroundBrush}">
    <Grid Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" Text="Credential Profile" FontSize="18" FontWeight="Bold" Margin="0,0,0,12"
                   Foreground="{DynamicResource ForegroundBrush}"/>

        <TextBlock Grid.Row="1" Text="Profile Name" FontWeight="Bold" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
        <TextBox Grid.Row="2" x:Name="NameBox" Margin="0,0,0,12"/>

        <TextBlock Grid.Row="3" Text="Authentication" FontWeight="Bold" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
        <StackPanel Grid.Row="4" Margin="0,0,0,12">
            <RadioButton x:Name="SqlAuthRadio" Content="SQL Server Authentication" Foreground="{DynamicResource ForegroundBrush}"
                         IsChecked="True" Checked="AuthMode_Changed" Margin="0,0,0,4"/>
            <RadioButton x:Name="ServicePrincipalAuthRadio" Content="Azure — Service Principal" Foreground="{DynamicResource ForegroundBrush}"
                         Checked="AuthMode_Changed" Margin="0,0,0,4"
                         ToolTip="Non-interactive Azure SQL auth using an Entra app registration (client id + secret)."/>
            <RadioButton x:Name="ManagedIdentityAuthRadio" Content="Azure — Managed Identity" Foreground="{DynamicResource ForegroundBrush}"
                         Checked="AuthMode_Changed"
                         ToolTip="Non-interactive Azure SQL auth using the managed identity of the Azure resource running Lite."/>
        </StackPanel>

        <!-- SQL Auth -->
        <StackPanel Grid.Row="5" x:Name="SqlCredentialsPanel" Margin="0,0,0,12">
            <TextBlock Text="Username" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
            <TextBox x:Name="UsernameBox" Margin="0,0,0,8"/>
            <TextBlock Text="Password" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
            <PasswordBox x:Name="PasswordBox"/>
        </StackPanel>

        <!-- Service Principal -->
        <StackPanel Grid.Row="5" x:Name="ServicePrincipalPanel" Visibility="Collapsed" Margin="0,0,0,12">
            <TextBlock Text="Client (Application) ID" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
            <TextBox x:Name="AzureClientIdBox" Margin="0,0,0,8"
                     ToolTip="The Application (client) ID of the Entra app registration / service principal."/>
            <TextBlock Text="Client Secret" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
            <PasswordBox x:Name="AzureClientSecretBox" Margin="0,0,0,8"/>
            <TextBlock Text="Tenant ID (optional)" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
            <TextBox x:Name="AzureTenantIdBox" Margin="0,0,0,4"
                     ToolTip="Optional. Stored for reference; the tenant is resolved automatically from the target server."/>
        </StackPanel>

        <!-- Managed Identity -->
        <StackPanel Grid.Row="5" x:Name="ManagedIdentityPanel" Visibility="Collapsed" Margin="0,0,0,12">
            <TextBlock Text="User-Assigned Identity Client ID (optional)" Foreground="{DynamicResource ForegroundBrush}" Margin="0,0,0,4"/>
            <TextBox x:Name="ManagedIdentityClientIdBox" Margin="0,0,0,8"
                     ToolTip="Leave blank to use the system-assigned managed identity. Set to a client id to use a specific user-assigned identity."/>
            <TextBlock TextWrapping="Wrap" Foreground="{DynamicResource ForegroundMutedBrush}" FontSize="11"
                       Text="Managed Identity only works when Lite is running on an Azure VM / resource that has a managed identity assigned — not on a typical workstation. Use Service Principal for non-interactive auth from a workstation."/>
        </StackPanel>

        <TextBlock Grid.Row="6" x:Name="StatusText" Foreground="{DynamicResource ForegroundMutedBrush}"
                   TextWrapping="Wrap" Margin="0,0,0,8"/>

        <StackPanel Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button x:Name="SaveButton" Content="Save" Width="80" Height="30" Click="SaveButton_Click" Style="{StaticResource AccentButton}" Margin="0,0,8,0"/>
            <Button Content="Cancel" Width="80" Height="30" Click="CancelButton_Click" IsCancel="True"/>
        </StackPanel>
    </Grid>
</Window>
