<div class="case-displayset-modal">
    <div class="mb-3">
        <h5>{{ ds.name }}</h5>
        {% if can_edit %}
            <a href="{% url 'atlas:case_displaysets' ds.case.pk %}?displayset={{ ds.pk }}&edit=true" class="btn btn-sm btn-outline-secondary ms-2">Edit display set</a>
        {% endif %}
        {% if ds.description %}
            <div class="text-muted">{{ ds.description }}</div>
        {% endif %}
    </div>

    {# Viewer area for the modal - mounted by rad/static/dv3d bundle #}
    <div class="mb-3">
        <div id="modal_viewer_{{ ds.pk }}" class="dicom-viewer-root" style="height:420px;" data-auto-cache-stack="false" data-annotationjson="{{ ds.annotations }}" data-viewerstate="{{ ds.viewerstate }}"></div>
    </div>

    {% if ds.viewerstate and ds.annotations %}
        <div class="mb-3">
            <button
                type="button"
                class="btn btn-primary"
                onclick='(window.importAnnotations_modal_viewer_{{ ds.pk }}||window.importAnnotations_modal_viewer||window.importAnnotations)({{ ds.annotations|safe }}); (window.importViewerState_modal_viewer_{{ ds.pk }}||window.importViewerState_modal_viewer||window.importViewerState)({{ ds.viewerstate|safe }});'
            >Reload display set</button>
        </div>
    {% endif %}

    <div class="mt-2">
        <strong>Findings:</strong>
        {% if ds.findings.all %}
            <ul>
                {% for finding in ds.findings.all %}
                    <li>{{ finding }}</li>
                {% endfor %}
            </ul>
        {% else %}
            <span class="text-muted">None</span>
        {% endif %}
    </div>

    <div>
        <strong>Structures:</strong>
        {% if ds.structures.all %}
            <ul>
                {% for structure in ds.structures.all %}
                    <li>{{ structure }}</li>
                {% endfor %}
            </ul>
        {% else %}
            <span class="text-muted">None</span>
        {% endif %}
    </div>

    <div>
        <strong>Conditions:</strong>
        {% if ds.conditions.all %}
            <ul>
                {% for condition in ds.conditions.all %}
                    <li>{{ condition }}</li>
                {% endfor %}
            </ul>
        {% else %}
            <span class="text-muted">None</span>
        {% endif %}
    </div>

    <div class="mt-3">
        <details>
            <summary class="small text-muted" style="cursor:pointer;">Show advanced (viewer state & annotations)</summary>
            <div>
                {% include 'atlas/partials/json_pretty.html' with json_value=ds.viewerstate title='Viewer State' %}
            </div>
            <div>
                {% include 'atlas/partials/json_pretty.html' with json_value=ds.annotations title='Annotations' %}
            </div>
        </details>
    </div>
</div>
