<?php

namespace App\Filament\Resources\Promos\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 PromosTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->label('Judul Promo') 
                    ->searchable(),
                    
                ImageColumn::make('image')
                    ->label('Banner') 
                    ->disk('public'),
                    
                TextColumn::make('start_date')
                    ->label('Mulai Tanggal') 
                    ->date()
                    ->sortable(),
                    
                TextColumn::make('end_date')
                    ->label('Sampai Tanggal') 
                    ->date()
                    ->sortable(),
                    
                TextColumn::make('creator.name')
                    ->label('Dibuat Oleh') 
                    ->sortable(),
                    
                TextColumn::make('editor.name')
                    ->label('Diubah Oleh') 
                    ->sortable(),
                    
                TextColumn::make('created_at')
                    ->label('Dibuat Pada') 
                    ->dateTime()
                    ->sortable(),
                    
                TextColumn::make('updated_at')
                    ->label('Diubah Pada') 
                    ->dateTime()
                    ->sortable(),
            ])
            ->filters([
                //
            ])
           ->actions([
                EditAction::make(),
                
                DeleteAction::make()
                    ->after(function () {
                        Cache::forget('home_promos');
                         Cache::forget('promos_page_list');
                         Cache::forget('promos_sidebar_all');
                    }),
            ])
           ->bulkActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make()
                        ->after(function () {
                            Cache::forget('home_promos');
                            Cache::forget('promos_page_list');
                            Cache::forget('promos_sidebar_all');
                      
                        }),
                ]),
            ]);
    }
}