<?php

namespace App\Exports;

use App\Models\DeviceResultModel;
use Maatwebsite\Excel\Concerns\FromCollection;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

class LaporanHasilPerhitunganExport implements FromView, ShouldAutoSize
{
    /**
     * @return \Illuminate\Support\Collection
     */
    public $awal;
    public $akhir;
    public $device;
    public $nama_device;

    public function __construct($awal, $akhir, $device, $nama_device)
    {
        $this->awal = $awal;
        $this->akhir = $akhir;
        $this->device = $device;
        $this->nama_device = $nama_device;
    }


    public function view(): View
    {
        return view('/content/hasil_perhitungan/excel', [
            'result' => DeviceResultModel::where("uuid_device", $this->device)->whereBetween('created', [$this->awal, $this->akhir])->get(),
            'nama_device'   =>  $this->nama_device,
            'awal'  =>  $this->awal,
            'akhir' =>  $this->akhir,
        ]);
    }
}
