import type { APIRoute } from 'astro';
import { clearAuthCookie } from '../../../../lib/auth';

export const POST: APIRoute = async ({ cookies }) => {
  try {
    // Clear the auth cookie
    clearAuthCookie(cookies);
    
    return new Response(JSON.stringify({
      success: true,
      message: 'Logged out successfully'
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
    
  } catch (error) {
    console.error('Logout error:', error);
    return new Response(JSON.stringify({
      error: error instanceof Error ? error.message : 'Internal server error'
    }), {
      status: 500,
      headers: { 'Content-Type': 'application/json' }
    });
  }
};
