

<?php $__env->startSection('content'); ?>
    <div class="card-header"><span><a href="<?php echo e(route('dashboard')); ?>"><?php echo e(__('Dashboard')); ?></a></span> >
        <span><?php echo e(__('Prize')); ?></span>
    </div>
    <div class="card-body dashboard-card">
        <div class="row">
            <div class="col-md-8 col-12" style="border-right: 2px solid">
                <div class="row">
                    <div class="col-md-2">
                        <button type="button" class="btn" id="addPrizeBtn">Add</button>
                    </div>
                   
                </div>

                <!------- Prizes table----->
                <div class="row mt-4">
                    <h5 class="ml-4"> Prizes List</h5>
                    <div class="col-12 table-responsive">
                        <table class="table table-bordered datatable">
                            <thead>
                                <tr>
                                    <th class="text-center" width="3%">Sl.No</th>
                                    <th width="35%">Category</th>
                                    <th width="20%">Prize</th>
                                    <th width="20%">Url Slug</th>
                                    <th width="40%">Count</th>
                                    <th width="2%">Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $prizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $prize): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($loop->index + 1); ?></td>
                                        <td><?php echo e($prize->category->name); ?></td>
                                        <td><?php echo e($prize->prize); ?></td>
                                        <td><?php echo e($prize->url_slug); ?></td>
                                        <td><?php echo e($prize->total_count); ?></td>
                                        <td>
                                            <p>
                                                <span id="view_prize" onclick="viewPrizeDetails(<?php echo e($prize->id); ?>)">
                                                    <i class="fa fa-eye" aria-hidden="true"></i>
                                                </span>
                                                <?php if($prize->status == 1): ?>
                                                    <span id="view_prize" onclick="deletePrizeDetails(<?php echo e($prize->id); ?>)"
                                                        style="color: rgb(182, 8, 8);">
                                                        <i class="fa fa-trash" aria-hidden="true"></i>
                                                    </span>
                                                <?php endif; ?>
                                            </p>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <button type="button" onclick="resetData()"
                        style="color:#f8f9fa;background-color:#f8f9fa!important;border:1px #f8f9fa"> Reset</button>
                    
                </div>
            </div>
            <div class="col-md-4 col-12">
                <!------- Prize category table----->
                <div class="row">
                    <div class="col-12">
                        <div class="row">
                            <div class="col-8">
                                <h5> Category List</h5>
                            </div>
                            <div class="col-4">
                                <button type="button" class="btn" id="addPrizeCategoryBtn">Add</button>
                            </div>
                        </div>

                    </div>
                    <div class="col-12 table-responsive mt-4 scroll-n-height">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    
                                    <th width="5%">Sl.No</th>
                                    <th width="50%">Name</th>
                                    <th width="5%">Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($loop->index + 1); ?></td>
                                        <td><?php echo e($category->name); ?></td>

                                        <td>
                                            <p>
                                                <span id="view_category"
                                                    onclick="viewPrizeCategoryDetails(<?php echo e($category->id); ?>)">
                                                    <i class="fa fa-eye" aria-hidden="true"></i>
                                                </span>
                                                <?php if($category->status == 1): ?>
                                                    <span id="view_category"
                                                        onclick="deletePrizeCategoryDetails(<?php echo e($category->id); ?>)"
                                                        style="color: rgb(182, 8, 8);">
                                                        <i class="fa fa-trash" aria-hidden="true"></i>
                                                    </span>
                                                <?php endif; ?>
                                            </p>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>

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

    <!---- Winner View modal --->
    <div class="modal" id="viewWinnerModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Winner Details</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">
                    <form action="#" name="winnerForm" id="winnerForm">
                        <h5 class="mb-3 text-center" id="winner_prize"> PRIZE </h5>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Prize</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="winner_prize_value" id="winner_prize_value" class="form-control"
                                    value="" readonly />
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Unique ID</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="winner_unique_id" id="winner_unique_id" class="form-control"
                                    value="" readonly />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Name</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="winner_name" id="winner_name" class="form-control"
                                    value="" readonly />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Phone</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="winner_phone" id="winner_phone" class="form-control"
                                    value="" readonly />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Q-ID</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="winner_q_id" id="winner_q_id" class="form-control"
                                    value="" readonly />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>IMEI number</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="winner_imei_number" id="winner_imei_number"
                                    class="form-control" value="" readonly />
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>


    <!---- Prize Category View modal --->
    <div class="modal" id="viewPrizeCategoryModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Category Details</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">
                    <form action="#" id="categoryForm" class="form-horizontal" method="post">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="category_id" id="category_id" value="">
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Name</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="name" id="name" class="form-control"
                                    value="" required />
                            </div>
                        </div>
                       
                    </form>
                    <div class="alert alert-danger mt-2 error_save_prize" style="display: none;"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" id="savePrizeCategoryBtn">Save</button>

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

    <!---- Prize View modal --->
    <div class="modal" id="viewPrizeModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Prize Details</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">
                    <form action="#" id="prizeForm" class="form-horizontal" method="post">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="prize_id" id="prize_id" value="">
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Category</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <select name="prize_category_id" id="prize_category_id" class="form-control" required >
                                    <option>Select</option>
                                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Prize</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="prize" id="prize" class="form-control"
                                    value="" required />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Url</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="text" name="url_slug" id="url_slug" class="form-control"
                                    value="" required />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Count</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="number" name="total_count" id="total_count" class="form-control"
                                    value="" required />
                            </div>
                        </div>
                    </form>
                    <div class="alert alert-danger mt-2 error_save_prize" style="display: none;"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" id="savePrizeBtn">Save</button>

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

    <!---- Settings modal --->
    <div class="modal" id="viewSettingsModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Settings</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">
                    <form action="#" id="settingsForm" class="form-horizontal" method="post">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="settings_id" id="settings_id" value="">
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Spin time</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <input type="number" name="spin_time" id="spin_time" class="form-control"
                                    value="40" max="100" required />
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 col-12">
                                <label>Speed</label>
                            </div>
                            <div class="col-md-9 col-12">
                                <!--<input type="number" name="speed" id="speed" class="form-control" value="5" max="10" required/>-->
                                <div class="input-group">
                                    <input type="number" name="speed" id="speed" class="form-control"
                                        value="5" max="10" required />
                                    <div class="input-group-append">
                                        <span class="input-group-text"> s </span>
                                    </div>
                                </div>
                                <span>Faster when value is less</span>
                            </div>
                        </div>
                    </form>
                    <div class="alert alert-danger mt-2 error_save_settings" style="display: none;"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" id="saveSettingsBtn">Save</button>

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

