/* Sanmar homepage sections — paste AFTER sanmar-custom.js in Custom JavaScript */
(function(){'use strict';
var CFG={
symbolUrl:'', // optional: URL of your symbol-only logo (PNG/SVG). Empty = uses your header logo
offerDays:3, // promo countdown length in days
wa:'966555792430'
};
var SPRITE=``;
var HTML=`
متجر سنمار الإلكتروني
سنمار .. خيارك الأول في عالم البناء
أدوات صحية ومعدات كهربائية بنوعيها السلكي واللاسلكي ومنتجات ديكور، بجودة تثق بها وتوصيل يصل إليك.
منتجات أصلية توصيل لجميع المناطق دفع آمن ومرن استبدال واسترجاع فروع في الطائف دعم عبر واتساب منتجات أصلية توصيل لجميع المناطق دفع آمن ومرن استبدال واسترجاع فروع في الطائف دعم عبر واتساب
`;
function isHome(){var p=location.pathname.replace(/\/+$/,'');return p===''||/^\/(ar|en)$/i.test(p)||document.body.classList.contains('index')}
function build(){
if(document.querySelector('.sm-home'))return true;
var first=document.querySelector('.s-block, .s-block--fixed-banner, .s-block--products-slider, main .container');
if(!first)return false;
var host=document.createElement('div');host.className='sm-home';host.innerHTML=SPRITE+HTML;
first.parentNode.insertBefore(host,first);
/* anchor so "shop" buttons scroll to Salla's products */
first.id=first.id||'sm-products';
host.querySelectorAll('a[href="#sm-products"]').forEach(function(a){a.addEventListener('click',function(e){e.preventDefault();first.scrollIntoView({behavior:'smooth'})})});
/* category tiles → real store menu links by name */
var links=[].slice.call(document.querySelectorAll('header a[href], .main-menu a[href], .navbar-nav a[href]'));
host.querySelectorAll('.tile').forEach(function(t){var n=(t.textContent||'').trim();
var m=links.filter(function(a){var x=(a.textContent||'').trim();return x&&(n.indexOf(x)>-1||x.indexOf(n)>-1)})[0];
if(m){t.href=m.href;}});
/* symbol image in the hero */
var sym=host.querySelector('.sym');
if(sym){var src=CFG.symbolUrl;if(!src){var lg=document.querySelector('.navbar-brand img, .store-header img, header img');src=lg&&(lg.currentSrc||lg.src)}
if(src){sym.style.background='none';sym.innerHTML='';sym.style.width='260px';sym.style.height='auto'}}
/* counters */
var rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
host.querySelectorAll('[data-count]').forEach(function(el){var end=+el.dataset.count;if(rm){el.textContent=end;return}
var s=performance.now();(function f(n){var p=Math.min((n-s)/1400,1);el.textContent=Math.round(end*(1-Math.pow(1-p,3)));if(p<1)requestAnimationFrame(f)})(s)});
/* tilt */
var tilt=host.querySelector('.sm-tilt');
if(tilt&&!rm){var p=tilt.parentNode;p.addEventListener('mousemove',function(e){var r=p.getBoundingClientRect(),x=(e.clientX-r.left)/r.width-.5,y=(e.clientY-r.top)/r.height-.5;tilt.style.transform='rotateY('+x*14+'deg) rotateX('+-y*14+'deg)'});p.addEventListener('mouseleave',function(){tilt.style.transform=''})}
/* countdown (resets every CFG.offerDays days) */
var KEY='sm_offer_end',end;try{end=+localStorage.getItem(KEY)}catch(e){}
if(!end||end0?y/h:0)+')';
if(header)header.classList.toggle('sm-scrolled',y>10);top.classList.toggle('show',y>600);t=false})}
addEventListener('scroll',onS,{passive:true});onS();
if(!rm&&'IntersectionObserver' in window){
var io=new IntersectionObserver(function(es){es.forEach(function(e){if(e.isIntersecting){e.target.classList.add('in');io.unobserve(e.target)}})},{threshold:.08,rootMargin:'0px 0px -40px 0px'});
document.querySelectorAll('.s-block, .s-block--custom-component').forEach(function(el){
if(el.getBoundingClientRect().top3)im.setAttribute('loading','lazy')});
});})();