@extends('layouts.nova')

@php
    $presentMd = $presentMd ?? \App\Services\ThumbnailPresenter::present($artwork, 'md');
    $presentLg = $presentLg ?? \App\Services\ThumbnailPresenter::present($artwork, 'lg');
    $presentXl = $presentXl ?? \App\Services\ThumbnailPresenter::present($artwork, 'xl');
    $presentSq = $presentSq ?? \App\Services\ThumbnailPresenter::present($artwork, 'sq');
    $canonicalUrl = route('art.show', ['id' => $artwork->id, 'slug' => $artwork->slug]);

    $meta = $meta ?? [
        'title' => trim((string) ($artwork->title ?? 'Artwork') . ' by ' . (string) ($artwork->user?->name ?? $artwork->user?->username ?? 'Unknown Author') . ' | Skinbase'),
        'description' => (string) ($artwork->description ?? ''),
        'canonical' => $canonicalUrl,
        'og_image' => $presentXl['url'] ?? $presentLg['url'] ?? $presentMd['url'] ?? null,
        'og_width' => $presentXl['width'] ?? $presentLg['width'] ?? null,
        'og_height' => $presentXl['height'] ?? $presentLg['height'] ?? null,
    ];

    $artworkData = $artworkData ?? [];
    $relatedItems = $relatedItems ?? [];
    $comments = $comments ?? [];
    $groupSummary = $groupSummary ?? null;
    $useUnifiedSeo = true;
    $canReadSessionAuth = request()->hasSession() && ! request()->attributes->get('skinbase.session_skipped');
@endphp

@push('head')
    @php
        $preloadSrcset = ($presentMd['url'] ?? '') . ' 640w, ' . ($presentLg['url'] ?? '') . ' 1280w, ' . ($presentXl['url'] ?? '') . ' 1920w';
    @endphp

    @if(!empty($presentLg['url']))
        <link rel="preload" as="image"
              href="{{ $presentLg['url'] }}"
              imagesrcset="{{ trim($preloadSrcset) }}"
              imagesizes="(min-width: 1280px) 1200px, (min-width: 768px) 90vw, 100vw">
    @endif

@endpush

@section('content')
    <div id="artwork-page"
         data-artwork='@json($artworkData)'
         data-related='@json($relatedItems)'
         data-present-md='@json($presentMd)'
         data-present-lg='@json($presentLg)'
         data-present-xl='@json($presentXl)'
         data-present-sq='@json($presentSq)'
         data-cdn='@json(rtrim((string) config("cdn.files_url", "https://files.skinbase.org"), "/"))'
         data-canonical='@json($meta["canonical"])'
         data-comments='@json($comments)'
            data-group-summary='@json($groupSummary)'
            data-is-authenticated='@json($canReadSessionAuth && auth()->check())'>
    </div>

    @vite(['resources/js/Pages/ArtworkPage.jsx'])
@endsection
