import type { APIRoute } from 'astro';
import { requireAdminSimple } from '../../../lib/simple-auth';

export const GET: APIRoute = async ({ request }) => {
  try {
    // Check if user is at least an admin (super admin functionality not fully implemented yet)
    const auth = await requireAdminSimple(request);
    
    // For now, super admin is not fully implemented, so we return false
    // This prevents the super admin button from showing but allows admin functionality
    const isSuperAdmin = false;
    
    return new Response(JSON.stringify({
      success: true,
      data: {
        isSuperAdmin,
        userId: auth.user.id,
        email: auth.user.email
      }
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
  } catch (error) {
    // If admin check fails, still return success but with isSuperAdmin false
    // This allows the admin dashboard to work even if super admin check fails
    return new Response(JSON.stringify({
      success: true,
      data: {
        isSuperAdmin: false,
        userId: null,
        email: null
      }
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
  }
};