<?php 

namespace App\Controllers;
use App\Models\AttendanceModel;

class Admin extends BaseController {
    public function dashboard() {
        return view('admin_dashboard',['records'=>(new AttendanceModel())->getAll()]);
    }
    public function export()
{
    $attendance = (new AttendanceModel())->findAll(); // or with join for names

    header("Content-Type: text/csv");
    header("Content-Disposition: attachment; filename=attendance.csv");

    $out = fopen('php://output', 'w');

    // CSV headers
    fputcsv($out, ['Employee', 'Date', 'Punch In', 'Punch Out', 'Mode']);

    foreach($attendance as $r) {
        fputcsv($out, [
            $r['employee'] ?? '---',
            $r['created_at'] ?? '',
            $r['punch_in'] ?? '',
            $r['punch_out'] ?? '',
            $r['work_mode'] ?? ''
        ]);
    }

    fclose($out);
    exit;
}

}
