<%namespace name="components" file="/components.html"/>
<%namespace name="state" file="/poll/state.html"/>

<%def name="_row(tile, proposal)">
    <div class="row_body">
        <h3 class="row_title"><a class="link" href="${h.entity_url(proposal)}">${proposal.title}</a>
            %if tile.fresh:
                ${_("(new)")}
            %endif
            <span id="badges_${proposal.id}" class="badges"
                  data-id="${proposal.id}">
                ${tiles.badge.badges(proposal.badges)}
            </span>
            <span  class="badges">
                ${tiles.badge.badges(proposal.categories)}
            </span>
            %if h.config.get_bool('adhocracy.proposal.split_badge_edit'):
            %if can.proposal.edit_badges(proposal):
            <a class="button_small edit"
               href="${h.entity_url(proposal, member='badges')}"
               rel="#overlay-form">${_(u"Edit Badges")}</a>
            %endif
            %else:
            %if can.proposal.edit(proposal):
            <a class="button_small edit"
               href="${h.entity_url(proposal, member='edit')}"
               rel="#overlay-form">${_(u"Edit")}</a>
            %endif
            %endif
        </h3>
        <div class="meta">
            %if proposal.is_adopt_polling():
                ${_("%s%% approval") % int(proposal.adopt_poll.tally.rel_for * 100)|n}
                ·
            %elif proposal.rate_poll is not None:
                ${_("%s:%s votes") % (proposal.rate_poll.tally.num_for, proposal.rate_poll.tally.num_against)|n}
                ·
            %endif
            %if proposal.instance.use_norms and proposal.instance.allow_propose_changes:
                ${ungettext("%s norm", "%s norms", len(proposal.selections)) % len(proposal.selections)}
                ·
            %endif
        </div>
    </div>
    <div id="thumbnailbadges_${proposal.id}" class="thumbnailbadges"
         data-id="${proposal.id}">
        ${tiles.badge.badges(proposal.thumbnails)}
    </div>
</%def>


<%def name="row(tile, proposal)">
    <li class="content_box ${'fresh' if tile.fresh else ''} proposal-row">
        <div class="main_row">
            ${_row(tile, proposal)}
        </div>
    </li>
</%def>


<%def name="row_inline(tile, proposal)">
    <li class="content_box ${'fresh' if tile.fresh else ''} proposal-row-inline">
        <div class="main_row">
            <div class="row_button">
                <a class="button_small showhide_button"
                   data-target="#proposal-${proposal.id}"
                   data-target-speed="fast"
                   data-toggle-class="less"
                   href="#"></a>
            </div>
            ${_row(tile, proposal)}
        </div>
        <article class="proposal" style="display: none" id="proposal-${proposal.id}">
            <div class="body">
                ${tiles.page.inline(proposal.description)}
            </div>
            <hr />

            %if not proposal.is_adopt_polling() and proposal.rate_poll is not None:
            ${tiles.poll.widget(proposal.rate_poll, cls='big')}
            %endif
            <a class="button" href="${h.entity_url(proposal, member='comments')}" rel="#overlay-url">${_('Join the discussion')}</a>
        </article>
    </li>
</%def>


<%def name="sidebar(tile, proposal)">
    %if proposal.is_adopt_polling():
        ${tiles.poll.booth(proposal.adopt_poll)}
    %endif

    <div class="sidebar_box">
        <h3>${_("Information")}</h3>
        <div>
            ${_("The proposal was created by %s on %s") % (h.user.link(proposal.creator), h.date_tag(proposal.create_time))|n}
            %if h.config.get_bool('adhocracy.show_abuse_button'):
            · <a href="${h.abuse.for_entity(proposal)}">${_("report")}</a>
            %endif
        </div>

        %if proposal.milestone and c.instance.milestones:
        <div class="infobox">
            ${_("This proposal relates to the milestone %s.") % h.milestone.link(proposal.milestone)|n}
        </div>
        %endif

        %if proposal.description.head.wiki:
        <div class="infobox">
            ${_("This is a <b>joint proposal</b> that can be improved by anyone. Edit it to improve or refine the text.")|n}
        </div>
        %endif

        <ul>
            <li><a href="${h.entity_url(proposal)}">${_("Main page")}</a></li>
            <li><a href="${h.entity_url(proposal.description, member='history')}">${_("History")}</a></li>
            %if c.instance.allow_delegate:
            <li><a title="${_('Who is receiving delegations?')}"
                   href="${h.entity_url(proposal, member='delegations')}"
                   class="delegations ttip">${_("Delegations")}
                    ##(${len(proposal.current_delegations())})</a>
            </li>
            %endif
        </ul>

        ${tiles.tag.sidebar(proposal)}
    </div>
    ${tiles.delegation.sidebar(proposal, tile)}
</%def>


<%def name="header(tile, proposal, active)">
    <h1>${h.delegateable.link(proposal, link=False)|n} ${tiles.badge.badges(proposal.badges)}</h1>
    ${tiles.proposal.panel(proposal, tile)}
</%def>


<%def name="panel(tile, proposal)">
    %if proposal.adopted:
    <div class="panel">
        <div class="info adoption adopted">
            ${_("%s has been adopted %s.") % (h.delegateable.link(proposal, link=False),
                                              h.datetime_tag(proposal.adopt_poll.end_time))|n}
        </div>
    </div>
    %elif proposal.is_adopt_polling():
    <!--
    <div class="panel">
        <div class="info adoption">
            <div class="given first">
                ${_("Adoption requirements:")}
            </div>
            %if proposal.adopt_poll.tally.has_majority() and not \
                proposal.adopt_poll.tally.has_participation():
                <div class="given">
                    ${_("%s%% approval") % int(c.instance.required_majority*100)}
                </div>
                <div class="">
                    ${_("%s participators") % c.instance.required_participation}
                </div>
            %else:
                <div class="${'given' if proposal.adopt_poll.tally.has_participation() else ''}">
                    ${_("%s participators") % c.instance.required_participation}
                </div>
                <div class="${'given' if proposal.adopt_poll.tally.has_majority() else ''}">
                    ${_("%s%% approval") % int(c.instance.required_majority*100)}
                </div>
            %endif
            <div class="last">
                ${_("stable majority for %s days") % c.instance.activation_delay}
            </div>
        </div>
    </div>
    -->
    %endif
</%def>
