<?php

namespace App\Filament\Resources;

use App\Filament\Resources\SolutionResource\Pages;
use App\Models\Solution;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;

class SolutionResource extends Resource
{
    protected static ?string $model = Solution::class;

    protected static ?string $navigationGroup = 'Settings';

    protected static ?string $navigationIcon = 'heroicon-o-light-bulb';

    protected static ?string $title = 'Solutions';

    protected static ?string $navigationLabel = 'Solutions';

    protected static ?string $slug = 'solutions';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Select::make('solution_group_id')
                    ->relationship('solutionGroup', 'name')
                    ->required()
                    ->searchable(),
                Forms\Components\TextInput::make('name')
                    ->label('Nom de la solution')
                    ->required()
                    ->maxLength(255),
                Forms\Components\Toggle::make('recommended')
                    ->label('Recommandé')
                    ->required(),
                Forms\Components\Toggle::make('is_active')
                    ->label('Active')
                    ->default(true)
                    ->required(),
                Forms\Components\TextInput::make('nb_panneaux')
                    ->type('number')
                    ->required(),
                Forms\Components\TextInput::make('potentiel_economie')
                    ->label('Potentiel economies (en Dh)')
                    ->type('number')
                    ->required(),
                Forms\Components\Textarea::make('short_description')
                    ->label('Description courte')
                    ->required()
                    ->maxLength(65535),
                Forms\Components\RichEditor::make('full_description')
                    ->label('Description complète')
                    ->required()
                    ->maxLength(65535)
                    ->columnSpanFull(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('solutionGroup.name'),
                Tables\Columns\TextColumn::make('name')
                    ->label('Solution'),
                Tables\Columns\IconColumn::make('is_active')
                    ->label('Active')
                    ->boolean(),
                Tables\Columns\IconColumn::make('recommended')
                    ->label('Recommandé')
                    ->boolean(),
                Tables\Columns\TextColumn::make('nb_panneaux'),
                Tables\Columns\TextColumn::make('short_description')
                    ->label('Description courte'),
                Tables\Columns\TextColumn::make('potentiel_economie'),
                Tables\Columns\TextColumn::make('created_at')
                    ->dateTime(),
                Tables\Columns\TextColumn::make('updated_at')
                    ->dateTime(),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\DeleteBulkAction::make(),
            ]);
    }

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