<?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"
             x:Class="unitechRFIDSampleMAUI.BluetoothConnectionPage"
             Title="Bluetooth Connection">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,20"
            VerticalOptions="Center">

            <!-- Device Type Display -->
            <Frame
                BackgroundColor="#F5F5F5"
                BorderColor="#E0E0E0"
                CornerRadius="10"
                Padding="15"
                Margin="0,0,0,20">
                <HorizontalStackLayout
                    Spacing="10"
                    HorizontalOptions="Center">
                    <Label
                        Text="Device Type:"
                        FontSize="16"
                        FontAttributes="Bold"
                        VerticalOptions="Center"/>
                    <Label
                        x:Name="DeviceTypeLabel"
                        Text="Unknown"
                        FontSize="16"
                        TextColor="#2196F3"
                        VerticalOptions="Center"/>
                </HorizontalStackLayout>
            </Frame>

            <!-- MAC Address Input Section -->
            <Frame
                BackgroundColor="White"
                BorderColor="#E0E0E0"
                CornerRadius="10"
                Padding="20"
                Margin="0,0,0,20">
                <VerticalStackLayout Spacing="15">
                    <Label
                        Text="Bluetooth MAC Address"
                        FontSize="16"
                        FontAttributes="Bold"
                        HorizontalOptions="Start"/>

                    <Label
                        Text="Enter the MAC address of your Bluetooth device (e.g., 00:11:22:33:44:55)"
                        FontSize="12"
                        TextColor="Gray"
                        HorizontalOptions="Start"/>

                    <Entry
                        x:Name="MacAddressEntry"
                        Placeholder="00:11:22:33:44:55"
                        FontSize="16"
                        BackgroundColor="#F9F9F9"
                        PlaceholderColor="Gray"
                        TextColor="Black"
                        MaxLength="17"
                        Keyboard="Default"
                        TextChanged="OnMacAddressTextChanged"/>

                    <!-- Validation Message -->
                    <Label
                        x:Name="ValidationLabel"
                        Text=""
                        FontSize="12"
                        TextColor="Red"
                        IsVisible="False"
                        HorizontalOptions="Start"/>
                </VerticalStackLayout>
            </Frame>

            <!-- Recently Used Addresses (if any) -->
            <Frame
                x:Name="RecentAddressesFrame"
                BackgroundColor="White"
                BorderColor="#E0E0E0"
                CornerRadius="10"
                Padding="20"
                Margin="0,0,0,20"
                IsVisible="False">
                <VerticalStackLayout Spacing="10">
                    <Label
                        Text="Recently Used Addresses"
                        FontSize="14"
                        FontAttributes="Bold"
                        HorizontalOptions="Start"/>

                    <StackLayout x:Name="RecentAddressesList"
                                 Spacing="5"/>
                </VerticalStackLayout>
            </Frame>

            <!-- Connection Status -->
            <Frame
                x:Name="StatusFrame"
                BackgroundColor="#FFF3E0"
                BorderColor="#FFB74D"
                CornerRadius="10"
                Padding="15"
                Margin="0,0,0,20"
                IsVisible="False">
                <HorizontalStackLayout
                    Spacing="10"
                    HorizontalOptions="Center">
                    <ActivityIndicator
                        x:Name="ConnectionIndicator"
                        IsRunning="False"
                        Color="#FF9800"
                        VerticalOptions="Center"/>
                    <Label
                        x:Name="StatusLabel"
                        Text="Ready to connect"
                        FontSize="14"
                        VerticalOptions="Center"/>
                </HorizontalStackLayout>
            </Frame>

            <!-- Action Buttons -->
            <Grid ColumnDefinitions="*,15,*"
                  Margin="0,0,0,0">
                <Button
                    Grid.Column="0"
                    x:Name="CancelBtn"
                    Text="Cancel"
                    SemanticProperties.Hint="Cancel and go back"
                    Clicked="OnCancelClicked"
                    BackgroundColor="#757575"
                    TextColor="White"
                    FontSize="14"
                    CornerRadius="8"
                    HeightRequest="50"/>

                <Button
                    Grid.Column="2"
                    x:Name="ConnectBtn"
                    Text="Connect"
                    SemanticProperties.Hint="Connect to the Bluetooth device"
                    Clicked="OnConnectClicked"
                    BackgroundColor="#4CAF50"
                    TextColor="White"
                    FontSize="16"
                    FontAttributes="Bold"
                    CornerRadius="8"
                    HeightRequest="50"
                    IsEnabled="False"/>
            </Grid>

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
