import{proxyCustomElement as e,HTMLElement as t,h as i,transformTag as l}from"@stencil/core/internal/client";import{G as s,R as r,b as o}from"./index.esm.js";import{g as n}from"./extension-mapping.js";import{d as c}from"./empty-state.js";import{d as a}from"./live-docs-info.js";import{n as f}from"./negate.js";const m=["pdf","edit","view"];var h=function(e,t,i,l){var s,r=arguments.length,o=r<3?t:null===l?l=Object.getOwnPropertyDescriptor(t,i):l;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,l);else for(var n=e.length-1;n>=0;n--)(s=e[n])&&(o=(r<3?s(o):r>3?s(t,i,o):s(t,i))||o);return r>3&&o&&Object.defineProperty(t,i,o),o};const u=e(class extends t{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.fileTypes=["view","contents","download"],this.renderLiveDocs=e=>{if(!this.isLiveDocsAvailable(e))return i("limebb-live-docs-info",null);if(!this.platform.isFeatureEnabled("useOfficeFilePreview"))return i("limebb-empty-state",{value:"Preview of this file type will be available soon",icon:{name:"attention",color:"rgb(var(--color-blue-light))"}});const t=this.getLiveDocsUrl(e);return i("iframe",{src:t,frameBorder:0,marginHeight:0,marginWidth:0})},this.renderFileViewer=e=>{const t=e.filename,l=this.getFileUrl(e);return l?i("limel-file-viewer",{filename:t,url:l,allowFullscreen:!0,allowOpenInNewTab:!0}):this.renderNotFound()},this.renderUnsupported=e=>i("limel-file-viewer",{filename:e.filename,url:void 0,allowFullscreen:!0,allowOpenInNewTab:!0}),this.renderNotFound=()=>[i("section",{class:"not-found"},i("limel-icon",{name:"error",size:"large"}),i("h2",null,this.translator.get("webclient.not-found")),i("p",null,this.translator.get("webclient.no-files-attached",{object:this.getDescriptive(this.limeobject)})))]}render(){const e=this.getFile();if(!e)return this.renderNotFound();const t=n(e.extension);return(0,{fileViewer:this.renderFileViewer,browser:this.renderFileViewer,sharepoint:this.renderLiveDocs,unsupported:this.renderUnsupported}[t])(e)}getLiveDocsUrl(e){let t=[...this.fileTypes];return this.platform.isFeatureEnabled("useOfficeFilePreview")&&(t=["pdf",...t]),t.filter(this.isLiveDocsType).map((t=>e.getUrl(t))).find(Boolean)}getFileUrl(e){return this.fileTypes.filter(f(this.isLiveDocsType)).map((t=>e.getUrl(t))).find(Boolean)}getFile(){const e=this.fileProperty;if(e)return this.limeobject.getFile(e.name)}isLiveDocsAvailable(e){return m.some((t=>e.getUrl(t)))}isLiveDocsType(e){return m.includes(e)}getDescriptive(e){var t;return(null==e?void 0:e.descriptive)||(null===(t=this.limetype)||void 0===t?void 0:t.localname.singular)||this.translator.get("object")}get fileProperty(){if(this.limeobject){if(this.property){const e=this.limeobject.getLimetype().getProperty(this.property);if("file"===e.type)return e}return Object.values(this.limeobject.getLimetype().properties).find((e=>"file"===e.type))}}get translator(){return this.platform.get(o.Translate)}static get style(){return".not-found{display:flex;flex-direction:column;height:100%;align-items:center;justify-content:center;line-height:1rem;color:rgb(var(--contrast-1100))}.not-found limel-icon{color:rgb(var(--color-red-default))}iframe{height:100%;width:100%}"}},[1,"limebb-limeobject-file-viewer",{platform:[16],context:[16],property:[1],fileTypes:[16],limeobject:[32],limetype:[32]}]);h([s()],u.prototype,"limeobject",void 0),h([r()],u.prototype,"limetype",void 0);const b=u,p=function(){"undefined"!=typeof customElements&&["limebb-limeobject-file-viewer","limebb-empty-state","limebb-live-docs-info"].forEach((e=>{switch(e){case"limebb-limeobject-file-viewer":customElements.get(l(e))||customElements.define(l(e),u);break;case"limebb-empty-state":customElements.get(l(e))||c();break;case"limebb-live-docs-info":customElements.get(l(e))||a()}}))};export{b as LimebbLimeobjectFileViewer,p as defineCustomElement}