@extends('layouts.nova')

@section('content')
<div class="container legacy-page">
    <div class="page-header-wrap">
        <div class="clearfix">
            <h2 style="margin:0;display:inline-block">Edit Artwork</h2>
            <a class="btn btn-default btn-xs pull-right" href="{{ route('dashboard.artworks.index') }}" style="margin-top:6px">
                <i class="fa fa-arrow-left fa-fw"></i> Back to list
            </a>
        </div>
        <div class="text-muted" style="margin-top:6px;font-size:12px">
            #{{ $artwork->id }} &middot; {{ $artwork->is_public ? 'Public' : 'Private' }}
        </div>
    </div>

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

    @if($errors->any())
        <div class="alert alert-danger" role="alert">
            <strong>Please fix the errors below.</strong>
        </div>
    @endif

    <div class="panel panel-default uploads-panel">
        <div class="panel-body">
            <form method="POST" action="{{ route('dashboard.artworks.update', $artwork->id) }}" enctype="multipart/form-data">
                @csrf
                @method('PUT')

                <div class="row">
                    <div class="col-md-7">
                        <div class="form-group @error('title') has-error @enderror">
                            <label for="title" class="control-label">Title</label>
                            <input id="title" type="text" name="title" class="form-control" value="{{ old('title', $artwork->title) }}" required>
                            @error('title')
                                <span class="help-block">{{ $message }}</span>
                            @enderror
                        </div>

                        <div class="form-group @error('description') has-error @enderror">
                            <label for="description" class="control-label">Description</label>
                            <textarea id="description" name="description" class="form-control" rows="8">{{ old('description', $artwork->description) }}</textarea>
                            <p class="help-block">Basic Markdown-style formatting and emoji are allowed. Raw HTML tags are not accepted.</p>
                            @error('description')
                                <span class="help-block">{{ $message }}</span>
                            @enderror
                        </div>

                        <button type="submit" class="btn btn-success">
                            <i class="fa fa-save fa-fw"></i> Save Changes
                        </button>
                    </div>

                    <div class="col-md-5">
                        <label class="control-label">Preview</label>
                        <div class="thumbnail" style="margin-top:6px">
                            <img
                                src="{{ $artwork->thumb_url ?? $artwork->thumb }}"
                                @if(!empty($artwork->thumb_srcset)) srcset="{{ $artwork->thumb_srcset }}" @endif
                                sizes="(max-width: 992px) 100vw, 400px"
                                class="img-responsive"
                                alt="{{ $artwork->title }}"
                            >
                        </div>

                        <div class="form-group @error('file') has-error @enderror">
                            <label for="file" class="control-label">Replace image (optional)</label>
                            <input id="file" type="file" name="file" class="form-control" accept="image/*">
                            <p class="help-block">Max 100MB. Images only.</p>
                            @error('file')
                                <span class="help-block">{{ $message }}</span>
                            @enderror
                        </div>

                        <p class="text-muted" style="font-size:12px;margin-bottom:0">
                            Created: {{ optional($artwork->created_at)->format('d.m.Y') }}
                        </p>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection
