import { NextResponse } from 'next/server';
import * as xlsx from 'xlsx';

export async function GET() {
  const ws = xlsx.utils.aoa_to_sheet([
    ['Código', 'Nombre del Producto', 'Tarifa Arancelaria', 'Valor Declarado']
  ]);
  
  const wb = xlsx.utils.book_new();
  xlsx.utils.book_append_sheet(wb, ws, 'Productos');
  
  const buffer = xlsx.write(wb, { type: 'buffer', bookType: 'xlsx' });
  
  return new NextResponse(buffer, {
    status: 200,
    headers: {
      'Content-Disposition': 'attachment; filename="formato_productos.xlsx"',
      'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    }
  });
}
