<?php

namespace App\Filament\Resources\SerahTerimaResource\Pages;

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

class EditSerahTerima extends EditRecord
{
    protected static string $resource = SerahTerimaResource::class;

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

    protected function afterSave(): void
    {
        $recipient = Auth::user();

        $title = $this->record->status === 'menerima' 
            ? 'Penerimaan Berhasil Diperbarui' 
            : 'Penyerahan Berhasil Diperbarui';

        $body = $this->record->status === 'menerima'
            ? "Penerimaan untuk {$this->record->nama_penerima} berhasil diperbarui"
            : "Penyerahan kepada {$this->record->nama_penerima} berhasil diperbarui";

        Notification::make()
            ->title($title)
            ->success()
            ->body($body)
            ->sendToDatabase($recipient);
    }

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

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