<script setup lang="ts">
import type { RuleHeader } from "@/api/rulebooks";

defineProps<{ topicId: number; rules: RuleHeader[] }>();
const emit = defineEmits<{
  "open-rule": [id: number];
  "create-rule": [topicId: number];
}>();
</script>

<template>
  <section class="pane">
    <header><h2>Rules</h2></header>
    <ul>
      <li v-for="r in rules" :key="r.id" @click="emit('open-rule', r.id)">
        <div class="title">{{ r.title }}</div>
        <div class="statement">{{ r.statement }}</div>
      </li>
    </ul>
    <button class="new-rule" @click="emit('create-rule', topicId)">+ New rule</button>
  </section>
</template>

<style src="@/assets/rules-shared.css" />
<style scoped>
ul { list-style: none; padding: 0; margin: 1rem 0; }
li {
  padding: 0.75rem;
  cursor: pointer;
  border-radius: 6px;
  border-left: 2px solid var(--fs-accent);
  margin-bottom: 0.5rem;
  background: rgba(255, 255, 255, 0.02);
}
li:hover { background: var(--fs-surface-hover); }
.title { font-family: Fraunces, serif; font-style: italic; font-size: 1.05em; }
.statement { font-size: 0.9em; opacity: 0.8; margin-top: 0.25rem; }
.new-rule { cursor: pointer; }
</style>
