<?php

namespace App\Filament\Resources;

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

class ApllyNowSubmissionResource extends Resource
{
    protected static ?string $model = ApllyNowSubmission::class;

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

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

    protected static ?int $navigationSort = 3;

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

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

    public static function canCreate(): bool
    {
        return false; // No create permission for submissions
    }

    public static function canEdit($record): bool
    {
        return false; // No edit permission for submissions
    }

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

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('firstName')
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('lastName')
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('country')
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('region')
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('phone_number')
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('email')
                    ->searchable()
                    ->sortable(),
                Tables\Columns\TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(),
            ])
            ->defaultSort('created_at', 'desc')
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\ViewAction::make()
                    ->visible(fn () => Gate::allows('view apllynowsubmission')),
                Tables\Actions\DeleteAction::make()
                    ->visible(fn () => Gate::allows('delete apllynowsubmission')),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make()
                        ->visible(fn () => Gate::allows('delete apllynowsubmission')),
                ]),
            ]);
    }

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

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListApllyNowSubmissions::route('/'),
            'view' => Pages\ViewApllyNowSubmission::route('/{record}'),
        ];
    }
}