<?php

namespace App\Filament\Resources\JurnalResource\Pages;

use App\Filament\Resources\JurnalResource;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\Select;
use Filament\Resources\Pages\ListRecords;

class ListJurnals extends ListRecords
{
    protected static string $resource = JurnalResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Action::make('printAll')
                ->label('Cetak Semua')
                ->icon('heroicon-o-printer')
                ->modal()
                ->modalHeading('Pilih Jurusan')
                ->modalDescription('Silakan pilih jurusan sebelum mencetak PDF')
                ->modalSubmitActionLabel('Cetak PDF')
                ->form([
                    Select::make('jurusan')
                        ->label('Jurusan')
                        ->options([
                            'Akuntansi' => 'Akuntansi',
                            'Manajemen Perkantoran' => 'Manajemen Perkantoran',
                        ])
                        ->native(false)
                        ->default('Akuntansi')
                        ->required()
                ])
                ->action(function (array $data) {
                    return redirect()->route('jurnal.download-pdf', ['jurusan' => $data['jurusan']]);
                }),
            Action::make('viewJurnal')
                ->label('Lihat Jurnal')
                ->icon('heroicon-o-eye')
                ->modal()
                ->modalHeading('Pilih Jurusan')
                ->form([
                    Select::make('jurusan')
                        ->options([
                            'Akuntansi' => 'Akuntansi',
                            'Manajemen Perkantoran' => 'Manajemen Perkantoran'
                        ])
                        ->native(false)
                        ->default('Akuntansi')
                ])
                ->action(function (array $data) {
                    $url = route('jurnal.view-pdf', $data);
                    return redirect($url);
                }),
            CreateAction::make(),
        ];
    }
}
