@extends('layouts.nova')

@section('content')
<div class="container legacy-page">
    <div class="page-header-wrap">
        <div class="clearfix">
            <h1 class="page-header" style="margin:0;display:inline-block">Artwork Statistics</h1>
            <span class="text-muted pull-right" style="margin-top:10px">
                Uploaded: {{ method_exists($artworks, 'total') ? $artworks->total() : $artworks->count() }}
            </span>
        </div>
        <div class="text-muted" style="margin-top:6px;font-size:12px">Sort your uploads by popularity, downloads, comments, and date.</div>
    </div>

    <div class="panel panel-default uploads-panel">
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-bordered table-striped table-hover" style="margin-bottom:0">
                    <thead>
                        <tr>
                            <th style="width:90px" class="text-center">Thumbnail</th>
                            <th>
                                <a href="{{ request()->fullUrlWithQuery(['sort' => 'name']) }}">Name</a>
                            </th>
                            <th style="width:110px" class="text-center">
                                <a href="{{ request()->fullUrlWithQuery(['sort' => 'dls']) }}">Downloads</a>
                            </th>
                            <th style="width:95px" class="text-center">
                                <a href="{{ request()->fullUrlWithQuery(['sort' => 'comments']) }}">Reviews</a>
                            </th>
                            <th style="width:180px">
                                <a href="{{ request()->fullUrlWithQuery(['sort' => 'category']) }}">Section</a>
                            </th>
                            <th style="width:130px" class="text-center">
                                <a href="{{ request()->fullUrlWithQuery(['sort' => 'date']) }}">Date</a>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                    @forelse($artworks as $art)
                        <tr>
                            <td class="text-center">
                                <a href="/art/{{ (int) $art->id }}" title="View">
                                    <img
                                        src="{{ $art->thumb_url ?? 'https://files.skinbase.org/default/missing_md.webp' }}"
                                        @if(!empty($art->thumb_srcset)) srcset="{{ $art->thumb_srcset }}" @endif
                                        sizes="70px"
                                        alt="{{ $art->name ?? '' }}"
                                        class="img-thumbnail"
                                        style="width:70px;height:70px;object-fit:cover"
                                    >
                                </a>
                            </td>
                            <td>
                                <a href="/art/{{ (int) $art->id }}">{{ $art->name ?? '' }}</a>
                                <div class="text-muted" style="font-size:12px">#{{ (int) $art->id }}</div>
                            </td>
                            <td class="text-center">{{ (int) ($art->dls ?? 0) }}</td>
                            <td class="text-center">{{ (int) ($art->num_comments ?? 0) }}</td>
                            <td>{{ $art->category_name ?? '' }}</td>
                            <td class="text-center">
                                @if(!empty($art->datum))
                                    {{ is_string($art->datum) ? date('d.m.Y', strtotime($art->datum)) : '' }}
                                @endif
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6">No artworks found.</td>
                        </tr>
                    @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="paginationMenu text-center">
        {{ $artworks->links('pagination::bootstrap-3') }}
    </div>
</div>
@endsection
