import React from 'react'
import { usePage } from '@inertiajs/react'
import StudioLayout from '../../Layouts/StudioLayout'

export default function StudioGroupProjects() {
  const { props } = usePage()
  const listing = props.listing || {}
  const items = Array.isArray(listing.items) ? listing.items : []

  return (
    <StudioLayout title={props.title} subtitle={props.description}>
      <div className="flex items-center justify-between gap-3">
        <div className="text-sm text-slate-400">Projects give the group a structured place for releases, teams, and linked outputs.</div>
        {props.createUrl ? <a href={props.createUrl} className="rounded-full border border-white/10 bg-white/[0.04] px-4 py-2 text-sm font-semibold text-white">Create project</a> : null}
      </div>
      <div className="mt-6 grid gap-4 lg:grid-cols-2">
        {items.length > 0 ? items.map((project) => (
          <a key={project.id} href={project.urls?.edit || project.url} className="rounded-[24px] border border-white/10 bg-white/[0.03] p-5 transition hover:border-white/20">
            <div className="flex items-center justify-between gap-3">
              <h2 className="text-xl font-semibold text-white">{project.title}</h2>
              <span className="rounded-full border border-white/10 bg-white/[0.04] px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-300">{project.status}</span>
            </div>
            <p className="mt-3 text-sm leading-6 text-slate-400">{project.summary || 'Project page'}</p>
            <div className="mt-4 text-xs text-slate-500">{project.counts?.artworks || 0} artworks • {project.counts?.assets || 0} assets • {project.counts?.team || 0} team • {project.counts?.milestones || 0} milestones • {project.counts?.releases || 0} releases</div>
          </a>
        )) : <div className="rounded-[24px] border border-dashed border-white/10 bg-white/[0.02] p-6 text-sm text-slate-400">No projects yet.</div>}
      </div>
    </StudioLayout>
  )
}