<%! from django.utils.translation import ugettext as _ %>
<%! import json %>

<%def name="render_dropdown(map)">
    % for child in map["children"]:
        % if child in map["entries"]:
            ${render_entry(map["entries"], child)}
        %else:
            ${render_category(map["subcategories"], child)}
        %endif
    %endfor
</%def>

<%def name="render_entry(entries, entry)">
    <li
        class="forum-nav-browse-menu-item"
        data-discussion-id='${entries[entry]["id"]}'
        data-cohorted="${str(entries[entry]['is_cohorted']).lower()}"
    >
        <a href="#" class="forum-nav-browse-title">${entry}</a>
    </li>
</%def>

<%def name="render_category(categories, category)">
    <li class="forum-nav-browse-menu-item">
        <a href="#" class="forum-nav-browse-title">${category}</a>
        <ul class="forum-nav-browse-submenu">
            ${render_dropdown(categories[category])}
        </ul>
    </li>
</%def>

<div class="forum-nav-browse-menu-wrapper" style="display: none">
    <form class="forum-nav-browse-filter">
        <label>
            <span class="sr">${_("Filter Topics")}</span>
            <input type="text" class="forum-nav-browse-filter-input" placeholder="${_("filter topics")}">
            <i class="icon icon-filter"></i>
        </label>
    </form>
    <ul class="forum-nav-browse-menu">
        <li class="forum-nav-browse-menu-item forum-nav-browse-menu-all">
            <a href="#" class="forum-nav-browse-title">${_("All Discussions")}</a>
        </li>
        <li class="forum-nav-browse-menu-item forum-nav-browse-menu-following">
            <a href="#" class="forum-nav-browse-title"><i class="icon icon-star"></i>${_("Posts I'm Following")}</a>
        </li>
        ${render_dropdown(category_map)}
    </ul>
</div>
