<?php

namespace App\Filament\Pages;

use App\Settings\SuccessSettings;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\SettingsPage;
use Illuminate\Contracts\Support\Htmlable;

class ManageSuccess extends SettingsPage
{
    protected static ?string $navigationGroup = 'Home';

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

    protected static string $settings = SuccessSettings::class;

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make('Success Section Content')
                    ->description('Manage the main content for the success section.')
                    ->icon('heroicon-o-document-text')
                    ->schema([
                        TextInput::make('success_subtitle')
                            ->label('Subtitle')
                            ->required()
                            ->maxLength(100),
                        TextInput::make('success_header')
                            ->label('Header')
                            ->required()
                            ->maxLength(255),
                        Textarea::make('success_paragraph')
                            ->label('Paragraph')
                            ->required()
                            ->rows(3)
                            ->maxLength(65535),
                        Grid::make()->schema([
                            TextInput::make('success_button_text')
                                ->label('Button Text')
                                ->required()
                                ->maxLength(50),
                            TextInput::make('success_button_url')
                                ->label('Button URL')
                                ->required()
                                ->maxLength(255)
                                ->url(),
                        ])->columns(2),
                        FileUpload::make('success_image')
                            ->label('Image')
                            ->directory('cms')
                            ->image()
                            ->required(),
                    ]),
                Section::make('Skill Items')
                    ->description('Manage the skill items with their names and percentages.')
                    ->icon('heroicon-o-adjustments-vertical')
                    ->schema([
                        Repeater::make('skill_items')
                            ->label('Skill Items')
                            ->schema([
                                TextInput::make('name')
                                    ->label('Skill Name')
                                    ->required()
                                    ->maxLength(100),
                                TextInput::make('percentage')
                                    ->label('Percentage')
                                    ->numeric()
                                    ->required()
                                    ->minValue(0)
                                    ->maxValue(100),
                            ])
                            ->columns(2)
                            ->minItems(1)
                            ->maxItems(5)
                            ->defaultItems(2)
                            ->reorderable()
                            ->collapsible(),
                    ]),
            ])
            ->columns(1)
            ->statePath('data');
    }

    public static function getNavigationGroup(): ?string
    {
        return __('Home');
    }

    public static function getNavigationLabel(): string
    {
        return __('Success Section');
    }

    public function getTitle(): string|Htmlable
    {
        return 'Success Section';
    }

    public function getHeading(): string|Htmlable
    {
        return 'Edit success section content from here';
    }

    public function getSubheading(): string|Htmlable|null
    {
        return 'Manage the success section content, including text, button, and skill bars.';
    }
}
