<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<style>
  body{ font-family: dejavusans, Arial, sans-serif; font-size:10.5pt; color:#111827; }
  h1{ font-size:14pt; color:#00829B; margin:0 0 8px; }
  .muted{ color:#6b7280; font-size:9.5pt; }
  .section{ margin-top:10px; padding:8px; background:#f4fbfc; border-left:4px solid #00829B; }
  .kv{ margin:2px 0; }
  .kv strong{ display:inline-block; width:150px; }
  table{ width:100%; border-collapse:collapse; margin-top:8px; }
  th,td{ border:1px solid #d1d5db; padding:6px; vertical-align:top; }
  th{ background:#eaf7f8; color:#004f5c; }
</style>

<h1>INCEIF Staff External Engagement Form</h1>
<div class="muted">Generated from Perfex CRM</div>

<div class="section"><strong>Section A — Staff Information</strong></div>
<div class="kv"><strong>Name:</strong> <?php echo htmlspecialchars($decl['staff_name'] ?? '-'); ?></div>
<div class="kv"><strong>Staff ID:</strong> <?php echo htmlspecialchars($decl['staff_code'] ?: ($decl['staff_id'] ?? '-')); ?></div>
<div class="kv"><strong>Position:</strong> <?php echo htmlspecialchars($decl['position'] ?? '-'); ?></div>
<div class="kv"><strong>Department:</strong> <?php echo htmlspecialchars($decl['department'] ?? '-'); ?></div>
<div class="kv"><strong>Division:</strong> <?php echo htmlspecialchars($decl['division'] ?? '-'); ?></div>

<div class="section"><strong>Section B — Type of Submission</strong></div>
<div class="kv"><strong>Submission Type:</strong> <?php echo htmlspecialchars($decl['submission_type'] ?? '-'); ?></div>

<div class="section"><strong>Section C — Details of External Engagement</strong></div>
<table>
  <thead>
    <tr>
      <th style="width:32px">No</th>
      <th style="width:120px">Type</th>
      <th>Organisation</th>
      <th>Position Held</th>
      <th style="width:70px">Start</th>
      <th style="width:70px">End</th>
      <th style="width:80px">Frequency</th>
      <th style="width:70px">Payment</th>
    </tr>
  </thead>
  <tbody>
    <?php if (!empty($items)) { ?>
      <?php foreach ($items as $i => $it) { ?>
        <tr>
          <td><?php echo (int)($i+1); ?></td>
          <td><?php echo htmlspecialchars($it['engagement_type'] ?? ''); ?></td>
          <td><?php echo htmlspecialchars($it['organisation'] ?? ''); ?></td>
          <td><?php echo htmlspecialchars($it['position_held'] ?? ''); ?></td>
          <td><?php echo htmlspecialchars($it['start_date'] ?? ''); ?></td>
          <td><?php echo htmlspecialchars($it['end_date'] ?? ''); ?></td>
          <td><?php echo htmlspecialchars($it['frequency'] ?? ''); ?></td>
          <td><?php echo htmlspecialchars(number_format((float)($it['payment'] ?? 0), 2)); ?></td>
        </tr>
      <?php } ?>
    <?php } else { ?>
      <tr><td colspan="8">No engagement rows recorded.</td></tr>
    <?php } ?>
  </tbody>
</table>

<div class="section"><strong>Section D — Conflict of Interest</strong></div>
<div class="kv"><strong>Competitor:</strong> <?php echo htmlspecialchars($decl['conflict_competing'] ?? '-'); ?></div>
<div class="kv"><strong>Family:</strong> <?php echo htmlspecialchars($decl['conflict_family'] ?? '-'); ?></div>
<div class="kv"><strong>IP Conflict:</strong> <?php echo htmlspecialchars($decl['conflict_ip'] ?? '-'); ?></div>
<div class="kv"><strong>Details:</strong> <?php echo nl2br(htmlspecialchars($decl['conflict_details'] ?? '-')); ?></div>

<div class="section"><strong>Section E — Intellectual Property</strong></div>
<div class="kv"><strong>Using IP:</strong> <?php echo htmlspecialchars($decl['ip_use'] ?? '-'); ?></div>
<div class="kv"><strong>Details:</strong> <?php echo nl2br(htmlspecialchars($decl['ip_details'] ?? '-')); ?></div>

<div class="section"><strong>Section F — Time Commitment</strong></div>
<div class="kv"><strong>Exceeds Limit:</strong> <?php echo htmlspecialchars($decl['day_limit'] ?? '-'); ?></div>
<div class="kv"><strong>Interfere:</strong> <?php echo htmlspecialchars($decl['interfere'] ?? '-'); ?></div>
<div class="kv"><strong>Mitigation:</strong> <?php echo nl2br(htmlspecialchars($decl['mitigation'] ?? '-')); ?></div>

<div class="section"><strong>Section G — Declaration</strong></div>
<div class="kv"><strong>Declaration:</strong> <?php echo htmlspecialchars($decl['declaration'] ?? '-'); ?></div>
<div class="kv"><strong>Signature:</strong> <?php echo htmlspecialchars($decl['digital_signature'] ?? '-'); ?></div>
<div class="kv"><strong>Date:</strong> <?php echo !empty($decl['submission_date']) ? htmlspecialchars($decl['submission_date']) : '-'; ?></div>
