<%def name="row(tile, event, avatars=True, preview=True)">
    <%
    from adhocracy.lib.event import formatting
    event_html = formatting.as_html(event)
    %>
    <li class="${event.event.code}">
        %if avatars and h.config.get_bool('adhocracy.use_avatars'):
        %if event.user.is_deleted():
        <img class="avatar" src="/img/icons/user.png"/>
        %else:
        <img class="avatar" src="${h.logo_url(event.user, 32, x=32)}"/>
        %endif
        %endif
        <div class="time">${h.datetime_tag(event.time)|n}</div>
        <div class="action">
            <a href="${h.entity_url(event.user)}">${event.user.name}</a>
            ${tiles.badge.badges(event.user.get_badges(event.instance))}
            ${event_html|n}
        </div>

        %if preview:
            %if event.event.code in [u't_proposal_create', u't_proposal_edit'] and event.proposal.description.head is not None:
            ${row_text(h.entity_url(event.proposal), _(u'Show full proposal'), event.proposal.description.head.render())}

            %elif event.event.code in [u't_amendment_create', u't_amendment_edit'] and event.proposal.description.head is not None:
            ${row_text(h.entity_url(event.proposal), _(u'Show full amendment'), event.proposal.description.head.render())}

            %elif event.event.code in [u't_comment_create', u't_comment_edit'] and event.comment.__class__.__name__=='Comment':
            ${row_text(h.entity_url(event.comment), _(u'Show full comment'), h.render(event.comment.latest.text))}

            %elif event.event.code in [u't_message_send', u't_massmessage_send']:
            ${row_text(h.entity_url(event.message), _(u'Show full message'), event.message.rendered_body(c.user))}

            %endif
        %endif
    </li>
</%def>


<%def name="profile_row(tile, event)">
    ${row(tile, event, avatars=False)}
</%def>


<%def name="sidebar_row(tile, event)">
    ${row(tile, event, avatars=False, preview=False)}
</%def>


<%def name="row_text(url, link_text, text)">
    <% short = h.text.truncate_html(text, 30, u'&hellip;') %>
    <blockquote class="preview">${short|n}
        <a href="${url}" class="more_link">${link_text}</a>
    </blockquote>
</%def>


<%def name="carousel(events, more_url=None)">
    <%
    from adhocracy.i18n import datetime_tag
    from adhocracy.lib.event import formatting
    %>
    <ul>
        %for event in events:
        <%
        if event.event.code == 't_proposal_create':
            body = event.proposal.title
            meta = formatting.as_html(event, msg=_('created new proposal'))
        else:
            body = h.html_to_plain_text(event.text())
            meta = formatting.as_html(event)
        %>
        <li>
            <div class="event ${event.event.code}">
                ${datetime_tag(event.time)|n}
                <a class="icon" href=${event.link()}>${formatting.as_icon(event)|n}</a>
                <div class="summary">
                    <a href="${h.entity_url(event.user)}">${event.user.name}</a>
                    ${meta|n}
                </div>
                <a class="preview" href="${event.link()}">${h.truncate(body, 60, u'...', whole_word=True)}</a>
            </div>
            %if more_url:
            <a href="${more_url}" class="more_link">${_('display all events')}</a>
            %endif
        </li>
        %endfor
    </ul>
</%def>
