<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class TeachersExport implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize
{
    public function __construct(private Collection $rows) {}

    public function collection(): Collection
    {
        return $this->rows->map(fn ($r) => [
            $r->teacher_code ?? '',
            $r->first_name ?? '',
            $r->last_name ?? '',
            $r->mobile ?? '',
            $r->email ?? '',
            $r->specialty ?? '',
            $r->status ?? '',
        ]);
    }

    public function headings(): array
    {
        return ['کد معلم', 'نام', 'نام خانوادگی', 'موبایل', 'ایمیل', 'تخصص', 'وضعیت'];
    }

    public function styles(Worksheet $sheet): array
    {
        return [
            1 => ['font' => ['bold' => true]],
        ];
    }
}
