---
interface Props {
label: string;
/** Which filter the bars toggle and count: `tag` or `tool`. */
facet: 'tag' | 'tool';
/** `[value, count]`, longest first. */
items: [string, number][];
accent?: string;
}
const { label, facet, items, accent } = Astro.props;
/**
* One ranked-bar block of the sheet filter's stats: label, a track filled in
* proportion to the longest bar, count. Each row is a toggle for its value.
* Used twice by SheetFilter (techniques, tools); the `data-sf-*` attributes
* are read by scripts/sheet-filter.ts.
*/
const max = items[0]?.[1] ?? 1;
const toggle = (value: string) => ({ [`data-sf-${facet}`]: value });
---
<div>
<p class="sf__label">{label}</p>
<ul class="sf-bars" style={accent ? `--bar: var(--${accent});` : undefined}>
{items.map(([value, n]) => (
<li>
<button type="button" class="sf-barrow" aria-pressed="false" {...toggle(value)}>
<span class="sf-barrow__label">{value}</span>
<span class="sf-barrow__track" aria-hidden="true"><i data-sf-fill={`${facet}:${value}`} data-max={max} style={`width:${Math.round((n / max) * 100)}%`}></i></span>
<span class="sf-barrow__n" data-sf-n={`${facet}:${value}`}>{String(n).padStart(2, '0')}</span>
</button>
</li>
))}
</ul>
</div>