<?php

namespace App\Filament\Clusters\DailyOps\Resources\Photos\Schemas;

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

class PhotoInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make(__('admin.moderation.sections.photo'))
                    ->columns(3)
                    ->schema([
                        ImageEntry::make('thumbnail_path')
                            ->label(__('admin.moderation.fields.photo'))
                            ->disk('public')
                            ->visibility('public')
                            ->getStateUsing(fn (Photo $record) => $record->thumbnail_path ?: $record->file_path)
                            ->columnSpanFull(),
                        TextEntry::make('event.name')
                            ->label(__('admin.moderation.fields.event'))
                            ->placeholder('—'),
                        TextEntry::make('event.tenant.name')
                            ->label(__('admin.moderation.fields.tenant'))
                            ->placeholder('—'),
                        TextEntry::make('guest_name')
                            ->label(__('admin.moderation.fields.uploader'))
                            ->placeholder('—'),
                        TextEntry::make('created_at')
                            ->label(__('admin.moderation.fields.uploaded_at'))
                            ->since()
                            ->placeholder('—'),
                        TextEntry::make('ingest_source')
                            ->label(__('admin.moderation.fields.ingest_source'))
                            ->formatStateUsing(fn (?string $state) => match ($state) {
                                Photo::SOURCE_GUEST_PWA => __('admin.moderation.ingest_sources.guest_pwa'),
                                Photo::SOURCE_TENANT_ADMIN => __('admin.moderation.ingest_sources.tenant_admin'),
                                Photo::SOURCE_PHOTOBOOTH => __('admin.moderation.ingest_sources.photobooth'),
                                Photo::SOURCE_SPARKBOOTH => __('admin.moderation.ingest_sources.sparkbooth'),
                                Photo::SOURCE_UNKNOWN => __('admin.moderation.ingest_sources.unknown'),
                                default => '—',
                            }),
                    ]),
                Section::make(__('admin.moderation.sections.moderation'))
                    ->columns(2)
                    ->schema([
                        TextEntry::make('status')
                            ->label(__('admin.moderation.fields.status'))
                            ->badge()
                            ->color(fn (?string $state) => match ($state) {
                                'approved' => 'success',
                                'rejected' => 'danger',
                                'hidden' => 'gray',
                                default => 'warning',
                            })
                            ->formatStateUsing(fn (?string $state) => match ($state) {
                                'pending' => __('admin.moderation.status.pending'),
                                'approved' => __('admin.moderation.status.approved'),
                                'rejected' => __('admin.moderation.status.rejected'),
                                'hidden' => __('admin.moderation.status.hidden'),
                                default => '—',
                            }),
                        TextEntry::make('moderator.name')
                            ->label(__('admin.moderation.fields.moderated_by'))
                            ->placeholder('—'),
                        TextEntry::make('moderated_at')
                            ->label(__('admin.moderation.fields.moderated_at'))
                            ->dateTime()
                            ->placeholder('—'),
                        TextEntry::make('moderation_notes')
                            ->label(__('admin.moderation.fields.moderation_notes'))
                            ->placeholder('—')
                            ->columnSpanFull(),
                        TextEntry::make('security_scan_status')
                            ->label(__('admin.moderation.fields.security_scan_status'))
                            ->badge()
                            ->color(fn (?string $state) => match ($state) {
                                'clean', 'skipped', 'stripped' => 'success',
                                'infected' => 'danger',
                                'error' => 'warning',
                                default => 'gray',
                            })
                            ->formatStateUsing(fn (?string $state) => match ($state) {
                                'pending' => __('admin.moderation.security_scan.pending'),
                                'clean' => __('admin.moderation.security_scan.clean'),
                                'infected' => __('admin.moderation.security_scan.infected'),
                                'skipped' => __('admin.moderation.security_scan.skipped'),
                                'stripped' => __('admin.moderation.security_scan.stripped'),
                                'error' => __('admin.moderation.security_scan.error'),
                                default => '—',
                            }),
                        TextEntry::make('security_scan_message')
                            ->label(__('admin.moderation.fields.security_scan_message'))
                            ->placeholder('—')
                            ->columnSpanFull(),
                        TextEntry::make('security_scanned_at')
                            ->label(__('admin.moderation.fields.security_scanned_at'))
                            ->dateTime()
                            ->placeholder('—'),
                    ]),
            ]);
    }
}
