<?php

namespace App\Http\Controllers;

use App\Models\Jurnal;
use Barryvdh\DomPDF\Facade\Pdf;

class JurnalController extends Controller
{
    public function viewJurnalPDF($jurusan = 'Akuntansi')
    {
        $jurnals = Jurnal::all();
        
        $filename = 'Jurnal_Kegiatan_' . str_replace(' ', '-', $jurusan) . '.pdf';
        
        $pdf = Pdf::loadView('jurnal.jurnal', [
            'jurnals' => $jurnals,
            'title' => 'JURNAL KEGIATAN<br>LABORAN ' . strtoupper($jurusan),
            'subtitle' => 'SMK NEGERI 1 BONDOWOSO'
        ]);

        return $pdf->setPaper('a4', 'potrait')->stream($filename);
    }

    public function downloadJurnalPDF($jurusan)
    {
        $jurnals = Jurnal::all();
        
        $filename = 'Jadwal_Praktik_' . str_replace(' ', '-', $jurusan) . '.pdf';
        
        $pdf = Pdf::loadView('jurnal.jurnal', [
            'jurnals' => $jurnals,
            'title' => 'JURNAL KEGIATAN<br>LABORAN ' . strtoupper($jurusan),
            'subtitle' => 'SMK NEGERI 1 BONDOWOSO'
        ]);

        return $pdf->setPaper('a4', 'potrait')->download($filename);
    }
}
