import { Calendar } from 'lucide-react'
import type { Media } from '../types'
type MediaDetailMetadataProps = {
media: Media
}
export function MediaDetailMetadata({ media }: MediaDetailMetadataProps) {
const heading = media.episode_title?.trim() || media.title
const showTitleContext = Boolean(media.episode_title?.trim() && media.title && media.title !== heading)
return (
<>
{heading}
{showTitleContext && (
{media.title}
)}
{media.year > 0 && (
{media.year} 年
)}
{media.width > 0 && (
{media.width} × {media.height}
)}
{fmtSize(media.size_bytes)}
{fmtDuration(media.duration_sec)}
{media.container && (
{media.container}
)}
{media.overview && (
)}
>
)
}
function MetadataTags({ label, values, primary = false }: { label: string; values: string[]; primary?: boolean }) {
if (values.length === 0) return null
const tagClass = primary
? 'rounded-full bg-brand-50 text-brand-700 border border-brand-100/30 px-3 py-1 text-2xs font-bold uppercase tracking-wider'
: 'rounded-xl bg-gray-100 text-gray-600 border border-gray-200/40 px-2.5 py-1 text-2xs font-semibold'
return (
{label}
{values.map((value) => (
{value}
))}
)
}
function fmtDuration(sec: number): string {
if (!sec || sec <= 0) return '—'
const h = Math.floor(sec / 3600)
const m = Math.floor((sec % 3600) / 60)
return h > 0 ? `${h}h ${m}m` : `${m}m`
}
function fmtSize(bytes: number): string {
if (!bytes || bytes <= 0) return '—'
const units = ['B', 'KB', 'MB', 'GB', 'TB']
let v = bytes
let i = 0
while (v >= 1024 && i < units.length - 1) {
v /= 1024
i++
}
return `${v.toFixed(2)} ${units[i]}`
}
function parseCSV(s?: string): string[] {
if (!s) return []
return s.split(',').map((x) => x.trim()).filter(Boolean)
}