---
// Admin: Create New Page
import AdminLayout from '@/layouts/AdminLayout.astro';
import PageEditor from '@/components/shim/PageEditor';

// Get first site ID (for demo, you'd select from a dropdown)
const { rows: sites } = await (await import('@/lib/db')).pool.query<{id: string}>('SELECT id FROM sites LIMIT 1');
const siteId = sites[0]?.id;

if (!siteId) {
  return Astro.redirect('/admin/sites');
}
---

<AdminLayout title="Create New Page">
  <div class="space-y-6">
    
    <div class="flex justify-between items-center">
      <div>
        <h1 class="text-3xl font-bold text-white">Create New Page</h1>
        <p class="text-slate-400 mt-1">Add a new static page to your site</p>
      </div>
      <a href="/admin/pages" class="px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white rounded-lg">
        ← Back to Pages
      </a>
    </div>

    <div class="bg-slate-800 rounded-lg border border-slate-700 p-6">
      <PageEditor 
        client:only="react" 
        siteId={siteId}
        onSave={(page) => {
          window.location.href = `/admin/pages/${page.id}/edit`;
        }}
      />
    </div>

  </div>
</AdminLayout>
