<UserControl x:Class="NexusShell.Views.NexusCalculatorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Focusable="True"
             PreviewKeyDown="CalculatorView_OnPreviewKeyDown"
             FontFamily="Segoe UI Variable Display, Segoe UI">
    <UserControl.Resources>
        <Style x:Key="CalcButton" TargetType="Button">
            <Setter Property="Height" Value="54"/>
            <Setter Property="Margin" Value="4"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Foreground" Value="#E8F4FF"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Background" Value="#22081428"/>
            <Setter Property="BorderBrush" Value="#3300D9FF"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Root" CornerRadius="16"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Root" Property="Background" Value="#3300D9FF"/>
                                <Setter TargetName="Root" Property="BorderBrush" Value="#7700D9FF"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="Root" Property="Background" Value="#448A4FFF"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="CalcOperatorButton" TargetType="Button" BasedOn="{StaticResource CalcButton}">
            <Setter Property="Foreground" Value="#00D9FF"/>
            <Setter Property="BorderBrush" Value="#668A4FFF"/>
            <Setter Property="Background" Value="#2A1A2840"/>
            <Setter Property="Effect">
                <Setter.Value>
                    <DropShadowEffect Color="#8A4FFF" BlurRadius="12" ShadowDepth="0" Opacity="0.35"/>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="CalcFunctionButton" TargetType="Button" BasedOn="{StaticResource CalcButton}">
            <Setter Property="Foreground" Value="#8CA3C7"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="BorderBrush" Value="#448CA3C7"/>
        </Style>

        <Style x:Key="CalcEqualsButton" TargetType="Button" BasedOn="{StaticResource CalcButton}">
            <Setter Property="Foreground" Value="#FFFFFF"/>
            <Setter Property="FontSize" Value="22"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Root" CornerRadius="16" BorderThickness="0">
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <GradientStop Color="#FF00D9FF" Offset="0"/>
                                    <GradientStop Color="#FF8A4FFF" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <Border.Effect>
                                <DropShadowEffect Color="#00D9FF" BlurRadius="18" ShadowDepth="0" Opacity="0.45"/>
                            </Border.Effect>
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Root" Property="Opacity" Value="0.92"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="Root" Property="Opacity" Value="0.82"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid Margin="16,8,16,16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Margin="8,0,8,12">
            <TextBlock Text="{Binding ExpressionLine}"
                       FontSize="14"
                       Foreground="#6B84A8"
                       TextAlignment="Right"
                       TextTrimming="CharacterEllipsis"
                       MinHeight="20"/>
            <TextBlock Text="{Binding Display}"
                       FontSize="42"
                       FontWeight="Light"
                       Foreground="#FFFFFF"
                       TextAlignment="Right"
                       TextTrimming="CharacterEllipsis"
                       Margin="0,4,0,0"/>
        </StackPanel>

        <Rectangle Grid.Row="1" Height="1" Margin="8,0,8,10" Fill="#2200D9FF" Opacity="0.7"/>

        <Grid Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Button Grid.Row="0" Grid.Column="0" Style="{StaticResource CalcFunctionButton}" Content="CE"
                    Command="{Binding ButtonCommand}" CommandParameter="CE"/>
            <Button Grid.Row="0" Grid.Column="1" Style="{StaticResource CalcFunctionButton}" Content="C"
                    Command="{Binding ButtonCommand}" CommandParameter="C"/>
            <Button Grid.Row="0" Grid.Column="2" Style="{StaticResource CalcFunctionButton}"
                    Command="{Binding ButtonCommand}" CommandParameter="Backspace">
                <Path Data="M21 11H8.83l3.58-3.59L11 6l-6 6 6 6 1.41-1.41L8.83 13H21z"
                      Fill="#8CA3C7" Stretch="Uniform" Width="18" Height="18"/>
            </Button>
            <Button Grid.Row="0" Grid.Column="3" Style="{StaticResource CalcOperatorButton}" Content="%"
                    Command="{Binding ButtonCommand}" CommandParameter="%"/>

            <Button Grid.Row="1" Grid.Column="0" Style="{StaticResource CalcButton}" Content="7"
                    Command="{Binding ButtonCommand}" CommandParameter="7"/>
            <Button Grid.Row="1" Grid.Column="1" Style="{StaticResource CalcButton}" Content="8"
                    Command="{Binding ButtonCommand}" CommandParameter="8"/>
            <Button Grid.Row="1" Grid.Column="2" Style="{StaticResource CalcButton}" Content="9"
                    Command="{Binding ButtonCommand}" CommandParameter="9"/>
            <Button Grid.Row="1" Grid.Column="3" Style="{StaticResource CalcOperatorButton}" Content="÷"
                    Command="{Binding ButtonCommand}" CommandParameter="/"/>

            <Button Grid.Row="2" Grid.Column="0" Style="{StaticResource CalcButton}" Content="4"
                    Command="{Binding ButtonCommand}" CommandParameter="4"/>
            <Button Grid.Row="2" Grid.Column="1" Style="{StaticResource CalcButton}" Content="5"
                    Command="{Binding ButtonCommand}" CommandParameter="5"/>
            <Button Grid.Row="2" Grid.Column="2" Style="{StaticResource CalcButton}" Content="6"
                    Command="{Binding ButtonCommand}" CommandParameter="6"/>
            <Button Grid.Row="2" Grid.Column="3" Style="{StaticResource CalcOperatorButton}" Content="×"
                    Command="{Binding ButtonCommand}" CommandParameter="*"/>

            <Button Grid.Row="3" Grid.Column="0" Style="{StaticResource CalcButton}" Content="1"
                    Command="{Binding ButtonCommand}" CommandParameter="1"/>
            <Button Grid.Row="3" Grid.Column="1" Style="{StaticResource CalcButton}" Content="2"
                    Command="{Binding ButtonCommand}" CommandParameter="2"/>
            <Button Grid.Row="3" Grid.Column="2" Style="{StaticResource CalcButton}" Content="3"
                    Command="{Binding ButtonCommand}" CommandParameter="3"/>
            <Button Grid.Row="3" Grid.Column="3" Style="{StaticResource CalcOperatorButton}" Content="−"
                    Command="{Binding ButtonCommand}" CommandParameter="-"/>

            <Button Grid.Row="4" Grid.Column="0" Style="{StaticResource CalcFunctionButton}"
                    Command="{Binding ButtonCommand}" CommandParameter="+/-">
                <Path Data="M7 11h10M12 3v18" Stroke="#8CA3C7" StrokeThickness="1.8"
                      Stretch="Uniform" Width="16" Height="16"
                      StrokeStartLineCap="Round" StrokeEndLineCap="Round"/>
            </Button>
            <Button Grid.Row="4" Grid.Column="1" Style="{StaticResource CalcButton}" Content="0"
                    Command="{Binding ButtonCommand}" CommandParameter="0"/>
            <Button Grid.Row="4" Grid.Column="2" Style="{StaticResource CalcButton}" Content="."
                    Command="{Binding ButtonCommand}" CommandParameter="."/>
            <Button Grid.Row="4" Grid.Column="3" Style="{StaticResource CalcOperatorButton}" Content="+"
                    Command="{Binding ButtonCommand}" CommandParameter="+"/>

            <Button Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" Style="{StaticResource CalcEqualsButton}" Content="="
                    Command="{Binding ButtonCommand}" CommandParameter="="/>
        </Grid>
    </Grid>
</UserControl>
