<?php

namespace App\Filament\Resources\HeroBannerTexts\Pages;

use App\Filament\Resources\HeroBannerTexts\HeroBannerTextResource;
use Filament\Actions\DeleteAction;
use Filament\Actions\ViewAction;
use Filament\Actions\Action; // Penting: Import Action untuk custom tombol
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Cache; // Penting: Import Cache

class EditHeroBannerText extends EditRecord
{
    protected static string $resource = HeroBannerTextResource::class;

    protected function getHeaderActions(): array
    {
        return [
            ViewAction::make(),
            DeleteAction::make()
                ->after(function () {
                    // Hapus Cache saat tombol Hapus di-klik
                    Cache::forget('home_hero_text');
                }),
        ];
    }

    // KUSTOMISASI TOMBOL SIMPAN (Agar ada konfirmasi seperti contohmu)
    protected function getSaveFormAction(): Action
    {
        return Action::make('save')
            ->label('Simpan Perubahan')
            ->action(fn () => $this->save())
            ->requiresConfirmation()
            ->modalIcon('heroicon-o-check-circle')
            ->modalHeading('Simpan Perubahan?')
            ->modalDescription('Yakin ingin mengubah data banner ini?')
            ->modalSubmitActionLabel('Ya, Update')
            ->keyBindings(['mod+s']);
    }

    // HAPUS CACHE SETELAH BERHASIL EDIT/SIMPAN
    protected function afterSave(): void
    {
        Cache::forget('home_hero_text');
    }

    // Redirect kembali ke halaman list setelah simpan
    protected function getRedirectUrl(): string
    {
        return $this->getResource()::getUrl('index');
    }
}