<script setup>
import { ref } from 'vue'
import { renderMarkdownInline } from '../markdown.js'

defineProps({ examples: { type: Array, default: () => [] } })
const open = ref(false)
</script>

<template>
  <div v-if="examples.length" class="worked">
    <button class="art-head" @click="open = !open">
      <span class="art-icon">📝</span> Examples
      <span class="art-count">{{ examples.length }}</span>
      <span class="art-toggle">{{ open ? '▾' : '▸' }}</span>
    </button>
    <div v-if="open" class="we-body">
      <div v-for="(b, i) in examples" :key="i" class="we-card">
        <div v-if="b.subblock" class="we-sub">{{ b.subblock }}</div>
        <div class="we-problem" v-html="renderMarkdownInline(b.problem)"></div>
        <ol class="we-steps">
          <li v-for="(s, j) in b.steps" :key="j" v-html="renderMarkdownInline(s)"></li>
        </ol>
        <div v-if="b.result" class="we-result">
          <span class="we-label">Result</span>
          <span v-html="renderMarkdownInline(b.result)"></span>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.worked { margin-top: 0.5rem; }
.art-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; cursor: pointer; padding: 0.35rem 0;
  font-size: 0.82rem; font-weight: 600; color: var(--text-muted);
}
.art-icon { font-size: 0.95rem; }
.art-count {
  background: var(--panel-soft); border: 1px solid var(--border);
  border-radius: 999px; padding: 0 0.45rem; font-size: 0.72rem;
}
.art-toggle { margin-left: auto; color: var(--text-faint); }

.we-body { margin-top: 0.4rem; display: flex; flex-direction: column; gap: 0.6rem; }
.we-card {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 0.7rem 0.9rem; background: var(--panel-soft);
  font-size: 0.92rem; line-height: 1.5;
}
.we-sub {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); font-weight: 700; margin-bottom: 0.3rem;
}
.we-problem { font-weight: 600; margin-bottom: 0.4rem; }
.we-steps { margin: 0 0 0.4rem 1.1rem; padding: 0; }
.we-steps li { margin: 0.2rem 0; }
.we-result {
  display: flex; gap: 6px; align-items: baseline;
  padding-top: 0.35rem; border-top: 1px dashed var(--border);
}
.we-label {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--success); font-weight: 700;
}
</style>
