<Window x:Class="CtrEditor.PopUps.MatrixPreviewWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Exportar Tags Extraidos" Height="600" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Matrix Preview -->
        <DataGrid x:Name="MatrixPreview" 
                  Grid.Row="0" 
                  ItemsSource="{Binding MatrixRows}"
                  AutoGenerateColumns="False"
                  CanUserReorderColumns="True"
                  CanUserAddRows="False"
                  HeadersVisibility="Column"
                  Background="White"
                  GridLinesVisibility="All"
                  Margin="5"
                  ColumnReordered="DataGrid_ColumnReordered"
                  SelectionMode="Extended"
                  SelectionUnit="Cell">
            <DataGrid.Resources>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Background" Value="LightGray"/>
                    <Setter Property="FontWeight" Value="Bold"/>
                    <Setter Property="Padding" Value="5"/>
                </Style>
            </DataGrid.Resources>
        </DataGrid>

        <!-- GridSplitter between tables -->
        <GridSplitter Grid.Row="1"
                      Height="5"
                      HorizontalAlignment="Stretch"
                      Background="LightGray"
                      ResizeDirection="Rows"/>

        <!-- Column Details -->
        <DataGrid Grid.Row="2"
                 ItemsSource="{Binding MatrixItems}"
                 AutoGenerateColumns="False"
                 CanUserAddRows="False"
                 Margin="5">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Column Number" 
                                  Binding="{Binding ColumnNumber, UpdateSourceTrigger=PropertyChanged}"
                                  Width="100"/>
                <DataGridTextColumn Header="Column Name" 
                                  Binding="{Binding ColumnName, UpdateSourceTrigger=PropertyChanged}"
                                  Width="150"/>
                <DataGridTextColumn Header="Tag Name" 
                                  Binding="{Binding TagName}"
                                  Width="150"
                                  IsReadOnly="True"/>
                <DataGridTextColumn Header="Type" 
                                  Binding="{Binding Type}"
                                  Width="100"
                                  IsReadOnly="True"/>
            </DataGrid.Columns>
        </DataGrid>

        <!-- Bottom Panel with Buttons -->
        <StackPanel Grid.Row="3" 
                    Orientation="Horizontal" 
                    HorizontalAlignment="Right" 
                    Margin="5"
                    Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
            <Button Content="Correccion de Descripcion" 
                    Command="{Binding AICorrectMatrixCommand}"
                    Margin="5"
                    Padding="10,5"/>
            <Button Content="Exportar a Excel" 
                    Command="{Binding ExportToExcelCommand}"
                    Margin="5"
                    Padding="10,5"/>
            <Button Content="Regenerar Matriz" 
                    Command="{Binding RegenerateMatrixCommand}"
                    Margin="5"
                    Padding="10,5"/>
            <Button Content="Salvar Cambios" 
                    Command="{Binding ApplyChangesCommand}" 
                    Margin="5" 
                    Padding="10,5"/>
            <Button Content="Cerrar" 
                    Command="{Binding CloseCommand}" 
                    Margin="5" 
                    Padding="10,5"/>
        </StackPanel>
    </Grid>
</Window>
