<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ZicMoove.Pages.EditEstimatePage"
             xmlns:converters="clr-namespace:ZicMoove.Converters;assembly=ZicMoove"
             xmlns:views="clr-namespace:ZicMoove.Views;assembly=ZicMoove"
             xmlns:local="clr-namespace:ZicMoove;assembly=ZicMoove"
             xmlns:behaviors="clr-namespace:ZicMoove.Behaviors;assembly=ZicMoove"
             xmlns:extensions="clr-namespace:ZicMoove.Extensions;assembly=ZicMoove"
             Style="{StaticResource PageStyle}">
  <ContentPage.Resources>
    <ResourceDictionary>
      <Style TargetType="Label">
        <Setter Property="Style" Value="{StaticResource ContentLabelStyle}" />
      </Style>
      <Style TargetType="Button">
        <Setter Property="Style" Value="{StaticResource ButtonStyle}" />
      </Style>
      <converters:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">

        <converters:BooleanToObjectConverter.FalseObject>
          <Style TargetType="Image">
            <Setter Property="HeightRequest" Value="20" />
            <Setter Property="Source"
                    Value="{extensions:ImageResource ZicMoove.Images.Validation.error.png}" />
          </Style>
        </converters:BooleanToObjectConverter.FalseObject>

        <converters:BooleanToObjectConverter.TrueObject>
          <Style TargetType="Image">
            <Setter Property="HeightRequest" Value="20" />
            <Setter Property="Source"
                    Value="{extensions:ImageResource ZicMoove.Images.Validation.success.png}" />
          </Style>
        </converters:BooleanToObjectConverter.TrueObject>

      </converters:BooleanToObjectConverter>
    </ResourceDictionary>
  </ContentPage.Resources>
  <ContentPage.Content>
    <StackLayout Padding="10,10,10,10" x:Name="mainLayout">
      <Grid HeightRequest="120">
        <Grid.RowDefinitions>
          <RowDefinition Height="2*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="2*" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Text="{Binding Client.UserName}" ></Label>
        <Label Grid.Row="0" Grid.Column="1" Text="{Binding Query.Location.Address}" ></Label>
        <Label Grid.Row="0" Grid.Column="2" Text="{Binding Query.EventDate, StringFormat='{0:dddd d MMMM yyyy à hh:mm}'}" ></Label>
      </Grid>
      <Entry Placeholder="Saisissez un titre pour ce devis" Text="{Binding Title, Mode=TwoWay}" />
      <views:MarkdownView x:Name="mdview"
                          Editable="True"
      Markdown="{Binding Description, Mode=TwoWay}">
        <views:MarkdownView.Behaviors>
          <behaviors:MarkdownViewLengthValidator x:Name="descriptionLenValidator" MaxLength="512" MinLength="3" />

        </views:MarkdownView.Behaviors>
      </views:MarkdownView>
<StackLayout x:Name="biAnVaLayout">
      <ListView x:Name="BillListView" ItemsSource="{Binding Bill}"
         HasUnevenRows="true" ItemTapped="OnEditLine">
        <ListView.ItemTemplate>
          <DataTemplate >
            <ViewCell>
              <ViewCell.View Padding="5,5,5,5" >
                <Grid>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                  </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition Width="90" />
                    <ColumnDefinition Width="16" />
                  </Grid.ColumnDefinitions>
                  <Label Text="{Binding Description}"
                         Grid.Row="0" Grid.Column="0" ></Label>
                  <Label Text="{Binding Duration, StringFormat=\{0\}}"
                         Grid.Row="0" Grid.Column="1" ></Label>
                  <Label Text="{Binding Count}"
                         Grid.Row="0" Grid.Column="2" ></Label>
                  <Label Text="{Binding UnitaryCost}"
                         Grid.Row="0" Grid.Column="3"
                         FontFamily="Monospace"></Label>
                  <Image Grid.Row="0" Grid.Column="4" Style="{Binding 
                                Path=ViewModelState.IsValid, 
                                Converter={StaticResource boolToStyleImage}}" ></Image>
                </Grid>
              </ViewCell.View>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
<StackLayout Orientation="Vertical">
      <Button Text="Ajouter une ligne de facture" Clicked="OnNewCommanLine"></Button>
      <Label FormattedText="{Binding FormattedTotal}"/>
      <Button x:Name="btnValidate" Text="Valider ce devis" Clicked="OnEstimateValidated" IsEnabled="{Binding ViewModelState.IsValid}" ></Button>
</StackLayout>
    </StackLayout>
    </StackLayout>
  </ContentPage.Content>
</ContentPage>