<UserControl x:Class="TradeBlotter.Views.PricingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:dc="clr-namespace:TradeBlotter.UIUtils"
             xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:Effects="clr-namespace:Telerik.Windows.Controls.ColorEditor.Effects;assembly=Telerik.Windows.Controls.Input"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <GroupStyle x:Key="PricingGroupStyle">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock 
            x:Name="txt" 
            Background="{StaticResource Brush_HeaderBackground}"
            FontWeight="Bold"
            Foreground="White"
            Margin="1"
            Padding="4,2,0,2"
            Text="People" 
            />
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Name}" Value="True">
                            <Setter TargetName="txt" Property="Text" Value="Companies" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>

        <Style x:Key="ValuationItemStyle" TargetType="{x:Type ListViewItem}">
            <!-- 
      Stretch the content of each cell so that we can 
      right-align text in the Total Sales column. 
      -->
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <!-- 
      Bind the IsSelected property of a ListViewItem to the 
      IsSelected property of a PricingViewModel object.
      -->
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="ItemsControl.AlternationIndex" Value="1" />
                        <Condition Property="IsSelected" Value="False" />
                        <Condition Property="IsMouseOver" Value="False" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="#EEEEEEEE" />
                </MultiTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <wpfx:BusyIndicator x:Name="BusyBar" BusyContent="Loading Prices..." IsBusy="{Binding BusyIndicator}">
        <Grid  Background="LightGray">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="6" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="4" />
                <RowDefinition Height="2*" />
                <RowDefinition Height="3" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Grid.Column="2" FontFamily="Arial" Content="{Binding Title}" HorizontalAlignment="Center" FontSize="20"/>

            <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Vertical">
                <Label Margin="2,0" Content="Watch List" HorizontalAlignment="Left" />
                <ComboBox Margin="2,1" ItemsSource="{Binding WatchListNames, Mode=OneTime}" SelectedItem="{Binding SelectedWatchList, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
                <!--<Label Margin="2,0" Content="Symbol" HorizontalAlignment="Left" Target="{Binding ElementName=tradeDateLbl}" />-->
                <Label Margin="2,0" Content="Symbol" HorizontalAlignment="Left" />							
                <ComboBox Margin="2,1" ItemsSource="{Binding Symbols, Mode=OneWay}" SelectedItem="{Binding SelectedSymbol, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
								<ComboBox.ItemsPanel>
									<ItemsPanelTemplate>
										<VirtualizingStackPanel/>
									</ItemsPanelTemplate>
								</ComboBox.ItemsPanel>									
								</ComboBox>	
                <Label Margin="2,0" Content="Day Count" HorizontalAlignment="Left"  />
                <ComboBox Margin="2,1" ItemsSource="{Binding DayCounts, Mode=OneWay}" SelectedItem="{Binding SelectedDayCount, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
                <Button Margin="2,1"  Content="Refresh" HorizontalAlignment="Left" Command="{Binding RefreshCommand}"/>
                <Button Margin="2,1" Content="Export" HorizontalAlignment="Left" Command="{Binding SaveCommand}"/>
                <CheckBox Content="Show Ratings" IsChecked="{Binding ShowRatings}" Height="16" HorizontalAlignment="Left" Margin="5,6,0,0" VerticalAlignment="Top" />
                <CheckBox Content="Least Squares Fit" IsChecked="{Binding CheckBoxLeastSquaresFit}" Height="16" HorizontalAlignment="Left" Margin="5,6,0,0" VerticalAlignment="Top" />
            </StackPanel>
            <DockPanel Grid.Row="4" Grid.Column="2" >
                <telerik:RadGridView AlternationCount="2" AutoGenerateColumns="False" AlternateRowBackground="Bisque" dc:GridExportGraphBehavior.ExportExcelProperty="{Binding SaveDocument}" ItemsSource="{Binding AllPrices, ValidatesOnDataErrors=True}" ShowGroupFooters="False" >
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Date, StringFormat=\{0:MM/dd/yyyy\}}" Header="Date"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding CompanyName}" Header="Company"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Symbol}" Header="Symbol"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Source}" Header="Source"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Open, StringFormat=\{0:C\}}" Header="Open"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding High, StringFormat=\{0:C\}}" Header="High"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Low, StringFormat=\{0:C\}}" Header="Low"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Close, StringFormat=\{0:C\}}" Header="Close"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Volume, StringFormat=\{0:#\,###0\}}" Header="Volume"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding AdjClose, StringFormat=\{0:C\}}" Header="AdjClose"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return1D, StringFormat=\{0:P\}}" Header="Return1D"/>											
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return5D, StringFormat=\{0:P\}}" Header="Return5D"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return10D, StringFormat=\{0:P\}}" Header="Return10D"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return15D, StringFormat=\{0:P\}}" Header="Return15D"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return30D, StringFormat=\{0:P\}}" Header="Return30D"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return60D, StringFormat=\{0:P\}}" Header="Return60D"/>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Return200D, StringFormat=\{0:P\}}" Header="Return200D"/>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </DockPanel>
            <DockPanel Grid.Row="2" Grid.Column="2" >
                <d3:ChartPlotter Background="WhiteSmoke" Margin="10,10,20,10" x:Name="prices" LegendVisibility="Hidden" NewLegendVisible="False" d3:Viewport2D.UsesApproximateContentBoundsComparison="False" BorderThickness="0">
                    <d3:ChartPlotter.MainHorizontalAxis>
                        <d3:HorizontalDateTimeAxis x:Name="dateAxis"/>
                    </d3:ChartPlotter.MainHorizontalAxis>
                    <d3:ChartPlotter.MainVerticalAxis>
                        <d3:VerticalAxis x:Name="countAxis" MinWidth="40" MaxWidth="40"/>
                    </d3:ChartPlotter.MainVerticalAxis>
                    <d3:LineGraph x:Name="Close" DataSource="{Binding Close}" Stroke="Black" StrokeThickness="1"/>
                    <d3:LineGraph x:Name="LeastSquaresFit" DataSource="{Binding LeastSquares}" Stroke="Orange" StrokeThickness="1"/>
                  
                    <d3:CursorCoordinateGraph x:Name="cursorGraph" dc:CoordinateGraphBehavior.XTextMappingProperty="MM/dd/yyyy" LineStrokeThickness="1"/>
                    <!--<d3:AxisCursorGraph/>-->
                    <!--<d3:Header FontFamily="Arial" Content="{Binding Path=Title}"/>-->
                    <d3:VerticalAxisTitle FontFamily="Arial" Content="Price"/>
                    <d3:HorizontalAxisTitle FontFamily="Arial" Content="" />

                    <d3:MarkerPointsGraph x:Name="MarkerPointsGraph" DataSource="{Binding RatingsPoints}">
                        <d3:MarkerPointsGraph.Marker>
                            <d3:CirclePointMarker Size="9" Fill="Red">
                                <d3:CirclePointMarker.Pen>
                                    <Pen Thickness="1" Brush="Black"/>
                                </d3:CirclePointMarker.Pen>
                            </d3:CirclePointMarker>
                        </d3:MarkerPointsGraph.Marker>
                    </d3:MarkerPointsGraph>

                    <d3:MarkersPointsGraph x:Name="AnalystRatingsMarkersPointsGraph" DataSource="{Binding RatingsPoints}" Markers="{Binding Markers}" >
                    </d3:MarkersPointsGraph>

                </d3:ChartPlotter>
            </DockPanel>
            <GridSplitter Background="LightBlue" ResizeDirection="Rows" Grid.Column="2" Grid.ColumnSpan="1" Grid.Row="3" Width="Auto" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
        </Grid>
    </wpfx:BusyIndicator>
</UserControl>
