<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vm="clr-namespace:LSFE.MobApp.ViewModels.Coverage"
             x:Class="LSFE.MobApp.Views.CoveragePlan.ConfirmSelectionModal"
             BackgroundColor="#00000066"
             NavigationPage.HasNavigationBar="False">
    <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>
        <!-- Backdrop / Overlay -->
        <BoxView Opacity="0.6" InputTransparent="False" />
        <Grid Padding="20"
          VerticalOptions="Center"
          HorizontalOptions="Center">

        <Border BackgroundColor="White"
                    Padding="20"
                    Stroke="#E2E8F0"
                    StrokeShape="RoundRectangle 14"
                    WidthRequest="700">
                
                <Border.Shadow>
                    <Shadow Brush="#00000044"
                Offset="0,4"
                Radius="12"/>
                </Border.Shadow>
                
                <VerticalStackLayout Spacing="15">

                <Label Text="Confirm Selection"
                       FontSize="22"
                       FontAttributes="Bold"
                       HorizontalOptions="Center"
                       TextColor="#1E293B"/>

                <!-- Doctor Info -->
                <Border BackgroundColor="#F1F5F9"
                        Stroke="#E2E8F0"
                        StrokeShape="RoundRectangle 10"
                       Padding="12">
                    <VerticalStackLayout Spacing="6">
                        <Label Text="{Binding DoctorName}" 
                               FontAttributes="Bold"
                               TextColor="#0F172A"/>

                        <Label Text="{Binding Specialization}" 
                               TextColor="#64748B"/>
                    </VerticalStackLayout>
                </Border>

                <!-- Marketing Materials -->
                <Label Text="Marketing Materials"
                       FontSize="16"
                       FontAttributes="Bold"
                       TextColor="#1E293B"
                       IsVisible="{Binding HasMaterials}"/>

                <FlexLayout Direction="Row"
                    Wrap="Wrap"
                    FlexLayout.Grow="1"
                    WidthRequest="700"
                    AlignItems="Start"
                    AlignContent="Start"
                    JustifyContent="Start"
                    IsVisible="{Binding HasMaterials}"
                    BindableLayout.ItemsSource="{Binding Materials}"
                    Margin="0,0,0,0">

                    <BindableLayout.ItemTemplate>
                        <DataTemplate>
                            <Border BackgroundColor="#F8FAFC"
                           Stroke="#E2E8F0"
                           StrokeShape="RoundRectangle 14"
                           Padding="15"
                           Margin="10,0,0,5"
                           WidthRequest="320">
                                <!-- TWO COLUMNS -->
                                <Label Text="{Binding ProductName}"
                               TextColor="#334155"/>
                            </Border>
                        </DataTemplate>
                    </BindableLayout.ItemTemplate>
                </FlexLayout>

                <!-- Sampling Items -->
                <Label Text="Sampling Items"
                   FontSize="16"
                   FontAttributes="Bold"
                   TextColor="#1E293B"
                   IsVisible="{Binding HasSamplings}" />

                <FlexLayout Direction="Row"
                    Wrap="Wrap"
                    FlexLayout.Grow="1"
                    WidthRequest="700"
                    AlignItems="Start"
                    AlignContent="Start"
                    JustifyContent="Start"
                    IsVisible="{Binding HasSamplings}"
                    BindableLayout.ItemsSource="{Binding Samplings}"
                    Margin="0,0,0,0">


                    <BindableLayout.ItemTemplate>
                        <DataTemplate>
                            <Border BackgroundColor="#F8FAFC"
                           Stroke="#E2E8F0"
                            StrokeShape="RoundRectangle 10"
                            Padding="5"
                            Margin="10,0,0,5"
                           WidthRequest="320">
                                <!-- TWO COLUMNS -->
                                <VerticalStackLayout Spacing="4">
                                    <Label Text="{Binding Description}"
                                   FontAttributes="Bold"
                                   TextColor="#334155"/>
                                    <Label Text="{Binding Qty, StringFormat='Qty: {0}'}"
                                   TextColor="#64748B"/>
                                </VerticalStackLayout>
                            </Border>
                        </DataTemplate>
                    </BindableLayout.ItemTemplate>

                </FlexLayout>

                <!-- Buttons -->
                <Grid ColumnDefinitions="*,*" ColumnSpacing="10" Margin="0,10,0,0">
                    <Button Text="Cancel"
                    Grid.Column="0"
                    BackgroundColor="#E2E8F0"
                    TextColor="#475569"
                    CornerRadius="14"
                    HeightRequest="46"
                    Command="{Binding CancelCommand}" />

                    <Button Text="Proceed"
                    Grid.Column="1"
                    BackgroundColor="#0EA5E9"
                    TextColor="White"
                    CornerRadius="14"
                    HeightRequest="46"
                    FontAttributes="Bold"
                    Command="{Binding ProceedCommand}" />
                </Grid>

            </VerticalStackLayout>
        </Border>

    </Grid>
    </Grid>
</ContentPage>