
<div class="org-level" id="level-@Level">
    @foreach (var node in Nodes)
    {
        <div class="org-node child-node" data-parent-id="@node.Id">
            <div class="node-connector"></div>
            <div class="node-card">
                <div class="node-avatar">
                    @if (!string.IsNullOrWhiteSpace(node.Avatar))
                    {
                        <MudAvatar Size="@GetAvatarSize(Level)">
                            <AppImage Path="@node.Avatar"
                                      ObjectFit="ObjectFit.Cover"
                                      ObjectPosition="ObjectPosition.Center" />
                        </MudAvatar>
                    }
                    else
                    {
                        <MudAvatar Size="@GetAvatarSize(Level)"
                            Color="Color.Primary"
                            Variant="Variant.Outlined">
                            @(string.IsNullOrWhiteSpace(node.FirstName) ? "N" : node.FirstName.Substring(0, 1))
                        </MudAvatar>
                    }
                    @if (node.Children?.Any() == true)
                    {
                        <button class="expand-btn" @onclick="() => ToggleNodeExpand(node.Id)" data-user-id="@node.Id">
                            <MudIcon Icon="@(node.IsExpanded ? Icons.Material.Filled.Remove : Icons.Material.Filled.Add)" Size="Size.Small" />
                        </button>
                    }
                </div>
                <div class="node-info">
                    @if (!string.IsNullOrWhiteSpace(node.FirstName) || !string.IsNullOrWhiteSpace(node.LastName))
                    {
                        <div class="node-name">@node.FirstName @node.LastName</div>
                    }
                    else
                    {
                        <div class="node-name">@node.Mobile</div>
                    }
                    @if (!string.IsNullOrWhiteSpace(node.ReferralCode))
                    {
                        <div class="node-referral">
                            <span class="referral-code">@node.ReferralCode</span>
                            <MudIconButton Icon="@Icons.Material.Filled.ContentCopy"
                                           Size="Size.Small"
                                           Class="referral-icon"
                                           OnClick="@(() => CopyReferralCode(node.ReferralCode!))" />
                            <MudIconButton Icon="@Icons.Material.Filled.Share"
                                           Size="Size.Small"
                                           Class="referral-icon"
                                           OnClick="@(() => ShareReferralCode(node.ReferralCode!))" />
                        </div>
                    }
                    @* <div class="node-amounts">
                        <div class="personal-amount">
                            <span class="label">خرید شخصی:</span>
                            <span class="amount">@(node.PersonalPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
                        </div>
                        <div class="team-amount">
                            <span class="label">خرید تیمی:</span>
                            <span class="amount">@(node.TeamPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
                        </div>
                    </div> *@
                </div>
            </div>

            @if (node.IsExpanded && node.Children?.Any() == true)
            {
                <OrganizationChartLevel Nodes="node.Children" Level="@(Level + 1)" />
            }
        </div>
    }
</div>

