@props([ 'art', 'loading' => 'lazy', 'fetchpriority' => null, ]) @php if (isset($art) && (is_array($art) || $art instanceof Illuminate\Support\Collection || $art instanceof Illuminate\Database\Eloquent\Collection)) { $first = null; if (is_array($art)) { $first = reset($art); } elseif ($art instanceof Illuminate\Support\Collection || $art instanceof Illuminate\Database\Eloquent\Collection) { $first = $art->first(); } if ($first) { $art = $first; } } $title = trim((string) ($art->name ?? $art->title ?? 'Untitled artwork')); $author = trim((string) ( $art->uname ?? $art->author_name ?? $art->author ?? ($art->user->name ?? null) ?? ($art->user->username ?? null) ?? 'Skinbase' )); $username = trim((string) ( $art->username ?? ($art->user->username ?? null) ?? '' )); $category = trim((string) ($art->category_name ?? $art->category ?? '')); $avatarUserId = $art->user->id ?? $art->user_id ?? null; $avatarHash = $art->user->profile->avatar_hash ?? $art->avatar_hash ?? null; $avatarUrl = \App\Support\AvatarUrl::forUser((int) ($avatarUserId ?? 0), $avatarHash, 64); $license = trim((string) ($art->license ?? 'Standard')); $resolution = trim((string) ($art->resolution ?? ((isset($art->width, $art->height) && $art->width && $art->height) ? ($art->width . '×' . $art->height) : ''))); $safeInt = function ($value, $fallback = 0) { if (is_numeric($value)) { return (int) $value; } if (is_array($value)) { return count($value); } if (is_object($value)) { if (method_exists($value, 'count')) { return (int) $value->count(); } if ($value instanceof Countable) { return (int) count($value); } } return (int) $fallback; }; $likes = $safeInt($art->likes ?? $art->favourites ?? 0); $comments = $safeInt($art->comments_count ?? $art->comment_count ?? $art->comments ?? 0); $imgSrc = (string) ($art->thumb ?? $art->thumbnail_url ?? '/images/placeholder.jpg'); $imgSrcset = (string) ($art->thumb_srcset ?? $art->thumbnail_srcset ?? $imgSrc); $imgAvifSrcset = (string) ($art->thumb_avif_srcset ?? $imgSrcset); $imgWebpSrcset = (string) ($art->thumb_webp_srcset ?? $imgSrcset); $resolveDimension = function ($value, string $field, $fallback) { if (is_numeric($value)) { return (int) $value; } if (is_array($value)) { $current = reset($value); return is_numeric($current) ? (int) $current : (int) $fallback; } if (is_object($value)) { if (method_exists($value, 'first')) { $first = $value->first(); if (is_object($first) && isset($first->{$field})) { return (int) ($first->{$field} ?: $fallback); } } if (isset($value->{$field})) { return (int) $value->{$field}; } } return (int) $fallback; }; // Use stored dimensions when available; otherwise leave ratio unconstrained // so the thumbnail displays at its natural proportions (no 1:1 or 16:9 forcing). $hasDimensions = ($art->width ?? 0) > 0 && ($art->height ?? 0) > 0; $imgWidth = $hasDimensions ? max(1, $resolveDimension($art->width, 'width', 0)) : null; $imgHeight = $hasDimensions ? max(1, $resolveDimension($art->height, 'height', 0)) : null; $imgAspectRatio = $hasDimensions ? ($imgWidth . ' / ' . $imgHeight) : null; $contentUrl = $imgSrc; $cardUrl = (string) ($art->url ?? ''); if ($cardUrl === '' || $cardUrl === '#') { if (isset($art->id) && is_numeric($art->id)) { $cardUrl = '/art/' . (int) $art->id . '/' . \Illuminate\Support\Str::slug($title); } else { $cardUrl = '#'; } } $authorUrl = $username !== '' ? '/@' . strtolower($username) : null; $metaParts = []; if ($resolution !== '') { $metaParts[] = $resolution; } if ($category !== '') { $metaParts[] = $category; } if ($license !== '') { $metaParts[] = $license; } @endphp