import React from 'react' import StatusBadge from '../Badges/StatusBadge' import RisingBadge from '../Badges/RisingBadge' import Checkbox from '../ui/Checkbox' function getStatus(art) { if (art.deleted_at) return 'archived' if (!art.is_public) return 'draft' return 'published' } export default function StudioTable({ artworks, selectedIds, onSelect, onSelectAll, onAction, onSort, currentSort }) { const allSelected = artworks.length > 0 && artworks.every((a) => selectedIds.includes(a.id)) const columns = [ { key: 'title', label: 'Title', sortable: false }, { key: 'status', label: 'Status', sortable: false }, { key: 'category', label: 'Category', sortable: false }, { key: 'created_at', label: 'Created', sortable: true, sort: 'created_at' }, { key: 'views', label: 'Views', sortable: true, sort: 'views' }, { key: 'favourites', label: 'Favs', sortable: true, sort: 'favorites_count' }, { key: 'shares', label: 'Shares', sortable: true, sort: 'shares_count' }, { key: 'comments', label: 'Comments', sortable: true, sort: 'comments_count' }, { key: 'downloads', label: 'Downloads', sortable: true, sort: 'downloads' }, { key: 'ranking_score', label: 'Rank', sortable: true, sort: 'ranking_score' }, { key: 'heat_score', label: 'Heat', sortable: true, sort: 'heat_score' }, ] const handleSort = (col) => { if (!col.sortable) return const field = col.sort const [currentField, currentDir] = (currentSort || '').split(':') const dir = currentField === field && currentDir === 'desc' ? 'asc' : 'desc' onSort(`${field}:${dir}`) } const getSortIcon = (col) => { if (!col.sortable) return null const [currentField, currentDir] = (currentSort || '').split(':') if (currentField !== col.sort) return return } return (
{columns.map((col) => ( ))} {artworks.map((art) => ( ))} {artworks.length === 0 && ( )}
handleSort(col)} > {col.label} {getSortIcon(col)} Actions
onSelect(art.id)} aria-label={`Select ${art.title}`} /> {art.title} {art.category || '—'} {art.created_at ? new Date(art.created_at).toLocaleDateString() : '—'} {art.views.toLocaleString()} {art.favourites.toLocaleString()} {art.shares.toLocaleString()} {art.comments.toLocaleString()} {art.downloads.toLocaleString()} {art.ranking_score.toFixed(1)} {art.heat_score.toFixed(1)}
No artworks found
) }