@extends('layouts.nova')

@section('content')
<div class="legacy-artwork">
    <div class="row">
        <div class="col-md-8">
            <div class="effect2" style="max-width:800px">
                <a class="artwork-zoom" href="{{ $thumb_file ?? '#' }}" title="{{ $artwork->name }}">
                    <img src="{{ $thumb_file }}" alt="{{ $artwork->name ?? '' }}" class="img-thumbnail img-responsive">
                </a>
            </div>

            <div style="clear:both;margin-top:10px;">
                <img src="{{ \App\Support\AvatarUrl::forUser((int) ($artwork->user_id ?? 0), null, 50) }}" class="pull-left" style="padding-right:10px;max-height:50px;" alt="Avatar">
                <h1 class="page-header">{{ $artwork->name }}</h1>
                <p>By <i class="fa fa-user fa-fw"></i> <a href="/profile/{{ $artwork->user_id }}/{{ \Illuminate\Support\Str::slug($artwork->uname) }}" title="Profile of member {{ $artwork->uname }}">{{ $artwork->uname }}</a></p>
                <hr>
            </div>

            @if(!empty($artwork->description))
                <div class="panel panel-skinbase">
                    <div class="panel-body">{!! nl2br(e($artwork->description)) !!}</div>
                </div>
            @endif

            {{-- Comments --}}
            @if(!empty($comments) && $comments->count() > 0)
                <h3 class="comment-title"><i class="fa fa-comments fa-fw"></i> Comments:</h3>
                @foreach($comments as $comment)
                    <div class="comment_box effect3">
                        <div class="cb_image">
                            <a href="/profile/{{ $comment->user_id }}/{{ urlencode($comment->uname) }}">
                                <img src="{{ \App\Support\AvatarUrl::forUser((int) $comment->user_id, null, 50) }}" width="50" height="50" class="comment_avatar" alt="{{ $comment->uname }}">
                            </a>
                        </div>
                        <div class="bubble_comment panel panel-skinbase">
                            <div class="panel-heading">
                                <div class="pull-right">{{ \Illuminate\Support\Str::limit($comment->date, 16) }}</div>
                                <h5 class="panel-title">Comment by: <a href="/profile/{{ $comment->user_id }}/{{ urlencode($comment->uname) }}">{{ $comment->uname }}</a></h5>
                            </div>
                            <div class="panel-body">
                                {!! nl2br(e($comment->description)) !!}
                            </div>
                            @if(!empty($comment->signature))
                                <div class="panel-footer comment-footer">{!! nl2br(e($comment->signature)) !!}</div>
                            @endif
                        </div>
                    </div>
                @endforeach
            @endif

            @auth
                <div class="comment_box effect3">
                    <div class="cb_image">
                        <a href="/profile/{{ auth()->id() }}/{{ urlencode(auth()->user()->name) }}">
                            <img src="{{ \App\Support\AvatarUrl::forUser((int) auth()->id(), null, 50) }}" class="comment_avatar" width="50" height="50">
                        </a>
                        <br>
                        <a href="/profile/{{ auth()->id() }}/{{ urlencode(auth()->user()->name) }}">{{ auth()->user()->name }}</a>
                    </div>
                    <form action="/art/{{ $artwork->id }}" method="post">
                        @csrf
                        <div class="bubble_comment panel panel-skinbase">
                            <div class="panel-heading"><h4 class="panel-title">Write comment</h4></div>
                            <div class="panel-body">
                                <textarea name="comment_text" class="form-control" style="width:98%; height:120px;"></textarea><br>
                            </div>
                            <div class="panel-footer">
                                <button type="submit" class="btn btn-success">Post comment</button>
                            </div>
                        </div>
                        <input type="hidden" name="artwork_id" value="{{ $artwork->id }}">
                        <input type="hidden" name="action" value="store_comment">
                    </form>
                </div>
            @endauth

        </div>

        <div class="col-md-4">
            <div class="panel panel-default effect3">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-6">
                            <a class="btn btn-info" style="width:100%;margin-bottom:5px" href="/download/{{ $artwork->id }}" title="Download Full Size Artwork to your computer">
                                <i class="fa fa-download fa-fw"></i> Download
                            </a>
                        </div>
                        <div class="col-md-6">
                            @if(auth()->check())
                                <span class="btn btn-warning addFavourites" style="width:100%" data-artwork_id="{{ $artwork->id }}"><i class="fa fa-heart fa-fw"></i> Add To Favourites</span>
                            @endif
                        </div>
                    </div>

                    <hr>
                    <h4 class="panel-title">Details</h4>
                    <table class="table table-condensed">
                        <tr><td>Category</td><td class="text-right">{{ $artwork->category_name ?? '' }}</td></tr>
                        <tr><td>Uptime</td><td class="text-right">{{ \Illuminate\Support\Str::limit($artwork->datum ?? '', 10) }}</td></tr>
                        <tr><td>Submitted</td><td class="text-right">{{ optional(\Carbon\Carbon::parse($artwork->datum))->format('d.m.Y') }}</td></tr>
                        <tr><td>Resolution</td><td class="text-right">{{ ($artwork->width ?? '') . 'x' . ($artwork->height ?? '') }}</td></tr>
                    </table>

                    <h4 class="panel-title">Statistics</h4>
                    <table class="table table-condensed">
                        <tr><td>Views</td><td class="text-right">{{ $artwork->views ?? 0 }}</td></tr>
                        <tr><td>Downloads</td><td class="text-right">{{ $artwork->dls ?? 0 }} @if(!empty($num_downloads)) <small>({{ $num_downloads }} today)</small>@endif</td></tr>
                    </table>

                    <h4 class="panel-title">Social</h4>
                    <div class="fb-like" data-href="{{ url()->current() }}" data-send="true" data-width="450" data-show-faces="true"></div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
