<?php
include 'renderer.php';
include '../vendor/autoload.php'; // Stelle sicher, dass der Autoloader für PhpSpreadsheet geladen wird

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

class Memberlistdownload extends Renderer {
    public function render(): void {
        $members = $this->getMemberList();
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $columnHeaders = ['Nachname', 'Vorname', 'Straße', 'Plz', 'Ort', 'Geburtsdatum', 'Telefon', 'Email',
                          'Mitgliedsbeitrag', 'Bank', 'IBAN', 'BIC', 'Kontoinhaber', 'Status der Mitgliedschaft', 
                          'Start der Mitgliedschaft', 'Letzte Zahlung', 'Position'
                         ];
        $sheet->fromArray([$columnHeaders], null, 'A1');
        $sheet->fromArray($members, null, 'A2');
        $writer = new Xlsx($spreadsheet);
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="excel_file.xlsx"');
        header('Cache-Control: max-age=0');
        $writer->save('php://output');            
    }
}
