@using System.Collections.Generic
@using RolemasterDb.App.Features

<div class="critical-cell">
    @if (!string.IsNullOrWhiteSpace(Description))
    {
        <p class="critical-cell-description">@Description</p>
    }

    @if ((Effects?.Count ?? 0) > 0 || (Branches?.Count ?? 0) > 0)
    {
        <div class="critical-cell-footer">
            <AffixBadgeList Effects="Effects" />

            @if (Branches?.Count > 0)
            {
                <div class="critical-branch-stack">
                    @foreach (var branch in Branches)
                    {
                        <div class="critical-branch-card">
                            <div class="critical-branch-header">
                                <span class="critical-branch-condition">
                                    @branch.ConditionText
                                </span>
                                <AffixBadgeList Effects="branch.Effects" />
                            </div>
                            @if (!string.IsNullOrWhiteSpace(branch.Description))
                            {
                                <p class="critical-branch-description">@branch.Description</p>
                            }
                        </div>
                    }
                </div>
            }
        </div>
    }
</div>

@code {
    [Parameter, EditorRequired]
    public string Description { get; set; } = string.Empty;

    [Parameter]
    public IReadOnlyList<CriticalEffectLookupResponse>? Effects { get; set; }

    [Parameter]
    public IReadOnlyList<CriticalBranchLookupResponse>? Branches { get; set; }
}
