<?php $__env->startSection('content'); ?>
<div class="space-y-6">
    <!-- Header controls -->
    <div class="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-6">
        <div>
            <h1 class="text-xl font-bold tracking-tight text-slate-900 md:text-2xl">🏦 ব্যাংকিং ও লিকুইডিটি নিয়ন্ত্রণ (Corporate Banking Module)</h1>
            <p class="text-xs text-slate-500 font-medium">কর্পোরেট ব্যাংক অ্যাকাউন্ট ব্যালেন্স ট্র্যাকার, ব্যাংকে ক্যাশ জমা এবং ক্যাশ উত্তোলনের সমন্বিত প্ল্যাটফর্ম।</p>
        </div>
        <?php if(Auth::user()->isSuperAdmin()): ?>
            <div>
                <button onclick="toggleBankAddModal()" class="bg-blue-600 hover:bg-blue-700 text-white font-extrabold text-xs px-4 py-2.5 rounded-xl shadow-md shadow-blue-500/10 flex items-center gap-2 cursor-pointer transition">
                    ➕ ব্যাংক অ্যাকাউন্ট যুক্ত করুন (Add Account)
                </button>
            </div>
        <?php endif; ?>
    </div>

    <!-- Bank Accounts Bento Grid -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-5">
        <?php $__currentLoopData = $bankAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="bg-gradient-to-br from-slate-900 to-slate-800 text-white rounded-3xl p-5 shadow-sm border border-slate-700/30 flex flex-col justify-between relative overflow-hidden">
                <div class="absolute -right-4 -bottom-4 opacity-5 text-8xl">🏦</div>
                <div>
                    <div class="flex items-center justify-between">
                        <span class="text-[10px] font-black uppercase bg-white/10 text-emerald-400 px-2.5 py-1 rounded-md"><?php echo e($account->status); ?></span>
                        <span class="text-xs font-bold text-slate-400"><?php echo e($account->account_type); ?></span>
                    </div>
                    <div class="mt-4">
                        <h4 class="text-xs font-bold text-slate-400"><?php echo e($account->bank_name); ?></h4>
                        <p class="text-sm font-semibold tracking-wide text-slate-200 mt-0.5 font-mono"><?php echo e($account->account_number); ?></p>
                        <p class="text-[10px] font-normal text-slate-400 mt-2 font-bold leading-none">হোল্ডারঃ <span class="text-slate-350"><?php echo e($account->account_name); ?></span></p>
                        <p class="text-[10px] font-normal text-slate-400 mt-1 font-bold leading-none">শাখাঃ <span class="text-slate-350"><?php echo e($account->branch); ?></span></p>
                    </div>
                </div>
                <div class="mt-4 pt-3 flex flex-col justify-between border-t border-slate-700/40">
                    <div>
                        <span class="text-[10px] text-slate-400 font-bold block uppercase">অবশিষ্ট ব্যাংক ব্যালেন্স</span>
                        <span class="text-xl font-black font-mono text-emerald-400 mt-1 block">৳<?php echo e(number_format($account->balance, 2)); ?></span>
                    </div>

                    <?php if(Auth::user()->isSuperAdmin()): ?>
                        <div class="flex items-center gap-2 mt-4 pt-3 border-t border-white/5 z-10 justify-end">
                            <button onclick="openBankEditModal('<?php echo e($account->id); ?>', '<?php echo e(addslashes($account->bank_name)); ?>', '<?php echo e(addslashes($account->account_name)); ?>', '<?php echo e($account->account_number); ?>', '<?php echo e(addslashes($account->branch)); ?>', '<?php echo e($account->balance); ?>', '<?php echo e($account->status); ?>')" class="bg-white/10 hover:bg-white/25 border border-white/10 text-slate-100 px-2.5 py-1 rounded-lg font-bold text-[10px] transition-all cursor-pointer">
                                ✏️ এডিট
                            </button>
                            <form action="<?php echo e(route('superadmin.deleteBankAccount', $account->id)); ?>" method="POST" class="inline" onsubmit="return confirm('আপনি কি নিশ্চিতভাবে এই ব্যাংক অ্যাকাউন্টটি ডিলিট করতে চান?')">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="bg-rose-500/20 hover:bg-rose-600/30 border border-rose-500/20 text-rose-300 hover:text-white px-2.5 py-1 rounded-lg font-bold text-[10px] transition-all cursor-pointer">
                                    🗑️ ডিলিট
                                </button>
                            </form>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <!-- Dynamic Actions Panel -->
    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
        
        <!-- Action: Deposit To Bank -->
        <div class="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm">
            <h3 class="text-xs font-black uppercase text-slate-400 tracking-wider mb-4 flex items-center gap-2">
                <span>📥 ব্যাংক ডিপোজিট বুকিং (Cash Drawer ➔ Bank)</span>
            </h3>
            <p class="text-[11px] text-slate-500 mb-4">ক্যাশ ড্রয়ার থেকে টাকা ব্যাংকে সরাসরি স্থানান্তর প্রসেস করুন। (বর্তমান ক্যাশ ড্রয়ার ব্যালেন্স: <strong class="text-slate-800 font-mono">৳<?php echo e(number_format($branch->balance, 2)); ?></strong>)</p>

            <form action="<?php echo e(route('banking.deposit')); ?>" method="POST" class="space-y-4 text-xs">
                <?php echo csrf_field(); ?>
                <div>
                    <label class="block font-bold text-slate-705 mb-1">টার্গেট ব্যাংক অ্যাকাউন্ট নির্ধারণ করুন *</label>
                    <select name="bank_account_id" required class="w-full bg-slate-50 border border-slate-200 px-3 py-2.5 rounded-xl font-bold text-slate-700 focus:outline-none focus:ring-1 focus:ring-blue-500">
                        <?php $__currentLoopData = $bankAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ac): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($ac->id); ?>"><?php echo e($ac->bank_name); ?> - <?php echo e($ac->account_number); ?> (ব্যালেন্স: ৳<?php echo e(number_format($ac->balance,2)); ?>)</option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div>
                    <label class="block font-bold text-slate-705 mb-1">স্থানান্তরের পরিমাণ (Amount BDT) *</label>
                    <input type="number" step="0.01" name="amount" required placeholder="যেমনঃ ৫০০০" class="w-full bg-slate-50 border border-slate-200 px-4 py-2.5 rounded-xl font-bold font-mono text-slate-800 focus:outline-none focus:ring-1 focus:ring-blue-500">
                </div>
                <div>
                    <label class="block font-bold text-slate-705 mb-1">অতিরিক্ত নোট / বিবরণ</label>
                    <input type="text" name="notes" placeholder="যেমনঃ স্লিপ নং-৪৪৪" class="w-full bg-slate-50 border border-slate-200 px-4 py-2.5 rounded-xl text-slate-800 focus:outline-none focus:ring-1 focus:ring-blue-500">
                </div>
                <button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-extrabold py-2.5 rounded-xl transition shadow-md shadow-blue-500/10">
                    ✅ ডিপোজিট নিশ্চিত করুন
                </button>
            </form>
        </div>

        <!-- Action: Withdraw From Bank -->
        <div class="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm">
            <h3 class="text-xs font-black uppercase text-slate-400 tracking-wider mb-4 flex items-center gap-2">
                <span>📤 ব্যাংক উইথড্রয়াল বা উত্তোলন (Bank ➔ Cash Drawer)</span>
            </h3>
            <p class="text-[11px] text-slate-500 mb-4">ক্যাশ ড্রয়ারে লিকুইডিটি বাড়ানোর জন্য ব্যাংক অ্যাকাউন্ট থেকে টাকা উত্তোলন করে ক্যাশ মেলাবেন।</p>

            <form action="<?php echo e(route('banking.withdraw')); ?>" method="POST" class="space-y-4 text-xs">
                <?php echo csrf_field(); ?>
                <div>
                    <label class="block font-bold text-slate-705 mb-1">উৎস ব্যাংক অ্যাকাউন্ট নির্ধারণ করুন *</label>
                    <select name="bank_account_id" required class="w-full bg-slate-50 border border-slate-200 px-3 py-2.5 rounded-xl font-bold text-slate-700 focus:outline-none focus:ring-1 focus:ring-emerald-500">
                        <?php $__currentLoopData = $bankAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ac): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($ac->id); ?>"><?php echo e($ac->bank_name); ?> - <?php echo e($ac->account_number); ?> (ব্যালেন্স: ৳<?php echo e(number_format($ac->balance,2)); ?>)</option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div>
                    <label class="block font-bold text-slate-705 mb-1">উত্তোলনের পরিমাণ (Amount BDT) *</label>
                    <input type="number" step="0.01" name="amount" required placeholder="যেমনঃ ২০০০" class="w-full bg-slate-50 border border-slate-200 px-4 py-2.5 rounded-xl font-bold font-mono text-slate-800 focus:outline-none focus:ring-1 focus:ring-emerald-500">
                </div>
                <div>
                    <label class="block font-bold text-slate-705 mb-1">অতিরিক্ত নোট / চেক নম্বর</label>
                    <input type="text" name="notes" placeholder="যেমনঃ চেক নং-৩২৮৪" class="w-full bg-slate-50 border border-slate-200 px-4 py-2.5 rounded-xl text-slate-800 focus:outline-none focus:ring-1 focus:ring-emerald-500">
                </div>
                <button type="submit" class="w-full bg-emerald-600 hover:bg-emerald-700 text-white font-extrabold py-2.5 rounded-xl transition shadow-md shadow-emerald-500/10">
                    🗳️ উত্তোলন নিশ্চিত করুন
                </button>
            </form>
        </div>

    </div>

    <!-- Bank ledger list -->
    <div class="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm">
        <h3 class="text-xs font-black uppercase text-slate-400 tracking-wider mb-4 block">📈 ব্যাংকিং ভাউচার হিস্টোরি (Bank Ledger Logs)</h3>
        <div class="overflow-x-auto">
            <table class="w-full text-xs font-medium text-slate-700">
                <thead>
                    <tr class="text-left text-[11px] text-slate-400 font-bold border-b border-slate-100 uppercase tracking-wider">
                        <th class="py-3 px-4">তারিখ</th>
                        <th class="py-3 px-4">ভাউচার আইডি</th>
                        <th class="py-3 px-4">ব্যাংক অ্যাকাউন্ট</th>
                        <th class="py-3 px-4">বিবরণ / Particulars</th>
                        <th class="py-3 px-4">পরিমাণ (Amount)</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    <?php $__empty_1 = true; $__currentLoopData = $bankLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr class="hover:bg-slate-50/50 transition">
                            <td class="py-3 px-4"><?php echo e($log->created_at->format('Y-m-d H:i')); ?></td>
                            <td class="py-3 px-4 font-mono font-bold text-slate-800"><?php echo e($log->voucher_no); ?></td>
                            <td class="py-3 px-4 font-bold text-slate-600">
                                <?php if($log->bankAccount): ?>
                                    <?php echo e($log->bankAccount->bank_name); ?> (<?php echo e($log->bankAccount->account_number); ?>)
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </td>
                            <td class="py-3 px-4 max-w-[300px] truncate" title="<?php echo e($log->particulars); ?>"><?php echo e($log->particulars); ?></td>
                            <td class="py-3 px-4">
                                <span class="font-mono font-black <?php echo e($log->category === 'Bank Withdrawal' ? 'text-emerald-600' : 'text-rose-600'); ?>">
                                    ৳<?php echo e(number_format($log->amount, 2)); ?>

                                </span>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="py-8 text-center text-slate-400">ব্যবসায়িক ব্যাংক লেনদেনের কোনো বিবরণ পাওয়া যায়নি।</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php if(Auth::user()->isSuperAdmin()): ?>
    <!-- Modal to Add New Bank Account -->
    <div id="bank-add-modal" class="hidden fixed inset-0 z-50 bg-slate-900/40 backdrop-blur-sm flex items-center justify-center p-4">
        <div class="bg-white rounded-3xl border border-slate-200 shadow-xl overflow-hidden max-w-md w-full flex flex-col text-slate-700">
            <div class="p-5 border-b border-slate-100 flex items-center justify-between bg-slate-50">
                <h3 class="text-xs font-black uppercase text-slate-500 tracking-wider">🏦 নতুন কর্পোরেট ব্যাংক অ্যাকাউন্ট যুক্ত করুন</h3>
                <button onclick="toggleBankAddModal()" class="text-slate-400 hover:text-slate-700 font-bold">✖</button>
            </div>
            <form action="<?php echo e(route('superadmin.storeBankAccount')); ?>" method="POST" class="p-5 space-y-4 text-xs font-bold text-slate-600">
                <?php echo csrf_field(); ?>
                <div>
                    <label class="block mb-1">ব্যাংকের নাম (Bank Name) *</label>
                    <input type="text" name="bank_name" required placeholder="যেমন: ডাচ-বাংলা ব্যাংক লিমিটেড" class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 focus:outline-none focus:ring-1 focus:ring-blue-500 font-semibold text-slate-800">
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block mb-1.5">অ্যাকাউন্ট হোল্ডার নাম *</label>
                        <input type="text" name="account_name" required placeholder="যেমন: Teletalk IT Co." class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 focus:outline-none focus:ring-1 focus:ring-blue-500 font-semibold text-slate-800">
                    </div>
                    <div>
                        <label class="block mb-1.5">অ্যাকাউন্ট নম্বর *</label>
                        <input type="text" name="account_number" required placeholder="N/A" class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 font-mono focus:outline-none focus:ring-1 focus:ring-blue-500 text-slate-800 font-semibold">
                    </div>
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block mb-1.5">ব্যাংক শাখা (Branch) *</label>
                        <input type="text" name="branch" required placeholder="যেমন: গুলশান শাখা" class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 focus:outline-none focus:ring-1 focus:ring-blue-500 font-semibold text-slate-800">
                    </div>
                    <div>
                        <label class="block mb-1.5">ওপেনিং ব্যালেন্স (Liquidity) *</label>
                        <input type="number" name="balance" required min="0" placeholder="0.00" class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 font-mono focus:outline-none focus:ring-1 focus:ring-blue-500 font-bold text-slate-800">
                    </div>
                </div>

                <div class="pt-2 border-t border-slate-100 flex items-center justify-end gap-3 text-xs">
                    <button type="button" onclick="toggleBankAddModal()" class="bg-slate-100 text-slate-700 px-4 py-2.5 rounded-xl hover:bg-slate-200 transition">বাতিল</button>
                    <button type="submit" class="bg-blue-600 text-white px-5 py-2.5 rounded-xl hover:bg-blue-700 shadow-md shadow-blue-500/10 cursor-pointer">অ্যাকাউন্ট যুক্ত করুন</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Modal to Edit Bank Account -->
    <div id="bank-edit-modal" class="hidden fixed inset-0 z-50 bg-slate-900/40 backdrop-blur-sm flex items-center justify-center p-4">
        <div class="bg-white rounded-3xl border border-slate-200 shadow-xl overflow-hidden max-w-md w-full flex flex-col text-slate-700">
            <div class="p-5 border-b border-slate-100 flex items-center justify-between bg-slate-50">
                <h3 class="text-xs font-black uppercase text-slate-500 tracking-wider">✏️ ব্যাংক অ্যাকাউন্ট এডিট ও ব্যালেন্স সংশোধন</h3>
                <button onclick="toggleBankEditModal()" class="text-slate-400 hover:text-slate-700 font-bold">✖</button>
            </div>
            <form id="bank-edit-form" method="POST" class="p-5 space-y-4 text-xs font-bold text-slate-600">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PATCH'); ?>
                
                <div>
                    <label class="block mb-1">ব্যাংকের নাম *</label>
                    <input type="text" id="bnk-edit-name" name="bank_name" required class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 focus:outline-none focus:ring-1 focus:ring-blue-500 font-semibold text-slate-800">
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block mb-1.5">হোল্ডার নাম *</label>
                        <input type="text" id="bnk-edit-ac-name" name="account_name" required class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 focus:outline-none focus:ring-1 focus:ring-blue-500 font-semibold text-slate-800 font-bold">
                    </div>
                    <div>
                        <label class="block mb-1.5">অ্যাকাউন্ট নম্বর *</label>
                        <input type="text" id="bnk-edit-ac-no" name="account_number" required class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 font-mono focus:outline-none focus:ring-1 focus:ring-blue-500 text-slate-800 font-semibold">
                    </div>
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block mb-1.5">ব্যাংক শাখা *</label>
                        <input type="text" id="bnk-edit-branch" name="branch" required class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 focus:outline-none focus:ring-1 focus:ring-blue-500 font-semibold text-slate-800">
                    </div>
                    <div>
                        <label class="block mb-1.5">সরাসরি লিকুইডিটি ব্যালেন্স সম্পাদন *</label>
                        <input type="number" id="bnk-edit-bal" name="balance" required min="0" class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 font-mono text-emerald-700 font-extrabold focus:ring-2 focus:ring-emerald-500 focus:outline-none">
                    </div>
                </div>

                <div>
                    <label class="block mb-1">অ্যাকাউন্ট স্ট্যাটাস *</label>
                    <select id="bnk-edit-status" name="status" required class="w-full bg-slate-50 border border-slate-200 rounded-xl p-2.5 font-semibold focus:outline-none focus:ring-1 focus:ring-indigo-500 text-slate-800">
                        <option value="Active">Active (সক্রিয়)</option>
                        <option value="Inactive">Inactive (নিষ্ক্রিয়)</option>
                    </select>
                </div>

                <div class="pt-2 border-t border-slate-100 flex items-center justify-end gap-3 text-xs">
                    <button type="button" onclick="toggleBankEditModal()" class="bg-slate-100 text-slate-700 px-4 py-2.5 rounded-xl hover:bg-slate-200 transition">বাতিল</button>
                    <button type="submit" class="bg-indigo-600 text-white px-5 py-2.5 rounded-xl hover:bg-indigo-700 shadow-md shadow-indigo-500/10 cursor-pointer">সমন্বয় সেভ করুন</button>
                </div>
            </form>
        </div>
    </div>
<?php endif; ?>

<script id="banking-mgmt-scripts">
    function toggleBankAddModal() {
        var modal = document.getElementById('bank-add-modal');
        if (modal) {
            modal.classList.toggle('hidden');
        }
    }

    function toggleBankEditModal() {
        var modal = document.getElementById('bank-edit-modal');
        if (modal) {
            modal.classList.toggle('hidden');
        }
    }

    function openBankEditModal(id, bankName, accountName, accountNumber, branch, balance, status) {
        document.getElementById('bnk-edit-name').value = bankName;
        document.getElementById('bnk-edit-ac-name').value = accountName;
        document.getElementById('bnk-edit-ac-no').value = accountNumber;
        document.getElementById('bnk-edit-branch').value = branch;
        document.getElementById('bnk-edit-bal').value = balance;
        document.getElementById('bnk-edit-status').value = status;

        document.getElementById('bank-edit-form').action = "/admin/banking/accounts/" + id + "/update";
        toggleBankEditModal();
    }
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\cash_management\resources\views/banking.blade.php ENDPATH**/ ?>