import{r as t,g as i,h as s}from"./p-BIwHMk6j.js";import{g as e}from"./p-CI7dwT4T.js";import{f as h}from"./p-B95D7tDb.js";import{j as o,b as a}from"./p-D5qhls4G.js";const r=o("object-resolver");class l{constructor(t){this.onStateChange=t,this.state={loadFailed:!1},this.hasPendingLoad=!1,this.isDisconnected=!1}get resolvedPlatform(){return this._platform}connect(t,i,s,e){this.limetype=t,this.objectid=i,this.isDisconnected=!1,this.hasPendingLoad=!1,this._platform=e||this.findPlatform(s),this._platform?(this.resolveLimeType(),this.loadLimeObject()):r.error(`No platform found. Pass "platform" prop or place the component inside a parent that exposes "platform". limetype=${t}, objectid=${i}`)}update(t,i){this.limetype=t,this.objectid=i,this.updateState({limeobject:void 0,limetypeData:void 0,loadFailed:!1}),this.hasPendingLoad||(this.hasPendingLoad=!0,queueMicrotask((()=>{if(this.hasPendingLoad=!1,!this.isDisconnected){if(!this._platform)return this.updateState({loadFailed:!0}),void r.warn(`Cannot update: no platform available. limetype=${this.limetype}, objectid=${this.objectid}`);this.resolveLimeType(),this.loadLimeObject()}})))}disconnect(){this.isDisconnected=!0}findPlatform(t){const i=h(t,this.hasPlatformProp);return null==i?void 0:i.platform}hasPlatformProp(t){return"platform"in t&&!!t.platform&&"object"==typeof t.platform}resolveLimeType(){const t=this._platform.get(a.LimeTypeRepository);this.updateState({limetypeData:t.getLimeType(this.limetype)})}async loadLimeObject(){const t=this.limetype,i=this.objectid,s=this._platform.get(a.LimeObjectRepository),e=s.getObject(t,i);if(e)this.updateState({limeobject:e});else{try{await s.loadObject(t,i)}catch(s){if(this.isStale(t,i))return;return this.updateState({loadFailed:!0}),void r.error(`Failed to load ${t}/${i}`,s)}this.isStale(t,i)||this.updateState({limeobject:s.getObject(t,i)})}}isStale(t,i){return this.isDisconnected||this.limetype!==t||this.objectid!==i}updateState(t){this.state=Object.assign(Object.assign({},this.state),t),this.isDisconnected||this.onStateChange(this.state)}}const n=class{constructor(i){t(this,i),this.size="default",this.data={loadFailed:!1},this.resolver=new l((t=>{this.data=t}))}connectedCallback(){this.resolver.connect(this.limetype,this.objectid,i(this),this.platform)}disconnectedCallback(){this.resolver.disconnect()}handlePropChange(){this.resolver.update(this.limetype,this.objectid)}render(){if(!this.resolver.resolvedPlatform)return;const t=e(this.data.limetypeData);return s("limel-chip",{text:this.getChipText(),icon:t,size:this.size,link:{href:(i=this.limetype,h=this.objectid,`object/${i}/${h}`)},loading:!this.data.limeobject&&!this.data.loadFailed});var i,h}getChipText(){var t;return(null===(t=this.data.limeobject)||void 0===t?void 0:t.descriptive)?this.data.limeobject.descriptive:this.data.loadFailed?this.getErrorText():""}getErrorText(){if(!this.resolver.resolvedPlatform)return"loading failed";try{return this.resolver.resolvedPlatform.get(a.Translate).get("webclient.limeobject.errors.load-failed")}catch(t){return"loading failed"}}static get watchers(){return{limetype:[{handlePropChange:0}],objectid:[{handlePropChange:0}]}}};n.style=":host{display:inline-block;vertical-align:baseline}";export{n as limebb_object_chip}