<style type="text/css">
    .btn {
        border-radius: 0 !important;
    }
</style>


<section class="margin-top-xs-55" style="">
    <div class="header-text mb-0">
        <div>
            <div class="row ">
                <div class="col-lg-12 col-md-12 col-sm-12 text-center">
                    <svg style="width:100%;height: 150px;" viewBox="0 0 1280 679" preserveAspectRatio="none" width="100%" height="100%">
                        <defs>
                            <g id="shape">
                                <path d="M0 0H1280V544.882C1280 544.882 1115 679 640 679C165 679 0 544.882 0 544.882V0Z" fill="#D9D9D9"></path>
                                <path d="M0 0H1280V544.882C1280 544.882 1115 679 640 679C165 679 0 544.882 0 544.882V0Z" fill="url(#gradient)"></path>
                            </g>
                            <radialGradient id="gradient" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(640 -261.197) rotate(90) scale(815.683 664.92)">
                                <stop stop-color="#4169E1"></stop>
                                <stop offset="1" stop-color="#071A34"></stop>
                            </radialGradient>
                        </defs>
                        <use href="#shape"></use>
                    </svg>
                    <div class="frame-image">
                        <div style="position: absolute; border-radius: inherit; inset: 0px;" data-framer-background-image-wrapper="true"><img decoding="async" sizes="100vw" src="<?php echo base_url(); ?>assets/lSHGuRrPALnsNPFyY1JslN8so.png" alt="" style="display: block; width: 100%; height: 100%; border-radius: inherit; object-position: center center; object-fit: cover;"></div>
                    </div>
                    <div class="text-body main-header-text">
                        <h1 class="text-center text-white"><b>Cart</b></h1>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Section -->
<section class="sptb">
    <div class="container">
        <div class="row">
            <!-- Course list -->
            <div class="col-xl-12 col-lg-12 col-md-12">
                <h3 class="mb-4">My Cart</h3>

                <div class="card">
                    <div class="card-body">
                        <?php if ($this->cart->contents()): ?>
                            <div class="table-responsive">
                                <table class="data-table-example table table-bordered table-hover mb-0 text-nowrap dataTable no-footer">
                                    <thead class="bg-light">
                                        <tr>
                                            <th>Thumbnail</th>
                                            <th>Course</th>
                                            <th>Price</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $discount = 0;
                                        foreach ($this->cart->contents() as $item):
                                            // Handle discount separately
                                            if (isset($item['options']['type']) && $item['options']['type'] === 'fbt_discount') {
                                                $discount += abs($item['price']);
                                                continue;
                                            }
                                        ?>
                                            <tr>
                                                <td width="100">
                                                    <img src="<?php echo base_url($item['options']['thumbnail']); ?>" alt="Image" width="80" class="rounded border shadow-sm">
                                                </td>
                                                <td><?php echo $item['name']; ?></td>
                                                <td>₹<?php echo number_format($item['price'], 2); ?></td>
                                                <td>
                                                    <a href="<?php echo base_url('cart/remove/' . $item['rowid']); ?>" class="btn btn-sm btn-danger">
                                                        <i class="fa fa-trash"></i> Remove
                                                    </a>
                                                </td>
                                            </tr>
                                        <?php endforeach; ?>
                                    </tbody>

                                    <tfoot>
                                        <?php if ($discount): ?>
                                            <tr>
                                                <th colspan="3" class="text-end text-success">FBT Bundle Discount</th>
                                                <th colspan="3" class="text-success">− ₹<?php echo number_format($discount, 2); ?></th>
                                            </tr>
                                        <?php endif; ?>
                                        <tr>
                                            <th colspan="3" class="text-end">Total</th>
                                            <th colspan="3">₹<?php echo number_format($this->cart->total(), 2); ?></th>
                                        </tr>
                                    </tfoot>

                                </table>
                            </div>

                            <!-- Coupon code and checkout -->
                            <div class="row mt-4">
                                <div class="col-md-6">
                                    <!-- <form method="post" action="<?php echo base_url('cart/apply_coupon'); ?>">
                                        <div class="input-group">
                                            <input type="text" name="coupon_code" class="form-control" placeholder="Enter coupon code">
                                            <button type="submit" class="btn btn-primary">Apply</button>
                                        </div>
                                    </form> -->
                                </div>
                                <div class="col-md-6 text-end">
                                    <?php if ($this->session->userdata('bcount_sess_logged_in')): ?>
                                        <a href="<?php echo base_url('course_buy'); ?>" class="btn btn-primary">
                                            Proceed to Checkout <i class="fa fa-arrow-right ms-1"></i>
                                        </a>
                                    <?php else: ?>
                                        <a href="<?php echo base_url('register/course'); ?>" class="btn btn-primary">
                                            Proceed to Checkout <i class="fa fa-arrow-right ms-1"></i>
                                        </a>
                                    <?php endif; ?>


                                </div>
                            </div>

                        <?php else: ?>
                            <div class="alert alert-warning text-center">
                                Your cart is empty.
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

            </div>
        </div>
    </div>
</section>