<?php

namespace App\Exports\PeopleMessages;

use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;

class SupervisorCartableExcel implements FromView, WithEvents, ShouldAutoSize
{
    public function __construct(private ?Collection $data){}

    public function view(): View
    {
        return view('Reports.PeopleMessages.SupervisorCartableReport', [
            'data' => $this->data,
        ]);
    }

    public function registerEvents(): array
    {
        return [
            AfterSheet::class    => function (AfterSheet $event) {
                $event->sheet->getDelegate()->setRightToLeft(true);
                $event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial');
                $event->sheet->getDelegate()->getStyle('A:U')
                    ->getAlignment()
                    ->setHorizontal(Alignment::HORIZONTAL_CENTER);

                $event->sheet->getDelegate()->getStyle('A:U')
                    ->getAlignment()
                    ->setVertical(Alignment::VERTICAL_CENTER);
            }
        ];
    }

}
