<UserControl x:Class="CtrEditor.ObjetosSim.HydraulicComponents.ucHydDischargeTank"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.HydraulicComponents"
             mc:Ignorable="d">

    <UserControl.DataContext>
        <vm:osHydDischargeTank Ancho="0.5" Alto="0.8"/>
    </UserControl.DataContext>

    <Canvas RenderTransformOrigin="0,0">
        <Canvas.RenderTransform>
            <TransformGroup>
                <ScaleTransform />
                <SkewTransform />
                <RotateTransform Angle="{Binding Angulo}" />
                <TranslateTransform />
            </TransformGroup>
        </Canvas.RenderTransform>

        <!-- Cuerpo del tanque -->
        <Rectangle x:Name="rectTank" 
                   Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}"
                   Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
                   Fill="{Binding ColorButton_oculto}" 
                   Stroke="Black" 
                   StrokeThickness="2"
                   RadiusX="5" 
                   RadiusY="5"/>
        
        <!-- Nivel del líquido con altura proporcional al nivel -->
        <Rectangle x:Name="rectLevel" 
                   Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=6}"
                   Canvas.Left="3"
                   Canvas.Bottom="3">
            <Rectangle.Height>
                <MultiBinding Converter="{StaticResource LevelToHeightMultiConverter}">
                    <Binding Path="FillPercentage" />
                    <Binding Path="Alto" Converter="{StaticResource MeterToPixelConverter}" />
                </MultiBinding>
            </Rectangle.Height>
            <Rectangle.Fill>Blue</Rectangle.Fill>
            <Rectangle.Opacity>0.6</Rectangle.Opacity>
        </Rectangle>
        
        <!-- Etiqueta con Viewbox para escalado -->
        <Viewbox Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}"
                 Height="20" 
                 Stretch="Uniform"
                 Canvas.Top="2">
            <Label Content="{Binding Nombre}" 
                   VerticalAlignment="Center" 
                   HorizontalAlignment="Center" 
                   FontWeight="Bold"
                   FontSize="14" 
                   Opacity="0.9" 
                   Foreground="White"/>
        </Viewbox>
        
        <!-- Indicador de conexión entrada -->
        <Ellipse x:Name="ConnectionIn" 
                 Fill="Green" 
                 Width="8" 
                 Height="8" 
                 Canvas.Left="-4" 
                 Canvas.Bottom="10"/>
        
        <!-- Indicador de nivel en porcentaje -->
        <Border x:Name="LevelIndicator" 
                Background="White" 
                BorderBrush="Black"
                BorderThickness="1"
                CornerRadius="2" 
                Canvas.Right="2" 
                Canvas.Top="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=0.5}">
            <TextBlock x:Name="LevelText" 
                       Text="{Binding FillPercentage, StringFormat='{}{0:F0}%'}" 
                       FontSize="6" 
                       Foreground="Black" 
                       Margin="2"/>
        </Border>
        
        <!-- Indicador de volumen -->
        <Border x:Name="VolumeIndicator" 
                Background="Yellow" 
                CornerRadius="2" 
                Visibility="Collapsed"
                Canvas.Bottom="2"
                Canvas.Left="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=0.5}">
            <TextBlock x:Name="VolumeText" 
                       Text="{Binding CurrentVolume, StringFormat='{}{0:F1}m³'}" 
                       FontSize="5" 
                       Foreground="Black" 
                       Margin="1"/>
        </Border>
        
    </Canvas>
</UserControl>
