<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class StockVerificationExport implements FromCollection, WithHeadings, WithMapping, WithStyles
{
    protected $inventories;

    public function __construct($inventories)
    {
        $this->inventories = $inventories;
    }

    public function collection()
    {
        return collect($this->inventories);
    }

    public function headings(): array
    {
        return [
            'Item Name',
            'Category',
            'Unit',
            'Unit Price',
            'Total Quantity',
            'Transferred Quantity',
            'Available Quantity',
            'Total Value',
            'Available Value'
        ];
    }

    public function map($inventory): array
    {
        return [
            $inventory['item_name'],
            $inventory['category'] ?? '',
            $inventory['item_unit'],
            $inventory['unit_price'],
            $inventory['total_quantity'],
            $inventory['transferred_quantity'],
            $inventory['available_quantity'],
            $inventory['total_value'],
            $inventory['available_value'],
        ];
    }

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

