<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>
<%namespace name="sidebar_defs" file="/sidebar.html"/>
<%namespace name="comment_tiles" file="/comment/tiles.html"/>
<%namespace name="state" file="/poll/state.html"/>

<%def name="title()">${c.proposal.title|n}</%def>

<%def name="breadcrumbs()">${h.proposal.breadcrumbs(c.proposal)|n}</%def>

<%block name="admin_controls">
<%components:admin_controls>

## FIXME: Reenable for adopt poll
##%if can.proposal.adopt(proposal):
##<a class="button title add ttip" title="${_('Call a vote on this proposal by freezing further development.')}"
##   href="${h.entity_url(proposal, member='ask_adopt')}">${_("call a vote")}</a>
##%endif

%if h.config.get_bool('adhocracy.proposal.split_badge_edit'):
%if can.proposal.edit_badges(c.proposal):
<a class="button edit" href="${h.entity_url(c.proposal, member='badges')}">${_("Edit Badges")}</a>
%endif
%endif

%if can.proposal.delete(c.proposal):
<a class="button title delete ttip" title="${_('Delete this proposal.')}"
   href="${h.entity_url(c.proposal, member='ask_delete')}">${_("delete")}</a>
%endif
</%components:admin_controls>
</%block>


<%block name="main_content">
<%
    url = h.base_url('/delegation/new?scope=%s' % str(c.proposal.id))
    delegate_url = url if can.delegation.create(c.proposal) else None
%>

%if not c.proposal.is_adopt_polling() and c.proposal.rate_poll is not None:
${tiles.poll.widget(c.proposal.rate_poll, cls='big', delegate_url=delegate_url)}
%endif

%if c.proposal.is_adopt_polling():
${tiles.poll.widget(c.proposal.adopt_poll, cls='big', delegate_url=delegate_url)}
%endif

<section>
    <article class="proposal">
        <h2>
            ${h.delegateable.link(c.proposal, link=False)|n}
            <div class="utility">
                %if can.proposal.edit(c.proposal):
                <a href="${h.entity_url(c.proposal, member='edit')}">${_("edit")}</a>
                %endif
            </div>
        </h2>

        <hr />

        <div class="body">
            ${tiles.page.inline(c.proposal.description,
                    hide_discussion=c.instance.use_norms and len(c.proposal.selections))}
        </div>

        ${components.social_share_buttons(c.proposal.title)}

        <div class="meta">
            %if not h.config.get_bool('adhocracy.proposal.hide_comments'):
            <a href="#discussions">${
                _("%s Discussions") % c.proposal.description.comment_count(reply_filter=None)
            }</a>
            %endif
            %if c.show_selections:
            ·
            %if len(c.num_selections) == 1:
            <a href="#proposals">${_("1 Proposed Implementation")}</a>
            %else:
            <a href="#proposals">${_("%s Proposed Implementations") % len(c.num_selections)}</a>
            %endif
            %endif
            %if h.config.get_bool('adhocracy.show_abuse_button'):
            ·
            <a href="${h.abuse.for_entity(c.proposal)}">${_("report")}</a>
            %endif
            ·
            <a href="${c.history_url}"
               rel="#overlay-url">${_('history')}</a>
        </div>
    </article>
    <br />

    %if not h.config.get_bool('adhocracy.proposal.hide_comments'):
    <div id="main_comments"
        %if c.monitor_comment_url:
        data-stats-baseurl="${c.monitor_comment_url}"
        %endif
    >
        <h3 id="discussions">
            ${_('Comments') if h.comment.wording() else _('Discussions')}
        </h3>
        ## comments are attached to the description which is a
        ## :class:`adhocracy.model.Page`
        ## proposal descriptions have no other variant than head.
        ${tiles.comment.list(c.proposal.description,
                             variant=c.proposal.description.head.variant)}
    </div>
    %endif
</section>


%if c.show_selections:
<section>
    <h3 id="proposals">${_("Proposed Implementations")}</h3>
    <hr />

    <ul class="papers_list">
        %for selection in c.sorted_selections:
        <% h.need.adhocracy_ko %>
        ${tiles.selection.row(selection)}
        %endfor
    </ul>

    <div class="list_button">
        <% auth = check.selection.create(c.proposal) %>
        <div id="propose-variant"></div>
        %if auth:
        <a class="button highlight"
           href="${h.entity_url(c.proposal, member='implementation/include')}">
            ${_("Propose to change a norm")}
        </a>
        %elif auth.propose_login():
        <a class="button highlight"
           href="${h.entity_url(c.proposal, member='implementation/include')}"
           rel="#overlay-login-button"
           title="${_('Login to propose to change a norm')}">
            ${_("Propose to change a norm")}
        </a>
        %elif auth.propose_join():
        <a class="button highlight"
           href="${h.entity_url(c.proposal, member='implementation/include')}"
           rel="#overlay-join-button"
           title="${_('Join instance to propose to change a norm')}">
            ${_("Propose to change a norm")}
        </a>
        %elif auth.propose_validate_email():
        <a class="button highlight"
           rel="#overlay-validate-button"
           title="${_('Validate email in order to propose to change a norm')}">
            ${_("Propose to change a norm")}
        </a>
        %endif
    </div>

    <%doc> FIXME: Enable change existing norm option
    %if norm.can.create
    <a class="button"
       title="${_('Propose to create a norm through this proposal.')}"
       href="${h.entity_url(c.proposal, member='implementation/propose')}">
        ${_("propose new norm")}
    </a>
    %endif
    </%doc>
