{% macro render_note(note, hidden=true, can_edit=false, for_event=none, anchor=none) %}
    {% if note %}
        {% if for_event %}
            <div class="event-note-section">
                {{ _render_note_box(note=note, event=for_event, hidden=hidden, can_edit=can_edit, anchor=anchor) }}
            </div>
        {% else %}
            <div class="note-area-wrapper">
                <div class="note-area {{ _togglable_classes(hidden) }}">
                    {{ _render_note_box(note=note, can_edit=can_edit, anchor=anchor) }}
                </div>
            </div>
        {% endif %}
    {% endif %}
{% endmacro %}


{% macro render_toggle_button(note, note_is_hidden, anchor=none) %}
    <div class="note-visibility-toggle">
        {% set hash = uuid() %}
        <input type="checkbox" class="js-toggle-note-cb" id="toggle-note-{{ note.id }}-{{ hash }}" style="display:none;" {% if not note_is_hidden %}checked{% endif %}>
        <label for="toggle-note-{{ note.id }}-{{ hash }}" class="ui basic mini icon button js-show-note-toggle"
               title="{% trans %}Minutes{% endtrans %}">
            <i class="icon list"></i>
        </label>
    </div>
{% endmacro %}


{% macro _render_note_box(note, event=none, hidden=false, can_edit=false, anchor=none) %}
    <div class="padded-box">
        <div class="padded-box-pad">
            <i class="icon list"></i>
        </div>
        <div class="padded-box-content">
            {{ _render_note_actions(note=note, event=event, hidden=hidden, can_edit=can_edit, anchor=anchor) }}
            <div class="note-text editor-output {% if event %}{{ _togglable_classes(hidden=hidden) }}{% endif %}">
                {{ note.html|sanitize_html }}
            </div>
            {% if event %}
                <div class="no-note-text {{ _togglable_classes(hidden=not hidden) }}">
                    {% trans %}There are minutes attached to this event.{% endtrans %}
                    <a href="#" class="js-show-note-toggle">{% trans %}Show them{% endtrans %}</a>.
                </div>
            {% endif %}
            {% if can_edit %}
                <div class="note-metadata {{ _togglable_classes(hidden=hidden) }}">
                    <span class="icon-time modification-date">
                        {{ note.current_revision.created_dt | format_datetime(format='short') }}
                    </span>
                    <span class="icon-user name">
                        {{ note.current_revision.user.full_name }}
                    </span>
                </div>
            {% endif %}
        </div>
    </div>
{% endmacro %}


{% macro _note_link(note, anchor) -%}
    {%- set url_kw = dict(request.view_args, **request.args.to_dict(false)) -%}
    {%- set __ = url_kw.pop('note', none) -%}
    {{- url_for(request.endpoint, note=note.id, _anchor=anchor, **url_kw) -}}
{%- endmacro %}


{% macro _render_note_actions(note, event=none, hidden=true, can_edit=false, anchor=none) %}
    <div class="note-actions {% if event %}{{ _togglable_classes(hidden) }}{% endif %}">
        {% if event %}
            <a href="#" class="js-show-note-toggle">{% trans %}Hide{% endtrans %}</a>
        {% endif %}
        <a href="{{ _note_link(note, anchor) }}" target="_blank"
           class="permalink icon-link" title="{% trans %}Permanent link{% endtrans %}"></a>
        {% if can_edit %}
            {% set title = _('Edit minutes') %}
            <span class="manage-notes-container hide-if-locked"
                  data-icon
                  data-api-url="{{ url_for('event_notes.api', note) }}"
                  data-modal-title="{{ title ~ ': ' ~ note.object.title }}"
                  {% if note.object.can_manage_attachments(session.user) %}
                      data-image-upload-url="{{ url_for('attachments.upload_editor', note) }}"
                  {% endif %}></span>
        {% endif %}
    </div>
{% endmacro %}


{% macro _togglable_classes(hidden) -%}
    togglable {% if hidden %}weak-hidden{% endif %}
{%- endmacro %}
