@extends('layouts.app')

@section('title', 'إدارة الحسابات البنكية')

@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 Accounts Management', __('Bank Accounts Management')) }}</h1>
        @permission('banking.accounts.create')
        <a href="{{ route('banking.accounts.create') }}" class="bg-blue-600 hover:bg-blue-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>

    @if(session('success'))
    <div class="bg-green-100 border border-green-400 text-green-700 p-4 py-3 rounded relative mb-4" role="alert">
        <span class="block sm:inline">{{ session('success') }}</span>
    </div>
    @endif

    @if(session('error'))
    <div class="bg-red-100 border border-red-400 text-red-700 p-4 py-3 rounded relative mb-4" role="alert">
        <span class="block sm:inline">{{ session('error') }}</span>
    </div>
    @endif

    <div class="bg-white shadow-md rounded-lg overflow-hidden">
        <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('Bank', __('Bank')) }}
                        </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 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->bank->name }}</div>
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-900">{{ $account->account_number }}</div>
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap">
                            <div class="text-sm text-gray-900">{{ $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 justify-center gap-1">
                                @permission('banking.accounts.view')
                                <a href="{{ route('banking.accounts.show', $account) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-blue-100 text-blue-600 hover:bg-blue-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('View Details', __('View Details')) }}">
                                    <i class="fas fa-eye mr-1"></i>
                                    <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('View', __('View')) }}</span>
                                </a>
                                @endpermission
                                
                                @permission('banking.accounts.edit')
                                <a href="{{ route('banking.accounts.edit', $account) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-amber-100 text-amber-600 hover:bg-amber-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Edit', __('Edit')) }}">
                                    <i class="fas fa-edit mr-1"></i>
                                    <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Edit', __('Edit')) }}</span>
                                </a>
                                @endpermission
                                
                                @permission('banking.accounts.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="inline-flex items-center px-3 py-2 rounded-lg bg-red-100 text-red-600 hover:bg-red-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Delete', __('Delete')) }}">
                                        <i class="fas fa-trash mr-1"></i>
                                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Delete', __('Delete')) }}</span>
                                    </button>
                                </form>
                                @endpermission
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="7" class="p-6 py-4 whitespace-nowrap text-sm text-gray-500 text-center">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('No bank accounts registered', __('No bank accounts registered')) }}
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
