@extends('layouts.front')

@section('content')
@php
    $totalPlayedAmount = (float) $gameplayhistory->sum('playedamount');
    $uniqueContests = $gameplayhistory->pluck('contestname')->filter()->unique()->count();
    $latestGame = $gameplayhistory->first();
@endphp
<div class="jel-portal-page">
    <section class="jel-history-layout">
        <div class="jel-history-intro">
            <span class="jel-portal-kicker">Student Activity</span>
            <h1>Your exam participation history.</h1>
            <p>Har joined competition ka quick log yahan milega, jisse aap dekh sakte hain kis exam mein kab aur kitni amount ke sath participate kiya tha.</p>

            <div class="jel-result-summary-grid jel-history-summary-grid">
                <article>
                    <span>Total Entries</span>
                    <strong>{{ $gameplayhistory->count() }}</strong>
                </article>
                <article>
                    <span>Total Participation</span>
                    <strong>&#8377;{{ number_format($totalPlayedAmount, 2) }}</strong>
                </article>
                <article>
                    <span>Contest Types</span>
                    <strong>{{ $uniqueContests }}</strong>
                </article>
                <article>
                    <span>Latest Attempt</span>
                    <strong>{{ $latestGame ? optional($latestGame->createtime)->format('d M Y') : 'No activity' }}</strong>
                </article>
            </div>

            <div class="jel-inline-actions">
                <a class="jel-portal-button jel-portal-button-muted" href="{{ route('competitionlist') }}">Competition Dashboard</a>
                <a class="jel-portal-button jel-portal-button-secondary" href="{{ route('scoringresult') }}">Scoring Results</a>
            </div>
        </div>

        @include('front.partials.history-tabs')
    </section>

    <section class="jel-history-card">
        <div class="jel-history-card-head">
            <div>
                <span class="jel-portal-kicker">Game History</span>
                <h2>Game Play Details</h2>
            </div>
            <span class="jel-history-count">{{ $gameplayhistory->count() }} Entries</span>
        </div>

        <div class="jel-history-list">
            @forelse ($gameplayhistory as $gameplayhistorydata)
                <article class="jel-history-item">
                    <div class="jel-history-item-main">
                        <h3>{{ $gameplayhistorydata->assignquestionname }}</h3>
                        <p>{{ $gameplayhistorydata->contestname }} contest mein participation recorded hai.</p>
                    </div>
                    <div class="jel-history-item-side">
                        <strong>&#8377;{{ number_format((float) $gameplayhistorydata->playedamount, 2) }}</strong>
                        <span>{{ optional($gameplayhistorydata->createtime)->format('d M Y, h:i A') }}</span>
                    </div>
                </article>
            @empty
                <div class="jel-empty-state">
                    <h3>No game history found yet.</h3>
                    <p>Jab aap kisi competition mein join karenge, uski entry yahan show hogi.</p>
                </div>
            @endforelse
        </div>
    </section>
</div>
@endsection
