---
export const prerender = false;

import SecureLayout from '../layouts/SecureLayout.astro';
import TemplateManager from '../components/TemplateManager.tsx';
import { verifyAuth } from '../lib/auth';

// Server-side authentication check
const auth = await verifyAuth(Astro.request);
if (!auth) {
  return Astro.redirect('/login-new');
}

// User is authenticated, get organization data
const user = {
  id: auth.user.id,
  organization_id: auth.organizationId,
  role: auth.isAdmin ? 'admin' : 'user'
};
---

<SecureLayout title="Page Templates - Black Canyon Tickets">
  <div class="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900">
    <TemplateManager 
      organizationId={user.organization_id || ''}
      client:load
    />
  </div>
</SecureLayout>