<?php

namespace App\Filament\Resources\SoumissionResource\Pages;

use App\Filament\Resources\SoumissionResource;
use App\Models\Soumission;
use Filament\Actions\EditAction;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Pages\ViewRecord;

class ViewSoumission extends ViewRecord
{
    protected static string $resource = SoumissionResource::class;

    public function mount(int | string $record): void
    {
        parent::mount($record);

        if ($this->record->sub_statut === 'new') {
            $this->record->update(['sub_statut' => 'read']);
        }
    }

    public function infolist(Infolist $infolist): Infolist
    {
        return $infolist->schema([
            TextEntry::make('sub_prenom')->label('Prénom'),
            TextEntry::make('sub_nom')->label('Nom'),
            TextEntry::make('sub_email')->label('Email')->copyable(),
            TextEntry::make('sub_tel')->label('Téléphone')->placeholder('—'),
            TextEntry::make('sub_profil')->label('Profil')->placeholder('—'),
            TextEntry::make('sub_projet')->label('Message')->columnSpanFull(),
            TextEntry::make('sub_locale')->label('Langue'),
            TextEntry::make('sub_statut')->label('Statut')
                ->formatStateUsing(fn (string $state): string => Soumission::STATUTS[$state] ?? $state),
            TextEntry::make('sub_created_at')->label('Reçue le')->dateTime('d/m/Y H:i'),
        ]);
    }

    protected function getHeaderActions(): array
    {
        return [
            EditAction::make()->label('Modifier le statut'),
        ];
    }
}
