<UserControl x:Class="NexusShell.Views.NexusAppHubView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Name="Root">
    <UserControl.Resources>
        <Style x:Key="HubTileButtonStyle" TargetType="Button">
            <Setter Property="MinHeight" Value="118"/>
            <Setter Property="Padding" Value="14"/>
            <Setter Property="Margin" Value="6"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Background" Value="#1200D9FF"/>
            <Setter Property="BorderBrush" Value="#2600D9FF"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="RootBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="16"
                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="RootBorder" Property="Background" Value="#2200D9FF"/>
                                <Setter TargetName="RootBorder" Property="BorderBrush" Value="#6600D9FF"/>
                                <Setter TargetName="RootBorder" Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect Color="#00D9FF" BlurRadius="20" ShadowDepth="0" Opacity="0.35"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.55"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Margin="0,0,0,18">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Border Height="48" CornerRadius="16" Background="#14081428" BorderBrush="#3300D9FF" BorderThickness="1">
                <Grid Margin="14,0">
                    <TextBlock Text="Søg Nexus apps, værktøjer og systemflader"
                               VerticalAlignment="Center"
                               Foreground="{StaticResource NexusTextSecondaryBrush}"
                               FontSize="13"
                               IsHitTestVisible="False">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Setter Property="Visibility" Value="Collapsed"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding SearchText}" Value="">
                                        <Setter Property="Visibility" Value="Visible"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                    <TextBox Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
                             Background="Transparent"
                             BorderThickness="0"
                             Foreground="{StaticResource NexusTextPrimaryBrush}"
                             CaretBrush="{StaticResource NexusAccentCyanBrush}"
                             FontSize="14"
                             VerticalContentAlignment="Center"/>
                </Grid>
            </Border>
            <Button Grid.Column="1" Content="Alle apps"
                    Command="{Binding ShowAllAppsCommand}"
                    Style="{StaticResource NexusGlassButtonStyle}"
                    Margin="12,0,0,0"
                    MinWidth="112"/>
        </Grid>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="2.2*"/>
                <ColumnDefinition Width="0.95*"/>
            </Grid.ColumnDefinitions>

            <ScrollViewer Grid.Column="0" VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding PinnedApps}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="3"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button Style="{StaticResource HubTileButtonStyle}"
                                    Command="{Binding DataContext.LaunchCommand, ElementName=Root}"
                                    CommandParameter="{Binding}"
                                    ToolTip="{Binding Description}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <Grid Grid.Row="0">
                                        <Border Width="42" Height="42" CornerRadius="13"
                                                Background="{StaticResource Nexus.IconBadgeBrush}"
                                                HorizontalAlignment="Left">
                                            <TextBlock Text="{Binding IconPath, TargetNullValue=⬡, FallbackValue=⬡}"
                                                       FontSize="18"
                                                       HorizontalAlignment="Center"
                                                       VerticalAlignment="Center"/>
                                        </Border>
                                        <Border HorizontalAlignment="Right" CornerRadius="999"
                                                Padding="8,3" Background="#18081428" BorderBrush="#2200D9FF" BorderThickness="1">
                                            <TextBlock Text="{Binding StatusLabel}" FontSize="10"
                                                       Foreground="{StaticResource NexusAccentCyanBrush}"
                                                       TextTrimming="CharacterEllipsis"
                                                       MaxWidth="86"/>
                                        </Border>
                                    </Grid>
                                    <StackPanel Grid.Row="1" Margin="0,12,0,10">
                                        <TextBlock Text="{Binding Name}"
                                                   Foreground="{StaticResource NexusTextPrimaryBrush}"
                                                   FontSize="15"
                                                   FontWeight="SemiBold"
                                                   TextTrimming="CharacterEllipsis"/>
                                        <TextBlock Text="{Binding Description}"
                                                   Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                   FontSize="11"
                                                   TextWrapping="Wrap"
                                                   MaxHeight="36"
                                                   Margin="0,5,0,0"/>
                                    </StackPanel>
                                    <TextBlock Grid.Row="2" Text="{Binding Category}"
                                               Foreground="{StaticResource NexusTextSecondaryBrush}"
                                               FontSize="10"
                                               FontWeight="SemiBold"/>
                                </Grid>
                            </Button>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>

            <Grid Grid.Column="1" Margin="18,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Border Grid.Row="0" Style="{StaticResource NexusGlassPanelStyle}" Padding="18" Margin="0,0,0,14">
                    <StackPanel>
                        <TextBlock Text="WORKSPACE" FontSize="10" FontWeight="Bold"
                                   Foreground="{StaticResource NexusTextSecondaryBrush}"/>
                        <TextBlock Text="{Binding UserDisplayName}" FontSize="18" FontWeight="SemiBold"
                                   Foreground="{StaticResource NexusTextPrimaryBrush}" Margin="0,8,0,0"/>
                        <TextBlock Text="{Binding UserRole}" FontSize="12"
                                   Foreground="{StaticResource NexusAccentCyanBrush}" Margin="0,3,0,0"/>
                    </StackPanel>
                </Border>

                <Border Grid.Row="1" Style="{StaticResource NexusGlassPanelStyle}" Padding="18">
                    <StackPanel>
                        <TextBlock Text="SENESTE" FontSize="10" FontWeight="Bold"
                                   Foreground="{StaticResource NexusTextSecondaryBrush}" Margin="0,0,0,12"/>
                        <ItemsControl ItemsSource="{Binding RecentDocuments}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border CornerRadius="12" Background="#0E00D9FF" Padding="10" Margin="0,0,0,8">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Text="{Binding Glyph}" FontSize="18" Margin="0,0,10,0"/>
                                            <StackPanel Grid.Column="1">
                                                <TextBlock Text="{Binding Name}" FontSize="12" FontWeight="SemiBold"
                                                           Foreground="{StaticResource NexusTextPrimaryBrush}"
                                                           TextTrimming="CharacterEllipsis"/>
                                                <TextBlock Text="{Binding Category}" FontSize="10"
                                                           Foreground="{StaticResource NexusTextSecondaryBrush}"/>
                                            </StackPanel>
                                            <TextBlock Grid.Column="2" Text="{Binding Time}" FontSize="10"
                                                       Foreground="{StaticResource NexusTextSecondaryBrush}"
                                                       VerticalAlignment="Center"/>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </Border>

                <Button Grid.Row="2" Content="Åbn Nexus Files"
                        Command="{Binding OpenFilesCommand}"
                        Style="{StaticResource NexusGlassButtonStyle}"
                        HorizontalAlignment="Stretch"
                        Margin="0,14,0,0"/>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
