import{MenuController}from"../menu.mjs";import{ModelTableView}from"../../view/table.mjs";import{ImageView,ImageInspectorView}from"../../view/image.mjs";import{isEmpty,humanDuration,sleep}from"../../base/helpers.mjs";import{ElementBuilder}from"../../base/builder.mjs";const imageWidthPadding=2,imageHeightPadding=100,E=new ElementBuilder({invocationOutputs:"enfugue-invocation-outputs",invocationOutput:"enfugue-invocation-output"});class InvocationTableView extends ModelTableView{static imageInspectorWidth=550;static imageInspectorHeight=550;static className="invocation-history";static searchFields=["plan"];static buttons=[{icon:"fa-solid fa-trash",label:"Delete",click:async function(t){await InvocationTableView.deleteInvocation(t.id),await sleep(100),await this.parent.requery()}}];static sortGroups=[{column:"started",direction:"desc"}];static printKwargs={prompt:"Prompt",negative_prompt:"Negative Prompt",width:"Width",height:"Height",image_width:"Engine Width",image_height:"Engine Height",model:"Checkpoint",inversion:"Textual Inversion(s)",lora:"LoRA(s)"};static columnFormatters={duration:t=>humanDuration(parseFloat(t)),plan:t=>JSON.stringify(t),outputs:async function(t,i){if(t>0){let e=E.invocationOutputs();for(let o=0;o<t;o++){let t=`${i.id}_${o}.png`,n=`/api/invocation/images/${t}`,a=`/api/invocation/thumbnails/${t}`,s=new ImageView(this.config,a),r=new ImageInspectorView(this.config,n,t,InvocationTableView.imageInspectorWidth,InvocationTableView.imageInspectorHeight),l=E.invocationOutput().content(await s.getNode()).on("click",(async()=>{let t=await InvocationTableView.spawnWindow(`${i.id} sample ${o+1}`,r,InvocationTableView.imageInspectorWidth+2,InvocationTableView.imageInspectorHeight+32);t.onResize((i=>{r.setDimension(t.visibleWidth-23,t.visibleHeight-53)}))}));e.append(l)}return e}return isEmpty(i.error)?"None":`Error: ${i.error}`}};static columns={started:"Started",duration:"Duration",plan:"Parameters",outputs:"Output"}}class ResultsController extends MenuController{static historyTableWidth=800;static historyTableHeight=500;static menuName="Results";static menuIcon="fa-solid fa-images";async initialize(){await super.initialize(),InvocationTableView.spawnWindow=(t,i,e,o)=>this.spawnWindow(t,i,e,o),InvocationTableView.deleteInvocation=t=>{this.model.delete(`/invocation/${t}`)}}async createResultsWindow(){return await this.spawnWindow("Results",new InvocationTableView(this.config,this.model.DiffusionInvocation),this.constructor.historyTableWidth,this.constructor.historyTableHeight)}async onClick(){isEmpty(this.historyWindow)?(this.historyWindow=await this.createResultsWindow(),this.historyWindow.onClose((()=>{delete this.historyWindow}))):this.historyWindow.focus()}}export{ResultsController as MenuController};
