<?php

declare(strict_types=1);

namespace App\Filament\Resources\Categories\Schemas;

use App\Support\MediaDisk;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class CategoryForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('基本信息')
                    ->columns(2)
                    ->schema([
                        TextInput::make('name')
                            ->label(__('category.name'))
                            ->required(),
                        TextInput::make('slug')
                            ->label(__('category.slug'))
                            ->helperText('留空自动生成'),
                        TextInput::make('display_order')
                            ->label(__('category.display_order'))
                            ->required()
                            ->numeric()
                            ->default(0),
                        TextInput::make('post_count')
                            ->label('文章数（自动统计）')
                            ->numeric()
                            ->disabled(),
                        Textarea::make('description')
                            ->label('分类介绍')
                            ->helperText('显示在分类列表页顶部，也用于 SEO description')
                            ->rows(4)
                            ->columnSpanFull(),
                    ]),
                Section::make('封面')
                    ->schema([
                        SpatieMediaLibraryFileUpload::make('cover')
                            ->label('封面图')
                            ->collection('cover')
                            ->image()
                            ->imageEditor()
                            ->disk(MediaDisk::name()),
                    ]),
            ]);
    }
}
