<?php $__env->startSection('page-title', 'All Accounts'); ?>

<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <div class="btn-group" role="group" aria-label="Account types">
            <a href="<?php echo e(route('cash.index')); ?>" class="btn btn-success btn-lg">
                <i class="fas fa-money-bill-wave"></i> Cash
            </a>
            <a href="<?php echo e(route('bank-accounts.index')); ?>" class="btn btn-primary btn-lg">
                <i class="fas fa-university"></i> Bank
            </a>
            <a href="<?php echo e(route('digital-payments.index')); ?>" class="btn btn-info btn-lg">
                <i class="fas fa-mobile-alt"></i> Digital
            </a>
        </div>

        <div class="dropdown">
            <button class="btn dropdown-toggle" type="button" id="addAccountDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                <i class="fas fa-plus"></i> Add Account
            </button>
            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="addAccountDropdown">
                <li><a class="dropdown-item" href="<?php echo e(route('transactions.create', ['payment_method' => 'cash'])); ?>"><i class="fas fa-money-bill-wave me-2"></i> Cash</a></li>
                <li><a class="dropdown-item" href="<?php echo e(route('bank-accounts.create')); ?>"><i class="fas fa-university me-2"></i> Bank</a></li>
                <li><a class="dropdown-item" href="<?php echo e(route('digital-payments.create')); ?>"><i class="fas fa-mobile-alt me-2"></i> Digital</a></li>
            </ul>
        </div>
    </div>


    <!-- Filter Tabs -->
