<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:LindtLeerformPlugin.ViewModels"
        x:Class="LindtLeerformPlugin.Views.CalibrationWindow"
        x:DataType="vm:CalibrationWindowViewModel"
        Title="Leerform Calibration"
        Width="1024" Height="800">

    <DockPanel>
        <!-- Toolbar -->
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="8" Margin="8">
            <Button Content="Start Preview" Command="{Binding StartPreviewCommand}" IsEnabled="{Binding !IsPreviewRunning}" />
            <Button Content="Stop Preview" Command="{Binding StopPreviewCommand}" IsEnabled="{Binding IsPreviewRunning}" />
            <Button Content="Capture Image" Command="{Binding CaptureImageCommand}" />
        </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="Captured: {0}">
                            <Binding Path="CapturedImageCount" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
            </StackPanel>
        </Border>

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

                    <TextBlock Text="Image Directory" Foreground="LightGray" />
                    <TextBox Text="{Binding CalibrationImageDirectory}" />

                    <Separator Margin="0,8" />

                    <Button Content="Calibrate" Command="{Binding RunCalibrationCommand}" Margin="0,4"
                            Background="#00C853" Foreground="White" FontWeight="Bold" />
                    <Button Content="Clear Images" Command="{Binding ClearCalibrationImagesCommand}" Margin="0,4"
                            Background="#FF6D00" Foreground="White" FontWeight="Bold" />

                    <Separator Margin="0,8" />

                    <TextBlock Text="Calibrated" Foreground="LimeGreen" IsVisible="{Binding IsCalibrated}" />
                    <TextBlock Foreground="LightGray" IsVisible="{Binding IsCalibrated}">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="RMS Error: {0:F4}">
                                <Binding Path="RmsError" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </StackPanel>
            </ScrollViewer>
        </Border>

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

</Window>
