import {a as a$1}from'./chunk-2K4IDUBI.js';import {a}from'./chunk-SYDG6PPD.js';import {PointWithUnit,NumberWithUnit,MeasureUnit,Anchor}from'@scandit/web-datacapture-core';import {nativeHandle}from'@scandit/web-datacapture-core/build/js/private/nativeHandle.js';var m=class m{constructor(e){this.onWorkerMessageHandler=this.onWorkerMessage.bind(this);this.defaultOffset=new PointWithUnit(new NumberWithUnit(0,MeasureUnit.Pixel),new NumberWithUnit(0,MeasureUnit.Pixel));this._viewForCapturedLabelMap=new Map;this._viewForCapturedLabelFieldMap=new Map;this._anchorForCapturedLabelMap=new Map;this._offsetForCapturedLabelMap=new Map;this._offsetForCapturedLabelFieldMap=new Map;this._anchorForCapturedLabelFieldMap=new Map;this.listener=null;this[nativeHandle]=e;}static async withLabelCaptureForView(e,a$1){let t=await a().workerCommand("labelCaptureAdvancedOverlayForLabelCapture",{payload:{labelCaptureHandle:e[nativeHandle]}}),i=new m(t);return i._dataCaptureView=a$1,await a$1.addOverlay(i),a().addWorkerListener(i.onWorkerMessageHandler),i}keyForCapturedLabelField(e,a){return `${e.trackingId}-${e.name}-${a.name}`}async setShouldShowScanAreaGuides(e){return await a().workerCommand("labelCaptureAdvancedOverlaySetShouldShowScanAreaGuides",{payload:{labelCaptureAdvancedOverlayHandle:this[nativeHandle],show:e}})}async getShouldShowScanAreaGuides(){return await a().workerCommand("labelCaptureAdvancedOverlayGetShouldShowScanAreaGuides",{payload:{labelCaptureAdvancedOverlayHandle:this[nativeHandle]}})}setViewForCapturedLabel(e,a){if(a==null){this._viewForCapturedLabelMap.set(e.name,null);return}this._viewForCapturedLabelMap.has(e.name)||this._viewForCapturedLabelMap.set(e.name,a);}setAnchorForCapturedLabel(e,a){this._anchorForCapturedLabelMap.set(e.name,a);}setOffsetForCapturedLabel(e,a){this._offsetForCapturedLabelMap.set(e.name,a);}setViewForCapturedLabelField(e,a,t){let i=this.keyForCapturedLabelField(a,e);if(t==null){this._viewForCapturedLabelFieldMap.set(i,null);return}this._viewForCapturedLabelFieldMap.has(i)||this._viewForCapturedLabelFieldMap.set(i,t);}setAnchorForCapturedLabelField(e,a,t){this._anchorForCapturedLabelFieldMap.set(this.keyForCapturedLabelField(a,e),t);}setOffsetForCapturedLabelField(e,a,t){this._offsetForCapturedLabelFieldMap.set(this.keyForCapturedLabelField(a,e),t);}clearCapturedLabelViews(){this._viewForCapturedLabelMap.clear(),this._viewForCapturedLabelFieldMap.clear(),this._dataCaptureView.renderCustomLocationsView({elements:[]});}onWorkerMessage(e){e.type==="labelCaptureOnSessionUpdated"&&this.update(a$1.fromJSON(e.payload.session));}handleUpdateField(e){var t,i,u,o,b,h,n,C;let a=[];for(let r of e.fields){let l=this.keyForCapturedLabelField(e,r),p=(u=this._viewForCapturedLabelFieldMap.get(l))!=null?u:(i=(t=this.listener)==null?void 0:t.viewForCapturedLabelField)==null?void 0:i.call(t,this,r),s=(h=this._anchorForCapturedLabelFieldMap.get(l))!=null?h:(b=(o=this.listener)==null?void 0:o.anchorForCapturedLabelField)==null?void 0:b.call(o,this,r),L=this._offsetForCapturedLabelFieldMap.get(l);L==null&&p!=null&&(L=(C=(n=this.listener)==null?void 0:n.offsetForCapturedLabelField)==null?void 0:C.call(n,this,r,p)),a.push({identifier:l,anchorPositions:r.anchorPositions,view:p!=null?p:null,anchor:s!=null?s:Anchor.BottomCenter,offset:L!=null?L:this.defaultOffset});}return a}update(e){var t,i,u,o,b,h,n,C;let a=[];for(let r of e.capturedLabels){let l=(u=this._viewForCapturedLabelMap.get(r.name))!=null?u:(i=(t=this.listener)==null?void 0:t.viewForCapturedLabel)==null?void 0:i.call(t,this,r),p=(h=this._anchorForCapturedLabelMap.get(r.name))!=null?h:(b=(o=this.listener)==null?void 0:o.anchorForCapturedLabel)==null?void 0:b.call(o,this,r),s=this._offsetForCapturedLabelMap.get(r.name);s==null&&l!=null&&(s=(C=(n=this.listener)==null?void 0:n.offsetForCapturedLabel)==null?void 0:C.call(n,this,r,l)),r.fields.length>0&&a.push({identifier:`${r.trackingId}-${r.name}`,anchorPositions:r.fields[0].anchorPositions,view:l!=null?l:null,anchor:p!=null?p:Anchor.BottomCenter,offset:s!=null?s:this.defaultOffset}),a.push(...this.handleUpdateField(r));}this._dataCaptureView.renderCustomLocationsView({elements:a});}toJSONObject(){return {type:this[nativeHandle].className,nativeHandle:this[nativeHandle]}}},M=m;export{M as a};