<?php

namespace App\Filament\Resources\RekapanGuruResource\Pages;

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

class ListRekapanGurus extends ListRecords
{
    protected static string $resource = RekapanGuruResource::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('rekapan-guru.download-pdf', ['jurusan' => $data['jurusan']]);
                }),
            Action::make('viewRekapan')
                ->label('Lihat Rekapan')
                ->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('rekapan-guru.view-pdf', $data);
                    return redirect($url);
                }),
            CreateAction::make(),
        ];
    }
}
