@using ZahlenAnalyse.Web.Models

<div class="pl-6 mt-2 border-l-2" style="border-color: var(--mud-palette-primary);">
    <MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2">
        <MudTextField @bind-Value="Node.Name" 
                      Placeholder="z.B. Italien oder Maut" 
                      Variant="Variant.Outlined" 
                      Margin="Margin.Dense" />
        
        <MudTooltip Text="Unterkategorie hinzufügen">
            <MudIconButton Icon="@Icons.Material.Filled.SubdirectoryArrowRight" 
                           Size="Size.Small" 
                           Color="Color.Info" 
                           OnClick="AddChild" />
        </MudTooltip>

        <MudTooltip Text="Knoten löschen">
            <MudIconButton Icon="@Icons.Material.Filled.Delete" 
                           Size="Size.Small" 
                           Color="Color.Error" 
                           OnClick="() => OnRemove.InvokeAsync(Node)" />
        </MudTooltip>
    </MudStack>

    @foreach (var child in Node.Children.ToList())
    {
        <NodeEditor Node="child" OnRemove="RemoveChild" />
    }
</div>

@code {
    [Parameter] public DimensionNode Node { get; set; } = default!;
    [Parameter] public EventCallback<DimensionNode> OnRemove { get; set; }

    private void AddChild()
    {
        Node.Children.Add(new DimensionNode());
    }

    private void RemoveChild(DimensionNode child)
    {
        Node.Children.Remove(child);
    }
}