<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vms="clr-namespace:MauiTestApp.ViewModels"
             xmlns:graph="clr-namespace:MauiTestApp.Graphing"
             x:Class="MauiTestApp.Pages.KyberPage"
             Title="KyberPage">
    <ContentPage.BindingContext>
        <vms:KyberViewModel x:Name="Binder"/>
    </ContentPage.BindingContext>

    <ContentPage.Resources>
        <graph:Graph x:Key="KeypairGraph" x:Name="KeypairGraph"/>
        <graph:Graph x:Key="EncapsGraph" x:Name="EncapsGraph"/>
        <graph:Graph x:Key="DecapsGraph" x:Name="DecapsGraph"/>
    </ContentPage.Resources>

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            VerticalOptions="Center">
            <Picker Margin="10" Grid.Row="0" Title="Select a KEM algorithm..." ItemsSource="{Binding Algorithms}" SelectedItem="{Binding SelectedAlgorithm}"/>
            <Button Margin="10" Grid.Row="1" Text="Perform test" Command="{Binding TestCommand}"/>

            <!--Lengths-->
            <Label Text="Data lengths" VerticalOptions="Center" HorizontalOptions="Center" />
            <Grid ColumnSpacing="-3" RowSpacing="-4" Margin="10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border Grid.Row="0" Grid.Column="0">
                    <Label Text="Public" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="1">
                    <Label Text="Secret" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="2">
                    <Label Text="Cipher" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="3">
                    <Label Text="Shared" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="0">
                    <Label Text="{Binding PublicKeyLength}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="1">
                    <Label Text="{Binding SecretKeyLength}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="2">
                    <Label Text="{Binding CiphertextLength}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="3">
                    <Label Text="{Binding SharedSecretLength}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
            </Grid>

            <Label Text="{Binding SuccessMesssage}" VerticalOptions="Center" HorizontalOptions="Center" />

            <!--Keypair-->
            <Label Text="Key Pairs" VerticalOptions="Center" HorizontalOptions="Center" />
            <Grid ColumnSpacing="-3" RowSpacing="-4" Margin="10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border Grid.Row="0" Grid.Column="0">
                    <Label Text="Memory" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="1">
                    <Label Text="CPU" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="2">
                    <Label Text="Time" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="0">
                    <Label Text="{Binding KeypairData.Memory}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="1">
                    <Label Text="{Binding KeypairData.CPU}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="2">
                    <Label Text="{Binding KeypairData.Time}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
            </Grid>
            <GraphicsView Margin="10,30,10,0" x:Name="KeypairCanvas" HorizontalOptions="Center" Drawable="{StaticResource KeypairGraph}" HeightRequest="200"/>

            <!--Encaps-->
            <Label Text="Encapsulation" VerticalOptions="Center" HorizontalOptions="Center" />
            <Grid ColumnSpacing="-3" RowSpacing="-4" Margin="10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border Grid.Row="0" Grid.Column="0">
                    <Label Text="Memory" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="1">
                    <Label Text="CPU" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="2">
                    <Label Text="Time" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="0">
                    <Label Text="{Binding EncapsData.Memory}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="1">
                    <Label Text="{Binding EncapsData.CPU}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="2">
                    <Label Text="{Binding EncapsData.Time}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
            </Grid>
            <GraphicsView Margin="10,30,10,0" x:Name="EncapsCanvas" HorizontalOptions="Center" Drawable="{StaticResource EncapsGraph}" HeightRequest="200"/>

            <!--Decaps-->
            <Label Text="Decapsulation" VerticalOptions="Center" HorizontalOptions="Center" />
            <Grid ColumnSpacing="-3" RowSpacing="-4" Margin="10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border Grid.Row="0" Grid.Column="0">
                    <Label Text="Memory" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="1">
                    <Label Text="CPU" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="0" Grid.Column="2">
                    <Label Text="Time" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="0">
                    <Label Text="{Binding DecapsData.Memory}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="1">
                    <Label Text="{Binding DecapsData.CPU}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
                <Border Grid.Row="1" Grid.Column="2">
                    <Label Text="{Binding DecapsData.Time}" VerticalOptions="Center" HorizontalOptions="Center" />
                </Border>
            </Grid>
            <GraphicsView Margin="10,30,10,30" x:Name="DecapsCanvas" HorizontalOptions="Center" Drawable="{StaticResource DecapsGraph}" HeightRequest="200"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>