<?php

namespace App\Filament\Resources\Cities\Pages;

use App\Filament\Resources\Cities\CityResource;
use Filament\Actions\Action; 
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Cache;

class CreateCity extends CreateRecord
{
    protected static string $resource = CityResource::class;

    // 1. TOMBOL SIMPAN (CREATE)
    protected function getCreateFormAction(): Action
    {
        return Action::make('simpan') 
            ->label('Simpan Kota')
            ->action(fn () => $this->create()) 
            ->requiresConfirmation()
            ->modalIcon('heroicon-o-check-circle')
            ->modalHeading('Simpan Data Kota?')
            ->modalDescription('Pastikan Nama dan Tipe Kota 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');
    }

    // 3. HAPUS CACHE 'home_origins'
    protected function afterCreate(): void
    {
        // Ini PENTING BANGET karena data kota di-cache 24 jam di Controller
        Cache::forget('home_origins');
    }

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