<?php

namespace App\Filament\Resources\Inquiries\Schemas;

use App\Support\PvConfigurator;
use App\Support\ServiceConfigurator;
use Filament\Infolists\Components\KeyValueEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Schema;

class InquiryInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                TextEntry::make('name'),
                TextEntry::make('first_name')->label('Vorname')->placeholder('-'),
                TextEntry::make('email')
                    ->label('Email address'),
                TextEntry::make('phone')
                    ->label('Telefon')
                    ->placeholder('-'),
                TextEntry::make('fax')
                    ->label('Telefax')
                    ->placeholder('-'),
                TextEntry::make('street')->label('Straße')->placeholder('-'),
                TextEntry::make('street_number')->label('Hausnummer')->placeholder('-'),
                TextEntry::make('postal_code')->label('PLZ')->placeholder('-'),
                TextEntry::make('city')->label('Ort')->placeholder('-'),
                TextEntry::make('audience')
                    ->label('Projektart')
                    ->placeholder('-'),
                TextEntry::make('message')
                    ->label('Anfrage / Konfiguration')
                    ->placeholder('-')
                    ->columnSpanFull(),
                KeyValueEntry::make('configuration')
                    ->label('Konfiguration als Felder')
                    ->getStateUsing(fn ($record): array => $record->configuration ? (ServiceConfigurator::flatSummaryForInquiry($record->configuration) ?: PvConfigurator::flatSummary($record->configuration)) : [])
                    ->keyLabel('Angabe')
                    ->valueLabel('Auswahl')
                    ->columnSpanFull(),
                TextEntry::make('status'),
                TextEntry::make('source'),
                TextEntry::make('ip_hash')
                    ->placeholder('-'),
                TextEntry::make('consent_at')
                    ->label('Einwilligung am')
                    ->dateTime(),
                TextEntry::make('customer_copy_sent_at')
                    ->label('Kundenkopie gesendet am')
                    ->dateTime()
                    ->placeholder('-'),
                TextEntry::make('handled_at')
                    ->dateTime()
                    ->placeholder('-'),
                TextEntry::make('created_at')
                    ->dateTime()
                    ->placeholder('-'),
                TextEntry::make('updated_at')
                    ->dateTime()
                    ->placeholder('-'),
            ]);
    }
}
