Files
AIDC-AI-ComfyUI-Copilot/dist/copilot_web/ParameterDebugInterfaceV2-CMlIMJWN.js
T
2025-06-27 11:52:22 +08:00

39 lines
64 KiB
JavaScript

function getImportPath(filename) {
return `./${filename}`;
}
import{j as e}from"./vendor-markdown-Mq66gLHN.js";import{r as k}from"./vendor-react-6F4zURhM.js";import{u as ve,a as ee,g as ie,W as se}from"./message-components-CP6ZQyhw.js";import{m as ht,i as gt}from"./workflowChat-CQWc5SUC.js";import{g as pt,q as ft,a as bt}from"./queuePrompt-Cm8deVJl.js";import"./input.js";/* empty css */const yt=({selectedNodes:t,handleParamSelect:s,selectedParams:r,handleNext:l,handleClose:o})=>{const n=t.flatMap(i=>(i.widgets||[]).map(x=>x.name)).some(i=>r[i]===!0);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Select parameters"}),e.jsx("p",{className:"text-xs text-gray-500",children:"multiple selections supported"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:o,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.map((i,x)=>{const m=i.title||"Unknown Node",u=i.widgets||[];return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsx("div",{className:"bg-gray-50 px-3 py-2 text-sm font-medium text-gray-700 border-b",children:m}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:u.map((d,p)=>{const y=d.name;return e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border flex items-center justify-center ${r[y]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:j=>s(y,j),children:r[y]&&e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500"})}),e.jsx("span",{className:"ml-2 text-gray-700 text-xs",children:y})]},`widget-${p}`)})})})]},`node-${x}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:i=>l(i),disabled:!n,className:`px-3 py-1.5 text-xs ${n?"bg-pink-200 text-pink-700 hover:bg-pink-300":"bg-gray-200 text-gray-500 cursor-not-allowed"} rounded-md transition-colors`,children:"Next"})})]})},jt=({selectedNodes:t,paramTestValues:s,selectedParams:r,updateParamTestValues:l,toggleDropdown:o,openDropdowns:a,handleTestValueSelect:n,searchTerms:i,handleSearch:x,handleSelectAll:m,handleNext:u,handlePrevious:d,handleClose:p,inputValues:y,setInputValues:j,textInputs:M,handleTextInputChange:$,handleAddTextInput:w,handleRemoveTextInput:E,openAiWritingModal:f})=>{const N=(g,S,I,U=0)=>{if(g=isNaN(g)?0:g,S=isNaN(S)?100:S,I=isNaN(I)||I<=0?1:I,S<g&&(S=g),Math.floor((S-g)/I)+1<=1)return[g];const P=[];let T=g;for(;T<=S;){const v=Math.pow(10,U),B=Math.round(T*v)/v;P.push(B),T+=I}return P};return k.useEffect(()=>{!t||t.length===0||t.forEach(g=>{const S=g.id.toString(),I=g.widgets||{};Object.values(I).forEach(b=>{const P=b.name;if(!r[P])return;if(!(s[S]?.[P]?.length>0)&&b.type==="number"){const v=b.options?.min||0,B=b.options?.max||100;let O=(b.options?.step||10)/10;O<.1&&(O=.1);const _=b.options?.precision||0,R=N(v,B,O,_);if(R.length>0){l(S,P,R);const z=`${S}_${P}`;j(C=>({...C,[z]:{min:v.toString(),max:B.toString(),step:O.toString()}}))}}if(b.type==="customtext"||b.type.toLowerCase().includes("text")){const v=`${S}_${P}`,B=M[v]||[""];JSON.stringify(B)!==JSON.stringify(s[S]?.[P]||[""])&&l(S,P,B)}})})},[t,r,s,M,l,j,N]),e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Set test values"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Configure the test values for each parameter"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:p,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.length>0?t.map((g,S)=>{const I=g.widgets||{},U=Object.values(I),b=g.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b flex justify-between items-center",children:[e.jsxs("span",{children:[g.type," (ID: ",b,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:P=>p(P,S),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"p-4 space-y-4",children:U.map((P,T)=>{const v=P.name;if(!r[v])return null;const B=`${b}_${v}`;if(P.type==="customtext"||P.type.toLowerCase().includes("text")){const O=M[B]||[""];return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[v,":"]}),e.jsxs("button",{className:"px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs flex items-center hover:bg-blue-200 transition-colors",onClick:()=>f(b,v),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),"AI Writing"]})]}),e.jsx("div",{className:"space-y-2",children:O.map((_,R)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:`flex-1 border ${_?"border-gray-300":"border-red-500"} rounded p-2 text-xs resize-y`,rows:2,placeholder:"Enter text...",value:_,onChange:z=>$(b,v,R,z.target.value),required:!0}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>E(b,v,R),title:"Remove",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},R))}),e.jsxs("button",{className:"mt-2 px-2 py-1 border border-dashed border-gray-300 rounded text-xs text-gray-600 hover:bg-gray-50 flex items-center",onClick:()=>w(b,v),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"Add Text"]})]},T)}if(P.type==="number"){const O=P.options?.min||0,_=P.options?.max||100,R=(P.options?.step||10)/10,z=P.options?.precision||0,C=N(O,_,R,z),F=y[B]||{min:O.toString(),max:_.toString(),step:R.toString()};return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[v,":"]}),e.jsx("div",{className:"w-4"})]}),e.jsxs("div",{className:"flex space-x-2 items-center",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Min"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:F.min,required:!0,onClick:L=>{L.preventDefault(),L.stopPropagation()},onChange:L=>{L.preventDefault(),L.stopPropagation();const D=L.target.value;if(j(A=>({...A,[B]:{...A[B],min:D}})),D===""||!isNaN(parseFloat(D))){const A=D===""?0:parseFloat(D),H=parseFloat(F.max||_.toString()),G=parseFloat(F.step||R.toString()),J=N(A,H,G,z);l(b,v,J)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Max"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:F.max,onClick:L=>{L.preventDefault(),L.stopPropagation()},required:!0,onChange:L=>{L.preventDefault(),L.stopPropagation();const D=L.target.value;if(j(A=>({...A,[B]:{...A[B],max:D}})),D===""||!isNaN(parseFloat(D))){const A=parseFloat(F.min||O.toString()),H=D===""?A:parseFloat(D),G=parseFloat(F.step||R.toString()),J=N(A,H,G,z);l(b,v,J)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Step"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:F.step,required:!0,onClick:L=>{L.preventDefault(),L.stopPropagation()},onChange:L=>{L.preventDefault(),L.stopPropagation();const D=L.target.value;if(j(A=>({...A,[B]:{...A[B],step:D}})),D===""||!isNaN(parseFloat(D))&&parseFloat(D)>0){const A=parseFloat(F.min||O.toString()),H=parseFloat(F.max||_.toString());let G=D===""?1:parseFloat(D);G<.1&&(G=.1);const J=N(A,H,G,z);l(b,v,J)}}})]}),e.jsxs("div",{className:"mt-1",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(()=>{const L=s[b]?.[v]||C;if(L.length<=10)return L.map((D,A)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:H=>{H.stopPropagation(),n(b,v,D,H)},children:[e.jsx("span",{children:D}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},A));{const D=L.slice(0,5),A=L.slice(L.length-5);return e.jsxs(e.Fragment,{children:[D.map((H,G)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:J=>{J.stopPropagation(),n(b,v,H,J)},children:[e.jsx("span",{children:H}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`first-${G}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),A.map((H,G)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:J=>{J.stopPropagation(),n(b,v,H,J)},children:[e.jsx("span",{children:H}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`last-${G}`))]})}})()})]}),e.jsx("div",{className:"mt-1",children:e.jsx("p",{className:"text-xs text-gray-500",children:"Values are distributed evenly between Min and Max"})})]},T)}else if(P.type==="combo"){const O=P.options?.values||[],_=`${b}_${v}`,R=C=>typeof C=="string"?C:C&&typeof C=="object"&&"name"in C?C.name:String(C),z=C=>typeof C=="object"&&C!==null&&"name"in C?C.name:C;return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"text-xs font-medium text-gray-700",children:v}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:`appearance-none border ${(s[b]?.[v]||[]).length===0?"border-red-500":"border-gray-300"} rounded px-2 py-0.5 pr-6 text-xs flex items-center bg-white text-gray-700`,onClick:C=>{C.preventDefault(),C.stopPropagation(),o(b,v,C)},"data-dropdown":_,children:[e.jsx("span",{children:(s[b]?.[v]||[]).length>0?`${v}: ${(s[b]?.[v]||[]).length} selected`:`Select ${v}`}),e.jsx("div",{className:"ml-2",children:e.jsx("svg",{className:"fill-current h-4 w-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"})})})]}),a[_]&&e.jsxs("div",{className:"absolute z-[9999] mt-1 w-64 bg-white border border-gray-300 rounded-md shadow-lg dropdown-menu",style:{position:"fixed",top:typeof a[_]=="object"?`${a[_].y}px`:"0px",left:typeof a[_]=="object"?`${a[_].x}px`:"0px",maxHeight:"300px",overflowY:"auto"},children:[e.jsx("div",{className:"p-2 border-b sticky top-0 bg-white",children:e.jsx("input",{type:"text",className:"w-full px-2 py-0.5 text-xs border border-gray-300 rounded",placeholder:"Search...",value:i[_]||"",onChange:C=>{C.preventDefault(),C.stopPropagation(),x(b,v,C.target.value)},onClick:C=>{C.preventDefault(),C.stopPropagation()},autoFocus:!0})}),e.jsxs("div",{className:"px-3 py-1.5 bg-gray-50 border-b cursor-pointer text-xs flex items-center text-gray-700 hover:bg-gray-100",onClick:C=>{C.preventDefault(),C.stopPropagation();const L=O.filter(D=>!i[_]||R(D).toLowerCase().includes((i[_]||"").toLowerCase())).map(z);m(b,v,L)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${O.length>0&&(s[b]?.[v]||[]).length===O.length?"bg-blue-500 border-blue-500":(s[b]?.[v]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(s[b]?.[v]||[]).length>0&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"font-medium",children:O.length>0&&(s[b]?.[v]||[]).length===O.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[O.filter(C=>!i[_]||R(C).toLowerCase().includes((i[_]||"").toLowerCase())).map((C,F)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:L=>{L.preventDefault(),L.stopPropagation(),n(b,v,z(C),L)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(s[b]?.[v]||[]).includes(z(C))?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(s[b]?.[v]||[]).includes(z(C))&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"whitespace-normal overflow-hidden text-ellipsis",children:R(C)})]},F)),O.filter(C=>!i[_]||R(C).toLowerCase().includes((i[_]||"").toLowerCase())).length===0&&e.jsx("div",{className:"px-3 py-4 text-sm text-gray-500 text-center",children:"No matching options"})]})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),(s[b]?.[v]||[]).length===0&&e.jsx("div",{className:"text-xs text-red-500 mt-1",children:"Please select at least one value"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(s[b]?.[v]||[]).map((C,F)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:C}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:L=>{L.preventDefault(),L.stopPropagation(),n(b,v,C,L)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},F))})]})]},T)}else return e.jsxs("div",{className:"border-b pb-3",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx("label",{className:"text-xs font-medium text-gray-700",children:v})}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[(s[b]?.[v]||[]).map((O,_)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:O}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:R=>{R.preventDefault(),R.stopPropagation(),n(b,v,O,R)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},_)),e.jsxs("button",{className:"px-2 py-0.5 border border-dashed border-blue-300 text-blue-600 rounded-md text-xs flex items-center hover:bg-blue-50",onClick:O=>{O.preventDefault(),O.stopPropagation();const _=`${v}${(s[b]?.[v]||[]).length+1}`;l(b,v,[...s[b]?.[v]||[],_])},children:[e.jsx("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),e.jsx("span",{children:"Add"})]})]})]})]},T)})})]},S)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:g=>d(g),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:g=>u(g),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},vt=({selectedNodes:t,paramTestValues:s,selectedParams:r,totalCount:l,errorMessage:o,handlePrevious:a,handleStartGeneration:n,handleClose:i})=>{const[x,m]=k.useState([]),[u,d]=k.useState(null),[p,y]=k.useState(!1),{dispatch:j}=ve(),M=()=>{const w=Object.values(ee.graph._nodes_by_id),E=[],f=[];for(const g of w)g.type==="SaveImage"?E.push(g.id):g.type==="PreviewImage"&&f.push(g.id);const N=[...E,...f];m(N),N.length===1?d(N[0]):N.length>1&&(y(!0),d(null))};k.useEffect(()=>{M()},[]),k.useEffect(()=>{const w=()=>{if(!ee.canvas.selected_nodes)return;const E=Object.values(ee.canvas.selected_nodes);if(E.length===0)return;const f=E[0];f&&(f.type==="SaveImage"||f.type==="PreviewImage")&&(console.log("Selected image node:",f.id),d(f.id))};return document.addEventListener("click",w),()=>{document.removeEventListener("click",w)}},[]);const $=w=>{if(w&&(w.preventDefault(),w.stopPropagation()),x.length>1&&!u){y(!0);return}n(w,u||void 0)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Conform combinations"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",l," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:i,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),p&&x.length>1&&e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 border border-yellow-200 rounded-md text-amber-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:u===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${x.join(",")}. Please click the node on canvas.`:`Current node ID is ${u}, please click Start Generation again`})]})}),o&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:o})]})}),t.length>0?t.map((w,E)=>{const f=w.type||"Unknown Node",N=w.widgets||[],g=w.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[f," (ID: ",g,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:N.map((S,I)=>{const U=S.name;if(!r[U])return null;const b=s[g]?.[U]||[],P=Array.isArray(b)?`[${b.join(", ")}]`:JSON.stringify(b);return e.jsxs("div",{className:I<N.length-1?"flex justify-between items-center border-b pb-2":"flex justify-between items-center",children:[e.jsx("label",{className:"font-medium text-gray-700 text-xs",children:U}),e.jsx("div",{className:"flex space-x-2 items-center",children:e.jsx("input",{type:"text",className:"w-64 h-7 border border-gray-300 rounded text-xs px-2 bg-gray-50 cursor-not-allowed text-gray-500",readOnly:!0,disabled:!0,value:P,onClick:T=>T.preventDefault()})})]},I)})})]},E)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500 text-xs",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:w=>a(w),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:w=>$(w),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${x.length>1&&!u?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:x.length>1&&!u,children:"Generate & Compare"})]})]})},Nt=({selectedNodes:t,paramTestValues:s,selectedParams:r,totalCount:l,completedCount:o,errorMessage:a,handleClose:n,setIsProcessing:i,setCurrentScreen:x,cleanupPolling:m})=>{const u=d=>{d.preventDefault(),d.stopPropagation(),ht({clear:!0}),gt(),m&&m(),i(!1),x(2)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 relative",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-500 bg-opacity-30 flex flex-col items-center justify-center z-10",children:e.jsxs("div",{className:"text-center text-gray-800 bg-white p-4 rounded-lg shadow-lg",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"Processing..."}),e.jsxs("div",{className:"text-xs mb-3",children:["Completed ",o," of ",l," runs"]}),e.jsx("div",{className:"w-48 h-2 bg-gray-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-pink-500 transition-all duration-200",style:{width:`${o/l*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",o," images"]}),e.jsx("button",{onClick:u,className:"mt-4 px-3 py-1.5 text-xs bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition-colors",children:"Cancel"})]})}),e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",l," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:n,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:a})]})}),t.length>0?t.map((d,p)=>{const y=d.type||"Unknown Node",j=d.widgets||[],M=d.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[y," (ID: ",M,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:j.map(($,w)=>{const E=$.name;if(!r[E])return null;const f=s[M]?.[E]||[],N=Array.isArray(f)?`[${f.join(", ")}]`:JSON.stringify(f);return e.jsxs("div",{className:w<j.length-1?"flex justify-between items-center border-b pb-2":"flex justify-between items-center",children:[e.jsx("label",{className:"font-medium text-gray-700",children:E}),e.jsx("div",{className:"flex space-x-2 items-center",children:e.jsx("input",{type:"text",className:"w-64 h-7 border border-gray-300 rounded text-sm px-2 bg-gray-50 cursor-not-allowed text-gray-500",readOnly:!0,disabled:!0,value:N,onClick:g=>g.preventDefault()})})]},w)})})]},p)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."})]})},te=({visible:t,imageUrl:s,params:r,onClose:l})=>{if(!t)return null;const o=()=>{if(!r||!r.nodeParams)return null;const a=Object.entries(r.nodeParams).map(([n,i])=>{const x=r.nodeNames?.[n]||r.selectedNodeInfoMap&&r.selectedNodeInfoMap[n]||(n.includes("text")?"Text Node":`Node ${n}`),m=Object.entries(i).filter(([u,d])=>typeof d!="object"||d===null).map(([u,d])=>e.jsxs("div",{className:"pl-4 text-sm py-1 flex",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-400 mr-2",children:"-"}),e.jsxs("span",{className:"font-medium mr-1",children:[u,":"]}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300 break-all",children:String(d)})]},u));return e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"font-semibold text-pink-600 dark:text-pink-400 text-base py-1 border-b border-gray-200 dark:border-gray-700 mb-2",children:x}),m.length>0?m:e.jsx("div",{className:"pl-4 text-sm text-gray-500 italic",children:"nodeParams is null"})]},n)});return e.jsx("div",{className:"overflow-y-auto max-h-full",children:a.length>0?a:e.jsx("div",{className:"text-sm text-gray-500 italic",children:"nodeParams is null"})})};return e.jsx("div",{className:"fixed inset-0 bg-black/40 backdrop-blur-sm flex items-center justify-center z-50",onClick:l,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl flex flex-row w-[90%] max-w-6xl max-h-[90vh] relative m-4 overflow-hidden",onClick:a=>a.stopPropagation(),style:{display:"flex",flexDirection:"row"},children:[e.jsx("button",{className:"absolute top-2 right-2 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 p-1 z-10",onClick:l,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("div",{className:"w-[65%] border-r border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"p-4 h-full flex items-center justify-center",children:e.jsx("img",{src:s,alt:"Enlarged image",className:"max-w-full max-h-[calc(90vh-2rem)] object-contain"})})}),e.jsx("div",{className:"w-[35%] h-full overflow-hidden flex flex-col",children:e.jsxs("div",{className:"p-4 flex-1 overflow-y-auto",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-800 dark:text-gray-200 mb-4",children:"Parameters"}),r&&!r.nodeParams&&Object.entries(r).filter(([a,n])=>a!=="nodeParams"&&typeof n!="object").map(([a,n])=>e.jsxs("div",{className:"py-1 text-sm text-gray-600 dark:text-gray-300",children:[e.jsxs("span",{className:"font-medium",children:[a,":"]})," ",String(n)]},a)),e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-300",children:o()})]})})]})})},wt=({generatedImages:t,selectedImageIndex:s,handleSelectImage:r,handleApplySelected:l,handlePrevious:o,handleClose:a,currentPage:n,handlePageChange:i,imagesPerPage:x,notificationVisible:m,modalVisible:u,modalImageUrl:d,modalImageParams:p,openImageModal:y,closeImageModal:j})=>{const M=Math.ceil(t.length/x),$=(n-1)*x,w=Math.min($+x,t.length),E=t.slice($,w);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Generation Complete"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["All ",t.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:a,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),m&&e.jsx("div",{className:"fixed top-4 right-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-3 shadow-md rounded animate-fade-in-out z-50",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"py-1",children:e.jsx("svg",{className:"h-4 w-4 text-green-500 mr-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-xs",children:"Parameters has been applied."})]})}),e.jsx(te,{visible:u,imageUrl:d,params:p||{},onClose:j}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:E.map((f,N)=>{const g=$+N;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${s===g?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:S=>r(g,S),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:S=>y(f.url,f.params,S),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:f.url,alt:`Generated image ${g+1}`,className:"w-full h-full object-cover"})}),e.jsx("div",{className:"p-2 text-xs text-gray-600 bg-white max-h-16 overflow-y-auto",children:Object.entries(f.params).filter(([S,I])=>S!=="nodeParams"&&typeof I!="object").map(([S,I])=>e.jsxs("div",{children:[S,": ",String(I)]},S))})]},g)})}),M>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:f=>i(1,f),disabled:n===1,className:`px-2 py-1 rounded ${n===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:f=>i(n-1,f),disabled:n===1,className:`px-2 py-1 rounded ${n===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",n," of ",M]}),e.jsx("button",{onClick:f=>i(n+1,f),disabled:n===M,className:`px-2 py-1 rounded ${n===M?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:f=>i(M,f),disabled:n===M,className:`px-2 py-1 rounded ${n===M?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx("button",{onClick:f=>l(f),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:s===null,children:"Apply Selected"})})]})},kt=({visible:t,aiWritingModalText:s,setAiWritingModalText:r,aiGeneratedTexts:l,aiSelectedTexts:o,aiWritingLoading:a,aiWritingError:n,handleAiWriting:i,toggleTextSelection:x,addSelectedTexts:m,onClose:u})=>t?e.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",onClick:u,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:`w-full px-4 py-3 border border-gray-200 dark:border-gray-600 rounded-lg text-gray-900 dark:text-white
bg-gray-50 dark:bg-gray-700
placeholder-gray-500 dark:placeholder-gray-400
focus:border-blue-500 dark:focus:border-blue-400
focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20
focus:outline-none`,rows:3,placeholder:"Enter some text here...",value:s,onChange:d=>r(d.target.value)}),e.jsx("button",{className:`mt-2 px-4 py-2 rounded-lg text-sm flex items-center transition-colors ${a?"bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white"}`,onClick:i,disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-gray-500 dark:text-gray-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Generating..."]}):e.jsx(e.Fragment,{children:"Generate"})})]}),n&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800/20 rounded-md text-red-700 dark:text-red-400 text-sm",children:n}),l.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Generated variations (select items to add):"}),e.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto p-2",children:l.map((d,p)=>e.jsxs("div",{className:"flex items-start border border-gray-200 dark:border-gray-600 rounded-md p-2",children:[e.jsx("div",{className:"mr-2 mt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",id:`text${p+1}`,checked:!!o[`text${p+1}`],onChange:()=>x(`text${p+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${o[`text${p+1}`]?"bg-blue-600 dark:bg-blue-500 border-blue-600 dark:border-blue-500":"border-gray-300 dark:border-gray-600"} flex items-center justify-center cursor-pointer`,onClick:()=>x(`text${p+1}`),children:o[`text${p+1}`]&&e.jsx("svg",{className:"h-3 w-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})]})}),e.jsx("label",{htmlFor:`text${p+1}`,className:"text-sm text-gray-700 dark:text-gray-300 cursor-pointer flex-1",children:d})]},p))})]})]}),e.jsxs("div",{className:"p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end flex-shrink-0",children:[e.jsx("button",{className:`px-5 py-2.5 text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700
rounded-lg font-medium transition-colors mr-3`,onClick:u,children:"Cancel"}),e.jsx("button",{className:`px-5 py-2.5 rounded-lg font-medium transition-colors ${Object.values(o).every(d=>!d)?"bg-gray-300 dark:bg-gray-600 text-gray-500 dark:text-gray-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white"}`,onClick:m,disabled:Object.values(o).every(d=>!d),children:"Add Selected"})]})]})}):null,je=t=>{const s=[],r={};if(Object.keys(t).forEach(a=>{const n=parseInt(a),i=t[a]||{},x=Object.keys(i).filter(u=>i[u]&&i[u].length>0);if(x.length===0)return;const m=[[]];x.forEach(u=>{const d=i[u],p=[];m.forEach(y=>{d.forEach(j=>{const M=[...y,{nodeId:n,paramName:u,paramValue:String(j)}];p.push(M)})}),m.length=0,m.push(...p)}),r[a]=m}),Object.keys(r).length===0)return s;if(Object.keys(r).length===1){const a=Object.keys(r)[0];return r[a]}const l=Object.keys(r);let o=r[l[0]];for(let a=1;a<l.length;a++){const n=r[l[a]],i=[];o.forEach(x=>{n.forEach(m=>{i.push([...x,...m])})}),o=i}return o},St=(t,s)=>{const r={};r.nodeParams={};const l=je(t);return s<l.length&&l[s].forEach(a=>{const n=a.nodeId.toString(),i=a.paramName,x=a.paramValue;r.nodeParams[n]||(r.nodeParams[n]={}),r.nodeParams[n][i]=x,r[i]=x}),r},Te="parameter_debug_history",De=30,Ae=async(t,s,r,l,o)=>{try{const a=Be(),n={id:ie(),timestamp:Date.now(),title:Ne(t,s),nodeName:t,params:{...s,nodeNames:{...s.nodeNames||{},[t.split("<")[0]]:t.split("<")[0]}},generatedImages:r,totalCount:l,workflow:o};return a.unshift(n),a.length>De&&a.splice(De),localStorage.setItem(Te,JSON.stringify(a)),n}catch(a){return console.error("Error saving parameter debug history:",a),null}},Be=()=>{try{const t=localStorage.getItem(Te);if(t)return JSON.parse(t)}catch(t){console.error("Error loading parameter debug history:",t)}return[]},Re=t=>{const s=new Date(t);return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")} ${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`},Ne=(t,s)=>{if(s.nodeParams)return Object.entries(s.nodeParams).map(([a,n])=>{let i=t;s.selectedNodeInfoMap&&s.selectedNodeInfoMap[a]&&(i=s.selectedNodeInfoMap[a]);const x=Object.keys(n).slice(0,3);return`${i}<${x.join(",")}>`}).join(";");const r=Object.keys(s).filter(l=>l!=="nodeParams"&&l!=="selectedNodeInfoMap").slice(0,3);return`${t}<${r.join(",")}>`},Ct=({historyItems:t,onViewHistoryItem:s,onClose:r})=>e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 flex flex-col h-full",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Experiments History"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Last ",t.length," experiments"]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:r,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500 text-sm",children:"No history items found"}):e.jsx("div",{className:"flex-1 overflow-y-auto",children:t.map(l=>e.jsxs("div",{className:"border border-gray-200 rounded-lg mb-3 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 py-2 px-3 flex items-center justify-between border-b",children:[e.jsx("div",{className:"text-[14px] text-gray-600",children:Re(l.timestamp)}),e.jsx("button",{onClick:()=>s(l),className:"px-3 py-1 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"view"})]}),e.jsx("div",{className:"p-3",children:e.jsx("div",{className:"text-[10px] font-medium text-gray-700",children:Ne(l.nodeName,l.params)})})]},l.id))})]}),Lt=({historyItem:t,selectedImageIndex:s,handleSelectImage:r,handleClose:l,currentPage:o,handlePageChange:a,imagesPerPage:n,modalVisible:i,modalImageUrl:x,modalImageParams:m,openImageModal:u,closeImageModal:d})=>{const{timestamp:p,nodeName:y,generatedImages:j,params:M}=t,$=Math.ceil(j.length/n),w=(o-1)*n,E=Math.min(w+n,j.length),f=j.slice(w,E);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:Ne(y,M)}),e.jsxs("p",{className:"text-xs text-gray-500",children:[Re(p)," • ",j.length," images"]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600 mt-0",onClick:l,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx(te,{visible:i,imageUrl:x,params:m?{...m,nodeNames:{[t.nodeName.split("<")[0]]:t.nodeName.split("<")[0]}}:void 0,onClose:d}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:f.map((N,g)=>{const S=w+g;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${s===S?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:I=>r(S,I),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:I=>u(N.url,N.params,I),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:N.url,alt:`Generated image ${S+1}`,className:"w-full h-full object-cover"})})]},S)})}),$>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:N=>a(1,N),disabled:o===1,className:`px-2 py-1 rounded ${o===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:N=>a(o-1,N),disabled:o===1,className:`px-2 py-1 rounded ${o===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",o," of ",$]}),e.jsx("button",{onClick:N=>a(o+1,N),disabled:o===$,className:`px-2 py-1 rounded ${o===$?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:N=>a($,N),disabled:o===$,className:`px-2 py-1 rounded ${o===$?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]})]})},Mt=`
@keyframes highlight-pulse {
0% {
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5);
}
70% {
box-shadow: 0 0 0 15px rgba(59, 130, 246, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
}
}
.highlight-pulse {
animation: highlight-pulse 1.5s infinite;
border: 2px solid #3b82f6;
}
@keyframes fade-in-out {
0% { opacity: 0; transform: translateY(-20px); }
10% { opacity: 1; transform: translateY(0); }
90% { opacity: 1; transform: translateY(0); }
100% { opacity: 0; transform: translateY(-20px); }
}
.animate-fade-in-out {
animation: fade-in-out 3s forwards;
}
`,re="parameter_debug_state",We=t=>{try{localStorage.setItem(re,JSON.stringify(t))}catch(s){console.error("Error saving parameter debug state:",s)}},$t=()=>{try{const t=localStorage.getItem(re);if(t)return JSON.parse(t)}catch(t){console.error("Error loading parameter debug state:",t)}return null},Et=()=>{try{localStorage.removeItem(re)}catch(t){console.error("Error clearing parameter debug state:",t)}},Pt=(t,s,r,l,o,a)=>{const n=`${t}_${s}`;a(x=>{const m=[...x[n]||[]];return m[r]=l,{...x,[n]:m}});const i=[...o[n]||[]];return i[r]=l,i},_t=(t,s,r,l)=>{const o=`${t}_${s}`;return l(a=>{const n=[...a[o]||[]];return n.push(""),{...a,[o]:n}}),[...r[o]||[],""]},Ot=(t,s,r,l,o)=>{const a=`${t}_${s}`;o(i=>{const x=[...i[a]||[]];return x.splice(r,1),{...i,[a]:x}});const n=[...l[a]||[]];return n.splice(r,1),n},It=(t,s,r,l,o)=>{r.preventDefault(),r.stopPropagation();const a=`${t}_${s}`;o(n=>{if(n[a]&&typeof n[a]=="object"?n[a].isOpen:!!n[a])return{...n,[a]:!1};{let x=0,m=0;if(r.currentTarget){const p=r.currentTarget.getBoundingClientRect();x=p.left,m=p.bottom}else x=r.clientX,m=r.clientY+20;const u=window.innerWidth,d=250;return x+d>u&&(x=u-d-10),x<0&&(x=10),{...n,[a]:{isOpen:!0,x,y:m}}}})},Dt=(t,s,r,l,o)=>{o(a=>{const n={...a};return n[t]||(n[t]={}),n[t][s]=r,n})},At=(t,s,r,l,o,a)=>{a&&(a.preventDefault(),a.stopPropagation()),o(n=>{const i={...n};i[t]||(i[t]={}),i[t][s]||(i[t][s]=[]);const x=i[t][s];return x.includes(r)?i[t][s]=x.filter(m=>m!==r):i[t][s]=[...x,r],i})},Wt=(t,s,r,l,o)=>{const a=`${t}_${s}`;o(n=>({...n,[a]:r}))},Tt=(t,s,r,l,o)=>{if(!l[t]){o(t,s,r);return}const a=l[t][s]||[];r.length===a.length?o(t,s,[]):o(t,s,[...r])},Bt=(t,s,r,l,o,a)=>{a&&(a.preventDefault(),a.stopPropagation());const n=s[t];if(r(i=>({...i,[t]:!n})),n){const i={...l};Object.keys(i).forEach(x=>{i[x][t]&&delete i[x][t]}),o(i)}},Rt=(t,s,r,l,o,a,n)=>{n.preventDefault(),n.stopPropagation();const i={...s};if(s.nodeParams){const x={};Object.keys(s.nodeParams).forEach(m=>{const u=r.find(d=>d.id.toString()===m);x[m]=u?u.title||`Node ${m}`:`Node ${m}`}),i.nodeNames=x}else if(Object.keys(s).length>0){const x={};Object.entries(s).forEach(([m,u])=>{(typeof u!="object"||u===null)&&(x[m]=u)}),Object.keys(x).length>0&&(i.nodeParams={default:x},i.nodeNames={default:s.node_name||s.nodeName||"参数"})}l(t),o(i),a(!0)},zt=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),t(!1)},Ft=(t,s,r,l,o,a,n,i,x,m,u)=>{if(u&&(u.preventDefault(),u.stopPropagation()),t===0){const d={...l};Object.keys(d).forEach(p=>{const y=d[p];Object.keys(y).forEach(j=>{r[j]||delete y[j]})}),o(d)}if(t===1){const d={...l};n.forEach(y=>{const j=y.id.toString(),M=y.widgets||{};Object.values(M).forEach($=>{const w=$.name;if(r[w]&&($.type==="customtext"||$.type.toLowerCase().includes("text"))){const E=`${j}_${w}`,f=a[E]||[""];d[j]=d[j]||{},d[j][w]=f}})}),o(d);const p=m(d);i(p.length)}x(null),s(d=>Math.min(d+1,2))},Ht=(t,s,r,l,o,a,n,i,x,m)=>{if(m&&(m.preventDefault(),m.stopPropagation()),x(null),n&&i(!1),t===1){const u=r.map(y=>y.id.toString()),d=Object.keys(l),p={...l};d.forEach(y=>{u.includes(y)||delete p[y]}),o(p)}if(t===2||n){const u={...l};Object.entries(a).forEach(([d,p])=>{if(!p||p.length===0)return;const[y,j]=d.split("_");r.some(M=>M.id.toString()===y)&&(u[y]=u[y]||{},JSON.stringify(u[y][j])!==JSON.stringify(p)&&(u[y][j]=p))}),o(u)}s(u=>Math.max(u-1,0))},Gt=(t,s,r,l,o)=>{o&&(o.preventDefault(),o.stopPropagation()),l(Math.max(1,Math.min(t,Math.ceil(r.length/s))))},Ut=async(t,s,r,l,o,a,n,i,x,m,u,d,p,y)=>{p&&(p.preventDefault(),p.stopPropagation()),Fe(m,x);const j=u(t),M=j.length;if(M>100){o(`Cannot generate more than 100 images at once (currently: ${M} images)`);return}o(null),r(!0),l(0),console.log("Generated parameter combinations:",j);let $=null;try{$=(await d.graphToPrompt()).output}catch(N){console.error("Error capturing workflow data:",N)}if(se.trackEvent({event_type:"start_generation",message_type:"parameter_debug",message_id:s,data:{workflow:$,all_params:t,count:M}}),j.length===0){o("No valid parameter combinations found. Please check your parameter selections."),r(!1);return}let w=y||null;if(w===null){const N=pt();N!==null&&(w=N)}if(w===null){o("Please select a SaveImage or PreviewImage node first."),r(!1);return}const E={};Object.keys(t).forEach(N=>{const g=d.graph._nodes_by_id[N];g&&(E[N]=g.type||g.comfyClass||"Unknown Node")});const f=[];try{const N=Date.now().toString();x.current=N;for(const P of j){const T=await ft(P);T.prompt_id?f.push(T.prompt_id):(console.error("Failed to get prompt_id from response:",T),f.push(""))}const g=Array(j.length).fill(null).map((P,T)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:St(t,T)}));a(g);const S=Date.now(),I=5*60*1e3,U=Object.keys(t)[0],b=E[U]||"Unknown Node";ze(f,w,g,N,S,I,x,m,a,l,r,n,i,b,t,M,$,E)}catch(N){console.error("Error generating images:",N),r(!1)}},ze=async(t,s,r,l,o,a,n,i,x,m,u,d,p,y,j,M,$,w)=>{if(n.current!==l){console.log("Another polling session has started, stopping this one");return}if(Date.now()-o>a){if(console.log("Timeout reached while waiting for images"),n.current===l&&(u(!1),d(!0),p(1),r.length>0&&y&&j)){const f=r[0].params;w&&(f.selectedNodeInfoMap=w),Ae(y,f,r,M||r.length,$)}return}let E=0;for(let f=0;f<t.length;f++){const N=t[f];if(N)try{const g=await bt(N,Number(s));g&&(r[f]={...r[f],url:g},E++)}catch(g){console.error(`Error fetching image for prompt ID ${N}:`,g)}}if(x([...r]),m(E),E===t.length){if(console.log("All images have been generated!"),n.current===l&&(u(!1),d(!0),p(1),r.length>0&&y&&j)){const f=r[0].params;w&&(f.selectedNodeInfoMap=w),Ae(y,f,r,M||r.length,$)}return}n.current===l&&(i.current=setTimeout(()=>{ze(t,s,r,l,o,a,n,i,x,m,u,d,p,y,j,M,$,w)},2e3))},Fe=(t,s)=>{t.current&&(clearTimeout(t.current),t.current=null),s.current=null},Jt=async(t,s,r,l,o,a)=>{if(!t.trim()){l("Please enter some text to generate variations");return}r(!0),l(null),o([]),a({});try{const n=await se.generateSDPrompts(t);o(n),se.trackEvent({event_type:"prompt_generate",message_type:"parameter_debug",message_id:s,data:{input_text:t,generated_texts:n}});const i={};n.forEach((x,m)=>{i[`text${m+1}`]=!1}),a(i)}catch(n){console.error("Error generating text:",n),l("Failed to generate text variations. Please try again.")}finally{r(!1)}},Kt=(t,s)=>{s(r=>({...r,[t]:!r[t]}))},Yt=(t,s,r,l,o,a,n,i,x,m)=>{const u=`${t}_${s}`,d=Object.entries(r).filter(([y,j])=>j).map(([y])=>{const j=parseInt(y.replace("text",""))-1;return l[j]});if(d.length===0)return;i(y=>{const j=[...y[u]||[]];return{...y,[u]:[...j,...d]}}),se.trackEvent({event_type:"prompt_apply",message_type:"parameter_debug",message_id:a,data:{input_text:o,generated_texts:l,selected_texts:d}});const p=[...n[u]||[],...d];x(t,s,p),m(!1)},Vt=(t,s,r,l,o,a,n,i,x,m)=>{r(!0),l(t),o(s),a(""),n([]),i({}),x(!1),m(null)},qt=(t,s,r,l,o,a,n,i,x,m,u,d,p,y,j,M,$,w,E,f,N,g,S,I,U,b,P,T,v,B=!1)=>{t(0),s({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),r(ie()),l(),o(!1),a(!1),n(0),i(12),x(null),m(Array(12).fill(null).map((O,_)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:_%3===0?5:_%3===1?10:15,sampler_name:"euler",cfg:1}}))),u({}),d({}),p({}),y({}),j(1),M(null),$(!1),w(!1),E(""),f(null),N({}),g(!1),S(""),I([]),U(!1),b(""),P(""),T(null),v({}),B&&Et()},Xt=(t,s,r)=>{r&&(r.preventDefault(),r.stopPropagation()),s(t)},Qt=async(t,s,r,l,o,a,n)=>{if(n&&(n.preventDefault(),n.stopPropagation()),t!==null){console.log(`Applied image ${t+1} with parameters:`,s[t].params);let i=1;if(o){for(const m in o)if(o[m])for(const u in o[m]){const d=o[m][u];if(d){let p=1;Array.isArray(d)?p=d.length>0?d.length:1:typeof d=="object"&&d!==null&&(p=Object.keys(d).length>0?Object.keys(d).length:1),i=i*p}}}se.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:l,data:{workflow:(await r.graphToPrompt()).output,selected_params:s[t].params,all_params:o,count:i}});const x=s[t].params;x.nodeParams&&(Object.entries(x.nodeParams).forEach(([m,u])=>{const d=r.graph._nodes_by_id[m];!d||!d.widgets||Object.entries(u).forEach(([p,y])=>{for(const j of d.widgets)if(j.name===p){j.value=y;break}})}),r.graph.setDirtyCanvas(!1,!0),a(!0),setTimeout(()=>{a(!1)},3e3))}},Zt=(t,s,r,l,o,a,n)=>{if(n&&(n.preventDefault(),n.stopPropagation()),t===1&&r!==void 0){const i=[...s];i[r],i.splice(r,1),i.length===0?o&&(l({type:"SET_SCREEN_STATE",payload:null}),a(!0),o()):l({type:"SET_SELECTED_NODE",payload:i});return}o&&(l({type:"SET_SCREEN_STATE",payload:null}),a(!0),o())},es=({selectedNodes:t,visible:s,onClose:r})=>{const[l,o]=k.useState(0),[a,n]=k.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[i,x]=k.useState(ie()),[m,u]=k.useState(!1),[d,p]=k.useState(!1),[y,j]=k.useState(0),[M,$]=k.useState(12),[w,E]=k.useState(null),[f,N]=k.useState(()=>Array(12).fill(null).map((c,h)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:h%3===0?5:h%3===1?10:15,sampler_name:"euler",cfg:1}}))),[g,S]=k.useState({}),[I,U]=k.useState({}),[b,P]=k.useState({}),[T,v]=k.useState({}),[B,O]=k.useState(1),_=6,[R,z]=k.useState(null),[C,F]=k.useState(!1),[L,D]=k.useState(!1),[A,H]=k.useState(""),[G,J]=k.useState(null),[Y,V]=k.useState({}),[He,ne]=k.useState(!1),[ce,de]=k.useState(""),[we,xe]=k.useState([]),[Ge,me]=k.useState(!1),[Ue,ke]=k.useState(""),[Je,Se]=k.useState(""),[Ke,ue]=k.useState(null),[Ce,ae]=k.useState({}),[he,ge]=k.useState(!1),[Ye,Ve]=k.useState([]),[Le,pe]=k.useState(null),{dispatch:fe}=ve(),Me=k.useRef(null),$e=k.useRef(null),[qe,oe]=k.useState(()=>s);k.useEffect(()=>{if(he){const c=Be();Ve(c)}},[he]);const Xe=async()=>{Jt(ce,i,me,ue,xe,ae)},Qe=(c,h,W,K)=>{const Q=Pt(c,h,W,K,Y,V);q(c,h,Q)},Ze=(c,h)=>{const W=_t(c,h,Y,V);q(c,h,W)},et=(c,h,W)=>{const K=Ot(c,h,W,Y,V);q(c,h,K)},tt=c=>{Kt(c,ae)},st=()=>{Yt(Ue,Je,Ce,we,ce,i,Y,V,q,ne)},rt=(c,h)=>{Vt(c,h,ne,ke,Se,de,xe,ae,me,ue)},Ee=c=>{c&&(c.preventDefault(),c.stopPropagation()),ge(h=>!h)},nt=c=>{pe(c),ge(!1),N(c.generatedImages||[]),E(null),O(1)},at=c=>{c&&(c.preventDefault(),c.stopPropagation()),pe(null)};k.useEffect(()=>{if(!t||t.length===0)return;const c={...g},h=t.map(K=>K.id.toString());Object.keys(c).forEach(K=>{h.includes(K)||delete c[K]}),t.forEach(K=>{const Q=K.id.toString();c[Q]||(c[Q]={})}),JSON.stringify(c)!==JSON.stringify(g)&&S(c)},[t,g]),k.useEffect(()=>{fe({type:"SET_SCREEN_STATE",payload:{currentScreen:l,isProcessing:m,isCompleted:d}})},[l,m,d,fe]),k.useEffect(()=>{const c=document.createElement("style");return c.textContent=Mt,document.head.appendChild(c),()=>{document.head.removeChild(c)}},[]),k.useEffect(()=>{const c=h=>{if(Object.values(I).some(W=>W)){const W=h.target,K=!!W.closest(".dropdown-menu"),Q=!!W.closest("[data-dropdown]");!K&&!Q&&U({})}};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c)}},[I]),k.useEffect(()=>{s&&(JSON.parse(localStorage.getItem(re)||"{}").task_id||x(ie()))},[s]),k.useEffect(()=>{if(s){oe(!0);try{const c=localStorage.getItem(re);if(c){const h=JSON.parse(c);if(!t||t.length===0){console.log("Not restoring parameter debug state: no nodes selected"),oe(!1);return}h.currentScreen!==void 0&&o(h.currentScreen),h.selectedParams&&n(h.selectedParams),h.task_id&&x(h.task_id);const W=h.generatedImages&&h.generatedImages.length>0;h.isProcessing!==void 0&&!h.isProcessing&&u(!1),h.isCompleted!==void 0&&W&&p(h.isCompleted),h.completedCount!==void 0&&j(h.completedCount),h.totalCount!==void 0&&$(h.totalCount),h.selectedImageIndex!==void 0&&E(h.selectedImageIndex),h.generatedImages&&N(h.generatedImages),h.paramTestValues&&S(h.paramTestValues),h.searchTerms&&P(h.searchTerms),h.inputValues&&v(h.inputValues),h.currentPage!==void 0&&O(h.currentPage),h.textInputs&&V(h.textInputs)}}catch(c){console.error("Error loading parameter debug state:",c)}finally{setTimeout(()=>{oe(!1)},50)}}else oe(!0);return()=>{if(!s)return;We({currentScreen:l,selectedParams:a,task_id:i,isProcessing:m,isCompleted:d,completedCount:y,totalCount:M,selectedImageIndex:w,generatedImages:f,paramTestValues:g,searchTerms:b,inputValues:T,currentPage:B,textInputs:Y})}},[s]);const ot=(c=!1)=>{qt(o,n,x,ye,u,p,j,$,E,N,S,U,P,v,O,z,F,D,H,J,V,ne,de,xe,me,ke,Se,ue,ae,c),ge(!1),pe(null)};k.useEffect(()=>{if(!s)return;const c=setTimeout(()=>{We({currentScreen:l,selectedParams:a,task_id:i,isProcessing:m,isCompleted:d,completedCount:y,totalCount:M,selectedImageIndex:w,generatedImages:f,paramTestValues:g,searchTerms:b,inputValues:T,currentPage:B,textInputs:Y})},500);return()=>clearTimeout(c)},[s,l,a,i,m,d,y,M,w,f,g,b,T,B,Y]);const Pe=c=>{Ft(l,o,a,g,S,Y,t,$,z,je,c)},be=c=>{Ht(l,o,t,g,S,Y,d,p,z,c)},lt=(c,h)=>{Bt(c,a,n,g,S,h)},it=(c,h,W)=>{It(c,h,W,I,U)},q=(c,h,W)=>{Dt(c,h,W,g,S)},ct=(c,h,W,K)=>{At(c,h,W,g,S,K)},dt=(c,h,W)=>{Wt(c,h,W,b,P)},xt=(c,h,W)=>{Tt(c,h,W,g,q)},_e=(c,h)=>{Gt(c,_,f,O,h)},ye=()=>{Fe(Me,$e)};k.useEffect(()=>()=>{ye()},[]);const mt=async(c,h)=>{Ut(g,i,u,j,z,N,p,O,$e,Me,je,ee,c,h)},Oe=(c,h)=>{Xt(c,E,h)},Ie=(c,h,W)=>{Rt(c,h,t,H,J,D,W)},Z=c=>{zt(D,c)},ut=async c=>{Qt(w,f,ee,i,g,F,c)},X=(c,h)=>{Zt(l,t,h,fe,r,ot,c)},le=()=>e.jsx(e.Fragment,{children:e.jsx(te,{visible:L,imageUrl:A,params:G||{},onClose:Z})});return Le?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:c=>c.stopPropagation(),children:e.jsx(Lt,{historyItem:Le,selectedImageIndex:w,handleSelectImage:Oe,handleClose:at,currentPage:B,handlePageChange:_e,imagesPerPage:_,modalVisible:L,modalImageUrl:A,modalImageParams:G,openImageModal:Ie,closeImageModal:Z})}):he?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:e.jsx(Ct,{historyItems:Ye,onViewHistoryItem:nt,onClose:Ee})}):qe&&s&&t.length>0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"p-8 rounded-lg shadow-sm relative flex flex-col items-center",children:[e.jsx("div",{className:"w-8 h-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"}),e.jsx("div",{className:"mt-4 text-gray-600 text-sm",children:"Loading interface..."})]}),e.jsx(te,{visible:L,imageUrl:A,params:G||{},onClose:Z})]}):!s||t.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"max-w-lg p-8 rounded-lg shadow-sm border border-blue-100 relative",children:[e.jsxs("div",{className:"absolute top-3 right-3 flex",children:[e.jsx("button",{className:"text-blue-500 hover:text-blue-700 mr-2",onClick:Ee,title:"Show History",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z",clipRule:"evenodd"})})}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:X,children:e.jsx("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h3",{className:"text-base font-bold text-blue-600 mb-2",children:"GenLab"}),e.jsx("div",{className:"h-1 w-16 bg-blue-500 mx-auto rounded-full mb-4"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-left mb-4",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-800 mb-3",children:"Batch-test parameters & find the best combo in one click."}),e.jsx("div",{className:"h-px w-full bg-gray-200 my-4"})]}),e.jsxs("div",{className:"text-left",children:[e.jsx("h4",{className:"text-base font-medium text-gray-800 mb-4",children:"How to use"}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("p",{className:"text-sm text-gray-700",children:[e.jsx("span",{className:"font-bold",children:"1 - "}),"Click any node(hold Shift to select multiple nodes)"]}),e.jsxs("p",{className:"text-sm text-gray-700",children:[e.jsx("span",{className:"font-bold",children:"2 - "}),"Set parameter ranges and start batch generation."]})]}),e.jsx("div",{className:"h-px w-full bg-gray-200 my-4"}),e.jsx("p",{className:"text-sm text-blue-600 mt-6",children:"Let's select a node to begin!"})]})]})]}),e.jsx(te,{visible:L,imageUrl:A,params:G||{},onClose:Z})]}):d?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:c=>c.stopPropagation(),children:e.jsx(wt,{generatedImages:f,selectedImageIndex:w,handleSelectImage:Oe,handleApplySelected:ut,handlePrevious:be,handleClose:X,currentPage:B,handlePageChange:_e,imagesPerPage:_,notificationVisible:C,modalVisible:L,modalImageUrl:A,modalImageParams:G,openImageModal:Ie,closeImageModal:Z})}):m?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:c=>c.stopPropagation(),children:[e.jsx(Nt,{selectedNodes:t,paramTestValues:g,selectedParams:a,totalCount:M,completedCount:y,errorMessage:R,handleClose:X,setIsProcessing:u,setCurrentScreen:o,cleanupPolling:ye}),e.jsx(le,{})]}):l===0?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:[e.jsx(yt,{selectedNodes:t,handleParamSelect:lt,selectedParams:a,handleNext:Pe,handleClose:X}),e.jsx(le,{})]}):l===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:[e.jsx(jt,{selectedNodes:t,paramTestValues:g,selectedParams:a,updateParamTestValues:q,toggleDropdown:it,openDropdowns:I,handleTestValueSelect:ct,searchTerms:b,handleSearch:dt,handleSelectAll:xt,handleNext:Pe,handlePrevious:be,handleClose:X,inputValues:T,setInputValues:v,textInputs:Y,handleTextInputChange:Qe,handleAddTextInput:Ze,handleRemoveTextInput:et,openAiWritingModal:rt}),e.jsx(kt,{visible:He,aiWritingModalText:ce,setAiWritingModalText:de,aiGeneratedTexts:we,aiSelectedTexts:Ce,aiWritingLoading:Ge,aiWritingError:Ke,handleAiWriting:Xe,toggleTextSelection:tt,addSelectedTexts:st,onClose:()=>ne(!1)}),e.jsx(le,{})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:c=>c.stopPropagation(),children:[e.jsx(vt,{selectedNodes:t,paramTestValues:g,selectedParams:a,totalCount:M,errorMessage:R,handlePrevious:be,handleStartGeneration:mt,handleClose:X}),e.jsx(le,{})]})},is=t=>{const{dispatch:s}=ve(),[r,l]=k.useState(!1);return k.useEffect(()=>{if(t.visible&&!r){const o=$t();o&&o.screenState&&s({type:"SET_SCREEN_STATE",payload:{currentScreen:o.currentScreen,isProcessing:o.isProcessing,isCompleted:o.isCompleted}}),l(!0)}},[t.visible,r,s]),k.useEffect(()=>()=>{t.visible||s({type:"SET_SCREEN_STATE",payload:null})},[t.visible,s]),e.jsx(es,{...t})};export{is as ParameterDebugInterface};