<?php $__env->startSection('content'); ?>
<div class="master-main mainContent mobile maincontent-design2 middlebackground background-design5">
    <div class="container">
        <div class="row multi">
            <div class="hidden"></div>
            
            <div class="col-xs-12 col-single tabbed main-content">
                <div class="content-inner-container mypromo-content">
                    
                    
                    <input type="hidden" name="rollingBonusID" id="rollingBonusID" />
                    
                    
                    <div class="nav-container">
                        <button type="button" id="Account_Deposit" class="btn btn-tab" style="order: 10" onclick="gotoView('/mobile/account/deposit')">
                            <span class="icon icon-deposit"></span>
                            <span>Deposit</span>
                        </button>
                        <button type="button" id="Account_Withdraw" class="btn btn-tab" style="order: 10" onclick="gotoView('/mobile/account/withdraw')">
                            <span class="icon icon-withdraw"></span>
                            <span>Withdraw</span>
                        </button>
                        <button type="button" id="Account_WDHistory" class="btn btn-tab" style="order: 10" onclick="gotoView('/mobile/account/walletsummary')">
                            <span class="icon icon-history"></span>
                            <span>History</span>
                        </button>
                        <button type="button" id="Account_MyPromo" class="btn btn-tab" style="order: 10" onclick="gotoView('/mobile/account/mypromo')">
                            <span class="icon icon-promo"></span>
                            <span>Promo saya</span>
                        </button>
                        <button type="button" id="Account_Wallet" class="btn btn-tab" style="order: 10" onclick="gotoView('/mobile/account/wallet')">
                            <span class="icon icon-saldo"></span>
                            <span>Saldo</span>
                        </button>
                    </div>

                    <h2 class="main-content-page-title">Promo saya</h2>
                    
                    <div class="promocontainer">
                        <div class="row">
                            
                            
                            <?php $__empty_1 = true; $__currentLoopData = $bonus_active; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $promo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <div class="col-xs-12" style="margin-bottom: 15px;">
                                    <div class="well" style="background: #1a1a1a; border: 1px solid #333; padding: 15px; border-radius: 8px;">
                                        
                                        
                                        <h4 style="color: #f3c300; margin-top: 0; border-bottom: 1px solid #444; padding-bottom: 10px; font-size: 15px;">
                                            <?php echo e($promo->bonus_title); ?>

                                        </h4>
                                        
                                        
                                        <table style="width: 100%; color: #ccc; font-size: 12px; margin-bottom: 15px;">
                                            <tr>
                                                <td style="padding: 5px 0;">Bonus:</td>
                                                <td style="text-align: right; color: #28a745; font-weight: bold;">Rp <?php echo e(number_format((float)$promo->bonus_amount, 0, ',', '.')); ?></td>
                                            </tr>
                                            <tr>
                                                <td style="padding: 5px 0;">Target TO:</td>
                                                <td style="text-align: right; color: #ff6600;">Rp <?php echo e(number_format((float)$promo->turn_over, 0, ',', '.')); ?></td>
                                            </tr>
                                            <tr>
                                                <td style="padding: 5px 0;">Tanggal:</td>
                                                <td style="text-align: right;"><?php echo e(date('d-m-Y', strtotime($promo->created_at))); ?></td>
                                            </tr>
                                            <tr>
                                                <td style="padding: 5px 0;">Status:</td>
                                                <td style="text-align: right;">
                                                    <?php if($promo->status == 0): ?>
                                                        <span class="label label-warning">Belum Tercapai</span>
                                                    <?php else: ?>
                                                        <span class="label label-success">Selesai</span>
                                                    <?php endif; ?>
                                                </td>
                                            </tr>
                                        </table>

                                        
                                        <?php if($promo->status == 0): ?>
                                        <div class="text-center" data-id="<?php echo e($promo->id); ?>" style="display: flex; gap: 8px;">
                                            <button class="btn btn-danger btn-sm" onclick="return CheckSurrenderBonusClickRepeat(this);" style="flex: 1; padding: 6px 0; font-size: 12px;">
                                                <i class="glyphicon glyphicon-remove"></i> Batal
                                            </button>
                                            
                                            <button class="btn btn-success btn-sm" onclick="return CheckRollingBonusClaimclickRepeat(this);" style="flex: 1; padding: 6px 0; font-size: 12px;">
                                                <i class="glyphicon glyphicon-ok"></i> Klaim
                                            </button>
                                        </div>
                                        <?php endif; ?>

                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                
                                <table class="col-xs-12 no-bonus">
                                    <tr>
                                        <td class="text-center" style="padding: 40px 20px; background: #1a1a1a; border: 1px dashed #444; border-radius: 8px; color: #aaa;">
                                            <i class="glyphicon glyphicon-info-sign" style="font-size: 30px; margin-bottom: 10px; display: block;"></i>
                                            Tidak ada bonus/promosi yang sedang berjalan
                                        </td>
                                    </tr>
                                </table>
                            <?php endif; ?>

                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>
