@using GmRelay.Shared.Domain
@using GmRelay.Web.Services.Portfolio

<div class="portfolio-grid">
    @foreach (var game in Games)
    {
        <a class="portfolio-card" href="@($"/portfolio/{game.Slug}")">
            @if (!string.IsNullOrWhiteSpace(game.CoverPath))
            {
                <div class="portfolio-card-cover" style="background-image: url('@game.CoverPath')"></div>
            }
            else
            {
                <div class="portfolio-card-cover portfolio-card-cover-empty">
                    <span>Без обложки</span>
                </div>
            }
            <div class="portfolio-card-body">
                <h3>@game.Title</h3>
                <div class="portfolio-card-meta">
                    <span class="status-badge status-success">Завершено</span>
                    <span class="portfolio-card-date">@game.CompletedAt.ToLocalTime().FormatMoscowShort()</span>
                </div>
                @if (!string.IsNullOrWhiteSpace(game.System) || !string.IsNullOrWhiteSpace(game.Format))
                {
                    <div class="portfolio-card-badges">
                        @if (!string.IsNullOrWhiteSpace(game.System))
                        {
                            <span class="status-badge status-info">@GetSystemDisplayName(game.System)</span>
                        }
                        @if (!string.IsNullOrWhiteSpace(game.Format))
                        {
                            <span class="status-badge status-neutral">@TranslateFormat(game.Format)</span>
                        }
                    </div>
                }
            </div>
        </a>
    }
</div>

@code {
    [Parameter, EditorRequired]
    public IReadOnlyList<PublicPortfolioCard> Games { get; set; } = [];

    private static string GetSystemDisplayName(string? system)
    {
        if (string.IsNullOrWhiteSpace(system))
            return system ?? string.Empty;

        if (Enum.TryParse<GameSystem>(system, out var gs))
            return gs.ToDisplayName();

        return system;
    }

    private static string TranslateFormat(string format) => format switch
    {
        "Online" => "Онлайн",
        "Offline" => "Офлайн",
        "Hybrid" => "Гибрид",
        _ => format
    };
}
