<?php

namespace App\Filament\Resources\Messages\Infolists;

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

class MessageInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Contact Information')
                    ->icon('heroicon-o-user')
                    ->schema([
                        TextEntry::make('name')
                            ->label('Name')
                            ->icon('heroicon-o-user')
                            ->weight('bold'),
                        
                        TextEntry::make('email')
                            ->label('Email')
                            ->icon('heroicon-o-envelope')
                            ->copyable()
                            ->copyMessage('Email copied!')
                            ->url(fn ($record) => "mailto:{$record->email}"),
                        
                        TextEntry::make('mobile')
                            ->label('Mobile')
                            ->icon('heroicon-o-phone')
                            ->copyable()
                            ->placeholder('Not provided')
                            ->url(fn ($record) => $record->mobile ? "tel:{$record->mobile}" : null),
                    ])
                    ->columns(3),
                
                Section::make('Message Details')
                    ->icon('heroicon-o-chat-bubble-left-right')
                    ->schema([
                        TextEntry::make('subject')
                            ->label('Subject')
                            ->icon('heroicon-o-document-text')
                            ->weight('bold')
                            ->columnSpanFull(),
                        
                        TextEntry::make('message')
                            ->label('Message')
                            ->markdown()
                            ->columnSpanFull(),
                    ]),
                
                Section::make('Status Information')
                    ->icon('heroicon-o-information-circle')
                    ->schema([
                        TextEntry::make('is_read')
                            ->label('Status')
                            ->badge()
                            ->formatStateUsing(fn ($state) => $state ? 'Read' : 'Unread')
                            ->color(fn ($state) => $state ? 'success' : 'warning'),
                        
                        TextEntry::make('created_at')
                            ->label('Received At')
                            ->dateTime()
                            ->since()
                            ->description(fn ($record) => $record->created_at->format('l, F j, Y \a\t g:i A')),
                        
                        TextEntry::make('read_at')
                            ->label('Read At')
                            ->dateTime()
                            ->placeholder('Not read yet')
                            ->description(fn ($record) => $record->read_at ? $record->read_at->format('l, F j, Y \a\t g:i A') : null),
                    ])
                    ->columns(3),
            ]);
    }
}
