<?php

namespace App\Filament\Resources\SupportConversations\Schemas;

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

class SupportConversationInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Grid::make(3)
                    ->schema([
                        Section::make('Customer & Service Details')
                            ->columnSpan(1)
                            ->schema([
                                TextEntry::make('name')
                                    ->weight('bold'),
                                TextEntry::make('email_phone')
                                    ->label('Contact'),
                                TextEntry::make('subject_service')
                                    ->label('Service')
                                    ->badge()
                                    ->color('info'),
                                TextEntry::make('status')
                                    ->badge()
                                    ->color(fn (string $state): string => match ($state) {
                                        'open' => 'success',
                                        'closed' => 'gray',
                                        'archived' => 'warning',
                                    }),
                                TextEntry::make('customer_last_seen_at')
                                    ->label('Customer Activity')
                                    ->badge()
                                    ->formatStateUsing(fn ($state, $record) => $record->is_customer_active
                                        ? 'Active now'
                                        : ($state ? $state->diffForHumans() : 'Not active'))
                                    ->color(fn ($state, $record): string => $record->is_customer_active ? 'success' : 'gray'),
                                TextEntry::make('is_waiting_for_staff')
                                    ->label('Response Status')
                                    ->badge()
                                    ->formatStateUsing(fn ($state): string => $state ? 'Waiting for reply' : 'Answered')
                                    ->color(fn ($state): string => $state ? 'warning' : 'success'),
                                TextEntry::make('created_at')
                                    ->label('First Message')
                                    ->dateTime(),
                            ]),
                        
                        Section::make('Conversation Thread')
                            ->columnSpan(2)
                            ->schema([
                                ViewEntry::make('messages')
                                    ->label('')
                                    ->view('filament.support-conversations.chat-thread'),
                            ])
                    ])
            ]);
    }
}
