<?php

namespace App\Exports;

use App\Models\KartuKendali;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class KartuKendaliExport implements FromCollection, WithHeadings
{
    /**
     * @return \Illuminate\Support\Collection
     */
    public function collection()
    {
        $kartukendali = KartuKendali::join("siswa", "siswa.user_id", "=", "kartukendali.user_id")->get(["siswa.user_id", "siswa.nama", "kartukendali.jumlah"]);
        for ($i = 0; $i < count($kartukendali); $i++) {
            $kartukendali[$i]["keterangan"] = $kartukendali[$i]["jumlah"] >= 40 ? "TUNTAS" : "BELUM TUNTAS";
        }

        return $kartukendali;
    }

    public function headings(): array
    {
        return [
            '#',
            'NAMA',
            'HADIR',
            'KETERANGAN'
        ];
    }
}
