<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <style>
        #root {
            padding: 1rem;
            display: flex;
            flex-direction: column;
            gap: 1rem;
            justify-content: space-between;
        }

        .preview-modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.2);
            /* Black w/ opacity */
        }

        .preview-modal-content {
            display: block;
            margin: 0 auto;
            position: relative;
            top: 50%;
            transform: translateY(-50%);
            height: 90%;
            max-width: 90%;
        }

        .thumbnail {
            cursor: pointer;
        }

        .collapsable-header {
            transform: rotate(0);
        }
    </style>
</head>

<body>

    <div id="root">

        <div class="card">
            <div class="card-header collapsable-header">
                <a class="btn stretched-link" data-bs-toggle="collapse" href="#collapseTopN">
                    Top {{ top_n_structures|length }} Structures
                </a>
            </div>
            <div id="collapseTopN" class="collapse show">
                <div class="card-body">
                    <div class="row row-cols-1 row-cols-sm-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4">
                        {% for item in top_n_structures %}
                        <div class="col mb-4">
                            <div class="card">
                                <img src="{{ item.img }}" class="card-img-top thumbnail" alt="thumbnail">
                                <div class="card-body">
                                    <ul class="list-unstyled">
                                        {% for key, value in item.metrics.items() %}
                                        <li><b>{{ key }}:</b> {{ value }}</li>
                                        {% endfor %}
                                    </ul>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-header collapsable-header">
                <a class="btn stretched-link" data-bs-toggle="collapse" href="#collapseBottomN">
                    Bottom {{ bottom_n_structures|length }} Structures
                </a>
            </div>
            <div id="collapseBottomN" class="collapse show">
                <div class="card-body">
                    <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5">
                        {% for item in bottom_n_structures %}
                        <div class="col mb-4">
                            <div class="card">
                                <img src="{{ item.img }}" class="card-img-top thumbnail" alt="thumbnail">
                                <div class="card-body">
                                    <ul class="list-unstyled">
                                        {% for key, value in item.metrics.items() %}
                                        <li><b>{{ key }}:</b> {{ value }}</li>
                                        {% endfor %}
                                    </ul>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="modal-root" class="preview-modal">
        <img class="preview-modal-content" id="modal-img" alt="">
    </div>
    <script>
        const modal = document.getElementById("modal-root");
        const modalImg = document.getElementById("modal-img");
        modalImg.addEventListener('click', (e) => {
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            return false;
        });
        modal.addEventListener('click', () => {
            modal.style.display = "none";
        });
        document.querySelectorAll(".thumbnail").forEach(
            img => {
                img.onclick = function () {
                    modal.style.display = "block";
                    modalImg.src = this.src;
                }
            }
        )
    </script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
        crossorigin="anonymous"></script>
</body>

</html>