<?php

namespace App\Filament\Resources\Monitoring\ContentRecaps\Schemas;

use App\Enums\Channel;
use App\Enums\ContentType;
use App\Enums\SocialMedia;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;

class ContentRecapForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make([
                    TextInput::make('title')
                        ->label('Judul')
                        ->placeholder('Reels Kerja Sama DPMPTSP')
                        ->autocomplete(false)
                        ->autofocus()
                        ->required()
                        ->maxLength(1000),

                    TextInput::make('link')
                        ->label('Tautan')
                        ->placeholder('https://www.pwknews.com')
                        ->autocomplete(false)
                        ->nullable()
                        ->maxLength(255)
                        ->url(),

                    Grid::make(2)
                        ->schema([
                            Select::make('type')
                                ->label('Tipe')
                                ->options(ContentType::options())
                                ->native(false)
                                ->in(implode(',', array_column(ContentType::cases(), 'value'))),

                            Select::make('channel')
                                ->label('Kanal')
                                ->options(Channel::options())
                                ->native(false)
                                ->required()
                                ->in(implode(',', array_column(Channel::cases(), 'value'))),

                            Select::make('social_media')
                                ->label('Media Sosial')
                                ->options(SocialMedia::options())
                                ->native(false)
                                ->required()
                                ->in(implode(',', array_column(SocialMedia::cases(), 'value'))),

                            DatePicker::make('posting_date')
                                ->label('Tanggal Posting')
                                ->placeholder(fn (): string => now()->translatedFormat('l, d F Y'))
                                ->native(false)
                                ->displayFormat('l, d F Y')
                                ->required(),
                        ]),
                ])->columnSpan(2),

                Section::make([
                    Select::make('classification_id')
                        ->label('Klasifikasi')
                        ->relationship('classification', 'name', function (Builder $query): Builder {
                            return $query->active();
                        })
                        ->native(false)
                        ->preload()
                        ->required(),

                    SpatieMediaLibraryFileUpload::make('image')
                        ->label('Gambar')
                        ->disk(config('filesystems.default'))
                        ->acceptedFileTypes(['image/*'])
                        ->maxSize(1024 * 3)
                        ->collection('content-recpaps')
                        ->customProperties(fn (): array => [
                            'feature' => 'content-recaps',
                            'date' => now()->toDateString(),
                        ])
                        ->image()
                        ->required(),
                ]),
            ])
            ->columns(3);
    }
}
