<?php

declare(strict_types=1);

$item = is_array($item ?? null) ? $item : [];
$options = is_array($item['options'] ?? null) ? $item['options'] : [];
$type = (string) ($item['item_type'] ?? 'single-choice');
?>
<fieldset class="myron-quiz__item" data-quiz-item="<?= myronEscape((string) ($item['id'] ?? '')) ?>">
  <legend class="myron-quiz__prompt"><?= myronEscape((string) ($item['prompt'] ?? '')) ?></legend>
  <?php if (in_array($type, ['single-choice', 'true-false', 'rating'], true)): ?>
    <?php foreach ($options as $option): ?>
      <label class="myron-quiz__option"><input type="radio" name="item[<?= myronEscape((string) ($item['id'] ?? '')) ?>]" value="<?= myronEscape((string) ($option['id'] ?? '')) ?>"> <span><?= myronEscape((string) ($option['label'] ?? '')) ?></span></label>
    <?php endforeach; ?>
  <?php elseif ($type === 'multi-choice'): ?>
    <?php foreach ($options as $option): ?>
      <label class="myron-quiz__option"><input type="checkbox" name="item[<?= myronEscape((string) ($item['id'] ?? '')) ?>][]" value="<?= myronEscape((string) ($option['id'] ?? '')) ?>"> <span><?= myronEscape((string) ($option['label'] ?? '')) ?></span></label>
    <?php endforeach; ?>
  <?php elseif ($type === 'email-contact'): ?>
    <input class="myron-quiz__input" type="email" name="item[<?= myronEscape((string) ($item['id'] ?? '')) ?>]" placeholder="you@example.com">
  <?php else: ?>
    <textarea class="myron-quiz__input" name="item[<?= myronEscape((string) ($item['id'] ?? '')) ?>]" rows="3"></textarea>
  <?php endif; ?>
</fieldset>
