<?php

namespace App\Filament\Resources\Abouts\Pages;

use App\Filament\Resources\Abouts\AboutResource;
use Filament\Actions\DeleteAction;
// use Filament\Actions\ViewAction;
use Filament\Actions\Action; 
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Cache;

class EditAbout extends EditRecord
{
    protected static string $resource = AboutResource::class;

    protected function getHeaderActions(): array
    {
        return [
            // ViewAction::make(),
            
            DeleteAction::make()
                ->after(function () {
                     // Hapus Cache saat dihapus
                     Cache::forget('home_abouts');
                     Cache::forget('about_page_content');
                }),
            
            // Tombol Kembali
            // Action::make('back')
            //     ->label('Kembali')
            //     ->url($this->getResource()::getUrl('index'))
            //     ->color('gray')
            //     ->icon('heroicon-m-arrow-left'),
        ];
    }

    // TOMBOL SIMPAN (UPDATE)
    protected function getSaveFormAction(): Action
    {
        return Action::make('simpanPerubahan')
            ->label('Simpan Perubahan')
            ->action(fn () => $this->save()) 
            ->requiresConfirmation()
            ->modalIcon('heroicon-o-check-circle')
            ->modalHeading('Simpan Perubahan?')
            ->modalDescription('Apakah Anda yakin ingin memperbarui data ini?')
            ->modalSubmitActionLabel('Ya, Update')
            ->keyBindings(['mod+s']);
    }

    // HAPUS CACHE SETELAH EDIT
    protected function afterSave(): void
    {
        Cache::forget('home_abouts');
        Cache::forget('about_page_content');
    }

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