{% props current: String, workspaces: Vec<(String, String, String, String)>, group: String = "", manage_path: String = "", id: String = "workspace-switcher" %}
{#- workspaces: (name, role, href, attention), attention a word like "2 urgent" or empty; `current` is the current workspace's href. Hidden for people in one workspace. -#}
{%- let initials = |name: &str| name.split_whitespace().take(2).filter_map(|w| w.chars().next()).collect::<String>().to_uppercase() %}
{%- if workspaces.len() > 1 %}
{%- for (name, role, href, _) in workspaces.iter().filter(|w| w.2 == current) %}
<button class="ui-sidebar-button" type="button" data-size="lg" popovertarget="{{ id }}" aria-haspopup="menu"><span class="ui-avatar" data-shape="square"><span class="ui-avatar-fallback">{{ initials(name) }}</span></span><span class="ui-sidebar-meta"><strong>{{ name }}</strong><span>{{ role }}</span></span><svg class="ui-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg></button>
{%- end %}
<div class="ui-menu ui-switcher-menu" id="{{ id }}" popover role="menu" aria-label="Switch workspace">
{%- if !group.is_empty() %}
<div class="ui-menu-label">{{ group }}</div>
{%- end %}
{%- for (name, role, href, attention) in workspaces.iter() %}
<a class="ui-menu-item ui-switcher-item" role="menuitemradio" aria-checked="{{ *href == current }}" href="{{ href }}"><span class="ui-avatar"><span class="ui-avatar-fallback">{{ initials(name) }}</span></span><span class="ui-switcher-text"><strong>{{ name }}</strong><span>{{ role }}</span></span>{% if !attention.is_empty() %}<span class="ui-badge" data-variant="destructive">{{ attention }}</span>{% end %}{% if *href == current %}<svg class="ui-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>{% end %}</a>
{%- end %}
{%- if !manage_path.is_empty() %}
<div class="ui-menu-sep" role="separator"></div>
<a class="ui-menu-item" role="menuitem" href="{{ manage_path }}"><svg class="ui-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 21v-7"/><path d="M4 10V3"/><path d="M12 21v-9"/><path d="M12 8V3"/><path d="M20 21v-5"/><path d="M20 12V3"/><path d="M1 14h6"/><path d="M9 8h6"/><path d="M17 16h6"/></svg>Manage workspaces</a>
{%- end %}
</div>
{%- end %}