<?php

namespace App\Filament\Resources\Etablissements\Tables;

use App\Actions\DownloadTemplateAction;
use App\Actions\ExportExcelAction;
use App\Actions\ImportExcelAction;
use App\Imports\EtablissementImport;
use App\Exports\EtablissementExport;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class EtablissementsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('libellear')
                    ->searchable(),
                TextColumn::make('libellefr')
                    ->searchable(),
                TextColumn::make('cycle.id')
                    ->searchable(),
                TextColumn::make('commune.id')
                    ->searchable(),
                TextColumn::make('code')
                    ->searchable(),
                TextColumn::make('latitude')
                    ->numeric()
                    ->sortable(),
                TextColumn::make('longitude')
                    ->numeric()
                    ->sortable(),
                TextColumn::make('date_creation')
                    ->searchable(),
                TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('updated_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                ImportExcelAction::makeImport(EtablissementImport::class),
                ExportExcelAction::makeExport(EtablissementExport::class, 'etablissements_export.xlsx'),
                DownloadTemplateAction::makeTemplate('etablissement', 'template_etablissements.xlsx'),
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
}
