<?php

namespace App\Filament\Resources\Publication\News\Tables;

use App\Filament\Actions\DefaultBulkActions;
use App\Filament\Columns\TimestampColumns;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;

class NewsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('title')
                    ->label('Judul')
                    ->searchable()
                    ->sortable()
                    ->wrap()
                    ->limit(50),

                TextColumn::make('author.name')
                    ->label('Penulis')
                    ->searchable()
                    ->sortable()
                    ->placeholder('Tidak ada'),

                TextColumn::make('view')
                    ->label('Dilihat')
                    ->numeric()
                    ->sortable()
                    ->alignCenter(),

                TextColumn::make('categories.name')
                    ->label('Kategori')
                    ->listWithLineBreaks()
                    ->limitList(3)
                    ->expandableLimitedList()
                    ->badge()
                    ->placeholder('Tidak ada tag'),

                TextColumn::make('tags.name')
                    ->label('Tag')
                    ->listWithLineBreaks()
                    ->limitList(3)
                    ->expandableLimitedList()
                    ->badge()
                    ->placeholder('Tidak ada tag'),

                TextColumn::make('link')
                    ->label('Tautan')
                    ->searchable()
                    ->sortable()
                    ->copyable()
                    ->copyMessage('Tautan berhasil disalin')
                    ->placeholder('Tidak ada')
                    ->toggleable(isToggledHiddenByDefault: true),

                TextColumn::make('status')
                    ->label('Status')
                    ->searchable()
                    ->sortable()
                    ->badge()
                    ->formatStateUsing(fn ($state) => $state->getLabel())
                    ->color(fn ($state) => $state->getColor()),

                TextColumn::make('published_at')
                    ->label('Tgl Publish')
                    ->searchable()
                    ->sortable()
                    ->date('l, d F Y H:i')
                    ->toggleable(isToggledHiddenByDefault: true),

                ...TimestampColumns::make(),
            ])
            ->filters([
                TrashedFilter::make()->native(false),
            ])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
                ForceDeleteAction::make(),
                RestoreAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    ...DefaultBulkActions::make('Berita'),
                ]),
            ])
            ->emptyStateIcon(Heroicon::Newspaper)
            ->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.')
            ->defaultSort('created_at', 'desc')
            ->deferFilters(false);
    }
}
