<?php

namespace App\Filament\Resources\Services\Tables;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Cache;

class ServicesTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('title')
                    ->label('Nama Layanan') 
                    ->searchable(),
                ImageColumn::make('image')
                    ->label('Icon') 
                    ->disk('public'),
                TextColumn::make('creator.name')
                    ->label('Dibuat Oleh') 
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('editor.name')
                    ->label('Diubah Oleh') 
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('created_at')
                    ->label('Dibuat Pada') 
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('updated_at')
                    ->label('Diubah Pada') 
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->actions([
                EditAction::make(),
                
                // TAMBAHAN: DELETE DENGAN HAPUS CACHE
                DeleteAction::make()
                    ->after(function () {
                        Cache::forget('home_services');
                        Cache::forget('services_page_list');
                        Cache::forget('services_sidebar_list');
                    }),
            ])
             ->bulkActions([
                BulkActionGroup::make([
                    // TAMBAHAN: BULK DELETE DENGAN HAPUS CACHE
                    DeleteBulkAction::make()
                        ->after(function () {
                            Cache::forget('home_services');
                            Cache::forget('services_page_list');
                            Cache::forget('services_sidebar_list');
                        }),
                ]),
            ]);
    }
}