<?php $__env->startSection('content'); ?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">

    <div class="container">
        
        <?php if(session('success')): ?>
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <?php echo e(session('success')); ?>

                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        <?php endif; ?>

        <?php if(session('error')): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <?php echo e(session('error')); ?>

                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        <?php endif; ?>

        <?php if($errors->any()): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <ul class="mb-0">
                    <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li><?php echo e($error); ?></li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        <?php endif; ?>

        <div class="text-center mb-1">
            <h1 class="display-8 fw-bold text-uppercase text-danger" style="letter-spacing: 2px;">
                Khan Motor's 
            </h1>
            <!-- <hr class="w-25 mx-auto border-5 border-danger"> -->
        </div>

        <h2 class="text-center mb-4">Car Sales</h2>
        <div class="mb-3 d-flex justify-content-end">
        <div class="input-group" style="width: 30%;">
            <span class="input-group-text bg-white">
                <i class="bi bi-search"></i>
            </span>
            <input type="text" id="tableSearch" class="form-control" placeholder="Search in table...">
        </div>
    </div>
        <table class="table table-bordered table-striped">
            <thead>
                <tr style="text-align: center;">
                    <th>Car ID</th>
                    <th>Recipt No</th>
                    <th>Registration No</th>
                    <th>Make</th>
                    <th>Varient</th>
                    <th>Color</th>
                    <th>Model</th>
                    <th>Seller Name</th>
                    <th>Buyer Name</th>
                    <th>Sold Price</th>
                    <th>Received</th>
                    <th>Date</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $carSales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sale): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr style="text-align: center;">
                        <td><?php echo e($loop->iteration); ?></td>
                        <td>KM-<?php echo e(\Carbon\Carbon::parse($sale->date)->format('Y')); ?>-<?php echo e($sale->id); ?></td>
                        <td><?php echo e($sale->registration_no); ?></td>
                        <td><?php echo e($sale->make); ?></td>
                        <td><?php echo e($sale->varient); ?></td>
                        <td><?php echo e($sale->color); ?></td>
                        <td><?php echo e($sale->model); ?></td>
                        <td><?php echo e($sale->seller_name); ?></td>
                        <td><?php echo e($sale->buyer_name); ?></td>
                        <td><?php echo e($sale->soled_price); ?></td>
                        <td><?php echo e($sale->received_amount); ?></td>
                        <td><?php echo e(\Carbon\Carbon::parse($sale->date)->format('d/m/Y')); ?></td>
                        <td class="action-buttons">
                            <a href="<?php echo e(route('car.sales.show', $sale->id)); ?>" class="btn btn-info"><i class="bi bi-eye"></i></a>
                            <a href="<?php echo e(route('car.sales.print', $sale->id)); ?>" class="btn btn-success"><i class="bi bi-printer"></i></a>
                            <br>
                            <a href="<?php echo e(route('edit.sale.info', $sale->id)); ?>" class="btn btn-primary btn-"><i class="bi bi-pencil"></i></a>
                            

                            <!-- Receive Payment Button -->
<!-- Add Payment Button -->
<button class="btn btn-warning" data-bs-toggle="modal" data-bs-target="#paymentModal<?php echo e($sale->id); ?>">
    <i class="bi bi-cash-stack"></i>
</button>


<!-- Modal -->
<div class="modal fade" id="paymentModal<?php echo e($sale->id); ?>" tabindex="-1" aria-labelledby="paymentModalLabel<?php echo e($sale->id); ?>" aria-hidden="true">
  <div class="modal-dialog">
    <form action="<?php echo e(route('car.sales.update.payment', $sale->id)); ?>" method="POST">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PATCH'); ?>
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="paymentModalLabel<?php echo e($sale->id); ?>">Add Payment for <?php echo e($sale->buyer_name); ?></h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
              <div class="mb-3">
                  <label for="received_amount" class="form-label">New Payment Amount</label>
                  <input type="number" class="form-control" name="additional_amount" min="1" required>
              </div>
              <p class="text-muted">Current Received: <?php echo e($sale->received_amount); ?></p>
              <p class="text-muted">Total Price: <?php echo e($sale->soled_price); ?></p>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-success">Add Payment</button>
            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
          </div>
        </div>
    </form>
  </div>
</div>







                            <form action="<?php echo e(route('car.sales.destroy', $sale->id)); ?>" method="POST" style="display:inline;">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="btn btn-danger"
                                    onclick="return confirm('Are you sure you want to delete this record?');">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
<?php $__env->stopSection(); ?>



<script>
// function printForm(carId) {
//     window.open(`/cars/${carId}/print`, '_blank');
// }

document.addEventListener('DOMContentLoaded', function () {
    const searchInput = document.getElementById('tableSearch');
    const tableRows = document.querySelectorAll('table tbody tr');

    searchInput.addEventListener('keyup', function () {
        const query = this.value.toLowerCase();

        tableRows.forEach(function (row) {
            const rowText = row.textContent.toLowerCase();
            row.style.display = rowText.includes(query) ? '' : 'none';
        });
    });
});
</script>



<style>
        .action-buttons {
        white-space: nowrap;
        line-height: 30px;
        }
    .drift-car {
        position: fixed;
        bottom: 220px;
        left: -200px;
        width: 500px;
        height: auto;
        z-index: 9999;
        animation: drift 4s ease-out forwards;
        pointer-events: none;
    }

    @keyframes  drift {
        0% { left: -200px; transform: rotate(0deg) scale(1); opacity: 0.5; }
        50% { transform: rotate(0deg) scale(1.2); }
        100% { left: 120%; transform: rotate(0deg) scale(0.8); opacity: 1; }
    }
</style>

<script>
    function showDriftAnimation() {
        const carImage = document.createElement('img');
        carImage.src = '/drift2.png'; // <- **change this to your car drift image**
        carImage.classList.add('drift-car');
        document.body.appendChild(carImage);

        setTimeout(() => {
            carImage.remove();
        }, 3000); // remove after animation
    }
</script>

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