<?php $__env->startSection('scripts'); ?>
    <script type="text/javascript">
        var s_message = "<?php echo e(session('success')); ?>";
        var e_message = "<?php echo e(session('error')); ?>";

        $(function() {

            var from_date = $('#from_date').val();
            var to_date = $('#to_date').val();

            if (s_message)
                Swal.fire({
                    text: s_message,
                    type: 'success',
                    confirmButtonText: 'Ok',
                    confirmButtonColor: "rgb(174,46,184)"

                });
            if (e_message)
                Swal.fire({
                    text: e_message,
                    type: 'error',
                    confirmButtonText: 'Ok',
                    confirmButtonColor: "rgb(174,46,184)"

                });

            var table = $('.datatable').DataTable();
        });

        // -------------------------Prize---------------------------------
        $("#addPrizeBtn").on("click", function() {
            $('#prizeForm').trigger("reset");
            $(".error_save_prize").hide();
            $("#prize_id").val("");
            $("#savePrizeBtn").show();
            $('#viewPrizeModal').modal('show');
        });

        $("#savePrizeBtn").on("click", function(e) {
            e.preventDefault();
            var url = "";
            if ($("#prize_id").val() == "") {
                url = "<?php echo e(route('prize.store')); ?>";
            } else {
                url = "<?php echo e(route('prize.update')); ?>";
            }
            $.ajax({
                type: "POST",
                url: url,
                data: $('#prizeForm').serialize(),
                success: function(data) {
                    console.log(data);
                    if (data.status == "success") {
                        $('#prizeForm').trigger("reset");
                        $(".error_save_prize").text("");
                        $(".error_save_prize").hide();
                        $('#viewPrizeModal').modal('hide');
                        Swal.fire({
                            text: data.message,
                            type: 'success',
                            confirmButtonText: 'Ok',
                            confirmButtonColor: "#0F61A5"

                        }).then((result) => {
                            // Reload the Page
                            location.reload();
                        });
                    } else {
                        $(".error_save_prize").text(data.message);
                        $(".error_save_prize").show();
                    }
                },
                error: function(data) {
                    // console.log('Error:', data);
                }
            });
        });

        function viewPrizeDetails(prize_id) {
            $.ajax({
                type: "POST",
                url: "<?php echo e(route('prize.show')); ?>",
                data: {
                    prize_id: prize_id,
                },
                success: function(data) {
                    console.log(data);
                    if (data.status == "success") {
                        $('#prizeForm').trigger("reset");
                        $(".error_save_prize").text("");
                        $(".error_save_prize").hide();
                        $("#prize_id").val(data.data.id);
                        $("#prize").val(data.data.prize);
                        $("#prize_category_id").val(data.data.prize_category_id);
                        $("#total_count").val(data.data.total_count);
                        $("#url_slug").val(data.data.url_slug);
                        if (data.data.status == 1) {
                            $("#savePrizeBtn").show();
                        } else {
                            $("#savePrizeBtn").hide();
                        }
                        $('#viewPrizeModal').modal('show');

                    }
                },
                error: function(data) {
                    // console.log('Error:', data);
                }
            });
        }

        function deletePrizeDetails(prize_id) {
            Swal.fire({
                title: "Are you sure?",
                text: "You will not be able to recover this!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#0F61A5",
                confirmButtonText: "Yes, delete it!",
            }).then((result) => {

                if (result.isConfirmed) {
                    $.ajax({
                        url: "<?php echo e(route('prize.delete')); ?>",
                        type: "POST",
                        data: {
                            prize_id: prize_id,
                        },
                        success: function(data) {
                            if (data.status == "success") {
                                Swal.fire({
                                    text: data.message,
                                    type: 'success',
                                    confirmButtonText: 'Ok',
                                    confirmButtonColor: "#0F61A5"

                                }).then((result) => {
                                    // Reload the Page
                                    location.reload();
                                });
                            }
                        },
                        error: function(xhr, ajaxOptions, thrownError) {}
                    });
                }
            });
        }

        // -------------------------Prize Category---------------------------------
        $("#addPrizeCategoryBtn").on("click", function() {
            $('#prizeCategoryForm').trigger("reset");
            $(".error_save_prize").hide();
            $("#prize_id").val("");
            $("#savePrizeCategoryBtn").show();
            $('#viewPrizeCategoryModal').modal('show');
        });

        $("#savePrizeCategoryBtn").on("click", function(e) {
            e.preventDefault();
            var url = "";
            if ($("#category_id").val() == "") {
                url = "<?php echo e(route('prize-category.store')); ?>";
            } else {
                url = "<?php echo e(route('prize-category.update')); ?>";
            }
            $.ajax({
                type: "POST",
                url: url,
                data: $('#categoryForm').serialize(),
                success: function(data) {
                    console.log(data);
                    if (data.status == "success") {
                        $('#categoryForm').trigger("reset");
                        $(".error_save_prize").text("");
                        $(".error_save_prize").hide();
                        $('#viewPrizeModal').modal('hide');
                        Swal.fire({
                            text: data.message,
                            type: 'success',
                            confirmButtonText: 'Ok',
                            confirmButtonColor: "#0F61A5"

                        }).then((result) => {
                            // Reload the Page
                            location.reload();
                        });
                    } else {
                        $(".error_save_prize").text(data.message);
                        $(".error_save_prize").show();
                    }
                },
                error: function(data) {
                    // console.log('Error:', data);
                }
            });
        });

        function viewPrizeCategoryDetails(category_id) {
            $.ajax({
                type: "POST",
                url: "<?php echo e(route('prize-category.show')); ?>",
                data: {
                    category_id: category_id,
                },
                success: function(data) {
                    console.log(data);
                    if (data.status == "success") {
                        $('#categoryForm').trigger("reset");
                        $(".error_save_prize").text("");
                        $(".error_save_prize").hide();
                        $("#category_id").val(data.data.id);
                        $("#name").val(data.data.name);
                        if (data.data.status == 1) {
                            $("#savePrizeCategoryBtn").show();
                        } else {
                            $("#savePrizeCategoryBtn").hide();
                        }
                        $('#viewPrizeCategoryModal').modal('show');

                    }
                },
                error: function(data) {
                    // console.log('Error:', data);
                }
            });
        }

        function deletePrizeCategoryDetails(category_id) {
            Swal.fire({
                title: "Are you sure?",
                text: "You will not be able to recover this!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#0F61A5",
                confirmButtonText: "Yes, delete it!",
            }).then((result) => {

                if (result.isConfirmed) {
                    $.ajax({
                        url: "<?php echo e(route('prize-category.delete')); ?>",
                        type: "POST",
                        data: {
                            category_id: category_id,
                        },
                        success: function(data) {
                            if (data.status == "success") {
                                Swal.fire({
                                    text: data.message,
                                    type: 'success',
                                    confirmButtonText: 'Ok',
                                    confirmButtonColor: "#0F61A5"

                                }).then((result) => {
                                    // Reload the Page
                                    location.reload();
                                });
                            }
                        },
                        error: function(xhr, ajaxOptions, thrownError) {}
                    });
                }
            });
        }

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

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