<?php

namespace App\Filament\Resources;

use App\Filament\Resources\VipLevelResource\Pages;
use App\Models\VipLevel;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class VipLevelResource extends Resource
{
    protected static ?string $model = VipLevel::class;

    protected static ?string $navigationIcon = 'heroicon-o-academic-cap';

    protected static ?string $navigationLabel = 'Niveles VIP';

    protected static ?string $modelLabel = 'Nivel VIP';

    protected static ?string $pluralModelLabel = 'Niveles VIP';

    protected static ?string $navigationGroup = 'Configuración de Sistema';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Section::make('Detalle del Nivel VIP')
                    ->schema([
                        Forms\Components\TextInput::make('name')
                            ->label('Identificador Interno (Minúsculas)')
                            ->required()
                            ->unique(ignoreRecord: true)
                            ->maxLength(255)
                            ->placeholder('ej: bronce, plata, oro, platino'),

                        Forms\Components\TextInput::make('display_name')
                            ->label('Nombre Visible')
                            ->required()
                            ->maxLength(255)
                            ->placeholder('ej: Bronce, Plata, VIP Oro'),

                        Forms\Components\TextInput::make('min_tickets')
                            ->label('Mínimo Boletos Comprados')
                            ->numeric()
                            ->required()
                            ->minValue(0)
                            ->default(0)
                            ->placeholder('Cantidad mínima de boletos requerida'),

                        Forms\Components\TextInput::make('bonus_multiplier')
                            ->label('Multiplicador de Puntos (Bono)')
                            ->numeric()
                            ->required()
                            ->minValue(1.00)
                            ->step(0.01)
                            ->default(1.00)
                            ->placeholder('ej: 1.25 representa 25% de puntos extra'),

                        Forms\Components\Textarea::make('description')
                            ->label('Descripción / Beneficios Exclusivos')
                            ->maxLength(255)
                            ->columnSpanFull(),
                    ])
                    ->columns(2),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('name')
                    ->label('Identificador')
                    ->searchable()
                    ->sortable(),

                Tables\Columns\TextColumn::make('display_name')
                    ->label('Nombre Visible')
                    ->searchable()
                    ->sortable(),

                Tables\Columns\TextColumn::make('min_tickets')
                    ->label('Mín. Boletos')
                    ->numeric()
                    ->sortable(),

                Tables\Columns\TextColumn::make('bonus_multiplier')
                    ->label('Bono Multiplicador')
                    ->numeric(decimalPlaces: 2)
                    ->suffix('x')
                    ->sortable(),

                Tables\Columns\TextColumn::make('description')
                    ->label('Beneficios')
                    ->limit(50),
            ])
            ->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\ListVipLevels::route('/'),
            'create' => Pages\CreateVipLevel::route('/create'),
            'edit' => Pages\EditVipLevel::route('/{record}/edit'),
        ];
    }
}
