<?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="GMCabsDriverAssistantSolution.Views.CouponHistoryPage"
             xmlns:vm="clr-namespace:GMCabsDriverAssistantSolution.ViewModels"
             Title="{Binding Title}">
    <ContentPage.BindingContext>
        <vm:CouponHistoryViewModel />
    </ContentPage.BindingContext>
    <ContentPage.Resources>
        <ResourceDictionary>
            <Color x:Key="Accent">#96d1ff</Color>
            <Style x:Key="LabelStyle" TargetType="Label">
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <StackLayout Orientation="Vertical"
                     BackgroundColor="#DCDCDC"
                     Padding="8">
            <Label Text="Coupon History"
                   FontSize="25"
                   TextColor="Black"
                   Margin="10,30,0,10"/>
            <CollectionView ItemsSource="{Binding CouponsHistory}">
                <CollectionView.ItemsLayout>
                    <LinearItemsLayout 
                        ItemSpacing="10" 
                        Orientation="Vertical"/>
                </CollectionView.ItemsLayout>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout Padding="5,0,5,0">
                            <Frame 
                                CornerRadius="24" 
                                Padding="10" 
                                BackgroundColor="White">
                                <StackLayout Orientation="Horizontal">
                                    <Frame Padding="0"
                                           CornerRadius="8">
                                        <Label Text="{Binding CouponText}"
                                               Padding="5,5,5,5"
                                               HorizontalOptions="Start"
                                               LineBreakMode="NoWrap"
                                               FontSize="Caption"
                                               TextTransform="Uppercase"
                                               VerticalTextAlignment="Center"
                                               BackgroundColor="{Binding CouponBackgroundColor}"
                                               Style="{StaticResource LabelStyle}"
                                               TextColor="White"/>
                                    </Frame>
                                    <Label Text="{Binding RedeemedLocation}" 
                                           VerticalTextAlignment="Center"
                                           HorizontalOptions="Start"
                                           FontSize="Body"
                                           TextColor="Black"/>
                                    <Label                                            
                                           VerticalTextAlignment="Center"
                                           HorizontalOptions="EndAndExpand"
                                           FontSize="Body"
                                           TextColor="Black">
                                        <Label.Triggers>
                                            <DataTrigger TargetType="Label" Binding="{Binding isRedemed}" Value="True">
                                                <Setter Property="Text" Value="{Binding RedeemedDate, StringFormat='{0:dd-MM}'}"/>
                                            </DataTrigger>
                                            <DataTrigger TargetType="Label" Binding="{Binding isRedemed}" Value="False">
                                                <Setter Property="Text" Value="{Binding ExpiryDate, StringFormat='{0:dd-MM}'}" />
                                            </DataTrigger>
                                        </Label.Triggers>
                                    </Label>
                                </StackLayout>
                            </Frame>
                        </StackLayout>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
                <CollectionView.EmptyView>
                    <ContentView>
                        <StackLayout Orientation="Vertical" 
                                 VerticalOptions="CenterAndExpand">
                            <Image Source="support"
                               HeightRequest="70"/>
                            <Label Text="{Binding LoadingText}"
                               TextColor="Black"
                               FontSize="20"
                               HorizontalTextAlignment="Center"
                               VerticalTextAlignment="Center"/>
                        </StackLayout>
                    </ContentView>
                </CollectionView.EmptyView>
            </CollectionView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>