<?php

namespace App\Filament\Resources\PaymentTransactions\Schemas;

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

class PaymentTransactionInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make(__('admin.payment_transactions.sections.summary'))
                    ->columns(3)
                    ->schema([
                        TextEntry::make('id')
                            ->label(__('admin.payment_transactions.fields.id'))
                            ->copyable(),
                        TextEntry::make('status')
                            ->label(__('admin.payment_transactions.fields.status'))
                            ->badge(),
                        TextEntry::make('type')
                            ->label(__('admin.payment_transactions.fields.type'))
                            ->badge(),
                        TextEntry::make('user.email')
                            ->label(__('admin.payment_transactions.fields.user'))
                            ->placeholder(__('admin.payment_transactions.placeholders.empty'))
                            ->copyable(),
                        TextEntry::make('creditProduct.name')
                            ->label(__('admin.payment_transactions.fields.credit_product'))
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('amount')
                            ->label(__('admin.payment_transactions.fields.amount'))
                            ->money(fn ($record): string => $record->currency ?: 'eur', divideBy: 100)
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('credits_expected')
                            ->label(__('admin.payment_transactions.fields.credits_expected'))
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('credits_granted')
                            ->label(__('admin.payment_transactions.fields.credits_granted')),
                        TextEntry::make('processed_at')
                            ->label(__('admin.payment_transactions.fields.processed_at'))
                            ->dateTime()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('invoice_email_sent_at')
                            ->label(__('admin.payment_transactions.fields.invoice_email_sent_at'))
                            ->dateTime()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                    ]),
                Section::make(__('admin.payment_transactions.sections.stripe'))
                    ->columns(2)
                    ->schema([
                        TextEntry::make('stripe_event_type')
                            ->label(__('admin.payment_transactions.fields.stripe_event_type'))
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_event_id')
                            ->label(__('admin.payment_transactions.fields.stripe_event_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_customer_id')
                            ->label(__('admin.payment_transactions.fields.stripe_customer_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_checkout_session_id')
                            ->label(__('admin.payment_transactions.fields.stripe_checkout_session_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_invoice_id')
                            ->label(__('admin.payment_transactions.fields.stripe_invoice_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_payment_intent_id')
                            ->label(__('admin.payment_transactions.fields.stripe_payment_intent_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_subscription_id')
                            ->label(__('admin.payment_transactions.fields.stripe_subscription_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('stripe_price_id')
                            ->label(__('admin.payment_transactions.fields.stripe_price_id'))
                            ->copyable()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('invoice_url')
                            ->label(__('admin.payment_transactions.fields.invoice_url'))
                            ->copyable()
                            ->url(fn ($state): ?string => $state)
                            ->openUrlInNewTab()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                        TextEntry::make('invoice_pdf_url')
                            ->label(__('admin.payment_transactions.fields.invoice_pdf_url'))
                            ->copyable()
                            ->url(fn ($state): ?string => $state)
                            ->openUrlInNewTab()
                            ->placeholder(__('admin.payment_transactions.placeholders.empty')),
                    ]),
                Section::make(__('admin.payment_transactions.sections.error'))
                    ->schema([
                        TextEntry::make('error_message')
                            ->label(__('admin.payment_transactions.fields.error_message'))
                            ->placeholder(__('admin.payment_transactions.placeholders.empty'))
                            ->columnSpanFull(),
                    ]),
                Section::make(__('admin.payment_transactions.sections.payload'))
                    ->schema([
                        TextEntry::make('payload')
                            ->label(__('admin.payment_transactions.fields.payload'))
                            ->formatStateUsing(fn (mixed $state): string => json_encode($state ?: [], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '{}')
                            ->fontFamily('mono')
                            ->columnSpanFull(),
                    ]),
            ]);
    }
}
