@php
use App\Models\Game;
use App\Models\GameList;
use App\Models\Platform;

// Construct the title of the main card and counts of games in certain statuses.
if (Auth::check() && auth()->user()->username == $user->username) {
    $cardTitle = 'My List';

    // Fetch the users games in 'playing' status and a count of them.
    $playingGames = GameList::where('user_id', Auth::id())->where('status', 1)->get();
    $playingCount = count($playingGames);

    // Fetch the users games in 'replaying' status and a count of them.
    $replayingGames = GameList::where('user_id', Auth::id())->where('status', 3)->where('is_replaying', 'Y')->get();
    $replayingCount = count($replayingGames);

    // Fetch the users games in 'continuously playing' status and a count of them.
    $continuouslyPlayingGames = GameList::where('user_id', Auth::id())->where('status', 2)->get();
    $continuouslyPlayingCount = count($continuouslyPlayingGames);

    // Fetch the users games in 'completed' status and a count of them.
    $completedGames = GameList::where('user_id', Auth::id())->where('status', 3)->get();
    $completedCount = count($completedGames);

    // Fetch the users games in 'on hold' status and a count of them.
    $onHoldGames = GameList::where('user_id', Auth::id())->where('status', 4)->get();
    $onHoldCount = count($onHoldGames);

    // Fetch the users games in 'dropped' status and a count of them.
    $droppedGames = GameList::where('user_id', Auth::id())->where('status', 5)->get();
    $droppedCount = count($droppedGames);

    // Fetch the users games in 'plan to play' status and a count of them.
    $planToPlayGames = GameList::where('user_id', Auth::id())->where('status', 6)->get();
    $planToPlayCount = count($planToPlayGames);
} elseif (isset($user)) {
    $cardTitle = $user->username . '\'s List';

    // Fetch the users games in 'playing' status and a count of them.
    $playingGames = GameList::where('user_id', $user->id)->where('status', 1)->get();
    $playingCount = count($playingGames);

    // Fetch the users games in 'replaying' status and a count of them.
    $replayingGames = GameList::where('user_id', $user->id)->where('status', 3)->where('is_replaying', 'Y')->get();
    $replayingCount = count($replayingGames);

    // Fetch the users games in 'continuously playing' status and a count of them.
    $continuouslyPlayingGames = GameList::where('user_id', $user->id)->where('status', 2)->get();
    $continuouslyPlayingCount = count($continuouslyPlayingGames);

    // Fetch the users games in 'completed' status and a count of them.
    $completedGames = GameList::where('user_id', $user->id)->where('status', 3)->get();
    $completedCount = count($completedGames);

    // Fetch the users games in 'on hold' status and a count of them.
    $onHoldGames = GameList::where('user_id', $user->id)->where('status', 4)->get();
    $onHoldCount = count($onHoldGames);

    // Fetch the users games in 'dropped' status and a count of them.
    $droppedGames = GameList::where('user_id', $user->id)->where('status', 5)->get();
    $droppedCount = count($droppedGames);

    // Fetch the users games in 'plan to play' status and a count of them.
    $planToPlayGames = GameList::where('user_id', $user->id)->where('status', 6)->get();
    $planToPlayCount = count($planToPlayGames);
}

// Fetch an array of all platform names.
$platformNames = Platform::pluck('name', 'id')->toArray();

@endphp

