<%#
  Dark banner at the top of the kit pages.
  Vars: kit (entry from config/kits.js with a `hero`), crumbs ([{ label, href? }]),
        detail (boolean: true on the gated pages — the board image is then not a link to the kit page),
        compact (optional boolean: only breadcrumb, eyebrow, title and the board image — used on project pages)
        heading (optional { label, title }: shown below the kit title — the project name on project pages)
        highlight (optional { board, blocks, callouts }: board = the kit's BOARD geometry from config/kit-projects.js,
                   blocks = names of the blocks to highlight; the rest of the board is dimmed.
                   callouts (optional) = a label for each highlighted block, laid out by routes/utils/kitCallouts.js:
                   on wide screens the labels stand beside the board with a leader line to their block;
                   on narrower screens each block gets a number and the labels are listed with those numbers.)
  Optional (taken from the page's own locals): account ({ name }) — the logged-in visitor; shows the Log out button.
%>
<% const callouts = (locals.highlight && highlight.blocks.length && highlight.callouts) || null; %>
<section class="kit-banner<%= locals.compact ? ' kit-banner--compact' : '' %>">
    <div class="container">
        <div class="kit-banner__top">
            <ul class="kit-banner__crumbs list-unstyled">
                <% crumbs.forEach(function (crumb, i) { %>
                <% if (i) { %><li>/</li><% } %>
                <li><% if (crumb.href) { %><a href="<%= crumb.href %>"><%= crumb.label %></a><% } else { %><%= crumb.label %><% } %></li>
                <% }); %>
            </ul>
            <% if (locals.account) { %>
            <form class="kit-banner__account" method="post" action="/api/kit/logout">
                <span>Hi, <%= (account.name || '').split(' ')[0] || 'there' %></span>
                <button type="submit">Log out</button>
            </form>
            <% } %>
        </div>
        <div class="kit-banner__inner<%= callouts ? ' kit-banner__inner--callouts' : '' %>">
            <div class="kit-banner__text">
                <span class="kit-banner__eyebrow"><%= kit.hero.eyebrow %></span>
                <h1><%= kit.hero.title %><span><%= kit.hero.titleSub %></span></h1>
                <% if (locals.heading) { %>
                <h2 class="kit-banner__heading"><span><%= heading.label %></span><%= heading.title %></h2>
                <% } %>
                <% if (!locals.compact) { %>
                <p class="kit-banner__lead"><%= kit.hero.lead %></p>
                <p class="kit-banner__quote"><% kit.hero.quote.forEach(function (line, i) { %><% if (i) { %><br><% } %><%= line %><% }); %></p>
                <div class="kit-banner__chips">
                    <% kit.hero.chips.forEach(function (chip) { %>
                    <div class="kit-banner__chip"><b><%= chip.value %></b><span><%= chip.label %></span></div>
                    <% }); %>
                </div>
                <% } %>
            </div>
            <% if (detail && callouts) { %>
            <div class="kit-banner__board kit-banner__board--callouts" style="--kit-pad-top: <%= callouts.pad.top.toFixed(3) %>; --kit-pad-right: <%= callouts.pad.right.toFixed(3) %>; --kit-pad-bottom: <%= callouts.pad.bottom.toFixed(3) %>; --kit-pad-left: <%= callouts.pad.left.toFixed(3) %>;">
            <% } else if (detail) { %>
            <div class="kit-banner__board">
            <% } else { %>
            <a class="kit-banner__board js-kit-open" href="/kit/<%= kit.slug %>" data-kit="<%= kit.slug %>" data-kit-name="<%= kit.name %>" aria-label="<%= kit.name %>">
            <% } %>
                <% if (locals.highlight && highlight.blocks.length) { %>
                <% const hb = highlight.board; const corner = Math.round(hb.width / 50); %>
                <svg class="kit-banner__map" viewBox="0 0 <%= hb.width %> <%= hb.height %>" role="img" aria-label="<%= kit.name %>, with the parts used in this project highlighted: <%= highlight.blocks.join(', ') %>">
                    <defs>
                        <mask id="kitBannerMask">
                            <rect x="0" y="0" width="<%= hb.width %>" height="<%= hb.height %>" fill="#fff"/>
                            <% highlight.blocks.forEach(function (name) { const b = hb.blocks[name]; %>
                            <rect x="<%= b[0] %>" y="<%= b[1] %>" width="<%= b[2] %>" height="<%= b[3] %>" rx="<%= corner %>" fill="#000"/>
                            <% }); %>
                        </mask>
                        <%# The picture keeps its rounded corners when the callouts are drawn outside it %>
                        <clipPath id="kitBannerClip"><rect x="0" y="0" width="<%= hb.width %>" height="<%= hb.height %>" rx="<%= corner %>"/></clipPath>
                    </defs>
                    <g clip-path="url(#kitBannerClip)">
                        <image href="<%= hb.image.replace(/\.(jpe?g|png)$/, '.webp') %>" x="0" y="0" width="<%= hb.width %>" height="<%= hb.height %>" preserveAspectRatio="none"/>
                        <rect class="kit-banner__map-dim" x="0" y="0" width="<%= hb.width %>" height="<%= hb.height %>" mask="url(#kitBannerMask)"/>
                    </g>
                    <% highlight.blocks.forEach(function (name) { const b = hb.blocks[name]; %>
                    <rect class="kit-banner__map-block" x="<%= b[0] %>" y="<%= b[1] %>" width="<%= b[2] %>" height="<%= b[3] %>" rx="<%= corner %>" stroke-width="<%= Math.round(hb.width / 110) %>"/>
                    <% }); %>
                    <% if (callouts) { %>
                    <%# Wide screens: label beside the board, joined to its block by a leader line %>
                    <g class="kit-banner__map-callouts" aria-hidden="true">
                        <% callouts.items.forEach(function (c) { %>
                        <path class="kit-banner__map-leader" d="<%= c.path %>" stroke-width="<%= callouts.lineWidth %>"/>
                        <circle class="kit-banner__map-dot" cx="<%= c.dot[0] %>" cy="<%= c.dot[1] %>" r="<%= callouts.dotRadius %>"/>
                        <text class="kit-banner__map-name" x="<%= c.textX %>" y="<%= c.nameY %>" text-anchor="<%= c.anchor %>" font-size="<%= callouts.nameSize %>"><%= c.name %></text>
                        <% if (c.text) { %>
                        <text class="kit-banner__map-role" x="<%= c.textX %>" y="<%= c.textY %>" text-anchor="<%= c.anchor %>" font-size="<%= callouts.textSize %>"><%= c.text %></text>
                        <% } %>
                        <% }); %>
                    </g>
                    <%# Narrower screens: a number on each block, explained in the list below the board %>
                    <g class="kit-banner__map-badges" aria-hidden="true">
                        <% callouts.items.forEach(function (c) { const bx = c.rect.x + callouts.badge.offset, by = c.rect.y + callouts.badge.offset; %>
                        <circle cx="<%= bx %>" cy="<%= by %>" r="<%= callouts.badge.radius %>"/>
                        <text x="<%= bx %>" y="<%= by %>" dy="0.35em" text-anchor="middle" font-size="<%= callouts.badge.size %>"><%= c.number %></text>
                        <% }); %>
                    </g>
                    <% } %>
                </svg>
                <% } else { %>
                <picture>
                    <source srcset="<%= kit.image.replace(/\.(jpe?g|png)$/, '.webp') %>" type="image/webp">
                    <img src="<%= kit.image %>" alt="<%= kit.name %>" width="<%= kit.imageSize[0] %>" height="<%= kit.imageSize[1] %>">
                </picture>
                <% } %>
            <% if (detail) { %></div><% } else { %></a><% } %>
            <% if (callouts) { %>
            <ol class="kit-banner__legend">
                <% callouts.items.forEach(function (c) { %>
                <li><b><%= c.name %></b><% if (c.text) { %><span><%= c.text %></span><% } %></li>
                <% }); %>
            </ol>
            <% } %>
        </div>
    </div>
</section>
