import './style.css'
import gsap from 'gsap'
// Configuration
const API_BASE_URL = 'https://logoapi.sportcreative.eu'
// Get UUID from URL
const urlParams = new URLSearchParams(window.location.search)
const logoId = urlParams.get('id')
// DOM Elements
const loadingState = document.getElementById('loadingState')
const errorState = document.getElementById('errorState')
const logoDetail = document.getElementById('logoDetail')
// Initialize
if (!logoId) {
showError()
} else {
loadLogoDetails(logoId)
}
async function loadLogoDetails(id) {
try {
const response = await fetch(`${API_BASE_URL}/logos/${id}/json`)
if (!response.ok) {
throw new Error('Logo not found')
}
const logo = await response.json()
displayLogoDetails(logo)
} catch (error) {
console.error('Error loading logo:', error)
showError()
}
}
function displayLogoDetails(logo) {
// Hide loading, show content
loadingState.classList.add('hidden')
logoDetail.classList.remove('hidden')
// Club Info
const editBtn = document.getElementById('editButton')
if (editBtn) editBtn.href = `/admin.html?id=${logoId}`
document.getElementById('clubName').textContent = logo.club_name
document.getElementById('clubMeta').textContent = `${logo.club_type || 'fotbal'}`
// Logo Previews - construct URL through API proxy
const previewUrl = `${API_BASE_URL}/logos/${logoId}`
document.getElementById('logoPreviewLight').src = previewUrl
document.getElementById('logoPreviewDark').src = previewUrl
// Formats
const formatsGrid = document.getElementById('formatsGrid')
const formats = []
if (logo.has_png) {
formats.push({
name: 'PNG',
url: `${API_BASE_URL}/logos/${logoId}?format=png`,
size: formatFileSize(logo.file_size_png),
icon: '🖼️',
color: 'bg-blue-600'
})
}
if (logo.has_svg) {
formats.push({
name: 'SVG',
url: `${API_BASE_URL}/logos/${logoId}?format=svg`,
size: formatFileSize(logo.file_size_svg),
icon: '📐',
color: 'bg-green-600'
})
}
formatsGrid.innerHTML = formats.map(format => `
${format.icon}
${format.name}
${format.name} Format
${format.size}
`).join('')
// Variants (if supported)
if (logo.variants && logo.variants.length > 0) {
document.getElementById('variantsSection').classList.remove('hidden')
const variantsGrid = document.getElementById('variantsGrid')
variantsGrid.innerHTML = logo.variants.map(variant => `
${variant.name || 'Varianta'}
${variant.description ? `
${variant.description}
` : ''}
${variant.format.toUpperCase()}
•
${formatFileSize(variant.size)}
⬇️
`).join('')
} else {
document.getElementById('variantsSection').classList.add('hidden')
}
// Metadata
document.getElementById('logoUuid').textContent = logo.id
document.getElementById('clubType').textContent = logo.club_type || 'fotbal'
const website = logo.club_website || 'N/A'
const websiteElement = document.getElementById('clubWebsite')
if (logo.club_website) {
websiteElement.innerHTML = `${logo.club_website}`
} else {
websiteElement.textContent = website
}
document.getElementById('uploadDate').textContent = formatDate(logo.created_at)
// API URLs
const baseUrl = API_BASE_URL
document.getElementById('apiUrlDefault').textContent = `${baseUrl}/logos/${logo.id}`
document.getElementById('apiUrlJson').textContent = `${baseUrl}/logos/${logo.id}/json`
// Animate
gsap.from('#logoDetail > *', {
duration: 0.6,
opacity: 0,
y: 20,
stagger: 0.1,
ease: 'power2.out'
})
}
function showError() {
loadingState.classList.add('hidden')
errorState.classList.remove('hidden')
}
function formatFileSize(bytes) {
if (!bytes) return 'N/A'
if (bytes < 1024) return bytes + ' B'
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB'
return (bytes / (1024 * 1024)).toFixed(2) + ' MB'
}
function formatDate(dateString) {
if (!dateString) return 'N/A'
const date = new Date(dateString)
return date.toLocaleDateString('cs-CZ', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
}
window.copyToClipboard = function(elementId) {
const element = document.getElementById(elementId)
const text = element.textContent
navigator.clipboard.writeText(text).then(() => {
showNotification('URL zkopírováno do schránky', 'success')
}).catch(err => {
console.error('Failed to copy:', err)
showNotification('Chyba při kopírování', 'error')
})
}
function showNotification(message, type = 'info') {
const notification = document.createElement('div')
notification.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg z-50 ${
type === 'success' ? 'bg-accent-green' :
type === 'error' ? 'bg-red-500' :
'bg-accent-blue'
} text-white font-medium`
notification.textContent = message
document.body.appendChild(notification)
gsap.from(notification, {
duration: 0.3,
opacity: 0,
y: -20,
ease: 'power2.out'
})
setTimeout(() => {
gsap.to(notification, {
duration: 0.3,
opacity: 0,
y: -20,
ease: 'power2.in',
onComplete: () => notification.remove()
})
}, 3000)
}
console.log('🇨🇿 České Kluby Loga API - Detail Loga')
console.log('Logo ID:', logoId)