<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>

<div id="wrapper">
  <div class="content">
    <div class="row">


<div class="col-md-12 tw-mb-3">
                <h4 class="tw-my-0 tw-font-bold tw-text-xl">
          <?php echo _l('coidisclosure');?>
                </h4><br>
             <div class="_buttons tw-mb-2">
              <?php if (staff_can('create','coi_special_approval')) { ?>
                <a href="<?php echo admin_url('coi_special_approval/create'); ?>"
                   class="btn btn-primary">
                  <i class="fa fa-plus"></i> <?php echo _l('new_coidisclosure');?>
                </a>
              <?php } ?>

              <?php if (!empty($has_data)) { ?>
                <a class="btn btn-success mright10"
                   href="<?php echo admin_url('coi_special_approval/export_excel'); ?>">
                  <i class="fa fa-file-excel-o"></i> Export Excel
                </a>
              <?php } ?>


         </div>
                
            </div>




      <div class="col-md-12">
        <div class="panel_s">
          <div class="panel-body">

           

            <hr class="hr-panel-heading" />

            <div class="table-responsive">
              <table class="table table-coi_special_approval">
                <thead>
                  <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Department</th>
                    <th>Activity</th>
                    <th>Status</th>
                    <th>Date Created</th>
                  </tr>
                </thead>
                <tbody></tbody>
              </table>
            </div>

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

<!-- Quick Approve/Reject Modal -->
<div class="modal fade" id="csaDecisionModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <?php echo form_open('', ['id'=>'csaDecisionForm']); ?>
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="csaDecisionTitle">Decision</h4>
      </div>
      <div class="modal-body">
        <input type="hidden" name="decision" id="csaDecisionInput" value="approved">
        <div class="form-group">
          <label>Comment (optional)</label>
          <textarea name="approval_comment" class="form-control" rows="4" placeholder="Enter CEO/PCEO comment..."></textarea>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo _l('close'); ?></button>
        <button type="submit" class="btn btn-primary" id="csaDecisionSubmit">Submit</button>
      </div>
    </div>
    <?php echo form_close(); ?>
  </div>
</div>

<?php init_tail(); ?>
<script>
$(function(){
  initDataTable('.table-coi_special_approval', admin_url+'coi_special_approval', undefined, undefined, undefined, [0,'desc']);

  let currentId = null;

  $(document).on('click', '.csa-quick-approve', function(e){
    e.preventDefault();
    currentId = $(this).data('id');
    $('#csaDecisionTitle').text('Approve Request #' + currentId);
    $('#csaDecisionInput').val('approved');
    $('#csaDecisionSubmit').removeClass('btn-danger').addClass('btn-success').text('Approve');
    $('#csaDecisionModal').modal('show');
  });

  $(document).on('click', '.csa-quick-reject', function(e){
    e.preventDefault();
    currentId = $(this).data('id');
    $('#csaDecisionTitle').text('Reject Request #' + currentId);
    $('#csaDecisionInput').val('rejected');
    $('#csaDecisionSubmit').removeClass('btn-success').addClass('btn-danger').text('Reject');
    $('#csaDecisionModal').modal('show');
  });

  $('#csaDecisionForm').on('submit', function(e){
    e.preventDefault();
    if(!currentId) return;
    this.action = admin_url+'coi_special_approval/approve/' + currentId;
    this.submit();
  });
});
</script>
