<?php $__env->startSection('content'); ?>
<div class="container" ><!-- style="width: 600px;" -->
    <h2>Edit Investment</h2>

    <form action="<?php echo e(route('investments.update', $investment->id)); ?>" method="POST">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PUT'); ?>

        <!-- Investor -->
        <div class="mb-3">
            <label for="investor_id" class="form-label">Investor</label>
            <select name="investor_id" id="investor_id" class="form-control" required>
                <?php $__currentLoopData = $investors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inv): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($inv->id); ?>" 
                        <?php echo e($inv->id == $investment->investor_id ? 'selected' : ''); ?>>
                        <?php echo e($inv->name); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>


        <!-- Type -->
        <div class="mb-3">
            <label for="type" class="form-label">Type</label>
            <select name="type" id="type" class="form-control" required>
                <option value="">Select Option</option>
                <option value="car" <?php echo e(old('type', $investment->type ?? '') == 'car' ? 'selected' : ''); ?>>Car</option>
                <option value="in" <?php echo e(old('type', $investment->type ?? '') == 'in' ? 'selected' : ''); ?>>IN</option>
                <option value="out" <?php echo e(old('type', $investment->type ?? '') == 'out' ? 'selected' : ''); ?>>OUT</option>
            </select>
        </div>

        <!-- Car dropdown (hidden by default, shown if type=car) -->
        <div class="mb-3" id="car-section" style="display: none;">
            <label>Select Car (Active Only)</label>
            <select name="car_id" id="car_id" class="form-control">
                <option value="">-- Select Car --</option>
                <?php $__currentLoopData = $cars; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $car): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($car->id); ?>" 
                        <?php echo e($car->id == $investment->car_id ? 'selected' : ''); ?>>
                        <?php echo e($car->make); ?> / <?php echo e($car->model); ?> / <?php echo e($car->varient); ?> / <?php echo e($car->color); ?> / <?php echo e($car->registration_no); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>


        <!-- Amount -->
        <div class="mb-3">
            <label for="amount" class="form-label">Amount</label>
            <input type="number" name="amount" class="form-control" value="<?php echo e($investment->amount); ?>" required>
        </div>

        <!-- Date -->
        <div class="mb-3">
            <label for="date" class="form-label">Date</label>
            <input type="date" name="date" class="form-control" value="<?php echo e($investment->date); ?>" required>
        </div>

        <!-- Remarks -->
        <div class="mb-3">
            <label for="remarks" class="form-label">Remarks</label>
            <textarea name="remarks" class="form-control"><?php echo e($investment->remarks); ?></textarea>
        </div>

        <!-- Buttons -->
        <button type="submit" class="btn btn-success">Update</button>
        <a href="<?php echo e(route('investments.index')); ?>" class="btn btn-secondary">Cancel</a>
    </form>
</div>

<!-- Show/hide car dropdown dynamically -->
<script>
document.addEventListener('DOMContentLoaded', function () {
    const typeSelect = document.getElementById('type');
    const carSection = document.getElementById('car-section');

    function toggleCarSection() {
        if (typeSelect.value === 'car') {
            carSection.style.display = 'block';
            document.getElementById('car_id').setAttribute('required', 'required');
        } else {
            carSection.style.display = 'none';
            document.getElementById('car_id').removeAttribute('required');
        }
    }

    // Run on page load
    toggleCarSection();

    // Run when type changes
    typeSelect.addEventListener('change', toggleCarSection);
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/laravel-app12/resources/views/investments/edit.blade.php ENDPATH**/ ?>