<?php

namespace App\Filament\Resources;

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

class ApplynowInfoResource extends Resource
{
    protected static ?string $model = applynowInfo::class;

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

    protected static ?string $navigationLabel = 'Apply Now Info';
    protected static ?string $navigationGroup = 'Form Content and Data';

    protected static ?int $navigationSort = 4;

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

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

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

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

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

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

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

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Section::make('Basic Information')
                    ->schema([
                        Forms\Components\TextInput::make('title')
                            ->required()
                            ->maxLength(255),
                        Forms\Components\Textarea::make('text')

                            ->columnSpanFull(),
                    ]),


                Forms\Components\Section::make('Button Settings')
                    ->schema([
                        Forms\Components\TextInput::make('button_label')
                            ->maxLength(255),
                        Forms\Components\ColorPicker::make('button_color'),

                        Forms\Components\ColorPicker::make('button_background_color'),
                    ])
                    ->columns(3),

                Forms\Components\Section::make('FAQ Section')
                    ->schema([
                        Forms\Components\TextInput::make('faq_title')

                            ->maxLength(255),
                        Forms\Components\Repeater::make('faq_items')
                            ->schema([
                                Forms\Components\TextInput::make('question')

                                    ->maxLength(255)
                                    ->label('FAQ Question'),
                                Forms\Components\Textarea::make('answer')

                                    ->maxLength(65535)
                                    ->label('FAQ Answer'),
                            ])
                            ->columns(1)
                            ->defaultItems(1)
                            ->addActionLabel('Add Another FAQ')
                            ->reorderable()
                            ->collapsible(),
                    ]),
            ]);
    }

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

                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 applynowinfo')),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make()
                        ->visible(fn () => Gate::allows('delete applynowinfo')),
                ]),
            ]);
    }

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

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