<?php

namespace App\Filament\Pages;

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

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

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

    protected static string $settings = PortfolioSettings::class;

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make('Portfolio Section Content')
                    ->description('Manage the main content for the portfolio section.')
                    ->icon('heroicon-o-document-text')
                    ->schema([
                        TextInput::make('portfolio_header')
                            ->label('Header')
                            ->required()
                            ->maxLength(255),
                        Grid::make()->schema([
                            TextInput::make('portfolio_button_text')
                                ->label('Button Text')
                                ->required()
                                ->maxLength(50),
                            TextInput::make('portfolio_button_url')
                                ->label('Button URL')
                                ->required()
                                ->maxLength(255)
                                ->url(),
                        ])->columns(2),
                    ]),
                Section::make('Portfolio Items')
                    ->description('Manage individual portfolio items.')
                    ->icon('heroicon-o-photo')
                    ->schema([
                        Repeater::make('portfolio_items')
                            ->label('Portfolio Items')
                            ->schema([
                                FileUpload::make('image')
                                    ->label('Image (700x525)')
                                    ->image()
                                    ->maxSize(2048)
                                    ->disk('public')
                                    ->directory('portfolio-images')
                                    ->required(),
                                TextInput::make('category')
                                    ->label('Category')
                                    ->required()
                                    ->maxLength(100),
                                TextInput::make('title')
                                    ->label('Title')
                                    ->required()
                                    ->maxLength(255),
                                TextInput::make('link')
                                    ->label('Link')
                                    ->required()
                                    ->maxLength(255)
                                    ->url(),
                            ])
                            ->columns(2)
                            ->minItems(1)
                            ->maxItems(8)
                            ->defaultItems(4)
                            ->reorderable()
                            ->collapsible(),
                    ]),
            ])
            ->columns(1)
            ->statePath('data');
    }

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

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

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

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

    public function getSubheading(): string|Htmlable|null
    {
        return 'Manage the portfolio section content, including items, categories, and titles.';
    }
}
