<?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 StudentsExport implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize
{
    public function __construct(private Collection $rows) {}

    public function collection(): Collection
    {
        return $this->rows->map(fn ($r) => [
            $r->student_code ?? '',
            $r->first_name ?? '',
            $r->last_name ?? '',
            $r->mobile ?? '',
            $r->father_mobile ?? '',
            $r->mother_mobile ?? '',
            $r->home_phone ?? '',
            $r->grade ?? '',
            $r->status ?? '',
        ]);
    }

    public function headings(): array
    {
        return ['کد دانش‌آموزی', 'نام', 'نام خانوادگی', 'موبایل', 'موبایل پدر', 'موبایل مادر', 'تلفن خانه', 'پایه', 'وضعیت'];
    }

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