<?php

namespace App\Filament\Resources\JadwalPerawatanResource\Pages;

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

class CreateJadwalPerawatan extends CreateRecord
{
    protected static string $resource = JadwalPerawatanResource::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('Jadwal Perawatan Berhasil Dibuat')
            ->success()
            ->body("Jadwal Perawatan {$this->record->jenisPerawatan->nama} berhasil dibuat")
            ->sendToDatabase($recipient);
    }

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