<local:FileViewControl x:Class="FFXIV_TexTools.Views.Controls.ModelFileControl"
             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:local="clr-namespace:FFXIV_TexTools.Views.Controls"
             xmlns:resx="clr-namespace:FFXIV_TexTools.Resources"
             xmlns:views="clr-namespace:FFXIV_TexTools.Views"
             xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" 
             xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             mc:Ignorable="d" 
             xmlns:hx="http://helix-toolkit.org/wpf/SharpDX"
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid>
            <hx:Viewport3DX
                x:Name="Viewport"
                DataContext="{Binding Path=ViewportVM}"
                Camera="{Binding Path=Camera}"
                CoordinateSystemLabelForeground="White"
                TextBrush="Black"
                UseDefaultGestures="False"
                BackgroundColor="{Binding Path=BackgroundColor}"
                EffectsManager="{Binding Path=EffectsManager}"
                IsZoomEnabled="True"
                ZoomExtentsWhenLoaded="True" 
                ShowTriangleCountInfo="True" FXAALevel="Medium" MSAA="Two" 
                OITRenderMode="DepthPeeling" OITWeightMode="Linear0" ZoomDistanceLimitNear="0.0001">
                <hx:Viewport3DX.InputBindings>
                    <KeyBinding Key="B" Command="hx:ViewportCommands.BackView" />
                    <KeyBinding Key="F" Command="hx:ViewportCommands.FrontView" />
                    <KeyBinding Key="U" Command="hx:ViewportCommands.TopView" />
                    <KeyBinding Key="D" Command="hx:ViewportCommands.BottomView" />
                    <KeyBinding Key="L" Command="hx:ViewportCommands.LeftView" />
                    <KeyBinding Key="R" Command="hx:ViewportCommands.RightView" />
                    <KeyBinding Command="hx:ViewportCommands.ZoomExtents" Gesture="Alt+E" />
                    <KeyBinding Command="hx:ViewportCommands.Reset" Gesture="Alt+R"/>
                    <MouseBinding Command="hx:ViewportCommands.Rotate" Gesture="RightClick" />
                    <MouseBinding Command="hx:ViewportCommands.Zoom" Gesture="MiddleClick" />
                    <MouseBinding Command="hx:ViewportCommands.Pan" Gesture="LeftClick" />
                </hx:Viewport3DX.InputBindings>
                <hx:DirectionalLight3D
                    Direction="{Binding Path=Light1Direction}"
                    Color="{Binding Path=Light1Color}" />
                <hx:DirectionalLight3D
                    Direction="{Binding Path=Light2Direction}"
                    Color="{Binding Path=Light2Color}" />
                <hx:DirectionalLight3D
                    Direction="{Binding Path=Light3Direction}"
                    Color="{Binding Path=Light3Color}" />
                <hx:GroupModel3D ItemsSource="{Binding Path=Models}"/>
            </hx:Viewport3DX>
            <Canvas Name="AlternateViewportCanvas" Visibility="Hidden" IsHitTestVisible="False"/>

            <Label x:Name="ViewportDisclaimer" VerticalAlignment="Top" HorizontalAlignment="Center" Content="{Binding Source={x:Static resx:UIStrings.Viewport_Disclaimer}}" Foreground="#FF151515" FontSize="10"/>
            <Label VerticalAlignment="Bottom" Content="{Binding ModelStatusLabel}" HorizontalContentAlignment="Center" Foreground="#FF151515" FontSize="18" Margin="10"/>


            <Grid x:Name="ViewerSettingsGrid" Grid.Row="1" VerticalAlignment="Top">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"></RowDefinition>
                    <RowDefinition Height="40"></RowDefinition>
                    <RowDefinition Height="40"></RowDefinition>
                    <RowDefinition Height="40"></RowDefinition>
                </Grid.RowDefinitions>
                <Button Grid.Row="0" Margin="5" Content="{Binding Source={x:Static resx:UIStrings.Viewer_Options}}" Click="ToggleFlyout"/>
                <Button Grid.Row="2" Margin="5" Content="Edit Model" Click="EditModel_Click" />

                <Grid x:Name="AddModelGrid" Margin="5" Grid.Row="1" ToolTip="Add/Merge other models into this model.">
                    <Button Grid.Column="0" Click="AddModel_Click" Content="Merge Models"/>
                    <Grid.ContextMenu>
                        <ContextMenu x:Name="AddModelContextMenu">
                            <MenuItem Header="FFXIV Model" Click="AddFfxivModel_Click"/>
                            <MenuItem Header="External Model File" Click="AddExternalModel_Click"/>
                        </ContextMenu>
                    </Grid.ContextMenu>
                </Grid>
            </Grid>

            <Grid x:Name="FloatingButtonsGrid" HorizontalAlignment="Left" VerticalAlignment="Bottom"  Width="200">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Grid x:Name="OtherActionsGrid" Margin="5" Grid.Row="2" ToolTip="Add/Merge other models into this model.">
                    <Button Grid.Column="0" Click="OtherActions_Click" Content="More Actions"/>
                    <Grid.ContextMenu>
                        <ContextMenu x:Name="OtherActionsContextMenu">
                            <MenuItem Header="Add to FMV" IsEnabled="{Binding Path=FmvButtonEnabled}" Click="FullModel_Click"/>
                            <MenuItem Header="Export Raw Textures" Click="ExportTextures_Click"/>
                            <MenuItem Header="Export PBR Textures" Click="ExportPbrTextures_Click"/>
                            <MenuItem Header="View/Edit Material" IsEnabled="{Binding Path=ShowMaterialEnabled}" Click="ShowMaterial_Click"/>
                            <MenuItem Header="Copy Model and Materials To..." Click="CopyModel_Click"/>
                            <MenuItem Header="Show Raw MDL Info" Click="ModelInfo_Click"/>
                        </ContextMenu>
                    </Grid.ContextMenu>
                </Grid>
            </Grid>

            <mah:ClipBorder Width="250" HorizontalAlignment="Left"> 
                <mah:FlyoutsControl Width="250" HorizontalAlignment="Left">
                    <mah:Flyout x:Name="ViewerOptionsFlyout"
                                Header="Viewer Options" 
                                Position="Left" 
                                Width="250" 
                                HorizontalContentAlignment="Stretch"
                                VerticalContentAlignment="Stretch"
                                DataContext="{Binding Path=ViewportVM}">
                        <views:ModelViewerOptionsView/>
                    </mah:Flyout>
                </mah:FlyoutsControl>
            </mah:ClipBorder>
        </Grid>
    </Grid>
</local:FileViewControl>
