<?php

namespace App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Schemas;

use App\Modules\OrderStatus\Repositories\OrderStatusRepository;
use App\Modules\Region\Repositories\RegionRepository;
use App\Modules\TurkmenPassport\Repositories\TurkmenPassportRepository;
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\SpatieMediaLibraryImageEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Fieldset;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;

class VisaMasterPaymentOrderInfolist
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make()
                    ->columnSpanFull()
                    ->columns(3)
                    ->components([
                        TextEntry::make('type')
                            ->label(__('Payment type'))
                            ->extraAttributes(['style' => 'text-transform:uppercase;font-size:1.5em;font-weight:bold;']),

                        TextEntry::make('status')
                            ->label(__('Status'))
                            ->formatStateUsing(fn (string $state) => OrderStatusRepository::statusFormatted($state))
                            ->extraAttributes(['style' => 'text-transform:uppercase;font-size:1.2em;font-weight:bold;'])
                            ->color(OrderStatusRepository::statusColorMatching()),

                        IconEntry::make('paid')
                            ->label(sprintf('%s (%s)', __('Paid'), __('This month')))
                            ->boolean()
                            ->trueIcon(Heroicon::CheckCircle)
                            ->falseIcon(Heroicon::XCircle)
                            ->trueColor('success')
                            ->falseColor('danger'),

                        TextEntry::make('notes')
                            ->label(__('Bellik'))
                            ->html()
                            ->columnSpanFull()
                            ->placeholder('-'),
                    ]),

                Tabs::make('Order Information')
                    ->tabs([
                        Tab::make(__('Order type and bank'))
                            ->schema([

                                Fieldset::make(__('Location'))
                                    ->schema([
                                        TextEntry::make('region')
                                            ->label(__('Region'))
                                            ->formatStateUsing(fn ($state) => RegionRepository::values()[$state] ?? $state),

                                        TextEntry::make('branch.name')
                                            ->label(__('Branch'))
                                            ->placeholder('-'),
                                    ]),
                            ]),

                        Tab::make(__('Payment sender data'))
                            ->columns(8)
                            ->schema([
                                TextEntry::make('sender_full_name')
                                    ->label(__('Name, Surname, Patronic name'))
                                    ->columnSpan(4)
                                    ->placeholder('-'),

                                TextEntry::make('sender_passport')
                                    ->label(__('Passport serie and number'))
                                    ->formatStateUsing(function ($record) {
                                        $serie = TurkmenPassportRepository::values()[$record->sender_passport_serie] ?? $record->sender_passport_serie;

                                        return $serie.' '.$record->sender_passport_number;
                                    })
                                    ->columnSpan(2)
                                    ->placeholder('-'),

                                TextEntry::make('phone')
                                    ->label(__('Phone'))
                                    ->formatStateUsing(fn ($state) => '+993 '.$state)
                                    ->columnSpan(2)
                                    ->placeholder('-'),

                                TextEntry::make('sender_deposit_account')
                                    ->label(__('Deposit account'))
                                    ->columnSpan(4)
                                    ->placeholder('-'),

                                TextEntry::make('address')
                                    ->label(__('Address'))
                                    ->columnSpan(4)
                                    ->placeholder('-'),

                                Section::make(__('Files'))
                                    ->description('PNG, JPEG, PDF')
                                    ->columnSpanFull()
                                    ->columns(2)
                                    ->schema([
                                        SpatieMediaLibraryImageEntry::make('sender_passport_local')
                                            ->collection('sender_passport_local')
                                            ->label(__('Ugradyja degişli Türkmenistanyň raýatynyň (içki milli) pasportynyň asyl görnüşi we göçürmesi')),

                                        SpatieMediaLibraryImageEntry::make('sender_passport_international')
                                            ->collection('sender_passport_international')
                                            ->label(__('Ugradyja degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň asyl görnüşi we  göçürmesi')),

                                        SpatieMediaLibraryImageEntry::make('sender_travel_stamp_on_passport')
                                            ->collection('sender_travel_stamp_on_passport')
                                            ->label(__('Ugradyja degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky daşary döwletine gidendigi we daşary  döwlete barandygy baradaky  (ştampyň) bellenen sahypasynyň göçürmesi')),

                                        SpatieMediaLibraryImageEntry::make('sender_proof_of_kinship')
                                            ->collection('sender_proof_of_kinship')
                                            ->label(__('Ugradyjynyň we kabul edijiniň (talybyň) özara garyndaşlyk derejesini tassyklaýjy resminamalarynyň göçürmesi')),

                                        SpatieMediaLibraryImageEntry::make('sender_passport_local_old')
                                            ->collection('sender_passport_local_old')
                                            ->label(__('Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportyny ikinji gezek alan bolsa, onda birinji gezek alan pasportynyň seriýasy baradaky maglumat')),

                                        SpatieMediaLibraryImageEntry::make('sender_passport_local_old_replacement')
                                            ->collection('sender_passport_local_old_replacement')
                                            ->label(__('Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportyny ikinji gezek alandan soňra birinji gezek alan pasportynyň seriýasy baradaky maglumaty bilmeýän ,bolsa onda polisiýanyň degişli edaralaryndan birinji alan pasportynyň seriýasy baradaky güwänamasy')),
                                    ]),
                            ]),

                        Tab::make(__('Payee information'))
                            ->columns(8)
                            ->schema([
                                TextEntry::make('reciever_full_name')
                                    ->label(__('Name, Surname, Patronic name'))
                                    ->columnSpan(5)
                                    ->placeholder('-'),

                                TextEntry::make('reciever_passport')
                                    ->label(__('Passport serie and number'))
                                    ->formatStateUsing(function ($record) {
                                        $serie = TurkmenPassportRepository::values()[$record->reciever_passport_serie] ?? $record->reciever_passport_serie;

                                        return $serie.' '.$record->reciever_passport_number;
                                    })
                                    ->columnSpan(3)
                                    ->placeholder('-'),

                                Section::make(__('Files'))
                                    ->description('PNG, JPEG, PDF')
                                    ->columnSpanFull()
                                    ->columns(2)
                                    ->schema([
                                        SpatieMediaLibraryImageEntry::make('receiver_requisite')
                                            ->collection('receiver_requisite')
                                            ->label(__('Talyba degişli walýuta "VISA" kartyň rekwizitleri'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_document_stating_he_is_studying')
                                            ->collection('receiver_document_stating_he_is_studying')
                                            ->label(__('Talybyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_ticket')
                                            ->collection('receiver_ticket')
                                            ->label(__('Talybyň bilediniň göçürmesi'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_passport_local')
                                            ->collection('receiver_passport_local')
                                            ->label(__('Talyba degişli Türkmenistanyň raýatynyň (içki milli) pasportynyň asyl görnüşi we göçürmesi'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_passport_international')
                                            ->collection('receiver_passport_international')
                                            ->label(__('Talybyň Türkmenistandan çykmak we Türkmenistana girmek üçin (zagran) pasportynyň göçürmesi'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_visa')
                                            ->collection('receiver_visa')
                                            ->label(__('Talybyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky daşary ýurtda galyp okap bilýändigi  baradaky berlen möhleti hereket edýän rugsatnamasynyň (wizasynyň) bellenen sahypasynyň göçürmesi'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_travel_stamp_on_passport')
                                            ->collection('receiver_travel_stamp_on_passport')
                                            ->label(__('Talybyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky Türkmenistandan çykandygy we daşary ýurt döwletine girendigi baradaky ştamplaryň (seneli ştampyň) bellenen sahypasynyň göçürmesi'))
                                            ->columnSpan(1),

                                        SpatieMediaLibraryImageEntry::make('receiver_document_stating_he_is_studying_2')
                                            ->collection('receiver_document_stating_he_is_studying_2')
                                            ->label(__('Talybyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasyndaky maglumatyň doly takyk däl ýagdaýynda takyk däl maglumatyň sebäpleri baradaky daşary ýurt döwletiniň ýokary okuw mekdebinden haty'))
                                            ->columnSpan(1),
                                    ]),
                            ]),
                    ])->columnSpanFull(),
            ]);
    }
}
