<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%namespace name="sidebar_defs" file="/sidebar.html"/>
<%namespace name="state" file="/poll/state.html"/>
<% from adhocracy.lib import sorting %>
<%def name="title()">${c.page.title|n}</%def>
<%def name="breadcrumbs()">${h.text.breadcrumbs(c.text)|n}</%def>


<%def name="flags(page)">
    <ul class="flags">
        %if page.allow_comment:
        <% comment_count = page.comment_count() %>
        <li class="comments"><a href="${h.entity_url(page, member='comments')}" rel="#overlay-url"
            title="${_(u'Comments') if h.comment.wording() else _('Discussions')}">
            <span class="count">${comment_count}</span>
            <span class="caption">${ungettext(u'Comment' , u'Comments', comment_count) if h.comment.wording() else ungettext(u'Discussion', u'Discussions', comment_count)}</span>
        </a></li>
        %endif
        %if page.allow_selection:
        <% selection_count = len(page.selections) %>
        <li class="selections"><a href="${h.entity_url(page, member='amendment')}" rel="#overlay-url-big"
            title="${_(u'Amendments')}">
            <span class="count">${selection_count}</span>
            <span class="caption">${ungettext(u'Amendment', u'Amendments', selection_count)}</span>
        </a></li>
        %endif
    </ul>
</%def>


<%def name="section(page)">
    <section id="subpage-${page.id}" class="subpage">
        <div class="body">
            ${page.render()|n}

            <aside>
                ${flags(page)}
                <div class="utility">
                    %if can.norm.edit(page):
                    <a href="${h.entity_url(page, member='edit', query={'section_parent': c.page.id})}" rel="#overlay-form" >${_(u"Edit")}</a>
                    %endif
                    %if can.page.delete(page):
                    <a href="${h.entity_url(page, member='ask_delete', query={'section_parent': c.page.id})}" rel="#overlay-form">${_(u"Delete")}</a>
                    %endif
                </div>
            </aside>
        </div>

        %for subpage in sorting.delegateable_label(page.subpages):
        ${section(subpage)}
        %endfor
    </section>
</%def>


<%block name="main">
    <h2 id="tutorial-sectionpage">
        ${c.page.title}
        %if not c.variant_details['is_head']:
        &ndash; ${c.variant_details['display_title']}
        %endif
    </h2>

    <section class="subpage">
        <div class="body">
            ${c.variant_details['text']|n}

            <aside id="tutorial-actions">
                ${flags(c.page)}
                <div class="utility">
                    %if c.variant_details['can_edit']:
                    <a href="${c.variant_details['edit_url']}" rel="#overlay-form" >${_(u"Edit")}</a>
                    %endif
                    %if can.page.delete(c.page):
                    <a href="${h.entity_url(c.page, member='ask_delete')}">${_(u"Delete")}</a>
                    %endif
                </div>
            </aside>
        </div>

        %for subpage in sorting.delegateable_label(c.page.subpages):
        ${section(subpage)}
        %endfor
    </section>

    %if can.page.create():
    <a class="button highlight" href="${h.base_url('/page/new', query_params={'section_parent': c.page.id})}">${_(u"Add section")}</a>
    %endif

    <%components:tutorial>
        <ol id="joyRideTipContent">
            <li data-id="tutorial-sectionpage"
                data-tip-location="top" class="custom">
                <p>${_('This norm has been split into several sections.')}</p>
            </li>
            <li data-id="tutorial-actions" data-next="${_(u'Close')}"
                data-tip-location="top" class="custom">
                <p>${_('You can propose amendments and comment each section individually by using the controls on the right.')}</p>
            </li>
        </ol>
    </%components:tutorial>
</%block>
