<?php

namespace App\Filament\Resources\Manage\EggCollections\Schemas;

use App\Enums\ChickenStatus;
use App\Models\Chicken;
use Filament\Forms\Components\Textarea;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Illuminate\Support\Facades\Cache;

class EggCollectionForm
{
    public static function configure(Schema $schema): Schema
    {
        $chickens = Cache::store('redis')->remember(
            'active_chickens_for_egg_collection_form',
            now()->addMinutes(10),
            function () {
                return Chicken::query()
                    ->where('status', ChickenStatus::ACTIVE)
                    ->orderBy('tag_code')
                    ->get();
            }
        );

        return $schema
            ->components([
                Section::make('Informasi Produksi')
                    ->schema([
                        Grid::make(3)
                            ->schema([
                                Textarea::make('notes')
                                    ->label('Catatan')
                                    ->placeholder('...')
                                    ->columnSpanFull(),
                            ]),
                    ])
                    ->collapsible(),

                Grid::make([
                    'default' => 1,
                    'lg' => 3,
                ])
                    ->schema([
                        Section::make('Daftar Ayam')
                            ->schema([
                                View::make('filament.resources.manage.egg-collections.chicken-eggs-grid')
                                    ->viewData([
                                        'chickens' => $chickens,
                                    ]),
                            ])
                            ->columnSpan([
                                'default' => 1,
                                'lg' => 3,
                            ]),
                    ]),
            ])
            ->columns(1);
    }
}
