export const dynamic = 'force-dynamic'

import { redirect } from 'next/navigation'
import { getLibraries } from '@/lib/libraries'
import LibraryCard from '@/components/LibraryCard'
import Link from 'next/link'

export default function HomePage() {
  const libraries = getLibraries()

  if (libraries.length === 0) {
    redirect('/manage')
  }

  return (
    <div>
      <div className="flex items-center justify-between mb-8">
        <div>
          <h1 className="text-2xl font-semibold mb-1" style={{ color: 'var(--text-primary)' }}>
            Libraries
          </h1>
          <p className="text-sm" style={{ color: 'var(--text-secondary)' }}>
            {libraries.length} {libraries.length === 1 ? 'library' : 'libraries'} configured
          </p>
        </div>
        <Link
          href="/manage"
          className="text-sm px-3 py-1.5 rounded-lg transition-colors"
          style={{ backgroundColor: 'var(--surface)', color: 'var(--text-secondary)', border: '1px solid var(--border)' }}
        >
          Manage
        </Link>
      </div>
      <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
        {libraries.map((lib) => (
          <LibraryCard key={lib.id} library={lib} />
        ))}
      </div>
    </div>
  )
}
