<?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:vm="clr-namespace:BookReader.ViewModels"
             x:Class="BookReader.Views.SettingsPage"
             x:DataType="vm:SettingsViewModel"
             Title="{Binding Title}"
             BackgroundColor="#1E1E1E">

    <ScrollView>
        <VerticalStackLayout Spacing="20" Padding="20">

            <!-- Calibre-Web Settings -->
            <Frame BackgroundColor="#2C2C2C"
                   CornerRadius="12"
                   Padding="15"
                   HasShadow="True"
                   BorderColor="Transparent">
                <VerticalStackLayout Spacing="12">
                    <Label Text="☁️ Calibre-Web Connection"
                           FontSize="18"
                           FontAttributes="Bold"
                           TextColor="White" />

                    <VerticalStackLayout Spacing="5">
                        <Label Text="Server URL"
                               FontSize="12"
                               TextColor="#B0B0B0" />
                        <Entry Text="{Binding CalibreUrl}"
                               Placeholder="https://your-calibre-server.com"
                               PlaceholderColor="#666"
                               TextColor="White"
                               BackgroundColor="#3C3C3C"
                               Keyboard="Url" />
                    </VerticalStackLayout>

                    <VerticalStackLayout Spacing="5">
                        <Label Text="Username"
                               FontSize="12"
                               TextColor="#B0B0B0" />
                        <Entry Text="{Binding CalibreUsername}"
                               Placeholder="Username"
                               PlaceholderColor="#666"
                               TextColor="White"
                               BackgroundColor="#3C3C3C" />
                    </VerticalStackLayout>

                    <VerticalStackLayout Spacing="5">
                        <Label Text="Password"
                               FontSize="12"
                               TextColor="#B0B0B0" />
                        <Entry Text="{Binding CalibrePassword}"
                               Placeholder="Password"
                               PlaceholderColor="#666"
                               TextColor="White"
                               BackgroundColor="#3C3C3C"
                               IsPassword="True" />
                    </VerticalStackLayout>

                    <Button Text="Test Connection"
                            BackgroundColor="#5D4037"
                            TextColor="White"
                            CornerRadius="8"
                            Command="{Binding TestConnectionCommand}"
                            IsEnabled="{Binding IsConnectionTesting, Converter={StaticResource InvertedBoolConverter}}" />

                    <Label Text="{Binding ConnectionStatus}"
                           FontSize="13"
                           TextColor="#81C784"
                           IsVisible="{Binding ConnectionStatus, Converter={StaticResource IsNotNullOrEmptyConverter}}" />
                </VerticalStackLayout>
            </Frame>

            <!-- Reading Settings -->
            <Frame BackgroundColor="#2C2C2C"
                   CornerRadius="12"
                   Padding="15"
                   HasShadow="True"
                   BorderColor="Transparent">
                <VerticalStackLayout Spacing="12">
                    <Label Text="📖 Reading Defaults"
                           FontSize="18"
                           FontAttributes="Bold"
                           TextColor="White" />

                    <VerticalStackLayout Spacing="5">
                        <Label Text="Default Font Size"
                               FontSize="12"
                               TextColor="#B0B0B0" />
                        <Picker ItemsSource="{Binding AvailableFontSizes}"
                                SelectedItem="{Binding DefaultFontSize}"
                                TextColor="White"
                                BackgroundColor="#3C3C3C" />
                    </VerticalStackLayout>

                    <VerticalStackLayout Spacing="5">
                        <Label Text="Default Font Family"
                               FontSize="12"
                               TextColor="#B0B0B0" />
                        <Picker ItemsSource="{Binding AvailableFonts}"
                                SelectedItem="{Binding DefaultFontFamily}"
                                TextColor="White"
                                BackgroundColor="#3C3C3C" />
                    </VerticalStackLayout>
                </VerticalStackLayout>
            </Frame>

            <!-- Save Button -->
            <Button Text="💾 Save Settings"
                    BackgroundColor="#4CAF50"
                    TextColor="White"
                    FontSize="16"
                    FontAttributes="Bold"
                    CornerRadius="12"
                    HeightRequest="50"
                    Command="{Binding SaveSettingsCommand}" />

        </VerticalStackLayout>
    </ScrollView>
</ContentPage>