<?php

namespace App\Filament\Resources\Customers\Schemas;

use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class CustomerForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Grid::make(3)
                    ->schema([
                        // Left / Main Column (span 2)
                        Grid::make(1)
                            ->schema([
                                Section::make()
                                    ->schema([
                                        TextInput::make('name')
                                            ->required()
                                            ->maxLength(255),
                                        TextInput::make('email')
                                            ->label('Email address')
                                            ->email()
                                            ->required()
                                            ->unique(table: 'users', ignoreRecord: true),
                                        TextInput::make('phone')
                                            ->label('Phone')
                                            ->tel()
                                            ->maxLength(50),
                                        DatePicker::make('birthday')
                                            ->label('Birthday')
                                            ->maxDate(now()),
                                    ])
                                    ->columns(2),
                            ])
                            ->columnSpan(2),

                        // Right Column (span 1)
                        Grid::make(1)
                            ->schema([
                                Section::make()
                                    ->schema([
                                        Placeholder::make('created_at')
                                            ->label('Created at')
                                            ->content(fn ($record): string => $record?->created_at ? $record->created_at->diffForHumans() : '-'),
                                        Placeholder::make('updated_at')
                                            ->label('Last modified at')
                                            ->content(fn ($record): string => $record?->updated_at ? $record->updated_at->diffForHumans() : '-'),
                                    ])
                                    ->hidden(fn ($record) => $record === null),
                            ])
                            ->columnSpan(1),
                    ])
                    ->columnSpanFull(),
            ]);
    }
}
