---
export const prerender = false;

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

// Get user session
const session = Astro.locals.session;
if (!session) {
  return Astro.redirect('/login');
}

// Get user data
const { data: user, error: userError } = await supabase
  .from('users')
  .select('id, organization_id, role')
  .eq('id', session.user.id)
  .single();

if (userError || !user) {
  return Astro.redirect('/login');
}
---

<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>