<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                    <?php 
                    //---------------------start check access action TAMBAH-------------------//
                    if(!empty($this->vartambah)){
                        echo "<a href='".base_url()."index.php/$link/add' class='btn btn-outline-info btn-sm'>Tambah Baru</a>";
                    }
                    //---------------------end check access action TAMBAH-------------------//
                    ?>
                </h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?php echo base_url();?>">Dashboard</a></li>
                    <li class="breadcrumb-item"><?php echo $parent;?></li>
                    <li class="breadcrumb-item active"><?php echo $title;?></li>
                </ol>
            </div>
        </div>
    </div>
</section>
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card card-default">
                    <div class="card-header">
                        <h3 class="card-title"><?php echo $title;?></h3>
                    </div>
                    <div class="card-body">
                        <?php if($this->session->flashdata('message')){?>
                        <div id="alert" class="alert alert-success alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <i class="icon fa fa-check"></i> Alert!
                            <?php echo $this->session->flashdata('message');?>
                        </div>
                        <?php }?>
                        <script> 
                            setTimeout(function() {
                                $('#alert').hide('fast');
                            }, 3000);
                        </script>
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Nama</th>
                                    <th>Link</th>
                                    <th>Icon</th>
                                    <th>Parent</th>
                                    <th>Level</th>
                                    <th>Action</th>
                                    <th>Sort</th>
                                    <th>Status</th>
                                    <th width="15%">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no=0;
                                    foreach ($mn as $dat) {
                                        $no++;
                                        //---------------------start check access action-------------------//
                                        $editbutton     = "";
                                        $viewbutton     = "";
                                        $deletebutton   = "";
                                        $disabledbutton = "";
                                        $aktifbutton    = "";
                                        
                                        if(!empty($this->varview)){
                                            $viewbutton="<a href='".base_url()."index.php/$link/view/".$dat->mm_id."' class='btn btn-info btn-xs'><i class='fa fa-eye'></i></a> ";
                                        }
                                        if(!empty($this->varedit)){
                                            $editbutton="<a href='".base_url()."index.php/$link/edit/".$dat->mm_id."' class='btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> ";
                                        }
                                        if(!empty($this->vardelete)){
                                            $deletebutton="<a onclick='del(".$dat->mm_id.")' class='btn btn-danger btn-xs'><i class='fa fa-times'></i></a> ";
                                        }
                                        
                                        $setstatus = "<span class='badge bg-teal'> Active</span>";
                                        if($dat->mm_status==0){
                                            $setstatus = "<span class='badge bg-red'> Disabled</span>";
                                            if(!empty($this->varedit)){
                                                $aktifbutton="<a onclick='aktif(".$dat->mm_id.")' class='btn btn-outline-success btn-xs'><i class='fa fa-check'></i></a> ";
                                            }
                                        }else{
                                            if(!empty($this->varedit)){
                                                $disabledbutton="<a onclick='disabled(".$dat->mm_id.")' class='btn btn-outline-danger btn-xs'><i class='fa fa-ban'></i></a> ";
                                            }
                                        }

                                        $parentmenu = "";
                                        $levelmenu  = "";
                                        $actionmenu = "";

                                        foreach($mn as $datmenu){if($datmenu->mm_id == $dat->mm_parent){$parentmenu = $datmenu->mm_name;}}

                                        if($dat->mm_level == 1){$levelmenu = "Parent";}else{$levelmenu = "Child - ".$dat->mm_level;}

                                        if($dat->mm_action == 1){$actionmenu = "True";}else{$actionmenu = "<code>False</code>";}
                                      
                                        echo("
                                            <tr>
                                                <input type='hidden' id='isi".$dat->mm_id."' value='".$dat->mm_name."'>
                                                <td>".$no."</td>
                                                <td>".$dat->mm_name."</td>
                                                <td>".$dat->mm_link."</td>
                                                <td>".$dat->mm_icon."</td>
                                                <td>".$parentmenu."</td>
                                                <td>".$levelmenu."</td>
                                                <td>".$actionmenu."</td>
                                                <td>".$dat->mm_sort."</td>
                                                <td style='text-align: center;'>".$setstatus."</td>
                                                <td>".$viewbutton.$editbutton.$disabledbutton.$aktifbutton.$deletebutton."</td>
                                            </tr>
                                        ");
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    var url="<?php echo base_url();?>";
    function disabled(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Disbaled Menu '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/st_menu/disabled/"+id;
        else
            return false;
    } 
    
    function aktif(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Aktifkan Menu '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/st_menu/active/"+id;
        else
            return false;
    }
    
    function del(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Menghapus Menu '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/st_menu/delete/"+id;
        else
            return false;
    }
</script>