</section>
%endif

<%components:tutorial>
<ol id="joyRideTipContent">
    <li data-id="col1"
        data-tip-location="top left" class="custom">
        <p>${_('tutorial_proposal_show_vote')}</p>
    </li>

    <li data-id="follow_proposal"
        data-tip-location="top left" class="custom">
        <p>${_('tutorial_proposal_show_follow')}</p>
    </li>

    <li data-id="information"
        data-tip-location="top" class="custom">
        <p>${_('tutorial_proposal_show_information')}</p>
    </li>

    <li data-id="FIXME-only-auth"
        data-tip-location="" class="custom">
        <p>${_('tutorial_proposal_show_tags')}</p>
    </li>

    <li data-id="socialshareprivacy"
        data-tip-location="" class="custom">
        <p>${_('tutorial_proposal_show_share')}</p>
    </li>

    <li data-id="FIXME: no id"
        data-tip-location="" class="custom">
        <p>${_('tutorial_proposal_show_vote_comment')}</p>
    </li>

    <li data-id="FIXME: no id"
        data-tip-location="" class="custom">
        <p>${_('tutorial_proposal_show_answers')}</p>
    </li>

    <li data-id="FIXME: no id"
        data-tip-location="" class="custom">
        <p>${_('tutorial_proposal_show_answer')}</p>
    </li>

    <li data-id="start-discussion-button"
        data-tip-location="bottom" class="custom">
        <p>${_('tutorial_proposal_show_new_discussion')}</p>
    </li>

    <li data-id="propose-variant" data-next="${_('Close')}"
        data-tip-location="bottom" class="custom">
        <p>${_('tutorial_proposal_show_propose_variant')}</p>
    </li>

</ol>
</%components:tutorial>
</%block>


<%block name="sidebar">
${components.message_button(c.proposal)}
${components.watch(c.proposal, id='follow_proposal')}

<div class="sidebar_box">
    <h3 id="information">${_('Information')}</h3>

    <div class="summary">
        ${sidebar_defs.shortlink(c.proposal)}

        <h6>${_('Last Activity')}</h6>
        <p>${h.datetime_tag(c.proposal.find_latest_comment_time())|n}</p>

        <% tally = c.proposal.rate_poll.tally %>

        %if c.proposal.rate_poll and can.poll.show_result():
        ${sidebar_defs.votes(c.proposal.rate_poll)}
        ${sidebar_defs.votedetail(c.votedetail)}
        %endif

        <h6>${_('Category')}</h6>
        <p>
          %if c.proposal.category:
          ${components.category_link(c.proposal.category)}
          %else:
          ${_("This proposal is not assigned to any category")}
          %endif
        </p>

        %if c.proposal.instance.milestones:
        <h6>${_('Milestones')}</h6>
        <% milestone = c.proposal.milestone %>
        <p>
            %if milestone:
            %if milestone.is_deleted():
            ${_("This proposal relates to the deleted milestone %s."
            ) % h.milestone.link(milestone)|n}
            %else:
            ${_("This proposal relates to the milestone %s."
            ) % h.milestone.link(milestone)|n}
            %endif
            %else:
            ${_("This proposal is not related to a milestone")}
            %endif
        </p>
        %endif

        <h6>${_('Created')}</h6>
        ## FIXME: ensure caching of history count (make it a tile?)
        <p>
            <%
            created_msg = _("by %s on %s, %s changes since then.") % (
                h.user.link(c.proposal.creator),
                h.date_tag(c.proposal.create_time),
                c.proposal.description.variant_changes_count(model.Text.HEAD))
            %>
            ${created_msg|n}
        </p>

        ${tiles.tag.sidebar(c.proposal)}

        ## FIXME: Reimplement Tagging
        ## <div class="only-js" id="add-tag">
        ##     <a href="#">Schlagwort hinzufügen</a>
        ## </div>
    </div>
</div>
</%block>
