<?php

namespace Modules\Identity\Filament\Resources\AuditLogs\Schemas;

use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class AuditLogInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Event')
                    ->schema([
                        Grid::make(3)
                            ->schema([
                                TextEntry::make('log_name')->label('Module')->badge(),
                                TextEntry::make('event')->badge()->placeholder('—'),
                                TextEntry::make('created_at')->dateTime(),
                                TextEntry::make('subject_type')->label('Subject Type')->placeholder('—'),
                                TextEntry::make('subject_id')->label('Subject ID')->placeholder('—'),
                                TextEntry::make('causer.name')->label('Caused By')->placeholder('System'),
                            ]),
                        TextEntry::make('description')->columnSpanFull(),
                    ]),
                Section::make('Changes')
                    ->schema([
                        TextEntry::make('attribute_changes')
                            ->label('')
                            ->formatStateUsing(fn (mixed $state) => $state
                                ? json_encode($state, JSON_PRETTY_PRINT)
                                : null)
                            ->placeholder('—')
                            ->columnSpanFull(),
                    ]),
            ]);
    }
}
