<?php

namespace App\Filament\Resources\TenantFeedbackResource\Schemas;

use Filament\Infolists\Components\KeyValueEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Support\Str;

class TenantFeedbackInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make(__('Überblick'))
                    ->columns(3)
                    ->schema([
                        TextEntry::make('tenant.name')->label(__('Tenant'))->placeholder('—'),
                        TextEntry::make('event.name')->label(__('Event'))->placeholder('—'),
                        TextEntry::make('category')
                            ->label(__('Kategorie'))
                            ->badge()
                            ->formatStateUsing(fn ($state) => $state ? Str::headline($state) : '—'),
                        TextEntry::make('sentiment')
                            ->label(__('Stimmung'))
                            ->badge()
                            ->color(fn (?string $state) => match ($state) {
                                'positive' => 'success',
                                'neutral' => 'warning',
                                'negative' => 'danger',
                                default => 'gray',
                            })
                            ->formatStateUsing(fn (?string $state) => $state ? Str::headline($state) : '—'),
                        TextEntry::make('rating')
                            ->label(__('Rating'))
                            ->formatStateUsing(fn (?int $state) => $state ? sprintf('%d/5', $state) : '—'),
                        TextEntry::make('created_at')
                            ->label(__('Eingegangen'))
                            ->since(),
                    ]),
                Section::make(__('Inhalt'))
                    ->columns(1)
                    ->schema([
                        TextEntry::make('title')
                            ->label(__('Betreff'))
                            ->placeholder('—'),
                        TextEntry::make('message')
                            ->label(__('Nachricht'))
                            ->markdown()
                            ->placeholder('—'),
                    ]),
                Section::make(__('Metadaten'))
                    ->schema([
                        KeyValueEntry::make('metadata')
                            ->label(__('Metadata'))
                            ->columnSpanFull(),
                    ]),
                Section::make(__('admin.feedback.sections.moderation'))
                    ->columns(2)
                    ->schema([
                        TextEntry::make('status')
                            ->label(__('admin.feedback.fields.status'))
                            ->badge()
                            ->color(fn (?string $state) => match ($state) {
                                'resolved' => 'success',
                                'hidden' => 'gray',
                                'deleted' => 'danger',
                                default => 'warning',
                            })
                            ->formatStateUsing(fn (?string $state) => match ($state) {
                                'pending' => __('admin.feedback.status.pending'),
                                'resolved' => __('admin.feedback.status.resolved'),
                                'hidden' => __('admin.feedback.status.hidden'),
                                'deleted' => __('admin.feedback.status.deleted'),
                                default => '—',
                            }),
                        TextEntry::make('moderator.name')
                            ->label(__('admin.feedback.fields.moderated_by'))
                            ->placeholder('—'),
                        TextEntry::make('moderated_at')
                            ->label(__('admin.feedback.fields.moderated_at'))
                            ->dateTime()
                            ->placeholder('—'),
                        TextEntry::make('moderation_notes')
                            ->label(__('admin.feedback.fields.moderation_notes'))
                            ->placeholder('—')
                            ->columnSpanFull(),
                    ]),
            ]);
    }
}
