{#
    Notes section partial for deal view.
    Expected variables:
      - deal: Deal entity
      - canEditDeal: boolean
      - noteAuthorLabels: array of author names keyed by user ID
#}
<div class="dv-card" id="dvCardNotes">
    <div class="dv-card-header" onclick="DealView.toggleCard('dvCardNotes')">
        <h3>Notes <span class="dv-count">({{ deal.getNotes()|length }})</span> <span class="dv-chevron"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z"/></svg></span></h3>
        {% if canEditDeal %}
            <div class="dv-card-header-actions">
                <button class="dv-btn dv-btn-sm" type="button" onclick="event.stopPropagation(); mQuery('#dealflowAddNote').modal('show');">+ Add Note</button>
            </div>
        {% endif %}
    </div>
    <div class="dv-card-body">
        {% if deal.getNotes() is empty %}
            <p style="color:var(--text-secondary);margin:0;">No notes yet.</p>
        {% else %}
            {% for note in deal.getNotes()|reverse %}
                <div class="dv-note-item">
                    <div class="dv-note-header">
                        <span class="dv-note-author">{{ noteAuthorLabels[note.getAuthorUserId()] ?? (note.getAuthorUserId() ? ('User #' ~ note.getAuthorUserId()) : 'System') }}</span>
                        <span class="dv-note-date">{{ note.getCreatedAt().format('M j, Y') }}</span>
                        {% if canEditDeal %}
                            <button class="dv-note-edit-icon" title="Edit note" onclick="event.stopPropagation(); DealView.openEditNote({{ note.getId() }}, this);" data-note-body="{{ note.getBody()|e('html_attr') }}"><i class="ri-pencil-line"></i></button>
                        {% endif %}
                    </div>
                    <div class="dv-note-body dv-truncated" id="dvNote{{ note.getId() }}">{{ note.getBody()|purify_allow_target_blank }}</div>
                    <button class="dv-show-more-note" id="dvNote{{ note.getId() }}Toggle" onclick="DealView.toggleNote('dvNote{{ note.getId() }}')">Show more</button>
                </div>
            {% endfor %}
        {% endif %}
    </div>
</div>
