@extends('layouts.nova')

@section('content')
<div class="container">
    <h2>Artwork Manager</h2>

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

    <div id="msgList">
        <table class="table table-bordered table-striped table-advanced">
            <thead>
                <tr>
                    <th>Modify</th>
                    <th>Name</th>
                    <th>Section</th>
                    <th>Date</th>
                    <th>#Votes</th>
                    <th>Rating</th>
                    <th>Downloads</th>
                    <th>Zooms</th>
                    <th>Views</th>
                </tr>
            </thead>
            <tbody>
            @foreach($artworks as $ar)
                <tr>
                    <td style="width:80px">
                        <a href="{{ route('manage.edit', $ar->id) }}" class="btn btn-xs btn-default">Edit</a>
                        <form method="POST" action="{{ route('manage.destroy', $ar->id) }}" style="display:inline-block;" onsubmit="return confirm('Delete artwork?');">
                            @csrf
                            <button class="btn btn-xs btn-danger">Delete</button>
                        </form>
                    </td>
                    <td style="cursor:pointer;" onclick="location.href='{{ route('manage.edit', $ar->id) }}'">{{ $ar->title }}</td>
                    <td>{{ $ar->category_name ?? ($ar->categoryRelation->category_name ?? '') }}</td>
                    <td class="text-center">{{ optional($ar->published_at)->format('d.m.Y') ?? (is_string($ar->published_at) ? date('d.m.Y', strtotime($ar->published_at)) : '') }}</td>
                    <td class="text-center">{{ $ar->rating_num }}</td>
                    <td class="text-center">{{ $ar->rating }}</td>
                    <td class="text-center">{{ $ar->dls }}</td>
                    <td class="text-center">{{ $ar->zoom }}</td>
                    <td class="text-center">{{ $ar->views }}</td>
                </tr>
            @endforeach
            </tbody>
        </table>

        {{ $artworks->links() }}
    </div>
</div>
@endsection
