<Window x:Class="ytLive.SocialsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Social Media Site Promotion" Height="520" Width="520"
        Icon="/Assets/llama-logo-icon.png"
        WindowStartupLocation="CenterOwner" ResizeMode="NoResize"
        ShowInTaskbar="False" Background="#1a1a2e">

    <Window.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="BoolToVis"/>
        </ResourceDictionary>
    </Window.Resources>

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

        <TextBlock Grid.Row="0" Text="Social Media Site Promotion" FontSize="18" FontWeight="Bold"
                   Foreground="#e0e0e0" Margin="0,0,0,12"/>

        <!-- Show/hide the bar on the stream -->
        <CheckBox Grid.Row="1" IsChecked="{Binding BarEnabled}" Margin="0,0,0,10">
            <TextBlock Text="Show the social bar on the stream" Foreground="#e0e0e0" FontSize="13"/>
        </CheckBox>

        <!-- Sign-in gate: the first slot is always your YouTube channel -->
        <Border Grid.Row="2" Background="#16213e" CornerRadius="5" Padding="10,8" Margin="0,0,0,10"
                Visibility="{Binding ShowSignInBanner, Converter={StaticResource BoolToVis}}">
            <StackPanel>
                <TextBlock Text="Sign in to YouTube first — the first slot is your channel."
                           Foreground="#e0e0e0" FontSize="12" TextWrapping="Wrap"/>
                <Button Content="Sign in to YouTube" Command="{Binding SignInCommand}"
                        Style="{StaticResource YtButtonSecondary}" HorizontalAlignment="Left"
                        Margin="0,8,0,0" Padding="12,4" FontSize="11"/>
            </StackPanel>
        </Border>
        <TextBlock Grid.Row="2" Text="Signing in… open the browser to authorize, then come back here."
                   Foreground="#e94560" FontSize="12" Margin="0,0,0,10"
                   Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>

        <!-- The six fixed slots -->
        <ScrollViewer Grid.Row="3" VerticalScrollBarVisibility="Auto">
            <ItemsControl ItemsSource="{Binding Slots}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,6">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="34"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <!-- Service icon: logo, lock (Premium) or do-not (empty/invalid) -->
                            <Border Grid.Column="0" Width="30" Height="30" CornerRadius="15"
                                    Background="#16213e" HorizontalAlignment="Left" VerticalAlignment="Top">
                                <Grid>
                                    <Path Data="{Binding LogoData}" Fill="White" Stretch="Uniform"
                                          Width="15" Height="15" HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Visibility="{Binding ShowLogo, Converter={StaticResource BoolToVis}}"/>
                                    <Path Data="{Binding LockedIconData}" Fill="#8a93a8" Stretch="Uniform"
                                          Width="15" Height="15" HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Visibility="{Binding IsLocked, Converter={StaticResource BoolToVis}}"/>
                                    <Path Data="{Binding DoNotIconData}" Fill="#5a5a6e" Stretch="Uniform"
                                          Width="15" Height="15" HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Visibility="{Binding ShowDoNot, Converter={StaticResource BoolToVis}}"/>
                                </Grid>
                            </Border>

                            <!-- Handle text / edit box / status -->
                            <Grid Grid.Column="1" Margin="10,0,8,0">
                                <TextBlock Text="{Binding DisplayText}" Foreground="#e0e0e0" FontSize="14"
                                           VerticalAlignment="Top" Margin="0,6,0,0"
                                           TextTrimming="CharacterEllipsis"
                                           Visibility="{Binding ShowDisplay, Converter={StaticResource BoolToVis}}"/>
                                <TextBox Text="{Binding EditText, UpdateSourceTrigger=PropertyChanged}"
                                         Style="{StaticResource YtTextBox}" FontSize="13"
                                         KeyDown="SocialEdit_KeyDown" LostFocus="SocialEdit_LostFocus"
                                         Visibility="{Binding ShowEditBox, Converter={StaticResource BoolToVis}}"/>
                                <TextBlock Text="{Binding Error}" Foreground="#e94560" FontSize="11"
                                           TextWrapping="Wrap" Margin="0,32,0,0"
                                           Visibility="{Binding ShowError, Converter={StaticResource BoolToVis}}"/>
                                <TextBlock Text="Checking…" Foreground="#a0a0b0" FontSize="11" Margin="0,32,0,0"
                                           Visibility="{Binding ShowBusy, Converter={StaticResource BoolToVis}}"/>
                            </Grid>

                            <!-- Row actions -->
                            <StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Top"
                                        Margin="0,3,0,0">
                                <Button Content="Sign in" Click="SignInButton_Click"
                                        Style="{StaticResource YtButtonSecondary}" Padding="10,3"
                                        FontSize="11" Margin="0,0,6,0"
                                        Visibility="{Binding ShowSignInButton, Converter={StaticResource BoolToVis}}"/>
                                <Button Content="+" Click="SlotAdd_Click" Tag="{Binding Index}"
                                        Style="{StaticResource IconButton}" Width="26" Height="26"
                                        ToolTip="Add a social" FontSize="16" FontWeight="Bold"
                                        Visibility="{Binding ShowAddButton, Converter={StaticResource BoolToVis}}"/>
                                <Button Content="&#x270F;&#xFE0F;" Click="SlotEdit_Click" Tag="{Binding Index}"
                                        Style="{StaticResource IconButton}" Width="26" Height="26"
                                        ToolTip="Edit" FontSize="13"
                                        Visibility="{Binding ShowEditButton, Converter={StaticResource BoolToVis}}"/>
                                <Button Content="&#x1F5D1;&#xFE0F;" Click="SlotDelete_Click" Tag="{Binding Index}"
                                        Style="{StaticResource IconButton}" Width="26" Height="26"
                                        ToolTip="Remove" FontSize="12" Foreground="#e94560"
                                        Visibility="{Binding ShowDeleteButton, Converter={StaticResource BoolToVis}}"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

        <!-- Actions -->
        <StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
            <Button Content="Cancel" Command="{Binding CancelCommand}"
                    Style="{StaticResource YtButtonSecondary}" Margin="0,0,8,0" IsCancel="True"/>
            <Button Content="Save" Command="{Binding SaveCommand}" Style="{StaticResource YtButton}" MinWidth="110"/>
        </StackPanel>
    </Grid>
</Window>
