import {a as a$1}from'./chunk-CHBH6UKJ.js';import {a}from'./chunk-SYDG6PPD.js';import {NotificationConfiguration,FrameSourceState}from'@scandit/web-datacapture-core';import {nativeHandle}from'@scandit/web-datacapture-core/build/js/private/nativeHandle.js';var c=class c{constructor(e,t){this.listener=null;this.labelCapture=null;this.receiptScanningHandler=null;this.dataCaptureView=null;this.overlayElement=null;this.onContextUpdatedListenerHandler=this.onContextUpdatedListener.bind(this);this.handlerListener={onProcessingStarted:this.onProcessingStarted.bind(this),onReceiptScanned:this.onReceiptScanned.bind(this),onReceiptScanningFailed:this.onReceiptScanningFailed.bind(this)};this.failedNotificationConfiguration=new NotificationConfiguration("A failure occurred","AdaptiveRecognitionOverlayError");this._isProcessing=false;this[nativeHandle]=e,this.labelCapture=t;}toJSONObject(){return {type:"AdaptiveRecognitionOverlay",nativeHandle:this[nativeHandle]}}static async withLabelCaptureForView(e,t){var n,o;let a$1=await a().workerCommand("receiptScanningOverlayForLabelCapture",{payload:{labelCaptureHandle:e[nativeHandle]}}),i=new c(a$1,e);return i.receiptScanningHandler=await e.receiptScanningHandler(),(n=i.receiptScanningHandler)==null||n.addListener(i.handlerListener),(o=e.context)==null||o.updateListeners.add(i.onContextUpdatedListenerHandler),t&&await t.addOverlay(i),i}async onProcessingStarted(){var e,t,a,i,n;this._isProcessing||((t=(e=this.dataCaptureView)==null?void 0:e.getNotificationPresenter())==null||t.hideNotification(this.failedNotificationConfiguration),this.showProcessingAnimation(),this._isProcessing=true,await((n=(i=(a=this.labelCapture)==null?void 0:a.context)==null?void 0:i.frameSource)==null?void 0:n.switchToDesiredState(FrameSourceState.Standby)));}async onReceiptScanned(e){var t,a;this.hideProcessingAnimation(),(a=(t=this.listener)==null?void 0:t.onRecognized)==null||a.call(t,e),this._isProcessing=false;}async onReceiptScanningFailed(){var e,t,a,i,n,o,d,s,u;this.hideProcessingAnimation(),(t=(e=this.listener)==null?void 0:e.onFailure)==null||t.call(e),this._isProcessing=false,await((i=(a=this.dataCaptureView)==null?void 0:a.getNotificationPresenter())==null?void 0:i.showNotification(this.failedNotificationConfiguration)),await((n=this.labelCapture)==null?void 0:n.setEnabled(true)),await((u=(s=(d=(o=this.labelCapture)==null?void 0:o.context)==null?void 0:d.frameSource)==null?void 0:s.switchToDesiredState)==null?void 0:u.call(s,FrameSourceState.On));}async applySettings(e){await a().workerCommand("receiptScanningOverlayApplySettings",{payload:{overlayHandle:this[nativeHandle],settingsHandle:e[nativeHandle]}});}async mount(e){this.dataCaptureView=e,this.setupUI();}unmount(){var e,t,a,i;(e=this.receiptScanningHandler)==null||e.removeListener(this.handlerListener),(a=(t=this.labelCapture)==null?void 0:t.context)==null||a.updateListeners.delete(this.onContextUpdatedListenerHandler),(i=this.overlayElement)==null||i.remove(),this.overlayElement=null,this.dataCaptureView=null,this.labelCapture=null,this.receiptScanningHandler=null,this._isProcessing=false;}async onContextUpdatedListener(e){var t;e.type==="removeOverlay"&&e.newValue===this&&this.unmount(),e.type==="addOverlay"&&e.newValue===this&&(this.mount(e.view),await((t=this.receiptScanningHandler)==null?void 0:t.startFlow()));}setupUI(){if(!this.dataCaptureView)return;a$1.register();let e=a$1.create();e.show=false,this.overlayElement=e;let t=this.dataCaptureView.htmlElement;t&&t.prepend(this.overlayElement);}showProcessingAnimation(){this.overlayElement&&!this.overlayElement.show&&!this._isProcessing&&(this.overlayElement.show=true);}hideProcessingAnimation(){var e;(e=this.overlayElement)!=null&&e.show&&this._isProcessing&&(this.overlayElement.show=false);}},h=c;export{h as a};