<?php

declare(strict_types=1);

namespace TechnoArtisan\FilamentCms\Filament\Admin\Resources\WebsiteSettings\Tables;

use Filament\Actions\Action;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use TechnoArtisan\FilamentCms\Enums\PhpType;
use TechnoArtisan\FilamentCms\Models\WebsiteSettingGroup;

class WebsiteSettingsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
            TextColumn::make('group.name')
                ->label('Group')
                ->badge()
                ->searchable()
            ,
            TextColumn::make('identifier')
                ->limit(30)
                ->lineClamp(2)
                ->searchable()
            ,
            TextColumn::make('value_type')
                ->badge()
                ->toggleable(),
            TextColumn::make('value')
                ->toggleable()
            ,
            TextColumn::make('created_at')
                ->dateTime()
                ->sortable()
                ->toggleable(isToggledHiddenByDefault: true)
            ,
            TextColumn::make('updated_at')
                ->dateTime()
                ->sortable()
                ->toggleable(isToggledHiddenByDefault: true)
            ,
            ])
            ->filters([
                SelectFilter::make('group_id')
                    ->label('Group')
                    ->options(WebsiteSettingGroup::query()->pluck('name', 'id')),
                SelectFilter::make('value_type')
                    ->label('Value Type')
                    ->options(PhpType::class)
            ])
            // customize filter layout
            ->filtersTriggerAction(
                fn (Action $action) => $action
                    ->button()
                    ->label('Filter'),
            )
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ])

            // empty state heading and description
            ->emptyStateHeading('No (website) settings) available yet')
            ->emptyStateDescription('Once you create a (website) setting, it will appear here.')
        ;
    }
}
