import {a as a$3}from'./chunk-KBXWH2TW.js';import {c}from'./chunk-TTPFUFVN.js';import {a}from'./chunk-O5PVNK4O.js';import {a as a$2}from'./chunk-CS7EEHHH.js';import {a as a$1}from'./chunk-SYDG6PPD.js';import {MarginsWithUnit,NumberWithUnit,MeasureUnit,Feedback,Logger}from'@scandit/web-datacapture-core';import {nativeHandle}from'@scandit/web-datacapture-core/build/js/private/nativeHandle.js';var p=class p{constructor(e,a$1,t){this.listener={onValidationFlowLabelCaptured:e=>{},onManualInput:(e,a,t)=>{}};this.stateManager=new c;this.presenter=null;this.onContextUpdatedListenerHandler=this.onContextUpdatedListener.bind(this);this.originalLabelCaptureFeedback=null;this[nativeHandle]=e,this.labelCapture=t,this.settings=a$1,this.feedback_=new a;}static async withLabelCaptureForView(e,a){var u;let t=await a$1().workerCommand("validationFlowOverlayForLabelCapture",{payload:{labelCaptureHandle:e[nativeHandle]}}),l=await a$2.create(),i=new p(t,l,e);return i.dataCaptureView=a,(u=e.context)==null||u.updateListeners.add(i.onContextUpdatedListenerHandler),await a.addOverlay(i),i}async applySettings(e){this.settings=e,await a$1().workerCommand("validationFlowOverlayApplySettings",{payload:{overlayHandle:this[nativeHandle],settingsHandle:e[nativeHandle]}}),this.presenter&&this.presenter.updateSettings(e);}toJSONObject(){return {type:"ValidationFlowOverlay",nativeHandle:this[nativeHandle]}}async onAddOverlay(){var a;this.beforeMountScanArea=(a=this.dataCaptureView.scanAreaMargins)!=null?a:new MarginsWithUnit(new NumberWithUnit(0,MeasureUnit.Pixel),new NumberWithUnit(0,MeasureUnit.Pixel),new NumberWithUnit(0,MeasureUnit.Pixel),new NumberWithUnit(0,MeasureUnit.Pixel)),this.originalLabelCaptureFeedback=this.labelCapture.feedback,this.labelCapture.feedback.success=new Feedback(null,null);let e=await this.labelCapture.validationFlowHandler();this.stateManager=new c,this.presenter=new a$3(this.stateManager,this.settings,e,this.labelCapture,this.feedback_),this.presenter.setExternalListener({onManualInput:(t,l,i)=>this.listener.onManualInput(t,l,i),onValidationFlowLabelCaptured:t=>this.listener.onValidationFlowLabelCaptured(t)}),await this.presenter.mount(this.dataCaptureView),await this.applySettings(this.settings);}async onRemoveOverlay(){var a,t,l,i;this.dataCaptureView&&(this.dataCaptureView.scanAreaMargins=this.beforeMountScanArea),this.originalLabelCaptureFeedback&&(this.labelCapture.feedback=this.originalLabelCaptureFeedback,this.originalLabelCaptureFeedback=null),(t=(a=this.labelCapture)==null?void 0:a.context)==null||t.updateListeners.delete(this.onContextUpdatedListenerHandler),(l=this.presenter)==null||l.setExternalListener({onManualInput:()=>{},onValidationFlowLabelCaptured:()=>{}}),await(await this.labelCapture.validationFlowHandler()).reset(),await this.labelCapture.unsetValidationFlowHandler(),await((i=this.presenter)==null?void 0:i.unmount(this.dataCaptureView)),this.presenter=null;}async onContextUpdatedListener(e){var a;e.type==="removeOverlay"&&e.newValue===this&&await this.onRemoveOverlay(),e.type==="addOverlay"&&e.newValue===this&&(await this.onAddOverlay(),await((a=this.presenter)==null?void 0:a.goToCompleteScan())),e.type==="modeEnabled"&&e.newValue&&this.presenter&&(this.stateManager.isFinished||this.stateManager.isIdle?(Logger.debug("Validation flow overlay: mode enabled and validation flow is finished or idle, going to complete scan"),await this.presenter.goToCompleteScan()):this.stateManager.isPaused&&(Logger.debug("Validation flow overlay: mode enabled and validation flow is paused, resuming scan"),await this.presenter.resumeScan()));}},h=p;export{h as a};