<?php

namespace App\Filament\Resources\Banners\Pages;

use App\Filament\Resources\Banners\BannerResource;
use Filament\Actions\Action; 
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Cache;

class CreateBanner extends CreateRecord
{
    protected static string $resource = BannerResource::class;

    // 1. TOMBOL SIMPAN (CREATE)
    // protected function getCreateFormAction(): Action
    // {
    //     // GANTI NAMA ACTION DARI 'create' JADI 'simpan' BIAR GAK BENTROK
    //     return Action::make('simpan') 
    //         ->label('Simpan Banner')
    //         ->action(fn () => $this->create()) // Tetap panggil fungsi create()
    //         ->requiresConfirmation()
    //         ->modalIcon('heroicon-o-check-circle')
    //         ->modalHeading('Simpan Data Banner?')
    //         ->modalDescription('Pastikan data sudah benar. Lanjutkan?')
    //         ->modalSubmitActionLabel('Ya, Simpan')
    //         ->keyBindings(['mod+s']);
    // }

    // 2. TOMBOL SIMPAN & BUAT LAGI
    // protected function getCreateAnotherFormAction(): Action
    // {
    //     // GANTI NAMA ACTION JADI 'simpanLagi'
    //     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');
    }

    protected function afterCreate(): void
    {
        Cache::forget('home_banners');
    }

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