<?php

declare(strict_types=1);

namespace App\Filament\Resources\Explanations\Schemas;

use App\Models\Explanation;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class ExplanationInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make(__('hr.sections.basic_info'))
                    ->schema([
                        TextEntry::make('employee.full_name')
                            ->label(__('hr.fields.employee')),
                        TextEntry::make('explanation_date')
                            ->label(__('hr.fields.explanation_date'))
                            ->date('d.m.Y'),
                    ])
                    ->columns(2),
                Section::make(__('hr.sections.explanation_details'))
                    ->schema([
                        TextEntry::make('reason')
                            ->label(__('hr.fields.reason'))
                            ->placeholder('—')
                            ->columnSpanFull(),
                        TextEntry::make('description')
                            ->label(__('hr.fields.description'))
                            ->placeholder('—')
                            ->columnSpanFull(),
                        TextEntry::make('attachment_path')
                            ->label(__('hr.fields.attachment'))
                            ->formatStateUsing(fn (?string $state): string => filled($state) ? basename($state) : '—'),
                    ])
                    ->columns(2),
                Section::make(__('hr.sections.metadata'))
                    ->schema([
                        TextEntry::make('created_at')
                            ->label(__('hr.fields.created_at'))
                            ->dateTime('d.m.Y H:i')
                            ->placeholder('—'),
                        TextEntry::make('updated_at')
                            ->label(__('hr.fields.updated_at'))
                            ->dateTime('d.m.Y H:i')
                            ->placeholder('—'),
                        TextEntry::make('deleted_at')
                            ->label(__('hr.fields.deleted_at'))
                            ->dateTime('d.m.Y H:i')
                            ->visible(fn (Explanation $record): bool => $record->trashed()),
                    ])
                    ->columns(2),
            ]);
    }
}
