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

<?php
$loggedStaffId = (int) get_staff_user_id();

$canViewAll = staff_can('view', 'gift_policy_statement');
$canViewOwn = staff_can('view_own', 'gift_policy_statement') && ((int)$decl['staff_id'] === $loggedStaffId);

$canEdit   = staff_can('edit', 'gift_policy_statement')   && ($canViewAll || $canViewOwn);
$canDelete = staff_can('delete', 'gift_policy_statement') && ($canViewAll || $canViewOwn);
?>

<div id="wrapper">
  <div class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="panel_s">
          <div class="panel-body">

            <div class="clearfix">
              <h4 class="pull-left">
                <?php echo _l('gift_policy_statement_view'); ?> #<?php echo (int)$decl['id']; ?>
              </h4>

              <div class="pull-right">
                <?php if ($canEdit) { ?>
                  <a class="btn btn-info" href="<?php echo admin_url('gift_policy_statement/edit/'.$decl['id']); ?>">
                    <i class="fa fa-pencil"></i> <?php echo _l('edit'); ?>
                  </a>
                <?php } ?>

                <?php if ($canDelete) { ?>
                  <a class="btn btn-danger _delete" href="<?php echo admin_url('gift_policy_statement/delete/'.$decl['id']); ?>">
                    <i class="fa fa-trash"></i> <?php echo _l('delete'); ?>
                  </a>
                <?php } ?>
              </div>
            </div>

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

            <div class="row">
              <div class="col-md-6">
                <p><strong>Name:</strong> <?php echo htmlspecialchars($decl['staff_name'] ?? ''); ?></p>
                <p><strong>Staff ID:</strong> <?php echo htmlspecialchars($decl['staff_code'] ?? $decl['staff_id']); ?></p>
                <p><strong>Position:</strong> <?php echo htmlspecialchars($decl['position'] ?? ''); ?></p>
                <p><strong>Department:</strong> <?php echo htmlspecialchars($decl['department'] ?? ''); ?></p>
              </div>
              <div class="col-md-6">
                <p><strong>Signature:</strong> <?php echo htmlspecialchars($decl['signature'] ?? ''); ?></p>
                <p><strong>Date:</strong> <?php echo htmlspecialchars($decl['signed_date'] ?? ''); ?></p>
                <p><strong>Created:</strong> <?php echo !empty($decl['created_at']) ? _dt($decl['created_at']) : '-'; ?></p>
                <p><strong>Updated:</strong> <?php echo !empty($decl['updated_at']) ? _dt($decl['updated_at']) : '-'; ?></p>
              </div>
            </div>

            <hr>

              <style>
  .gps-section-title{
    display:flex;align-items:center;gap:10px;
    padding:10px 12px;margin:0 0 10px;
    background:#f7fbfc;border:1px solid #e5eef0;border-left:4px solid #00829B;
    border-radius:6px;
  }
  .gps-section-title h5{margin:0;font-weight:700}
  .gps-section-sub{margin:0;color:#6b7280;font-size:13px}

  .gps-card{
    border:1px solid #e5e7eb;border-radius:8px;background:#fff;
    padding:14px 14px;margin-bottom:12px;
  }
  .gps-card h6{
    margin:0 0 8px;font-weight:700;font-size:14px;color:#0f4a56;
    display:flex;align-items:center;gap:8px;
  }
  .gps-badge{
    font-size:12px;padding:2px 8px;border-radius:999px;
    background:#e8f5f7;color:#004f5c;border:1px solid #cfeaec;
  }
  .gps-list{margin:0;padding-left:18px;color:#6b7280}
  .gps-list li{margin:6px 0}
  .gps-note{
    background:#f8fafc;border:1px dashed #d8e2ea;color:#475569;
    padding:10px 12px;border-radius:8px;margin-bottom:12px;
  }
</style>
<!-- Part B -->
<div class="gps-section-title">
  <h5><strong>Part B – Policy and Declaration</strong></h5>
  <p class="gps-section-sub">Summary of key requirements under INCEIF’s policy.</p>
</div>

<div class="gps-note">
  In accordance with INCEIF’s Conflict of Interest Policy, all employees must exercise integrity and sound judgment
  when offered gifts, entertainment, or other benefits by external parties.
</div>

<div class="gps-card">
  <h6><span class="gps-badge">1</span> Prohibited Gifts and Benefits</h6>
  <ul class="gps-list">
    <li>Does or seeks to do business with INCEIF;</li>
    <li>Competes with INCEIF;</li>
    <li>Has received, is receiving, or is seeking any contract or transaction with INCEIF;</li>
    <li>Is a connected party whose relationship could reasonably influence decision-making.</li>
  </ul>
</div>

<div class="gps-card">
  <h6><span class="gps-badge">2</span> Permissible Gifts</h6>
  <ul class="gps-list">
    <li>Modest in value (≤ RM200), reasonable, and infrequent;</li>
    <li>Not lavish or excessive;</li>
    <li>Properly disclosed as required under policy.</li>
  </ul>
</div>

<div class="gps-card">
  <h6><span class="gps-badge">3</span> Disclosure and Approval Requirements</h6>
  <ul class="gps-list">
    <li>Any gift exceeding RM200, or any gift that may create a conflict of interest, must be declared to HC.</li>
    <li>Prior written approval from the PCEO is required for:
      <ul class="gps-list" style="margin-top:6px;">
        <li>Any gift exceeding RM200;</li>
        <li>Lavish, excessive, or non-business entertainment.</li>
      </ul>
    </li>
    <li>Annual declarations are required every January, with prompt updates for new gifts.</li>
  </ul>
</div>

<div class="gps-card">
  <h6><span class="gps-badge">4</span> Examples</h6>
  <ul class="gps-list">
    <li><strong>Acceptable:</strong> Modest business lunch (&lt; RM200).</li>
    <li><strong>Requires PCEO approval:</strong> Luxury event tickets, gifts &gt; RM200, recurring hospitality.</li>
  </ul>
</div>

<hr>

<!-- Part C -->
<div class="gps-section-title">
  <h5><strong>Part C – Employee Confirmation</strong></h5>
  <p class="gps-section-sub">Please read and confirm the statements below.</p>
</div>

<div class="gps-card">
  <ol class="gps-list">
    <li>I have read and understood INCEIF’s Gift Policy and the Conflict of Interest Policy.</li>
    <li>I agree to comply with all disclosure and approval requirements.</li>
    <li>I confirm I have not accepted any prohibited gifts or favours.</li>
    <li>I will submit a Gift Disclosure Form if required and provide annual declarations.</li>
    <li>I understand that non-compliance may result in disciplinary action.</li>
  </ol>
</div>
            <?php if (!empty($activity_logs)) { ?>
              <h5 class="mtop20"><strong>Activity Log</strong></h5>
              <div class="table-responsive">
                <table class="table table-striped">
                  <thead>
                    <tr>
                      <th style="width:170px">Date</th>
                      <th style="width:220px">Staff</th>
                      <th>Action</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php foreach ($activity_logs as $l) {
                      $staffName = trim(($l['firstname'] ?? '') . ' ' . ($l['lastname'] ?? ''));
                    ?>
                      <tr>
                        <td><?php echo _dt($l['date']); ?></td>
                        <td><?php echo htmlspecialchars($staffName ?: ('ID ' . ($l['staffid'] ?? '-'))); ?></td>
                        <td><?php echo htmlspecialchars($l['description'] ?? ''); ?></td>
                      </tr>
                    <?php } ?>
                  </tbody>
                </table>
              </div>
            <?php } ?>

            <div class="mtop20">
              <a class="btn btn-default" href="<?php echo admin_url('gift_policy_statement'); ?>">
                <i class="fa fa-arrow-left"></i> <?php echo _l('back'); ?>
              </a>
            </div>

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

<?php init_tail(); ?>
