<?php

namespace App\Modules\HR\Reports\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class AttendanceSummaryExport implements FromCollection, WithHeadings
{
    protected $departments;

    public function __construct($data)
    {
        $this->departments = $data['departments'];
    }

    public function collection()
    {
        return $this->departments->map(function ($dept) {
            return [
                $dept->department_name,
                $dept->present_count,
                $dept->absent_count,
                $dept->late_count,
                number_format($dept->total_ot_hrs, 2),
                number_format($dept->total_dot_hrs, 2),
            ];
        });
    }

    public function headings(): array
    {
        return [
            'Department',
            'Present',
            'Absent',
            'Late',
            'Total OT Hrs',
            'Total DOT Hrs',
        ];
    }
}
