namespace Htmx.ApiDemo.Templates.Components;
///
/// shadcn-style Accordion. Items collapse/expand client-side via components.js.
/// Pass a list of (Title, Content) tuples; set openIndex to expand one by default (-1 = all closed).
///
public sealed class Accordion : AccordionBase
{
private const string ChevronSvg =
"""""";
private readonly byte[] _idData;
private readonly byte[] _itemsData;
public Accordion(string id, IEnumerable<(string Title, string Content)> items, int openIndex = -1)
{
_idData = id.ToUtf8Bytes();
var list = items.ToList();
var sb = new System.Text.StringBuilder();
for (int i = 0; i < list.Count; i++)
{
var (title, content) = list[i];
var expanded = i == openIndex;
var height = expanded ? "auto" : "0";
var opacity = expanded ? "1" : "0";
sb.Append($"""