<?php

namespace App\Filament\Resources\TrustBadges;

use App\Filament\Resources\TrustBadges\Pages\ManageTrustBadges;
use App\Models\TrustBadge;
use BackedEnum;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

use Filament\Forms\Components\Select;
use Filament\Schemas\Components\Section;

class TrustBadgeResource extends Resource
{
    protected static ?string $model = TrustBadge::class;

    protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-shield-check';

    protected static string|\UnitEnum|null $navigationGroup = 'Site Builder';

    protected static ?int $navigationSort = 4;

    protected static ?string $recordTitleAttribute = 'title';

    public static function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Trust Badge Details')
                    ->description('Specify the trust badge text, icon, and display order.')
                    ->schema([
                        TextInput::make('title')
                            ->label('Title')
                            ->required()
                            ->placeholder('e.g. Free Delivery'),
                        TextInput::make('description')
                            ->label('Description')
                            ->required()
                            ->placeholder('e.g. For all orders above ৳1000'),
                        Select::make('icon')
                            ->label('Icon Representation')
                            ->required()
                            ->options([
                                'Truck' => 'Delivery Truck',
                                'ShieldCheck' => 'Secure Payment / Trust Shield',
                                'Clock' => '24/7 Support Clock',
                                'RotateCcw' => 'Easy Return Arrow',
                                'Heart' => 'Heart Favorite',
                                'Percent' => 'Discount / Offer Percentage',
                                'Star' => 'Top Rated Star',
                            ])
                            ->default('Truck'),
                        TextInput::make('sort_order')
                            ->label('Sort Order')
                            ->numeric()
                            ->default(0)
                            ->required(),
                        Toggle::make('is_active')
                            ->label('Active on Storefront')
                            ->default(true)
                            ->required(),
                    ])->columns(2)
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('title')
            ->columns([
                TextColumn::make('title')
                    ->searchable(),
                TextColumn::make('description')
                    ->searchable(),
                TextColumn::make('icon')
                    ->searchable(),
                TextColumn::make('sort_order')
                    ->numeric()
                    ->sortable(),
                IconColumn::make('is_active')
                    ->boolean(),
                TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('updated_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getPages(): array
    {
        return [
            'index' => ManageTrustBadges::route('/'),
        ];
    }
}
