<?php

namespace App\Exports;

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

/**
 * Excel export for the enquiry weekday / time-of-day trend reports. Both share the same
 * {label, enquiry_count} row shape, so the only per-report difference is the first-column heading
 * (e.g. "Day" vs "Hour").
 */
class EnquiryTimingBreakdownExport implements FromCollection, WithHeadings, ShouldAutoSize, NullComparison, WithStyles
{
    public function __construct(protected Collection $data, protected string $bucketHeading)
    {
        //
    }

    public function collection(): Enumerable
    {
        return $this->data;
    }

    /**
     * Heading row
     *
     * @return string[]
     */
    public function headings(): array
    {
        return [
            $this->bucketHeading,
            __('labels.total'),
        ];
    }

    public function styles(Worksheet $sheet)
    {
        $last_row = $this->data->count() + 1;
        $sheet->getStyle('A1:B1')->getFont()->setBold(true);
        $sheet->getStyle('A1:A' . $last_row)->getFont()->setBold(true);
        $sheet->setSelectedCell('A1');
    }
}
