import{Ar as e,Kn as t,_n as n,fn as r,kr as i}from"./three@0.169.19.js";import{$i as a,Xi as o,ct as s,eo as c,ot as l}from"./needle-engine-ui.B3WhUziG.js";import"./needle-engine@5.0.3.js";import{m as u}from"./needle-engine-webxr.XIy9opUR.js";import{m as d,t as f}from"./needle-engine.extras.BWlo-D5V.js";var p=class extends l{raycaster=new t;touchPos=new i;plane=new n(new e(0,1,0),0);initialPinchDistance=0;initialScale=new e;isScaling=!1;onEnable(){let e=this.context.renderer.domElement;e.addEventListener(`touchstart`,this.onTouchStart),e.addEventListener(`touchmove`,this.onTouchMove),e.addEventListener(`touchend`,this.onTouchEnd)}onDisable(){let e=this.context.renderer.domElement;e.removeEventListener(`touchstart`,this.onTouchStart),e.removeEventListener(`touchmove`,this.onTouchMove),e.removeEventListener(`touchend`,this.onTouchEnd)}onTouchStart=e=>{if(e.touches.length===2){this.isScaling=!0;let t=e.touches[0],n=e.touches[1];this.initialPinchDistance=Math.hypot(n.clientX-t.clientX,n.clientY-t.clientY),this.initialScale.copy(this.gameObject.scale)}};onTouchMove=t=>{if(t.preventDefault(),this.isScaling&&t.touches.length===2){let e=t.touches[0],n=t.touches[1],r=Math.hypot(n.clientX-e.clientX,n.clientY-e.clientY)/this.initialPinchDistance,i=this.initialScale.clone().multiplyScalar(r);this.gameObject.scale.copy(i)}else if(t.touches.length===1&&!this.isScaling){let n=t.touches[0],r=this.context.renderer.domElement.getBoundingClientRect();this.touchPos.set((n.clientX-r.left)/r.width*2-1,-((n.clientY-r.top)/r.height)*2+1),this.raycaster.setFromCamera(this.touchPos,this.context.mainCamera);let i=new e;this.raycaster.ray.intersectPlane(this.plane,i)&&this.gameObject.position.copy(i)}};onTouchEnd=e=>{e.touches.length<2&&(this.isScaling=!1)}};function m(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var h=new WeakMap,g=class extends l{isMobile=!1;isDesktop=!1;isXR=!1;dishName=``;dishes=[];webXROrigin;dishBobAmplitude=.05;dishBobSpeed=2.5;usdzExporter;arSessionBobPaused=!1;selectedDishIndex=0;onEnable(){if(this.dishName=new URLSearchParams(window.location.search).get(`dishName`)??``,this.webXROrigin&&(this.usdzExporter=this.webXROrigin.getComponent(u)??void 0),this.dishName){let e=!1;this.dishes.forEach((t,n)=>{t&&t.name===this.dishName&&(this.selectedDishIndex=n,e=!0)}),this.dishes.forEach(t=>{if(!t)return;let n=e&&t.name===this.dishName;n||this.restoreDishBaseY(t),s.setActive(t,n)}),e||this.ensureOnlySelectedDishVisible()}else this.ensureOnlySelectedDishVisible();this.updateUSDZExporterTarget(),this.checkForDeviceType().then(()=>{this.isMobile?console.log(`[MenuController] isMobile`):this.isDesktop?this.setupDesktopControls():this.isXR}),this.setupMobileControls(),this.disableDoubleTapZoom()}onEnterXR(e){e.xr.mode===`immersive-ar`&&(this.arSessionBobPaused=!0,this.snapActiveDishToBaseY())}onLeaveXR(e){this.arSessionBobPaused=!1}update(){if(this.arSessionBobPaused||this.dishBobAmplitude<=0||this.getValidDishIndices().length===0)return;let e=this.dishes[this.selectedDishIndex];if(!e)return;let t=h.get(e);t===void 0&&(t=e.position.y,h.set(e,t));let n=this.context.time.time;e.position.y=t+Math.sin(n*this.dishBobSpeed)*this.dishBobAmplitude}async checkForDeviceType(){await this.isXRDevice()?this.isXR=!0:(console.log(`DeviceUtilities.isMobileDevice()`,c.isMobileDevice()),this.isMobile=c.isMobileDevice(),this.isMobile||(this.isDesktop=c.isDesktop()))}async isXRDevice(){if(navigator.xr)try{return await navigator.xr.isSessionSupported(`immersive-vr`)}catch{return console.log(`XR check error!`),!1}return!1}setupMobileControls(){typeof document<`u`&&document.querySelector(`#asset-picker`)||this.createMenuMobileControls()}setupDesktopControls(){}createMenuMobileControls(){let e=document.createElement(`div`);e.id=`menuControlsZone`,e.style.cssText=`
            position: absolute;
            display: flex;
            justify-content: space-between;
            bottom: 10%;
            left: 10%;
            right: 10%;
            height: 150px;
        `,document.body.appendChild(e);let t=document.createElement(`button`);t.id=`previousButton`,t.style.cssText=`
            height: 100px;
            width: 100px;
            background-color: #ffffff;
            color: #111111;
            border: none;
            border-radius: 50px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.25);
            display: flex;
            align-items: center;
            justify-content: center;
            touch-action: manipulation;
        `,t.setAttribute(`aria-label`,`Previous`),t.innerHTML=`
            <svg width="40" height="40" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M15 18L9 12L15 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
            </svg>
        `,t.onclick=this.selectPreviousDish.bind(this);let n=document.createElement(`button`);n.id=`nextButton`,n.style.cssText=`
            height: 100px;
            width: 100px;
            background-color: #ffffff;
            color: #111111;
            border: none;
            border-radius: 50px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.25);
            display: flex;
            align-items: center;
            justify-content: center;
            touch-action: manipulation;
        `,n.setAttribute(`aria-label`,`Next`),n.innerHTML=`
            <svg width="40" height="40" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M9 6L15 12L9 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
            </svg>
        `,n.onclick=this.selectNextDish.bind(this),this.dishName&&(t.disabled=!0,t.style.display=`none`,n.disabled=!0,n.style.display=`none`),e.appendChild(t),e.appendChild(n)}disableDoubleTapZoom(){let e=0;document.addEventListener(`touchend`,t=>{let n=Date.now();n-e<=300&&t.preventDefault(),e=n},{passive:!1})}getValidDishIndices(){return this.dishes.map((e,t)=>e==null?-1:t).filter(e=>e>=0)}ensureOnlySelectedDishVisible(){let e=this.getValidDishIndices();if(e.length===0)return;let t=this.selectedDishIndex;e.indexOf(t)<0&&(t=e[0],this.selectedDishIndex=t),e.forEach(e=>{let t=e===this.selectedDishIndex,n=this.dishes[e];t||this.restoreDishBaseY(n),s.setActive(this.dishes[e],t)})}restoreDishBaseY(e){if(!e)return;let t=h.get(e);t!==void 0&&(e.position.y=t)}snapActiveDishToBaseY(){this.restoreDishBaseY(this.dishes[this.selectedDishIndex])}getDishSlotCount(){return this.getValidDishIndices().length}getPickerLabel(){let e=this.getValidDishIndices();if(e.length===0)return`Menu`;let t=Math.max(0,e.indexOf(this.selectedDishIndex)),n=this.dishes[this.selectedDishIndex]?.name?.trim();return n?`${n} (${t+1}/${e.length})`:`Dish ${t+1} / ${e.length}`}selectPreviousDish(){let e=this.getValidDishIndices();if(e.length===0)return;let t=e.indexOf(this.selectedDishIndex);t<0&&(t=0),this.restoreDishBaseY(this.dishes[e[t]]),s.setActive(this.dishes[e[t]],!1),t=(t-1+e.length)%e.length,this.selectedDishIndex=e[t],s.setActive(this.dishes[this.selectedDishIndex],!0),this.updateUSDZExporterTarget()}selectNextDish(){let e=this.getValidDishIndices();if(e.length===0)return;let t=e.indexOf(this.selectedDishIndex);t<0&&(t=0),this.restoreDishBaseY(this.dishes[e[t]]),s.setActive(this.dishes[e[t]],!1),t=(t+1)%e.length,this.selectedDishIndex=e[t],s.setActive(this.dishes[this.selectedDishIndex],!0),this.updateUSDZExporterTarget()}updateUSDZExporterTarget(){let e=this.dishes[this.selectedDishIndex];this.usdzExporter&&e&&(this.usdzExporter.objectToExport=e)}getUrlParameter(e){return new URLSearchParams(window.location.search).get(e)}};m([o(r)],g.prototype,`dishes`,void 0),m([o(r)],g.prototype,`webXROrigin`,void 0),m([o()],g.prototype,`dishBobAmplitude`,void 0),m([o()],g.prototype,`dishBobSpeed`,void 0);var _=class extends l{volume;start(){if(!this.volume){console.warn(`No PostProcessVolume assigned`);return}this.volume.addEffect(new d({intensity:3,luminanceThreshold:.2}))}};m([o(f)],_.prototype,`volume`,void 0),a.add(`ARObjectController`,p),a.add(`MenuController`,g),a.add(`PostProcessingVolumeController`,_);