<%def name="render_form_filter_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><a href="#" class="topic" data-discussion_id="${entries[entry]['id']}" cohorted = "${entries[entry]['id'] in cohorted_commentables}">${entry}</a></li>
</%def>

<%def name="render_category(categories, category)">
    <li>
        <a href="#">${category}</a>
        <ul>
            ${render_form_filter_dropdown(categories[category])}
        </ul>
    </li>
</%def>


<article class="new-post-article">
    <div class="inner-wrapper">
        <form class="new-post-form">
            <div class="left-column">
                <label>Create new post about:</label>
                <div class="form-topic-drop">
                    <a href="#" class="topic_dropdown_button">Show All Discussions<span class="drop-arrow">▾</span></a>
                    <div class="topic_menu_wrapper">
                        <div class="topic_menu_search">
                            <input type="text" class="form-topic-drop-search-input" placeholder="filter topics">
                        </div>
                        <ul class="topic_menu">
                            ${render_form_filter_dropdown(category_map)}
                        </ul>
                    </div>
                </div>
                <div class="options">
                    <input type="checkbox" name="follow" class="discussion-follow" class="discussion-follow" id="new-post-follow" checked><label for="new-post-follow">follow this post</label>
                    <br>
                    % if course.allow_anonymous:
                        <input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
                    %elif course.allow_anonymous_to_peers:
                        <input type="checkbox" name="anonymous_to_peers" class="discussion-anonymous-to-peers" id="new-post-anonymous-to-peers"><label for="new-post-anonymous-to-peers">post anonymously to classmates</label>
                    %endif
                    %if is_course_cohorted and is_moderator:
                    <div class="form-group-label choose-cohort">
                        Make visible to:
                        <select class="group-filter-select new-post-group" name = "group_id">
                            <option value="">All Groups</option>
                            %for c in cohorts:
                                <option value="${c.id}"
                                %if user_cohort and str(user_cohort) == str(c.id):
                                    selected
                                %endif
                                >${c.name}</option>
                            %endfor
                        </select>
                    </div>
                    %endif
                </div>
            </div>
            <div class="right-column">
                <ul class="new-post-form-errors"></ul>
                <div class="form-row">
                    <input type="text" class="new-post-title" name="title" placeholder="Title">
                </div>
                <div class="form-row">
                    <div class="new-post-body" name="body" placeholder="Enter your question or comment…"></div>
                    <!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>-->
                </div>
                ## TODO tags commenting out til we figure out what to do w/ tags
                ##<div class="form-row">
                ##    <input type="text" class="new-post-tags" name="tags" placeholder="Tags">
                ##</div>
                <input type="submit" class="submit" value="Add post">
                <a href="#" class="new-post-cancel">Cancel</a>
            </div>
        </form>
    </div>
</article>
