<?php

namespace App\Filament\Resources\JadwalPerawatanResource\Pages;

use App\Filament\Resources\JadwalPerawatanResource;
use Filament\Actions\DeleteAction;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class EditJadwalPerawatan extends EditRecord
{
    protected static string $resource = JadwalPerawatanResource::class;

    protected function getSavedNotification(): ?Notification
    {
        return null;
    }

    protected function afterSave(): void
    {
        $nama = $this->record->jenisPerawatan->nama;

        $recipient = Auth::user();

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

        Notification::make()
            ->title('Perubahan Data Jadwal Perawatan')
            ->success()
            ->body("Data jadwal perawatan {$nama} berhasil diperbarui")
            ->sendToDatabase($recipient);
    }

    protected function getHeaderActions(): array
    {
        return [
            DeleteAction::make(),
        ];
    }

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