/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import{m as t,a as s,g as i}from"./p-Cc_lzbST.js";import{s as e,w as n}from"./p-FRKLa468.js";import{r,c as o}from"./p-CjG1fMh1.js";import{v as h}from"./p-DsZcVdq8.js";import{m as a}from"./p-Dc9KNUUp.js";import{n as c}from"./p-DxRQdGXU.js";class m{constructor(t,s,i,e){this.model=t;this.client=s;this.jwtProvider=i;this.deviceId=e;this.outcome=Promise.resolve(undefined);this.debugLogs=false}addEntity(s){if(this.debugLogs){const i=t.ModelEntity.deserializeBinary(s.modelEntity);this.log(`Adding ModelEntity. [entityId={${i.getEntityId()}}, sceneItemId={${i.getSceneItemId()}}]`)}return this.performMeasurement((()=>this.model.addEntity(s)))}clearEntities(){this.log("Clearing all ModelEntities.");return this.performMeasurement((()=>{this.model.clearEntities();this.model.clearOutcome();return true}))}removeEntity(s){if(this.debugLogs){const i=t.ModelEntity.deserializeBinary(s.modelEntity);this.log(`Removing ModelEntity. [entityId={${i.getEntityId()}}, sceneItemId={${i.getSceneItemId()}}]`)}return this.performMeasurement((()=>this.model.removeEntity(s)))}setEntities(s){if(this.debugLogs){const i=Array.from(s).map((s=>t.ModelEntity.deserializeBinary(s.modelEntity)));this.log(`Setting ${i.length} ModelEntities. [entityIds=[${i.map((t=>t.getEntityId())).join(", ")}], sceneItemIds=[${i.map((t=>t.getSceneItemId())).join(", ")}]]`)}return this.performMeasurement((()=>this.model.setEntities(s)))}setDebugLogs(t){this.debugLogs=t}performMeasurement(t){const s=this.model.getEntities();const i=t();const e=this.model.getEntities();if(i){this.measureAndUpdateModel(e);this.highlightEntities(s,e)}return this.outcome}measureAndUpdateModel(t){if(t.length>0){this.outcome=this.measureEntities(t).then((t=>{this.model.setOutcome(t);return this.model.getOutcome()}))}else{this.outcome=Promise.resolve(undefined)}}async measureEntities(t){if(t.length>0){const i=await r((async s=>{const i=await o(this.jwtProvider,this.deviceId);const n=new e.MeasureRequest;n.setEntitiesList(t.map((t=>t.toProto())));this.client.measure(n,i,s)}));return s(i.toObject())}else{return undefined}}async highlightEntities(s,i){await r((async r=>{const h=await o(this.jwtProvider,this.deviceId);const a=new Set(i);const c=s.filter((t=>!a.has(t)));const m=c.map((s=>{const i=new e.ModelEntityUpdate;i.setModelEntity(t.ModelEntity.deserializeBinary(s.modelEntity));i.setHighlight((new n.BoolValue).setValue(false));return i}));const d=i.map((s=>{const i=new e.ModelEntityUpdate;i.setModelEntity(t.ModelEntity.deserializeBinary(s.modelEntity));i.setHighlight((new n.BoolValue).setValue(true));return i}));const u=new e.UpdateModelEntitiesRequest;u.setUpdatesList([...m,...d]);this.client.updateModelEntities(u,h,r)}))}log(t,...s){if(this.debugLogs){console.debug(t,s)}}}class d{constructor(t,s){this.point=t;this.modelEntity=s}static fromHit(t){if(t.hitPoint!=null&&t.modelEntity!=null){const s=a.ifInvalidThrow(c)(t.hitPoint);const i=h.protobuf.core.ModelEntity.encode(t.modelEntity).finish();return new d(s,i)}else{throw new Error("Cannot create MeasurementEntity from Hit. Hit is missing hit point and model entity")}}toProto(){const s=new e.MeasureEntity;const n=new i.Vector3f;n.setX(this.point.x);n.setY(this.point.y);n.setZ(this.point.z);s.setPoint(n);const r=t.ModelEntity.deserializeBinary(this.modelEntity);s.setModelEntity(r);return s}}export{m as M,d as a};
//# sourceMappingURL=p-CEqRAyUS.js.map