<?php

namespace App\Filament\Resources\Promos\Pages;

use App\Filament\Resources\Promos\PromoResource;
use Filament\Actions\Action; 
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Cache;

class CreatePromo extends CreateRecord
{
    protected static string $resource = PromoResource::class;

    // 1. TOMBOL SIMPAN (CREATE)
    // protected function getCreateFormAction(): Action
    // {
    //     return Action::make('simpan') 
    //         ->label('Simpan Promo')
    //         ->action(fn () => $this->create()) 
    //         ->requiresConfirmation()
    //         ->modalIcon('heroicon-o-check-circle')
    //         ->modalHeading('Simpan Data Promo?')
    //         ->modalDescription('Pastikan data promo (Judul, Gambar, Tanggal) sudah benar.')
    //         ->modalSubmitActionLabel('Ya, Simpan')
    //         ->keyBindings(['mod+s']);
    // }

    // 2. TOMBOL SIMPAN & BUAT LAGI
    // protected function getCreateAnotherFormAction(): Action
    // {
    //     return Action::make('simpanLagi') 
    //         ->label('Simpan & Buat Lagi')
    //         ->action(fn () => $this->createAnother()) 
    //         ->color('gray')
    //         ->requiresConfirmation()
    //         ->modalIcon('heroicon-o-plus-circle')
    //         ->modalHeading('Simpan & Buat Lagi?')
    //         ->modalSubmitActionLabel('Ya, Lanjut');
    // }

     protected function getCreateFormAction(): Action
    {
     
        return parent::getCreateFormAction() 
            ->label('Simpan') 
            ->submit('create') 
            ->keyBindings(['mod+s']); 
    }


    protected function getCreateAnotherFormAction(): Action
    {
        return parent::getCreateAnotherFormAction() 
            ->label('Simpan & Buat Lagi');
    }

    // 3. HAPUS CACHE (Sapu Bersih Semua Tempat Promo Muncul)
    protected function afterCreate(): void
    {
        Cache::forget('home_promos');       // Di Home
        Cache::forget('promos_page_list');  // Di Halaman List Promo
        Cache::forget('promos_sidebar_all');// Di Sidebar Detail & Menu Header
    }

    // 4. REDIRECT KE LIST
    protected function getRedirectUrl(): string
    {
        return $this->getResource()::getUrl('index');
    }
}