/* search.js — Pagefind UI initialisation for /search.html.
   Loaded only on pages with search: true in frontmatter.
   Pre-fills the search box from the ?q= query parameter so that
   the selection popup's "Here" button lands ready to go. */
(function () {
    'use strict';

    window.addEventListener('DOMContentLoaded', function () {
        var ui = new PagefindUI({
            element: '#search',
            showImages: false,
            excerptLength: 30,
        });

        /* Pre-fill from URL parameter and trigger the search */
        var params = new URLSearchParams(window.location.search);
        var q      = params.get('q');
        if (q) {
            ui.triggerSearch(q);
        }
    });
}());
