{% extends '__layout__.html' %}
{% block title %}Games{% endblock %}
{% block head %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<style>
.place-card { height:220px !important; aspect-ratio:0.640909/1; }
.place-card-container { display:flex; flex-wrap:wrap; justify-content:flex-start; gap:0; }
</style>
{% endblock %}
{% block content %}
<div class="w-100 ps-4 pe-4" style="padding-top:24px;min-height:100vh;max-width:1950px;margin:0 auto;">
    {% if GameLookupResults %}
        <form method="get" style="min-width:250px;max-width:500px;margin-bottom:12px;">
            <div class="d-flex" style="gap:6px;">
                <input type="text" class="form-control" name="q" value="{% if SearchQuery != None %}{{SearchQuery}}{% endif %}" placeholder="Search games...">
                <button type="submit" class="btn btn-secondary fw-bold" style="min-width:44px;"><i class="bi bi-search"></i></button>
            </div>
        </form>
        <div class="p-2 w-100 place-card-container">
            {% for place in GameLookupResults: %}
            <a class="text-decoration-none p-1" href="/games/{{place.id}}/{{place.slug}}">
                <div class="overflow-hidden place-card w-100">
                    <div class="position-relative">
                        <img width="100%" style="aspect-ratio:1/1;" src="/Thumbs/PlaceIcon.ashx?assetId={{place.id}}&x=150&y=150" alt="{{place.name}}">
                        <div class="position-absolute" style="bottom:0;left:0;">
                            <div class="fw-bold text-white" style="font-size:12px;padding:3px;border-top-right-radius:4px;background:rgba(0,0,0,0.55);">{{place.placeyear.value}}</div>
                        </div>
                    </div>
                    <div class="p-1">
                        <h5 class="mb-0" style="font-size:17px;text-overflow:ellipsis;">{{place.name}}</h5>
                        <div class="d-flex align-items-center">
                            <p style="margin:0;font-size:14px;" class="text-secondary"><i class="bi bi-people"></i> {{place.playingcount}} <span style="font-size:13px;">Playing</span></p>
                        </div>
                        <div class="w-100 votePercentageBackground">
                            <div class="votePercentageFill" style="width:{{place.likePercentage}}%;"></div>
                            <div><div class="segment" style="left:18%;"></div><div class="segment" style="left:38%;"></div><div class="segment" style="left:58%;"></div><div class="segment" style="left:78%;"></div></div>
                        </div>
                    </div>
                </div>
            </a>
            {%endfor%}
        </div>
        <div class="d-flex align-items-center mt-2">
            {% if GameLookupResultsBackendResult.has_prev: %}
            <a href="/games?q={{SearchQuery}}&page={{GameLookupResultsBackendResult.prev_num}}" class="ms-auto text-decoration-none">Previous</a>
            {%else%}
            <span class="ms-auto text-secondary">Previous</span>
            {% endif %}
            <p class="ms-3 me-3 m-0">Page {{GameLookupResultsBackendResult.page}} of {{GameLookupResultsBackendResult.pages}}</p>
            {% if GameLookupResultsBackendResult.has_next: %}
            <a href="/games?q={{SearchQuery}}&page={{GameLookupResultsBackendResult.next_num}}" class="me-auto text-decoration-none">Next</a>
            {%else%}
            <span class="me-auto text-secondary">Next</span>
            {% endif %}
        </div>
    {% elif not GameLookupResults and SearchQuery %}
        <form method="get" style="min-width:250px;max-width:500px;margin-bottom:12px;">
            <div class="d-flex" style="gap:6px;">
                <input type="text" class="form-control" name="q" value="{{SearchQuery}}" placeholder="Search games...">
                <button type="submit" class="btn btn-secondary fw-bold" style="min-width:44px;"><i class="bi bi-search"></i></button>
            </div>
        </form>
        <div class="w-100 p-2">
            <p>No results found for "{{SearchQuery}}"</p>
        </div>
    {% else %}
        <div class="d-flex align-items-center" style="flex-wrap:wrap;gap:12px;margin-bottom:8px;">
            <div class="d-flex align-items-center">
                <h1 style="margin:0;">Popular</h1>
                <a class="ms-3 text-decoration-none" href="/games/popular/view">View All</a>
            </div>
            <form method="get" class="ms-auto" style="min-width:300px;">
                <div class="d-flex" style="gap:6px;">
                    <input type="text" class="form-control" name="q" value="{% if SearchQuery != None %}{{SearchQuery}}{% endif %}" placeholder="Search games...">
                    <button type="submit" class="btn btn-secondary fw-bold" style="min-width:44px;"><i class="bi bi-search"></i></button>
                </div>
            </form>
        </div>
        <div class="p-2 w-100 place-card-container">
            {% for place in PopularPlaces: %}
            <a class="text-decoration-none p-1" href="/games/{{place.id}}/{{place.slug}}">
                <div class="overflow-hidden place-card w-100">
                    <div class="position-relative">
                        <img width="100%" style="aspect-ratio:1/1;" src="/Thumbs/PlaceIcon.ashx?assetId={{place.id}}&x=150&y=150" alt="{{place.name}}">
                        <div class="position-absolute" style="bottom:0;left:0;">
                            <div class="fw-bold text-white" style="font-size:12px;padding:3px;border-top-right-radius:4px;background:rgba(0,0,0,0.55);">{{place.placeyear.value}}</div>
                        </div>
                    </div>
                    <div class="p-1">
                        <h5 class="mb-0" style="font-size:17px;text-overflow:ellipsis;">{{place.name}}</h5>
                        <div class="d-flex align-items-center">
                            <p style="margin:0;font-size:14px;" class="text-secondary"><i class="bi bi-people"></i> {{place.playingcount}} <span style="font-size:13px;">Playing</span></p>
                        </div>
                        <div class="w-100 votePercentageBackground">
                            <div class="votePercentageFill" style="width:{{place.likePercentage}}%;"></div>
                            <div><div class="segment" style="left:18%;"></div><div class="segment" style="left:38%;"></div><div class="segment" style="left:58%;"></div><div class="segment" style="left:78%;"></div></div>
                        </div>
                    </div>
                </div>
            </a>
            {%endfor%}
        </div>
        <div class="d-flex align-items-center mt-3">
            <h1 style="margin:0;">Featured</h1>
            <a class="ms-3 text-decoration-none" href="/games/featured/view">View All</a>
        </div>
        <div class="p-2 w-100 place-card-container">
            {% for place in FeaturedPlacesInfo: %}
            <a class="text-decoration-none p-1" href="/games/{{place.id}}/{{place.slug}}">
                <div class="overflow-hidden place-card w-100">
                    <div class="position-relative">
                        <img width="100%" style="aspect-ratio:1/1;" src="/Thumbs/PlaceIcon.ashx?assetId={{place.id}}&x=150&y=150" alt="{{place.name}}">
                        <div class="position-absolute" style="bottom:0;left:0;">
                            <div class="fw-bold text-white" style="font-size:12px;padding:3px;border-top-right-radius:4px;background:rgba(0,0,0,0.55);">{{place.placeyear.value}}</div>
                        </div>
                    </div>
                    <div class="p-1">
                        <h5 class="mb-0" style="font-size:17px;text-overflow:ellipsis;">{{place.name}}</h5>
                        <div class="d-flex align-items-center">
                            <p style="margin:0;font-size:14px;" class="text-secondary"><i class="bi bi-people"></i> {{place.playingcount}} <span style="font-size:13px;">Playing</span></p>
                        </div>
                        <div class="w-100 votePercentageBackground">
                            <div class="votePercentageFill" style="width:{{place.likePercentage}}%;"></div>
                            <div><div class="segment" style="left:18%;"></div><div class="segment" style="left:38%;"></div><div class="segment" style="left:58%;"></div><div class="segment" style="left:78%;"></div></div>
                        </div>
                    </div>
                </div>
            </a>
            {%endfor%}
        </div>
        <div class="d-flex align-items-center mt-3">
            <h1 style="margin:0;">Recently Updated</h1>
            <a class="ms-3 text-decoration-none" href="/games/updated/view">View All</a>
        </div>
        <div class="p-2 w-100 place-card-container">
            {% for place in RecentlyUpdatedPlaces: %}
            <a class="text-decoration-none p-1" href="/games/{{place.id}}/{{place.slug}}">
                <div class="overflow-hidden place-card w-100">
                    <div class="position-relative">
                        <img width="100%" style="aspect-ratio:1/1;" src="/Thumbs/PlaceIcon.ashx?assetId={{place.id}}&x=150&y=150" alt="{{place.name}}">
                        <div class="position-absolute" style="bottom:0;left:0;">
                            <div class="fw-bold text-white" style="font-size:12px;padding:3px;border-top-right-radius:4px;background:rgba(0,0,0,0.55);">{{place.placeyear.value}}</div>
                        </div>
                    </div>
                    <div class="p-1">
                        <h5 class="mb-0" style="font-size:17px;text-overflow:ellipsis;">{{place.name}}</h5>
                        <div class="d-flex align-items-center">
                            <p style="margin:0;font-size:14px;" class="text-secondary"><i class="bi bi-people"></i> {{place.playingcount}} <span style="font-size:13px;">Playing</span></p>
                        </div>
                        <div class="w-100 votePercentageBackground">
                            <div class="votePercentageFill" style="width:{{place.likePercentage}}%;"></div>
                            <div><div class="segment" style="left:18%;"></div><div class="segment" style="left:38%;"></div><div class="segment" style="left:58%;"></div><div class="segment" style="left:78%;"></div></div>
                        </div>
                    </div>
                </div>
            </a>
            {%endfor%}
        </div>
    {% endif %}
</div>
{% endblock %}