<%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="section(page)">
    <section id="subpage-${page.id}" class="subpage">
        <div class="body">
            ${page.render()|n}

            <aside>
                <ul class="flags">
                    %if page.allow_comment:
                    <li><a href="${h.entity_url(page, member='comments')}" rel="#overlay-url">${_(u'Comments') if h.comment.wording() else _('Discussions')} (${page.comment_count()})</a></li>
                    %endif
                    %if page.allow_selection:
                    <li><a href="${h.entity_url(page, member='amendment')}" rel="#overlay-url-big">${_(u'Amendments')} (${len(page.selections)})</a></li>
                    %endif
                </ul>
                <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_title(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">
                <ul class="flags">
                    %if c.page.allow_comment:
                    <li><a href="${h.entity_url(c.page, member='comments')}" rel="#overlay-url">${_(u'Comments') if h.comment.wording() else _(u'Discussions')} (${c.page.comment_count()})</a></li>
                    %endif
                    %if c.page.allow_selection:
                    <li><a href="${h.entity_url(c.page, member='amendment')}" rel="#overlay-url-big">${_(u'Amendments')} (${len(c.page.selections)})</a></li>
                    %endif
                </ul>
                <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_title(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>
