@using PlanTempus.Application.Features.Accounts.Models
@using PlanTempus.Application.Features.Localization.Services
@model IEnumerable<PlanInfo>

@{
    var currentPlanKey = (string)ViewBag.CurrentPlanKey;
    var L = (ILocalizationService)ViewBag.Localization;
}

<swp-plan-grid>
    @foreach (var plan in Model)
    {
        var isCurrent = plan.Key == currentPlanKey;
        var cardClass = plan.Key switch
        {
            "enterprise" => isCurrent ? "enterprise current" : "enterprise",
            _ => isCurrent ? "current" : ""
        };

        var badgeClass = isCurrent ? "current" : plan.BadgeClass;
        var badgeText = isCurrent ? L.Get("account.subscription.currentPlan") : plan.BadgeText;
        var badgeIcon = isCurrent ? "ph-check" : plan.BadgeIcon;

        var buttonText = isCurrent
            ? L.Get("account.subscription.currentPlan")
            : plan.IsContactSales
                ? L.Get("account.subscription.contactSales")
                : L.Get("account.subscription.switchTo").Replace("{plan}", plan.Name);

        var buttonClass = isCurrent
            ? "secondary"
            : plan.IsContactSales
                ? "outline"
                : "secondary";

        <swp-plan-card class="@cardClass">
            <swp-plan-badge class="@badgeClass">
                <i class="ph @badgeIcon"></i>
                @badgeText
            </swp-plan-badge>
            <swp-plan-name>@plan.Name</swp-plan-name>
            <swp-plan-users>@plan.UserRange</swp-plan-users>
            <swp-plan-price>
                @if (plan.PricePerMonth.HasValue)
                {
                    <swp-plan-price-amount>@plan.PriceDisplay</swp-plan-price-amount>
                    <swp-plan-price-period localize="account.subscription.pricePerMonth">kr/md</swp-plan-price-period>
                }
                else
                {
                    <swp-plan-price-amount localize="account.subscription.contactUs">Kontakt os</swp-plan-price-amount>
                }
            </swp-plan-price>
            <swp-plan-features>
                @foreach (var feature in plan.Features)
                {
                    <swp-plan-feature>
                        <i class="ph ph-check-circle"></i>
                        @feature
                    </swp-plan-feature>
                }
            </swp-plan-features>
            <swp-plan-action>
                <swp-btn class="@buttonClass">@buttonText</swp-btn>
            </swp-plan-action>
        </swp-plan-card>
    }
</swp-plan-grid>
