<?php

namespace App\Filament\Resources;

use App\Filament\Resources\ContactUsResource\Pages;
use App\Filament\Resources\ContactUsResource\RelationManagers;
use App\Models\ContactUs;
use Filament\Forms;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class ContactUsResource extends Resource
{
    protected static ?string $model = ContactUs::class;

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

    protected static ?string $pluralModelLabel = 'Contact Us';

    // protected static ?string $navigationGroup = 'Contact Us';

    public static function getNavigationBadge(): ?string
    {
        return ContactUs::get()->count();
    }

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('first_name'),
                TextInput::make('last_name'),
                TextInput::make('email'),
                TextInput::make('phone'),
                RichEditor::make('message'),
                Checkbox::make('agree')
                    ->columnSpanFull(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('first_name')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                TextColumn::make('last_name')
                    ->alignCenter()
                    ->searchable()
                    ->sortable(),
                TextColumn::make('email')
                    ->wrap()
                    ->words(17)
                    ->alignCenter()
                    ->toggleable(),
                TextColumn::make('phone')
                    ->wrap()
                    ->words(17)
                    ->alignCenter()
                    ->toggleable(),
                TextColumn::make('message')
                    ->wrap()
                    ->words(17)
                    ->alignCenter()
                    ->toggleable()
                    ->toggledHiddenByDefault(),
                IconColumn::make('agree')
                    ->boolean()
                    ->alignCenter()
                    ->sortable(),
            ])->defaultSort('created_at', 'desc')

            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\ViewAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

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

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