<div class="card mb-4">
    <div class="card-body py-2">
        <ul class="nav nav-pills nav-fill" id="accountFilter" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active" data-filter="all" type="button">
                    All <span class="badge bg-secondary ms-1"><?php echo e($allAccounts->count()); ?></span>
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" data-filter="cash" type="button">
                    <i class="fas fa-money-bill-wave me-1"></i> Cash
                    <span class="badge bg-success ms-1"><?php echo e($allAccounts->where('type', 'cash')->count()); ?></span>
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" data-filter="bank" type="button">
                    <i class="fas fa-university me-1"></i> Bank
                    <span class="badge bg-primary ms-1"><?php echo e($allAccounts->where('type', 'bank')->count()); ?></span>
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" data-filter="digital" type="button">
                    <i class="fas fa-mobile-alt me-1"></i> Digital
                    <span class="badge bg-info ms-1"><?php echo e($allAccounts->where('type', 'digital')->count()); ?></span>
                </button>
            </li>
        </ul>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const buttons = document.querySelectorAll('#accountFilter [data-filter]');
    const cards = document.querySelectorAll('[data-account-type]');

    buttons.forEach(btn => {
        btn.addEventListener('click', function() {
            buttons.forEach(b => b.classList.remove('active'));
            this.classList.add('active');

            const filter = this.dataset.filter;
            let visibleCount = 0;

            cards.forEach(card => {
                const type = card.dataset.accountType;
                if (filter === 'all' || type === filter) {
                    card.style.display = '';
                    visibleCount++;
                } else {
                    card.style.display = 'none';
                }
            });

            // Show/hide empty state
            const emptyState = document.querySelector('.text-center.py-5');
            if (emptyState) {
                emptyState.style.display = visibleCount === 0 ? 'block' : 'none';
            }
        });
    });
});
</script>

    <div class="card">
       <div class="card-body">
    <?php if($allAccounts->isEmpty()): ?>
        <div class="text-center py-5">
            <i class="fas fa-wallet fa-3x text-muted mb-3"></i>
            <h5 class="text-muted">No accounts yet</h5>
            <p class="text-muted small">Start by adding your first Cash, Bank, or Digital account.</p>
            <div class="dropdown">
                <button class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">
                    <i class="fas fa-plus"></i> Add Account
                </button>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="<?php echo e(route('transactions.create', ['payment_method' => 'cash'])); ?>">
                        <i class="fas fa-money-bill-wave me-2 text-success"></i>Cash
                    </a></li>
                    <li><a class="dropdown-item" href="<?php echo e(route('bank-accounts.create')); ?>">
                        <i class="fas fa-university me-2 text-primary"></i>Bank
                    </a></li>
                    <li><a class="dropdown-item" href="<?php echo e(route('digital-payments.create')); ?>">
                        <i class="fas fa-mobile-alt me-2 text-info"></i>Digital
                    </a></li>
                </ul>
            </div>
        </div>
    <?php else: ?>
        <div class="row g-4">
            <?php $__currentLoopData = $allAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="col-md-6 col-lg-4" data-account-type="<?php echo e($account->type); ?>">
                    <div class="card h-100 shadow-sm border-0">
                        <!-- Card Header -->
                        <div class="card-header d-flex justify-content-between align-items-center bg-white">
                            <div class="d-flex align-items-center">
                                <?php if($account->type === 'cash'): ?>
                                    <span class="bg-success bg-opacity-10 text-success rounded p-2 me-2">
                                        <i class="fas fa-money-bill-wave"></i>
                                    </span>
                                <?php elseif($account->type === 'bank'): ?>
                                    <span class="bg-primary bg-opacity-10 text-primary rounded p-2 me-2">
                                        <i class="fas fa-university"></i>
                                    </span>
                                <?php else: ?>
                                    <span class="bg-info bg-opacity-10 text-info rounded p-2 me-2">
                                        <i class="fas fa-mobile-alt"></i>
                                    </span>
                                <?php endif; ?>
                                <div>
                                    <h6 class="mb-0 fw-bold"><?php echo e($account->provider); ?></h6>
                                    <small class="text-muted"><?php echo e($account->account_name); ?></small>
                                </div>
                            </div>
                            <span class="badge bg-<?php echo e($account->is_active ? 'success' : 'secondary'); ?>">
                                <?php echo e($account->is_active ? 'Active' : 'Inactive'); ?>

                            </span>
                        </div>

                        <!-- Card Body -->
                        <div class="card-body">
                            <?php if($account->account_number): ?>
                                <p class="mb-2 small">
                                    <i class="fas fa-hashtag text-muted me-1"></i>
                                    <strong>Number:</strong> <?php echo e($account->account_number); ?>

                                </p>
                            <?php endif; ?>
                            <?php if($account->branch): ?>
                                <p class="mb-2 small">
                                    <i class="fas fa-building text-muted me-1"></i>
                                    <strong>Branch:</strong> <?php echo e($account->branch); ?>

                                </p>
                            <?php endif; ?>
                            <div class="d-flex justify-content-between align-items-center mt-3">
                                <div>
                                    <small class="text-muted d-block">Balance</small>
                                    <span class="fw-bold <?php echo e($account->balance >= 0 ? 'text-success' : 'text-danger'); ?>">
                                        <?php echo e(number_format($account->balance, 2)); ?>

                                    </span>
                                </div>
                                <div class="text-end">
                                    <small class="text-muted d-block">Transactions</small>
                                    <span class="fw-semibold"><?php echo e($account->transaction_count); ?></span>
                                </div>
                            </div>
                        </div>

                        <!-- Card Footer -->
                        <div class="card-footer bg-white border-top-0">
                            <div class="d-flex gap-2">
                                <a href="<?php echo e(route($account->route_prefix . '.edit', $account->id)); ?>"
                                   class="btn btn-sm btn-outline-primary flex-grow-1">
                                    <i class="fas fa-edit"></i> Edit
                                </a>
                                <?php if($account->type !== 'cash'): ?>
                                <form action="<?php echo e(route($account->route_prefix . '.destroy', $account->id)); ?>"
                                      method="POST" class="d-inline"
                                      onsubmit="return confirm('Delete this account? All related transactions will be affected.')">
                                    <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                                    <button type="submit" class="btn btn-sm btn-outline-danger">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </form>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>

        <!-- Quick Stats -->
        <div class="row mt-4">
            <div class="col-md-4">
                <div class="p-3 bg-success bg-opacity-10 rounded text-center">
                    <small class="text-muted d-block">Cash Balance</small>
                    <span class="fw-bold text-success">
                        <?php echo e(number_format($allAccounts->where('type', 'cash')->sum('balance'), 2)); ?>

                    </span>
                </div>
            </div>
            <div class="col-md-4">
                <div class="p-3 bg-primary bg-opacity-10 rounded text-center">
                    <small class="text-muted d-block">Bank Balance</small>
                    <span class="fw-bold text-primary">
                        <?php echo e(number_format($allAccounts->where('type', 'bank')->sum('balance'), 2)); ?>

                    </span>
                </div>
            </div>
            <div class="col-md-4">
                <div class="p-3 bg-info bg-opacity-10 rounded text-center">
                    <small class="text-muted d-block">Digital Balance</small>
                    <span class="fw-bold text-info">
                        <?php echo e(number_format($allAccounts->where('type', 'digital')->sum('balance'), 2)); ?>

                    </span>
                </div>
            </div>
        </div>
    <?php endif; ?>
</div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\startup sabbir\Desktop\jannat\sarvice-accounts\accounting-system\resources\views/accounts/all.blade.php ENDPATH**/ ?>