<?php

namespace App\Filament\Resources\MemberDues\Schemas;

use App\Models\User;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;

class MemberDueForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema->components([
            Select::make('user_id')->label('Anggota')
                ->options(User::where('status', 'aktif')->pluck('name', 'id'))
                ->searchable()->required(),
            TextInput::make('period')->label('Periode (YYYY-MM)')
                ->placeholder(now()->format('Y-m'))
                ->required(),
            TextInput::make('amount')->label('Jumlah (Rp)')->numeric()->required(),
            Select::make('status')->options(['lunas' => 'Lunas', 'belum' => 'Belum Lunas'])
                ->default('belum')->required()
                ->live(),
            DatePicker::make('paid_at')->label('Tanggal Bayar')
                ->visible(fn ($get) => $get('status') === 'lunas'),
            Textarea::make('notes')->label('Catatan')->rows(2)->columnSpanFull(),
        ]);
    }
}
