<?php

namespace App\Exports;

use App\Employees;
use Maatwebsite\Excel\Concerns\FromCollection;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithMapping;
 


class EmployeesExport implements FromCollection, WithHeadings, ShouldAutoSize, WithMapping,  WithColumnFormatting 

{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return collect(Employees::getEmployees());
    }
    public function headings(): array
    {
        return [
            'EmployeeID',
            'Prefix',
            'FirstName',
            'LastName',
            'MiddleName',
            'Email',
            'Gender',
            'Role',
            'BusinessUnit',
            'Department',
            'JobTitle',
            'EmploymentStatus',
            'DateofJoining',
            'DateofLeaving',
            'Years of Experience',
            'Work Phone',
            'Personal Phone',
            'Extension',
            'KRA Pin',
            'NSSF No.',
            'NHIF No.',
            'IFMIS No.',
            'Duration',
            
        ];
    }
    public function map($Employees): array
    {
        return [
            $Employees ->employee_id,
            $Employees ->prefix,
            $Employees ->first_name,
            $Employees ->last_name,
            $Employees ->middle_name,
            $Employees ->email_address,
            $Employees ->gender,
            $Employees ->role,
            $Employees ->business_unit,
            $Employees ->department,
            $Employees ->job_title,
            $Employees ->employment_status,
            Date::PHPToExcel($Employees -> date_of_joining),
            Date::PHPToExcel($Employees -> date_of_leaving),
            $Employees ->years_of_experience,
            $Employees ->work_phone,
            $Employees ->personal_phone,
            $Employees ->extension,
            $Employees ->kra_pin,
            $Employees ->nssf_number,
            $Employees ->nhif_number,
            $Employees ->ifmis_number,
            $Employees ->reporting_manager,
            $Employees ->duration,
        ];
    }
    public function columnFormats(): array
    {
        return [
            'M' => NumberFormat::FORMAT_DATE_YYYYMMDD2,//dateofjoining column
            'N' => NumberFormat::FORMAT_DATE_YYYYMMDD2,//dateofleaving column
        ];
    }
}
