<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:OpenGptChat"
    xmlns:sys="clr-namespace:System;assembly=System.Runtime"
    xmlns:controls="clr-namespace:OpenGptChat.Controls">
    
    <sys:Double x:Key="NormalFontSize">14</sys:Double>
    <sys:Double x:Key="SmallFontSize">12</sys:Double>
    <sys:Double x:Key="LargeFontSize">16</sys:Double>
    <sys:Double x:Key="ExtremLargeFontSize">18</sys:Double>

    <CircleEase x:Key="ease" EasingMode="EaseOut"/>


    <Style TargetType="{x:Type controls:NoteControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:NoteControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            RenderTransform="{TemplateBinding ContentRenderTransform}"
                            CornerRadius="0 0 3 3" Padding="5 3">
                        <TextBlock Text="{TemplateBinding Text}" TextWrapping="Wrap"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type controls:ChatBubble}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ChatBubble}">
                    <StackPanel Margin="0 5" Background="{TemplateBinding Background}">
                        <TextBox HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Username}"
                                 FontSize="{DynamicResource SmallFontSize}" Foreground="{TemplateBinding HeaderForeground}" Background="{TemplateBinding HeaderBackground}"
                                 IsReadOnly="True" BorderThickness="0" TextWrapping="Wrap"/>
                        <Border x:Name="chatBubble" HorizontalAlignment="Stretch" Background="{TemplateBinding ContentBackground}"
                            BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" Padding="5">
                            <StackPanel HorizontalAlignment="Stretch">
                                <controls:ConditionalControl Condition="{TemplateBinding IsReadonly}">
                                    <controls:ConditionalControl.ElementWhileTrue>
                                        <controls:MarkdownViewer Content="{Binding Content,RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                                    </controls:ConditionalControl.ElementWhileTrue>
                                    <controls:ConditionalControl.ElementWhileFalse>
                                        <TextBox HorizontalAlignment="Stretch"
                                                 Text="{Binding Content,RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                 BorderThickness="0" Background="Transparent" TextWrapping="Wrap" AcceptsReturn="True" Foreground="{TemplateBinding ContentForeground}"/>
                                    </controls:ConditionalControl.ElementWhileFalse>
                                </controls:ConditionalControl>
                            </StackPanel>
                        </Border>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type controls:ConditionalControl}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ConditionalControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <ContentPresenter x:Name="elementWhileTrue" Content="{TemplateBinding ElementWhileTrue}">
                                <ContentPresenter.Style>
                                    <Style TargetType="ContentPresenter">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Condition}" Value="True">
                                                <Setter Property="Visibility" Value="Visible"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Condition}" Value="False">
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ContentPresenter.Style>
                            </ContentPresenter>

                            <ContentPresenter x:Name="elementWhileFalse" Content="{TemplateBinding ElementWhileFalse}">
                                <ContentPresenter.Style>
                                    <Style TargetType="ContentPresenter">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Condition}" Value="True">
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Condition}" Value="False">
                                                <Setter Property="Visibility" Value="Visible"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ContentPresenter.Style>
                            </ContentPresenter>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type controls:MarkdownViewer}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:MarkdownViewer">
                    <ContentControl Content="{TemplateBinding RenderedContent}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type controls:LoadingCircle}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:LoadingCircle">
                    <Viewbox Stretch="Uniform">
                        <UniformGrid Width="75" Height="50" Columns="5">
                            <UniformGrid.Resources>
                                <Style x:Key="rec" TargetType="Rectangle">
                                    <Setter Property="Width" Value="10"/>
                                    <Setter Property="Height" Value="30"/>
                                    <Setter Property="Margin" Value="2.5 0"/>
                                </Style>
                                <PowerEase x:Key="powerEase" Power="3" EasingMode="EaseInOut"/>
                                <Storyboard x:Key="animation" RepeatBehavior="Forever" Storyboard.TargetProperty="Height">
                                    <DoubleAnimation Storyboard.TargetName="rec1" To="50" BeginTime="0:0:0.0" Duration="0:0:0.3" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
                                    <DoubleAnimation Storyboard.TargetName="rec2" To="50" BeginTime="0:0:0.12" Duration="0:0:0.3" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
                                    <DoubleAnimation Storyboard.TargetName="rec3" To="50" BeginTime="0:0:0.24" Duration="0:0:0.3" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
                                    <DoubleAnimation Storyboard.TargetName="rec4" To="50" BeginTime="0:0:0.36" Duration="0:0:0.3" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
                                    <DoubleAnimation Storyboard.TargetName="rec5" To="50" BeginTime="0:0:0.48" Duration="0:0:0.3" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
                                </Storyboard>
                            </UniformGrid.Resources>
                            <UniformGrid.Triggers>
                                <EventTrigger RoutedEvent="Loaded">
                                    <BeginStoryboard Name="animation" Storyboard="{StaticResource animation}"/>
                                </EventTrigger>
                                <EventTrigger RoutedEvent="Unloaded">
                                    <StopStoryboard BeginStoryboardName="animation"/>
                                </EventTrigger>
                            </UniformGrid.Triggers>

                            <Rectangle Name="rec1" Grid.Column="0" Style="{StaticResource rec}" Fill="{TemplateBinding Foreground}"/>
                            <Rectangle Name="rec2" Grid.Column="1" Style="{StaticResource rec}" Fill="{TemplateBinding Foreground}"/>
                            <Rectangle Name="rec3" Grid.Column="2" Style="{StaticResource rec}" Fill="{TemplateBinding Foreground}"/>
                            <Rectangle Name="rec4" Grid.Column="3" Style="{StaticResource rec}" Fill="{TemplateBinding Foreground}"/>
                            <Rectangle Name="rec5" Grid.Column="4" Style="{StaticResource rec}" Fill="{TemplateBinding Foreground}"/>
                        </UniformGrid>
                    </Viewbox>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
