<?php

namespace App\Exports;

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

class MenuSalesReportExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize
{
    public function __construct(private readonly Collection $rows)
    {
    }

    public function collection(): Collection
    {
        return $this->rows;
    }

    public function headings(): array
    {
        return [
            'Menu',
            'Harga Pokok',
            'Harga Jual',
            'Total Qty',
            'Total Penjualan',
        ];
    }

    public function map($row): array
    {
        return [
            $row->nama,
            (float) ($row->menu_harga_pokok ?? 0),
            (float) ($row->menu_harga_jual ?? 0),
            (int) $row->total_qty,
            (float) $row->total_sales,
        ];
    }
}
