<UserControl x:Class="TeamViewerApi.Views.SessionsView" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:viewModels="clr-namespace:TeamViewerApi.ViewModels" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.DataContext>
        <viewModels:SessionsViewModel />
    </UserControl.DataContext>
    
    <Grid>
        <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" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0" Text="Session" />
        <DockPanel Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" LastChildFill="False">
            <ComboBox DockPanel.Dock="Left" 
                      HorizontalAlignment="Left" 
                      Width="300px" 
                      ItemsSource="{Binding Sessions.Items, Mode=OneWay}" 
                      SelectedItem="{Binding SelectedSession, Mode=TwoWay}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Style="{x:Null}">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} from {1:dd.MM.yyyy hh:mm}">
                                    <Binding Path="Code" Mode="OneWay" />
                                    <Binding Path="DateCreated" Mode="OneWay" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <CheckBox DockPanel.Dock="Left" VerticalAlignment="Center" IsChecked="{Binding FullListOption, Mode=TwoWay}" Content="Get full" />
        </DockPanel>
        <DockPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="5" 
                   Background="AliceBlue" />
        <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Center" FontWeight="Bold" Text="Current session" />

        <TextBlock Grid.Row="3" Grid.Column="0" Text="State" />
        <ComboBox Grid.Row="3" Grid.Column="1" 
                  Width="150px" 
                  HorizontalAlignment="Left" 
                  ItemsSource="{Binding States, Mode=OneWay}" 
                  SelectedItem="{Binding SelectedSession.State, Mode=TwoWay}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Style="{x:Null}" Text="{Binding ., Mode=OneWay}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <TextBlock Grid.Row="3" Grid.Column="2" Text="Date closed" />
        <TextBlock Grid.Row="3" Grid.Column="3" HorizontalAlignment="Left" Text="{Binding SelectedSession.DateClosed, StringFormat='dd.MM.yyyy hh:mm', Mode=OneWay}" />
        <TextBlock Grid.Row="4" Grid.Column="0" Text="Group" />
        <ComboBox Grid.Row="4" Grid.Column="1" 
                  Width="150px" 
                  HorizontalAlignment="Left" 
                  SelectedValuePath="GroupId" 
                  ItemsSource="{Binding Groups.Items, Mode=OneWay}" 
                  SelectedValue="{Binding SelectedSession.GroupId, Mode=TwoWay}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Style="{x:Null}" Text="{Binding Name, Mode=OneWay}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <TextBlock Grid.Row="5" Grid.Column="0" Text="Customer" />
        <TextBox Grid.Row="5" Grid.Column="1" 
                 Width="150px" 
                 Text="{Binding SelectedSession.Customer.Name, Mode=TwoWay}" />
        <TextBlock Grid.Row="5" Grid.Column="2" Text="Email" />
        <TextBox Grid.Row="5" Grid.Column="3" 
                 Width="200px" 
                 Text="{Binding SelectedSession.Customer.Email, Mode=TwoWay}" />
        <TextBlock Grid.Row="6" Grid.Column="0" Text="Description" />
        <TextBox Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="3" 
                 HorizontalAlignment="Left" 
                   Width="350px" 
                 Text="{Binding SelectedSession.CustomerDescription, Mode=TwoWay}" />
        <TextBlock Grid.Row="7" Grid.Column="0" Text="Message" />
        <TextBox Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="3" 
                   HorizontalAlignment="Left" 
                   Width="350px" 
                   Text="{Binding SelectedSession.WaitingMessage, Mode=TwoWay}" />
        <TextBlock Grid.Row="8" Grid.Column="0" Text="Assigned" />
        <TextBlock Grid.Row="8" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding SelectedSession.DateAssigned, StringFormat='dd.MM.yyyy hh:mm', Mode=OneWay}" />
        <TextBlock Grid.Row="9" Grid.Column="0" Text="Customer link" />
        <TextBlock Grid.Row="9" Grid.Column="1" HorizontalAlignment="Left">
            <Hyperlink Command="{Binding OpenCustomerLinkCommand, Mode=OneWay}">
                <TextBlock Style="{x:Null}" Text="{Binding SelectedSession.CustomerLink, Mode=OneWay}" />
            </Hyperlink>
        </TextBlock>
        <TextBlock Grid.Row="10" Grid.Column="0" Text="Support link" />
        <TextBlock Grid.Row="10" Grid.Column="1" HorizontalAlignment="Left">
            <Hyperlink Command="{Binding OpenSupportLinkCommand, Mode=OneWay}">
                <TextBlock Style="{x:Null}" Text="{Binding SelectedSession.SupporterLink, Mode=OneWay}" />
            </Hyperlink>
        </TextBlock>

        <DockPanel Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="4" LastChildFill="False">
            <Button DockPanel.Dock="Left" 
                    Content="Get sessions" 
                    Command="{Binding GetSessionsCommand, Mode=OneWay}" />
            <Button DockPanel.Dock="Right" 
                    Content="Save changes" 
                    Command="{Binding SaveSessionCommand, Mode=OneWay}" />
        </DockPanel>
        <DockPanel Grid.Row="12" Grid.Column="0" Grid.ColumnSpan="2" LastChildFill="False">
            <Button DockPanel.Dock="Left" 
                    Content="Create session" 
                    Command="{Binding CreateSessionCommand, Mode=OneWay}" />
        </DockPanel>
    </Grid>
</UserControl>
