(function () {
    const cfg = window.plantshop_wc_cart_info || {};
    if (!cfg.html) return;

    let inserted = false;
    let mo;

    function inject() {
        if (inserted) return;

        const items = document.querySelector('.wc-block-cart');
        if (!items) return;

        if (document.querySelector('.plantshop-neighbors')) {
            inserted = true;
            if (mo) mo.disconnect();
            return;
        }

        const wrap = document.createElement('div');
        wrap.innerHTML = cfg.html;

        const node = wrap.firstElementChild;
        if (!node) return;

        items.after(node);
        inserted = true;
        if (mo) mo.disconnect();
    }

    if (document.readyState !== 'loading') inject();
    else document.addEventListener('DOMContentLoaded', inject);

    try {
        mo = new MutationObserver(inject);
        mo.observe(document.body, {childList: true, subtree: true});
    } catch (e) {
    }
})();
