<UserControl x:Class="FasdDesktopUi.Basics.UserControls.SearchBar"
             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:FasdDesktopUi.Basics.UserControls"
             xmlns:ico="clr-namespace:FasdDesktopUi.Basics.UserControls.AdaptableIcon;assembly=F4SD-AdaptableIcon"
             xmlns:vc="clr-namespace:FasdDesktopUi.Basics.Converter"
             mc:Ignorable="d"
             d:DesignHeight="450"
             d:DesignWidth="800"
             Name="_this"
             IsVisibleChanged="BlurInvoker_IsActiveChanged"
             Loaded="SearchBar_Loaded">

    <UserControl.Resources>
        <vc:LanguageDefinitionsConverter x:Key="LanguageConverter" />
    </UserControl.Resources>

    <Border Background="{DynamicResource BackgroundColor.Menu.Categories}"
            CornerRadius="17.5"
            Margin="-2.5"
            Padding="2.5"
            VerticalAlignment="Bottom"
            x:Name="BackgroundBorder"
            x:FieldModifier="private">

        <DockPanel>
            <ico:AdaptableIcon x:Name="SearchButton"
                               x:FieldModifier="private"
                               DockPanel.Dock="Left"
                               Style="{DynamicResource Menu.MenuBar.PinnedIcon}"
                               MouseUp="SearchButton_Click"
                               TouchDown="SearchButton_Click"
                               IconBackgroundColor="Transparent"
                               IconHeight="{Binding SearchButtonSize, RelativeSource={RelativeSource AncestorType=UserControl}}"
                               IconWidth="{Binding SearchButtonSize, RelativeSource={RelativeSource AncestorType=UserControl}}"
                               SelectedInternIcon="menuBar_search" />

            <ico:AdaptableIcon x:Name="PhoneCallIndicator"
                               x:FieldModifier="private"
                               DockPanel.Dock="Left"
                               Style="{DynamicResource Menu.MenuBar.PinnedIcon}"
                               IconBackgroundColor="Transparent"
                               Visibility="Collapsed"
                               SelectedMaterialIcon="ic_phone" />

            <ico:AdaptableIcon x:Name="ComputerCallIndicator"
                               x:FieldModifier="private"
                               DockPanel.Dock="Left"
                               Style="{DynamicResource Menu.MenuBar.PinnedIcon}"
                               IconBackgroundColor="Transparent"
                               Visibility="Collapsed"
                               SelectedInternIcon="misc_computer" />

            <ico:AdaptableIcon x:Name="UserCallIndicator"
                               x:FieldModifier="private"
                               DockPanel.Dock="Left"
                               Style="{DynamicResource Menu.MenuBar.PinnedIcon}"
                               IconBackgroundColor="Transparent"
                               Visibility="Collapsed"
                               SelectedInternIcon="misc_user" />

            <ico:AdaptableIcon x:Name="WarningIndicator"
                               x:FieldModifier="private"
                               DockPanel.Dock="Left"
                               Style="{DynamicResource Menu.MenuBar.PinnedIcon}"
                               IconBackgroundColor="Transparent"
                               PrimaryIconColor="#FFFF8800"
                               Visibility="Collapsed"
                               SelectedInternIcon="status_bad" />

            <Grid DockPanel.Dock="Left">

                <TextBlock IsHitTestVisible="False"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Left"
                           Margin="9 0 0 0"
                           Foreground="{DynamicResource FontColor.DetailsPage.DataHistory.Date}">
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Text, ElementName=SearchTextBox}"
                                             Value="">
                                    <Setter Property="Text"
                                            Value="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Searchbar.Placeholder.UserName}" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>

                <TextBox x:Name="SearchTextBox"
                         x:FieldModifier="private"
                         Text="{Binding ElementName=_this, Path=SearchValue, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}"
                         Style="{DynamicResource SearchBar.TextBox}" />

                <StackPanel Orientation="Horizontal"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Center">
                    <ico:AdaptableIcon x:Name="SearchSpinner"
                                       x:FieldModifier="private"
                                       Visibility="Hidden"
                                       Margin="5 0 0 0"
                                       Padding="0"
                                       SelectedInternGif="loadingSpinner"
                                       RenderTransformOrigin="0.5,0.5">
                        <ico:AdaptableIcon.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform />
                                <SkewTransform />
                                <RotateTransform Angle="90" />
                                <TranslateTransform />
                            </TransformGroup>
                        </ico:AdaptableIcon.RenderTransform>
                    </ico:AdaptableIcon>
                    <ico:AdaptableIcon x:Name="CloseButton"
                                       x:FieldModifier="private"
                                       Style="{DynamicResource SettingsPage.Close.Icon}"
                                       IconHeight="{Binding CloseButtonSize, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                       IconWidth="{Binding CloseButtonSize, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                       Margin="-3 0 0 0"
                                       Padding="0"
                                       ToolTip="{Binding Converter={StaticResource LanguageConverter}, ConverterParameter=Global.NavBar.Close}"
                                       MouseUp="CloseButton_Click"
                                       TouchDown="CloseButton_Click"
                                       SelectedInternIcon="window_close" />
                </StackPanel>

            </Grid>
        </DockPanel>
    </Border>
</UserControl>
