<?php

namespace App\Filament\Resources\HeroSlides;

use App\Filament\Resources\HeroSlides\Pages\ManageHeroSlides;
use App\Models\HeroSlide;
use BackedEnum;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Textarea;
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\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class HeroSlideResource extends Resource
{
    protected static ?string $model = HeroSlide::class;

    protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPhoto;

    protected static ?string $navigationLabel = 'Hero Slaýdlary';

    protected static string|\UnitEnum|null $navigationGroup = 'Sahypa mazmunu';

    protected static ?int $navigationSort = 1;

    public static function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextInput::make('headline')
                    ->label('Sözbaşy')
                    ->required()
                    ->columnSpanFull(),
                Textarea::make('subheadline')
                    ->label('Ikinji sözbaşy')
                    ->rows(2)
                    ->columnSpanFull(),
                TextInput::make('cta_label')
                    ->label('Düwme ýazgysy'),
                TextInput::make('cta_url')
                    ->label('Düwme URL')
                    ->url(),
                FileUpload::make('image')
                    ->label('Surat')
                    ->image()
                    ->disk('public')
                    ->directory('hero-slides')
                    ->columnSpanFull(),
                TextInput::make('sort_order')
                    ->label('Tertip')
                    ->required()
                    ->numeric()
                    ->default(0),
                Toggle::make('is_active')
                    ->label('Işjeň')
                    ->default(true),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                ImageColumn::make('image')
                    ->label('Surat')
                    ->disk('public')
                    ->circular(),
                TextColumn::make('headline')
                    ->label('Sözbaşy')
                    ->searchable()
                    ->limit(40),
                TextColumn::make('cta_label')
                    ->label('Düwme')
                    ->searchable(),
                TextColumn::make('sort_order')
                    ->label('Tertip')
                    ->numeric()
                    ->sortable(),
                IconColumn::make('is_active')
                    ->label('Işjeň')
                    ->boolean(),
                TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->defaultSort('sort_order')
            ->filters([])
            ->recordActions([
                EditAction::make(),
                DeleteAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }

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