<UserControl
    x:Class="SHH.CameraDashboard.CameraEdit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:SHH.CameraDashboard"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DataContext="{d:DesignInstance Type=local:CameraEditViewModel}"
    d:DesignHeight="700"
    d:DesignWidth="500"
    mc:Ignorable="d">

    <Grid Margin="15" Background="{DynamicResource Brush.Bg.Window}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock
            Margin="0,0,0,15"
            FontSize="18"
            FontWeight="Bold"
            Foreground="{DynamicResource Brush.Text.Primary}"
            Text="设备参数配置" />

        <ScrollViewer
            Grid.Row="1"
            Padding="0,0,5,0"
            VerticalScrollBarVisibility="Auto">
            <StackPanel>

                <StackPanel.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="Foreground" Value="{DynamicResource Brush.Text.Primary}" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>
                    <Style TargetType="TextBox">
                        <Setter Property="Height" Value="26" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                        <Setter Property="Background" Value="{DynamicResource Brush.Bg.Input}" />
                        <Setter Property="Foreground" Value="{DynamicResource Brush.Text.Primary}" />
                        <Setter Property="BorderBrush" Value="{DynamicResource Brush.Border}" />
                    </Style>
                </StackPanel.Resources>

                <GroupBox
                    Margin="0,0,0,15"
                    Padding="10"
                    BorderBrush="{DynamicResource Brush.Border}"
                    Foreground="{DynamicResource Brush.Text.Primary}"
                    Header="基础身份 (Identity)">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="80" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <WrapPanel Grid.ColumnSpan="2">
                            <TextBlock Margin="0,5" Text="设备 ID *" />
                            <TextBox
                                Width="80"
                                Margin="30,5"
                                Text="{Binding EditingDto.Id}" />

                            <TextBlock Margin="0,5" Text="品牌类型" />
                            <ComboBox
                                Width="180"
                                Margin="5,5,0,5"
                                DisplayMemberPath="Label"
                                ItemsSource="{Binding BrandOptions}"
                                SelectedValue="{Binding EditingDto.Brand}"
                                SelectedValuePath="Value" />
                        </WrapPanel>


                        <TextBlock
                            Grid.Row="1"
                            Margin="0,5"
                            Text="设备名称" />
                        <TextBox
                            Grid.Row="1"
                            Grid.Column="1"
                            Margin="0,5"
                            Text="{Binding EditingDto.Name}" />


                        <TextBlock
                            Grid.Row="3"
                            Margin="0,5"
                            Text="安装位置" />
                        <TextBox
                            Grid.Row="3"
                            Grid.Column="1"
                            Margin="0,5"
                            Text="{Binding EditingDto.Location}" />
                    </Grid>
                </GroupBox>

                <GroupBox
                    Margin="0,0,0,15"
                    Padding="10"
                    BorderBrush="{DynamicResource Brush.Border}"
                    Foreground="{DynamicResource Brush.Text.Primary}"
                    Header="核心连接 (Connectivity)">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="80" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="60" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBlock Margin="0,5" Text="IP 地址 *" />
                        <TextBox
                            Grid.Column="1"
                            Margin="0,5,10,5"
                            Text="{Binding EditingDto.IpAddress}" />

                        <TextBlock
                            Grid.Column="2"
                            Margin="0,5"
                            HorizontalAlignment="Right"
                            Text="端口 " />
                        <TextBox
                            Grid.Column="3"
                            Margin="5,5,0,5"
                            Text="{Binding EditingDto.Port}" />

                        <WrapPanel Grid.Row="1" Grid.ColumnSpan="4">
                            <TextBlock
                                Width="80"
                                Margin="0,5,0,5"
                                Text="用户名" />
                            <TextBox
                                Width="120"
                                Margin="0,5,0,5"
                                Text="{Binding EditingDto.Username}" />

                            <TextBlock
                                Width="40"
                                Margin="33,5,10,5"
                                Text="密码" />
                            <TextBox
                                Width="140"
                                Margin="0,5,0,5"
                                Text="{Binding EditingDto.Password}" />
                        </WrapPanel>

                        <WrapPanel Grid.Row="2" Grid.ColumnSpan="4">
                            <TextBlock
                                Width="80"
                                Margin="0,5,0,5"
                                Text="句柄" />
                            <TextBox
                                Width="70"
                                Margin="0,5,0,5"
                                Text="{Binding EditingDto.RenderHandle}" />

                            <TextBlock
                                Width="40"
                                Margin="23,5,0,5"
                                Text="通道号" />
                            <TextBox
                                Width="40"
                                Margin="10,5,0,5"
                                Text="{Binding EditingDto.ChannelIndex}" />

                            <TextBlock
                                Width="50"
                                Margin="20,0,10,0"
                                Text="码流类型" />
                            <ComboBox
                                Width="80"
                                Margin="0,5,0,5"
                                SelectedIndex="{Binding EditingDto.StreamType}">
                                <ComboBoxItem Content="主码流" />
                                <ComboBoxItem Content="子码流" />
                            </ComboBox>
                        </WrapPanel>

                    </Grid>
                </GroupBox>

                <GroupBox
                    Margin="0,0,0,15"
                    Padding="10"
                    BorderBrush="{DynamicResource Brush.Border}"
                    Foreground="{DynamicResource Brush.Text.Primary}"
                    Header="关联主板 (Metadata)">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="80" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="60" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Margin="0,5" Text="主板 IP" />
                        <TextBox
                            Grid.Column="1"
                            Margin="0,5,10,5"
                            Text="{Binding EditingDto.MainboardIp}" />

                        <TextBlock
                            Grid.Column="2"
                            Margin="0,5"
                            HorizontalAlignment="Right"
                            Text="端口 " />
                        <TextBox
                            Grid.Column="3"
                            Margin="5,5,0,5"
                            Text="{Binding EditingDto.MainboardPort}" />
                    </Grid>
                </GroupBox>

                <GroupBox
                    Margin="0,0,0,15"
                    Padding="10"
                    BorderBrush="{DynamicResource Brush.Border}"
                    Foreground="{DynamicResource Brush.Text.Primary}"
                    Header="运行参数 (Runtime)">
                    <WrapPanel>
                        <TextBlock
                            Width="30"
                            Margin="0,5,0,5"
                            Text="RTSP" />
                        <TextBox
                            Width="360"
                            Height="60"
                            Margin="20,5,0,5"
                            VerticalContentAlignment="Top"
                            Text="{Binding EditingDto.RtspPath}" />
                    </WrapPanel>
                </GroupBox>
            </StackPanel>
        </ScrollViewer>

        <StackPanel
            Grid.Row="2"
            Margin="0,10,0,0"
            HorizontalAlignment="Right"
            Orientation="Horizontal">
            <Button
                Width="100"
                Height="32"
                Margin="0,0,10,0"
                Command="{Binding SaveCommand}"
                Content="保存配置"
                Cursor="Hand">
                <Button.Style>
                    <Style TargetType="Button">
                        <Setter Property="Background" Value="{DynamicResource Brush.State.Success}" />
                        <Setter Property="Foreground" Value="White" />
                        <Setter Property="BorderThickness" Value="0" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border Background="{TemplateBinding Background}" CornerRadius="4">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="0.9" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>

            <Button
                Width="100"
                Height="32"
                Command="{Binding CancelCommand}"
                Content="取消"
                Cursor="Hand">
                <Button.Style>
                    <Style TargetType="Button">
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="Foreground" Value="{DynamicResource Brush.Text.Primary}" />
                        <Setter Property="BorderBrush" Value="{DynamicResource Brush.Border}" />
                        <Setter Property="BorderThickness" Value="1" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border
                                        Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        CornerRadius="4">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="{DynamicResource Brush.Bg.Hover}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </StackPanel>
    </Grid>
</UserControl>