<?php

namespace App\Filament\Resources;

use App\Filament\Resources\IndividualZoneResource\Pages;
use App\Models\IndividualZone;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Gate;

class IndividualZoneResource extends Resource
{
    protected static ?string $model = IndividualZone::class;

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

    protected static ?int $navigationSort = 6;
    protected static ?string $navigationGroup = 'Activities Content';

    public static function canViewAny(): bool
    {
        return Gate::allows('view individualzone');
    }

    public static function canView($record): bool
    {
        return Gate::allows('view individualzone');
    }

    public static function canCreate(): bool
    {
        return Gate::allows('create individualzone');
    }

    public static function canEdit($record): bool
    {
        return Gate::allows('edit individualzone');
    }

    public static function canDelete($record): bool
    {
        return Gate::allows('delete individualzone');
    }

    public static function canRestore($record): bool
    {
        return Gate::allows('restore individualzone');
    }

    public static function canForceDelete($record): bool
    {
        return Gate::allows('force delete individualzone');
    }

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('main_title')
                    ->required()
                    ->maxLength(255)
                    ->label('Main Title'),
                Forms\Components\TextInput::make('main_description')
                    ->required()
                    ->label('Main Description'),
                Forms\Components\FileUpload::make('main_images')
                    ->multiple()
                    ->image()

                    ->label('Main Image'),
                Forms\Components\ColorPicker::make('background_color')
                    ->label('Background Color'),
                Forms\Components\TextInput::make('game_count')
                    ->numeric()
                    ->label('Game Count'),
                Forms\Components\TextInput::make('second_title')
                    ->maxLength(255)
                    ->label('Second Title'),
                Forms\Components\TextInput::make('button_text')
                    ->maxLength(255)
                    ->label('Button Text'),
                Forms\Components\ColorPicker::make('button_color')
                    ->label('Button Color'),
                Forms\Components\ColorPicker::make('button_background_color')
                    ->label('Button Background Color'),
                Forms\Components\TextInput::make('club_articles_heading')
                    ->maxLength(255)
                    ->label('Club Articles Heading'),
                Forms\Components\TextInput::make('article_count')
                    ->numeric()
                    ->label('Article Count'),
                Forms\Components\TextInput::make('article_button_text')
                    ->maxLength(255)
                    ->label('Article Button Text'),
                Forms\Components\ColorPicker::make('article_button_color')
                    ->label('Article Button Color'),
                Forms\Components\ColorPicker::make('article_button_background_color')
                    ->label('Article Button Background Color'),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('main_title')
                    ->sortable()
                    ->searchable()
                    ->label('Main Title'),
                Tables\Columns\ImageColumn::make('main_image')
                    ->label('Main Image'),
                Tables\Columns\TextColumn::make('background_color')
                    ->label('Background Color'),
                Tables\Columns\TextColumn::make('game_count')
                    ->numeric()
                    ->sortable()
                    ->label('Game Count'),
                Tables\Columns\TextColumn::make('second_title')
                    ->sortable()
                    ->searchable()
                    ->label('Second Title'),
                Tables\Columns\TextColumn::make('button_text')
                    ->label('Button Text'),
                Tables\Columns\TextColumn::make('button_color')
                    ->label('Button Color'),
                Tables\Columns\TextColumn::make('button_background_color')
                    ->label('Button Background Color'),
                Tables\Columns\TextColumn::make('club_articles_heading')
                    ->label('Club Articles Heading'),
                Tables\Columns\TextColumn::make('article_count')
                    ->numeric()
                    ->sortable()
                    ->label('Article Count'),
                Tables\Columns\TextColumn::make('article_button_text')
                    ->label('Article Button Text'),
                Tables\Columns\TextColumn::make('article_button_color')
                    ->label('Article Button Color'),
                Tables\Columns\TextColumn::make('article_button_background_color')
                    ->label('Article Button Background Color'),
                Tables\Columns\TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                Tables\Columns\TextColumn::make('updated_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make()
                    ->visible(fn () => Gate::allows('edit individualzone')),
                Tables\Actions\DeleteAction::make()
                    ->visible(fn () => Gate::allows('delete individualzone')),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make()
                        ->visible(fn () => Gate::allows('delete individualzone')),
                ]),
            ]);
    }

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

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