<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="using:OF_DL.Gui.Views"
        x:Class="OF_DL.Gui.Views.FaqWindow"
        x:DataType="views:FaqWindow"
        Width="800"
        Height="680"
        MinWidth="650"
        MinHeight="550"
        Title="FAQ"
        Background="{DynamicResource WindowBackgroundBrush}"
        mc:Ignorable="d">
    <Window.Styles>
        <Style Selector="Border.faqCard">
            <Setter Property="Background" Value="{DynamicResource SurfaceBackgroundBrush}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SurfaceBorderBrush}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="CornerRadius" Value="12" />
            <Setter Property="Padding" Value="20" />
            <Setter Property="Margin" Value="0,0,0,16" />
            <Setter Property="BoxShadow" Value="0 1 3 0 #0F000000, 0 1 2 -1 #0F000000" />
            <Setter Property="Transitions">
                <Transitions>
                    <BoxShadowsTransition Property="BoxShadow" Duration="0:0:0.2" />
                </Transitions>
            </Setter>
        </Style>

        <Style Selector="Border.faqCard:pointerover">
            <Setter Property="BoxShadow" Value="0 4 6 -1 #19000000, 0 2 4 -1 #0F000000" />
        </Style>

        <Style Selector="TextBlock.question">
            <Setter Property="FontSize" Value="18" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>

        <Style Selector="TextBlock.answer">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Foreground" Value="{DynamicResource TextSecondaryBrush}" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="LineHeight" Value="22" />
        </Style>

        <Style Selector="Button.link">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Foreground" Value="{DynamicResource PrimaryButtonBackgroundBrush}" />
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="HorizontalAlignment" Value="Left" />
        </Style>

        <Style Selector="Button.link:pointerover">
            <Setter Property="Foreground" Value="{DynamicResource PrimaryButtonBackgroundHoverBrush}" />
        </Style>

        <Style Selector="Border.codeBlock">
            <Setter Property="Background" Value="{DynamicResource PreviewBackgroundBrush}" />
            <Setter Property="BorderBrush" Value="{DynamicResource PreviewBorderBrush}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="CornerRadius" Value="8" />
            <Setter Property="Padding" Value="12" />
            <Setter Property="Margin" Value="0,8,0,0" />
        </Style>
    </Window.Styles>

    <Grid Margin="24"
          RowDefinitions="Auto,*">
        <!-- Header -->
        <TextBlock Grid.Row="0"
                   FontSize="32"
                   FontWeight="Bold"
                   Foreground="{DynamicResource TextPrimaryBrush}"
                   Text="Frequently Asked Questions"
                   Margin="0,0,0,20" />

        <!-- FAQ Items -->
        <ScrollViewer Grid.Row="1">
            <ItemsControl ItemsSource="{Binding Entries}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate x:DataType="views:FaqEntry">
                        <Border Classes="faqCard">
                            <StackPanel Spacing="12">
                                <!-- Question -->
                                <TextBlock Classes="question"
                                           Text="{Binding Question}" />

                                <!-- Answer Paragraphs -->
                                <ItemsControl ItemsSource="{Binding Paragraphs}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate x:DataType="x:String">
                                            <TextBlock Classes="answer"
                                                       Text="{Binding .}"
                                                       Margin="0,0,0,8" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>

                                <!-- Links -->
                                <ItemsControl IsVisible="{Binding HasLinks}"
                                              ItemsSource="{Binding Links}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Spacing="8" />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate x:DataType="views:FaqLink">
                                            <Button Classes="link"
                                                    Content="{Binding Label}"
                                                    ToolTip.Tip="{Binding Url}"
                                                    CommandParameter="{Binding Url}"
                                                    Click="OnLinkClick" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>

                                <!-- Code Snippet -->
                                <Border IsVisible="{Binding HasCodeSnippet}"
                                        Classes="codeBlock">
                                    <TextBlock Text="{Binding CodeSnippet}"
                                               FontFamily="Consolas,Courier New,monospace"
                                               FontSize="13"
                                               Foreground="{DynamicResource TextPrimaryBrush}"
                                               TextWrapping="Wrap" />
                                </Border>
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</Window>
