<?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.AddEditDoctorPage"
              xmlns:vm="clr-namespace:LSFE.MobApp.ViewModels.Coverage"
             x:DataType="vm:AddEditDoctorVM"
             Title="AddEditDoctorPage">
    
    <ContentPage.Resources>
        <Style x:Key="FormLabelStyle" TargetType="Label">
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="TextColor" Value="#374151"/>
            <Setter Property="FontAttributes" Value="Bold"/>
            <Setter Property="Margin" Value="0,0,0,6"/>
        </Style>

        <Style x:Key="FormEntryStyle" TargetType="Entry">
            <Setter Property="BackgroundColor" Value="White"/>
            <Setter Property="TextColor" Value="#111827"/>
            <Setter Property="PlaceholderColor" Value="#9CA3AF"/>
        </Style>

        <Style x:Key="FormBorderStyle" TargetType="Border">
            <Setter Property="Stroke" Value="#D1D5DB"/>
            <Setter Property="StrokeThickness" Value="1"/>
            <Setter Property="StrokeShape" Value="RoundRectangle 8"/>
            <Setter Property="BackgroundColor" Value="White"/>
            <Setter Property="Padding" Value="12,8"/>
        </Style>
    </ContentPage.Resources>

    <ScrollView>
        <VerticalStackLayout Padding="20" Spacing="20" BackgroundColor="#F9FAFB">

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

                    <!-- First Name -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="First Name *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding FirstName}" 
                                   Placeholder="Enter first name"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Middle Initial -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Middle Initial" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding MiddleInitial}" 
                                   Placeholder="M.I."
                                   MaxLength="5"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Last Name -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Last Name *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding LastName}" 
                                   Placeholder="Enter last name"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Birth Date -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Birth Date *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <DatePicker Date="{Binding BirthDate}" 
                                        TextColor="#111827"
                                        BackgroundColor="Transparent"/>
                        </Border>
                    </VerticalStackLayout>
                </VerticalStackLayout>
            </Border>

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

                    <!-- Specialization -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Specialization" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding Specialization}" 
                                   Placeholder="e.g., Cardiology"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- License Number -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="License Number *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding LicenseNo}" 
                                   Placeholder="Enter license number"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Institution -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Institution" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Picker ItemsSource="{Binding Institutions}"
                                    ItemDisplayBinding="{Binding InstitutionName}"
                                    SelectedItem="{Binding SelectedInstitution}"
                                    Title="Select Institution"
                                    TextColor="#111827"
                                    BackgroundColor="Transparent"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Max Visits -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Max Visits per Day" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding MaxVisit}" 
                                   Placeholder="e.g., 10"
                                   Keyboard="Numeric"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Status -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Status *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Picker ItemsSource="{Binding StatusOptions}"
                                    SelectedIndex="{Binding SelectedStatusIndex}"
                                    Title="Select Status"
                                    TextColor="#111827"
                                    BackgroundColor="Transparent"/>
                        </Border>
                    </VerticalStackLayout>
                </VerticalStackLayout>
            </Border>

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

                    <!-- Email -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Email Address *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding EmailAddress}" 
                                   Placeholder="doctor@example.com"
                                   Keyboard="Email"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Phone -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Phone Number *" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding PhoneNo}" 
                                   Placeholder="09XXXXXXXXX"
                                   Keyboard="Telephone"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>

                    <!-- Address -->
                    <VerticalStackLayout Spacing="6">
                        <Label Text="Address" Style="{StaticResource FormLabelStyle}"/>
                        <Border Style="{StaticResource FormBorderStyle}">
                            <Entry Text="{Binding Address}" 
                                   Placeholder="Enter full address"
                                   Style="{StaticResource FormEntryStyle}"/>
                        </Border>
                    </VerticalStackLayout>
                </VerticalStackLayout>
            </Border>

            <!-- Action Buttons -->
            <Grid ColumnDefinitions="*,*" ColumnSpacing="12" Margin="0,10,0,20">
                <Button Grid.Column="0"
                        Text="Cancel"
                        BackgroundColor="White"
                        TextColor="#6B7280"
                        BorderColor="#D1D5DB"
                        BorderWidth="1"
                        CornerRadius="8"
                        Padding="0,16"
                        FontSize="16"
                        FontAttributes="Bold"
                        Command="{Binding CancelCommand}"/>

                <Button Grid.Column="1"
                        Text="{Binding SaveButtonText}"
                        BackgroundColor="#0EA5E9"
                        TextColor="White"
                        CornerRadius="8"
                        Padding="0,16"
                        FontSize="16"
                        FontAttributes="Bold"
                        Command="{Binding SaveCommand}"/>
            </Grid>

            <!-- Loading Indicator -->
            <ActivityIndicator IsRunning="{Binding IsLoading}" 
                              IsVisible="{Binding IsLoading}"
                              Color="#0EA5E9"
                              VerticalOptions="Center"
                              HorizontalOptions="Center"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>