<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:VisionBuilder.UI.RaspberryAcquisition.ViewModels"
        x:Class="VisionBuilder.UI.RaspberryAcquisition.Views.MainWindow"
        x:DataType="vm:MainWindowViewModel"
        Title="RPi Image Acquisition"
        Width="1024" Height="800">

    <DockPanel>
        <!-- Toolbar -->
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="8" Margin="8">
            <Button Content="Start" Command="{Binding StartCaptureCommand}" IsEnabled="{Binding !IsRunning}" />
            <Button Content="Stop" Command="{Binding StopCaptureCommand}" IsEnabled="{Binding IsRunning}" />
            <Button Content="Save Image" Command="{Binding SaveImageCommand}" />
            <Button Content="Apply Settings" Command="{Binding ApplySettingsCommand}" IsEnabled="{Binding IsRunning}" />
        </StackPanel>

        <!-- Status Bar -->
        <Border DockPanel.Dock="Bottom" Background="#1E1E1E" Padding="8,4">
            <StackPanel Orientation="Horizontal" Spacing="16">
                <TextBlock Text="{Binding StatusText}" Foreground="LightGray" />
                <TextBlock Foreground="LightGray">
                    <TextBlock.Text>
                        <MultiBinding StringFormat="Frames: {0}">
                            <Binding Path="FrameCount" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
            </StackPanel>
        </Border>

        <!-- Settings Panel -->
        <Border DockPanel.Dock="Right" Width="220" Padding="12" Background="#2D2D2D">
            <ScrollViewer>
                <StackPanel Spacing="8">
                    <TextBlock Text="Camera Settings" FontWeight="Bold" FontSize="14" Foreground="White" />

                    <TextBlock Text="Width" Foreground="LightGray" />
                    <TextBox Text="{Binding Width}" />

                    <TextBlock Text="Height" Foreground="LightGray" />
                    <TextBox Text="{Binding Height}" />

                    <TextBlock Text="Shutter (µs)" Foreground="LightGray" />
                    <TextBox Text="{Binding ShutterSpeed}" />

                    <TextBlock Text="Framerate" Foreground="LightGray" />
                    <TextBox Text="{Binding Framerate}" />

                    <TextBlock Text="AWB Gain Red" Foreground="LightGray" />
                    <TextBox Text="{Binding AwbGainRed}" />

                    <TextBlock Text="AWB Gain Blue" Foreground="LightGray" />
                    <TextBox Text="{Binding AwbGainBlue}" />

                    <Separator Margin="0,8" />

                    <TextBlock Text="Save Directory" Foreground="LightGray" />
                    <TextBox Text="{Binding SaveDirectory}" />

                    <Separator Margin="0,8" />

                    <TextBlock Text="Calibration" FontWeight="Bold" FontSize="14" Foreground="White" />
                    <TextBlock Text="Calibration Dir" Foreground="LightGray" />
                    <TextBox Text="{Binding CalibrationDirectory}" />
                    <Button Content="Calibrate" Command="{Binding CalibrateCameraCommand}" Margin="0,4" />
                    <TextBlock Text="Calibrated" Foreground="LimeGreen" IsVisible="{Binding IsCalibrated}" />
                </StackPanel>
            </ScrollViewer>
        </Border>

        <!-- Live Preview -->
        <Border Background="#1A1A1A" Margin="4">
            <Image Source="{Binding PreviewImage}" Stretch="Uniform" />
        </Border>
    </DockPanel>

</Window>
