<!DOCTYPE html><html><head>
	<title><?php echo $judul_app[0]['judul_app'];?></title>
	<meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=yes">
    <meta name="description" content="<?php echo $judul_app[0]['deskripsi_toko'];?>">
    <link rel="icon" href="<?php echo base_url('upload');?>/favicon.png">

    <link rel="stylesheet" href="<?php echo base_url('public/main');?>/css/bootstrap.css">
	<link rel="stylesheet" href="<?php echo base_url('public/main');?>/css/C0ZQJyIsETSp.css">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url('public/main');?>/css/style_5.css">

	<script src="<?php echo base_url('public/main');?>/js/akrijVHqSezO.js"></script>
    <script src="<?php echo base_url('public/main');?>/js/Mopviz8qZA7L.js"></script>

    <script type="text/javascript" src="<?php echo base_url('public/main');?>/js/cgc5FZTlKIMz.js"></script>
    <script src="<?php echo base_url('public/main');?>/js/pJmXAZ9oHmFn.js"></script>
    <script src="<?php echo base_url('public/main');?>/js/7dVeiyDoPwoP.js"></script>
</head>
<body style="background-image: url(<?php echo site_url('/upload/wall-2.png');?>); background-position: center; background-size: cover; background-repeat: no-repeat; background-color: black; min-height: 60em;">

	<canvas id="my-canvas" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: none;"></canvas>
	<section class="container">	
		<div id="popup-container-ads" class="popup-container">
            <div id="popup-body" class="popup-body popup-container-ads" style="width: 300px; height: 72px;">
                <div class="popup-close" onclick="close_popup_start()"><center><b>x</b></center></div>
                <h6 style="text-align: center; padding: 17px;">SELAMAT DATANG DI <br> <?php echo $judul_app[0]['judul_app'];?></h6>
            </div>
        </div>		

        <div id="popup-container-win" class="popup-container" style="display: none;">
            <div id="popup-body" class="popup-body" style="height: 563px; background: none;">
                <div class="popup-close" onclick="close_popup_winner()"><center><b>x</b></center></div>
                <div id="popup-header" class="popup-header" style="background: none;">
                    <center><h5 id="title-popup-win" style="padding: 10px;"><b>Selamat Anda Mendapatkan</b></h5></center>
                </div>
                
                <div style="height: 91.5%;width: 100%; padding: 20px 0px;">
                    <table style="width: 100%;">
                    	<tbody><tr>
	                    	<td align="center" style="padding: 20px 0px;">
	                    		<img id="item-image">
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td align="center" style="color: #f8df03;">
	                    		<h3 id="item-value">IDR 18.000,00</h3>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td align="center" style="padding: 15px 30px; color: #f8df03;">
	                    		<h6 id="item-description" style="color: white; margin-bottom: 10px;">Selamat anda mendapatkan hadiah <b><span id="item-name"></span> - <span id="item-prize"></span></b>. Silahkan anda Screenshot sebagai bukti kemenangan anda!</h6>

	                    		<h6 style="margin: 0;">USERNAME : <span id="voucher-username">jojo_cornor</span></h6>
	                    		<h6 style="margin: 0;">KODE TIKET : <span id="voucher-code">101010</span></h6>
	                    	</td>
	                    </tr>
	                    <tr>
	                    	<td align="center" style="padding: 10px 0px;">
	                    		<a class="claimed" href="https://wa.me/6281285854756" onclick="close_popup_winner()" target="_blank"><b>KLAIM SEKARANG</b></a>
	                    	</td>
	                    </tr>
                    </tbody></table>
                </div>
            </div>
        </div>

        <div id="popup-container-history" class="popup-container" style="display: none;">
            <div id="popup-body" class="popup-body" style="height: 563px;">
                <div class="popup-close" onclick="close_popup_history()"><center><b>x</b></center></div>
                <div id="popup-header" class="popup-header">
                    <center><h6 id="title-popup-win" style="padding: 10px;"><b>60 Daftar Riwayat Spin Terakhir</b></h6></center>
                </div>
                
                <div style="overflow-y: scroll;height: 91.5%;width: 100%;">
                    <div style="padding: 5px;">
                    	<table style="width: 100%;">
                    		<thead>
                    			<tr>
                    				<th align="center" valign="center" style="width: 10%; text-align: center;">NO</th>
		                    		<th align="center" valign="center" style="width: 50%;">USERNAME</th>
		                    		<th align="center" valign="center" style="width: 40%; text-align: center;">WINNER</th>
		                    	</tr>
                    		</thead>
	                    	<tbody id="history-container">
	                    		<tr>
	                    			<td style="width: 10%; padding: 5px; text-align: center;">1</td>
		                    		<td style="width: 50%; padding: 5px;">Username</td>
		                    		<td style="width: 40%; padding: 5px; text-align: center;">IDR 18.000,00</td>
		                    	</tr>
	                    	</tbody>
	                    </table>
                    </div>
                </div>
            </div>
        </div>
	</section>

	<script src="<?php echo base_url('public/main');?>/js/dZVbifHRnC9n.js" crossorigin="anonymous"></script>
	<script src="<?php echo base_url('public/main');?>/js/h3mxO1NuPTjZ.js" crossorigin="anonymous"></script>
	<script type="text/javascript" src="<?php echo base_url('public/main');?>/js/2dMLd1GLhKhg.js"></script>

    <script>
    	var data_winner = null, theWheel, claim_message = 'Halo bossku, saya dengan ID *{{username}}* ingin klaim hadiah *{{item_name}} {{item_value}}* bossku';
    	let audio = new Audio ('<?php echo base_url('public/main/audio/spin.mp3');?>');
    	audio.volume = 0.2
	    audio.loop = true;

    	if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
		 var v_mobile = '<table style="margin-left: 0px;">'+
							'<tr>'+
								'<td align="center" valign="center">'+
									'<img class="logo-mobile" src="<?php echo site_url('/upload/logoweb.png');?>" style="padding: 10px; margin-top: 10%; padding-bottom: 0; ">'+
								'</td>'+
							'</tr>'+
							'<tr>'+
								'<td align="center" valign="center">'+
									'<div class="container_spinner_mobile" style="">'+
									  	'<canvas class="inner" id="canvas" width="620" height="620">'+
									        '<p style="color: white" align="center">Sorry, your browser doesn\'t support canvas. Please try another.</p>'+
									    '</canvas>'+
									'</div>'+
									'<img src="upload/spin-6.png" style="height: auto;width: 250px;margin-bottom: 20%; position: relative; transform: scale(1.5);">'+
								'</td>'+
							'</tr>'+
							'<tr>'+
								'<td align="center" valign="center">'+
						        	'<div class="margin-box_mobile">'+
													'<h2 style="color: white; margin: 7px; font-size: 23px;"><b>Masukkan Kode Tiket</b></h2>'+
									        		'<input type="text" name="voucher" placeholder="Kode Tiket" autocomplete="off">'+
									        		'<small id="error_message_voucher" class="text-warning form-label"></small>'+
									        		'<div class="row">'+
									        			'<div class="col-md-6" style="margin-top: 20px;">'+
									        				'<button type="submit" name="start" class="submit" onclick="startSpin()"><b>SPIN</b></button>'+
									        			'</div>'+
									        			'<div class="col-md-6" style="margin-top: 20px;">'+
									        				'<button type="submit" name="history" class="submit" onclick="getHistory()"><b>RIWAYAT</b></button>'+
									        			'</div>'+
									        		'</div>'+
						        	'</div>'+
						        '</td>'+
							'</tr>'+
						'</table>';
			$("body").prepend(v_mobile);
			setSpinner();
		}else{
			var v_desktop = '<img src="<?php echo site_url('/upload/wall-2.png');?>" style="width: 100%; height: 100vh; position: fixed;"/>'+
							'<div class="row">'+
								'<div class="col-md-6">'+
									'<div class="container_spinner">'+
									  	'<canvas class="inner" id="canvas" width="620" height="620">'+
							                '<p style="color: white" align="center">Sorry, your browser doesn\'t support canvas. Please try another.</p>'+
							            '</canvas>'+
									  	'<img class="inner" id="img-desktop" src="<?php echo site_url('/upload/spin-6.png');?>">'+
									'</div>'+
								'</div>'+
								'<div class="col-md-6">'+
									'<table class="main">'+
										'<tr>'+
											'<td align="center" valign="center">'+
									        	'<div class="margin-box" style="margin-top: 80%;">'+
									        		'<img class="logo-web" src="<?php echo site_url('/upload/logoweb.png');?>" style="width: 100%;">'+
													'<h2 style="color: white; margin: 27px;"><b>Masukkan Kode Tiket</b></h2>'+
									        		'<input type="text" name="voucher" placeholder="Kode Tiket" autocomplete="off">'+
									        		'<small id="error_message_voucher" class="text-warning form-label"></small>'+
									        		'<div class="row">'+
									        			'<div class="col-md-6" style="margin-top: 20px;">'+
									        				'<button type="submit" name="start" class="submit" onclick="startSpin()"><b>SPIN</b></button>'+
									        			'</div>'+
									        			'<div class="col-md-6" style="margin-top: 20px;">'+
									        				'<button type="submit" name="history" class="submit" onclick="getHistory()"><b>RIWAYAT</b></button>'+
									        			'</div>'+
									        		'</div>'+
									        	'</div>'+
									        '</td>'+
										'</tr>'+
									'</table>'+
								'</div>'+
							'</div>';

			$("body").prepend(v_desktop);
			setSpinner();
		}

		function visitPage(){
        window.location='login/logout';
    	}


        function setSpinner(){
            theWheel = new Winwheel({

				// 'numSegments'     : <?php echo count($image); ?>,         // Specify number of segments.
                // 'outerRadius'       : 200, 
                
                // 'textFontSize'      : 16,
                // 'textOrientation'   : 'curved',
                // 'textAlignment'     : 'outer',
                // 'textMargin'        : 90,
                // 'textFontFamily'    : 'monospace',
                // 'textStrokeStyle'   : 'black',
                // 'textLineWidth'     : 3,
                // 'textFillStyle'     : 'white',
                // 'pointerAngle'		: 5,
                // 'drawMode'          : 'segmentImage', 

                // 'numSegments'       : 8,
                'outerRadius'     : 235,        // Set outer radius so wheel fits inside the background.
                // 'innerRadius'     : 50,         // Make wheel hollow so segments don't go all way to center.
                'textFontSize'    : 24,         // Set default font size for the segments.
                'textOrientation' : 'curved', // Make text vertial so goes down from the outside of wheel.
                'textAlignment'   : 'outer',    // Align text to outside of wheel.
                'textFillStyle'   : 'black',
                'textMargin'      : 50,
                // 'drawText'        : true, 
				'textLineWidth'     : 3,
                'drawMode'        : 'segmentImage', 
                'numSegments'     : <?php echo count($image); ?>,         // Specify number of segments.
                'segments'        :                  
                [
					<?php 
					$no=1;		
					
					foreach ($image as $value) { ?>
					<?php
					$url = site_url('upload');
					$img = $url."/".$value->image;
					$numbers = array($value->id_order);					
					$even = array();
					$odd = array();
					foreach ($numbers as $number) { ?>
					<?php if ($number % 2 == 0) { ?>
					{'image' : '<?php echo $img; ?>', 'fillStyle' : '<?php if ($value->id_order === $last_value) { echo "#FF0000";}else{ echo "#f2bd18";} ?>' ,'text' : '<?php echo $value->value; ?>'},
					<?php } else { ?>
					{'image' : '<?php echo $img; ?>', 'fillStyle' : '<?php if ($value->id_order === $last_value) { echo "#FF0000";}else{ echo "#e5e5e5";} ?>', 'textFillStyle' : 'black', 'text' : '<?php echo $value->value; ?>'},
					<?php } ?>
				   	<?php } ?>
				   	<?php } ?>

                ],
                'animation' :    
                {
                    'type'     : 'spinToStop',
                    'duration' : 8, 
                    'spins'    : 2, 
                    'callbackSound' : playSound, 
                    'callbackFinished' : dialodWinner
                }
            });
        }

		function update(){
        	var voucher_val = $("input[name=voucher]").val();
					if (voucher_val.length <= 0){
					Swal.fire({
					icon: 'error',
					title: 'Oops...',
					text: 'Vourcher Code Is Empty!'
					})
        		// $("#error_message_voucher").html("Voucher Code Its Empty!");
        		return;
        	}
	        $.ajax({
	            url: 'main/confirm/'+voucher_val,
	            type: 'get',
	            contentType: 'application/json',
	        });
        }

        function startSpin(){
        	var voucher_val = $("input[name=voucher]").val();
					if (voucher_val.length <= 0){
					Swal.fire({
					icon: 'error',
					title: 'Oops...',
					text: 'Vourcher Code Is Empty!'
					})
        		// $("#error_message_voucher").html("Voucher Code Its Empty!");
        		return;
        	}

        	$("button[name=start]").attr('disabled','disabled');
        	$("button[name=history]").attr('disabled','disabled');
	        // $("#error_message_voucher").html('Checking voucher code...');
	        $.ajax({
	            // url: 'check.php?'+voucher_val,
	            url: 'main/check/'+voucher_val,
	            type: 'get',
	            contentType: 'application/json',
	            success: function( data, textStatus, jQxhr ){
				    var data = JSON.parse(data);
				    $("#error_message_voucher").html(data['message']);
				    if (data['code'] == 200) {
				    	data_winner = data;
				    	setTimeout(function(){
					    	theWheel.stopAnimation(false); 
			                theWheel.rotationAngle = 2; 
			                theWheel.draw();  

			                theWheel.animation.spins = 5;
			                let segmentNumber = data['id_order'];
 
							if (segmentNumber) {
								let stopAt = theWheel.getRandomForSegment(segmentNumber);
								theWheel.animation.stopAngle = stopAt;
								theWheel.startAnimation();
							}
					    }, 200);
						$(data).load('main/confirm/'+voucher_val);
				    }else{
						Swal.fire({
						icon: 'warning',
						title: 'Oops...',
						text: 'Voucher is Invalid or Expired!'
						})
						// $("#error_message_voucher").html('Voucher is Invalid or Expired!');
				    	$("button[name=start]").removeAttr('disabled');
				    	$("button[name=history]").removeAttr('disabled');
				    }
				},
				error: function( jqXhr, textStatus, errorThrown ){
				    console.log(errorThrown);
				}
	        });
        }

        function dialodWinner(indicatedSegment){
            if (data_winner != null) {
            	audio.src ="<?php echo base_url('public/main/audio/congrats.mp3');?>";
            	audio.loop = false;
            	audio.play();
            	
            	$("#item-image").attr("src", data_winner['item_image']);
	            $("#item-value").html(data_winner['item_value']);
	            $("#item-prize").html(data_winner['item_value']);
	            $("#item-name").html(data_winner['item_name']);
	            $("#voucher-username").html(data_winner['username']);
	            $("#voucher-code").html(data_winner['voucher']);
	            $("#item-description").html(data_winner['item_description']);


				claim_message = claim_message.replaceAll('{{username}}', data_winner['username']);
				claim_message = claim_message.replaceAll('{{voucher}}', data_winner['voucher']);
				claim_message = claim_message.replaceAll('{{item_name}}', data_winner['item_name']);
				claim_message = claim_message.replaceAll('{{item_value}}', data_winner['item_value']);

				var link_claim = "https://wa.me/#?text="+claim_message;
				$("#link_claim").attr('href', link_claim);

	            var confettiElement = document.getElementById('my-canvas');
				var confettiSettings = { target: confettiElement };
				var confetti = new ConfettiGenerator(confettiSettings);
				confetti.render();
			    
			    $("#my-canvas").css("display", "block");
	            $("#popup-container-win").fadeIn(1000);
            }else{
            	audio.src ="<?php echo base_url('public/main/audio/musik.mp3');?>";
            	audio.play();
            }
        }

        function getHistory(){
        	$("#error_message_voucher").html("Mohon Tunggu...");

        	$("button[name=history]").attr('disabled','disabled');
	        $.ajax({
	            url: 'main/history',
	            type: 'get',
	            contentType: 'application/json',
	            success: function( data, textStatus, jQxhr ){
				    var data = JSON.parse(data);
				    $("#error_message_voucher").html("");
				    $("#history-container").html("");

				    var str = '';
				    for (var i = 0; i < data.length; i++) {
				    	str += '<tr>'+
	                    			'<td style="width: 10%; padding: 5px; text-align: center;">'+data[i]['no']+'</td>'+
		                    		'<td style="width: 50%; padding: 5px;">'+data[i]['username']+'</td>'+
		                    		'<td style="width: 40%; padding: 5px; text-align: center;">'+data[i]['value']+'</td>'+
		                    	'</tr>';
				    }

				    $("#history-container").html(str);
				    $("#popup-container-history").fadeIn(1000);
				},
				error: function( jqXhr, textStatus, errorThrown ){
				    console.log(errorThrown);
				}
	        });
        }

        function playSound() {
            audio.pause();
            audio.currentTime = 0;

            audio.src ="<?php echo base_url('public/main/audio/spin.mp3');?>";
            audio.loop = false;
            audio.play();
        }

        function close_popup_winner() {
        	data_winner = null;
        	audio.src ="<?php echo base_url('public/main/audio/musik.mp3');?>";
        	audio.loop = true;
        	audio.play();

        	$("#error_message_voucher").html("");
        	$("input[name=voucher]").val("");
        	$("button[name=start]").removeAttr('disabled');
			$("button[name=history]").removeAttr('disabled');
		    $("#popup-container-win").fadeOut(500);
		    $("#my-canvas").css("display", "none");

		    theWheel.animation.spins = 2;
            theWheel.animation.stopAngle = 15;

            theWheel.startAnimation();
		}

		function close_popup_history() {
        	$("button[name=start]").removeAttr('disabled');
			$("button[name=history]").removeAttr('disabled');
		    $("#popup-container-history").fadeOut(500);
		}

		function close_popup_start() {
		    $("#popup-container-ads").fadeOut(500);

		    theWheel.animation.spins = 2;
            theWheel.animation.stopAngle = 15;

            theWheel.startAnimation();
		}

        var music = document.createElement("AUDIO")
        document.body.appendChild(music);

                	document.oncontextmenu = function (e) {e.preventDefault(); return false;}
            document.onkeydown = function (e) {
                if (event.keyCode == 123) {return false;}
                if (e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {return false;}
                if (e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {return false; }
                if (e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {return false; }
                if (e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {return false;}
            }
            </script>

			<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</body>
</html>