document.addEventListener('DOMContentLoaded',()=>{const menu=document.querySelector('.filter-menu');if(!menu)return;menu.addEventListener('wheel',function(e){if(this.scrollWidth>this.clientWidth&&Math.abs(e.deltaY)>Math.abs(e.deltaX)){e.preventDefault();this.scrollLeft-=e.deltaY}},{passive:!1})});document.addEventListener('DOMContentLoaded',()=>{const searchInput=document.querySelector('.search-section input[type="search"]');const cards=document.querySelectorAll('.products-section .product-card');if(!searchInput||!cards.length)return;searchInput.addEventListener('input',function(){const v=this.value.trim().toLowerCase();cards.forEach(card=>{const title=card.querySelector(".name-phrase")?.textContent.toLowerCase()||"";const caption=card.querySelector(".caption-phrase")?.textContent.toLowerCase()||"";card.style.display=(title.includes(v)||caption.includes(v))?"":"none"})})});document.addEventListener('DOMContentLoaded',()=>{const form=document.querySelector('.search-section form');const button=document.querySelector('.search-section-button');const target=document.querySelector('#products');if(!form||!button||!target)return;const STICKY_HEADER_OFFSET=40;function scrollToTarget(){const top=target.getBoundingClientRect().top+window.pageYOffset-STICKY_HEADER_OFFSET;window.scrollTo({top,behavior:'smooth'})}
    form.addEventListener('submit',(e)=>{e.preventDefault();scrollToTarget()});button.addEventListener('click',(e)=>{e.preventDefault();scrollToTarget()})});document.addEventListener('click',(e)=>{const btn=e.target.closest('.filter-menu .filter-btn');if(!btn)return;const menu=btn.closest('.filter-menu');if(!menu)return;menu.querySelectorAll('.filter-btn').forEach(b=>b.classList.remove('active'));btn.classList.add('active');const key=String(btn.dataset.filter||'').trim();const cards=document.querySelectorAll('.products-section .product-card');if(!cards.length)return;if(!key||key==='all'){cards.forEach(c=>c.style.display='');return}
    cards.forEach(card=>{const cats=(card.getAttribute('data-cats')||'').split(/\s+/).filter(Boolean);card.style.display=cats.includes(key)?'':'none'})});function initSliderForPopup(popup){if(!popup)return;const sliderThumb=popup.querySelector('#sliderThumb');const sliderTrack=popup.querySelector('#sliderTrack');const valueDisplay=popup.querySelector('#valueDisplay');const priceValueEl=popup.querySelector('.slider-container-price-price');const priceSignEl=popup.querySelector('.slider-container-price-plus');if(!sliderThumb||!sliderTrack||!valueDisplay)return;const snapPoints=[0,30,50,70,100];const displayValues={"0":"۱۰۰/۰","30":"۷۰/۳۰","50":"۵۰/۵۰","70":"۳۰/۷۰","100":"۰/۱۰۰"};let isDragging=!1;function updateValueDisplay(percentage){let closest=snapPoints.reduce((p,c)=>Math.abs(c-percentage)<Math.abs(p-percentage)?c:p);valueDisplay.textContent=displayValues[String(closest)]||'';const pointEl=sliderTrack.querySelector('.point-'+String(closest));if(pointEl){const sign=pointEl.getAttribute('data-name')??'';const price=pointEl.getAttribute('data-price')??'';if(priceValueEl)priceValueEl.textContent=price;if(priceSignEl)priceSignEl.textContent=sign}
    const rect=sliderTrack.getBoundingClientRect();const leftPx=(percentage/100)*rect.width;valueDisplay.style.left=`${leftPx + sliderThumb.offsetWidth / (window.innerWidth < 500 ? 0.625 : 1.25)}px`;valueDisplay.style.opacity=1}
    function updateThumbPosition(percentage){sliderThumb.style.left=`${percentage}%`;updateValueDisplay(percentage)}
    function handleMouseDown(){isDragging=!0;sliderThumb.style.transition='none';valueDisplay.style.opacity=1;document.addEventListener('mousemove',handleMouseMove);document.addEventListener('mouseup',handleMouseUp)}
    function handleMouseMove(e){if(!isDragging)return;const rect=sliderTrack.getBoundingClientRect();let percentage=((e.clientX-rect.left)/rect.width)*100;percentage=Math.max(0,Math.min(100,percentage));updateThumbPosition(percentage)}
    function handleMouseUp(){isDragging=!1;sliderThumb.style.transition='left 0.2s ease-out';const currentLeft=parseFloat(sliderThumb.style.left)||50;let closest=snapPoints.reduce((p,c)=>Math.abs(c-currentLeft)<Math.abs(p-currentLeft)?c:p);updateThumbPosition(closest);document.removeEventListener('mousemove',handleMouseMove);document.removeEventListener('mouseup',handleMouseUp)}
    function clickTrack(e){const rect=sliderTrack.getBoundingClientRect();let percentage=((e.clientX-rect.left)/rect.width)*100;percentage=Math.max(0,Math.min(100,percentage));let closest=snapPoints.reduce((p,c)=>Math.abs(c-percentage)<Math.abs(p-percentage)?c:p);updateThumbPosition(closest)}
    sliderThumb.removeEventListener('mousedown',handleMouseDown);sliderThumb.addEventListener('mousedown',handleMouseDown);sliderTrack.addEventListener('click',clickTrack);updateThumbPosition(50)}
