@extends('layouts.nova')

@section('content')
<div class="container legacy-page">
    <div class="page-header-wrap">
        <h1 class="page-header">Favourites</h1>
        <p class="text-muted">List of uploaded Artworks which were added to user's favourites list</p>
    </div>

    @if(session('status'))
        <div class="alert alert-success">{{ session('status') }}</div>
    @endif

    <table class="table table-striped">
        <thead>
            <tr>
                <th>Thumb</th>
                <th>Name</th>
                <th>Author</th>
                <th>Date</th>
                <th>Dls</th>
                <th>Views</th>
                <th>Zoom</th>
                <th>Rating</th>
            </tr>
        </thead>
        <tbody>
        @foreach($results as $ar)
            @php
                $artId = (int)($ar->id ?? 0);
                $nid = (int)($artId / 100);
                $picture = rawurlencode($ar->picture ?? '');
            @endphp
            <tr>
                <td style="width:80px;">
                    <a href="/art/{{ $artId }}/{{ $ar->slug }}"><img src="/files/archive/shots/{{ $nid }}/{{ $picture }}" height="60" alt="{{ $ar->name }}"></a>
                </td>
                <td>
                    @if(auth()->check() && auth()->id() == ($ar->user_id ?? null))
                        <form method="POST" action="{{ route('legacy.favourites.delete', ['userId' => auth()->id(), 'artworkId' => $artId]) }}" style="display:inline" onsubmit="return confirm('Really Remove From Favourites: {{ addslashes($ar->name ?? '') }}');">
                            @csrf
                            <button type="submit" class="btn btn-link"><img src="/gfx/icon_delete.gif" alt="Delete"></button>
                        </form>
                    @endif
                    <a href="/art/{{ $artId }}/{{ $ar->slug }}">{{ $ar->name }}</a>
                </td>
                <td><a href="/profile.php?uname={{ urlencode($ar->uname ?? '') }}">{{ $ar->uname ?? '' }}</a></td>
                <td>{{ is_string($ar->datum) ? date('d.m.Y', strtotime($ar->datum)) : '' }}</td>
                <td>{{ (int)($ar->dls ?? 0) }}</td>
                <td>{{ (int)($ar->views ?? 0) }}</td>
                <td>{{ e($ar->zoom ?? '') }}</td>
                <td>{{ e($ar->rating ?? '') }}</td>
            </tr>
        @endforeach
        </tbody>
    </table>

    {{-- Simple pagination controls --}}
    @php
        $pages = (int) ceil($total / $hits);
    @endphp
    @if($pages > 1)
        <nav>
            <ul class="pagination">
                @for($i=1;$i<=$pages;$i++)
                    <li class="{{ $i == $page ? 'active' : '' }}"><a href="{{ route('legacy.favourites', ['id' => $user_id, 'page' => $i]) }}">{{ $i }}</a></li>
                @endfor
            </ul>
        </nav>
    @endif

</div>
@endsection
