<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:Navigator.ViewModels"   
             ControlTemplate="{StaticResource ActivityIndicatorTemplate}"
             mc:Ignorable="d"
             Title="{Binding Title}"
             x:Class="Navigator.Views.CompanyProfilePage">

  <ContentPage.BindingContext>
    <vm:CompanyProfileViewModel />
  </ContentPage.BindingContext>

  <ContentPage.Resources>
    <ResourceDictionary>
      <Style x:Key="NameLabel" TargetType="Label">
        <Setter Property="FontSize" Value="16"/>
        <Setter Property="FontAttributes" Value="Bold" />
        <Setter Property="TextColor" Value="Black" />
      </Style>

      <Style x:Key="CompanyLabel" TargetType="Label">
        <Setter Property="FontSize" Value="16" />
        <Setter Property="FontAttributes" Value="Bold" />
        <Setter Property="TextColor" Value="Black" />
      </Style>

      <Style x:Key="LabelStyle" TargetType="Label">
        <Setter Property="FontSize" Value="14" />
      </Style>

      <Style x:Key="EntryStyle" TargetType="Label">
        <Setter Property="FontSize" Value="16" />
        <Setter Property="FontAttributes" Value="Bold, Italic" />
        <Setter Property="TextColor" Value="Blue" />
      </Style>

      <Style x:Key="imageLableStackLayout" TargetType="StackLayout">
        <Setter Property="Orientation" Value="Horizontal" />
      </Style>

      <Style x:Key="detailsStackLayout" TargetType="StackLayout">
        <Setter Property="HorizontalOptions" Value="FillAndExpand" />
        <Setter Property="VerticalOptions" Value="FillAndExpand" />
        <Setter Property="Spacing" Value="2" />
      </Style>

      <Style x:Key="imageStyle" TargetType="Image">
        <Setter Property="WidthRequest" Value="8" />
        <Setter Property="HeightRequest" Value="8" />
      </Style>

      <Style x:Key="profileImageStyle" TargetType="Image">
        <Setter Property="WidthRequest" Value="80" />
        <Setter Property="HeightRequest" Value="60" />
        <Setter Property="Aspect" Value="AspectFit" />
      </Style>

      <Style x:Key="profileImageFrameStyle" TargetType="Frame">
        <Setter Property="CornerRadius" Value="5" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="IsClippedToBounds" Value="True" />
        <Setter Property="MinimumWidthRequest" Value="50" />
      </Style>

      <Style x:Key="FrameCardViewStyle" TargetType="Frame">
        <Setter Property="CornerRadius" Value="5" />
        <Setter Property="Margin" Value="5" />
        <Setter Property="Padding" Value="5" />
        <Setter Property="HorizontalOptions" Value="FillAndExpand" />
        <Setter Property="OutlineColor" Value="LightGray" />
        <Setter Property="BorderColor" Value="LightGray" />
        <Setter Property="HasShadow" Value="True" />
      </Style>

      <Style x:Key="itemsCardViewStackLayoutStyle" TargetType="StackLayout">
        <Setter Property="Margin" Value="5" />
        <Setter Property="HorizontalOptions" Value="FillAndExpand" />
        <Setter Property="Spacing" Value="8" />
      </Style>

      <Style x:Key="itemsInsideCardViewStackLayoutStyle" TargetType="StackLayout">
        <Setter Property="Orientation" Value="Horizontal" />
        <Setter Property="Spacing" Value="8" />
      </Style>
    </ResourceDictionary>
  </ContentPage.Resources>

  <ContentPage.Content>
    <Grid BackgroundColor="White" Margin="2">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="60*" />
      </Grid.RowDefinitions>

      <Frame Grid.Row="0" Style="{StaticResource FrameCardViewStyle}">
        <RefreshView Grid.Row="1" IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}" Command="{Binding RefreshCommand}">
           <CollectionView ItemsSource="{Binding Positions}" SelectionMode="Single" SelectedItem="{Binding SelectedPosition}">
            <CollectionView.ItemTemplate>
              <DataTemplate>
                <StackLayout Spacing="8" HorizontalOptions="EndAndExpand">
                  <Frame Style="{StaticResource FrameCardViewStyle}">
                    <StackLayout Style="{StaticResource itemsCardViewStackLayoutStyle}">
                      <StackLayout Style="{StaticResource itemsInsideCardViewStackLayoutStyle}">
                        <Frame Style="{StaticResource profileImageFrameStyle}">
                          <Label Text="{Binding Symbol}" Style="{StaticResource NameLabel}" />
                        </Frame>
                        <StackLayout Style="{StaticResource detailsStackLayout}">

                          <!--<StackLayout Style="{StaticResource imageLableStackLayout}">
                            <Label Text="{Binding Date,StringFormat='{}{0:dddd, MMMM d, yyyy}'}" Style="{StaticResource LabelStyle}" />
                            <Label Text="{Binding Modified,StringFormat='{}{0:HH:mm:ss}'}" Style="{StaticResource LabelStyle}" />
                          </StackLayout>-->

                          <StackLayout Style="{StaticResource imageLableStackLayout}">
                            <Label Text="{Binding CompanyName}" Style="{StaticResource LabelStyle}" />
                          </StackLayout>

                          <StackLayout Style="{StaticResource imageLableStackLayout}">
                            <Label Text="Exposure:" Style="{StaticResource LabelStyle}" />
                            <Label Text="{Binding Exposure,StringFormat='{}{0:C}'}" Style="{StaticResource LabelStyle}" />
                            <Label Text="Shares:" Style="{StaticResource LabelStyle}" />
                            <Label Text="{Binding Shares,StringFormat='{}{0:#.00}'}" Style="{StaticResource LabelStyle}" />
                          </StackLayout>

                          <StackLayout Style="{StaticResource imageLableStackLayout}">
                            <!--<Label Text="Source :" Style="{StaticResource LabelStyle}" />-->
                            <Label Text="{Binding Description}" Style="{StaticResource LabelStyle}" />
                          </StackLayout>

                        </StackLayout>
                      </StackLayout>
                    </StackLayout>
                  </Frame>
                </StackLayout>
              </DataTemplate>
            </CollectionView.ItemTemplate>
          </CollectionView >
        </RefreshView>
      </Frame>
    </Grid>
  </ContentPage.Content>


</ContentPage>