<Window x:Class="Immense.RemoteControl.Desktop.UI.WPF.Views.ChatWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        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:local="clr-namespace:Immense.RemoteControl.Desktop.UI.WPF.Views"
        xmlns:fakes="clr-namespace:Immense.RemoteControl.Desktop.UI.WPF.ViewModels.Fakes"
        xmlns:Models="clr-namespace:Immense.RemoteControl.Shared.Models;assembly=Immense.RemoteControl.Shared"
        mc:Ignorable="d"
        WindowStyle="None"
        ResizeMode="CanResizeWithGrip"
        MouseLeftButtonDown="Window_MouseLeftButtonDown"
        WindowStartupLocation="CenterScreen"
        AllowsTransparency="True"
        BorderBrush="DimGray"
        BorderThickness="1"
        MinHeight="250"
        MinWidth="200"
        Topmost="True"
        Title="Chat Session" Height="450" Width="450" 
        Icon="{Binding Icon}"
        Loaded="Window_Loaded"
        ContentRendered="Window_ContentRendered"
        d:DataContext="{d:DesignInstance Type=fakes:FakeChatWindowViewModel, IsDesignTimeCreatable=True}">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Immense.RemoteControl.Desktop.UI.WPF;component/Resources/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Border Height="50" Background="{Binding TitleBackgroundColor}">
            <Grid Margin="10,0,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Height="50" Width="50"  Margin="0,0,10,0" Source="{Binding Icon}"></Image>
                <TextBlock Grid.Column="1" Foreground="{Binding TitleForegroundColor}" FontWeight="Bold" FontSize="20" VerticalAlignment="Center">
                        <Run Text="{Binding ProductName}"></Run>
                        <Run Text="Chat"></Run>
                </TextBlock>
                <Button Grid.Column="2" Style="{StaticResource TitlebarButton}" Click="MinimizeButton_Click" Content="____" Foreground="{Binding TitleButtonForegroundColor}" Background="{Binding TitleBackgroundColor}"/>
                <Button Grid.Column="3" Style="{StaticResource TitlebarButton}" Click="CloseButton_Click" Content="X" Foreground="{Binding TitleButtonForegroundColor}" Background="{Binding TitleBackgroundColor}" />
            </Grid>
        </Border>

        <TextBlock Grid.Row="1" FontWeight="Bold" Foreground="DimGray" Margin="10,10,10,0" TextWrapping="Wrap">
                <Run>Chat session with</Run>
                <Run Text="{Binding OrganizationName}"></Run>
        </TextBlock>
        
        <Grid Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="5" />
                <RowDefinition Height="50" />
            </Grid.RowDefinitions>

            <Border BorderBrush="Gray" BorderThickness="1" Margin="5">
                <ScrollViewer x:Name="MessagesScrollViewer">
                    <ItemsControl x:Name="MessagesItemsControl" ItemsSource="{Binding ChatMessages}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="{x:Type Models:ChatMessage}">
                                <TextBlock TextWrapping="Wrap" Margin="5" FontSize="14">
                                    <Run Text="{Binding SenderName}" FontWeight="Bold">
                                        <Run.Style>
                                            <Style TargetType="Run">
                                                <Style.Triggers>
                                                    <Trigger Property="Text" Value="You">
                                                        <Setter Property="Foreground" Value="SteelBlue"></Setter>
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Run.Style>
                                    </Run>
                                    <Run>: </Run>
                                    <Run Text="{Binding Message}"></Run>
                                </TextBlock>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </Border>
            
            <GridSplitter Grid.Row="1" Height="5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

            <TextBox Grid.Row="2"
                FontSize="14"
                Margin="5"
                Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                TextWrapping="Wrap" 
                VerticalScrollBarVisibility="Auto" 
                PreviewKeyUp="ChatInputBox_PreviewKeyUp" />
        </Grid>
    </Grid>
</Window>