function openPopup(popupId){const popup=document.getElementById(popupId);if(!popup)return;popup.classList.add('active');document.body.style.overflow='hidden';setTimeout(()=>initSliderForPopup(popup),50)}
function closePopup(popupId){const popup=document.getElementById(popupId);if(!popup)return;popup.classList.remove('active');document.body.style.overflow='auto'}
document.addEventListener('click',(e)=>{const btn=e.target.closest('.product-card-button');if(!btn||btn.disabled)return;const id=btn.getAttribute('data-popup-id');if(id)openPopup(id);});document.addEventListener('click',(event)=>{const popups=document.querySelectorAll('.popup.active');popups.forEach(popup=>{if(popup.contains(event.target)&&!event.target.closest('.popup-container')){closePopup(popup.id)}})});document.addEventListener('click',(event)=>{const closeBtn=event.target.closest('.close-btn');if(!closeBtn)return;const popup=closeBtn.closest('.popup');if(popup)closePopup(popup.id);});document.addEventListener('DOMContentLoaded',()=>{document.querySelectorAll('.product-card.outsell .product-card-button').forEach(b=>{b.disabled=!0;b.setAttribute('aria-disabled','true')})});document.addEventListener("DOMContentLoaded",function(){const mapEl=document.getElementById('map');if(!mapEl||typeof L==='undefined')return;var lat=37.271554,lng=49.571069;var map=L.map("map",{gestureHandling:!0}).setView([lat,lng],15);L.tileLayer("https://{s}.tile.jawg.io/jawg-dark/{z}/{x}/{y}.png?access-token=Ag8z1KOzczrJCjwDL5jIdBA8AU0S0Su6VjIrb6ovYxKltbKwhpBqq9JlFKpa5HU8",{attribution:'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(map);var customIcon=L.divIcon({className:"leaflet-div-icon",html:'<i class="ph-fill ph-map-pin" style="font-size: 32px; color: red;"></i>',iconSize:[32,32],iconAnchor:[16,32],popupAnchor:[0,-32],});var marker=L.marker([lat,lng],{icon:customIcon}).addTo(map);marker.bindPopup("کافیتو اینجاست").openPopup();if(window.innerWidth<=660){map.dragging.disable();map.scrollWheelZoom.disable();map.on("touchstart",function(e){if(e.touches&&e.touches.length===2){map.dragging.enable();map.scrollWheelZoom.enable()}});map.on("touchend",function(e){if(!e.touches||e.touches.length<2){map.dragging.disable();map.scrollWheelZoom.disable()}})}});(function($){if(!$)return;function initOnce($ctx,selector,opts){if(typeof $.fn.owlCarousel==='undefined')return;$ctx.find(selector).each(function(){var $el=$(this);if($el.hasClass('owl-loaded'))return;$el.owlCarousel(opts||{rtl:!0,loop:!1,margin:20,nav:!0,dots:!1,responsive:{0:{items:1},700:{items:2},992:{items:3},1200:{items:4}}})})}
    $(window).on('elementor/frontend/init',function(){elementorFrontend.hooks.addAction('frontend/element_ready/BaristaChoiceW.default',function($scope){initOnce($scope,'.owl-carousel-bestseller',{rtl:!0,loop:!1,margin:20,nav:!0,dots:!1,responsive:{0:{items:1},700:{items:2}}})});elementorFrontend.hooks.addAction('frontend/element_ready/ServicessectionW.default',function($scope){initOnce($scope,'.owl-carousel-services')})});$(function(){initOnce($(document),'.owl-carousel-bestseller',{rtl:!0,loop:!1,margin:20,nav:!0,dots:!1,responsive:{0:{items:1},700:{items:2}}});initOnce($(document),'.owl-carousel-services')})})(window.jQuery);function initSliderForPopup(popup){if(!popup)return;const sliderThumb=popup.querySelector('#sliderThumb');const sliderTrack=popup.querySelector('#sliderTrack');const valueDisplay=popup.querySelector('#valueDisplay');const priceValueEl=popup.querySelector('.slider-container-price-price');const priceSignEl=popup.querySelector('.slider-container-price-plus');if(!sliderThumb||!sliderTrack||!valueDisplay)return;const snapPoints=[0,30,50,70,100];const displayValues={"0":"۱۰۰/۰","30":"۷۰/۳۰","50":"۵۰/۵۰","70":"۳۰/۷۰","100":"۰/۱۰۰"};let isDragging=!1;function updateValueDisplay(percentage){let closest=snapPoints.reduce((p,c)=>Math.abs(c-percentage)<Math.abs(p-percentage)?c:p);valueDisplay.textContent=displayValues[String(closest)]||'';const pointEl=sliderTrack.querySelector('.point-'+String(closest));if(pointEl){const sign=pointEl.getAttribute('data-name')??'';const price=pointEl.getAttribute('data-price')??'';if(priceValueEl)priceValueEl.textContent=price;if(priceSignEl)priceSignEl.textContent=sign}
    const rect=sliderTrack.getBoundingClientRect();const leftPx=(percentage/100)*rect.width;valueDisplay.style.left=`${leftPx + sliderThumb.offsetWidth / (window.innerWidth < 500 ? 0.625 : 1.25)}px`;valueDisplay.style.opacity=1}
    function updateThumbPosition(percentage){sliderThumb.style.left=`${percentage}%`;updateValueDisplay(percentage)}
    function getClientX(event){return event.type.startsWith('touch')?event.touches[0].clientX:event.clientX}
    function handleStart(event){event.preventDefault();isDragging=!0;sliderThumb.style.transition='none';valueDisplay.style.opacity=1;document.addEventListener('mousemove',handleMove);document.addEventListener('mouseup',handleEnd);document.addEventListener('touchmove',handleMove,{passive:!1});document.addEventListener('touchend',handleEnd)}
    function handleMove(event){if(!isDragging)return;event.preventDefault();const rect=sliderTrack.getBoundingClientRect();let percentage=((getClientX(event)-rect.left)/rect.width)*100;percentage=Math.max(0,Math.min(100,percentage));updateThumbPosition(percentage)}
    function handleEnd(){isDragging=!1;sliderThumb.style.transition='left 0.2s ease-out';const currentLeft=parseFloat(sliderThumb.style.left)||50;let closest=snapPoints.reduce((p,c)=>Math.abs(c-currentLeft)<Math.abs(p-currentLeft)?c:p);updateThumbPosition(closest);document.removeEventListener('mousemove',handleMove);document.removeEventListener('mouseup',handleEnd);document.removeEventListener('touchmove',handleMove);document.removeEventListener('touchend',handleEnd)}
    function clickTrack(event){const rect=sliderTrack.getBoundingClientRect();let percentage=((getClientX(event)-rect.left)/rect.width)*100;percentage=Math.max(0,Math.min(100,percentage));let closest=snapPoints.reduce((p,c)=>Math.abs(c-percentage)<Math.abs(p-currentLeft)?c:p);updateThumbPosition(closest)}
    sliderThumb.removeEventListener('mousedown',handleStart);sliderThumb.removeEventListener('touchstart',handleStart);sliderTrack.removeEventListener('click',clickTrack);sliderTrack.removeEventListener('touchstart',clickTrack);sliderThumb.addEventListener('mousedown',handleStart);sliderThumb.addEventListener('touchstart',handleStart,{passive:!1});sliderTrack.addEventListener('click',clickTrack);sliderTrack.addEventListener('touchstart',clickTrack,{passive:!1});updateThumbPosition(50)}(function($){"use strict";var LABEL_PREV="اسلاید قبلی";var LABEL_NEXT="اسلاید بعدی";var NAV_GROUP_LABEL="ناوبری اسلایدر";function ensureId($el){if(!$el.attr("id")){$el.attr("id","owl-"+Math.random().toString(36).slice(2,9))}
    return $el.attr("id")}
    function syncDisabledState($btn){$btn.attr("aria-disabled",$btn.hasClass("disabled")?"true":"false")}
    function enhanceOwlA11y(event){var $carousel=$(event.target);var $nav=$carousel.find(".owl-nav");if(!$nav.length)return;var cid=ensureId($carousel);$nav.attr({"role":"group","aria-label":NAV_GROUP_LABEL});var $prev=$nav.find(".owl-prev");var $next=$nav.find(".owl-next");$prev.removeAttr("role");$next.removeAttr("role");$prev.attr({"type":"button","aria-label":LABEL_PREV,"aria-controls":cid});$next.attr({"type":"button","aria-label":LABEL_NEXT,"aria-controls":cid});syncDisabledState($prev);syncDisabledState($next)}
    $(document).on("initialized.owl.carousel",enhanceOwlA11y).on("refreshed.owl.carousel",enhanceOwlA11y).on("changed.owl.carousel",function(event){var $owl=$(event.target);var $nav=$owl.find(".owl-nav");if(!$nav.length)return;syncDisabledState($nav.find(".owl-prev"));syncDisabledState($nav.find(".owl-next"))});$(function(){$(".owl-carousel").each(function(){var $el=$(this);if($el.data("owl.carousel")){$el.trigger("refresh.owl.carousel")}})})})(jQuery)