<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-body">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h1 class="h4 mb-0">Borrow Transactions</h1>
            <a href="<?php echo e(route('borrows.create')); ?>" class="btn btn-primary">Record Borrow</a>
        </div>

        <form class="d-flex flex-wrap flex-md-nowrap gap-2 mb-4 align-items-center" method="GET" action="<?php echo e(route('borrows.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('borrows.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>Agent</th>
                        <th>Currency</th>
                        <th>Target Account</th>
                        <th class="text-end">Quantity</th>
                        <th class="text-end">Rate</th>
                        <th>Status</th>
                        <th class="text-end">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $borrows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $borrow): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($borrow->created_at->format('Y-m-d')); ?></td>
                            <td><?php echo e(optional($borrow->agent)->name); ?></td>
                            <td><?php echo e(optional($borrow->currency)->code); ?></td>
                            <td><?php echo e(optional($borrow->account)->name); ?></td>
                            <td class="text-end"><?php echo e(number_format($borrow->quantity, 4)); ?></td>
                            <td class="text-end"><?php echo e(number_format($borrow->rate, 4)); ?></td>
                            <td>
                                <?php if($borrow->borrow_settled_at): ?>
                                    <span class="badge bg-success">Settled on <?php echo e($borrow->borrow_settled_at->format('Y-m-d')); ?></span>
                                <?php else: ?>
                                    <span class="badge bg-warning text-dark">Unsettled</span>
                                <?php endif; ?>
                            </td>
                            <td class="text-end">
                                <?php if(!$borrow->borrow_settled_at): ?>
                                    <a href="<?php echo e(route('borrows.settle', $borrow)); ?>" class="btn btn-sm btn-outline-success">Settle</a>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td class="text-muted text-center" colspan="8">No borrow 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/borrows/index.blade.php ENDPATH**/ ?>