@page "/references/magic-materials"
@using AOW4.Data

<div class="page-container">
    <h1>Magic Materials Reference</h1>
    <p class="subtitle">A reference view of the `MagicMaterial` data loaded from `MagicMaterialsData.RawData`.</p>

    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Category</th>
                    <th>Annex Resources</th>
                    <th>Global Bonus</th>
                    <th>Infusion 1</th>
                    <th>Infusion 2</th>
                    <th>Infusion 3</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var material in MagicMaterialsData.RawData)
                {
                    <tr>
                        <td>@material.Name</td>
                        <td>@material.Category</td>
                        <td>@FormatAnnexResources(material)</td>
                        <td>@material.GlobalBonus</td>
                        <td><div class="preformatted">@material.InfusionEffects1</div></td>
                        <td><div class="preformatted">@material.InfusionEffects2</div></td>
                        <td><div class="preformatted">@material.InfusionEffects3</div></td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>

@code {
    private static string FormatAnnexResources(MagicMaterial material)
    {
        var parts = new List<string>();

        void Add(string label, int? value)
        {
            if (value.HasValue)
            {
                parts.Add(value.Value < 0 ? $"{value.Value}% {label}" : $"+{value.Value} {label}");
            }
        }

        Add("Production", material.IncreaseProduction);
        Add("Gold", material.IncreaseGold);
        Add("Mana", material.IncreaseMana);
        Add("Draft", material.IncreaseDraft);
        Add("Knowledge", material.IncreaseKnowledge);
        Add("Food", material.IncreaseFood);
        Add("Stability", material.IncreaseStability);
        Add("Imperium", material.IncreaseImperium);
        Add("Allegiance from Whispering Stones", material.IncreaseAllegianceFromWhisperingStones);
        Add("Relations with Free Cities and Rulers", material.IncreaseRelationWithFreeCitiesAndRulers);
        Add("Combat Casting Points", material.IncreaseCombatCastingPoints);
        Add("World Map Casting Points", material.IncreaseWorldCastingPoints);
        Add("HP Regeneration", material.IncreaseHPRegen);
        Add("Hit Points", material.IncreaseHitPoints);
        Add("Experience Percent", material.IncreaseExperiencePercent);
        Add("Allegiance from Umbral Dwellings", material.IncreaseAllegianceFromUmbralDwellings);
        Add("Draft Cost Reduction", material.DecreaseDraftCostPercent);
        Add("Recruitment Cost Reduction", material.DecreaseRecruitmentCostPercent);
        Add("Knowledge Research Cost Reduction", material.DecreaseKnowledgeResearchCostPercent);
        Add("Turn Reduction to Found/Absorb/Migrate", material.DecreaseTurnsTakenToFoundAbsorbMigrateCities);

        return parts.Count > 0 ? string.Join("; ", parts) : "—";
    }
}

<style>
    .page-container {
        padding: 2rem;
        max-width: 1200px;
        margin: 0 auto;
    }

    .subtitle {
        color: #666;
        margin-bottom: 1.5rem;
    }

    .table-responsive {
        overflow-x: auto;
    }

    .preformatted {
        white-space: pre-wrap;
        font-family: var(--bs-font-sans-serif);
        color: #333;
    }
</style>
