<?php
// Example placeholder for now
$subtasks = afb_get_asana_subtasks($task_gid); // Optional helper you may define

$current_group = '';
?>

<section class="bg-white shadow rounded-lg p-6 max-w-screen-2xl mx-auto">
  <h2 class="text-lg font-semibold text-gray-700 mb-4">Subtask Checklist</h2>

  <?php if (!empty($subtasks)): ?>
    <div class="space-y-4">
      <?php foreach ($subtasks as $task): ?>
        <?php
          $name = $task['name'] ?? '';
          $is_header = str_ends_with($name, ':');
          $completed = $task['completed'] ?? false;
          $assignee = $task['assignee']['name'] ?? null;
          $due = $task['due_on'] ?? null;
        ?>

        <?php if ($is_header): ?>
          <h3 class="text-sm font-bold text-blue-700 mt-6 mb-2"><?= esc_html($name) ?></h3>
        <?php else: ?>
          <div class="flex justify-between items-center bg-gray-50 border rounded px-3 py-2">
            <div class="flex items-center gap-2">
              <input type="checkbox" disabled <?= $completed ? 'checked' : '' ?> />
              <span class="<?= $completed ? 'line-through text-gray-500' : '' ?>">
                <?= esc_html($name) ?>
              </span>
            </div>
            <div class="text-xs text-gray-500 text-right">
              <?php if ($assignee): ?><div>👤 <?= esc_html($assignee) ?></div><?php endif; ?>
              <?php if ($due): ?><div>📅 <?= esc_html(date('M j, Y', strtotime($due))) ?></div><?php endif; ?>
            </div>
          </div>
        <?php endif; ?>
      <?php endforeach; ?>
    </div>
  <?php else: ?>
    <p class="text-gray-500 text-sm">No subtasks found for this task.</p>
  <?php endif; ?>
</section>
