<UserControl 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:vm="clr-namespace:PSCHelpdesk.Plugins.HetznerServer.ViewModels"
             xmlns:converter="clr-namespace:PSCHelpdesk.Plugins.HetznerServer.Converter"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="PSCHelpdesk.Plugins.HetznerServer.Views.ServerView"
             x:DataType="vm:ServerViewModel"
             Name="Servers">
    <Design.DataContext>
        <vm:ServerViewModel></vm:ServerViewModel>
    </Design.DataContext>
    <UserControl.Resources>
        <converter:StatusConverter x:Key="StatusConverter"></converter:StatusConverter>
        <converter:DateTimeConverter x:Key="DateTimeConverter"></converter:DateTimeConverter>
    </UserControl.Resources>
    <SplitView IsPaneOpen="{Binding IsPagePaneOpen }"
               DisplayMode="Inline"
               PanePlacement="Right">
        <Grid Margin="20" RowDefinitions="Auto,*">
            <StackPanel Grid.Row="0">
                <TextBlock Margin="0 5" >Suchtext</TextBlock>
                <TextBox Text="{Binding SearchText}"></TextBox>
            </StackPanel>
            <DataGrid Grid.Row="1" ItemsSource="{Binding Server}"
                      AutoGenerateColumns="False" IsReadOnly="True" 
                      GridLinesVisibility="All"
                      BorderThickness="1" BorderBrush="Gray"
                      x:Name="ServerTable">
                <DataGrid.Styles>
                    <Style Selector="DataGridCell.status">
                        <Setter Property="Foreground" Value="{Binding Status, Converter={StaticResource StatusConverter}}" />
                    </Style>
                    <Style Selector="DataGridCell.lastBackup">
                        <Setter Property="Foreground" Value="{Binding BackupLastModified, Converter={StaticResource DateTimeConverter}}" />
                    </Style>
                </DataGrid.Styles>
                <Interaction.Behaviors>
                    <EventTriggerBehavior EventName="SelectionChanged">
                        <InvokeCommandAction Command="{Binding SelectionChanged}" PassEventArgsToCommand="true"></InvokeCommandAction>
                    </EventTriggerBehavior>
                </Interaction.Behaviors>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Id"  Binding="{Binding Id}"/>
                    <DataGridTextColumn Header="Name" Binding="{Binding Name}" />
                    <DataGridTextColumn Header="Status" Binding="{Binding Status}" CellStyleClasses="status" />
                    <DataGridTextColumn Header="Type" Binding="{Binding Type}" />
                    <DataGridTextColumn IsReadOnly="False" Header="IpV4" Binding="{Binding Ipv4}" />
                    <DataGridTextColumn Header="IpV6" Binding="{Binding Ipv6}" />
                    <DataGridTemplateColumn Width="*" Header="">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button
                                    HorizontalAlignment="Center"
                                    HorizontalContentAlignment="Center"
                                    Background="#232323"
                                    Command="{Binding ShowServerDetails}"
                                    CommandParameter="{Binding $self}"
                                    Content="View"
                                    Foreground="White" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Width="*" Header="">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button
                                    HorizontalAlignment="Center"
                                    HorizontalContentAlignment="Center"
                                    Background="#232323"
                                    Click="openSSH"
                                    Content="Open SSH"
                                    Foreground="White" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Width="*" Header="">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button
                                    HorizontalAlignment="Center"
                                    HorizontalContentAlignment="Center"
                                    Background="#232323"
                                    Click="openSCP"
                                    Content="Open SCP"
                                    Foreground="White" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
        <SplitView.Pane>
            <TextBlock Text="{Binding SelectedServer.Name}"
                       FontSize="24"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"/>
        </SplitView.Pane>
    </SplitView>
</UserControl>
