<script lang="ts">
  export let prompt: string;
  export let answers: string[] = [];
  export let correctIndex: number;
  export let onComplete: () => void;

  let selected = -1;

  const handleChoice = (index: number) => {
    if (index === correctIndex) {
      selected = index;

      setTimeout(onComplete, 500);
    } else {
      selected = index;
    }
  };
</script>

<div class="container">
  <p class="big-text">{prompt}</p>

  {#each answers as answer, i}
    <button
      onclick={() => handleChoice(i)}
      style={selected === i
        ? i === correctIndex
          ? 'background: var(--base0B)'
          : 'background: var(--base0E)'
        : ''}
    >
      {answer}
    </button>
  {/each}
</div>