<x-base-layout>

    <!--begin::Row-->
    <div class="row gy-5 g-xl-8">
        <!--begin::Col-->
        <div class="col-xxl-12">
            <div class="card shadow-sm mb-2">
                <div class="card-header">
                    <h3 class="card-title">{{ $cardTitle }}</h3>
                </div>
                <div class="card-body">
                    <ul class="nav nav-tabs nav-line-tabs mb-5 fs-6">
                        <li class="nav-item">
                            <a class="nav-link active" data-bs-toggle="tab" href="#kt_tab_pane_1">Playing (<?php echo $playingCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_2">Replaying (<?php echo $replayingCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_3">Continuously Playing (<?php echo $continuouslyPlayingCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_4">Completed (<?php echo $completedCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_5">On-Hold (<?php echo $onHoldCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_6">Dropped (<?php echo $droppedCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_7">Plan to Play (<?php echo $planToPlayCount; ?>)</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" data-bs-toggle="tab" href="#kt_tab_pane_8">All</a>
                        </li>
                    </ul>
                    <div class="tab-content" id="myTabContent">
                        <div class="tab-pane fade show active" id="kt_tab_pane_1" role="tabpanel">
                            {{-- Check to see if the user has any games being played currently. --}}
                            @if (count($playingGames) < 1)
                            <p class="mb-0">No games are currently being played.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 playing" id="playing">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user is playing. --}}
                                    @foreach ($playingGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_2" role="tabpanel">
                            {{-- Check to see if the user has any games being replayed currently. --}}
                            @if (count($replayingGames) < 1)
                            <p class="mb-0">No games are currently being replayed.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 replaying" id="replaying">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user is replaying. --}}
                                    @foreach ($replayingGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_3" role="tabpanel">
                            {{-- Check to see if the user has any continuously playing games. --}}
                            @if (count($continuouslyPlayingGames) < 1)
                            <p class="mb-0">No games are currently being continuously played.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 continuouslyPlaying" id="continuouslyPlaying">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user is continuously playing. --}}
                                    @foreach ($continuouslyPlayingGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_4" role="tabpanel">
                            {{-- Check to see if the user has any completed games. --}}
                            @if (count($completedGames) < 1)
                            <p class="mb-0">No games have been marked as completed.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 completed" id="completed">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has completed. --}}
                                    @foreach ($completedGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_5" role="tabpanel">
                            {{-- Check to see if the user has any games set to on hold. --}}
                            @if (count($onHoldGames) < 1)
                            <p class="mb-0">No games have been set to on-hold.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 onHold" id="onHold">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has on hold. --}}
                                    @foreach ($onHoldGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_6" role="tabpanel">
                            {{-- Check to see if the user has any dropped games. --}}
                            @if (count($droppedGames) < 1)
                            <p class="mb-0">No games have been marked as dropped.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 dropped" id="dropped">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has dropped. --}}
                                    @foreach ($droppedGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_7" role="tabpanel">
                            {{-- Check to see if the user has games set to plan to play. --}}
                            @if (count($planToPlayGames) < 1)
                            <p class="mt-6 mb-0">No games are set to plan to play.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 planToPlay" id="planToPlay">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has set to plan to play. --}}
                                    @foreach ($planToPlayGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                        <div class="tab-pane fade" id="kt_tab_pane_8" role="tabpanel">
                            <h3>Playing</h3>
                            {{-- Check to see if the user has any games being played currently. --}}
                            @if (count($playingGames) < 1)
                            <p class="mb-0">No games are currently being played.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 playing" id="playing">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user is playing. --}}
                                    @foreach ($playingGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                            <h3 class="mt-5">Replaying</h3>
                            {{-- Check to see if the user has any games being replayed currently. --}}
                            @if (count($replayingGames) < 1)
                            <p class="mb-0">No games are currently being replayed.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 replaying" id="replaying">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user is replaying. --}}
                                    @foreach ($replayingGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                            <h3 class="mt-5">Continuously Playing</h3>
                            {{-- Check to see if the user has any continuously playing games. --}}
                            @if (count($continuouslyPlayingGames) < 1)
                            <p class="mb-0">No games are currently being continuously played.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 continuouslyPlaying" id="continuouslyPlaying">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user is continuously playing. --}}
                                    @foreach ($continuouslyPlayingGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                            <h3 class="mt-5">Completed</h3>
                            {{-- Check to see if the user has any completed games. --}}
                            @if (count($completedGames) < 1)
                            <p class="mb-0">No games have been marked as completed.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 completed" id="completed">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has completed. --}}
                                    @foreach ($completedGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                            <h3 class="mt-5">On-Hold</h3>
                            {{-- Check to see if the user has any games set to on hold. --}}
                            @if (count($onHoldGames) < 1)
                            <p class="mb-0">No games have been set to on-hold.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 onHold" id="onHold">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has on hold. --}}
                                    @foreach ($onHoldGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                            <h3 class="mt-5">Dropped</h3>
                            {{-- Check to see if the user has any dropped games. --}}
                            @if (count($droppedGames) < 1)
                            <p class="mb-0">No games have been marked as dropped.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 dropped" id="dropped">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has dropped. --}}
                                    @foreach ($droppedGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                            <h3 class="mt-5">Plan to Play</h3>
                            {{-- Check to see if the user has games set to plan to play. --}}
                            @if (count($planToPlayGames) < 1)
                            <p class="mt-6 mb-0">No games are set to plan to play.</p>
                            @else
                            <table class="table table-row-bordered border table-rounded table-striped gs-4 gy-5 mb-0 planToPlay" id="planToPlay">
                                <thead>
                                    <tr class="fw-bold fs-6 text-gray-800 border-bottom border-gray-200">
                                        <th></th>
                                        <th>Name</th>
                                        <th>Rating</th>
                                        <th>Platform</th>
                                        <th>Priority</th>
                                        <th>Added to List On</th>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <th></th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    {{-- Go through each of the games the user has set to plan to play. --}}
                                    @foreach ($planToPlayGames as $game)
                                        @php
                                        $gameOwnership = $game->ownership;

                                        // Fetch the game's platform.
                                        foreach ($platformNames as $key => $value) {
                                            if ($key == $game->platform_id) {
                                                $platformName = $value;
                                            }
                                        }

                                        // Create a data-order attribute for the priority.
                                        if (!$game->priority) {
                                            $dataOrder = 'data-order="0"';
                                        } elseif ($game->priority == 'Low') {
                                            $dataOrder = 'data-order="1"';
                                        } elseif ($game->priority == 'Medium') {
                                            $dataOrder = 'data-order="2"';
                                        } elseif($game->priority == 'High') {
                                            $dataOrder = 'data-order="4"';
                                        }
                                        @endphp
                                    <tr>
                                        <td><i class="fas fa-angle-right"></i></td>
                                        <td><a href="/game/{{ $game->game_id }}/{{ str_replace('/', '_', str_replace(' ', '_', $game->name)) }}">{{ $game->name }}</a></td>
                                        <td>{{ $game->rating ?? '-' }}</td>
                                        <td>{{ $platformName ?? '-' }}</td>
                                        <td {{ $dataOrder }}>{{ $game->priority ?? '-' }}</td>
                                        <td>{{ $game->created_at->format('Y-m-d') }}</td>
                                        @if (Auth::check() && route('games.list.index') == url()->current())
                                        <td>
                                            <a href="{{ route('games.list.edit', $game) }}" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Edit"><i class="fal fa-edit me-1"></i></a>
                                            <form class="d-inline m-0" method="POST" action="{{ route('games.list.destroy', $game) }}">
                                                @method('DELETE')
                                                @csrf
                                                <a class="text-danger" href="#" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="tooltip-dark" title="Delete" onclick="event.preventDefault(); this.closest('form').submit();"><i class="fal fa-trash-alt"></i>
                                                </a>
                                            </form>
                                        </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--end::Col-->
    </div>
    <!--end::Row-->

</x-base-layout>
