globalThis.spotler_search_templates = globalThis.spotler_search_templates || {}; globalThis.spotler_search_templates['0d872e3c-a5c2-4f26-a2e5-c3381790e19c'] = (function (props) { const currencyFormatter = new Intl.NumberFormat('nl-NL', { //style: 'currency', //currency: 'EUR', minimumFractionDigits: 2, maximumFractionDigits: 2 }); function formatCurrency(price) { return currencyFormatter.format(price); } function matchQueryInBold(str) { if (str === undefined) { return ''; } const escapedSearchTerm = props.spotler.getSearchTerm().replace(/([.?*+^$[\]\\(){}|-])/g, "\\$&"); return str.replace(new RegExp(escapedSearchTerm, 'gi'), '$&'); } function triggerChangeView(event, view) { event.preventDefault(); props.spotler.triggerViewChange(view); } function revertToPreviousSuccessfulState() { props.spotler.revertToPreviousSuccessfulState(); } async function SuggestView(props) { const { items, content } = await props.spotler.fetchResults(); return `
Zoeksuggesties
Makita accu
Makita accuboormachine
Makita bithouder
Productsuggesties
${items.data?.map(item => `
${matchQueryInBold(item.properties.title)}
★★★★☆53 reviews
€299
${formatCurrency(item.properties.price)}
`).join("")}
Meer informatie
${content.data?.map(content => `
${matchQueryInBold(content.properties.title)}
`).join('')}
`; } async function ItemsView(props) { const { items } = await props.spotler.fetchResults(); props.state.datasets['items'].filterStates = items.facets.reduce((obj, f) => { obj[f.id] = { collapsed: f.is_default_collapsed, ...obj[f.id] }; return obj; }, props.state.datasets['items'].filterStates ?? {}); if (items.meta.total > (items.meta.offset + items.meta.limit)) { props.spotler.registerInfiniteScroll('items', '[data-sqr-infinite-scroll-item]:last-child', ({ items }) => Items(items.data)); } return `
Kies je filter
${ActiveFilters(props.state.datasets['items'], items?.facets)} ${Filters(items?.facets)}
${items?.meta?.total === 1 ? 'Resultaat' : 'Resultaten'}${items?.meta?.total} ${items?.meta?.total === 1 ? 'product' : 'producten'}
Sortering:
Resultaten${items?.meta?.total} ${items?.meta?.total === 1 ? 'resultaat' : 'resultaten'}
${items.meta.total === 0 ? `

We hebben geen resultaten gevonden

${props.spotler.hasPreviousSuccessfulState() ? ` ` : ``}
` : ` ${SpellcheckMessage(items?.spellcheck, items?.meta?.total)} ${Banners(items?.banners)}
${Items(items?.data)}
`}
`; } function ActiveFilters(dataset, facets) { if (!Array.isArray(dataset.filters) || dataset.filters.length === 0) { return ''; } const filters = []; for (const filter of dataset.filters) { const facet = facets.find(f => f.name === filter.field); if (!facet) { continue; } switch (facet.type) { case 'dualslider': filters.push({ name: facet.name, label: facet.label, value: `${renderFilterLabel(filter.start, facet.prefix, facet.suffix)} - ${renderFilterLabel(filter.end, facet.prefix, facet.suffix)}` }); break; case 'multiselect': filters.push({ name: facet.name, label: facet.label, value: facet.values.filter(v => filter.values.includes(v.value)).map(v => renderFilterLabel(v.label, facet.prefix, facet.suffix)).join(', ') }); break; default: filters.push({ name: facet.name, label: facet.label, value: renderFilterLabel(filter.value, facet.prefix, facet.suffix) }); } } if (filters.length === 0) { return ''; } function clearFilters(event, dataset) { event.preventDefault(); props.spotler.clearAllFilters(dataset); } return `

Filteren

Huidige filters
${filters.map(ActiveFilter).join('')}
Alles wissen
`; } function ActiveFilter(filter) { function removeFilter(event, dataset, filterId) { props.spotler.triggerFilterChange(dataset, filterId); } return ` ${filter.value} `; } function Filters(filters) { return filters?.map(facet => { switch (facet.type) { case 'select': return renderSelectFilter({ ...facet, dataset: 'items' }); case 'multiselect': return renderMultiSelectFilter({ ...facet, dataset: 'items' }); case 'radio': return renderRadioFilter({ ...facet, dataset: 'items' }); case 'slider': return renderSliderFilter({ ...facet, dataset: 'items' }); case 'dualslider': return renderDualSliderFilter({ ...facet, dataset: 'items' }); } }).join(''); } function SpellcheckMessage(spellcheck, total) { if (!spellcheck) { return ''; } return `
Je zocht op ${spellcheck.old}, maar wij vonden geen resultaten. Bedoel je ${spellcheck.new}? Daar vonden wij ${total} ${total === 1 ? 'resultaat' : 'resultaten'}.
`; } function Banners(banners) { if (!Array.isArray(banners) || banners.length === 0) { return ''; } const banner = banners.pop(); const bannerTypes = Object.keys(banner); let bannerHtml = ''; for (let i = 0, l = bannerTypes.length; i < l; i++) { const bannerType = bannerTypes[i]; switch (bannerType) { case 'mobile': bannerHtml += Banner(banner, bannerType, 'sqr-block tablet:sqr-hidden'); break; case 'tablet': bannerHtml += Banner(banner, bannerType, 'sqr-hidden tablet:sqr-block desktop:sqr-hidden'); break; case 'desktop': bannerHtml += Banner(banner, bannerType, 'sqr-hidden desktop:sqr-block'); break; } } return bannerHtml; } function Banner(banner, type, mediaClasses) { if (!(type in banner)) { return ''; } if (banner[type].url) { return ` `; } return ``; } function Items(items) { return items?.map(Item).join(''); } function isBeforeNovemberFirst(dateString) { // Parse the input date string const givenDate = new Date(dateString); // Create the comparison date for November 1, 2024, 00:00:00 UTC const novemberFirst2024 = new Date('2024-11-01T00:00:00Z'); // Check if the given date is valid and compare the dates if (isNaN(givenDate.getTime())) { throw new Error("Invalid date format."); } return givenDate < novemberFirst2024; } function Item(item) { let num = item.properties.min_sale_qty let integerPart = Math.trunc(num); let hasStock = ( ( item.properties.stock_barneveld && item.properties.stock_barneveld.length > 0 && parseInt(item.properties.stock_barneveld[0]) >= 1 ) || ( item.properties.leverdatum && item.properties.leverdatum.length && isBeforeNovemberFirst(item.properties.leverdatum) && item.properties.voorraadkoppeling && item.properties.voorraadkoppeling > 0 ) ); let stockCLass = window.innerWidth < 768 ? `in-stock-mobile` : `in-stock` let stockStatus = hasStock ? `
Op voorraad
` : ''; return `
${item.properties.title}

${item.properties.brand && item.properties.brand[0]}

${props.spotler.getConfig('enableResultItemClick') ? `` : ''} ${item.properties.title}

  • ${item.properties.attributes_usps_usp_1}
  • ${item.properties.attributes_usps_usp_2}
  • ${item.properties.attributes_usps_usp_3}
${item.properties.price ? `

${formatCurrency(item.properties.price)}

` : ''}
${item.properties.double_normal_price ? formatCurrency(item.properties.double_normal_price) : ""}
${stockStatus}
`; } function getUrl(item) { window.open(item.properties.detail_url) } function getButton(item, num) { return ` ${num === 1 ? window.innerWidth < 768 ? `Bekijken` : `Product bekijken` : ``} `; } function renderFilter(facet, children) { const filterState = props.state.datasets[facet.dataset].filterStates?.[facet.id]; const collapsed = filterState?.collapsed ?? facet.is_default_collapsed; function collapse(e, dataset, filterId) { e.preventDefault(); const element = e.currentTarget; const filterState = props.state.datasets[dataset].filterStates?.[filterId]; const active = element.classList.contains('sqr-active'); element.classList.toggle('sqr-active', !active); element.nextElementSibling.classList.toggle('sqr-hidden', active); filterState.collapsed = active; } return `
${children}
`; } function renderSelectFilter(facet) { return renderFilter(facet, `
`); } function showMore(e, dataset, filterId) { e.preventDefault(); const element = e.currentTarget; const parentElement = element.closest('[data-sqr-filter]'); const filterState = props.state.datasets[dataset].filterStates?.[filterId]; filterState.showing_more = !filterState.showing_more; element.textContent = filterState.showing_more ? 'Toon minder' : 'Toon meer'; parentElement.dataset.sqrFilterShowingMore = filterState.showing_more; parentElement.querySelectorAll('[data-initially-hidden]').forEach(element => { element.classList.toggle('sqr-hidden', !filterState.showing_more); }); } function renderMultiSelectFilter(facet) { const hasMoreValues = facet.values.length > facet.result_limit; const filterState = props.state.datasets[facet.dataset].filterStates?.[facet.id]; const showingMore = filterState.showing_more ?? false; return renderFilter(facet, `
${facet.label.includes("Kleur") ? facet.values.map((filterValue, index) => `
= facet.result_limit ? 'data-initially-hidden' : ''} class="sqr-flex sqr-items-baseline ${(!showingMore && index >= facet.result_limit) ? 'sqr-hidden' : ''}">
`).join("") : facet.values.map((filterValue, index) => `
= facet.result_limit ? 'data-initially-hidden' : ''} class="sqr-flex sqr-items-center ${(!showingMore && index >= facet.result_limit) ? 'sqr-hidden' : ''}"> (${filterValue.count})
`).join("") } ${hasMoreValues ? ` ` : ''}
`); } function renderRadioFilter(facet) { const hasMoreValues = facet.values.length > facet.result_limit; const filterState = props.state.datasets[facet.dataset].filterStates?.[facet.id]; const showingMore = filterState.showing_more ?? false; return renderFilter(facet, `
${facet.values.map((filterValue) => `
${filterValue.count}
`).join("")} ${hasMoreValues ? ` ` : ''}
`); } function renderSliderFilter(facet) { return renderFilter( facet, `
` ); } function renderDualSliderFilter(facet) { return renderFilter(facet, `
${facet.use_input ? `
` : `
${facet.prefix ?? ''} ${facet.min} ${facet.suffix ?? ''}
${facet.prefix ?? ''} ${facet.max} ${facet.suffix ?? ''}
`}
`); } function renderFilterLabel(label, prefix, suffix) { const colors = { Antraciet: { color1: "#303030" }, AntiqueBrass: { color1: "#CD9575" }, Ash: { color1: "#B2BEB5" }, Beige: { color1: "#F5F5DC" }, Betongrijs: { color1: "#7F8C8D" }, Blauw: { color1: "#0000FF" }, Blush: { color1: "#FFC0CB" }, Bordeaux: { color1: "#800020" }, Brick: { color1: "#CB4154" }, Bronze: { color1: "#CD7F32" }, Bruin: { color1: "#A52A2A" }, "Bruin/Beige": { color1: "#A52A2A", color2: "#F5F5DC" }, "Bruin/Zwart": { color1: "#A52A2A", color2: "#000000" }, Camel: { color1: "#C19A6B" }, Caramel: { color1: "#FFDDAF" }, Champagne: { color1: "#F7E7CE" }, Charcoal: { color1: "#36454F" }, Chrome: { color1: "#CCCCCC" }, Cinnamon: { color1: "#D2691E" }, Clay: { color1: "#B66A50" }, Cognac: { color1: "#87421F" }, Crème: { color1: "#FFFDD0" }, Donkerblauw: { color1: "#00008B" }, Donkerbruin: { color1: "#654321" }, Donkergrijs: { color1: "#A9A9A9" }, Donkergroen: { color1: "#013220" }, Eiken: { color1: "#DEB887" }, Ecru: { color1: "#C2B280" }, Espresso: { color1: "#613318" }, Geel: { color1: "#FFFF00" }, Gember: { color1: "#D2C295" }, Goud: { color1: "#FFD700" }, Greige: { color1: "#B8A07E" }, Grijs: { color1: "#808080" }, "Grijs/Bruin": { color1: "#808080", color2: "#A52A2A" }, "Grijs/Groen": { color1: "#808080", color2: "#008000" }, Groen: { color1: "#008000" }, "Wit/Eiken": { color1: "#FFFFF", color2: "#DEB887" }, "Groen/Eiken": { color1: "#008000", color2: "#DEB887" }, "Groen/Walnoot": { color1: "#008000", color2: "#774422" }, Ivory: { color1: "#FFFFF0" }, Khaki: { color1: "#C3B091" }, Koper: { color1: "#B87333" }, Lila: { color1: "#C8A2C8" }, Lichtbruin: { color1: "#D2B48C" }, Lichtgrijs: { color1: "#D3D3D3" }, "lichtgroen": { color1: "#98FF98" }, Marmer: { color1: "#FFFFFF" }, Messing: { color1: "#B5A642" }, Mint: { color1: "#98FF98" }, Mosterd: { color1: "#FFDB58" }, Multi: { color1: "#FFFFFF" }, Multikleur: { color1: "#FFFFFF" }, Mushroom: { color1: "#8F7D6B" }, Naturel: { color1: "#FFFFFF" }, Nikkel: { color1: "#727472" }, Nude: { color1: "#E3BC9A" }, Oker: { color1: "#CC7722" }, Okerbruin: { color1: "#CC7722" }, Olijfgroen: { color1: "#808000" }, Oranje: { color1: "#FFA500" }, Patchwork: { color1: "#FFFFFF" }, Paars: { color1: "#800080" }, Petrol: { color1: "#005F6A" }, Pistache: { color1: "#93C572" }, Roest: { color1: "#985F2A" }, Rood: { color1: "#FF0000" }, Roze: { color1: "#FFC0CB" }, ShadowZwart: { color1: "#000000" }, Shiitake: { color1: "#826644" }, Silver: { color1: "#C0C0C0" }, Stone: { color1: "#928E85" }, Tan: { color1: "#D2B48C" }, Taupe: { color1: "#483C32" }, Terra: { color1: "#E2725B" }, Thyme: { color1: "#748B83" }, Transparant: { color1: "#FFFFFF" }, Travertin: { color1: "#FFFFFF" }, Turquoise: { color1: "#40E0D0" }, Vermiljoen: { color1: "#E34234" }, Walnoot: { color1: "#774422" }, WarmBeige: { color1: "#F5F5DC" }, Wit: { color1: "#FFFFFF" }, Zand: { color1: "#C2B280" }, Zilver: { color1: "#C0C0C0" }, Zwart: { color1: "#000000" }, "Zwart/Wit": { color1: "#000000", color2: "#FFFFFF" }, Lood: { color1: "#8D8D8D" }, Smoke: { color1: "#738276" }, "Wit/Naturel": { color1: "#FFFFFF", color2: "#FFFFFF" }, // Adjust color2 if needed "Wit Marmerlook": { color1: "#FFFFFF" }, // Assuming single color representation "Zwart / Goud": { color1: "#000000", color2: "#FFD700" }, "Zwart Marmerlook": { color1: "#FFFFFF", color2: "#000000" }, // Assuming single color representation "Zwart/Brons": { color1: "#000000", color2: "#CD7F32" }, Brass: { color1: "#B5A642" }, Ivoor: { color1: "#FFFFF0" }, Brons: { color1: "#CD7F32" }, "Off White": { color1: "#FAF9F6" }, "Shadow Zwart": { color1: "#000000" }, Nougat: { color1: "#E6B997" }, "Wit/Zwart": { color1: "#FFFFFF", color2: "#000000" }, "Licht beige": { color1: "#F5F5DC" }, "Wit/Groen": { color1: "#FFFFF", color2: "008000" }, Bloemenprint: { color1: "#FFFFFF" }, // Defaulting to white as it's a pattern "Rococo Agave": { color1: "#67A588" }, "Warm beige": { color1: "#F5F5DC" }, "Zwart/Naturel": { color1: "#000000", color2: "#F5F5DC" }, "Wit/Walnoot": { color1: "#FFFFFF", color2: "#774422" }, "Naturel/Zwart": { color1: "#F5F5DC", color2: "#000000" }, "Walnoot/Antraciet": { color1: "#774422", color2: "#303030" }, "Walnoot/Zwart": { color1: "#774422", color2: "#000000" }, "Walnoot/Wit": { color1: "#774422", color2: "#FFFFFF" }, "Zwart/Walnoot": { color1: "#000000", color2: "#774422" }, "Naturel/Rood": { color1: "#F5F5DC", color2: "#FF0000" }, "Naturel/Wit": { color1: "#F5F5DC", color2: "#FFFFFF" }, "Shadow_Zwart": { color1: "#000000" }, "Wit/Goud": { color1: "#FFFFFF", color2: "#FFD700" }, "Zwart Brushed": { color1: "#000000" }, // Assuming a single color, brushed texture "Antique Brass": { color1: "#CD9575" }, "Naturel/Blauw": { color1: "#F5F5DC", color2: "#0000FF" }, "Naturel/Grijs": { color1: "#F5F5DC", color2: "#808080" }, "Naturel_Groen": { color1: "#F5F5DC", color2: "#008000" }, "Stone/Wit": { color1: "#928E85", color2: "#FFFFFF" }, "Walnoot/Geel": { color1: "#774422", color2: "#FFFF00" }, "Wit/Bruin": { color1: "#FFFFFF", color2: "#A52A2A" }, "Wit/Zwart": { color1: "#FFFFFF", color2: "#000000" } }; function getColorValue(colorName) { if (colors.hasOwnProperty(colorName)) { const colorInfo = colors[colorName]; const numColors = Object.keys(colors[colorName]).length; let styleString = `background-color: ${colorInfo.color1};`; let colorClass = 'one-color'; if (numColors === 2) { styleString = `background: linear-gradient(to left, ${colors[colorName].color1}, ${colors[colorName].color2});`; colorClass = 'two-colors'; } return ` ${label} `; } return label; } return `${prefix ?? ''} ${getColorValue(label) || colors[defaultColor]} ${suffix ?? ''}`.trim(); } if (props.state.view === 'items') { return ItemsView(props); } return SuggestView(props); });