import{isEmpty,cleanHTML}from"../base/helpers.mjs";import{ElementBuilder}from"../base/builder.mjs";import{View}from"./base.mjs";const E=new ElementBuilder;class ModelMetadataView extends View{static placeholderText="Model metadata loading&hellip;";static noMetadataText="Sorry, metadata could not be found for this model.";static className="civit-ai-item";setMetadata(e){if(isEmpty(e))this.node.content(E.p().class("placeholder").content(this.constructor.noMetadataText));else{if(this.node.empty(),this.node.append(E.h2().content(E.a().content(e.name).target("_blank").href(`https://civitai.com/models/${e.modelId}`)),E.h4().content(`${e.model.name} (${e.baseModel} ${e.model.type})`),E.p().content(cleanHTML(`${e.description}`))),isEmpty(e.trainedWords)||this.node.append(E.div().class("triggers").content(...e.trainedWords.map((e=>E.span().content(e))))),!isEmpty(e.images)){let t=e.images.slice(0,4);this.node.append(E.div().class("images").content(...t.map((e=>{let a;return a="video"===e.type?E.video().content(E.source().src(e.url)).autoplay(!0).muted(!0).loop(!0).controls(!1):E.img().src(e.url),isEmpty(e.meta)||isEmpty(e.meta.prompt)||a.data("tooltip",cleanHTML(e.meta.prompt)),a.css({"max-width":100/t.length+"%","max-height":"100%"}),a}))))}this.node.render()}}async build(){let e=await super.build();return e.content(E.p().class("placeholder").content(this.constructor.placeholderText)),e}}export{ModelMetadataView};
