<?php

namespace App\Filament\Resources\MapelResource\Pages;

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

class CreateMapel extends CreateRecord
{
    protected static string $resource = MapelResource::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('Mapel Berhasil Dibuat')
            ->success()
            ->body("Mapel {$this->record->nama_mapel} berhasil dibuat")
            ->sendToDatabase($recipient);
    }

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