{# Sprint 6 iter 6c — gear-btn on /gameboard/my-sea/ + the gatekeeper.  #}
{# NVM-only menu (no DEL, no BYE) — gear is the "back out without      #}
{# committing" affordance. Caller passes `nvm_url` to control where    #}
{# NVM nav-backs to: my_sea landing (table hex) from gatekeeper +      #}
{# picker; falls back to /gameboard/ otherwise. Render unconditionally  #}
{# (no active-draw guard) so fresh users + post-DEL states still see it.#}
{# `<button>` not `<a class='btn'>` — `.btn` doesn't reset font-family, #}
{# so the anchor inherits body's serif font (the Brief's NVM uses       #}
{# `<button>` + reads correctly as sans-serif).                         #}
{# See [[feedback-btn-vs-anchor-font-family]].                          #}
{% if not nvm_url %}{% url 'gameboard' as nvm_url %}{% endif %}
{# mySeaGuardedNav — defined inline (dependency-free; this partial loads on    #}
{# pages w/o the voice JS). When voice is LIVE and the NVM target leaves       #}
{# my_sea entirely (url has no `/my-sea`), warn via the shared guard portal    #}
{# before navigating, since the page reload tears the mesh down for this       #}
{# party. NVMs that stay within my_sea, or any nav with no live mic, go        #}
{# straight through. (Voice-disconnect guard — user-spec 2026-05-29.)          #}
<script>
window.mySeaGuardedNav = window.mySeaGuardedNav || function (e, url) {
    var live = window.VoiceRoom && window.VoiceRoom.localStream;
    var leavesMySea = url.indexOf('/my-sea') === -1;
    if (live && leavesMySea && typeof window.showGuard === 'function') {
        if (e && e.preventDefault) e.preventDefault();
        var anchor = (e && (e.currentTarget || e.target)) || document.body;
        window.showGuard(
            anchor,
            'Leave the Sea?<br>You’ll disconnect from voice.',
            function () {                                   // confirm = leave
                if (window.mySeaVoiceForget) window.mySeaVoiceForget();
                if (window.VoiceRoom && window.VoiceRoom.leave) window.VoiceRoom.leave();
                window.location.href = url;
            },
            null,                                           // dismiss = stay
            { yesLabel: 'OK' }                              // confirm = OK (user-spec 2026-05-30)
        );
        return;
    }
    window.location.href = url;
};
</script>
<div id="id_my_sea_menu" style="display:none">
    {# `.menu-btns` is the flex container the shared %applet-menu styles —    #}
    {# column in portrait / row in landscape (the menu itself can't be flexed #}
    {# since applets.js force-sets display:block on open).                    #}
    <div class="menu-btns">
        {# `nvm_handler` lets a caller swap the default leave-the-sea nav for a   #}
        {# phase-aware handler (the visitor's my_sea_visit routes NVM to the bud  #}
        {# page from the table hex, but back to the hex from the draw phase).    #}
        <button type="button" class="btn btn-cancel" onclick="{% if nvm_handler %}{{ nvm_handler }}{% else %}mySeaGuardedNav(event, '{{ nvm_url }}'){% endif %}">NVM</button>
        {# Spectator-only BYE (Phase B) — drops presence (status=LEFT, frees seat #}
        {# 2C, kills voice). Rendered below NVM only when the caller passes a     #}
        {# `leave_url`; the owner's pages never do, so their menu is unchanged.   #}
        {% if leave_url %}
        <form method="POST" action="{{ leave_url }}" style="display:contents">
            {% csrf_token %}
            {# BYE is an explicit leave — forget the room so the destination page #}
            {# (and any return to my_sea) doesn't auto-rejoin the dropped call.   #}
            <button type="submit" id="id_my_sea_bye_btn" class="btn btn-abandon"
                    onclick="if(window.mySeaVoiceForget)window.mySeaVoiceForget()">BYE</button>
        </form>
        {% endif %}
    </div>
</div>
{% include "apps/applets/_partials/_gear.html" with menu_id="id_my_sea_menu" %}
