<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="RelayClient.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    Title="Relay Client">

    <Grid RowDefinitions="Auto,*,Auto"
          ColumnDefinitions="220,*"
          Padding="12"
          RowSpacing="10"
          ColumnSpacing="10">

        <!-- Header -->
        <Border Grid.Row="0"
                Grid.ColumnSpan="2"
                StrokeThickness="1"
                Padding="10">
            <VerticalStackLayout Spacing="4">
                <Label x:Name="UserLabel"
                       Text="Logged in as: Unknown"
                       FontAttributes="Bold"
                       FontSize="18" />
                <Label x:Name="ChannelLabel"
                       Text="No channel selected"
                       FontSize="14" />
            </VerticalStackLayout>
        </Border>

        <!-- Sidebar -->
        <Border Grid.Row="1"
                Grid.Column="0"
                StrokeThickness="1"
                Padding="10">
            <ScrollView>
                <VerticalStackLayout Spacing="8">
                    <Label Text="Channels"
                           FontAttributes="Bold"
                           FontSize="16" />
                    <VerticalStackLayout x:Name="SidebarList"
                                         Spacing="6" />
                </VerticalStackLayout>
            </ScrollView>
        </Border>

        <!-- Messages -->
        <Border Grid.Row="1"
                Grid.Column="1"
                StrokeThickness="1"
                Padding="10">
            <ScrollView x:Name="MessagesScrollView">
                <VerticalStackLayout x:Name="MessagesLayout"
                                     Spacing="8" />
            </ScrollView>
        </Border>
        <Border x:Name="RtcView"
                Grid.Row="1"
                Grid.Column="1"
                StrokeThickness="1"
                Padding="10"
                IsVisible="False">
            <!-- <WebView Source="test.html"/> -->
            <Grid RowDefinitions="Auto,*"
                  ColumnDefinitions="*">
                <HybridWebView x:Name="hybridWebView"
                               RawMessageReceived="OnHybridWebViewRawMessageReceived"
                               Grid.Row="1" />
            </Grid>
        </Border>

        <!-- Input -->
        <Grid Grid.Row="2"
              Grid.Column="1"
              ColumnDefinitions="*,Auto"
              ColumnSpacing="10">
            <Entry x:Name="MessageEntry"
                   Grid.Column="0"
                   Placeholder="Type a message..."
                   ReturnType="Send"
                   Completed="MessageEntry_OnCompleted" />

            <Button Grid.Column="1"
                    Text="Send"
                    Clicked="SendButton_OnClicked" />
        </Grid>
        
        <!-- Swap View -->
        <Button x:Name="ViewSwapped" Grid.Row="2" Grid.Column="0"
                Text="Swap to WebView"
                Clicked="SwapView_OnClicked" />

    </Grid>
</ContentPage>