<UserControl
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
    xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:models="clr-namespace:Ryujinx.Ava.UI.Models.Input"
    xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input"
    x:Class="Ryujinx.Ava.UI.Views.Input.AssignedDevicesInputView"
    x:DataType="viewModels:InputViewModel"
    x:CompileBindings="True"
    mc:Ignorable="d">
    <Grid Margin="10" RowDefinitions="Auto,Auto">
        <Border
            Grid.Row="0"
            Padding="10,8"
            BorderBrush="{DynamicResource ThemeControlBorderColor}"
            BorderThickness="1"
            CornerRadius="5"
            HorizontalAlignment="Stretch">
            <ItemsControl ItemsSource="{Binding PlayerInputDevices}">
                <ItemsControl.Styles>
                    <Style Selector="ContentPresenter">
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>
                </ItemsControl.Styles>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel HorizontalAlignment="Stretch" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate DataType="models:PlayerInputDeviceAssignmentItem">
                        <Border
                            Margin="0,3"
                            Padding="10,8"
                            CornerRadius="4"
                            HorizontalAlignment="Stretch"
                            Background="{DynamicResource ControlFillColorTertiary}"
                            BorderBrush="{DynamicResource ThemeControlBorderColor}"
                            BorderThickness="1"
                            PointerPressed="DeviceRow_OnPointerPressed"
                            Cursor="Hand"
                            IsEnabled="{Binding !IsDisabledByOtherPlayer}">
                            <DockPanel
                                HorizontalAlignment="Stretch"
                                LastChildFill="True">
                                <CheckBox
                                    DockPanel.Dock="Left"
                                    Margin="0,0,8,0"
                                    Padding="0"
                                    VerticalAlignment="Center"
                                    ClipToBounds="False"
                                    IsChecked="{Binding IsAssigned}"
                                    Checked="AssignedDeviceCheckBox_OnCheckedChanged"
                                    Unchecked="AssignedDeviceCheckBox_OnCheckedChanged" />
                                <TextBlock
                                    DockPanel.Dock="Right"
                                    Margin="10,0,0,0"
                                    Opacity="0.6"
                                    FontSize="12"
                                    MaxWidth="200"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Right"
                                    TextWrapping="Wrap"
                                    Text="{Binding AssignedToPlayers}"
                                    IsVisible="{Binding HasAssignedToPlayers}" />
                                <StackPanel
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center">
                                    <TextBlock
                                        HorizontalAlignment="Left"
                                        Text="{Binding Name}" />
                                    <TextBlock
                                        HorizontalAlignment="Left"
                                        Opacity="0.6"
                                        FontSize="12"
                                        TextTrimming="CharacterEllipsis"
                                        TextWrapping="NoWrap"
                                        MaxLines="1"
                                        IsVisible="{Binding HasBoundProfileName}">
                                        <Run Text="{ext:Locale ControllerSettingsProfile}" />
                                        <Run Text=": " />
                                        <Run Text="{Binding BoundProfileName}" />
                                    </TextBlock>
                                </StackPanel>
                            </DockPanel>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Border>
        <CheckBox
            Grid.Row="1"
            Margin="0,8,0,0"
            IsChecked="{Binding AllowDuplicateDeviceAssignment}">
            <TextBlock
                VerticalAlignment="Center"
                Text="{ext:Locale ControllerSettingsAllowDuplicateDeviceAssignment}" />
        </CheckBox>
    </Grid>
</UserControl>
