<?php

namespace App\Filament\Resources\LegalDocuments\Schemas;

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

class LegalDocumentInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make(__('admin.legal_documents.sections.identity'))
                    ->columns(3)
                    ->schema([
                        TextEntry::make('id')
                            ->label(__('admin.legal_documents.fields.id'))
                            ->copyable(),
                        TextEntry::make('slug')
                            ->label(__('admin.legal_documents.fields.slug'))
                            ->copyable(),
                        TextEntry::make('type')
                            ->label(__('admin.legal_documents.fields.type'))
                            ->badge(),
                        TextEntry::make('version')
                            ->label(__('admin.legal_documents.fields.version')),
                        TextEntry::make('is_active')
                            ->label(__('admin.legal_documents.fields.is_active'))
                            ->badge()
                            ->formatStateUsing(fn (bool $state): string => $state
                                ? __('admin.legal_documents.status.active')
                                : __('admin.legal_documents.status.inactive')),
                        TextEntry::make('published_at')
                            ->label(__('admin.legal_documents.fields.published_at'))
                            ->dateTime()
                            ->placeholder(__('admin.legal_documents.placeholders.empty')),
                    ]),
                Section::make(__('admin.legal_documents.sections.content'))
                    ->schema([
                        KeyValueEntry::make('title')
                            ->label(__('admin.legal_documents.fields.title')),
                        TextEntry::make('content')
                            ->label(__('admin.legal_documents.fields.content'))
                            ->formatStateUsing(fn (mixed $state): string => json_encode($state ?: [], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}')
                            ->fontFamily('mono')
                            ->columnSpanFull(),
                    ]),
                Section::make(__('admin.legal_documents.sections.metadata'))
                    ->columns(2)
                    ->schema([
                        TextEntry::make('created_at')
                            ->label(__('admin.legal_documents.fields.created_at'))
                            ->dateTime(),
                        TextEntry::make('updated_at')
                            ->label(__('admin.legal_documents.fields.updated_at'))
                            ->dateTime(),
                    ]),
            ]);
    }
}
