<?php

namespace App\Filament\Resources\KelasResource\Pages;

use App\Filament\Resources\KelasResource;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class CreateKelas extends CreateRecord
{
    protected static string $resource = KelasResource::class;

    protected function getCreatedNotification(): ?Notification
    {
        return null;
    }
    
    protected function afterCreate(): void
    {
        $recipient = Auth::user();

        if (!$recipient) {
            Log::error('No authenticated user available for notification');
            return;
        }

        Notification::make()
            ->title('Kelas Berhasil Dibuat')
            ->success()
            ->body("Kelas {$this->record->nama_kelas} berhasil dibuat")
            ->sendToDatabase($recipient);
    }

    protected function getRedirectUrl(): string
    {
        return $this->getResource()::getUrl('index');
    }
}
