import{isEmpty,deepClone,createElementsFromString}from"../../../base/helpers.mjs";import{ElementBuilder}from"../../../base/builder.mjs";import{FormView}from"../../base.mjs";import{InputView}from"../base.mjs";import{StringInputView,TextInputView}from"../string.mjs";import{NumberInputView,FloatInputView}from"../numeric.mjs";import{FormInputView,RepeatableInputView}from"../parent.mjs";import{SelectInputView,SearchListInputView,SearchListInputListView}from"../enumerable.mjs";const E=new ElementBuilder;class ModelPickerListInputView extends SearchListInputListView{static classList=SearchListInputListView.classList.concat(["model-picker-list-input-view"])}class ModelPickerStringInputView extends StringInputView{setValue(e,t){return isEmpty(e)||(e.startsWith("<")?e=createElementsFromString(e)[0].innerText:-1!==e.indexOf("/")&&(e=e.split("/")[1])),super.setValue(e,t)}}class ModelPickerInputView extends SearchListInputView{static placeholder="Start typing to search models…";static stringInputClass=ModelPickerStringInputView;static listInputClass=ModelPickerListInputView;async showMetadata(){this.showingMetadata=!0;try{await this.constructor.showModelMetadata(this.value)}finally{this.showingMetadata=!1}}setValue(e,t){if(super.setValue(e,t),!t&&void 0!==this.node){let t=this.node.find("i.show-metadata");isEmpty(e)||!e.startsWith("checkpoint")?t.hide():t.show()}}async build(){let e=await super.build(),t=E.i().class("fa-solid fa-magnifying-glass show-metadata").data("tooltip","View Model Metadata").on("click",(e=>{e.stopPropagation(),e.preventDefault(),!0!==this.showingMetadata&&this.showMetadata()}));return e.append(t),this.onChange((()=>{isEmpty(this.value)||!this.value.startsWith("checkpoint")?t.hide():t.show()})),isEmpty(this.value)&&t.hide(),e}}class ModelInputView extends SearchListInputView{static stringInputClass=ModelPickerStringInputView;async setValue(e){if(await super.setValue(e),void 0!==this.node){let e=this.node.find(".show-metadata");isEmpty(this.value)?e.hide():e.show()}}async showMetadata(){this.showingMetadata=!0;try{await this.constructor.showModelMetadata(this.value)}finally{this.showingMetadata=!1}}async build(){let e=await super.build(),t=E.i().class("fa-solid fa-magnifying-glass show-metadata").data("tooltip","View Model Metadata").on("click",(e=>{e.stopPropagation(),e.preventDefault(),!0!==this.showingMetadata&&this.showMetadata()}));return e.append(t),this.onChange((()=>{isEmpty(this.value)?t.hide():t.show()})),isEmpty(this.value)&&t.hide(),e}}class LoraInputView extends ModelInputView{}class VAEInputView extends ModelInputView{}class LycorisInputView extends ModelInputView{}class InversionInputView extends ModelInputView{}class CheckpointInputView extends ModelInputView{}class MotionModuleInputView extends ModelInputView{}class ControlNetModelInputView extends ModelInputView{}class LoraFormView extends FormView{static autoSubmit=!0;static fieldSets={LoRA:{model:{label:"Model",class:LoraInputView,config:{required:!0}},weight:{label:"Weight",class:FloatInputView,config:{value:1,step:.01,required:!0}}}}}class LoraFormInputView extends FormInputView{static formClass=LoraFormView}class LycorisFormView extends FormView{static autoSubmit=!0;static fieldSets={LyCORIS:{model:{label:"Model",class:LycorisInputView,config:{required:!0}},weight:{label:"Weight",class:FloatInputView,config:{value:1,step:.01,required:!0}}}}}class LycorisFormInputView extends FormInputView{static formClass=LycorisFormView}class MultiLoraInputView extends RepeatableInputView{static noItemsLabel="No LoRA Configured";static addItemLabel="Add LoRA";static memberClass=LoraFormInputView}class MultiLycorisInputView extends RepeatableInputView{static noItemsLabel="No LyCORIS Configured";static addItemLabel="Add LyCORIS";static memberClass=LycorisFormInputView}class MultiInversionInputView extends RepeatableInputView{static noItemsLabel="No Textual Inversion Configured";static addItemLabel="Add Textual Inversion";static memberClass=InversionInputView}class ModelMergeModeInputView extends SelectInputView{static defaultOptions={"add-difference":"Add Difference","weighted-sum":"Weighted Sum"}}class ModelTypeInputView extends SelectInputView{static defaultOptions={checkpoint:"Checkpoint",lora:"LoRA",lycoris:"LyCORIS",inversion:"Textual Inversion",motion:"Motion Module"}}export{CheckpointInputView,LoraInputView,LycorisInputView,InversionInputView,MultiLoraInputView,MultiLycorisInputView,MultiInversionInputView,VAEInputView,ModelPickerStringInputView,ModelPickerListInputView,ModelPickerInputView,ModelMergeModeInputView,MotionModuleInputView,ModelTypeInputView,ControlNetModelInputView};
