import { nothing, type TemplateResult } from "lit-html";
/**
* A `[condition, template]` tuple — the condition is evaluated and when
* `true` its template is returned by {@link renderSwitch}.
*/
export type SwitchEntry = readonly [
condition: boolean,
template: TemplateResult
];
/**
* One item in the array passed to {@link renderSwitch}.
*
* Either:
* - `[condition, template]` — a conditional branch.
* - `TemplateResult` — an unconditional fallback (typically placed last).
*/
export type SwitchCase = SwitchEntry | TemplateResult;
/**
* `renderSwitch` — return the template for the first truthy branch.
*
* Iterates `cases` in order:
* - **`[condition, template]`** — if `condition` is truthy, `template` is returned.
* - **`TemplateResult`** — returned unconditionally (acts as a default / fallback).
*
* If no branch matches and there is no fallback, `nothing` is returned so the
* call site produces no DOM output.
*
* TypeScript narrows each element to either `SwitchEntry` (a 2-tuple) or
* `TemplateResult` — both can be inferred without explicit type annotations at
* the call site.
*
* @example
* ```ts
* // Three tabs + a fallback shown when no tab is active
* html`${renderSwitch([
* [tab === "home", html`
Select a tab to get started.
`, // ← default * ])}` * * // Without a default — returns nothing when no condition is met * html`${renderSwitch([ * [isAdmin, html`