{"id":38397,"date":"2025-08-28T15:08:42","date_gmt":"2025-08-28T13:08:42","guid":{"rendered":"https:\/\/livres-alie.fr\/Boutique\/?page_id=38397"},"modified":"2025-08-28T15:08:44","modified_gmt":"2025-08-28T13:08:44","slug":"recherche","status":"publish","type":"page","link":"https:\/\/livres-alie.fr\/Boutique\/recherche\/","title":{"rendered":"Recherche"},"content":{"rendered":"        <div id=\"alie-results-wrap\">\n            <div id=\"alie-results-head\">\n                <input id=\"alie-q\" type=\"search\" placeholder=\"Rechercher\u2026\" value=\"\">\n                <button id=\"alie-btn\" class=\"button\">Rechercher<\/button>\n            <\/div>\n            <div id=\"alie-results-list\" class=\"alie-list\"><\/div>\n            <div id=\"alie-pager\">\n                <button id=\"alie-prev\" class=\"button\" disabled>Pr\u00e9c\u00e9dent<\/button>\n                <span id=\"alie-info\"><\/span>\n                <button id=\"alie-next\" class=\"button\" disabled>Suivant<\/button>\n            <\/div>\n        <\/div>\n        <style>\n            #alie-results-head{display:flex;gap:8px;margin:10px 0}\n            #alie-q{flex:1;padding:.6rem .8rem;border:1px solid #ddd;border-radius:8px}\n            #alie-btn{padding:.6rem .9rem;border-radius:8px}\n            .alie-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:14px}\n            .alie-card{display:flex;flex-direction:column;gap:10px;padding:10px;border:1px solid #eee;border-radius:10px;background:#fff;color:inherit}\n            .alie-card .alie-card-link{display:flex;gap:10px;flex:1;text-decoration:none;color:inherit}\n            .alie-card img{width:70px;height:95px;object-fit:cover;border-radius:6px;background:#eee}\n            .alie-card-actions{margin-top:auto;display:flex}\n            .alie-card-actions .button{flex:1;text-align:center}\n            .alie-title{font-weight:600;margin-bottom:4px}\n            .alie-sub{font-size:12px;color:#666}\n            .alie-chip{font-size:11px;padding:2px 6px;border-radius:999px;border:1px solid #ddd}\n            .in{background:#eaffea;border-color:#b7e4b7;color:#237a23}\n            .remote{background:#f2f2f2;color:#555}\n            #alie-pager{display:flex;align-items:center;gap:12px;justify-content:center;margin:18px 0}\n            .alie-loading{display:flex;align-items:center;gap:10px;padding:12px}\n            .alie-spinner{width:16px;height:16px;border:2px solid #ddd;border-top-color:#888;border-radius:50%;animation:alie-spin .8s linear infinite}\n            @keyframes alie-spin{to{transform:rotate(360deg)}}\n            .alie-empty{padding:12px;color:#777}\n        <\/style>\n        <script>\n        (function(){\n            const qs=(k)=>new URLSearchParams(location.search).get(k)||'';\n            const input=document.getElementById('alie-q');\n            const btn=document.getElementById('alie-btn');\n            const list=document.getElementById('alie-results-list');\n            const prev=document.getElementById('alie-prev');\n            const next=document.getElementById('alie-next');\n            const info=document.getElementById('alie-info');\n\n            let from=0, size=24, total=0, ROOT=null;\n\n            async function detectRoot(){\n                if (ROOT) return ROOT;\n                const bases = [\n                    window.wpApiSettings?.root,\n                    location.origin + '\/wp-json\/',\n                    location.origin + '\/Boutique\/wp-json\/'\n                ].filter(Boolean);\n                for (const base of [...new Set(bases)]) {\n                    try {\n                        const testUrl = base.replace(\/\\\/+$\/,'') + '\/alie\/v1\/search?q=test&size=1';\n                        const res = await fetch(testUrl, { headers: { 'Accept': 'application\/json' } });\n                        const ct = (res.headers.get('content-type') || '').toLowerCase();\n                        if (res.ok && ct.includes('application\/json')) {\n                            const final = new URL(res.url);\n                            const root = final.href.replace(\/\\\/alie\\\/v1\\\/search.*$\/,'\/').replace(\/\\\/+$\/,'\/');\n                            ROOT = root;\n                            return ROOT;\n                        }\n                    } catch (e) {}\n                }\n                throw new Error('API indisponible');\n            }\n\n            async function search(q){\n                const root = await detectRoot();\n                const url  = root.replace(\/\\\/+$\/,'') + `\/alie\/v1\/search?q=${encodeURIComponent(q)}&size=${size}&from=${from}`;\n                list.innerHTML = `<div class=\"alie-loading\"><span class=\"alie-spinner\"><\/span>Recherche\u2026<\/div>`;\n                const r = await fetch(url, { headers: { 'Accept': 'application\/json' } });\n                const ct = (r.headers.get('content-type') || '').toLowerCase();\n                if (!r.ok || !ct.includes('application\/json')) {\n                    throw new Error(`HTTP ${r.status} \/ CT ${ct}`);\n                }\n                return r.json();\n            }\n\n            function render(data,q){\n                total=data.total||0; const items=data.items||[];\n                if(!items.length){\n                    list.innerHTML='<div class=\"alie-empty\">Aucun r\u00e9sultat<\/div>';\n                    prev.disabled=true; next.disabled=true; info.textContent=''; return;\n                }\n                list.innerHTML = items.map(it=>{\n                    const viewHref = (it.permalink && it.permalink.length) ? it.permalink\n                                     : '\/Boutique\/?ensure-remote=' + encodeURIComponent(it.sku);\n                    const addHref  = (it.product_id && String(it.product_id).length)\n                          ? ('?add-to-cart=' + encodeURIComponent(it.product_id))\n                          : ('\/Boutique\/?add-remote=' + encodeURIComponent(it.sku));\n                    const chip = it.in_stock ? '<span class=\"alie-chip in\">En stock<\/span>'\n                                             : '<span class=\"alie-chip remote\">Sur commande<\/span>';\n                    const img  = it.image ? `<img decoding=\"async\" src=\"${it.image}\" alt=\"\">` : `<img alt=\"\">`;\n                    const sub  = [it.auteur,it.editeur].filter(Boolean).join(' \u2014 ');\n                    return `<div class=\"alie-card\">\n                              <a href=\"${viewHref}\" class=\"alie-card-link\">\n                                ${img}\n                                <div>\n                                  <div class=\"alie-title\">${(it.titre||'').replace(\/<\/g,'&lt;')}<\/div>\n                                  <div class=\"alie-sub\">${(sub||'').replace(\/<\/g,'&lt;')}<\/div>\n                                <\/div>\n                              <\/a>\n                              <div class=\"alie-card-actions\">\n                                <a class=\"button alt\" href=\"${addHref}\">Ajouter au panier<\/a>\n                              <\/div>\n                            <\/div>`;\n                }).join('');\n\n                const page=Math.floor(from\/size)+1, pages=Math.max(1,Math.ceil(total\/size));\n                prev.disabled = (from===0);\n                next.disabled = (from+size>=total);\n                info.textContent = `${total} r\u00e9sultats \u2014 page ${page}\/${pages}`;\n                history.replaceState(null,'',`?q=${encodeURIComponent(q)}&p=${page}`);\n            }\n\n            async function run(){\n                const q=input.value.trim();\n                if(q.length<2){ list.innerHTML='<div class=\"alie-empty\">Tapez au moins 2 lettres<\/div>'; return; }\n                try{ const data=await search(q); render(data,q); }\n                catch(e){ list.innerHTML='<div class=\"alie-empty\">Recherche indisponible<\/div>'; }\n            }\n\n            btn.addEventListener('click', ()=>{from=0; run();});\n            input.addEventListener('keydown', (e)=>{ if(e.key==='Enter'){ e.preventDefault(); from=0; run(); }});\n            prev.addEventListener('click', ()=>{ if(from>=size){ from-=size; run(); }});\n            next.addEventListener('click', ()=>{ if(from+size<total){ from+=size; run(); }});\n\n            input.value = qs('q');\n            const p=parseInt(qs('p')||'1',10); if(p>1) from=(p-1)*size;\n            run();\n        })();\n        <\/script>\n        \n\n    <div class=\"xs_social_share_widget xs_share_url after_content \t\tmain_content  wslu-style-1 wslu-share-box-shaped wslu-fill-colored wslu-none wslu-share-horizontal wslu-theme-font-no wslu-main_content\">\n\n\t\t\n        <ul>\n\t\t\t        <\/ul>\n    <\/div> \n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-38397","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/pages\/38397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/comments?post=38397"}],"version-history":[{"count":1,"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/pages\/38397\/revisions"}],"predecessor-version":[{"id":38408,"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/pages\/38397\/revisions\/38408"}],"wp:attachment":[{"href":"https:\/\/livres-alie.fr\/Boutique\/wp-json\/wp\/v2\/media?parent=38397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}