<Window x:Class="RevitEstimate.ElectricalModule.ElectricalEstimateWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Advanced MEP Electrical Fittings Estimation &amp; BIM Module" Height="800" Width="1300" WindowStartupLocation="CenterScreen">
    <Grid Margin="10">
        <TabControl x:Name="MainTabControl">
            <!-- TAB 1: HEIGHTS & FIXTURES SETUP -->
            <TabItem Header="1. Electrical Heights &amp; Fixtures Setup">
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Orientation="Horizontal" Margin="0,0,0,15">
                        <TextBlock Text="Main Electrical Panel / DB Source Level: " FontWeight="Bold" VerticalAlignment="Center"/>
                        <ComboBox x:Name="CmbPanelLevel" Width="220" DisplayMemberPath="Name" Margin="10,0,0,0"/>
                    </StackPanel>

                    <TextBlock Grid.Row="1" Text="Standard Electrical Fixture Heights from Finished Floor Level (FFL):" FontWeight="Bold" Margin="0,0,0,5"/>

                    <DataGrid x:Name="GridElectricalHeights" Grid.Row="2" AutoGenerateColumns="False" CanUserAddRows="False" AlternatingRowBackground="#FFF5F5F5">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Fixture / Switch Category" Binding="{Binding FixtureName}" Width="280" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Height from FFL (mm)" Binding="{Binding HeightFromFFL_MM, StringFormat=N0}" Width="160"/>
                            <DataGridTextColumn Header="Standard Placement Purpose &amp; Guidelines" Binding="{Binding Description}" Width="500" IsReadOnly="True">
                                <DataGridTextColumn.ElementStyle>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="TextWrapping" Value="Wrap"/>
                                    </Style>
                                </DataGridTextColumn.ElementStyle>
                            </DataGridTextColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>

            <!-- TAB 2: ROOM-WISE ELECTRICAL MATRIX -->
            <TabItem Header="2. Room-wise Electrical Points Matrix">
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="Rooms grouped by Flats. Electrical points (Lights, Fans, Switches, Sockets, DB) auto-assigned based on room type:" FontWeight="Bold" Margin="0,0,0,10"/>

                    <DataGrid x:Name="GridRoomElectricalMatrix" Grid.Row="1" AutoGenerateColumns="False" CanUserAddRows="False" AlternatingRowBackground="#FFF5F5F5">
                        <DataGrid.GroupStyle>
                            <GroupStyle>
                                <GroupStyle.HeaderTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Margin="5,10,5,5">
                                            <CheckBox Content="{Binding Name}" FontWeight="Bold" FontSize="13" Foreground="#FF003366" 
                                                      IsChecked="{Binding Items[0].IsFlatEnabled, Mode=OneWay}" 
                                                      Click="FlatToggle_Click" VerticalAlignment="Center"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </GroupStyle.HeaderTemplate>
                            </GroupStyle>
                        </DataGrid.GroupStyle>
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Room Tag &amp; Name" Binding="{Binding RoomTag}" Width="180" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Zone Type" Binding="{Binding ZoneType}" Width="110" IsReadOnly="True"/>
                            <DataGridCheckBoxColumn Header="Active" Binding="{Binding IsRoomActive, UpdateSourceTrigger=PropertyChanged}" Width="70"/>
                            <DataGridTextColumn Header="Light Points" Binding="{Binding LightPointQty}" Width="80"/>
                            <DataGridTextColumn Header="Ceiling Fan" Binding="{Binding CeilingFanQty}" Width="80"/>
                            <DataGridTextColumn Header="Wall Fan" Binding="{Binding WallFanQty}" Width="75"/>
                            <DataGridTextColumn Header="Light/Fan SW" Binding="{Binding LightFanSwitchBoardQty}" Width="95"/>
                            <DataGridTextColumn Header="Bedside SW" Binding="{Binding BedsideSwitchBoardQty}" Width="90"/>
                            <DataGridTextColumn Header="5-Pin Socket" Binding="{Binding General5PinSocketQty}" Width="90"/>
                            <DataGridTextColumn Header="Kitchen Socket" Binding="{Binding KitchenCounterSocketQty}" Width="95"/>
                            <DataGridTextColumn Header="Heavy Power" Binding="{Binding HeavyPowerSocketQty}" Width="90"/>
                            <DataGridTextColumn Header="DB Box" Binding="{Binding DbBoxQty}" Width="70"/>
                        </DataGrid.Columns>
                    </DataGrid>

                    <Button Grid.Row="2" Content="Calculate Electrical Circuits &amp; DSR Estimate ->" Height="45" Background="#FF007ACC" Foreground="White" FontWeight="Bold" Margin="0,15,0,0" Click="BtnGenerateElectricalEstimate_Click"/>
                </Grid>
            </TabItem>

            <!-- TAB 3: ACTUAL SYSTEM QUANTITIES (NEW) -->
            <TabItem Header="3. Actual System Quantities (From Model)">
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <Button x:Name="BtnCalculateActual" Content="Calculate Actual Model Quantities" Width="250" Height="30" HorizontalAlignment="Left" Margin="0,0,0,10" Click="BtnCalculateActual_Click"/>

                    <DataGrid x:Name="GridActualQuantities" Grid.Row="1" AutoGenerateColumns="False" CanUserAddRows="False" HeadersVisibility="Column" AlternatingRowBackground="#FFF5F5F5">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Revit Category" Binding="{Binding Category}" Width="180" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Family &amp; Type Name" Binding="{Binding FamilyAndType}" Width="350" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Count (Nos)" Binding="{Binding Count}" Width="100" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Total Length (M)" Binding="{Binding TotalLengthMeter, StringFormat=\{0:F2\}}" Width="120" IsReadOnly="True"/>
                            <DataGridTextColumn Header="Unit" Binding="{Binding Unit}" Width="80" IsReadOnly="True"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</Window>