<?php

namespace App\Filament\Resources;

use App\Enums\Language;
use App\Enums\WordStatus;
use App\Filament\Resources\WordResource\Pages;
use App\Models\Category;
use App\Models\Word;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;

class WordResource extends Resource
{
    protected static ?string $model = Word::class;

    protected static ?string $navigationIcon = 'heroicon-o-book-open';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make('User Details')->schema([
              TextInput::make('word')
                    ->required()
                    ->maxLength(255),

                TextInput::make('part_of_speech')
                    ->maxLength(100),

                
                    Select::make('language')
                    ->options(Language::class)
                     ->required(),

                 Forms\Components\Textarea::make('meaning')
                    ->rows(3),

                Textarea::make('synonyms')
    ->label('Synonyms')
    ->rows(3)
    ->nullable(),
               Textarea::make('examples')
                    ->rows(3),

                Textarea::make('translations')
                ->label('Translations')
                ->rows(4)
                ->nullable(),
                Select::make('status')
                    ->options(WordStatus::class)
                    ->required(),
                ]),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('word')->searchable()->sortable(),
                Tables\Columns\TextColumn::make('part_of_speech')->sortable(),
                Tables\Columns\TextColumn::make('language'),
                TextColumn::make('status')
                ->badge(),
                Tables\Columns\TextColumn::make('user.name')
    ->label('Added by')
    ->sortable(),

                
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListWords::route('/'),
            'create' => Pages\CreateWord::route('/create'),
            'edit' => Pages\EditWord::route('/{record}/edit'),
        ];
    }
    
}
