<?php

namespace App\Filament\Resources\Footers\Schemas;

use Filament\Forms\Components\Builder;
use Filament\Forms\Components\Builder\Block;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class FooterForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make()
                ->schema([
                    Builder::make('links')
                        ->label('Odnośniki')
                        ->addActionLabel('Dodaj odnośnik')
                        ->collapsible()
                        ->collapsed()
                        ->reorderable()
                        ->blocks([
                            Block::make('link')
                                ->label(function (?array $state): string {
                                    if ($state === null) {
                                        return 'Odnośnik';
                                    }
                            
                                    return $state['name'] ?? 'Odnośnik';
                                })
                                ->schema([
                                    TextInput::make('name')
                                        ->label('Nazwa')
                                        ->required(),
                                    TextInput::make('icon')
                                        ->label('Ikona (FontAwesome)'),
                                    TextInput::make('link')
                                        ->label('Link')
                                        ->required(),
                                    Toggle::make('external')
                                        ->label('Zewnętrzny link')
                                        ->required(),
                                ])
                                ->columns(2),
                        ])
                ])
        ])->statePath('data');
    }
}
