<?php $__env->startSection('content'); ?>
<div class="row g-4">
    <div class="col-lg-4">
        <div class="card">
            <div class="card-body">
                <h1 class="h4 mb-3">Adjust Balance</h1>
                <form method="POST" action="<?php echo e(route('accounts.adjust.store')); ?>">
                    <?php echo csrf_field(); ?>
                    
                    <div class="mb-3">
                        <label class="form-label" for="account_id">Account</label>
                        <select class="form-select" id="account_id" name="account_id" required>
                            <option value="">Select account</option>
                            <?php $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($account->id); ?>" <?php if(old('account_id') == $account->id): echo 'selected'; endif; ?>>
                                    <?php echo e($account->name); ?> (<?php echo e($account->currency->code); ?> - Balance: <?php echo e(number_format((float) $account->balance, 4)); ?>)
                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="amount">Amount</label>
                        <input type="number" step="0.0001" min="0.0001" class="form-control" id="amount" name="amount" value="<?php echo e(old('amount')); ?>" placeholder="0.0000" required>
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="adjustment_type">Adjustment Type</label>
                        <select class="form-select" id="adjustment_type" name="adjustment_type" required>
                            <option value="increase" <?php if(old('adjustment_type') === 'increase'): echo 'selected'; endif; ?>>Increase (+)</option>
                            <option value="decrease" <?php if(old('adjustment_type') === 'decrease'): echo 'selected'; endif; ?>>Decrease (-)</option>
                        </select>
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="date">Transaction Date</label>
                        <input type="date" class="form-control" id="date" name="date" value="<?php echo e(old('date', now()->format('Y-m-d\TH:i'))); ?>" required>
                    </div>

                    <div class="mb-3">
                        <label class="form-label" for="description">Description / Reason</label>
                        <textarea class="form-control" id="description" name="description" rows="3" placeholder="e.g. Audit correction, system synch issue" required><?php echo e(old('description')); ?></textarea>
                    </div>

                    <button class="btn btn-primary w-100" type="submit">Apply Adjustment</button>
                </form>
            </div>
        </div>
    </div>

    <div class="col-lg-8">
        <div class="card">
            <div class="card-body">
                <h2 class="h4 mb-3">Recent Adjustments</h2>
                <form class="d-flex flex-wrap flex-md-nowrap gap-2 mb-4 align-items-center" method="GET" action="<?php echo e(route('accounts.adjust.index')); ?>">
                    <div class="flex-grow-1">
                        <input type="text" class="form-control" name="search" value="<?php echo e($filters['search'] ?? ''); ?>" placeholder="Search description, account...">
                    </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('accounts.adjust.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>Account</th>
                                <th>Currency</th>
                                <th class="text-end">Amount Adjusted</th>
                                <th>Description</th>
                                <th class="text-end">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $adjustments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $adjustment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e($adjustment->created_at->format('Y-m-d H:i')); ?></td>
                                    <td class="fw-semibold"><?php echo e(optional($adjustment->account)->name ?? 'Deleted Account'); ?></td>
                                    <td><?php echo e($adjustment->currency->code); ?></td>
                                    <td class="text-end fw-semibold text-<?php echo e((float) $adjustment->quantity >= 0 ? 'success' : 'danger'); ?>">
                                        <?php echo e((float) $adjustment->quantity >= 0 ? '+' : ''); ?><?php echo e(number_format((float) $adjustment->quantity, 4)); ?>

                                    </td>
                                    <td><?php echo e($adjustment->description); ?></td>
                                    <td class="text-end">
                                        <form action="<?php echo e(route('transactions.destroy', $adjustment)); ?>" method="POST" onsubmit="return confirm('Are you sure you want to delete this adjustment? This will completely reverse the account balance adjustment.')" style="display:inline-block;">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="submit" class="btn btn-outline-danger btn-sm">Delete</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td class="text-muted text-center" colspan="6">No adjustments recorded yet.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </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/accounts/adjust.blade.php ENDPATH**/ ?>