<?php
namespace App\Modules\HR\Reports\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Illuminate\Support\Collection;

class PayrollSignatureExport implements FromCollection, WithHeadings
{
    protected $data;
    protected $currency;

    public function __construct($data, $currency = null)
    {
        $this->data = $data['employees'];
        $this->currency = $currency;
    }

    public function collection()
    {
        $rows = [];

        foreach ($this->data as $item) {
            $rows[] = [
                $item['employee_code'],
                $item['epf_no'],
                $item['employee_name'],
                $item['department'],
                $item['designation'],
                number_format($item['net_salary'], 2),
                '', // Signature column (empty for manual signing)
            ];
        }

        return collect($rows);
    }

    public function headings(): array
    {
        return [
            'Employee Code',
            'EPF No',
            'Employee Name',
            'Department',
            'Designation',
            'Net Salary (' . ($this->currency ?? 'Rs.') . ')',
            'Signature',
        ];
    }
}
