---
export const prerender = false;

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

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

// 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-new');
}

// Check if user is admin (superuser)
const isAdmin = user.role === 'admin';

if (!isAdmin) {
  return Astro.redirect('/dashboard?error=access_denied');
}
---

<SecureLayout title="Custom Pricing - Black Canyon Tickets">
  <div class="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900">
    <div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
      <CustomPricingManager 
        userId={user.id}
        isAdmin={isAdmin}
        client:load
      />
    </div>
  </div>
</SecureLayout>