<?php $this->load->view('site/layout'); ?>
<?php $this->load->view('site/navbar'); ?>

<style type="text/css">
    .main-table  td, .main-table  th{ vertical-align: middle !important;  }
</style>
<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">
    <!-- begin:: Content Head -->
    <div class="kt-subheader  kt-grid__item" id="kt_subheader">
        <div class="kt-container  kt-container--fluid ">
            <div class="kt-subheader__main">
                <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                <span class="kt-subheader__desc"><?php echo $this->lang->line('points'); ?></span>
            </div>

        </div>
    </div>
    <div class="kt-portlet kt-portlet--mobile">
        <div class="kt-portlet__head kt-portlet__head--lg">
            <div class="kt-portlet__head-label">
                <span class="kt-portlet__head-icon">
                    <i class="kt-font-brand flaticon2-line-chart"></i>
                </span>
                <h3 class="kt-portlet__head-title">
                    <?php echo $title ?>
                </h3>
            </div>
            <div class="kt-portlet__head-toolbar">
                <div class="kt-portlet__head-wrapper">
                    <div class="kt-portlet__head-actions">
                        <a class="btn btn-success pull-right" href="<?php echo base_url('points/category/create/' . $category_type); ?>"><span><?php echo $this->lang->line('add'); ?></span></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="kt-portlet__body">
            <div class="table-responsive">

                <?php if ($this->session->userdata('message')) { ?>
                    <div class="alert alert-success alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <?php echo $this->session->userdata('message'); ?>
                    </div>
                <?php } ?>

                <table class=" table table-striped table-bordered" id="datatable">
                    <thead>
                        <tr>
                            <th><?php echo $this->lang->line('sno'); ?></th>
                            <th><?php echo $this->lang->line('name'); ?></th>
                            <th><?php echo $this->lang->line('status'); ?></th>
                            <th><?php echo $this->lang->line('action'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if ($results) {
                            $s = 1;
                            foreach ($results as $result) {
                                ?>
                                <tr>
                                    <td><?php echo $s++; ?></td>
                                    <td><?php echo $result->category_name; ?> <?php if ($category_type == "discount") { ?><br> 
                                            <?php echo $this->lang->line('points'); ?> :  <?php echo $result->points; ?> <br> <?php echo $this->lang->line('points_discount_for'); ?> :   <?php echo $result->points_for == 1 ? $this->lang->line('balance') : $this->lang->line('balance_and_points'); ?>
                                        <?php } ?></td>
                                    <td>
                                        <span class="switch switch-outline switch-success">
                                            <label>
                                                <input type="checkbox" <?= $result->category_status == 1 ? 'checked="checked"' : '' ?> data-status="<?php echo $result->category_status; ?>" data-id="<?php echo $result->id; ?>"  class="approve_switch switch-input"  />
                                                <span></span>
                                            </label>
                                        </span>
                                    </td>
                                    <td><a href="<?php echo base_url(); ?>points/category/edit/<?php echo $result->id; ?>" class="btn btn-success m-btn m-btn--icon btn-sm m-btn--icon-only"><i class="fa fa-edit"></i></a>
                                        <a href="<?php echo base_url(); ?>points/category/delete/<?php echo $result->id; ?>" class="btn btn-danger m-btn m-btn--icon btn-sm m-btn--icon-only" onclick="return  confirm('are you sure?');"><i class="fa fa-trash"></i></a>
                                    </td>
                                </tr>
                            <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<?php $this->load->view('site/footer_2'); ?>
<script type="text/javascript">
    var b_url = "<?php echo base_url(); ?>";
    $(document).ready(function() {
    $('#datatable').DataTable(<?php if ($this->session->userdata('language') == "arabic") { ?>{
        "language": {
        "url": "<?php echo admin_url('js/Arabic.json'); ?>"
        }
        } <?php } ?>);
    });
    $('.switch-input').change(function() {
    if ($(this).is(":checked")) {
    var status = 1;
    }
    else{
    var status = 0;
    }

    var id = $(this).attr("data-id")
            //alert(id);
            $.ajax({
            url: b_url + "points/category/status/" + id + "/" + status,
                    success: function(e) {
                    alert('Success!!');
                    }

            });
    });

</script>

