<%- include('static/head.ejs', { bot,user,path})  %>
<div id="content" class="main-content">
    <div class="layout-px-spacing">

        <div class="page-header">
            <nav class="breadcrumb-one" aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="javascript:void(0);">Bot List</a></li>
                    <li class="breadcrumb-item active"><a href="javascript:void(0);">Codes</a></li>
                </ol>
            </nav>
        </div>
        
        <div class="row layout-top-spacing" id="cancel-row">
        
            <div class="col-xl-12 col-lg-12 col-sm-12  layout-spacing">
                <div class="widget-content widget-content-area br-6">
                    <table id="default-ordering" class="table table-hover" style="width:100%">
                        <thead>
                            <tr>
                                <th>Code Name</th>
                                <th>Code</th>
                                <th>Code Category</th>
                                <th class="text-center dt-no-sorting">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <% koddata.map(b => {%>
                            <tr>
                                <td><%= b.codeName %></td>
                                <td><%= b.code %></td>
                                <td><%= b.codeCategory %></td>
                            
                                <td class="text-center">
                                    <button onclick="window.location.href='/admin/editcode/<%= b.code %>'" class="btn btn-success btn-sm">Edit</button>
                                    <button onclick="deletequest('<%= b.code %>')" class="btn btn-danger btn-sm">Delete</button>
                                </td>
                            </tr>
                            <% }) %>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>Code Name</th>
                                <th>Code</th>
                                <th>Code Category</th>
                                <th class="invisible"></th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
        <script>
            function deletequest(uptimecode) {
Swal.fire({
  title: 'Are you sure?',
  text: "Are you sure you want to permanently delete the link you selected?",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonText: 'Yes, delete it!',
  cancelButtonText: 'No, cancel it!',
  reverseButtons: true
}).then((result) => {
  if (result.isConfirmed) {
    window.location.href = '/admin/deletecode/'+uptimecode;
  } else {
    Swal.fire(
      'Canceled..',
      'Link deletion from the uptime system has been canceled.',
      'error'
    )
  }
})
}
            var urlParams = new URLSearchParams(window.location.search);
            if(urlParams.has('success') && urlParams.get('success')){
            Swal.fire({
             icon: 'success',
             title: 'Succesfull...',
             closeOnConfirm: false,
             text: urlParams.get('message'),
             footer: 'Copyright 2021 &copy vCodes.xyz - All right reserved.'
            }).then((result) => {
          if (result.isConfirmed) {
            window.location.href = '/admin/codes';
          }
        })
            }
            if(urlParams.has('error') && urlParams.get('error')){
            Swal.fire({
             icon: 'error',
             title: 'Oops...',
             text: urlParams.get('message'),
             footer: 'Copyright 2021 &copy vCodes.xyz - All right reserved.'
            }).then((result) => {
          if (result.isConfirmed) {
            window.location.href = '/admin/codes';
          }    
        })
            }
           </script>
        </div></div>
        <%- include('static/foot.ejs', { bot,user,path}) %>