<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:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
             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>
    <Grid ColumnDefinitions="*,4,*">
        <Grid Grid.Column="0" Margin="20" RowDefinitions="Auto,*">
            <StackPanel Grid.Row="0" Margin="0 0 0 5">
                <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>
                    <DataGridTemplateColumn Width="30" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <materialIcons:MaterialIcon Foreground="{Binding IsGoodColor}" Kind="{Binding IsGoodIcon}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Width="75" Header="Id"  Binding="{Binding Id}"/>
                    <DataGridTextColumn Width="*" Header="Name" Binding="{Binding Name}" />
                    <DataGridTextColumn Width="60" Header="Status" Binding="{Binding Status}" CellStyleClasses="status" />
                    <DataGridTextColumn Width="45" Header="Type" Binding="{Binding Type}" />
                    <DataGridTextColumn Width="*" IsReadOnly="False" Header="IpV4" Binding="{Binding Ipv4}" />
                    <DataGridTextColumn Width="*" Header="IpV6" Binding="{Binding Ipv6}" />
                    <DataGridTextColumn Header="Datum"
                                        Binding="{Binding Datum}"
                                        Width="80" />
                    <DataGridTextColumn Header="Re"
                                        Binding="{Binding Release}"
                                        Width="35" />

                    <DataGridTextColumn Header="Last Backup"
                                        Binding="{Binding BackupLastModified}"
                                        Width="*"
                                        CellStyleClasses="lastBackup"/>
                    <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>
        <GridSplitter Grid.Column="1" Background="Black" ResizeDirection="Columns"/>
        <StackPanel Grid.Column="2" Margin="5 0">
            <TextBlock Text="{Binding SelectedServer.Name}" FontSize="24"/>
            <ListBox ItemsSource="{Binding SelectedServer.Domains}" Margin="0" Padding="0">
                <ListBox.Styles> 
                    <Style Selector="ListBoxItem">
                        <Setter Property="Padding" Value="0" />
                    </Style> 
                </ListBox.Styles>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border Padding="1" Margin="0">
                            <!--<TextBox Text="{Binding Name}" DoubleTapped="InputElement_OnDoubleTapped"></TextBox>-->
                            <HyperlinkButton Content="{Binding LinkDomain}" NavigateUri="{Binding LinkDomain}"></HyperlinkButton>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
    </Grid>
</UserControl>
