@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Bank Details', __('Bank Details')))

@section('content')
<div class="container m-auto p-4 sm:p-6 lg:p-8 py-8">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2l font-semibold text-gray-900">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Details', __('Bank Details')) }}: {{ $bank->name }}</h1>
        <div class="flex space-y-2 rtl:space-y-reverse">
            <a href="{{ route('banking.banks.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 p-4 rounded">
                <i class="fas fa-arrow-right ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Back to List', __('Back to List')) }}
            </a>
            @permission('banking.edit')
            <a href="{{ route('banking.banks.edit', $bank) }}" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 p-4 rounded">
                <i class="fas fa-edit ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Edit', __('Edit')) }}
            </a>
            @endpermission
        </div>
    </div>

    <div class="bg-white shadow-md rounded-lg overflow-hidden mb-6">
        <div class="p-6">
            <h2 class="text-l font-semibold mb-4">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Information', __('Bank Information')) }}</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Name', __('Name')) }}:</p>
                    <p class="font-semibold">{{ $bank->name }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Code', __('Code')) }}:</p>
                    <p class="font-semibold">{{ $bank->code ?? \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('SWIFT Code', __('SWIFT Code')) }}:</p>
                    <p class="font-semibold">{{ $bank->swift_code ?? \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Address', __('Address')) }}:</p>
                    <p class="font-semibold">{{ $bank->address ?? \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Phone Number', __('Phone Number')) }}:</p>
                    <p class="font-semibold">{{ $bank->phone ?? \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Contact Person', __('Contact Person')) }}:</p>
                    <p class="font-semibold">{{ $bank->contact_person ?? \App\Helpers\TranslationHelper::transFromDatabase('Not Set', __('Not Set')) }}</p>
                </div>
                <div>
                    <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Status', __('Status')) }}:</p>
                    <p class="font-semibold">
                        @if($bank->is_active)
                        <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Active', __('Active')) }}
                        </span>
                        @else
                        <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Inactive', __('Inactive')) }}
                        </span>
                        @endif
                    </p>
                </div>
            </div>
            
            @if($bank->notes)
            <div class="mt-4">
                <p class="text-gray-600 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Notes', __('Notes')) }}:</p>
                <p>{{ $bank->notes }}</p>
            </div>
            @endif
        </div>
    </div>

    <div class="bg-white shadow-md rounded-lg overflow-hidden">
        <div class="p-6">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-l font-semibold">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Accounts', __('Bank Accounts')) }}</h2>
                @permission('banking.create')
                <a href="{{ route('banking.accounts.create', ['bank_id' => $bank->id]) }}" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 p-4 rounded">
                    <i class="fas fa-plus ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Add New Account', __('Add New Account')) }}
                </a>
                @endpermission
            </div>
            
            <div class="overflow--auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Account Number', __('Account Number')) }}
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Account Name', __('Account Name')) }}
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Currency', __('Currency')) }}
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Current Balance', __('Current Balance')) }}
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Status', __('Status')) }}
                            </th>
                            <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Actions', __('Actions')) }}
                            </th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        @forelse($bankAccounts as $account)
                        <tr>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm font-medium text-gray-900">{{ $account->account_number }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-500">{{ $account->account_name }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-500">{{ $account->currency }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-500">{{ number_format($account->current_balance, 2) }}</div>
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap">
                                @if($account->is_active)
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Active', __('Active')) }}
                                </span>
                                @else
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Inactive', __('Inactive')) }}
                                </span>
                                @endif
                            </td>
                            <td class="p-6 py-4 whitespace-nowrap text-sm font-medium">
                                <div class="flex items-center space-y-4 rtl:space-y-reverse">
                                    @permission('banking.view')
                                    <a href="{{ route('banking.accounts.show', $account) }}" class="text-blue-600 hover:text-blue-900">
                                        <i class="fas fa-eye"></i>
                                    </a>
                                    @endpermission
                                    
                                    @permission('banking.edit')
                                    <a href="{{ route('banking.accounts.edit', $account) }}" class="text-indigo-600 hover:text-indigo-900">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    @endpermission
                                    
                                    @permission('banking.delete')
                                    <form action="{{ route('banking.accounts.destroy', $account) }}" method="POST" class="inline" onsubmit="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Are you sure you want to delete this account?', __('Are you sure you want to delete this account?')) }}');">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="text-red-600 hover:text-red-900">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </form>
                                    @endpermission
                                </div>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="p-6 py-4 whitespace-nowrap text-sm text-gray-500 text-center">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('No bank accounts registered for this bank', __('No bank accounts registered for this bank')) }}
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection
