<?php $__env->startSection('content'); ?>
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
    <h1 class="h3 mb-0">Pending Transactions</h1>
</div>

<div class="card">
    <div class="card-body">
        <form class="d-flex flex-wrap flex-md-nowrap gap-2 mb-4 align-items-center" method="GET" action="<?php echo e(route('transactions.pending.index')); ?>">
            <div class="flex-grow-1">
                <input type="text" class="form-control" name="search" value="<?php echo e($filters['search'] ?? ''); ?>" placeholder="Search description, currency...">
            </div>
            <div class="flex-grow-1">
                <select class="form-select" name="agent_id">
                    <option value="">All Agents</option>
                    <?php $__currentLoopData = $agents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $agent): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($agent->id); ?>" <?php if(($filters['agent_id'] ?? '') == $agent->id): echo 'selected'; endif; ?>>
                            <?php echo e($agent->name); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div>
                <input type="date" class="form-control" name="date_from" value="<?php echo e($filters['date_from'] ?? ''); ?>" title="From Date">
            </div>
            <div>
                <input type="date" class="form-control" name="date_to" value="<?php echo e($filters['date_to'] ?? ''); ?>" title="To Date">
            </div>
            <div class="d-flex gap-1">
                <button type="submit" class="btn btn-primary px-3">Filter</button>
                <a href="<?php echo e(route('transactions.pending.index')); ?>" class="btn btn-outline-secondary px-3">Reset</a>
            </div>
        </form>
        <div class="table-responsive">
            <table class="table table-striped align-middle">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Type</th>
                        <th>Agent</th>
                        <th>Target Currency</th>
                        <th class="text-end">Total Quantity</th>
                        <th class="text-end">Calculated Rate</th>
                        <th class="text-end">Payment Amount</th>
                        <th class="text-end">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($transaction->created_at->format('Y-m-d H:i')); ?></td>
                            <td>
                                <span class="badge bg-<?php echo e($transaction->type === 'buy' ? 'primary' : 'warning'); ?> text-capitalize text-dark">
                                    <?php echo e($transaction->type); ?> (Pending)
                                </span>
                            </td>
                            <td><?php echo e(optional($transaction->agent)->name ?? '-'); ?></td>
                            <td><?php echo e($transaction->currency->code); ?></td>
                            <td class="text-end fw-bold"><?php echo e(number_format((float) $transaction->quantity + (float) $transaction->handling_fee, 4)); ?> <?php echo e($transaction->currency->code); ?></td>
                            <td class="text-end"><?php echo e(number_format((float) $transaction->rate, 4)); ?></td>
                            <td class="text-end"><?php echo e(number_format((float) $transaction->payment_amount, 4)); ?> <?php echo e(optional($transaction->paymentCurrency)->code); ?></td>
                            <td class="text-end">
                                <div class="btn-group btn-group-sm">
                                    <form action="<?php echo e(route('transactions.pending.received', $transaction)); ?>" method="POST" onsubmit="return confirm('Confirm receipt of this currency? This will credit the target account.')" style="display:inline;">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="btn btn-success">
                                            <i class="feather icon-check"></i> Received
                                        </button>
                                    </form>

                                    <?php if($transaction->type === 'buy'): ?>
                                        <a class="btn btn-outline-primary" href="<?php echo e(route('transactions.buy.edit', $transaction)); ?>" title="Edit">
                                            <i class="feather icon-edit-2"></i> Edit
                                        </a>
                                    <?php elseif($transaction->type === 'sell'): ?>
                                        <a class="btn btn-outline-primary" href="<?php echo e(route('transactions.sell.edit', $transaction)); ?>" title="Edit">
                                            <i class="feather icon-edit-2"></i> Edit
                                        </a>
                                    <?php endif; ?>

                                    <form action="<?php echo e(route('transactions.destroy', $transaction)); ?>" method="POST" onsubmit="return confirm('Are you sure you want to delete this transaction? This will reverse all balance effects.')" style="display:inline;">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="btn btn-outline-danger" title="Delete">
                                            <i class="feather icon-trash-2"></i> Delete
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td class="text-muted text-center" colspan="9">No pending transactions found.</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH F:\christopher\currencychangerui\resources\views/transactions/pending.blade.php ENDPATH**/ ?>