{{!
    This file is part of Moodle - http://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template local_adminer/foreign_key/header_js

    This template prints the toggle JS and a small style in the header of the Adminer page.

    Example context (json):
    {
        "nonce": "nonce=\"jsjlfjlfjdsf\""
    }
}}

<script {{{nonce}}}>
    document.addEventListener("click", function(event) {
        if (event.target.dataset.mdlforeignkeybutton == "1" || event.target.dataset.rowid > 0) {
            event.preventDefault();
            let button = event.target;
            let morediv = button.parentElement.parentElement.querySelector('div.fk-more');
            if (morediv) {
                if (morediv.classList.contains('hidden')) {
                    morediv.classList.remove('hidden');
                    button.innerText = '[{{#str}}hide{{/str}}]';
                } else {
                    morediv.classList.add('hidden');
                    button.innerText = '[{{#str}}more{{/str}}]';
                }
            }
        }
    })
</script>
<style>
    .morelink-button {
        cursor: pointer;
    }
</style>
