<?php

namespace App\Filament\Resources;

use App\Filament\Resources\FaqResource\Pages;
use App\Filament\Resources\FaqResource\RelationManagers;
use App\Models\Faq;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class FaqResource extends Resource
{
    protected static ?string $model = Faq::class;


    protected static ?string $navigationIcon = 'heroicon-o-arrow-down-on-square-stack';
    protected static ?string $navigationGroup = 'Legal';
    public static function canCreate(): bool
    {
        return Faq::count() === 0;
    }


    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make()
                    ->columns(1)
                    ->schema([

                        TextInput::make('title')
                            ->required()
                            ->maxLength(255),

                        TextInput::make('description')
                            ->maxLength(255),

                        Repeater::make('question')
                            ->schema([
                                TextInput::make('question')
                                    ->label('Question')
                                    ->required(),
                                Textarea::make('answer')
                                    ->label('Answer')
                                    ->required(),
                            ])
                            ->columnSpanFull(),


                    ]),
                Section::make('Booking')
                    // ->collapsed()
                    ->collapsible()
                    ->columns(1)
                    ->schema([

                        TextInput::make('booking_title')
                            ->maxLength(255),

                        TextInput::make('booking_description')
                            ->maxLength(255),

                    ]),
                Section::make('Meta Data')
                    ->collapsed()
                    ->collapsible()
                    ->columns(1)
                    ->schema([
                        TextInput::make('meta_title')
                            ->maxLength(255),

                        TextInput::make('meta_description')
                            ->maxLength(255),

                        TextInput::make('meta_keyword')
                            ->maxLength(length: 255),
                    ]),
            ]);
    }


    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('title')
                    ->limit(15),
                TextColumn::make('description')
                    ->limit(15),
            ])
            ->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\ListFaqs::route('/'),
            'create' => Pages\CreateFaq::route('/create'),
            'edit' => Pages\EditFaq::route('/{record}/edit'),
        ];
    }
}
