<UserControl x:Class="TradeBlotter.Views.OptionsWorksheetView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:dc="clr-namespace:TradeBlotter.UIUtils"
             xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">
    <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="Loading options worksheet...">
        <Grid  Background="LightGray">

          
      <Grid.Resources>
        <dc:EquityPriceShockPositionGLStyle x:Key="EquityPriceShockPositionGLStyle">
          <dc:EquityPriceShockPositionGLStyle.NegativeStyle>
            <Style TargetType="telerik:GridViewCell">
              <Setter Property="Foreground" Value="Red"/>
            </Style>
          </dc:EquityPriceShockPositionGLStyle.NegativeStyle>
          <dc:EquityPriceShockPositionGLStyle.PositiveStyle>
            <Style TargetType="telerik:GridViewCell">
              <Setter Property="Foreground" Value="Green" />
            </Style>
          </dc:EquityPriceShockPositionGLStyle.PositiveStyle>
        </dc:EquityPriceShockPositionGLStyle>



        <dc:EquityPriceShockTransactionGLStyle x:Key="EquityPriceShockTransactionGLStyle">
          <dc:EquityPriceShockTransactionGLStyle.NegativeStyle>
            <Style TargetType="telerik:GridViewCell">
              <Setter Property="Foreground" Value="Red"/>
            </Style>
          </dc:EquityPriceShockTransactionGLStyle.NegativeStyle>
          <dc:EquityPriceShockTransactionGLStyle.PositiveStyle>
            <Style TargetType="telerik:GridViewCell">
              <Setter Property="Foreground" Value="Green" />
            </Style>
          </dc:EquityPriceShockTransactionGLStyle.PositiveStyle>
        </dc:EquityPriceShockTransactionGLStyle>
      </Grid.Resources>


      <AdornerDecorator>
                <Grid>
                    <DockPanel>
                        <Grid Margin="4">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="6" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="3" />
                                <RowDefinition Height="30" />
                            </Grid.RowDefinitions>
                        </Grid>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height=".12*" />
                                <RowDefinition Height=".8*" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition Width=".01*"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" FontFamily="Arial" Content="{Binding Path=Title}" HorizontalAlignment="Center" FontSize="20"></Label>
                            <DockPanel Grid.Row="1" Grid.Column="0" >
                            </DockPanel>
                            <GroupBox BorderBrush="Black"  Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="1" Header="Options Worksheet" Grid.RowSpan="2" FontSize="11" >
                                <StackPanel Grid.Row="0" Grid.Column="1">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height="7" />
                                            <RowDefinition Height=".7*" />
                                            <RowDefinition Height="7" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="62*"></ColumnDefinition>
                                            <ColumnDefinition Width="3*"></ColumnDefinition>
                                            <ColumnDefinition Width="56*"></ColumnDefinition>
                                            <ColumnDefinition Width="3*"></ColumnDefinition>
                                            <ColumnDefinition Width="52*"></ColumnDefinition>
                                            <ColumnDefinition Width="3*"></ColumnDefinition>
                                            <ColumnDefinition Width="52*"></ColumnDefinition>
                                            <ColumnDefinition Width="3*"></ColumnDefinition>
                                            <ColumnDefinition Width="52*"></ColumnDefinition>
                                            <ColumnDefinition Width="3*"></ColumnDefinition>
                                            <ColumnDefinition Width="52*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>

                                        <Label Grid.Row="0" Grid.Column="0" FontSize="10" Content="Investment" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="The initial investment." Grid.Row="1" Grid.Column="0" FontSize="10" IsReadOnly="true" Text="{Binding Path=Investment, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="0" Grid.Column="2" FontSize="10" Content="Bid" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="The bid price of the option." Grid.Row="1" Grid.Column="2" FontSize="10" IsReadOnly="true" Text="{Binding Path=Bid, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="0" Grid.Column="4" FontSize="10" Content="Strike" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="The strike price of the option." Grid.Row="1" Grid.Column="4" FontSize="10" IsReadOnly="true" Text="{Binding Path=Strike, Mode=OneWay}" ></TextBox>

                                        <Label Grid.Row="0" Grid.Column="6" FontSize="10" Content="Expiration Date" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="The expiration date of the option." Grid.Row="1" Grid.Column="6" FontSize="10" IsReadOnly="true" Background="{Binding Path=ExpirationDateBackground}" Text="{Binding Path=ExpirationDate, Mode=OneWay}" ></TextBox>

                                        <Label Grid.Row="2" Grid.Column="0" FontSize="10" Content="Shares" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="The number of shares purchased with initial investment." Grid.Row="3" Grid.Column="0" FontSize="10" IsReadOnly="true" Text="{Binding Path=Shares, Mode=OneWay}" ></TextBox>

                                        <Label Grid.Row="2" Grid.Column="2" FontSize="10" Content="Contracts" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Number of contracts purchaseable with investment" Grid.Row="3" Grid.Column="2" FontSize="10"  IsReadOnly="true" Text="{Binding Path=Contracts, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>
                                      
                                        <Label Grid.Row="4" Grid.Column="0" FontSize="10" Content="Open Interest" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Open Interest" Grid.Row="5" Grid.Column="0" FontSize="10"  IsReadOnly="true" Text="{Binding Path=OpenInterest, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="4" Grid.Column="2" FontSize="10" Content="Premium" HorizontalAlignment="Left" ></Label>
                                        <TextBox ToolTipService.ToolTip="The premium received for the option." Grid.Row="5" Grid.Column="2"  FontSize="10" IsReadOnly="true" Text="{Binding Path=Premium, Mode=OneWay}" ></TextBox>

                                        <Label Grid.Row="2" Grid.Column="4" FontSize="10" Content="Underlier Price" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Price when record created" Grid.Row="3" Grid.Column="4" FontSize="10"  IsReadOnly="true" Text="{Binding Path=UnderlierPrice, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="2" Grid.Column="6" FontSize="10" Content="Underlier Price Date" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Pricing date when record was created" Grid.Row="3" Grid.Column="6" FontSize="10"  IsReadOnly="true" Text="{Binding Path=UnderlierPriceDate, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="4" Grid.Column="4" FontSize="10" Content="Current Price" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Latest market price in database" Grid.Row="5" Grid.Column="4" FontSize="10"  IsReadOnly="true" Text="{Binding Path=CurrentPrice, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="4" Grid.Column="6" FontSize="10" Content="Current Price Date" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Latest market price date in database" Grid.Row="5" Grid.Column="6" FontSize="10"  IsReadOnly="true" Text="{Binding Path=CurrentPriceDate, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="6" Grid.Column="0" FontSize="10" Content="Volatility" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Volatility of stock." Grid.Row="7" Grid.Column="0" FontSize="10"  IsReadOnly="true" Text="{Binding Path=Volatility, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>
                                      
                                        <Label Grid.Row="6" Grid.Column="2" FontSize="10" Content="Volatility Days" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Number of days in volatility." Grid.Row="7" Grid.Column="2" FontSize="10"  IsReadOnly="true" Text="{Binding Path=VolatilityDays, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="6" Grid.Column="4" FontSize="10" Content="Loss Point" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Price at which transaction is losing money." Grid.Row="7" Grid.Column="4" FontSize="10"  IsReadOnly="true" Text="{Binding Path=LossPoint, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <Label Grid.Row="6" Grid.Column="6" FontSize="10" Content="Transaction G/L" HorizontalAlignment="Left"></Label>
                                        <TextBox ToolTipService.ToolTip="Current Gain/Loss." Grid.Row="7" Grid.Column="6" FontSize="10"  IsReadOnly="true" Background="{Binding Path=TransactionGLBackground}" Text="{Binding Path=TransactionGL, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>

                                        <CheckBox Grid.Row="9" Content="Realtime Price" IsChecked="{Binding Path=UseRealPrice}" Margin="0,1" ></CheckBox>


                    <DockPanel Grid.Row="0" Grid.Column="8" Grid.ColumnSpan="4"  Grid.RowSpan="8">
                                <d3:ChartPlotter Background="WhiteSmoke" Margin="10,10,20,10" x:Name="prices" LegendVisibility="Hidden" NewLegendVisible="False" d3:Viewport2D.UsesApproximateContentBoundsComparison="False" BorderThickness="2">
                                  <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="Blue" 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:ChartPlotter>
                              </DockPanel>



                  </Grid>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="5" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="93*"/>
                      <ColumnDefinition Width="191*"/>
                    </Grid.ColumnDefinitions>
                    <telerik:RadGridView Grid.Row="1" CanUserSelect="True" FontSize="10" SelectionMode="Single" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupPanel="false" ShowGroupFooters="False" ItemsSource="{Binding Path=EquityPriceShocks, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" Grid.ColumnSpan="2" Margin="0,0,0,15" >
                      <telerik:RadContextMenu.ContextMenu>
                        <telerik:RadContextMenu x:Name="GridContextMenu" StaysOpen="False" ItemsSource="{Binding MenuItems}">
                          <telerik:RadContextMenu.ItemContainerStyle>
                            <Style TargetType="telerik:RadMenuItem">
                              <Setter Property="Header" Value="{Binding Text}" />
                              <Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
                              <Setter Property="StaysOpenOnClick" Value="False" />
                            </Style>
                          </telerik:RadContextMenu.ItemContainerStyle>
                        </telerik:RadContextMenu>
                      </telerik:RadContextMenu.ContextMenu>
                      <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn Header="Equity Price Shocks" IsReadOnly="true" DataMemberBinding="{Binding Path=PriceShock}" />
                        <telerik:GridViewDataColumn Header="Market Price"  IsReadOnly="true" DataMemberBinding="{Binding Path=MarketPrice,StringFormat={}{0:C}}" />
                        <telerik:GridViewDataColumn Header="Strike Price"  IsReadOnly="true" DataMemberBinding="{Binding Path=StrikePrice,StringFormat={}{0:C}}" />
                        <telerik:GridViewDataColumn Header="Premium"  IsReadOnly="true" DataMemberBinding="{Binding Path=Premium,StringFormat={}{0:C}}" />
                        <telerik:GridViewDataColumn Header="Position G/L"  CellStyleSelector="{StaticResource EquityPriceShockPositionGLStyle}" IsReadOnly="true" DataMemberBinding="{Binding Path=PositionGL,StringFormat={}{0:C}}" />
                        <telerik:GridViewDataColumn Header="Transaction G/L" CellStyleSelector="{StaticResource EquityPriceShockTransactionGLStyle}" IsReadOnly="true" DataMemberBinding="{Binding Path=TransactionGL,StringFormat={}{0:C}}" />
                        <telerik:GridViewDataColumn Header="Expected Outcome"  IsReadOnly="true" DataMemberBinding="{Binding Path=ExpectedOutcome,StringFormat={}{0:C}}" />
                      </telerik:RadGridView.Columns>
                                        </telerik:RadGridView>
                                    </Grid>
                                </StackPanel>
                            </GroupBox>
                        </Grid>
                    </DockPanel>
                </Grid>
            </AdornerDecorator>
        </Grid>
    </wpfx:BusyIndicator>
</UserControl>
