<?php

namespace App\Filament\Pages;

use App\Models\Plugin;
use BackedEnum;
use Filament\Pages\Page;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use UnitEnum;

class Plugins extends Page implements Tables\Contracts\HasTable
{
    use Tables\Concerns\InteractsWithTable;

    protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-puzzle-piece';

    protected static string|UnitEnum|null $navigationGroup = 'Plugins';

    protected static ?string $navigationLabel = 'Plugin List';

    protected static ?string $title = 'Plugins';

    protected string $view = 'filament.pages.plugins';

    protected static ?string $slug = 'list-plugins';

    public static function getNavigationGroup(): ?string
    {
        return __('filament.navigation.groups.plugins');
    }

    public static function getNavigationLabel(): string
    {
        return __('filament.navigation.plugin_list');
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->label(__('Name'))
                    ->searchable()
                    ->sortable(),
                TextColumn::make('identifier')
                    ->label(__('Identifier'))
                    ->searchable()
                    ->sortable(),
                IconColumn::make('enabled')
                    ->label(__('Enabled'))
                    ->boolean(),
                IconColumn::make('configured')
                    ->label(__('Configured'))
                    ->boolean(),
            ])
            ->records(fn () => Plugin::getAllPlugins())
            ->paginated(false)
            ->emptyStateHeading(__('No plugins found'))
            ->emptyStateDescription(__('Drop PHP plugin files into app/Api/Plugins (excluding ApiPluginInterface.php).'));
    }
}