<script>
    // ==========================================
    // FUNGSI SLIDER NAVIGASI MOBILE
    // ==========================================
    $(function () {
        var navContainerEl = $('.tabbed .nav-container');
        setNavButtonActiveClass();
        showSlideIndicator(true, navContainerEl);
        
        $('.tabbed .nav-container').on('scroll', function (e) {
            if ($(this).find('.slide-indicator').hasClass('start')) showSlideIndicator(false, navContainerEl);
        });
        
        var settingSeq = "Account_Deposit,Account_Withdraw,Account_WDHistory,Account_MyPromo,Account_Wallet";
        var arrSeq = (settingSeq !== "") ? settingSeq.split(",") : [];
        if (arrSeq.length > 0) {
            arrSeq.forEach(function (element, index) {
                if (element !== "" && element !== null && typeof element !== "undefined") navContainerEl.find('#' + element).css("order", index);
            });
        }
        
        showOOBEl(navContainerEl.find("button.active"), navContainerEl);
        updateIndicatorWidth();
        $(window).on("resize", updateIndicatorWidth);
    });

    var isClickTab = false;
    function gotoView(page) {
        if (isClickTab) return;
        isClickTab = true;
        location.href = page;
        setTimeout(function() { isClickTab = false; }, 2000);
    }

    function setNavButtonActiveClass() {
        var activeView = "Account_MyPromo";
        var btnNavEl = $("#" + activeView);
        if (btnNavEl && btnNavEl.length > 0) {
            btnNavEl.addClass("active");
            btnNavEl.attr('onclick', "");
        }
    }

    function showSlideIndicator(isShow, element) {
        if (isShow == "" || isShow == null || typeof isShow == undefined) isShow = false;
        var slideIndicatorEl = "";
        var slideIndicatorContainer = "<div class=\"slide-indicator stop\"><span class=\"glyphicon glyphicon-chevron-right\" ></span><span class=\"glyphicon glyphicon-chevron-right\" style=\"left: -10px;\"></span></div>";
        if (element.find('.slide-indicator').length == 0) element.append(slideIndicatorContainer);
        slideIndicatorEl = element.find('.slide-indicator');
        var navContainerLastButtonEl = element.find('button').last();
        if (slideIndicatorEl && slideIndicatorEl.length > 0) {
            if (isShow) {
                if (navContainerLastButtonEl && typeof navContainerLastButtonEl === "object" && navContainerLastButtonEl.length > 0) {
                    const rect = navContainerLastButtonEl[0].getBoundingClientRect();
                    if (rect.right > window.innerWidth) {
                        slideIndicatorEl.show();
                        slideIndicatorEl.addClass('start').removeClass('stop');
                        slideIndicatorEl.css('animation-play-state', 'running');
                    }
                }
            } else {
                slideIndicatorEl.hide();
                slideIndicatorEl.removeClass('start').addClass('stop');
                slideIndicatorEl.css('animation-play-state', 'paused');
            }
        }
    }

    function showOOBEl(el, elContainer) {
        if (el && el.length > 0 && elContainer && elContainer.length > 0) {
            let containerRect = elContainer[0].getBoundingClientRect();
            let activeButtonRect = el[0].getBoundingClientRect();
            if (activeButtonRect.right > containerRect.right) elContainer.scrollLeft(elContainer.scrollLeft() + (activeButtonRect.right - containerRect.left));
        }
    }

    function updateIndicatorWidth() {
        let navContainer = $(".tabbed .nav-container");
        if (navContainer.length) {
            if ($("#nav-bottom-border").length === 0) {
                $("<style id='nav-bottom-border'>.tabbed .nav-container::after { width: " + navContainer[0].scrollWidth + "px; }</style>").appendTo("head");
            }
        }
    }

    // ==========================================
    // FUNGSI AKSI KLAIM & SURRENDER
    // ==========================================
    var submit = 0;

    function CheckSurrenderBonusClickRepeat(btn) {
        if (!confirm("Bonus akan dibatalkan jika surrender sekarang. Apakah Anda yakin untuk membatalkan bonus ini?")) return false;
        if (++submit > 1) return false;
        
        try {
            var idPromo = $(btn).parent().data('id');
            $('#rollingBonusID').val(idPromo); // Simpan ID ke hidden input
            
            // Lakukan Ajax / aksi form submit pembatalan di sini
            // alert("Berhasil menyiapkan ID " + idPromo + " untuk Surrender");
            
            return true;
        } catch (e) {
            alert("Surrender Error: Terjadi kesalahan.");
            submit = 0;
            return false;
        }
    }

    function CheckRollingBonusClaimclickRepeat(btn) {
        if (!confirm("Apakah Anda yakin untuk klaim promosi ini? Pastikan target Turn Over telah tercapai.")) return false;
        if (++submit > 1) return false;
        
        try {
            var idPromo = $(btn).parent().data('id');
            $('#rollingBonusID').val(idPromo); // Simpan ID ke hidden input
            
            // Lakukan Ajax / aksi form submit klaim bonus di sini
            // alert("Berhasil menyiapkan ID " + idPromo + " untuk Klaim");
            
            return true;
        } catch (e) {
            alert("Error: Gagal memproses klaim promosi.");
            submit = 0;
            return false;
        }
    }
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('frontend.mobile.pages.account.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /www/wwwroot/website/sewa/dragon158/resources/views/frontend/mobile/pages/account/pages/mypromo.blade.php ENDPATH**/ ?>