import {a as a$2}from'./chunk-7JPCVI74.js';import {a as a$1,b as b$1}from'./chunk-HTKUJZG2.js';import {a}from'./chunk-YWNGCXKZ.js';import {b}from'./chunk-OLJXVUYE.js';import {CameraSettings,convertToPublicFrameData}from'@scandit/web-datacapture-core';import {warnMultithreadingUnavailable}from'@scandit/web-datacapture-core/build/js/private/utils/warnMultithreadingUnavailable.js';var m=class u{constructor(){this.feedback=a.createDefaultFeedback();this.skipSerialization=true;this.type="barcodeFind";this._isEnabled=true;this._context=null;this.listeners=new Set;this.privateListeners=new Set;this.workerMessageListener=this.onWorkerMessage.bind(this);this._transformer=null;}static get recommendedCameraSettings(){let e=new CameraSettings(b.BarcodeFind.CameraSettings.settings);for(let[t,r]of Object.entries(b.BarcodeFind.CameraSettings.hiddenProperties))e.setProperty(t,r);return e}get context(){return this._context}get allListeners(){return [...this.privateListeners,...this.listeners]}static async forSettings(e){warnMultithreadingUnavailable();let t=new u;return t.settings=e,t}isEnabled(){return this._isEnabled}async setEnabled(e){var t;this._isEnabled=e,await this.workerCommand("barcodeFindSetEnabled",{enabled:e}),await((t=this.context)==null?void 0:t.update([{type:"modeEnabled",newValue:e}],{updateContext:false}));}async applySettings(e){this.settings=e,await this.workerCommand("barcodeFindApplySettings",{settings:e.toJSONObject()});}addListener(e){this.listeners.add(e);}removeListener(e){this.listeners.delete(e);}async setItemList(e){var t;for(let r of this.privateListeners)(t=r.onSetItemList)==null||t.call(r,e);return this.workerCommand("barcodeFindSetItemList",{itemList:e.map(r=>r.toJSONObject())})}async setBarcodeTransformer(e){var t;return this._transformer=e,this.workerCommand("barcodeFindSetTransformerFunction",{functionAsString:(t=this._transformer)==null?void 0:t.transformBarcodeData.toString()})}async start(){return this.workerCommand("barcodeFindSearchStart",{})}async stop(){return this.workerCommand("barcodeFindSearchStop",{})}async pause(){return this.workerCommand("barcodeFindSearchPause",{})}toJSONObject(){return {type:this.type,enabled:this.isEnabled(),settings:this.settings.toJSONObject()}}async workerCommand(e,t){this.context!=null&&await this.context.workerCommand(e,t);}async attachedToContext(e){this._context=e,this._context.subscribeToWorkerMessages(this.workerMessageListener),await this.workerCommand("barcodeFindForSettings",{settings:this.settings.toJSONObject()});}async detachedFromContext(){var e;await this.workerCommand("barcodeFindModeRemove",{}),(e=this._context)==null||e.unsubscribeToWorkerMessages(this.workerMessageListener),this._context=null;}async onWorkerMessage(e){var t,r,c;switch(e.type){case "barcodeFindDidUpdateSession":{if(this._context==null)return;for(let a of this.allListeners)(t=a.onDidUpdateSession)==null||t.call(a,this,a$2.fromJSON(e.payload.session),convertToPublicFrameData(e.payload.frameData,this._context));break}case "barcodeFindSearchPaused":{for(let a of this.allListeners){let i=e.payload.foundItems.map(o=>new a$1(new b$1(o),null));a.didPauseSearch(i);}break}case "barcodeFindSearchStarted":{for(let a of this.allListeners)a.didStartSearch();break}case "barcodeFindSearchStopped":{for(let a of this.allListeners){let i=e.payload.foundItems.map(o=>new a$1(new b$1(o),null));a.didStopSearch(i);}break}case "barcodeFindListUpdatedFeedback":{for(let a of this.allListeners)(r=a.onFindListUpdatedFeedback)==null||r.call(a);break}case "barcodeFindFeedback":{for(let a of this.allListeners)(c=a.onFeedback)==null||c.call(a);break}}}addPrivateListener(e){this.privateListeners.add(e);}removePrivateListener(e){this.privateListeners.delete(e);}};export{m as a};