<?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="LSFE.MobApp.Pages.CoveragePlan.ActualCoveragePage"
             xmlns:Local="clr-namespace:LSFE.MobApp.Converters"
             xmlns:vm="clr-namespace:LSFE.MobApp.ViewModels.Coverage"
             x:DataType="vm:ActualCoverageVM"
             Title="Actual Coverage">
    <ContentPage.Resources>
        <ResourceDictionary>
            <!-- Status Color Converter -->
            <Style x:Key="StatusBadgeStyle" TargetType="Border">
                <Setter Property="Padding" Value="12,6" />
                <Setter Property="StrokeShape" Value="RoundRectangle 12" />
                <Setter Property="StrokeThickness" Value="0" />
            </Style>

            <Style x:Key="CardStyle" TargetType="Border">
                <Setter Property="BackgroundColor" Value="White" />
                <Setter Property="Stroke" Value="#E5E7EB" />
                <Setter Property="StrokeThickness" Value="1" />
                <Setter Property="StrokeShape" Value="RoundRectangle 12" />
                <Setter Property="Padding" Value="20" />
                <Setter Property="Margin" Value="0,0,0,16" />
            </Style>

            <Style x:Key="PrimaryButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="#0EA5E9" />
                <Setter Property="TextColor" Value="White" />
                <Setter Property="CornerRadius" Value="8" />
                <Setter Property="Padding" Value="16,12" />
                <Setter Property="FontAttributes" Value="Bold" />
            </Style>

            <Style x:Key="SecondaryButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="White" />
                <Setter Property="TextColor" Value="#4B5563" />
                <Setter Property="BorderColor" Value="#D1D5DB" />
                <Setter Property="BorderWidth" Value="1" />
                <Setter Property="CornerRadius" Value="8" />
                <Setter Property="Padding" Value="16,12" />
            </Style>

            <Style x:Key="CallButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="Orange" />
                <Setter Property="TextColor" Value="White" />
                <Setter Property="CornerRadius" Value="12" />
                <Setter Property="Padding" Value="0,16" />
                <Setter Property="FontSize" Value="16" />
                <Setter Property="FontAttributes" Value="Bold" />
            </Style>
            <Style x:Key="CommonButtonStyle" TargetType="Button">
                <Setter Property="CornerRadius" Value="12" />
                <Setter Property="Padding" Value="0,16" />
                <Setter Property="FontSize" Value="16" />
                <Setter Property="FontAttributes" Value="Bold" />
                <Setter Property="HeightRequest" Value="60" />
            </Style>

            <Style x:Key="DeleteButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="#EF4444" />
                <Setter Property="TextColor" Value="White" />
                <Setter Property="CornerRadius" Value="8" />
                <Setter Property="Padding" Value="16,12" />
            </Style>
            <Style x:Key="TransparentButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="Transparent" />
                <Setter Property="TextColor" Value="White" />
                <Setter Property="CornerRadius" Value="8" />
                <Setter Property="Padding" Value="5,5" />
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>
    <Grid>
        <!-- Fullscreen Loading Overlay -->
        <Grid 
        BackgroundColor="#80000000"
        IsVisible="{Binding IsLoading}"
        ZIndex="999"
        RowDefinitions="*"
        ColumnDefinitions="*"
        HorizontalOptions="Fill"
        VerticalOptions="Fill">

            <Border
            StrokeShape="RoundRectangle 16"
            BackgroundColor="White"
            Padding="32"
            WidthRequest="200"
            HeightRequest="150"
            HorizontalOptions="Center"
            VerticalOptions="Center">

                <VerticalStackLayout Spacing="16"
                             HorizontalOptions="Center"
                             VerticalOptions="Center">

                    <ActivityIndicator 
                IsRunning="True"
                Color="#0EA5E9"
                WidthRequest="40"
                HeightRequest="40" />

                    <Label 
                Text="Processing..."
                TextColor="#0EA5E9"
                FontAttributes="Bold"
                FontSize="16"
                HorizontalOptions="Center" />

                </VerticalStackLayout>
            </Border>
        </Grid>
        <ScrollView>
            <VerticalStackLayout Padding="20" Spacing="20">
                <!-- Header Card with Avatar -->
            <Border BackgroundColor="White" 
                    Stroke="#E5E7EB" 
                    StrokeThickness="1"
                    StrokeShape="RoundRectangle 16"
                    Padding="24">
                <Grid RowDefinitions="Auto,Auto" ColumnDefinitions="Auto,*,Auto,*">
                    <!-- Large Avatar -->
                    <Border Grid.Row="0" 
                            Grid.RowSpan="2"
                            Grid.Column="0"
                            BackgroundColor="#E0F2FE" 
                            WidthRequest="80" 
                            HeightRequest="80"
                            StrokeShape="RoundRectangle 40"
                            StrokeThickness="0"
                            VerticalOptions="Center"
                            Margin="0,0,20,0">
                        <Label Text="👨‍⚕️" 
                               FontSize="48" 
                               HorizontalOptions="Center" 
                               VerticalOptions="Center"/>
                    </Border>

                    <!-- Name and Specialization -->
                    <VerticalStackLayout Grid.Row="0" 
                                         Grid.Column="1" 
                                         Spacing="6"
                                         VerticalOptions="Center">
                        <Label Text="{Binding FullName}" 
                               FontSize="24" 
                               FontAttributes="Bold" 
                               TextColor="#111827"/>
                        <Label Text="{Binding Specialization}" 
                               FontSize="16" 
                               TextColor="#6B7280"/>
                    </VerticalStackLayout>

                    <!-- Status Badge -->
                        <Border Grid.Row="0" 
                            Grid.Column="2" 
                            BackgroundColor="{Binding StatusBackgroundColor}"
                            Padding="16,8"
                            StrokeShape="RoundRectangle 12"
                            StrokeThickness="0"
                            VerticalOptions="Start">
                            <Label Text="{Binding StatusText}" 
                               TextColor="{Binding StatusTextColor}" 
                               FontSize="13" 
                               FontAttributes="Bold"/>
                        </Border>
                    </Grid>
            </Border>

            <!-- Professional Details -->
            <Border BackgroundColor="White" 
                    Stroke="#E5E7EB" 
                    StrokeThickness="1"
                    StrokeShape="RoundRectangle 12"
                    Padding="20">
                <VerticalStackLayout Spacing="20">
                    <Label Text="Professional Details" 
                           FontSize="18" 
                           FontAttributes="Bold" 
                           TextColor="#111827"/>

                    <!-- License Number -->
                    <Grid ColumnDefinitions="Auto,*" ColumnSpacing="12">
                        <Border Grid.Column="0"
                                BackgroundColor="#DBEAFE"
                                WidthRequest="44"
                                HeightRequest="44"
                                StrokeShape="RoundRectangle 22"
                                StrokeThickness="0">
                            <Label Text="🆔" 
                                   FontSize="22" 
                                   HorizontalOptions="Center" 
                                   VerticalOptions="Center"/>
                        </Border>
                        <VerticalStackLayout Grid.Column="1" Spacing="4" VerticalOptions="Center">
                            <Label Text="License Number" 
                                   FontSize="12" 
                                   TextColor="#6B7280"/>
                            <Label Text="{Binding LicenseNo}" 
                                   FontSize="15" 
                                   TextColor="#111827"
                                   FontAttributes="Bold"/>
                        </VerticalStackLayout>
                    </Grid>

                    <!-- Institution -->
                    <Grid ColumnDefinitions="Auto,*" ColumnSpacing="12" IsVisible="{Binding HasInstitution}">
                        <Border Grid.Column="0"
                                BackgroundColor="#FCE7F3"
                                WidthRequest="44"
                                HeightRequest="44"
                                StrokeShape="RoundRectangle 22"
                                StrokeThickness="0">
                            <Label Text="🏥" 
                                   FontSize="22" 
                                   HorizontalOptions="Center" 
                                   VerticalOptions="Center"/>
                        </Border>
                        <VerticalStackLayout Grid.Column="1" Spacing="4" VerticalOptions="Center">
                            <Label Text="Institution" 
                                   FontSize="12" 
                                   TextColor="#6B7280"/>
                            <Label Text="{Binding InstitutionName}" 
                                   FontSize="15" 
                                   TextColor="#111827"
                                   FontAttributes="Bold"/>
                        </VerticalStackLayout>
                    </Grid>

                    <!-- Max Visits -->
                    <Grid ColumnDefinitions="Auto,*" ColumnSpacing="12">
                        <Border Grid.Column="0"
                                BackgroundColor="#E0E7FF"
                                WidthRequest="44"
                                HeightRequest="44"
                                StrokeShape="RoundRectangle 22"
                                StrokeThickness="0">
                            <Label Text="📅" 
                                   FontSize="22" 
                                   HorizontalOptions="Center" 
                                   VerticalOptions="Center"/>
                        </Border>
                        <VerticalStackLayout Grid.Column="1" Spacing="4" VerticalOptions="Center">
                            <Label Text="Maximum Visits Per Month" 
                                   FontSize="12" 
                                   TextColor="#6B7280"/>
                            <Label Text="{Binding MaxVisit}" 
                                   FontSize="15" 
                                   TextColor="#111827"
                                   FontAttributes="Bold"/>
                        </VerticalStackLayout>
                    </Grid>

                    <!-- Birth Date -->
                    <Grid ColumnDefinitions="Auto,*" ColumnSpacing="12">
                        <Border Grid.Column="0"
                                BackgroundColor="#FEE2E2"
                                WidthRequest="44"
                                HeightRequest="44"
                                StrokeShape="RoundRectangle 22"
                                StrokeThickness="0">
                            <Label Text="🎂" 
                                   FontSize="22" 
                                   HorizontalOptions="Center" 
                                   VerticalOptions="Center"/>
                        </Border>
                        <VerticalStackLayout Grid.Column="1" Spacing="4" VerticalOptions="Center">
                            <Label Text="Birth Date" 
                                   FontSize="12" 
                                   TextColor="#6B7280"/>
                            <Label Text="{Binding BirthDateFormatted}" 
                                   FontSize="15" 
                                   TextColor="#111827"
                                   FontAttributes="Bold"/>
                        </VerticalStackLayout>
                    </Grid>

                </VerticalStackLayout>
            </Border>
            <!-- Action Button -->
            <Grid Grid.Row="2" 
               Grid.Column="0" 
               Grid.ColumnSpan="2" 
               ColumnDefinitions="*,*" 
               ColumnSpacing="10"
               Margin="0,10,0,0">

                <Button Text="❌ Close" 
             Style="{StaticResource CommonButtonStyle}"
             BackgroundColor="#0EA5E9"
             TextColor="White"
             Command="{Binding CloseCommand}" />

               <Button
                Grid.Column="1"
                Text="▶️ Start Coverage"
                BackgroundColor="Green"
                TextColor="White"
                Style="{StaticResource CommonButtonStyle}"
                Command="{Binding StartCoverageCommand}"
                IsEnabled="True" />

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