import React from 'react' import CollectionVisibilityBadge from './CollectionVisibilityBadge' async function requestJson(url, { method = 'GET', body } = {}) { const response = await fetch(url, { method, credentials: 'same-origin', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '', 'X-Requested-With': 'XMLHttpRequest', }, body: body ? JSON.stringify(body) : undefined, }) const payload = await response.json().catch(() => ({})) if (!response.ok) { const message = payload?.message || 'Request failed.' throw new Error(message) } return payload } function formatUpdated(value) { if (!value) return 'Updated recently' const date = new Date(value) if (Number.isNaN(date.getTime())) return 'Updated recently' return new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric', year: 'numeric', }).format(date) } function StatPill({ icon, label, value }) { return ( {value} {label} ) } function CoverMedia({ collection, isOwner }) { const coverImage = collection?.cover_image const coverMaturity = !isOwner && collection?.cover_image_maturity ? collection.cover_image_maturity : null const shouldBlur = Boolean(coverMaturity?.should_blur) const isMature = Boolean(coverMaturity?.is_mature_effective) if (!coverImage) { return (
{collection.subtitle}
: null} {collection?.owner?.name ?Curated by {collection.owner.name}{collection?.owner?.username ? ` • @${collection.owner.username}` : ''}
: null}{(collection?.artworks_count ?? 0).toLocaleString()} artworks
{collection.description_excerpt}
) : collection?.smart_summary ? ({collection.smart_summary}
) : null}