<?php

namespace App\Filament\Resources\ContactMessages\Pages;

use App\Filament\Resources\ContactMessages\ContactMessageResource;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class ViewContactMessage extends ViewRecord
{
    protected static string $resource = ContactMessageResource::class;

    public function mount(int|string $record): void
    {
        parent::mount($record);
        $this->record->read_at ?? $this->record->update(['read_at' => now()]);
    }

    public function infolist(Schema $infolist): Schema
    {
        return $infolist->schema([
            Section::make('Informasi Pengirim')->schema([
                TextEntry::make('name')->label('Nama'),
                TextEntry::make('email')->label('Email')->default('-'),
                TextEntry::make('phone')->label('Telepon')->default('-'),
                TextEntry::make('created_at')->label('Dikirim')->dateTime('d M Y H:i'),
            ])->columns(2),

            Section::make('Pesan')->schema([
                TextEntry::make('subject')->label('Subjek'),
                TextEntry::make('message')->label('Isi Pesan')->columnSpanFull(),
            ]),
        ]);
    }
}
