<?php
/*
 * *************************************************
 * Copyright (C) 2020 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div class="logo">
                <img src="<?= base_url('img/logohimalaya.png') ?>" class="img img-responsive" />
            </div>
            <span class="text-box">
                <span> SOFT LAUNCHING</span>
            </span>
            <span class="text bigger">DOORPRIZE : Tablet Android</span>
            <span class="separator half" style="padding:1vh"></span>
            <span class="randomizer">
            </span>
           <a class="btn btn-primary" style="display:none;" accesskey="l" onclick="doorprize.run()" href="javascript:void(0)">Get</a>
            <a class="btn btn-primary" style="display:none;" accesskey="k" onclick="doorprize.stop()" href="javascript:void(0)">Stop</a>
            <a class="btn btn-primary" style="display:none;" accesskey="p" onclick="doorprize.select()" href="javascript:void(0)">select</a>
            <a class="btn btn-primary" style="display:none;" accesskey="o" onclick="doorprize.updatelist()" href="javascript:void(0)">select</a>
            <ul style="display:none;">
                <li>IE, Chrome, Safari, Opera 15+: [ALT] + <em>accesskey</em></li>
                <li>Opera prior version 15: [SHIFT] [ESC] + <em>accesskey</em></li>
                <li>Firefox: [ALT] [SHIFT] + <em>accesskey</em></li>
            </ul>
            <span class="separator"></span>
            <span class="separator"></span>
        </div>
    </div>
</div>
<style>
    .randomizer .name-display {
        font-size: 4em;
        font-family: quicksandbold;
        text-align: center;
        text-transform: capitalize;
    }
    .dorr {
        font-size:0.5em;
        line-height:5vh;
       display:block; 
    }
</style>
<?php
$list_url = base_url('doorprize/get_list');
$draw_url = base_url('doorprize/draw');
Ci::set_script(<<<EOD
    var doorprize = function () {
        var the;
        var source = [];
        var display = $('.randomizer');
        var interval;
        var number;
        return{
            init: function () {
                the = this;
                the.updatelist();
            },
            updatelist:function(){
                $.ajax({
                    url: '{$list_url}', type: 'POST', dataType: 'JSON',
                    success: function (res) {
                        source = res.data;
                    }
                });
            },
            run: function () {
                if (source.length > 0) {
                    interval = setInterval(function () {
                        number = 0 + Math.floor(Math.random() * source.length);
                        var registerName = source[number].registerName+' '+source[number].registerNameLast+'<br><span class="dorr">'+source[number].registerCity+'</span>';
                        display.html($('<h1>', {'class': 'name-display'}).html(registerName));
                    }, 1);
                } else {
                    display.html($('<h1>', {'class': 'name-display'}).text('All participant has selected'));
                }
            },
            stop: function () {
                clearInterval(interval);
            },
            select:function(){
                display.empty();
                    display2.empty();
                    display3.empty();
                    display4.empty();
//                if(typeof source[number] !== 'undefined'){
//                    $.ajax({
//                        url: '{$draw_url}', type: 'POST', dataType: 'JSON',
//                        data: {
//                            registerId: source[number].registerId
//                        },
//                        success: function (res) {
//                            source = res.data;
//                            
//                        }
//                    });
//                }
            }
        };
    }();
    $(document).ready(function () {
        doorprize.init();
    });
EOD
        , 'embed');
