import React from 'react'
import { Head, router, usePage } from '@inertiajs/react'
import AdminLayout from '../../../Layouts/AdminLayout'

export default function AcademySubmissions({ submissions }) {
  const flash = usePage().props.flash || {}

  return (
    <AdminLayout title="Academy Challenge Submissions" subtitle="Approve or reject Academy challenge entries.">
      <Head title="Admin · Academy Challenge Submissions" />

      {flash.success ? <div className="mb-6 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 px-4 py-3 text-sm text-emerald-100">{flash.success}</div> : null}

      <div className="space-y-4">
        {(submissions?.data || []).map((submission) => (
          <article key={submission.id} className="rounded-[28px] border border-white/[0.08] bg-white/[0.03] p-5">
            <div className="grid gap-5 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-start">
              <div className="space-y-3">
                <div className="flex flex-wrap items-center gap-3">
                  <span className="rounded-full border border-white/10 bg-white/[0.04] px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.2em] text-white/80">{submission.moderation_status}</span>
                  <span className="text-sm text-slate-400">{submission.challenge?.title || 'Challenge'}</span>
                </div>
                <h2 className="text-xl font-semibold text-white">{submission.artwork?.title || 'Artwork removed'}</h2>
                <p className="text-sm text-slate-400">{submission.user?.name || 'Unknown user'} · {submission.ai_tool_used || 'No tool noted'}</p>
                {submission.prompt_used ? <pre className="whitespace-pre-wrap rounded-2xl border border-white/10 bg-black/20 p-4 text-sm leading-7 text-slate-200">{submission.prompt_used}</pre> : null}
                {submission.workflow_notes ? <div className="rounded-2xl border border-white/10 bg-black/20 p-4 text-sm leading-7 text-slate-300">{submission.workflow_notes}</div> : null}
              </div>

              <div className="flex flex-wrap gap-3 lg:justify-end">
                <button type="button" onClick={() => router.post(submission.approve_url, {}, { preserveScroll: true })} className="rounded-full border border-emerald-300/20 bg-emerald-300/10 px-4 py-2 text-sm font-semibold text-emerald-100">Approve</button>
                <button type="button" onClick={() => router.post(submission.reject_url, {}, { preserveScroll: true })} className="rounded-full border border-rose-300/20 bg-rose-300/10 px-4 py-2 text-sm font-semibold text-rose-100">Reject</button>
              </div>
            </div>
          </article>
        ))}
      </div>
    </AdminLayout>
  )
}