@kelceyp/caw-server 1.0.283 → 1.0.285
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +406 -385
- package/dist/public_html/main.js +1 -1
- package/package.json +1 -1
package/dist/public_html/main.js
CHANGED
|
@@ -3080,7 +3080,7 @@ ${this.parser.parse(Z)}</blockquote>
|
|
|
3080
3080
|
${Z}</tr>
|
|
3081
3081
|
`}tablecell(Z){let J=this.parser.parseInline(Z.tokens),Q=Z.header?"th":"td";return(Z.align?`<${Q} align="${Z.align}">`:`<${Q}>`)+J+`</${Q}>
|
|
3082
3082
|
`}strong({tokens:Z}){return`<strong>${this.parser.parseInline(Z)}</strong>`}em({tokens:Z}){return`<em>${this.parser.parseInline(Z)}</em>`}codespan({text:Z}){return`<code>${JO(Z,!0)}</code>`}br(Z){return"<br>"}del({tokens:Z}){return`<del>${this.parser.parseInline(Z)}</del>`}link({href:Z,title:J,tokens:Q}){let X=this.parser.parseInline(Q),K=Hs0(Z);if(K===null)return X;Z=K;let Y='<a href="'+Z+'"';return J&&(Y+=' title="'+JO(J)+'"'),Y+=">"+X+"</a>",Y}image({href:Z,title:J,text:Q,tokens:X}){X&&(Q=this.parser.parseInline(X,this.parser.textRenderer));let K=Hs0(Z);if(K===null)return JO(Q);Z=K;let Y=`<img src="${Z}" alt="${Q}"`;return J&&(Y+=` title="${JO(J)}"`),Y+=">",Y}text(Z){return"tokens"in Z&&Z.tokens?this.parser.parseInline(Z.tokens):("escaped"in Z)&&Z.escaped?Z.text:JO(Z.text)}},H20=class{strong({text:Z}){return Z}em({text:Z}){return Z}codespan({text:Z}){return Z}del({text:Z}){return Z}html({text:Z}){return Z}text({text:Z}){return Z}link({text:Z}){return""+Z}image({text:Z}){return""+Z}br(){return""}checkbox({raw:Z}){return Z}},xq=class Z{options;renderer;textRenderer;constructor(J){this.options=J||OP,this.options.renderer=this.options.renderer||new $s,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new H20}static parse(J,Q){return new Z(Q).parse(J)}static parseInline(J,Q){return new Z(Q).parseInline(J)}parse(J){let Q="";for(let X=0;X<J.length;X++){let K=J[X];if(this.options.extensions?.renderers?.[K.type]){let U=K,z=this.options.extensions.renderers[U.type].call({parser:this},U);if(z!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(U.type)){Q+=z||"";continue}}let Y=K;switch(Y.type){case"space":{Q+=this.renderer.space(Y);break}case"hr":{Q+=this.renderer.hr(Y);break}case"heading":{Q+=this.renderer.heading(Y);break}case"code":{Q+=this.renderer.code(Y);break}case"table":{Q+=this.renderer.table(Y);break}case"blockquote":{Q+=this.renderer.blockquote(Y);break}case"list":{Q+=this.renderer.list(Y);break}case"checkbox":{Q+=this.renderer.checkbox(Y);break}case"html":{Q+=this.renderer.html(Y);break}case"def":{Q+=this.renderer.def(Y);break}case"paragraph":{Q+=this.renderer.paragraph(Y);break}case"text":{Q+=this.renderer.text(Y);break}default:{let U='Token with "'+Y.type+'" type was not found.';if(this.options.silent)return console.error(U),"";throw Error(U)}}}return Q}parseInline(J,Q=this.renderer){let X="";for(let K=0;K<J.length;K++){let Y=J[K];if(this.options.extensions?.renderers?.[Y.type]){let z=this.options.extensions.renderers[Y.type].call({parser:this},Y);if(z!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(Y.type)){X+=z||"";continue}}let U=Y;switch(U.type){case"escape":{X+=Q.text(U);break}case"html":{X+=Q.html(U);break}case"link":{X+=Q.link(U);break}case"image":{X+=Q.image(U);break}case"checkbox":{X+=Q.checkbox(U);break}case"strong":{X+=Q.strong(U);break}case"em":{X+=Q.em(U);break}case"codespan":{X+=Q.codespan(U);break}case"br":{X+=Q.br(U);break}case"del":{X+=Q.del(U);break}case"text":{X+=Q.text(U);break}default:{let z='Token with "'+U.type+'" type was not found.';if(this.options.silent)return console.error(z),"";throw Error(z)}}}return X}},Wb=class{options;block;constructor(Z){this.options=Z||OP}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(Z){return Z}postprocess(Z){return Z}processAllTokens(Z){return Z}emStrongMask(Z){return Z}provideLexer(){return this.block?fq.lex:fq.lexInline}provideParser(){return this.block?xq.parse:xq.parseInline}},E06=class{defaults=X20();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=xq;Renderer=$s;TextRenderer=H20;Lexer=fq;Tokenizer=Ps;Hooks=Wb;constructor(...Z){this.use(...Z)}walkTokens(Z,J){let Q=[];for(let X of Z)switch(Q=Q.concat(J.call(this,X)),X.type){case"table":{let K=X;for(let Y of K.header)Q=Q.concat(this.walkTokens(Y.tokens,J));for(let Y of K.rows)for(let U of Y)Q=Q.concat(this.walkTokens(U.tokens,J));break}case"list":{let K=X;Q=Q.concat(this.walkTokens(K.items,J));break}default:{let K=X;this.defaults.extensions?.childTokens?.[K.type]?this.defaults.extensions.childTokens[K.type].forEach((Y)=>{let U=K[Y].flat(1/0);Q=Q.concat(this.walkTokens(U,J))}):K.tokens&&(Q=Q.concat(this.walkTokens(K.tokens,J)))}}return Q}use(...Z){let J=this.defaults.extensions||{renderers:{},childTokens:{}};return Z.forEach((Q)=>{let X={...Q};if(X.async=this.defaults.async||X.async||!1,Q.extensions&&(Q.extensions.forEach((K)=>{if(!K.name)throw Error("extension name required");if("renderer"in K){let Y=J.renderers[K.name];Y?J.renderers[K.name]=function(...U){let z=K.renderer.apply(this,U);return z===!1&&(z=Y.apply(this,U)),z}:J.renderers[K.name]=K.renderer}if("tokenizer"in K){if(!K.level||K.level!=="block"&&K.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let Y=J[K.level];Y?Y.unshift(K.tokenizer):J[K.level]=[K.tokenizer],K.start&&(K.level==="block"?J.startBlock?J.startBlock.push(K.start):J.startBlock=[K.start]:K.level==="inline"&&(J.startInline?J.startInline.push(K.start):J.startInline=[K.start]))}"childTokens"in K&&K.childTokens&&(J.childTokens[K.name]=K.childTokens)}),X.extensions=J),Q.renderer){let K=this.defaults.renderer||new $s(this.defaults);for(let Y in Q.renderer){if(!(Y in K))throw Error(`renderer '${Y}' does not exist`);if(["options","parser"].includes(Y))continue;let U=Y,z=Q.renderer[U],W=K[U];K[U]=(...G)=>{let q=z.apply(K,G);return q===!1&&(q=W.apply(K,G)),q||""}}X.renderer=K}if(Q.tokenizer){let K=this.defaults.tokenizer||new Ps(this.defaults);for(let Y in Q.tokenizer){if(!(Y in K))throw Error(`tokenizer '${Y}' does not exist`);if(["options","rules","lexer"].includes(Y))continue;let U=Y,z=Q.tokenizer[U],W=K[U];K[U]=(...G)=>{let q=z.apply(K,G);return q===!1&&(q=W.apply(K,G)),q}}X.tokenizer=K}if(Q.hooks){let K=this.defaults.hooks||new Wb;for(let Y in Q.hooks){if(!(Y in K))throw Error(`hook '${Y}' does not exist`);if(["options","block"].includes(Y))continue;let U=Y,z=Q.hooks[U],W=K[U];Wb.passThroughHooks.has(Y)?K[U]=(G)=>{if(this.defaults.async&&Wb.passThroughHooksRespectAsync.has(Y))return(async()=>{let H=await z.call(K,G);return W.call(K,H)})();let q=z.call(K,G);return W.call(K,q)}:K[U]=(...G)=>{if(this.defaults.async)return(async()=>{let H=await z.apply(K,G);return H===!1&&(H=await W.apply(K,G)),H})();let q=z.apply(K,G);return q===!1&&(q=W.apply(K,G)),q}}X.hooks=K}if(Q.walkTokens){let K=this.defaults.walkTokens,Y=Q.walkTokens;X.walkTokens=function(U){let z=[];return z.push(Y.call(this,U)),K&&(z=z.concat(K.call(this,U))),z}}this.defaults={...this.defaults,...X}}),this}setOptions(Z){return this.defaults={...this.defaults,...Z},this}lexer(Z,J){return fq.lex(Z,J??this.defaults)}parser(Z,J){return xq.parse(Z,J??this.defaults)}parseMarkdown(Z){return(J,Q)=>{let X={...Q},K={...this.defaults,...X},Y=this.onError(!!K.silent,!!K.async);if(this.defaults.async===!0&&X.async===!1)return Y(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof J>"u"||J===null)return Y(Error("marked(): input parameter is undefined or null"));if(typeof J!="string")return Y(Error("marked(): input parameter is of type "+Object.prototype.toString.call(J)+", string expected"));if(K.hooks&&(K.hooks.options=K,K.hooks.block=Z),K.async)return(async()=>{let U=K.hooks?await K.hooks.preprocess(J):J,z=await(K.hooks?await K.hooks.provideLexer():Z?fq.lex:fq.lexInline)(U,K),W=K.hooks?await K.hooks.processAllTokens(z):z;K.walkTokens&&await Promise.all(this.walkTokens(W,K.walkTokens));let G=await(K.hooks?await K.hooks.provideParser():Z?xq.parse:xq.parseInline)(W,K);return K.hooks?await K.hooks.postprocess(G):G})().catch(Y);try{K.hooks&&(J=K.hooks.preprocess(J));let U=(K.hooks?K.hooks.provideLexer():Z?fq.lex:fq.lexInline)(J,K);K.hooks&&(U=K.hooks.processAllTokens(U)),K.walkTokens&&this.walkTokens(U,K.walkTokens);let z=(K.hooks?K.hooks.provideParser():Z?xq.parse:xq.parseInline)(U,K);return K.hooks&&(z=K.hooks.postprocess(z)),z}catch(U){return Y(U)}}}onError(Z,J){return(Q)=>{if(Q.message+=`
|
|
3083
|
-
Please report this to https://github.com/markedjs/marked.`,Z){let X="<p>An error occurred:</p><pre>"+JO(Q.message+"",!0)+"</pre>";return J?Promise.resolve(X):X}if(J)return Promise.reject(Q);throw Q}}},FP=new E06;function W5(Z,J){return FP.parse(Z,J)}W5.options=W5.setOptions=function(Z){return FP.setOptions(Z),W5.defaults=FP.defaults,Os0(W5.defaults),W5};W5.getDefaults=X20;W5.defaults=OP;W5.use=function(...Z){return FP.use(...Z),W5.defaults=FP.defaults,Os0(W5.defaults),W5};W5.walkTokens=function(Z,J){return FP.walkTokens(Z,J)};W5.parseInline=FP.parseInline;W5.Parser=xq;W5.parser=xq.parse;W5.Renderer=$s;W5.TextRenderer=H20;W5.Lexer=fq;W5.lexer=fq.lex;W5.Tokenizer=Ps;W5.Hooks=Wb;W5.parse=W5;var{options:RbZ,setOptions:PbZ,use:$bZ,walkTokens:TbZ,parseInline:VbZ}=W5;var CbZ=xq.parse,IbZ=fq.lex;Es();var zF8=G0(X8(),1),iy=r7.create({namespace:"caw:client:markdown"}),XF8=!1,KF8=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return"mmd-"+Math.random().toString(36).slice(2)+"-"+Date.now()},LH=(Z)=>{return(Z??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},vC6=new Set(["details","summary","pre","code","br","hr","img","b","svg","g","circle","rect","path","line","polygon","ellipse","polyline","text","tspan","textpath","defs","use","filter","fegaussianblur","animate","set","lineargradient","radialgradient","stop","mask","pattern","clippath","marker","symbol","title","desc"]),bC6=/<(\/?)([A-Za-z][A-Za-z0-9-]*)/g,fC6=(Z)=>{return Z.replace(bC6,(J,Q,X)=>{if(vC6.has(X.toLowerCase()))return J;return`<${Q}${X}`})},xC6="internal-link",hC6="noopener noreferrer",yC6="data-caw-safe",gC6="http://www.w3.org/1999/xhtml",mC6=(Z)=>Z.classList?.contains(xC6)||Z.getAttribute?.("rel")===hC6||Z.hasAttribute?.(yC6),uC6=(Z)=>{for(let J of Array.from(Z.querySelectorAll("a"))){if(J.namespaceURI&&J.namespaceURI!==gC6)continue;if(mC6(J))continue;let Q=J.parentNode;if(!Q)continue;while(J.firstChild)Q.insertBefore(J.firstChild,J);Q.removeChild(J)}},pC6=/^(.*?)\|(\d+)(?:x(\d+))?$/,cC6=({href:Z,title:J,text:Q})=>{try{let X=Q??"",K=Z??"",Y=pC6.exec(X),U=Y?Y[1]:X,z=` alt="${LH(U)}"`,W=J?` title="${LH(J)}"`:"";if(!K)return`<img${z}${W}>`;let G=` src="${LH(K)}"`;if(!Y)return`<img${G}${z}${W}>`;let q=Number(Y[2]),H=Y[3]!==void 0?Number(Y[3]):null;if(q===0)return`<img${G}${z}${W}>`;let B=` width="${q}"`,F=H!==null&&H!==0?` height="${H}"`:"";return`<img${G}${z}${B}${F}${W}>`}catch(X){return iy.error("Image render error:",X),'<img alt="">'}},I80=(Z)=>{return Z.toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim()},sy=(Z)=>Z?.split("#")[0]??"",D80=(Z)=>{let J=Z?.indexOf("#")??-1;return J>=0?Z.slice(J+1):null},_N0=(Z)=>{let J=sy(Z);if(J?.startsWith("?"))return new URLSearchParams(J).get("id");return null},KS=/^[A-Z][dtfsj]\d+$/,YF8=/^\/?documents\/.+/,UF8=/^\/?templates\/.+/,lC6=(Z)=>{if(!Z)return!1;if(Z.startsWith("#"))return!0;let J=sy(Z);if(KS.test(J)||YF8.test(J)||UF8.test(J))return!0;let Q=_N0(Z);return Q&&KS.test(Q)},dC6=(Z)=>{if(Z?.startsWith("#"))return"anchor";let J=sy(Z);if(KS.test(J))return"id";if(YF8.test(J)||UF8.test(J))return"path";let Q=_N0(Z);if(Q&&KS.test(Q))return"id";return null},kN0=/<svg(?:\s[^>]*)?>|<\/svg\s*>/gi,iC6=/^<svg[\s>]/i,sC6=/(?:^|\n)<svg[\s>]/i,nC6={name:"svgBlock",level:"block",start(Z){let J=sC6.exec(Z);if(!J)return;return J.index===0?0:J.index+1},tokenizer(Z){if(!iC6.test(Z))return;kN0.lastIndex=0;let J=0,Q;while((Q=kN0.exec(Z))!==null)if(J+=Q[0][1]==="/"?-1:1,J===0){let X=Z.slice(0,kN0.lastIndex);return{type:"svgBlock",raw:X,text:X}}return},renderer(Z){return Z.text}};W5.use({extensions:[nC6],walkTokens(Z){if(Z.type==="html"&&typeof Z.text==="string")Z.text=fC6(Z.text)}});var fQ=({markdown:Z,className:J="",onInternalLinkClick:Q,onRenderComplete:X,onDetailsOpen:K})=>{let Y=l2.useRef(null),U=l2.useRef(0),z=l2.useRef(new Set),W=l2.useRef(!1),G=T1(),q=l2.useMemo(()=>{let F=G.pathname.match(/\/project\/([^/]+)(?:\/store\/([^/]+))?/);return F?`${F[1]}/${F[2]||"A"}`:null},[G.pathname]),H=(F)=>{let M=F.target.closest("a.internal-link");if(!M)return;if(F.metaKey||F.ctrlKey||F.shiftKey||F.button!==0)return;if(M.closest("code, pre"))return;let A=M.getAttribute("data-link-type");if(A==="anchor"){F.preventDefault();let w=D80(M.getAttribute("href")),N=w?I80(w):null;Q?.({type:"anchor",id:null,path:null,anchor:N});return}if(A==="id"){let w=M.getAttribute("data-internal-id"),N=D80(M.getAttribute("href")),R=N?I80(N):null;if(w&&KS.test(w))F.preventDefault(),Q?.({type:"id",id:w,path:null,anchor:R})}else if(A==="path"){let w=M.getAttribute("data-internal-path"),N=D80(M.getAttribute("href")),R=N?I80(N):null;if(w&&/^\/(?:documents|templates)\/.+/.test(w))F.preventDefault(),Q?.({type:"path",id:null,path:w,anchor:R})}},B=l2.useMemo(()=>{try{let F=new W5.Renderer;F.code=({text:P,lang:V})=>{let $=((V??"").trim().split(" ")[0]??"").toLowerCase(),C=LH(P);if($==="mermaid")return`<pre class="mermaid" data-mermaid-id="${KF8()}">${C}</pre>`;return`<pre><code class="language-${$}">${C}</code></pre>`},F.link=function({href:P,title:V,tokens:$}){let C=this.parser.parseInline($),D=LH(P??""),E=V?` title="${LH(V)}"`:"";if(lC6(P)){let S=dC6(P);if(S==="anchor")return`<a href="${D}" class="internal-link" data-link-type="anchor"${E}>${C}</a>`;let f=S==="path"&&P&&!P.startsWith("/")?"/"+P:P,j=LH(f??""),v=S==="id"?KS.test(sy(P))?sy(P):_N0(P):null,b=D80(P),_=S==="id"?LH(Pq(v,G.pathname,b)?.url??P??""):LH(bj0(f,G.pathname)?.url??f??""),x=S==="id"?`data-internal-id="${LH(v)}"`:`data-internal-path="${j}"`;return`<a href="${_}" class="internal-link" data-link-type="${S}" ${x}${E}>${C}</a>`}return`<a href="${D}" target="_blank" rel="noopener noreferrer"${E}>${C}</a>`};let M=new Map,A=0;F.heading=function({tokens:P,depth:V}){let $=this.parser.parseInline(P),C=$.replace(/<[^>]+>/g,""),D=I80(C);if(!D)A++,D=`heading-${A}`;if(M.has(D)){let S=M.get(D);M.set(D,S+1),D=`${D}-${S}`}else M.set(D,1);let E=`h${V}`;return`<${E} id="${LH(D)}">${$}</${E}>`},F.image=cC6;let w=W5.parse(Z??"",{renderer:F,breaks:!0}),N=SB.sanitize(w,{RETURN_DOM_FRAGMENT:!0,ADD_TAGS:["pre","details","summary","animate","set"],ADD_ATTR:["class","data-mermaid-id","data-link-type","data-internal-id","data-internal-path","id","width","height","open","target","rel","from","to","calcmode","data-caw-safe"]});uC6(N);let R=document.createElement("div");return R.appendChild(N),R.innerHTML}catch(F){return iy.error("Markdown parse error:",F),""}},[Z,q]);return l2.useEffect(()=>{if(B)X?.()},[B,X]),l2.useEffect(()=>{if(!B)return;let F=!1,M=++U.current;return(async()=>{let A=Y.current;if(!A)return;let w=Array.from(A.querySelectorAll("pre.mermaid[data-mermaid-id]")),R=Array.from(A.querySelectorAll("pre > code.language-mermaid")).map((V)=>V.parentElement).filter(Boolean),P=[...w,...R];if(P.length===0)return;try{let V=await Promise.resolve().then(() => (QF8(),JF8)),$=V.default||V;if(!XF8)$.initialize({startOnLoad:!1,theme:"default",suppressErrorRendering:!0}),XF8=!0;let C=P.map(async(E)=>{let S=(E.textContent??"").trim();if(!S)return{el:E,svg:null,error:null};let f=E.getAttribute("data-mermaid-id")||KF8();try{let{svg:j}=await $.render(`render-${f}`,S);return{el:E,svg:j,error:null}}catch(j){return{el:E,svg:null,error:j}}}),D=await Promise.all(C);if(F||M!==U.current)return;for(let{el:E,svg:S,error:f}of D){if(!E)continue;if(f||!S){if(iy.warn("Mermaid render error:",f),E.classList.add("mermaid-error"),f){let j=document.createElement("span");j.className="mermaid-error-message";let v=f.message||f.toString();j.textContent=v?`Mermaid syntax error: ${v}`:"Mermaid syntax error",E.prepend(j)}continue}try{let j=document.createElement("div");j.className="mermaid-diagram",j.innerHTML=S,E.replaceWith(j)}catch(j){iy.warn("Mermaid DOM replace error:",j),E.classList.add("mermaid-error")}}}catch(V){iy.error("Mermaid initialization error:",V)}})(),()=>{F=!0}},[B]),l2.useEffect(()=>{let F=Y.current;if(!F)return;let M=(A)=>{if(!(A.target instanceof HTMLDetailsElement))return;let w=A.target.querySelector(":scope > summary");if(!w)return;let N=w.textContent;if(A.target.open){if(z.current.add(N),!W.current)K?.()}else z.current.delete(N)};return F.addEventListener("toggle",M,!0),()=>F.removeEventListener("toggle",M,!0)},[]),l2.useLayoutEffect(()=>{let F=Y.current;if(!F||z.current.size===0)return;W.current=!0;for(let M of F.querySelectorAll("details")){let A=M.querySelector(":scope > summary");if(!A)continue;if(z.current.has(A.textContent))M.open=!0}W.current=!1},[B]),zF8.jsxDEV("div",{ref:Y,className:`prose prose-sm max-w-none ${J}`,dangerouslySetInnerHTML:{__html:B},onClick:H},void 0,!1,void 0,this)};var qK=G0(X8(),1),S3=({open:Z,onOpenChange:J,value:Q="",onSave:X,projectId:K,storeCode:Y})=>{let[U,z]=ny.useState(Q);return ny.useEffect(()=>{if(Z)z(Q)},[Z,Q]),qK.jsxDEV(E7,{open:Z,onOpenChange:J,children:qK.jsxDEV(T7,{className:"max-w-6xl h-[85vh] flex flex-col",children:[qK.jsxDEV(A7,{className:"flex-shrink-0",children:qK.jsxDEV(N7,{children:"Edit Text"},void 0,!1,void 0,this)},void 0,!1,void 0,this),qK.jsxDEV(ji0,{defaultValue:"edit",className:"flex-1 flex flex-col min-h-0",children:[qK.jsxDEV(aY0,{className:"justify-start self-start",children:[qK.jsxDEV(zs,{value:"edit",children:"Edit"},void 0,!1,void 0,this),qK.jsxDEV(zs,{value:"preview",children:"Preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qK.jsxDEV(Ws,{value:"edit",className:"flex-1 min-h-0 flex flex-col",children:qK.jsxDEV("div",{className:"flex-1 min-h-0",children:qK.jsxDEV(eW,{value:U,onChange:z,projectId:K,storeCode:Y,path:"field-editor.md",height:"100%"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),qK.jsxDEV(Ws,{value:"preview",className:"flex-1 min-h-0",children:qK.jsxDEV("div",{className:"h-full p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:qK.jsxDEV(fQ,{markdown:U},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qK.jsxDEV(t7,{className:"flex-shrink-0",children:[qK.jsxDEV(c0,{variant:"outline",onClick:()=>{J?.(!1)},children:"Cancel"},void 0,!1,void 0,this),qK.jsxDEV(c0,{onClick:()=>{X?.(U)},children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var m$=G0(s0(),1);var gY=G0(X8(),1),ry=({value:Z,onChange:J,onSubmit:Q,fieldName:X,projectId:K,storeCode:Y,minHeight:U=120,maxHeight:z=400,readOnly:W=!1,autoFocus:G=!1,headerLeft:q=null})=>{let[H,B]=m$.useState("edit"),[F,M]=m$.useState(!1),[A,w]=m$.useState(""),N=m$.useCallback(()=>{w(Z??""),M(!0)},[Z]);if(W)return gY.jsxDEV("div",{className:"p-4 border border-border rounded-md bg-muted overflow-auto",style:{minHeight:U,maxHeight:z},children:gY.jsxDEV(fQ,{markdown:Z??""},void 0,!1,void 0,this)},void 0,!1,void 0,this);return gY.jsxDEV("div",{className:"flex flex-col w-full",children:[gY.jsxDEV("div",{className:"flex items-center justify-between mb-1.5",children:[gY.jsxDEV("div",{className:"flex items-center gap-2",children:q},void 0,!1,void 0,this),gY.jsxDEV("div",{className:"flex items-center gap-1.5",children:[gY.jsxDEV("div",{className:"flex items-center rounded-lg bg-muted p-0.5",children:[gY.jsxDEV("button",{type:"button",onClick:()=>B("edit"),className:`px-3 py-1 text-xs font-medium rounded-md transition-all ${H==="edit"?"bg-background text-foreground shadow-sm border border-border":"text-muted-foreground hover:text-foreground border border-transparent"}`,children:"Edit"},void 0,!1,void 0,this),gY.jsxDEV("button",{type:"button",onClick:()=>B("preview"),className:`px-3 py-1 text-xs font-medium rounded-md transition-all ${H==="preview"?"bg-background text-foreground shadow-sm border border-border":"text-muted-foreground hover:text-foreground border border-transparent"}`,children:"Preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),gY.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:N,"aria-label":"Open in editor",children:gY.jsxDEV(XA,{className:"h-3.5 w-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H==="edit"?gY.jsxDEV(eW,{value:Z??"",onChange:J,onSubmit:Q,projectId:K,storeCode:Y,path:`template-param-${X}.md`,autoGrow:!0,lineNumbers:"off",minHeight:U,maxHeight:z,autoFocus:G},void 0,!1,void 0,this):gY.jsxDEV("div",{className:"p-4 border border-border rounded-md bg-muted overflow-auto",style:{minHeight:U,maxHeight:z},children:gY.jsxDEV(fQ,{markdown:Z??""},void 0,!1,void 0,this)},void 0,!1,void 0,this),gY.jsxDEV(S3,{open:F,onOpenChange:M,value:A,onSave:(R)=>{J?.(R),M(!1)},projectId:K,storeCode:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var j3=G0(X8(),1),bN0=({value:Z,onChange:J,fieldDef:Q,readOnly:X,projectId:K,storeCode:Y,className:U,mode:z="textarea"})=>{let[W,G]=vN0.useState(!1),q=Q.rows??3;if(z==="monaco"){let H=Q.description?j3.jsxDEV("span",{className:"text-sm text-muted-foreground",children:Q.description},void 0,!1,void 0,this):null;return j3.jsxDEV("div",{className:a8("relative",U),children:j3.jsxDEV(ry,{value:Z??"",onChange:J,fieldName:Q.name,projectId:K,storeCode:Y,readOnly:X,headerLeft:H},void 0,!1,void 0,this)},void 0,!1,void 0,this)}if(X)return j3.jsxDEV("div",{className:a8("text-sm p-2 rounded-md border border-transparent",U),style:{height:`${q*1.5}rem`,overflowY:"auto"},children:Z||""},void 0,!1,void 0,this);return j3.jsxDEV("div",{className:a8("relative",U),children:[j3.jsxDEV(eF,{value:Z??"",onChange:(H)=>J(H.target.value),rows:q,className:"pr-8"},void 0,!1,void 0,this),j3.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-6 w-6",onClick:()=>G(!0),"aria-label":"Open in editor",children:j3.jsxDEV(XA,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),j3.jsxDEV(S3,{open:W,onOpenChange:G,value:Z??"",onSave:(H)=>{J(H),G(!1)},projectId:K,storeCode:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var rC6=G0(s0(),1);var fN0=G0(X8(),1),xN0=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q){let K=Z!=null?new Intl.NumberFormat().format(Z):"";return fN0.jsxDEV("span",{className:a8("text-sm",X),children:K},void 0,!1,void 0,this)}return fN0.jsxDEV(yZ,{type:"number",step:"1",value:Z??"",onChange:(K)=>J(K.target.value),className:X},void 0,!1,void 0,this)};var aC6=G0(s0(),1);var hN0=G0(X8(),1),yN0=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q){let K=Z!=null?new Intl.NumberFormat().format(Z):"";return hN0.jsxDEV("span",{className:a8("text-sm",X),children:K},void 0,!1,void 0,this)}return hN0.jsxDEV(yZ,{type:"number",step:"any",value:Z??"",onChange:(K)=>J(K.target.value),className:X},void 0,!1,void 0,this)};var E80=G0(s0(),1);var ay="",oy=()=>({"Content-Type":"application/json","X-Session-Id":D7()});async function WF8(Z,J){let Q=J[1];switch(Q){case"d":case"t":{let X=await fetch(`${ay}/api/p/${Z}/documents/${J}`,{headers:oy()}),K=await X6(X,"Failed to fetch entity metadata");return{name:K.name,type:K.type,subtype:K.subtype??null}}case"f":{let X=await fetch(`${ay}/api/p/${Z}/folders/${J}`,{headers:oy()}),K=await X6(X,"Failed to fetch entity metadata");return{name:K.name,type:"f",subtype:K.subtype??null}}case"s":{let X=await fetch(`${ay}/api/p/${Z}/stories/${J}`,{headers:oy()});return{name:(await X6(X,"Failed to fetch entity metadata")).name,type:"s",subtype:null}}case"j":{let X=await fetch(`${ay}/api/p/${Z}/jobs/${J}`,{headers:oy()});return{name:(await X6(X,"Failed to fetch entity metadata")).name,type:"j",subtype:null}}case"e":{let X=await fetch(`${ay}/api/p/${Z}/tracks/${J}`,{headers:oy()});return{name:(await X6(X,"Failed to fetch entity metadata")).name,type:"e",subtype:"track"}}default:throw Error(`Unrecognised entity type code: ${Q} (entity ID: ${J})`)}}function YM(Z,J){return k7({queryKey:["entityMetadata",Z,J],queryFn:()=>WF8(Z,J),enabled:!!J,staleTime:300000,gcTime:1800000})}var oC6={d:{default:{icon:gX,draftIcon:aH},task:{icon:$W,draftIcon:uk},cartridge:{icon:LV,draftIcon:LV},scratch:{icon:MV,draftIcon:MV}},t:{default:{icon:Y2,draftIcon:aH},prompt:{icon:DK,draftIcon:DK},"saved-search":{icon:tM,draftIcon:tM}},f:{default:{icon:$z,openIcon:iw,loadingIcon:O9},tasks:{icon:sk}},j:{default:{icon:ZX}},e:{default:{icon:BJ},track:{icon:BJ}},s:{default:{icon:xX}}};function M5(Z,J,{hasDraft:Q,isOpen:X,isLoading:K}={}){let Y=oC6[Z];if(!Y)return gX;let U=Y[J]||Y.default;if(!U)return gX;if(Z==="f"){if(K&&U.loadingIcon)return U.loadingIcon;if(X&&U.openIcon)return U.openIcon;return U.icon}if(Q&&U.draftIcon)return U.draftIcon;return U.icon}var GJ=G0(X8(),1),GF8=({entityId:Z,projectId:J})=>{let{data:Q,isLoading:X,isError:K}=YM(J,Z);if(!Z)return null;if(X||K||!Q)return GJ.jsxDEV("span",{className:"text-sm text-muted-foreground font-mono",children:Z},void 0,!1,void 0,this);let Y=M5(Q.type,Q.subtype);return GJ.jsxDEV("span",{className:"inline-flex items-center gap-1.5 text-sm",children:[GJ.jsxDEV(Y,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),GJ.jsxDEV("span",{children:Q.name},void 0,!1,void 0,this),GJ.jsxDEV("span",{className:"text-xs text-muted-foreground font-mono",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},tC6=({value:Z,onChange:J,projectId:Q,className:X,externalError:K,onValidationChange:Y,paramName:U})=>{let z=typeof Z==="string"?Z.trim():Z,W=z!==null&&z!==void 0&&z!=="",{data:G,isLoading:q,isError:H}=YM(Q,W?z:null),B=W&&!q&&(H||!G),F=!!K||B,M=K||(B?`Entity '${z}' not found`:null);return E80.useEffect(()=>{if(!Y)return;Y(U,!F,F?M:null)},[Y,U,F,M]),E80.useEffect(()=>{return()=>{if(Y)Y(U,!0,null)}},[Y,U]),GJ.jsxDEV("div",{className:a8("space-y-1",X),children:[GJ.jsxDEV(yZ,{type:"text",value:Z??"",onChange:(A)=>J(A.target.value),placeholder:"Entity ID (e.g. Ad123)",className:F?"border-destructive focus-visible:ring-destructive":void 0,"aria-invalid":F||void 0},void 0,!1,void 0,this),W&&!F&&GJ.jsxDEV(GF8,{entityId:z,projectId:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};function eC6(Z){let J=new Map;for(let Q of Z){let X=Q.group??"";if(!J.has(X))J.set(X,[]);J.get(X).push(Q)}return Array.from(J.entries()).map(([Q,X])=>({group:Q,items:X}))}var gN0=({value:Z,onChange:J,readOnly:Q,fieldDef:X,isLoading:K,projectId:Y,className:U,error:z,onValidationChange:W})=>{if(Q)return GJ.jsxDEV("div",{className:a8(U),children:GJ.jsxDEV(GF8,{entityId:Z,projectId:Y},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(K)return GJ.jsxDEV(g7,{disabled:!0,children:[GJ.jsxDEV(_7,{className:a8("w-full",U),children:GJ.jsxDEV(m7,{placeholder:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),GJ.jsxDEV(v7,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(X?.allowed?.options){let G=eC6(X.allowed.options),q=G.length>1;return GJ.jsxDEV(g7,{value:Z||"",onValueChange:J,children:[GJ.jsxDEV(_7,{className:a8("w-full",U),children:GJ.jsxDEV(m7,{placeholder:"Select..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),GJ.jsxDEV(v7,{children:q?G.map(({group:H,items:B})=>GJ.jsxDEV(AU,{children:[GJ.jsxDEV(G2,{children:H},void 0,!1,void 0,this),B.map((F)=>GJ.jsxDEV(l9,{value:F.value,children:F.label},F.value,!1,void 0,this))]},H,!0,void 0,this)):G.flatMap(({items:H})=>H.map((B)=>GJ.jsxDEV(l9,{value:B.value,children:B.label},B.value,!1,void 0,this)))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}return GJ.jsxDEV(tC6,{value:Z,onChange:J,projectId:Y,className:U,externalError:z,onValidationChange:W,paramName:X?.name},void 0,!1,void 0,this)};var YI6=G0(s0(),1);var LF8=G0(s0(),1);var d2=G0(s0(),1);var JW=G0(VZ(),1),S80="Checkbox",[ZI6,nO1]=n5(S80),[JI6,mN0]=ZI6(S80);function QI6(Z){let{__scopeCheckbox:J,checked:Q,children:X,defaultChecked:K,disabled:Y,form:U,name:z,onCheckedChange:W,required:G,value:q="on",internal_do_not_use_render:H}=Z,[B,F]=n4({prop:Q,defaultProp:K??!1,onChange:W,caller:S80}),[M,A]=d2.useState(null),[w,N]=d2.useState(null),R=d2.useRef(!1),P=M?!!U||!!M.closest("form"):!0,V={checked:B,disabled:Y,setChecked:F,control:M,setControl:A,name:z,form:U,value:q,hasConsumerStoppedPropagationRef:R,required:G,defaultChecked:_N(K)?!1:K,isFormControl:P,bubbleInput:w,setBubbleInput:N};return JW.jsx(JI6,{scope:J,...V,children:XI6(H)?H(V):X})}var qF8="CheckboxTrigger",HF8=d2.forwardRef(({__scopeCheckbox:Z,onKeyDown:J,onClick:Q,...X},K)=>{let{control:Y,value:U,disabled:z,checked:W,required:G,setControl:q,setChecked:H,hasConsumerStoppedPropagationRef:B,isFormControl:F,bubbleInput:M}=mN0(qF8,Z),A=QZ(K,q),w=d2.useRef(W);return d2.useEffect(()=>{let N=Y?.form;if(N){let R=()=>H(w.current);return N.addEventListener("reset",R),()=>N.removeEventListener("reset",R)}},[Y,H]),JW.jsx(f9.button,{type:"button",role:"checkbox","aria-checked":_N(W)?"mixed":W,"aria-required":G,"data-state":MF8(W),"data-disabled":z?"":void 0,disabled:z,value:U,...X,ref:A,onKeyDown:l6(J,(N)=>{if(N.key==="Enter")N.preventDefault()}),onClick:l6(Q,(N)=>{if(H((R)=>_N(R)?!0:!R),M&&F){if(B.current=N.isPropagationStopped(),!B.current)N.stopPropagation()}})})});HF8.displayName=qF8;var uN0=d2.forwardRef((Z,J)=>{let{__scopeCheckbox:Q,name:X,checked:K,defaultChecked:Y,required:U,disabled:z,value:W,onCheckedChange:G,form:q,...H}=Z;return JW.jsx(QI6,{__scopeCheckbox:Q,checked:K,defaultChecked:Y,disabled:z,required:U,onCheckedChange:G,name:X,form:q,value:W,internal_do_not_use_render:({isFormControl:B})=>JW.jsxs(JW.Fragment,{children:[JW.jsx(HF8,{...H,ref:J,__scopeCheckbox:Q}),B&&JW.jsx(OF8,{__scopeCheckbox:Q})]})})});uN0.displayName=S80;var BF8="CheckboxIndicator",pN0=d2.forwardRef((Z,J)=>{let{__scopeCheckbox:Q,forceMount:X,...K}=Z,Y=mN0(BF8,Q);return JW.jsx(bJ,{present:X||_N(Y.checked)||Y.checked===!0,children:JW.jsx(f9.span,{"data-state":MF8(Y.checked),"data-disabled":Y.disabled?"":void 0,...K,ref:J,style:{pointerEvents:"none",...Z.style}})})});pN0.displayName=BF8;var FF8="CheckboxBubbleInput",OF8=d2.forwardRef(({__scopeCheckbox:Z,...J},Q)=>{let{control:X,hasConsumerStoppedPropagationRef:K,checked:Y,defaultChecked:U,required:z,disabled:W,name:G,value:q,form:H,bubbleInput:B,setBubbleInput:F}=mN0(FF8,Z),M=QZ(Q,F),A=vl(Y),w=vp(X);d2.useEffect(()=>{let R=B;if(!R)return;let P=window.HTMLInputElement.prototype,$=Object.getOwnPropertyDescriptor(P,"checked").set,C=!K.current;if(A!==Y&&$){let D=new Event("click",{bubbles:C});R.indeterminate=_N(Y),$.call(R,_N(Y)?!1:Y),R.dispatchEvent(D)}},[B,A,Y,K]);let N=d2.useRef(_N(Y)?!1:Y);return JW.jsx(f9.input,{type:"checkbox","aria-hidden":!0,defaultChecked:U??N.current,required:z,disabled:W,name:G,value:q,form:H,...J,tabIndex:-1,ref:M,style:{...J.style,...w,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});OF8.displayName=FF8;function XI6(Z){return typeof Z==="function"}function _N(Z){return Z==="indeterminate"}function MF8(Z){return _N(Z)?"indeterminate":Z?"checked":"unchecked"}var j80=G0(X8(),1),HK=LF8.forwardRef(({className:Z,...J},Q)=>j80.jsxDEV(uN0,{ref:Q,className:a8("peer h-4 w-4 shrink-0 rounded-sm border border-primary disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",Z),...J,children:j80.jsxDEV(pN0,{className:a8("flex items-center justify-center text-current"),children:j80.jsxDEV(hX,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this));HK.displayName="Checkbox";var cN0=G0(X8(),1),lN0=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q)return cN0.jsxDEV("span",{className:a8("text-sm",X),children:Z?"Yes":"No"},void 0,!1,void 0,this);return cN0.jsxDEV(HK,{checked:!!Z,onCheckedChange:(K)=>J(K),className:X},void 0,!1,void 0,this)};var UI6=G0(s0(),1);var dN0=G0(X8(),1),k80=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q){let K=Z;try{if(Z)K=JSON.stringify(JSON.parse(Z),null,2)}catch{}return dN0.jsxDEV("pre",{className:a8("text-sm font-mono whitespace-pre-wrap",X),children:K??""},void 0,!1,void 0,this)}return dN0.jsxDEV(eF,{value:Z??"",onChange:(K)=>J(K.target.value),className:a8("font-mono",X)},void 0,!1,void 0,this)};var XW=G0(s0(),1);var vN="",bN=()=>({"Content-Type":"application/json","X-Session-Id":D7()}),_80=async(Z,{store:J}={})=>{let Q=new URLSearchParams;if(J)Q.set("store",J);let X=Q.toString(),K=`${vN}/api/p/${Z}/tracks${X?`?${X}`:""}`,Y=await fetch(K,{headers:bN()});return X6(Y,"Failed to list tracks")},AF8=async(Z,{store:J,name:Q,states:X})=>{let K=await fetch(`${vN}/api/p/${Z}/tracks`,{method:"POST",headers:bN(),body:JSON.stringify({store:J,name:Q,states:X})});return X6(K,"Failed to create track")},NF8=async(Z,J,{name:Q,states:X,renames:K})=>{let Y=await fetch(`${vN}/api/p/${Z}/tracks/${J}`,{method:"PUT",headers:bN(),body:JSON.stringify({name:Q,states:X,renames:K})});return X6(Y,"Failed to update track")},wF8=async(Z,J)=>{let Q=await fetch(`${vN}/api/p/${Z}/tracks/${J}`,{method:"DELETE",headers:bN()});return X6(Q,"Failed to delete track")},v80=async()=>{let Z=await fetch(`${vN}/api/shared/tracks`,{headers:bN()});return X6(Z,"Failed to list shared tracks")},RF8=async({name:Z,states:J})=>{let Q=await fetch(`${vN}/api/shared/tracks`,{method:"POST",headers:bN(),body:JSON.stringify({name:Z,states:J})});return X6(Q,"Failed to create shared track")},PF8=async(Z,{name:J,states:Q,renames:X})=>{let K=await fetch(`${vN}/api/shared/tracks/${Z}`,{method:"PUT",headers:bN(),body:JSON.stringify({name:J,states:Q,renames:X})});return X6(K,"Failed to update shared track")},$F8=async(Z)=>{let J=await fetch(`${vN}/api/shared/tracks/${Z}`,{method:"DELETE",headers:bN()});return X6(J,"Failed to delete shared track")};var k3=(Z,{store:J}={})=>{let Q=!Z&&J==="B";return k7({queryKey:Q?["tracks","shared",J??"demux"]:["tracks",Z,J??"demux"],queryFn:()=>Q?v80():_80(Z,{store:J}),enabled:!!Z||Q,staleTime:30000})},TF8=(Z)=>{let J=i6();return s9({mutationFn:({store:Q,name:X,states:K})=>Z?AF8(Z,{store:Q,name:X,states:K}):RF8({name:X,states:K}),onSuccess:(Q,{store:X})=>{if(Z)J.invalidateQueries({queryKey:["tracks",Z,X??"demux"]});else J.invalidateQueries({queryKey:["tracks","shared"]})}})},VF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,name:X,states:K,renames:Y})=>Z?NF8(Z,Q,{name:X,states:K,renames:Y}):PF8(Q,{name:X,states:K,renames:Y}),onSuccess:()=>{if(Z)J.invalidateQueries({queryKey:["tracks",Z]}),J.invalidateQueries({queryKey:["stories",Z]}),J.invalidateQueries({queryKey:["fields",Z]}),J.invalidateQueries({predicate:(Q)=>Q.queryKey[0]==="templatesByType"&&Q.queryKey[1]===Z});else J.invalidateQueries({queryKey:["tracks","shared"]})}})},CF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q})=>Z?wF8(Z,Q):$F8(Q),onSuccess:()=>{if(Z)J.invalidateQueries({queryKey:["tracks",Z]});else J.invalidateQueries({queryKey:["tracks","shared"]})}})},QW=(Z,J)=>{if(!Z)return"";let Q=(J||[]).find((X)=>X.id===Z);if(!Q)return Z;return Q.name};var T6=G0(X8(),1);var IF8=["waiting","ready","in-progress","done"],DF8=["usage-resumption"],EF8={s:{label:"Stories",visibilityKey:"story"},"d/task":{label:"Tasks",visibilityKey:"task"},j:{label:"Jobs",visibilityKey:"job"}},zI6=(Z)=>{if(!Z)return{ok:!0,data:{}};try{let J=JSON.parse(Z);if(!J||typeof J!=="object"||Array.isArray(J))return{ok:!1,error:"Expected an object"};let Q=J.visibility;if(Q!==void 0&&(typeof Q!=="object"||Array.isArray(Q)||Q===null))return{ok:!1,error:"visibility must be an object"};return{ok:!0,data:Q??{}}}catch(J){return{ok:!1,error:`Invalid JSON: ${J.message}`}}},WI6=(Z)=>{let J={},Q=Z.story;if(Q&&typeof Q==="object"){let Y=Object.entries(Q).filter(([,U])=>Array.isArray(U)&&U.length>0);if(Y.length>0)J.story=Object.fromEntries(Y)}let X=Z.task;if(X&&Array.isArray(X._stages)&&X._stages.length>0)J.task={_stages:X._stages};let K=Z.job;if(K&&Array.isArray(K._contexts)&&K._contexts.length>0)J.job={_contexts:K._contexts};if(Object.keys(J).length===0)return null;return JSON.stringify({visibility:J})},GI6=(Z,J)=>{if(!J)return"None";if(Z==="story"){let Q=Object.keys(J).length;return Q>0?`${Q} track${Q!==1?"s":""}`:"None"}if(Z==="task"){let Q=Array.isArray(J._stages)?J._stages.length:0;return Q>0?`${Q} stage${Q!==1?"s":""}`:"None"}if(Z==="job"){let Q=Array.isArray(J._contexts)?J._contexts.length:0;return Q>0?`${Q} context${Q!==1?"s":""}`:"None"}return"None"},qI6=(Z,J)=>{if(!J)return!1;if(Z==="story")return Object.values(J).some((Q)=>Array.isArray(Q)&&Q.length>0);if(Z==="task")return Array.isArray(J._stages)&&J._stages.length>0;if(Z==="job")return Array.isArray(J._contexts)&&J._contexts.length>0;return!1},SF8=({value:Z,onChange:J,editable:Q,className:X,projectId:K,storeCode:Y})=>{let U=XW.useMemo(()=>zI6(Z),[Z]),[z,W]=XW.useState(()=>U.ok?U.data:{}),[G,q]=XW.useState(!1),[H,B]=XW.useState(null),[F,M]=XW.useState(null),[A,w]=XW.useState(null);XW.useEffect(()=>{if(U.ok)W(U.data)},[Z]);let{data:N=[]}=k3(G?K:null,{store:"all"}),R=XW.useCallback((e)=>{if(q(e),!e)B(null),M(null)},[]),P=(e)=>{W(e),J(WI6(e))};if(!U.ok)return T6.jsxDEV("div",{className:a8("space-y-1",X),children:T6.jsxDEV("p",{className:"text-xs text-destructive",children:U.error},void 0,!1,void 0,this)},void 0,!1,void 0,this);let V=(e)=>{let r={...z};delete r[e],P(r),w(null)},$=(e)=>{M(e),B("story-stages")},C=(e)=>{let r={...z.story||{}};delete r[e],P({...z,story:r})},D=(e)=>{M(e),B("story-stages")},E=(e,r,W0)=>{let t=Array.isArray(z.story?.[e])?z.story[e]:[],U0=W0?[...t,r]:t.filter((o)=>o!==r),n={...z.story||{}};if(U0.length===0)delete n[e];else n[e]=U0;P({...z,story:n})},S=(e,r)=>{let W0=Array.isArray(z.task?._stages)?z.task._stages:[],t=r?[...W0,e]:W0.filter((U0)=>U0!==e);P({...z,task:{_stages:t}})},f=(e,r)=>{let W0=Array.isArray(z.job?._contexts)?z.job._contexts:[],t=r?[...W0,e]:W0.filter((U0)=>U0!==e);P({...z,job:{_contexts:t}})},j=Object.keys(z.story||{}),b=(Y==="B"?N.filter((e)=>e.storeCode==="B"):N).filter((e)=>!j.includes(e.id)),x=N.find((e)=>e.id===F)?.states||[],h=Array.isArray(z.story?.[F])?z.story[F]:[],u=()=>T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{children:[T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Visibility Configuration"},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Prompt will be available from:"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("div",{className:"space-y-1",children:Object.entries(EF8).map(([,{label:e,visibilityKey:r}])=>{let W0=z[r],t=qI6(r,W0);return T6.jsxDEV("div",{className:"flex items-center gap-1",children:[T6.jsxDEV("button",{type:"button",className:"flex items-center gap-1 text-sm text-left px-2 py-1.5 rounded hover:bg-accent",onClick:()=>B(r==="story"?"story":r),children:[T6.jsxDEV("span",{children:e},void 0,!1,void 0,this),T6.jsxDEV(IZ,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("span",{className:"flex-1 text-xs text-muted-foreground",children:GI6(r,W0)},void 0,!1,void 0,this),t&&Q&&T6.jsxDEV("button",{type:"button",className:"p-1 text-muted-foreground hover:text-destructive",onClick:()=>w(r),"aria-label":`Remove ${e} visibility`,children:T6.jsxDEV(iZ,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},r,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m=()=>T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>B(null),children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Story Visibility"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Select a track to view stages"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1",children:[j.map((e)=>{let r=Array.isArray(z.story[e])?z.story[e].length:0,W0=(N||[]).find((U0)=>U0.id===e),t=W0?W0.name:QW(e,N);return T6.jsxDEV("div",{className:"flex items-center gap-1",children:[T6.jsxDEV("button",{type:"button",className:"flex items-center gap-1 text-sm text-left px-2 py-1.5 rounded hover:bg-accent",onClick:()=>$(e),children:[W0&&T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:t},void 0,!1,void 0,this),W0&&T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[W0.storeCode]||S7.A}`,children:W0.id},void 0,!1,void 0,this),T6.jsxDEV(IZ,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("span",{className:"flex-1 text-xs text-muted-foreground",children:[r," stage",r!==1?"s":""]},void 0,!0,void 0,this),Q&&T6.jsxDEV("button",{type:"button",className:"p-1 text-muted-foreground hover:text-destructive",onClick:()=>C(e),"aria-label":`Remove ${t} track`,children:T6.jsxDEV(iZ,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},e,!0,void 0,this)}),j.length===0&&T6.jsxDEV("p",{className:"text-xs text-muted-foreground italic px-2",children:"No tracks configured"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&b.length>0&&T6.jsxDEV("div",{className:"border-t pt-2",children:[T6.jsxDEV("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Add track"},void 0,!1,void 0,this),T6.jsxDEV(g7,{value:"",onValueChange:D,children:[T6.jsxDEV(_7,{className:"h-7 text-xs",children:T6.jsxDEV(m7,{placeholder:"Select..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV(v7,{children:[b.filter((e)=>e.storeCode!=="B").length>0&&T6.jsxDEV(AU,{children:[T6.jsxDEV(G2,{children:"Project"},void 0,!1,void 0,this),b.filter((e)=>e.storeCode!=="B").map((e)=>T6.jsxDEV(l9,{value:e.id,children:T6.jsxDEV("span",{className:"inline-flex items-center gap-1.5",children:[T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:e.name},void 0,!1,void 0,this),T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[e.storeCode]||S7.A}`,children:e.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},e.id,!1,void 0,this))]},void 0,!0,void 0,this),b.filter((e)=>e.storeCode==="B").length>0&&T6.jsxDEV(AU,{children:[T6.jsxDEV(G2,{children:"Shared"},void 0,!1,void 0,this),b.filter((e)=>e.storeCode==="B").map((e)=>T6.jsxDEV(l9,{value:e.id,children:T6.jsxDEV("span",{className:"inline-flex items-center gap-1.5",children:[T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:e.name},void 0,!1,void 0,this),T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[e.storeCode]||S7.A}`,children:e.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},e.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y=()=>{let e=x.length,r=h.length;return T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>{B("story"),M(null)},children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:(()=>{let W0=(N||[]).find((U0)=>U0.id===F),t=W0?W0.name:QW(F,N);return T6.jsxDEV(T6.Fragment,{children:["Track:",W0&&T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:t},void 0,!1,void 0,this),W0&&T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[W0.storeCode]||S7.A}`,children:W0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Prompt visible for these stages"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1.5 max-h-64 overflow-y-auto",children:[x.map((W0)=>T6.jsxDEV("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[T6.jsxDEV("input",{type:"checkbox",checked:h.includes(W0),onChange:(t)=>Q&&E(F,W0,t.target.checked),disabled:!Q,className:"rounded"},void 0,!1,void 0,this),W0]},W0,!0,void 0,this)),e===0&&T6.jsxDEV("p",{className:"text-xs text-muted-foreground italic",children:"No stages defined for this track"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e>0&&T6.jsxDEV("p",{className:"text-xs text-muted-foreground border-t pt-1",children:[r," of ",e," selected"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},p=()=>{let e=Array.isArray(z.task?._stages)?z.task._stages:[];return T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>B(null),children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Task Visibility"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Prompt visible for these stages"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1.5",children:IF8.map((r)=>T6.jsxDEV("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[T6.jsxDEV("input",{type:"checkbox",checked:e.includes(r),onChange:(W0)=>Q&&S(r,W0.target.checked),disabled:!Q,className:"rounded"},void 0,!1,void 0,this),r]},r,!0,void 0,this))},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground border-t pt-1",children:[e.length," of ",IF8.length," selected"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},l=()=>{let e=Array.isArray(z.job?._contexts)?z.job._contexts:[];return T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>B(null),children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Job Visibility"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Prompt visible for these contexts"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1.5",children:DF8.map((r)=>T6.jsxDEV("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[T6.jsxDEV("input",{type:"checkbox",checked:e.includes(r),onChange:(W0)=>Q&&f(r,W0.target.checked),disabled:!Q,className:"rounded"},void 0,!1,void 0,this),r]},r,!0,void 0,this))},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground border-t pt-1",children:[e.length," of ",DF8.length," selected"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},d=()=>{let e=H==="story"||H==="story-stages",r=H==="story-stages",W0=e||H==="task"||H==="job";return T6.jsxDEV("div",{className:"relative",children:[T6.jsxDEV("div",{className:"p-4 w-52",children:u()},void 0,!1,void 0,this),W0&&T6.jsxDEV("div",{className:"absolute top-0 left-full flex items-start",style:{marginLeft:"20px",gap:"20px"},children:[e&&T6.jsxDEV("div",{className:"p-4 w-80 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:m()},void 0,!1,void 0,this),H==="task"&&T6.jsxDEV("div",{className:"p-4 w-80 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:p()},void 0,!1,void 0,this),H==="job"&&T6.jsxDEV("div",{className:"p-4 w-80 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:l()},void 0,!1,void 0,this),r&&T6.jsxDEV("div",{className:"p-4 w-64 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:y()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},Z0=(e)=>{return Object.values(EF8).find((W0)=>W0.visibilityKey===e)?.label??e};return T6.jsxDEV(T6.Fragment,{children:[T6.jsxDEV("div",{className:a8(X),children:T6.jsxDEV(jK,{open:G,onOpenChange:R,children:[T6.jsxDEV(kK,{asChild:!0,children:T6.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",children:"View/Edit Config"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV(sX,{className:"w-auto p-0 overflow-visible",align:"start",side:"top",sideOffset:48,children:d()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV(E7,{open:A!==null,onOpenChange:(e)=>{if(!e)w(null)},children:T6.jsxDEV(T7,{children:[T6.jsxDEV(A7,{children:T6.jsxDEV(N7,{children:["Remove ",Z0(A)," visibility settings?"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"This will clear all visibility rules for this type. This cannot be undone."},void 0,!1,void 0,this),T6.jsxDEV(t7,{children:[T6.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",onClick:()=>w(null),children:"Cancel"},void 0,!1,void 0,this),T6.jsxDEV(c0,{type:"button",variant:"destructive",size:"sm",onClick:()=>V(A),children:"Remove"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var OI6=G0(s0(),1);var jF8=G0(s0(),1);var HI6=r7.create({namespace:"caw:perf:publish"});var AH=(Z,J)=>{return k7({queryKey:["document",J],queryFn:()=>bz(Z,J),enabled:!!Z&&!!J})},fN=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,content:X})=>gv(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]})}})},YS=(Z)=>{let J=i6(),Q=jF8.useRef(0);return s9({mutationFn:async({id:X})=>{let K=performance.now(),Y=await xl0(Z,X);return Q.current=Math.round(performance.now()-K),Y},onSuccess:async(X,{id:K})=>{let Y=Q.current,U=performance.now(),W=await Promise.all([{label:"document",queryKey:["document",K]},{label:"documents",queryKey:["documents"]},{label:"versions",queryKey:["versions",K]},{label:"parameters",queryKey:["parameters",K]}].map(async({label:H,queryKey:B})=>{let F=performance.now();return await J.invalidateQueries({queryKey:B}),{label:H,ms:Math.round(performance.now()-F)}})),G=Math.round(performance.now()-U),q=Y+G;if(q>=300){let H=W.map((B)=>`${B.label}=${B.ms}`).join(" ");HI6.warn("PERF_PUBLISH_CLIENT id=%s totalMs=%d requestMs=%d refetchMs=%d %s",K,q,Y,G,H)}}})},US=(Z)=>{let J=i6();return s9({mutationFn:({id:Q})=>hl0(Z,Q),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]})}})},xN=(Z,J)=>{return k7({queryKey:["versions",J],queryFn:()=>yl0(Z,J),enabled:!!Z&&!!J})},kF8=(Z,J,{enabled:Q}={})=>{return k7({queryKey:["incomingReferences",J],queryFn:()=>gl0(Z,J),enabled:!!Q&&!!Z&&!!J})},zS=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,ack:X})=>XP(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["versions",X]}),J.invalidateQueries({queryKey:["folderContents"]})}})},u$=(Z)=>{let J=i6();return s9({mutationFn:({parentId:Q,name:X,content:K,subtype:Y,fields:U})=>qI(Z,{parentId:Q,name:X,content:K,subtype:Y,fields:U}),onSuccess:()=>{J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]})}})},_F8=(Z)=>{let J=i6();return s9({mutationFn:({parentId:Q,name:X,content:K,subtype:Y,fields:U})=>fl0(Z,{parentId:Q,name:X,content:K,subtype:Y,fields:U}),onSuccess:()=>{J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]})}})},WS=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,path:X,parentId:K})=>mv(Z,Q,{path:X,parentId:K}),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]})}})},b80=(Z,J)=>{return k7({queryKey:["parameters",J],queryFn:()=>ml0(Z,J),enabled:!!Z&&!!J,select:(Q)=>{let X=Q?.parameters?Object.entries(Q.parameters).map(([w,N])=>({name:w,...N})):[],K=Q?.target==="stdout"?"clipboard":Q?.target||null,Y=Q?.targetPath||null,U=Q?.path||null,z=Q?.targetParentId||null,W=Q?.targetName||null,G=Q?.targetRoot||null,q=Q?.targetStore||null,H=Q?.targetConfig||null,B=Q?.skipDialog??!1,F=Q?.targetFields||null,M=Q?.targetSubtype||null,A=Q?.templateSubtype||null;return{parameters:X,target:K,targetPath:Y,path:U,targetParentId:z,targetName:W,targetRoot:G,targetStore:q,targetConfig:H,skipDialog:B,targetFields:F,targetSubtype:M,templateSubtype:A}}})},vF8=(Z)=>{return s9({mutationFn:({id:J,params:Q,target:X,targetOptions:K})=>ul0(Z,J,{params:Q,target:X,targetOptions:K})})},BI6=(Z,J,{store:Q,storyId:X}={})=>["templatesByType",Z,J,Q??"A",X??null],i2=(Z,J,{store:Q,storyId:X}={})=>{return k7({queryKey:BI6(Z,J,{store:Q,storyId:X}),queryFn:()=>pl0(Z,J,{store:Q,storyId:X}),enabled:!!Z&&!!J})},bF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,subtype:X,fields:K})=>ll0(Z,Q,{subtype:X,fields:K}),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]}),J.invalidateQueries({queryKey:["fields",Z,X]})}})},fF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q})=>dl0(Z,Q),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]}),J.invalidateQueries({queryKey:["fields",Z,X]})}})};function s2(Z,J,Q={},{missingSectionMode:X="hidden"}={}){return Z.filter((K)=>FI6(K,J,Q,X))}function FI6(Z,J,Q,X){let{config:K}=Z;if(!K)return!1;let Y;try{Y=JSON.parse(K)}catch{return!1}let U=Y?.visibility;if(!U)return!1;let z=U[J];if(!z)return X==="passthrough";if(J==="story"){let W=z[Q.trackId];if(!Array.isArray(W))return!1;return W.includes(Q.states)}if(J==="task"){let W=z._stages;if(!Array.isArray(W)||W.length===0)return!0;return W.includes(Q.states)}if(J==="job"){let W=z._contexts;if(!Array.isArray(W)||W.length===0)return!0;return W.includes(Q.contexts)}return!0}var hN=G0(X8(),1),xF8=({value:Z,onChange:J,readOnly:Q,projectId:X,fieldDef:K})=>{let{data:Y}=i2(X,K.templateType),U=s2(Y?.templates??[],K.templateEntityType,{contexts:K.templateVisibilityContext});if(Q){let z=U.find((W)=>W.id===Z);return hN.jsxDEV("span",{className:"text-sm",children:z?z.name?.replace(/\.md$/,""):Z},void 0,!1,void 0,this)}return hN.jsxDEV(g7,{value:Z||"__none__",onValueChange:(z)=>J(z==="__none__"?null:z),children:[hN.jsxDEV(_7,{children:hN.jsxDEV(m7,{placeholder:"None"},void 0,!1,void 0,this)},void 0,!1,void 0,this),hN.jsxDEV(v7,{children:[hN.jsxDEV(l9,{value:"__none__",children:"None"},void 0,!1,void 0,this),U.map((z)=>hN.jsxDEV(l9,{value:z.id,children:z.name?.replace(/\.md$/,"")},z.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var MI6=G0(s0(),1);var _G=G0(X8(),1),hF8=({value:Z,onChange:J,readOnly:Q,projectId:X})=>{let{data:K}=k3(X,{store:"all"}),Y=K??[];if(Q){let W=Y.find((G)=>G.id===Z);return _G.jsxDEV("span",{className:"text-sm",children:W?W.name:Z},void 0,!1,void 0,this)}let U=Y.filter((W)=>W.storeCode!=="B"),z=Y.filter((W)=>W.storeCode==="B");return _G.jsxDEV(g7,{value:Z??"",onValueChange:(W)=>J(W),children:[_G.jsxDEV(_7,{children:_G.jsxDEV(m7,{placeholder:"Select track"},void 0,!1,void 0,this)},void 0,!1,void 0,this),_G.jsxDEV(v7,{children:[U.length>0&&_G.jsxDEV(AU,{children:[_G.jsxDEV(G2,{children:"Project"},void 0,!1,void 0,this),U.map((W)=>_G.jsxDEV(l9,{value:W.id,children:W.name},W.id,!1,void 0,this))]},void 0,!0,void 0,this),z.length>0&&_G.jsxDEV(AU,{children:[_G.jsxDEV(G2,{children:"Shared"},void 0,!1,void 0,this),z.map((W)=>_G.jsxDEV(l9,{value:W.id,children:W.name},W.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var iN0=G0(X8(),1),AI6={string:rY0,text:bN0,int:xN0,float:yN0,date:Mv,object_ref:gN0,boolean:lN0,json:k80},NI6={"caw:visibility-config":SF8,"caw:template-selector":xF8,"caw:track-selector":hF8},wI6=({value:Z,onChange:J,fieldDef:Q,readOnly:X,projectId:K,storeCode:Y,className:U,isLoading:z,fieldValues:W,onFieldChange:G,editable:q,mode:H,error:B,onValidationChange:F})=>{let M=X||Q.editable===!1;if(Q.jsonSchema){let w=NI6[Q.jsonSchema.$id];return iN0.jsxDEV(w||k80,{value:Z,onChange:J,fieldDef:Q,readOnly:M,projectId:K,storeCode:Y,className:U,isLoading:z,...w?{fieldValues:W,onFieldChange:G,editable:q}:{}},void 0,!1,void 0,this)}let A=AI6[Q.primitiveType];if(!A)throw Error(`No renderer for primitiveType: ${Q.primitiveType}`);return iN0.jsxDEV(A,{value:Z,onChange:J,fieldDef:Q,readOnly:M,projectId:K,storeCode:Y,className:U,isLoading:z,mode:H,error:B,onValidationChange:F},void 0,!1,void 0,this)},Zz=wI6;var cJ=G0(s0(),1);var RI6=G0(s0(),1);var G4=G0(X8(),1),f80=({values:Z,editable:J,editingRowIndex:Q,dirtyFlags:X,rowExtras:K,onEditingRowIndexChange:Y,onEditRow:U,onUndoRow:z,onMoveUp:W,onMoveDown:G,onRemove:q,renderEditingCell:H,renderReadOnlyCell:B})=>G4.jsxDEV("table",{className:"w-full text-sm border-collapse",children:[G4.jsxDEV("thead",{children:G4.jsxDEV("tr",{className:"border-b",children:[G4.jsxDEV("th",{className:"text-left py-1 px-1 w-8 text-muted-foreground font-medium",children:"#"},void 0,!1,void 0,this),G4.jsxDEV("th",{className:"text-left py-1 px-1 text-muted-foreground font-medium",children:"Value"},void 0,!1,void 0,this),J&&G4.jsxDEV("th",{className:"text-right py-1 px-1 w-28 text-muted-foreground font-medium",children:"Actions"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),G4.jsxDEV("tbody",{children:Z.map((F,M)=>{let A=Q===M;return G4.jsxDEV("tr",{className:"border-b border-border/50",children:[G4.jsxDEV("td",{className:"py-1 px-1 text-muted-foreground",children:M+1},void 0,!1,void 0,this),G4.jsxDEV("td",{className:"py-1 px-1 min-w-0",children:[A?H({index:M,value:F,onChange:(w)=>U(M,w)}):B({index:M,value:F}),K?.[M]??null]},void 0,!0,void 0,this),J&&(()=>{let w=X[M];return G4.jsxDEV("td",{className:"py-1 px-1 text-right",children:G4.jsxDEV("div",{className:"inline-flex items-center gap-0",children:[w?G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>z(M),title:"Undo",children:G4.jsxDEV(mX,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this):G4.jsxDEV("span",{className:"h-5 w-5 inline-block"},void 0,!1,void 0,this),G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>Y(A?null:M),title:A?"Done":"Edit",children:A?G4.jsxDEV(hX,{className:"w-3 h-3"},void 0,!1,void 0,this):G4.jsxDEV(iQ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M>0?G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>W(M),title:"Move up",children:G4.jsxDEV(zq,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this):G4.jsxDEV("span",{className:"h-5 w-5 inline-block"},void 0,!1,void 0,this),M<Z.length-1?G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>G(M),title:"Move down",children:G4.jsxDEV(NF,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this):G4.jsxDEV("span",{className:"h-5 w-5 inline-block"},void 0,!1,void 0,this),G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 hover:text-destructive",onClick:()=>q(M),title:"Remove",children:G4.jsxDEV(iZ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)})()]},M,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this);var PI6=G0(s0(),1),yF8=G0(X8(),1),x80=({value:Z,maxWidth:J})=>yF8.jsxDEV("span",{className:"text-sm block",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:J||"100%"},title:Z||"",children:Z||""},void 0,!1,void 0,this);var TX=G0(s0(),1);var I4=G0(X8(),1),gF8=({value:Z,onChange:J,fieldDef:Q,editable:X,projectId:K,storeCode:Y,originalValue:U,rowExtras:z,className:W})=>{let[G,q]=TX.useState(!1),[H,B]=TX.useState(null),[F,M]=TX.useState(!1),[A,w]=TX.useState(""),[N,R]=TX.useState(0),P=Array.isArray(Z)?Z:[],V=Array.isArray(U)?U:[],$=P.length===0,C=TX.useMemo(()=>{let y=new Map;return V.forEach((p)=>y.set(p,(y.get(p)||0)+1)),P.map((p)=>{let l=y.get(p)||0;if(l>0)return y.set(p,l-1),!1;return!0})},[P,V]),D=$?"No values":P.length===1?"1 value":`${P.length} values`,E=Q?.name??"values",S=TX.useCallback((y)=>{if(q(y),!y)B(null),M(!1),w("")},[]),f=TX.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),H===y)B(null)},[P,J,H]),j=TX.useCallback((y)=>{if(y<=0)return;let p=[...P];if([p[y-1],p[y]]=[p[y],p[y-1]],J(p),H===y)B(y-1);else if(H===y-1)B(y)},[P,J,H]),v=TX.useCallback((y)=>{if(y>=P.length-1)return;let p=[...P];if([p[y],p[y+1]]=[p[y+1],p[y]],J(p),H===y)B(y+1);else if(H===y+1)B(y)},[P,J,H]),b=TX.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),H===y)B(null)},[P,J,H]),_=TX.useCallback((y,p)=>{J(P.map((l,d)=>d===y?p:l))},[P,J]),x=TX.useCallback(()=>{B(null)},[]),h=TX.useCallback(()=>{if(A===""||A==null)return;J([...P,A]),w(""),M(!0),R((y)=>y+1)},[A,P,J]),u=TX.useCallback(()=>{w(""),M(!1)},[]);if($&&!X)return I4.jsxDEV("div",{className:W,children:I4.jsxDEV("span",{className:"text-sm italic text-muted-foreground",children:"No values"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let m=()=>I4.jsxDEV("div",{className:"flex flex-col gap-1 border border-border rounded-md p-2",children:[I4.jsxDEV(ry,{value:A,onChange:w,onSubmit:h,fieldName:`${E}-add`,projectId:K,storeCode:Y,autoFocus:!0},void 0,!1,void 0,this),I4.jsxDEV("div",{className:"flex justify-end gap-1",children:[I4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:u,title:"Cancel",children:I4.jsxDEV(iZ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),I4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:h,title:"Done",children:I4.jsxDEV(hX,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},N,!0,void 0,this);return I4.jsxDEV("div",{className:W,children:I4.jsxDEV(E7,{open:G,onOpenChange:S,children:[I4.jsxDEV($j0,{asChild:!0,children:I4.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs font-normal",children:D},void 0,!1,void 0,this)},void 0,!1,void 0,this),I4.jsxDEV(T7,{className:a8("max-w-4xl max-h-[85vh] flex flex-col"),children:[I4.jsxDEV(A7,{children:I4.jsxDEV(N7,{children:["Edit ",E]},void 0,!0,void 0,this)},void 0,!1,void 0,this),I4.jsxDEV(_W,{className:"gap-2",children:$?m():I4.jsxDEV(I4.Fragment,{children:[I4.jsxDEV(f80,{values:P,editable:X,editingRowIndex:H,dirtyFlags:C,rowExtras:z,onEditingRowIndexChange:B,onEditRow:_,onUndoRow:b,onMoveUp:j,onMoveDown:v,onRemove:f,renderEditingCell:({value:y,onChange:p})=>I4.jsxDEV(ry,{value:y,onChange:p,onSubmit:x,fieldName:E,projectId:K,storeCode:Y,autoFocus:!0},void 0,!1,void 0,this),renderReadOnlyCell:({value:y})=>I4.jsxDEV(x80,{value:y},void 0,!1,void 0,this)},void 0,!1,void 0,this),X&&(F?m():I4.jsxDEV(c0,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs self-start",onClick:()=>M(!0),children:[I4.jsxDEV(i5,{className:"w-3 h-3 mr-1"},void 0,!1,void 0,this),"Add"]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var D4=G0(X8(),1),mF8=(Z)=>Z.primitiveType==="text",$I6=(Z)=>{if(Z>=3)return"w-[32rem]";if(Z===2)return"w-96";return"w-72"},KW=({value:Z,onChange:J,fieldDef:Q,editable:X,projectId:K,storeCode:Y,className:U,originalValue:z,onValidationChange:W,rowExtras:G})=>{let[q,H]=cJ.useState(null),[B,F]=cJ.useState(!1),[M,A]=cJ.useState(""),[w,N]=cJ.useState(0),R=cJ.useRef(null),P=Array.isArray(Z)?Z:[],V=Array.isArray(z)?z:[],$=P.length===0,C=cJ.useMemo(()=>{let y=new Map;return V.forEach((p)=>y.set(p,(y.get(p)||0)+1)),P.map((p)=>{let l=y.get(p)||0;if(l>0)return y.set(p,l-1),!1;return!0})},[P,V]),D=$?"No values":P.length===1?"1 value":`${P.length} values`,E=$I6(Q.colSpan??Q.colspan??1),S=cJ.useMemo(()=>{if(!W)return null;return P.map((y,p)=>(l,d,Z0)=>W(p,d,Z0))},[P.length,W]);cJ.useEffect(()=>{if(B&&R.current){let y=R.current.querySelector("input, select, button, [tabindex]");if(y)y.focus()}},[B,w]);let f=cJ.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),q===y)H(null)},[P,J,q]),j=cJ.useCallback((y)=>{if(y<=0)return;let p=[...P];if([p[y-1],p[y]]=[p[y],p[y-1]],J(p),q===y)H(y-1);else if(q===y-1)H(y)},[P,J,q]),v=cJ.useCallback((y)=>{if(y>=P.length-1)return;let p=[...P];if([p[y],p[y+1]]=[p[y+1],p[y]],J(p),q===y)H(y+1);else if(q===y+1)H(y)},[P,J,q]),b=cJ.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),q===y)H(null)},[P,J,q]),_=cJ.useCallback((y,p)=>{let l=[...P];l[y]=p,J(l)},[P,J]),x=cJ.useCallback(()=>{if(M===""||M==null)return;J([...P,M]),A(""),F(!0),N((y)=>y+1)},[M,P,J]),h=cJ.useCallback(()=>{A(""),F(!1)},[]),u=cJ.useCallback((y)=>{if(y.key==="Enter")y.preventDefault(),x();else if(y.key==="Escape")y.preventDefault(),h()},[x,h]),m=(y=!0)=>D4.jsxDEV("div",{ref:R,onKeyDown:u,className:"flex items-center gap-1",children:[D4.jsxDEV("div",{className:"flex-1 min-w-0",children:D4.jsxDEV(Zz,{value:M,onChange:A,fieldDef:Q,readOnly:!1,projectId:K,storeCode:Y},void 0,!1,void 0,this)},void 0,!1,void 0,this),D4.jsxDEV("div",{className:"flex items-center gap-1 shrink-0",children:[D4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:x,title:"Confirm add",children:D4.jsxDEV(i5,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y&&D4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:h,title:"Cancel",children:D4.jsxDEV(iZ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},w,!0,void 0,this);if(mF8(Q))return D4.jsxDEV(gF8,{value:Z,onChange:J,fieldDef:Q,editable:X,projectId:K,storeCode:Y,originalValue:z,rowExtras:G},void 0,!1,void 0,this);if($&&!X)return D4.jsxDEV("div",{className:U,children:D4.jsxDEV("span",{className:"text-sm italic text-muted-foreground",children:"No values"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return D4.jsxDEV("div",{className:U,children:D4.jsxDEV(jK,{onOpenChange:(y)=>{if(!y)F(!1),A(""),H(null)},children:[D4.jsxDEV(kK,{asChild:!0,children:D4.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs font-normal",children:D},void 0,!1,void 0,this)},void 0,!1,void 0,this),D4.jsxDEV(sX,{className:a8(E,"p-3 z-[60] flex flex-col"),align:"start",style:{maxHeight:"var(--radix-popover-content-available-height)"},children:$?X?m(!1):D4.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"No values"},void 0,!1,void 0,this):D4.jsxDEV("div",{className:"flex flex-col gap-2 min-h-0 flex-1",children:[D4.jsxDEV("div",{className:"overflow-y-auto min-h-0 flex-1",children:D4.jsxDEV(f80,{values:P,editable:X,editingRowIndex:q,dirtyFlags:C,rowExtras:G,onEditingRowIndexChange:H,onEditRow:_,onUndoRow:b,onMoveUp:j,onMoveDown:v,onRemove:f,renderEditingCell:({index:y,value:p,onChange:l})=>D4.jsxDEV(Zz,{value:p,onChange:l,fieldDef:Q,readOnly:!1,projectId:K,storeCode:Y,onValidationChange:S?.[y]},void 0,!1,void 0,this),renderReadOnlyCell:({index:y,value:p})=>mF8(Q)?D4.jsxDEV(x80,{value:p},void 0,!1,void 0,this):D4.jsxDEV(Zz,{value:p,fieldDef:Q,readOnly:!0,projectId:K,storeCode:Y,onValidationChange:S?.[y]},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),X&&(B?m():D4.jsxDEV(c0,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>F(!0),children:[D4.jsxDEV(i5,{className:"w-3 h-3 mr-1"},void 0,!1,void 0,this),"Add"]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var h80=G0(s0(),1);function y80({fieldDef:Z,projectId:J,entityId:Q,typeCode:X,subtype:K,parentId:Y,storeCode:U,dependencyValues:z}){let W=Z?.allowed?.type==="function",G=W&&Q!=null,q=W&&!G&&X!=null&&Y!=null&&U!=null,H=Z?.allowed?.dependsOn,B=h80.useMemo(()=>{if(!Array.isArray(H)||H.length===0)return null;let N={};for(let R of H)N[R]=z?.[R]??null;return JSON.stringify(N)},[H,z]),F=h80.useMemo(()=>B===null?null:JSON.parse(B),[B]),M=h80.useMemo(()=>{if(F===null)return;let N={};for(let[R,P]of Object.entries(F))if(P!==null&&P!==void 0)N[R]=P;return N},[F]),{data:A,isLoading:w}=k7({queryKey:["allowed-values",J,Z?.name,Q??null,X??null,K??null,Y??null,U??null,F],queryFn:()=>Ci0(J,{entityId:G?Q:void 0,typeCode:q?X:void 0,subtype:q?K:void 0,parentId:q?Y:void 0,storeCode:q?U:void 0,fieldName:Z.name,dependencyValues:M}),enabled:W&&J!=null&&Z!=null&&(G||q)});if(!Z?.allowed)return{values:null,options:null,isLoading:!1};if(Z.allowed.type==="enum")return{values:Z.allowed.values,options:null,isLoading:!1};if(Z.allowed.type==="function")return{values:A?.values??null,options:A?.options??null,isLoading:w};return{values:null,options:null,isLoading:!1}}var mY=G0(X8(),1),sN0=(Z)=>{switch(Z){case 2:return"sm:col-span-2";case 3:return"sm:col-span-2 lg:col-span-3";case 4:return"sm:col-span-2 lg:col-span-4";default:return""}},uF8=({fieldDef:Z,currentValue:J,onFieldChange:Q,isControlled:X,projectId:K,storeCode:Y,entityId:U,typeCode:z,subtype:W,parentId:G,dependencyValues:q,fieldValues:H,isDirty:B,originalValue:F,editingFieldId:M,setEditingFieldId:A,editSnapshot:w,setEditSnapshot:N,editFieldError:R,setEditFieldError:P,readOnly:V=!1})=>{let $=Z.multiplicity==="multi",C=!Z.editable,D=Z.name==="parent",E=Z.jsonSchema?.$id==="caw:visibility-config",S=Z.primitiveType==="text",f=!V&&M!==void 0,j=f&&M===Z.name,v=f&&!C&&!$&&!D&&!E,b=B&&f&&!C&&!D,_=V?!0:!f?C:$?C:!j,[x,h]=Jz.useState(!1),u=Jz.useRef(null);Jz.useEffect(()=>{u.current=R??null},[R]);let m=Z.classDescription||Z.description,y=$?Array.isArray(J)?J:J?[J]:[]:J??"",[p,l]=Jz.useState(y);Jz.useEffect(()=>{let a=$?Array.isArray(J)?J:J?[J]:[]:J??"";l(a)},[J,$]);let d=Jz.useCallback((a)=>{if(l(a),j&&P){let K0=Z.required&&(a===null||a===void 0||a==="")?"Required":null;P(K0)}if(X&&Q)Q(Z.name,a)},[j,P,Z.required,Z.name,X,Q]),{values:Z0,options:e,isLoading:r}=y80({fieldDef:Z,projectId:K,entityId:U,typeCode:z,subtype:W,parentId:G,storeCode:Y,dependencyValues:q}),W0=Z.allowed?.type==="function"&&Z0!==null?{...Z,allowed:{type:"enum",values:Z0,options:e}}:Z,t=Z.allowed?.type==="function"&&r,U0=Jz.useCallback(()=>{if(R)return;if(S){h(!0);return}if(A)A(Z.name);if(N)N({fieldName:Z.name,value:J});if(P)P(null)},[R,S,Z.name,J,A,N,P]),n=Jz.useCallback((a)=>{if(!j)return;let K0=a.relatedTarget;if(K0&&(K0.closest("[data-radix-popper-content-wrapper]")||K0.closest('[role="listbox"]')))return;requestAnimationFrame(()=>{if(u.current)return;if(A)A((B0)=>B0===Z.name?null:B0);if(N)N((B0)=>B0?.fieldName===Z.name?null:B0)})},[j,Z.name,A,N]),o=Jz.useCallback((a)=>{if(a.key!=="Escape"||!j)return;if(a.preventDefault(),w?.fieldName===Z.name&&X&&Q)Q(Z.name,w.value);if(A)A(null);if(N)N(null);if(P)P(null)},[j,w,Z.name,X,Q,A,N,P]);return mY.jsxDEV("div",{className:a8("space-y-1",sN0(Z.colspan)),children:[mY.jsxDEV("div",{className:"flex items-center gap-1",children:[mY.jsxDEV("label",{className:`text-sm font-medium ${B?"text-dirty":"text-foreground"}`,children:[Z.label||Z.name,Z.required&&mY.jsxDEV("span",{className:"text-destructive ml-1",children:"*"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&mY.jsxDEV("button",{type:"button",onClick:U0,className:"text-muted-foreground hover:text-foreground","aria-label":`Edit ${Z.label||Z.name}`,children:mY.jsxDEV(iQ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),b&&mY.jsxDEV("button",{type:"button",onClick:()=>Q&&Q(Z.name,F),className:"text-muted-foreground hover:text-foreground","aria-label":`Undo ${Z.label||Z.name}`,children:mY.jsxDEV(mX,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&mY.jsxDEV("p",{className:"text-xs text-muted-foreground",children:m},void 0,!1,void 0,this),$?mY.jsxDEV(KW,{value:p,onChange:(a)=>{if(l(a),X&&Q)Q(Z.name,a)},fieldDef:W0,editable:!C&&!V,projectId:K,storeCode:Y,originalValue:F},void 0,!1,void 0,this):E?mY.jsxDEV(Zz,{value:p,onChange:d,fieldDef:W0,editable:!C,projectId:K,storeCode:Y,isLoading:t,fieldValues:H,onFieldChange:Q},void 0,!1,void 0,this):mY.jsxDEV("div",{onBlur:n,onKeyDown:j?o:void 0,children:_&&!j&&!p&&p!==0?mY.jsxDEV("span",{className:"text-sm text-muted-foreground/60 italic",children:"No value"},void 0,!1,void 0,this):mY.jsxDEV(Zz,{value:p,onChange:d,fieldDef:W0,readOnly:_,projectId:K,storeCode:Y,isLoading:t,fieldValues:H,onFieldChange:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),S&&v&&mY.jsxDEV(S3,{open:x,onOpenChange:h,value:J??"",onSave:(a)=>{if(X&&Q)Q(Z.name,a);h(!1)},projectId:K,storeCode:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var Qz=G0(X8(),1),GS=({sectionKey:Z,sectionLabel:J,fields:Q,fieldValues:X,isExpanded:K,onToggle:Y,onFieldChange:U,isControlled:z,projectId:W,storeCode:G,entityPath:q,entityId:H,typeCode:B,subtype:F,parentId:M,dependencyValues:A,dirtyFieldNames:w,originalFieldValues:N,editingFieldId:R,setEditingFieldId:P,editSnapshot:V,setEditSnapshot:$,editFieldError:C,setEditFieldError:D,readOnly:E=!1})=>{let S=`section-${Z}`;return Qz.jsxDEV("div",{className:"border border-border rounded-md",children:[Qz.jsxDEV("button",{id:`section-header-${Z}`,type:"button",className:"flex items-center gap-2 w-full px-3 py-2 text-left text-sm font-medium text-foreground hover:bg-muted/50 rounded-t-md",onClick:Y,"aria-expanded":K,"aria-controls":S,children:[K?Qz.jsxDEV(CZ,{className:"w-4 h-4 flex-shrink-0"},void 0,!1,void 0,this):Qz.jsxDEV(IZ,{className:"w-4 h-4 flex-shrink-0"},void 0,!1,void 0,this),J]},void 0,!0,void 0,this),K&&Qz.jsxDEV("div",{id:S,role:"region","aria-labelledby":`section-header-${Z}`,className:"px-3 pb-3",children:Qz.jsxDEV("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:Q.map((f)=>Qz.jsxDEV(pF8.default.Fragment,{children:[f.name==="parent"&&q!==void 0&&Qz.jsxDEV("div",{className:a8("space-y-1",sN0(3)),children:[Qz.jsxDEV("label",{className:"text-sm font-medium text-foreground",children:"Path"},void 0,!1,void 0,this),Qz.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Full path in the folder hierarchy"},void 0,!1,void 0,this),q?Qz.jsxDEV("span",{className:"text-sm text-foreground block",children:q},void 0,!1,void 0,this):Qz.jsxDEV("span",{className:"text-sm text-muted-foreground/60 italic",children:"No value"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Qz.jsxDEV(uF8,{fieldDef:f,currentValue:X?.[f.name],onFieldChange:U,isControlled:z,projectId:W,storeCode:G,entityId:H,typeCode:B,subtype:F,parentId:M,dependencyValues:A,isDirty:w?.has(f.name)??!1,originalValue:N?.[f.name],editingFieldId:R,setEditingFieldId:P,editSnapshot:V,setEditSnapshot:$,editFieldError:C,setEditFieldError:D,readOnly:E},void 0,!1,void 0,this)]},f.id,!0,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var TI6=new Set(["base","pathable","versioned"]),g80=(Z,{typeCode:J,typeLabel:Q,subtypeLabel:X})=>{let K=[...Z].filter((U)=>!U.hidden).sort((U,z)=>(U.sortOrder??1/0)-(z.sortOrder??1/0)),Y=new Map;for(let U of K){let z=U.sectionKey||"_ungrouped";if(!Y.has(z))Y.set(z,{sectionKey:z,sectionLabel:U.sectionLabel||"Info",sectionOrder:U.sectionOrder??999,fields:[]});Y.get(z).fields.push(U)}if(Q){let U=[];for(let z of TI6)if(Y.has(z))U.push(...Y.get(z).fields),Y.delete(z);if(U.length>0){if(!Y.has("type"))Y.set("type",{sectionKey:"type",sectionLabel:"Info",sectionOrder:3,fields:[]});let z=Y.get("type");z.fields=[...z.fields,...U].sort((W,G)=>(W.sortOrder??1/0)-(G.sortOrder??1/0))}if(Y.has("type"))Y.get("type").sectionLabel=`${Q} info`;if(X&&Y.has("subtype"))Y.get("subtype").sectionLabel=`${X} extension info`}return Array.from(Y.values()).sort((U,z)=>(U.sectionOrder??999)-(z.sectionOrder??999))};var vG=G0(s0(),1);var IJ=G0(X8(),1),cF8=({projectId:Z,entityId:J,draftVersionId:Q,storeCode:X})=>{let[K,Y]=vG.useState(null),{data:U,isLoading:z,error:W}=xN(Z,J),G=vG.useMemo(()=>{let D=[];if(Q)D.push({versionEntityId:Q,label:"Draft",isDraft:!0});if(U)for(let E of U)D.push({versionEntityId:E.versionEntityId,versionNumber:E.versionNumber,publishedAt:E.publishedAt,label:`v${E.versionNumber}`,isDraft:!1});return D},[Q,U]);vG.useEffect(()=>{if(G.length>0&&!K)Y(G[0].versionEntityId)},[G,K]);let{data:q,isLoading:H,error:B}=tF(Z,"v",null),{data:F,isLoading:M,error:A}=jU(Z,K),w=vG.useMemo(()=>{if(!q)return[];return g80(q,{typeCode:"v",typeLabel:"Version",subtypeLabel:null})},[q]),[N,R]=vG.useState({type:!0}),P=vG.useCallback((D)=>{R((E)=>({...E,[D]:!E[D]}))},[]),V=vG.useCallback((D)=>{Y(D)},[]);if(!z&&G.length===0)return null;if(z)return IJ.jsxDEV("div",{className:"mt-4 border border-border rounded-md p-4",children:IJ.jsxDEV("div",{className:"flex items-center justify-center",children:[IJ.jsxDEV(O9,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this),IJ.jsxDEV("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading versions..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(W)return IJ.jsxDEV("div",{className:"mt-4 border border-border rounded-md p-4",children:[IJ.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error loading versions"},void 0,!1,void 0,this),IJ.jsxDEV("p",{className:"text-sm text-destructive mt-1",children:W.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let $=H||M,C=B||A;return IJ.jsxDEV("div",{className:"mt-4 space-y-4",children:[IJ.jsxDEV("div",{className:"flex items-center gap-2",children:[IJ.jsxDEV("span",{className:"text-sm font-medium text-foreground",children:"Select version:"},void 0,!1,void 0,this),IJ.jsxDEV(g7,{value:K||"",onValueChange:V,children:[IJ.jsxDEV(_7,{className:"text-sm h-auto py-1",children:IJ.jsxDEV(m7,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),IJ.jsxDEV(v7,{children:G.map((D)=>IJ.jsxDEV(l9,{value:D.versionEntityId,children:D.isDraft?`Draft (${D.versionEntityId})`:`${D.label} (${D.versionEntityId}) Published`},D.versionEntityId,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$&&IJ.jsxDEV("div",{className:"flex items-center justify-center p-4",children:[IJ.jsxDEV(O9,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this),IJ.jsxDEV("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading version fields..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!$&&C&&IJ.jsxDEV("div",{className:"p-4 border border-border rounded-md",children:[IJ.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error loading version fields"},void 0,!1,void 0,this),IJ.jsxDEV("p",{className:"text-sm text-destructive mt-1",children:C.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!$&&!C&&w.map((D)=>IJ.jsxDEV(GS,{sectionKey:D.sectionKey,sectionLabel:D.sectionLabel,fields:D.fields,fieldValues:F,isExpanded:N[D.sectionKey]??!1,onToggle:()=>P(D.sectionKey),projectId:Z,storeCode:X,entityId:K,typeCode:"v"},D.sectionKey,!1,void 0,this))]},void 0,!0,void 0,this)};var NH=G0(X8(),1),bG=({projectId:Z,entityId:J,entityType:Q,entitySubtype:X,entityPath:K,onFieldChange:Y,fieldValues:U,dirtyFieldNames:z,originalFieldValues:W,storeCode:G,readOnly:q=!1,excludeFields:H})=>{let[B,F]=Xz.useState(null),[M,A]=Xz.useState(null),[w,N]=Xz.useState(null),R=U!==void 0,{data:P,isLoading:V,error:$}=jU(Z,J),C=R?U:P,{data:D,isLoading:E,error:S}=tF(Z,Q,X),f=Xz.useMemo(()=>{let y=D||[];if(!H)return y;return y.filter((p)=>!H.has(p.name))},[D,H]),j=Xz.useMemo(()=>{let y={};for(let p of f){let l=p.allowed?.dependsOn;if(l)for(let d of l){if(!y[d])y[d]=[];y[d].push(p.name)}}return y},[f]),v=Xz.useCallback((y,p)=>{if(Y)Y(y,p);let l=j[y];if(l){for(let d of l)if(Y)Y(d,null)}},[Y,j]),b=Xz.useMemo(()=>{let y=f.find((d)=>d.sectionKey==="type")?.sectionLabel??null,p=f.find((d)=>d.sectionKey==="subtype")?.sectionLabel??null,l=g80(f,{typeCode:Q,typeLabel:y,subtypeLabel:p});if(!R&&C){let d=new Set(f.map((e)=>e.name)),Z0=Object.keys(C).filter((e)=>!d.has(e)&&(!H||!H.has(e)));if(Z0.length>0)l.push({sectionKey:"entity",sectionLabel:"Entity-scoped",sectionOrder:5,fields:Z0.map((e)=>({id:`entity:${e}`,name:e,label:e,primitiveType:"string",colspan:1,rows:1,multiplicity:"single",editable:!1,isVirtual:!1}))})}return l},[f,R,C,Q,H]),[_,x]=Xz.useState({type:!0,subtype:!0}),h=Xz.useCallback((y)=>{x((p)=>({...p,[y]:!p[y]}))},[]),u=V||E,m=$||S;if(u)return NH.jsxDEV("div",{className:"flex items-center justify-center p-8",children:[NH.jsxDEV(O9,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this),NH.jsxDEV("span",{className:"ml-2 text-muted-foreground",children:"Loading info..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(m)return NH.jsxDEV("div",{className:"p-4 text-destructive",children:[NH.jsxDEV("p",{className:"font-medium",children:"Error loading info"},void 0,!1,void 0,this),NH.jsxDEV("p",{className:"text-sm mt-1",children:m.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(b.length===0)return NH.jsxDEV("div",{className:"p-4 text-muted-foreground text-sm",children:"No info available for this entity type."},void 0,!1,void 0,this);return NH.jsxDEV("div",{className:"space-y-4",children:[b.map((y)=>NH.jsxDEV(GS,{sectionKey:y.sectionKey,sectionLabel:y.sectionLabel,fields:y.fields,fieldValues:C,isExpanded:_[y.sectionKey]??!1,onToggle:()=>h(y.sectionKey),onFieldChange:v,isControlled:R,projectId:Z,storeCode:G,entityPath:y.sectionKey==="type"?K:void 0,entityId:J,typeCode:Q,subtype:X,dependencyValues:C,dirtyFieldNames:z,originalFieldValues:W,editingFieldId:B,setEditingFieldId:F,editSnapshot:M,setEditSnapshot:A,editFieldError:w,setEditFieldError:N,readOnly:q},y.sectionKey,!1,void 0,this)),(Q==="d"||Q==="t")&&NH.jsxDEV(cF8,{projectId:Z,entityId:J,draftVersionId:C?.draft_version??null,storeCode:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var II6=G0(s0(),1);var _3=async(Z,J="Copied")=>{try{await navigator.clipboard.writeText(Z),N6.success(J)}catch{N6.error("Failed to copy")}},lF8=(Z)=>{if(!Z)return"";let J=Z.indexOf("/");return J===-1?Z:Z.slice(J+1)},VI6=(Z)=>Z[0].toUpperCase()+Z.slice(1),CI6=({items:Z,projectId:J,entityType:Q,viewType:X})=>{if(!Z||Z.length===0)return"";let K=Z[0],Y=BZ(K.id),U=Y&&Y!=="A"?`/store/${Y}`:"",z=`${window.location.origin}/project/${J}${U}`;if(Q==="document")return`${z}/documents?id=${K.id}`;if(Q==="template")return`${z}/templates?id=${K.id}`;if(Q==="story")return`${z}/story/${K.id}`;if(Q==="job")return`${z}/jobs/${K.id}`;if(Q==="folder")return`${z}/${X??"documents"}?id=${K.id}`;return""},m80=({items:Z,projectId:J,entityType:Q,jobFields:X,getContent:K,getTranscript:Y,getChildrenIds:U,viewType:z})=>{if(!Z||Z.length===0)return[];let W=Z.length>1,G=[],q=VI6(Q);if(Q!=="story"&&Q!=="folder"&&Q!=="job")G.push({key:"content",label:W?`Copy ${q} Contents`:`Copy ${q} Content`,icon:R5,successMessage:W?`${q} Contents copied`:`${q} Content copied`,getValue:async()=>{if(K)return await K(Z);return Z.map((H)=>H.content??"").filter(Boolean).join(`
|
|
3083
|
+
Please report this to https://github.com/markedjs/marked.`,Z){let X="<p>An error occurred:</p><pre>"+JO(Q.message+"",!0)+"</pre>";return J?Promise.resolve(X):X}if(J)return Promise.reject(Q);throw Q}}},FP=new E06;function W5(Z,J){return FP.parse(Z,J)}W5.options=W5.setOptions=function(Z){return FP.setOptions(Z),W5.defaults=FP.defaults,Os0(W5.defaults),W5};W5.getDefaults=X20;W5.defaults=OP;W5.use=function(...Z){return FP.use(...Z),W5.defaults=FP.defaults,Os0(W5.defaults),W5};W5.walkTokens=function(Z,J){return FP.walkTokens(Z,J)};W5.parseInline=FP.parseInline;W5.Parser=xq;W5.parser=xq.parse;W5.Renderer=$s;W5.TextRenderer=H20;W5.Lexer=fq;W5.lexer=fq.lex;W5.Tokenizer=Ps;W5.Hooks=Wb;W5.parse=W5;var{options:RbZ,setOptions:PbZ,use:$bZ,walkTokens:TbZ,parseInline:VbZ}=W5;var CbZ=xq.parse,IbZ=fq.lex;Es();var zF8=G0(X8(),1),iy=r7.create({namespace:"caw:client:markdown"}),XF8=!1,KF8=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return"mmd-"+Math.random().toString(36).slice(2)+"-"+Date.now()},LH=(Z)=>{return(Z??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},vC6=new Set(["details","summary","pre","code","br","hr","img","b","svg","g","circle","rect","path","line","polygon","ellipse","polyline","text","tspan","textpath","defs","use","filter","fegaussianblur","animate","set","lineargradient","radialgradient","stop","mask","pattern","clippath","marker","symbol","title","desc"]),bC6=/<(\/?)([A-Za-z][A-Za-z0-9-]*)/g,fC6=(Z)=>{return Z.replace(bC6,(J,Q,X)=>{if(vC6.has(X.toLowerCase()))return J;return`<${Q}${X}`})},xC6="internal-link",hC6="noopener noreferrer",yC6="data-caw-safe",gC6="http://www.w3.org/1999/xhtml",mC6=(Z)=>Z.classList?.contains(xC6)||Z.getAttribute?.("rel")===hC6||Z.hasAttribute?.(yC6),uC6=(Z)=>{for(let J of Array.from(Z.querySelectorAll("a"))){if(J.namespaceURI&&J.namespaceURI!==gC6)continue;if(mC6(J))continue;let Q=J.parentNode;if(!Q)continue;while(J.firstChild)Q.insertBefore(J.firstChild,J);Q.removeChild(J)}},pC6=/^(.*?)\|(\d+)(?:x(\d+))?$/,cC6=({href:Z,title:J,text:Q})=>{try{let X=Q??"",K=Z??"",Y=pC6.exec(X),U=Y?Y[1]:X,z=` alt="${LH(U)}"`,W=J?` title="${LH(J)}"`:"";if(!K)return`<img${z}${W}>`;let G=` src="${LH(K)}"`;if(!Y)return`<img${G}${z}${W}>`;let q=Number(Y[2]),H=Y[3]!==void 0?Number(Y[3]):null;if(q===0)return`<img${G}${z}${W}>`;let B=` width="${q}"`,F=H!==null&&H!==0?` height="${H}"`:"";return`<img${G}${z}${B}${F}${W}>`}catch(X){return iy.error("Image render error:",X),'<img alt="">'}},I80=(Z)=>{return Z.toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim()},sy=(Z)=>Z?.split("#")[0]??"",D80=(Z)=>{let J=Z?.indexOf("#")??-1;return J>=0?Z.slice(J+1):null},_N0=(Z)=>{let J=sy(Z);if(J?.startsWith("?"))return new URLSearchParams(J).get("id");return null},KS=/^[A-Z][dtfsj]\d+$/,YF8=/^\/?documents\/.+/,UF8=/^\/?templates\/.+/,lC6=(Z)=>{if(!Z)return!1;if(Z.startsWith("#"))return!0;let J=sy(Z);if(KS.test(J)||YF8.test(J)||UF8.test(J))return!0;let Q=_N0(Z);return Q&&KS.test(Q)},dC6=(Z)=>{if(Z?.startsWith("#"))return"anchor";let J=sy(Z);if(KS.test(J))return"id";if(YF8.test(J)||UF8.test(J))return"path";let Q=_N0(Z);if(Q&&KS.test(Q))return"id";return null},kN0=/<svg(?:\s[^>]*)?>|<\/svg\s*>/gi,iC6=/^<svg[\s>]/i,sC6=/(?:^|\n)<svg[\s>]/i,nC6={name:"svgBlock",level:"block",start(Z){let J=sC6.exec(Z);if(!J)return;return J.index===0?0:J.index+1},tokenizer(Z){if(!iC6.test(Z))return;kN0.lastIndex=0;let J=0,Q;while((Q=kN0.exec(Z))!==null)if(J+=Q[0][1]==="/"?-1:1,J===0){let X=Z.slice(0,kN0.lastIndex);return{type:"svgBlock",raw:X,text:X}}return},renderer(Z){return Z.text}};W5.use({extensions:[nC6],walkTokens(Z){if(Z.type==="html"&&typeof Z.text==="string")Z.text=fC6(Z.text)}});var fQ=({markdown:Z,className:J="",onInternalLinkClick:Q,onRenderComplete:X,onDetailsOpen:K})=>{let Y=l2.useRef(null),U=l2.useRef(0),z=l2.useRef(new Set),W=l2.useRef(!1),G=T1(),q=l2.useMemo(()=>{let F=G.pathname.match(/\/project\/([^/]+)(?:\/store\/([^/]+))?/);return F?`${F[1]}/${F[2]||"A"}`:null},[G.pathname]),H=(F)=>{let M=F.target.closest("a.internal-link");if(!M)return;if(F.metaKey||F.ctrlKey||F.shiftKey||F.button!==0)return;if(M.closest("code, pre"))return;let A=M.getAttribute("data-link-type");if(A==="anchor"){F.preventDefault();let w=D80(M.getAttribute("href")),N=w?I80(w):null;Q?.({type:"anchor",id:null,path:null,anchor:N});return}if(A==="id"){let w=M.getAttribute("data-internal-id"),N=D80(M.getAttribute("href")),R=N?I80(N):null;if(w&&KS.test(w))F.preventDefault(),Q?.({type:"id",id:w,path:null,anchor:R})}else if(A==="path"){let w=M.getAttribute("data-internal-path"),N=D80(M.getAttribute("href")),R=N?I80(N):null;if(w&&/^\/(?:documents|templates)\/.+/.test(w))F.preventDefault(),Q?.({type:"path",id:null,path:w,anchor:R})}},B=l2.useMemo(()=>{try{let F=new W5.Renderer;F.code=({text:P,lang:V})=>{let $=((V??"").trim().split(" ")[0]??"").toLowerCase(),C=LH(P);if($==="mermaid")return`<pre class="mermaid" data-mermaid-id="${KF8()}">${C}</pre>`;return`<pre><code class="language-${$}">${C}</code></pre>`},F.link=function({href:P,title:V,tokens:$}){let C=this.parser.parseInline($),D=LH(P??""),E=V?` title="${LH(V)}"`:"";if(lC6(P)){let S=dC6(P);if(S==="anchor")return`<a href="${D}" class="internal-link" data-link-type="anchor"${E}>${C}</a>`;let f=S==="path"&&P&&!P.startsWith("/")?"/"+P:P,j=LH(f??""),v=S==="id"?KS.test(sy(P))?sy(P):_N0(P):null,b=D80(P),_=S==="id"?LH(Pq(v,G.pathname,b)?.url??P??""):LH(bj0(f,G.pathname)?.url??f??""),x=S==="id"?`data-internal-id="${LH(v)}"`:`data-internal-path="${j}"`;return`<a href="${_}" class="internal-link" data-link-type="${S}" ${x}${E}>${C}</a>`}return`<a href="${D}" target="_blank" rel="noopener noreferrer"${E}>${C}</a>`};let M=new Map,A=0;F.heading=function({tokens:P,depth:V}){let $=this.parser.parseInline(P),C=$.replace(/<[^>]+>/g,""),D=I80(C);if(!D)A++,D=`heading-${A}`;if(M.has(D)){let S=M.get(D);M.set(D,S+1),D=`${D}-${S}`}else M.set(D,1);let E=`h${V}`;return`<${E} id="${LH(D)}">${$}</${E}>`},F.image=cC6;let w=W5.parse(Z??"",{renderer:F,breaks:!0}),N=SB.sanitize(w,{RETURN_DOM_FRAGMENT:!0,ADD_TAGS:["pre","details","summary","animate","set"],ADD_ATTR:["class","data-mermaid-id","data-link-type","data-internal-id","data-internal-path","id","width","height","open","target","rel","from","to","calcmode","data-caw-safe","data-caw-tool-key"]});uC6(N);let R=document.createElement("div");return R.appendChild(N),R.innerHTML}catch(F){return iy.error("Markdown parse error:",F),""}},[Z,q]);return l2.useEffect(()=>{if(B)X?.()},[B,X]),l2.useEffect(()=>{if(!B)return;let F=!1,M=++U.current;return(async()=>{let A=Y.current;if(!A)return;let w=Array.from(A.querySelectorAll("pre.mermaid[data-mermaid-id]")),R=Array.from(A.querySelectorAll("pre > code.language-mermaid")).map((V)=>V.parentElement).filter(Boolean),P=[...w,...R];if(P.length===0)return;try{let V=await Promise.resolve().then(() => (QF8(),JF8)),$=V.default||V;if(!XF8)$.initialize({startOnLoad:!1,theme:"default",suppressErrorRendering:!0}),XF8=!0;let C=P.map(async(E)=>{let S=(E.textContent??"").trim();if(!S)return{el:E,svg:null,error:null};let f=E.getAttribute("data-mermaid-id")||KF8();try{let{svg:j}=await $.render(`render-${f}`,S);return{el:E,svg:j,error:null}}catch(j){return{el:E,svg:null,error:j}}}),D=await Promise.all(C);if(F||M!==U.current)return;for(let{el:E,svg:S,error:f}of D){if(!E)continue;if(f||!S){if(iy.warn("Mermaid render error:",f),E.classList.add("mermaid-error"),f){let j=document.createElement("span");j.className="mermaid-error-message";let v=f.message||f.toString();j.textContent=v?`Mermaid syntax error: ${v}`:"Mermaid syntax error",E.prepend(j)}continue}try{let j=document.createElement("div");j.className="mermaid-diagram",j.innerHTML=S,E.replaceWith(j)}catch(j){iy.warn("Mermaid DOM replace error:",j),E.classList.add("mermaid-error")}}}catch(V){iy.error("Mermaid initialization error:",V)}})(),()=>{F=!0}},[B]),l2.useEffect(()=>{let F=Y.current;if(!F)return;let M=(A)=>{if(!(A.target instanceof HTMLDetailsElement))return;let w=A.target.querySelector(":scope > summary");if(!w)return;let N=A.target.getAttribute("data-caw-tool-key")||w.textContent;if(A.target.open){if(z.current.add(N),!W.current)K?.()}else z.current.delete(N)};return F.addEventListener("toggle",M,!0),()=>F.removeEventListener("toggle",M,!0)},[]),l2.useLayoutEffect(()=>{let F=Y.current;if(!F||z.current.size===0)return;W.current=!0;for(let M of F.querySelectorAll("details")){let A=M.querySelector(":scope > summary");if(!A)continue;let w=M.getAttribute("data-caw-tool-key")||A.textContent;if(z.current.has(w))M.open=!0}W.current=!1},[B]),zF8.jsxDEV("div",{ref:Y,className:`prose prose-sm max-w-none ${J}`,dangerouslySetInnerHTML:{__html:B},onClick:H},void 0,!1,void 0,this)};var qK=G0(X8(),1),S3=({open:Z,onOpenChange:J,value:Q="",onSave:X,projectId:K,storeCode:Y})=>{let[U,z]=ny.useState(Q);return ny.useEffect(()=>{if(Z)z(Q)},[Z,Q]),qK.jsxDEV(E7,{open:Z,onOpenChange:J,children:qK.jsxDEV(T7,{className:"max-w-6xl h-[85vh] flex flex-col",children:[qK.jsxDEV(A7,{className:"flex-shrink-0",children:qK.jsxDEV(N7,{children:"Edit Text"},void 0,!1,void 0,this)},void 0,!1,void 0,this),qK.jsxDEV(ji0,{defaultValue:"edit",className:"flex-1 flex flex-col min-h-0",children:[qK.jsxDEV(aY0,{className:"justify-start self-start",children:[qK.jsxDEV(zs,{value:"edit",children:"Edit"},void 0,!1,void 0,this),qK.jsxDEV(zs,{value:"preview",children:"Preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qK.jsxDEV(Ws,{value:"edit",className:"flex-1 min-h-0 flex flex-col",children:qK.jsxDEV("div",{className:"flex-1 min-h-0",children:qK.jsxDEV(eW,{value:U,onChange:z,projectId:K,storeCode:Y,path:"field-editor.md",height:"100%"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),qK.jsxDEV(Ws,{value:"preview",className:"flex-1 min-h-0",children:qK.jsxDEV("div",{className:"h-full p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:qK.jsxDEV(fQ,{markdown:U},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qK.jsxDEV(t7,{className:"flex-shrink-0",children:[qK.jsxDEV(c0,{variant:"outline",onClick:()=>{J?.(!1)},children:"Cancel"},void 0,!1,void 0,this),qK.jsxDEV(c0,{onClick:()=>{X?.(U)},children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var m$=G0(s0(),1);var gY=G0(X8(),1),ry=({value:Z,onChange:J,onSubmit:Q,fieldName:X,projectId:K,storeCode:Y,minHeight:U=120,maxHeight:z=400,readOnly:W=!1,autoFocus:G=!1,headerLeft:q=null})=>{let[H,B]=m$.useState("edit"),[F,M]=m$.useState(!1),[A,w]=m$.useState(""),N=m$.useCallback(()=>{w(Z??""),M(!0)},[Z]);if(W)return gY.jsxDEV("div",{className:"p-4 border border-border rounded-md bg-muted overflow-auto",style:{minHeight:U,maxHeight:z},children:gY.jsxDEV(fQ,{markdown:Z??""},void 0,!1,void 0,this)},void 0,!1,void 0,this);return gY.jsxDEV("div",{className:"flex flex-col w-full",children:[gY.jsxDEV("div",{className:"flex items-center justify-between mb-1.5",children:[gY.jsxDEV("div",{className:"flex items-center gap-2",children:q},void 0,!1,void 0,this),gY.jsxDEV("div",{className:"flex items-center gap-1.5",children:[gY.jsxDEV("div",{className:"flex items-center rounded-lg bg-muted p-0.5",children:[gY.jsxDEV("button",{type:"button",onClick:()=>B("edit"),className:`px-3 py-1 text-xs font-medium rounded-md transition-all ${H==="edit"?"bg-background text-foreground shadow-sm border border-border":"text-muted-foreground hover:text-foreground border border-transparent"}`,children:"Edit"},void 0,!1,void 0,this),gY.jsxDEV("button",{type:"button",onClick:()=>B("preview"),className:`px-3 py-1 text-xs font-medium rounded-md transition-all ${H==="preview"?"bg-background text-foreground shadow-sm border border-border":"text-muted-foreground hover:text-foreground border border-transparent"}`,children:"Preview"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),gY.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:N,"aria-label":"Open in editor",children:gY.jsxDEV(XA,{className:"h-3.5 w-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H==="edit"?gY.jsxDEV(eW,{value:Z??"",onChange:J,onSubmit:Q,projectId:K,storeCode:Y,path:`template-param-${X}.md`,autoGrow:!0,lineNumbers:"off",minHeight:U,maxHeight:z,autoFocus:G},void 0,!1,void 0,this):gY.jsxDEV("div",{className:"p-4 border border-border rounded-md bg-muted overflow-auto",style:{minHeight:U,maxHeight:z},children:gY.jsxDEV(fQ,{markdown:Z??""},void 0,!1,void 0,this)},void 0,!1,void 0,this),gY.jsxDEV(S3,{open:F,onOpenChange:M,value:A,onSave:(R)=>{J?.(R),M(!1)},projectId:K,storeCode:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var j3=G0(X8(),1),bN0=({value:Z,onChange:J,fieldDef:Q,readOnly:X,projectId:K,storeCode:Y,className:U,mode:z="textarea"})=>{let[W,G]=vN0.useState(!1),q=Q.rows??3;if(z==="monaco"){let H=Q.description?j3.jsxDEV("span",{className:"text-sm text-muted-foreground",children:Q.description},void 0,!1,void 0,this):null;return j3.jsxDEV("div",{className:a8("relative",U),children:j3.jsxDEV(ry,{value:Z??"",onChange:J,fieldName:Q.name,projectId:K,storeCode:Y,readOnly:X,headerLeft:H},void 0,!1,void 0,this)},void 0,!1,void 0,this)}if(X)return j3.jsxDEV("div",{className:a8("text-sm p-2 rounded-md border border-transparent",U),style:{height:`${q*1.5}rem`,overflowY:"auto"},children:Z||""},void 0,!1,void 0,this);return j3.jsxDEV("div",{className:a8("relative",U),children:[j3.jsxDEV(eF,{value:Z??"",onChange:(H)=>J(H.target.value),rows:q,className:"pr-8"},void 0,!1,void 0,this),j3.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-6 w-6",onClick:()=>G(!0),"aria-label":"Open in editor",children:j3.jsxDEV(XA,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),j3.jsxDEV(S3,{open:W,onOpenChange:G,value:Z??"",onSave:(H)=>{J(H),G(!1)},projectId:K,storeCode:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var rC6=G0(s0(),1);var fN0=G0(X8(),1),xN0=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q){let K=Z!=null?new Intl.NumberFormat().format(Z):"";return fN0.jsxDEV("span",{className:a8("text-sm",X),children:K},void 0,!1,void 0,this)}return fN0.jsxDEV(yZ,{type:"number",step:"1",value:Z??"",onChange:(K)=>J(K.target.value),className:X},void 0,!1,void 0,this)};var aC6=G0(s0(),1);var hN0=G0(X8(),1),yN0=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q){let K=Z!=null?new Intl.NumberFormat().format(Z):"";return hN0.jsxDEV("span",{className:a8("text-sm",X),children:K},void 0,!1,void 0,this)}return hN0.jsxDEV(yZ,{type:"number",step:"any",value:Z??"",onChange:(K)=>J(K.target.value),className:X},void 0,!1,void 0,this)};var E80=G0(s0(),1);var ay="",oy=()=>({"Content-Type":"application/json","X-Session-Id":D7()});async function WF8(Z,J){let Q=J[1];switch(Q){case"d":case"t":{let X=await fetch(`${ay}/api/p/${Z}/documents/${J}`,{headers:oy()}),K=await X6(X,"Failed to fetch entity metadata");return{name:K.name,type:K.type,subtype:K.subtype??null}}case"f":{let X=await fetch(`${ay}/api/p/${Z}/folders/${J}`,{headers:oy()}),K=await X6(X,"Failed to fetch entity metadata");return{name:K.name,type:"f",subtype:K.subtype??null}}case"s":{let X=await fetch(`${ay}/api/p/${Z}/stories/${J}`,{headers:oy()});return{name:(await X6(X,"Failed to fetch entity metadata")).name,type:"s",subtype:null}}case"j":{let X=await fetch(`${ay}/api/p/${Z}/jobs/${J}`,{headers:oy()});return{name:(await X6(X,"Failed to fetch entity metadata")).name,type:"j",subtype:null}}case"e":{let X=await fetch(`${ay}/api/p/${Z}/tracks/${J}`,{headers:oy()});return{name:(await X6(X,"Failed to fetch entity metadata")).name,type:"e",subtype:"track"}}default:throw Error(`Unrecognised entity type code: ${Q} (entity ID: ${J})`)}}function YM(Z,J){return k7({queryKey:["entityMetadata",Z,J],queryFn:()=>WF8(Z,J),enabled:!!J,staleTime:300000,gcTime:1800000})}var oC6={d:{default:{icon:gX,draftIcon:aH},task:{icon:$W,draftIcon:uk},cartridge:{icon:LV,draftIcon:LV},scratch:{icon:MV,draftIcon:MV}},t:{default:{icon:Y2,draftIcon:aH},prompt:{icon:DK,draftIcon:DK},"saved-search":{icon:tM,draftIcon:tM}},f:{default:{icon:$z,openIcon:iw,loadingIcon:O9},tasks:{icon:sk}},j:{default:{icon:ZX}},e:{default:{icon:BJ},track:{icon:BJ}},s:{default:{icon:xX}}};function M5(Z,J,{hasDraft:Q,isOpen:X,isLoading:K}={}){let Y=oC6[Z];if(!Y)return gX;let U=Y[J]||Y.default;if(!U)return gX;if(Z==="f"){if(K&&U.loadingIcon)return U.loadingIcon;if(X&&U.openIcon)return U.openIcon;return U.icon}if(Q&&U.draftIcon)return U.draftIcon;return U.icon}var GJ=G0(X8(),1),GF8=({entityId:Z,projectId:J})=>{let{data:Q,isLoading:X,isError:K}=YM(J,Z);if(!Z)return null;if(X||K||!Q)return GJ.jsxDEV("span",{className:"text-sm text-muted-foreground font-mono",children:Z},void 0,!1,void 0,this);let Y=M5(Q.type,Q.subtype);return GJ.jsxDEV("span",{className:"inline-flex items-center gap-1.5 text-sm",children:[GJ.jsxDEV(Y,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),GJ.jsxDEV("span",{children:Q.name},void 0,!1,void 0,this),GJ.jsxDEV("span",{className:"text-xs text-muted-foreground font-mono",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},tC6=({value:Z,onChange:J,projectId:Q,className:X,externalError:K,onValidationChange:Y,paramName:U})=>{let z=typeof Z==="string"?Z.trim():Z,W=z!==null&&z!==void 0&&z!=="",{data:G,isLoading:q,isError:H}=YM(Q,W?z:null),B=W&&!q&&(H||!G),F=!!K||B,M=K||(B?`Entity '${z}' not found`:null);return E80.useEffect(()=>{if(!Y)return;Y(U,!F,F?M:null)},[Y,U,F,M]),E80.useEffect(()=>{return()=>{if(Y)Y(U,!0,null)}},[Y,U]),GJ.jsxDEV("div",{className:a8("space-y-1",X),children:[GJ.jsxDEV(yZ,{type:"text",value:Z??"",onChange:(A)=>J(A.target.value),placeholder:"Entity ID (e.g. Ad123)",className:F?"border-destructive focus-visible:ring-destructive":void 0,"aria-invalid":F||void 0},void 0,!1,void 0,this),W&&!F&&GJ.jsxDEV(GF8,{entityId:z,projectId:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};function eC6(Z){let J=new Map;for(let Q of Z){let X=Q.group??"";if(!J.has(X))J.set(X,[]);J.get(X).push(Q)}return Array.from(J.entries()).map(([Q,X])=>({group:Q,items:X}))}var gN0=({value:Z,onChange:J,readOnly:Q,fieldDef:X,isLoading:K,projectId:Y,className:U,error:z,onValidationChange:W})=>{if(Q)return GJ.jsxDEV("div",{className:a8(U),children:GJ.jsxDEV(GF8,{entityId:Z,projectId:Y},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(K)return GJ.jsxDEV(g7,{disabled:!0,children:[GJ.jsxDEV(_7,{className:a8("w-full",U),children:GJ.jsxDEV(m7,{placeholder:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),GJ.jsxDEV(v7,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(X?.allowed?.options){let G=eC6(X.allowed.options),q=G.length>1;return GJ.jsxDEV(g7,{value:Z||"",onValueChange:J,children:[GJ.jsxDEV(_7,{className:a8("w-full",U),children:GJ.jsxDEV(m7,{placeholder:"Select..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),GJ.jsxDEV(v7,{children:q?G.map(({group:H,items:B})=>GJ.jsxDEV(AU,{children:[GJ.jsxDEV(G2,{children:H},void 0,!1,void 0,this),B.map((F)=>GJ.jsxDEV(l9,{value:F.value,children:F.label},F.value,!1,void 0,this))]},H,!0,void 0,this)):G.flatMap(({items:H})=>H.map((B)=>GJ.jsxDEV(l9,{value:B.value,children:B.label},B.value,!1,void 0,this)))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}return GJ.jsxDEV(tC6,{value:Z,onChange:J,projectId:Y,className:U,externalError:z,onValidationChange:W,paramName:X?.name},void 0,!1,void 0,this)};var YI6=G0(s0(),1);var LF8=G0(s0(),1);var d2=G0(s0(),1);var JW=G0(VZ(),1),S80="Checkbox",[ZI6,nO1]=n5(S80),[JI6,mN0]=ZI6(S80);function QI6(Z){let{__scopeCheckbox:J,checked:Q,children:X,defaultChecked:K,disabled:Y,form:U,name:z,onCheckedChange:W,required:G,value:q="on",internal_do_not_use_render:H}=Z,[B,F]=n4({prop:Q,defaultProp:K??!1,onChange:W,caller:S80}),[M,A]=d2.useState(null),[w,N]=d2.useState(null),R=d2.useRef(!1),P=M?!!U||!!M.closest("form"):!0,V={checked:B,disabled:Y,setChecked:F,control:M,setControl:A,name:z,form:U,value:q,hasConsumerStoppedPropagationRef:R,required:G,defaultChecked:_N(K)?!1:K,isFormControl:P,bubbleInput:w,setBubbleInput:N};return JW.jsx(JI6,{scope:J,...V,children:XI6(H)?H(V):X})}var qF8="CheckboxTrigger",HF8=d2.forwardRef(({__scopeCheckbox:Z,onKeyDown:J,onClick:Q,...X},K)=>{let{control:Y,value:U,disabled:z,checked:W,required:G,setControl:q,setChecked:H,hasConsumerStoppedPropagationRef:B,isFormControl:F,bubbleInput:M}=mN0(qF8,Z),A=QZ(K,q),w=d2.useRef(W);return d2.useEffect(()=>{let N=Y?.form;if(N){let R=()=>H(w.current);return N.addEventListener("reset",R),()=>N.removeEventListener("reset",R)}},[Y,H]),JW.jsx(f9.button,{type:"button",role:"checkbox","aria-checked":_N(W)?"mixed":W,"aria-required":G,"data-state":MF8(W),"data-disabled":z?"":void 0,disabled:z,value:U,...X,ref:A,onKeyDown:l6(J,(N)=>{if(N.key==="Enter")N.preventDefault()}),onClick:l6(Q,(N)=>{if(H((R)=>_N(R)?!0:!R),M&&F){if(B.current=N.isPropagationStopped(),!B.current)N.stopPropagation()}})})});HF8.displayName=qF8;var uN0=d2.forwardRef((Z,J)=>{let{__scopeCheckbox:Q,name:X,checked:K,defaultChecked:Y,required:U,disabled:z,value:W,onCheckedChange:G,form:q,...H}=Z;return JW.jsx(QI6,{__scopeCheckbox:Q,checked:K,defaultChecked:Y,disabled:z,required:U,onCheckedChange:G,name:X,form:q,value:W,internal_do_not_use_render:({isFormControl:B})=>JW.jsxs(JW.Fragment,{children:[JW.jsx(HF8,{...H,ref:J,__scopeCheckbox:Q}),B&&JW.jsx(OF8,{__scopeCheckbox:Q})]})})});uN0.displayName=S80;var BF8="CheckboxIndicator",pN0=d2.forwardRef((Z,J)=>{let{__scopeCheckbox:Q,forceMount:X,...K}=Z,Y=mN0(BF8,Q);return JW.jsx(bJ,{present:X||_N(Y.checked)||Y.checked===!0,children:JW.jsx(f9.span,{"data-state":MF8(Y.checked),"data-disabled":Y.disabled?"":void 0,...K,ref:J,style:{pointerEvents:"none",...Z.style}})})});pN0.displayName=BF8;var FF8="CheckboxBubbleInput",OF8=d2.forwardRef(({__scopeCheckbox:Z,...J},Q)=>{let{control:X,hasConsumerStoppedPropagationRef:K,checked:Y,defaultChecked:U,required:z,disabled:W,name:G,value:q,form:H,bubbleInput:B,setBubbleInput:F}=mN0(FF8,Z),M=QZ(Q,F),A=vl(Y),w=vp(X);d2.useEffect(()=>{let R=B;if(!R)return;let P=window.HTMLInputElement.prototype,$=Object.getOwnPropertyDescriptor(P,"checked").set,C=!K.current;if(A!==Y&&$){let D=new Event("click",{bubbles:C});R.indeterminate=_N(Y),$.call(R,_N(Y)?!1:Y),R.dispatchEvent(D)}},[B,A,Y,K]);let N=d2.useRef(_N(Y)?!1:Y);return JW.jsx(f9.input,{type:"checkbox","aria-hidden":!0,defaultChecked:U??N.current,required:z,disabled:W,name:G,value:q,form:H,...J,tabIndex:-1,ref:M,style:{...J.style,...w,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});OF8.displayName=FF8;function XI6(Z){return typeof Z==="function"}function _N(Z){return Z==="indeterminate"}function MF8(Z){return _N(Z)?"indeterminate":Z?"checked":"unchecked"}var j80=G0(X8(),1),HK=LF8.forwardRef(({className:Z,...J},Q)=>j80.jsxDEV(uN0,{ref:Q,className:a8("peer h-4 w-4 shrink-0 rounded-sm border border-primary disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",Z),...J,children:j80.jsxDEV(pN0,{className:a8("flex items-center justify-center text-current"),children:j80.jsxDEV(hX,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this));HK.displayName="Checkbox";var cN0=G0(X8(),1),lN0=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q)return cN0.jsxDEV("span",{className:a8("text-sm",X),children:Z?"Yes":"No"},void 0,!1,void 0,this);return cN0.jsxDEV(HK,{checked:!!Z,onCheckedChange:(K)=>J(K),className:X},void 0,!1,void 0,this)};var UI6=G0(s0(),1);var dN0=G0(X8(),1),k80=({value:Z,onChange:J,readOnly:Q,className:X})=>{if(Q){let K=Z;try{if(Z)K=JSON.stringify(JSON.parse(Z),null,2)}catch{}return dN0.jsxDEV("pre",{className:a8("text-sm font-mono whitespace-pre-wrap",X),children:K??""},void 0,!1,void 0,this)}return dN0.jsxDEV(eF,{value:Z??"",onChange:(K)=>J(K.target.value),className:a8("font-mono",X)},void 0,!1,void 0,this)};var XW=G0(s0(),1);var vN="",bN=()=>({"Content-Type":"application/json","X-Session-Id":D7()}),_80=async(Z,{store:J}={})=>{let Q=new URLSearchParams;if(J)Q.set("store",J);let X=Q.toString(),K=`${vN}/api/p/${Z}/tracks${X?`?${X}`:""}`,Y=await fetch(K,{headers:bN()});return X6(Y,"Failed to list tracks")},AF8=async(Z,{store:J,name:Q,states:X})=>{let K=await fetch(`${vN}/api/p/${Z}/tracks`,{method:"POST",headers:bN(),body:JSON.stringify({store:J,name:Q,states:X})});return X6(K,"Failed to create track")},NF8=async(Z,J,{name:Q,states:X,renames:K})=>{let Y=await fetch(`${vN}/api/p/${Z}/tracks/${J}`,{method:"PUT",headers:bN(),body:JSON.stringify({name:Q,states:X,renames:K})});return X6(Y,"Failed to update track")},wF8=async(Z,J)=>{let Q=await fetch(`${vN}/api/p/${Z}/tracks/${J}`,{method:"DELETE",headers:bN()});return X6(Q,"Failed to delete track")},v80=async()=>{let Z=await fetch(`${vN}/api/shared/tracks`,{headers:bN()});return X6(Z,"Failed to list shared tracks")},RF8=async({name:Z,states:J})=>{let Q=await fetch(`${vN}/api/shared/tracks`,{method:"POST",headers:bN(),body:JSON.stringify({name:Z,states:J})});return X6(Q,"Failed to create shared track")},PF8=async(Z,{name:J,states:Q,renames:X})=>{let K=await fetch(`${vN}/api/shared/tracks/${Z}`,{method:"PUT",headers:bN(),body:JSON.stringify({name:J,states:Q,renames:X})});return X6(K,"Failed to update shared track")},$F8=async(Z)=>{let J=await fetch(`${vN}/api/shared/tracks/${Z}`,{method:"DELETE",headers:bN()});return X6(J,"Failed to delete shared track")};var k3=(Z,{store:J}={})=>{let Q=!Z&&J==="B";return k7({queryKey:Q?["tracks","shared",J??"demux"]:["tracks",Z,J??"demux"],queryFn:()=>Q?v80():_80(Z,{store:J}),enabled:!!Z||Q,staleTime:30000})},TF8=(Z)=>{let J=i6();return s9({mutationFn:({store:Q,name:X,states:K})=>Z?AF8(Z,{store:Q,name:X,states:K}):RF8({name:X,states:K}),onSuccess:(Q,{store:X})=>{if(Z)J.invalidateQueries({queryKey:["tracks",Z,X??"demux"]});else J.invalidateQueries({queryKey:["tracks","shared"]})}})},VF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,name:X,states:K,renames:Y})=>Z?NF8(Z,Q,{name:X,states:K,renames:Y}):PF8(Q,{name:X,states:K,renames:Y}),onSuccess:()=>{if(Z)J.invalidateQueries({queryKey:["tracks",Z]}),J.invalidateQueries({queryKey:["stories",Z]}),J.invalidateQueries({queryKey:["fields",Z]}),J.invalidateQueries({predicate:(Q)=>Q.queryKey[0]==="templatesByType"&&Q.queryKey[1]===Z});else J.invalidateQueries({queryKey:["tracks","shared"]})}})},CF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q})=>Z?wF8(Z,Q):$F8(Q),onSuccess:()=>{if(Z)J.invalidateQueries({queryKey:["tracks",Z]});else J.invalidateQueries({queryKey:["tracks","shared"]})}})},QW=(Z,J)=>{if(!Z)return"";let Q=(J||[]).find((X)=>X.id===Z);if(!Q)return Z;return Q.name};var T6=G0(X8(),1);var IF8=["waiting","ready","in-progress","done"],DF8=["usage-resumption"],EF8={s:{label:"Stories",visibilityKey:"story"},"d/task":{label:"Tasks",visibilityKey:"task"},j:{label:"Jobs",visibilityKey:"job"}},zI6=(Z)=>{if(!Z)return{ok:!0,data:{}};try{let J=JSON.parse(Z);if(!J||typeof J!=="object"||Array.isArray(J))return{ok:!1,error:"Expected an object"};let Q=J.visibility;if(Q!==void 0&&(typeof Q!=="object"||Array.isArray(Q)||Q===null))return{ok:!1,error:"visibility must be an object"};return{ok:!0,data:Q??{}}}catch(J){return{ok:!1,error:`Invalid JSON: ${J.message}`}}},WI6=(Z)=>{let J={},Q=Z.story;if(Q&&typeof Q==="object"){let Y=Object.entries(Q).filter(([,U])=>Array.isArray(U)&&U.length>0);if(Y.length>0)J.story=Object.fromEntries(Y)}let X=Z.task;if(X&&Array.isArray(X._stages)&&X._stages.length>0)J.task={_stages:X._stages};let K=Z.job;if(K&&Array.isArray(K._contexts)&&K._contexts.length>0)J.job={_contexts:K._contexts};if(Object.keys(J).length===0)return null;return JSON.stringify({visibility:J})},GI6=(Z,J)=>{if(!J)return"None";if(Z==="story"){let Q=Object.keys(J).length;return Q>0?`${Q} track${Q!==1?"s":""}`:"None"}if(Z==="task"){let Q=Array.isArray(J._stages)?J._stages.length:0;return Q>0?`${Q} stage${Q!==1?"s":""}`:"None"}if(Z==="job"){let Q=Array.isArray(J._contexts)?J._contexts.length:0;return Q>0?`${Q} context${Q!==1?"s":""}`:"None"}return"None"},qI6=(Z,J)=>{if(!J)return!1;if(Z==="story")return Object.values(J).some((Q)=>Array.isArray(Q)&&Q.length>0);if(Z==="task")return Array.isArray(J._stages)&&J._stages.length>0;if(Z==="job")return Array.isArray(J._contexts)&&J._contexts.length>0;return!1},SF8=({value:Z,onChange:J,editable:Q,className:X,projectId:K,storeCode:Y})=>{let U=XW.useMemo(()=>zI6(Z),[Z]),[z,W]=XW.useState(()=>U.ok?U.data:{}),[G,q]=XW.useState(!1),[H,B]=XW.useState(null),[F,M]=XW.useState(null),[A,w]=XW.useState(null);XW.useEffect(()=>{if(U.ok)W(U.data)},[Z]);let{data:N=[]}=k3(G?K:null,{store:"all"}),R=XW.useCallback((e)=>{if(q(e),!e)B(null),M(null)},[]),P=(e)=>{W(e),J(WI6(e))};if(!U.ok)return T6.jsxDEV("div",{className:a8("space-y-1",X),children:T6.jsxDEV("p",{className:"text-xs text-destructive",children:U.error},void 0,!1,void 0,this)},void 0,!1,void 0,this);let V=(e)=>{let r={...z};delete r[e],P(r),w(null)},$=(e)=>{M(e),B("story-stages")},C=(e)=>{let r={...z.story||{}};delete r[e],P({...z,story:r})},D=(e)=>{M(e),B("story-stages")},E=(e,r,W0)=>{let t=Array.isArray(z.story?.[e])?z.story[e]:[],U0=W0?[...t,r]:t.filter((o)=>o!==r),n={...z.story||{}};if(U0.length===0)delete n[e];else n[e]=U0;P({...z,story:n})},S=(e,r)=>{let W0=Array.isArray(z.task?._stages)?z.task._stages:[],t=r?[...W0,e]:W0.filter((U0)=>U0!==e);P({...z,task:{_stages:t}})},f=(e,r)=>{let W0=Array.isArray(z.job?._contexts)?z.job._contexts:[],t=r?[...W0,e]:W0.filter((U0)=>U0!==e);P({...z,job:{_contexts:t}})},j=Object.keys(z.story||{}),b=(Y==="B"?N.filter((e)=>e.storeCode==="B"):N).filter((e)=>!j.includes(e.id)),x=N.find((e)=>e.id===F)?.states||[],h=Array.isArray(z.story?.[F])?z.story[F]:[],u=()=>T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{children:[T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Visibility Configuration"},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Prompt will be available from:"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("div",{className:"space-y-1",children:Object.entries(EF8).map(([,{label:e,visibilityKey:r}])=>{let W0=z[r],t=qI6(r,W0);return T6.jsxDEV("div",{className:"flex items-center gap-1",children:[T6.jsxDEV("button",{type:"button",className:"flex items-center gap-1 text-sm text-left px-2 py-1.5 rounded hover:bg-accent",onClick:()=>B(r==="story"?"story":r),children:[T6.jsxDEV("span",{children:e},void 0,!1,void 0,this),T6.jsxDEV(IZ,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("span",{className:"flex-1 text-xs text-muted-foreground",children:GI6(r,W0)},void 0,!1,void 0,this),t&&Q&&T6.jsxDEV("button",{type:"button",className:"p-1 text-muted-foreground hover:text-destructive",onClick:()=>w(r),"aria-label":`Remove ${e} visibility`,children:T6.jsxDEV(iZ,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},r,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m=()=>T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>B(null),children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Story Visibility"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Select a track to view stages"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1",children:[j.map((e)=>{let r=Array.isArray(z.story[e])?z.story[e].length:0,W0=(N||[]).find((U0)=>U0.id===e),t=W0?W0.name:QW(e,N);return T6.jsxDEV("div",{className:"flex items-center gap-1",children:[T6.jsxDEV("button",{type:"button",className:"flex items-center gap-1 text-sm text-left px-2 py-1.5 rounded hover:bg-accent",onClick:()=>$(e),children:[W0&&T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:t},void 0,!1,void 0,this),W0&&T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[W0.storeCode]||S7.A}`,children:W0.id},void 0,!1,void 0,this),T6.jsxDEV(IZ,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("span",{className:"flex-1 text-xs text-muted-foreground",children:[r," stage",r!==1?"s":""]},void 0,!0,void 0,this),Q&&T6.jsxDEV("button",{type:"button",className:"p-1 text-muted-foreground hover:text-destructive",onClick:()=>C(e),"aria-label":`Remove ${t} track`,children:T6.jsxDEV(iZ,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},e,!0,void 0,this)}),j.length===0&&T6.jsxDEV("p",{className:"text-xs text-muted-foreground italic px-2",children:"No tracks configured"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&b.length>0&&T6.jsxDEV("div",{className:"border-t pt-2",children:[T6.jsxDEV("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Add track"},void 0,!1,void 0,this),T6.jsxDEV(g7,{value:"",onValueChange:D,children:[T6.jsxDEV(_7,{className:"h-7 text-xs",children:T6.jsxDEV(m7,{placeholder:"Select..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV(v7,{children:[b.filter((e)=>e.storeCode!=="B").length>0&&T6.jsxDEV(AU,{children:[T6.jsxDEV(G2,{children:"Project"},void 0,!1,void 0,this),b.filter((e)=>e.storeCode!=="B").map((e)=>T6.jsxDEV(l9,{value:e.id,children:T6.jsxDEV("span",{className:"inline-flex items-center gap-1.5",children:[T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:e.name},void 0,!1,void 0,this),T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[e.storeCode]||S7.A}`,children:e.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},e.id,!1,void 0,this))]},void 0,!0,void 0,this),b.filter((e)=>e.storeCode==="B").length>0&&T6.jsxDEV(AU,{children:[T6.jsxDEV(G2,{children:"Shared"},void 0,!1,void 0,this),b.filter((e)=>e.storeCode==="B").map((e)=>T6.jsxDEV(l9,{value:e.id,children:T6.jsxDEV("span",{className:"inline-flex items-center gap-1.5",children:[T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:e.name},void 0,!1,void 0,this),T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[e.storeCode]||S7.A}`,children:e.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},e.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y=()=>{let e=x.length,r=h.length;return T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>{B("story"),M(null)},children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:(()=>{let W0=(N||[]).find((U0)=>U0.id===F),t=W0?W0.name:QW(F,N);return T6.jsxDEV(T6.Fragment,{children:["Track:",W0&&T6.jsxDEV(BJ,{className:"w-4 h-4 shrink-0 text-muted-foreground"},void 0,!1,void 0,this),T6.jsxDEV("span",{children:t},void 0,!1,void 0,this),W0&&T6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono shrink-0 ${S7[W0.storeCode]||S7.A}`,children:W0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Prompt visible for these stages"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1.5 max-h-64 overflow-y-auto",children:[x.map((W0)=>T6.jsxDEV("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[T6.jsxDEV("input",{type:"checkbox",checked:h.includes(W0),onChange:(t)=>Q&&E(F,W0,t.target.checked),disabled:!Q,className:"rounded"},void 0,!1,void 0,this),W0]},W0,!0,void 0,this)),e===0&&T6.jsxDEV("p",{className:"text-xs text-muted-foreground italic",children:"No stages defined for this track"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e>0&&T6.jsxDEV("p",{className:"text-xs text-muted-foreground border-t pt-1",children:[r," of ",e," selected"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},p=()=>{let e=Array.isArray(z.task?._stages)?z.task._stages:[];return T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>B(null),children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Task Visibility"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Prompt visible for these stages"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1.5",children:IF8.map((r)=>T6.jsxDEV("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[T6.jsxDEV("input",{type:"checkbox",checked:e.includes(r),onChange:(W0)=>Q&&S(r,W0.target.checked),disabled:!Q,className:"rounded"},void 0,!1,void 0,this),r]},r,!0,void 0,this))},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground border-t pt-1",children:[e.length," of ",IF8.length," selected"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},l=()=>{let e=Array.isArray(z.job?._contexts)?z.job._contexts:[];return T6.jsxDEV("div",{className:"space-y-3",children:[T6.jsxDEV("div",{className:"flex items-center gap-1.5",children:[T6.jsxDEV("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>B(null),children:T6.jsxDEV(yX,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("h3",{className:"text-sm font-medium",children:"Job Visibility"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Prompt visible for these contexts"},void 0,!1,void 0,this),T6.jsxDEV("div",{className:"space-y-1.5",children:DF8.map((r)=>T6.jsxDEV("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[T6.jsxDEV("input",{type:"checkbox",checked:e.includes(r),onChange:(W0)=>Q&&f(r,W0.target.checked),disabled:!Q,className:"rounded"},void 0,!1,void 0,this),r]},r,!0,void 0,this))},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-xs text-muted-foreground border-t pt-1",children:[e.length," of ",DF8.length," selected"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},d=()=>{let e=H==="story"||H==="story-stages",r=H==="story-stages",W0=e||H==="task"||H==="job";return T6.jsxDEV("div",{className:"relative",children:[T6.jsxDEV("div",{className:"p-4 w-52",children:u()},void 0,!1,void 0,this),W0&&T6.jsxDEV("div",{className:"absolute top-0 left-full flex items-start",style:{marginLeft:"20px",gap:"20px"},children:[e&&T6.jsxDEV("div",{className:"p-4 w-80 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:m()},void 0,!1,void 0,this),H==="task"&&T6.jsxDEV("div",{className:"p-4 w-80 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:p()},void 0,!1,void 0,this),H==="job"&&T6.jsxDEV("div",{className:"p-4 w-80 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:l()},void 0,!1,void 0,this),r&&T6.jsxDEV("div",{className:"p-4 w-64 shrink-0 rounded-md border bg-popover text-popover-foreground shadow-md",children:y()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},Z0=(e)=>{return Object.values(EF8).find((W0)=>W0.visibilityKey===e)?.label??e};return T6.jsxDEV(T6.Fragment,{children:[T6.jsxDEV("div",{className:a8(X),children:T6.jsxDEV(jK,{open:G,onOpenChange:R,children:[T6.jsxDEV(kK,{asChild:!0,children:T6.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",children:"View/Edit Config"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV(sX,{className:"w-auto p-0 overflow-visible",align:"start",side:"top",sideOffset:48,children:d()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV(E7,{open:A!==null,onOpenChange:(e)=>{if(!e)w(null)},children:T6.jsxDEV(T7,{children:[T6.jsxDEV(A7,{children:T6.jsxDEV(N7,{children:["Remove ",Z0(A)," visibility settings?"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"This will clear all visibility rules for this type. This cannot be undone."},void 0,!1,void 0,this),T6.jsxDEV(t7,{children:[T6.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",onClick:()=>w(null),children:"Cancel"},void 0,!1,void 0,this),T6.jsxDEV(c0,{type:"button",variant:"destructive",size:"sm",onClick:()=>V(A),children:"Remove"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var OI6=G0(s0(),1);var jF8=G0(s0(),1);var HI6=r7.create({namespace:"caw:perf:publish"});var AH=(Z,J)=>{return k7({queryKey:["document",J],queryFn:()=>bz(Z,J),enabled:!!Z&&!!J})},fN=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,content:X})=>gv(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]})}})},YS=(Z)=>{let J=i6(),Q=jF8.useRef(0);return s9({mutationFn:async({id:X})=>{let K=performance.now(),Y=await xl0(Z,X);return Q.current=Math.round(performance.now()-K),Y},onSuccess:async(X,{id:K})=>{let Y=Q.current,U=performance.now(),W=await Promise.all([{label:"document",queryKey:["document",K]},{label:"documents",queryKey:["documents"]},{label:"versions",queryKey:["versions",K]},{label:"parameters",queryKey:["parameters",K]}].map(async({label:H,queryKey:B})=>{let F=performance.now();return await J.invalidateQueries({queryKey:B}),{label:H,ms:Math.round(performance.now()-F)}})),G=Math.round(performance.now()-U),q=Y+G;if(q>=300){let H=W.map((B)=>`${B.label}=${B.ms}`).join(" ");HI6.warn("PERF_PUBLISH_CLIENT id=%s totalMs=%d requestMs=%d refetchMs=%d %s",K,q,Y,G,H)}}})},US=(Z)=>{let J=i6();return s9({mutationFn:({id:Q})=>hl0(Z,Q),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]})}})},xN=(Z,J)=>{return k7({queryKey:["versions",J],queryFn:()=>yl0(Z,J),enabled:!!Z&&!!J})},kF8=(Z,J,{enabled:Q}={})=>{return k7({queryKey:["incomingReferences",J],queryFn:()=>gl0(Z,J),enabled:!!Q&&!!Z&&!!J})},zS=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,ack:X})=>XP(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["versions",X]}),J.invalidateQueries({queryKey:["folderContents"]})}})},u$=(Z)=>{let J=i6();return s9({mutationFn:({parentId:Q,name:X,content:K,subtype:Y,fields:U})=>qI(Z,{parentId:Q,name:X,content:K,subtype:Y,fields:U}),onSuccess:()=>{J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]})}})},_F8=(Z)=>{let J=i6();return s9({mutationFn:({parentId:Q,name:X,content:K,subtype:Y,fields:U})=>fl0(Z,{parentId:Q,name:X,content:K,subtype:Y,fields:U}),onSuccess:()=>{J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]})}})},WS=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,path:X,parentId:K})=>mv(Z,Q,{path:X,parentId:K}),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]})}})},b80=(Z,J)=>{return k7({queryKey:["parameters",J],queryFn:()=>ml0(Z,J),enabled:!!Z&&!!J,select:(Q)=>{let X=Q?.parameters?Object.entries(Q.parameters).map(([w,N])=>({name:w,...N})):[],K=Q?.target==="stdout"?"clipboard":Q?.target||null,Y=Q?.targetPath||null,U=Q?.path||null,z=Q?.targetParentId||null,W=Q?.targetName||null,G=Q?.targetRoot||null,q=Q?.targetStore||null,H=Q?.targetConfig||null,B=Q?.skipDialog??!1,F=Q?.targetFields||null,M=Q?.targetSubtype||null,A=Q?.templateSubtype||null;return{parameters:X,target:K,targetPath:Y,path:U,targetParentId:z,targetName:W,targetRoot:G,targetStore:q,targetConfig:H,skipDialog:B,targetFields:F,targetSubtype:M,templateSubtype:A}}})},vF8=(Z)=>{return s9({mutationFn:({id:J,params:Q,target:X,targetOptions:K})=>ul0(Z,J,{params:Q,target:X,targetOptions:K})})},BI6=(Z,J,{store:Q,storyId:X}={})=>["templatesByType",Z,J,Q??"A",X??null],i2=(Z,J,{store:Q,storyId:X}={})=>{return k7({queryKey:BI6(Z,J,{store:Q,storyId:X}),queryFn:()=>pl0(Z,J,{store:Q,storyId:X}),enabled:!!Z&&!!J})},bF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q,subtype:X,fields:K})=>ll0(Z,Q,{subtype:X,fields:K}),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]}),J.invalidateQueries({queryKey:["fields",Z,X]})}})},fF8=(Z)=>{let J=i6();return s9({mutationFn:({id:Q})=>dl0(Z,Q),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["document",X]}),J.invalidateQueries({queryKey:["documents"]}),J.invalidateQueries({queryKey:["folderContents"]}),J.invalidateQueries({queryKey:["fields",Z,X]})}})};function s2(Z,J,Q={},{missingSectionMode:X="hidden"}={}){return Z.filter((K)=>FI6(K,J,Q,X))}function FI6(Z,J,Q,X){let{config:K}=Z;if(!K)return!1;let Y;try{Y=JSON.parse(K)}catch{return!1}let U=Y?.visibility;if(!U)return!1;let z=U[J];if(!z)return X==="passthrough";if(J==="story"){let W=z[Q.trackId];if(!Array.isArray(W))return!1;return W.includes(Q.states)}if(J==="task"){let W=z._stages;if(!Array.isArray(W)||W.length===0)return!0;return W.includes(Q.states)}if(J==="job"){let W=z._contexts;if(!Array.isArray(W)||W.length===0)return!0;return W.includes(Q.contexts)}return!0}var hN=G0(X8(),1),xF8=({value:Z,onChange:J,readOnly:Q,projectId:X,fieldDef:K})=>{let{data:Y}=i2(X,K.templateType),U=s2(Y?.templates??[],K.templateEntityType,{contexts:K.templateVisibilityContext});if(Q){let z=U.find((W)=>W.id===Z);return hN.jsxDEV("span",{className:"text-sm",children:z?z.name?.replace(/\.md$/,""):Z},void 0,!1,void 0,this)}return hN.jsxDEV(g7,{value:Z||"__none__",onValueChange:(z)=>J(z==="__none__"?null:z),children:[hN.jsxDEV(_7,{children:hN.jsxDEV(m7,{placeholder:"None"},void 0,!1,void 0,this)},void 0,!1,void 0,this),hN.jsxDEV(v7,{children:[hN.jsxDEV(l9,{value:"__none__",children:"None"},void 0,!1,void 0,this),U.map((z)=>hN.jsxDEV(l9,{value:z.id,children:z.name?.replace(/\.md$/,"")},z.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var MI6=G0(s0(),1);var _G=G0(X8(),1),hF8=({value:Z,onChange:J,readOnly:Q,projectId:X})=>{let{data:K}=k3(X,{store:"all"}),Y=K??[];if(Q){let W=Y.find((G)=>G.id===Z);return _G.jsxDEV("span",{className:"text-sm",children:W?W.name:Z},void 0,!1,void 0,this)}let U=Y.filter((W)=>W.storeCode!=="B"),z=Y.filter((W)=>W.storeCode==="B");return _G.jsxDEV(g7,{value:Z??"",onValueChange:(W)=>J(W),children:[_G.jsxDEV(_7,{children:_G.jsxDEV(m7,{placeholder:"Select track"},void 0,!1,void 0,this)},void 0,!1,void 0,this),_G.jsxDEV(v7,{children:[U.length>0&&_G.jsxDEV(AU,{children:[_G.jsxDEV(G2,{children:"Project"},void 0,!1,void 0,this),U.map((W)=>_G.jsxDEV(l9,{value:W.id,children:W.name},W.id,!1,void 0,this))]},void 0,!0,void 0,this),z.length>0&&_G.jsxDEV(AU,{children:[_G.jsxDEV(G2,{children:"Shared"},void 0,!1,void 0,this),z.map((W)=>_G.jsxDEV(l9,{value:W.id,children:W.name},W.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var iN0=G0(X8(),1),AI6={string:rY0,text:bN0,int:xN0,float:yN0,date:Mv,object_ref:gN0,boolean:lN0,json:k80},NI6={"caw:visibility-config":SF8,"caw:template-selector":xF8,"caw:track-selector":hF8},wI6=({value:Z,onChange:J,fieldDef:Q,readOnly:X,projectId:K,storeCode:Y,className:U,isLoading:z,fieldValues:W,onFieldChange:G,editable:q,mode:H,error:B,onValidationChange:F})=>{let M=X||Q.editable===!1;if(Q.jsonSchema){let w=NI6[Q.jsonSchema.$id];return iN0.jsxDEV(w||k80,{value:Z,onChange:J,fieldDef:Q,readOnly:M,projectId:K,storeCode:Y,className:U,isLoading:z,...w?{fieldValues:W,onFieldChange:G,editable:q}:{}},void 0,!1,void 0,this)}let A=AI6[Q.primitiveType];if(!A)throw Error(`No renderer for primitiveType: ${Q.primitiveType}`);return iN0.jsxDEV(A,{value:Z,onChange:J,fieldDef:Q,readOnly:M,projectId:K,storeCode:Y,className:U,isLoading:z,mode:H,error:B,onValidationChange:F},void 0,!1,void 0,this)},Zz=wI6;var cJ=G0(s0(),1);var RI6=G0(s0(),1);var G4=G0(X8(),1),f80=({values:Z,editable:J,editingRowIndex:Q,dirtyFlags:X,rowExtras:K,onEditingRowIndexChange:Y,onEditRow:U,onUndoRow:z,onMoveUp:W,onMoveDown:G,onRemove:q,renderEditingCell:H,renderReadOnlyCell:B})=>G4.jsxDEV("table",{className:"w-full text-sm border-collapse",children:[G4.jsxDEV("thead",{children:G4.jsxDEV("tr",{className:"border-b",children:[G4.jsxDEV("th",{className:"text-left py-1 px-1 w-8 text-muted-foreground font-medium",children:"#"},void 0,!1,void 0,this),G4.jsxDEV("th",{className:"text-left py-1 px-1 text-muted-foreground font-medium",children:"Value"},void 0,!1,void 0,this),J&&G4.jsxDEV("th",{className:"text-right py-1 px-1 w-28 text-muted-foreground font-medium",children:"Actions"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),G4.jsxDEV("tbody",{children:Z.map((F,M)=>{let A=Q===M;return G4.jsxDEV("tr",{className:"border-b border-border/50",children:[G4.jsxDEV("td",{className:"py-1 px-1 text-muted-foreground",children:M+1},void 0,!1,void 0,this),G4.jsxDEV("td",{className:"py-1 px-1 min-w-0",children:[A?H({index:M,value:F,onChange:(w)=>U(M,w)}):B({index:M,value:F}),K?.[M]??null]},void 0,!0,void 0,this),J&&(()=>{let w=X[M];return G4.jsxDEV("td",{className:"py-1 px-1 text-right",children:G4.jsxDEV("div",{className:"inline-flex items-center gap-0",children:[w?G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>z(M),title:"Undo",children:G4.jsxDEV(mX,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this):G4.jsxDEV("span",{className:"h-5 w-5 inline-block"},void 0,!1,void 0,this),G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>Y(A?null:M),title:A?"Done":"Edit",children:A?G4.jsxDEV(hX,{className:"w-3 h-3"},void 0,!1,void 0,this):G4.jsxDEV(iQ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M>0?G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>W(M),title:"Move up",children:G4.jsxDEV(zq,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this):G4.jsxDEV("span",{className:"h-5 w-5 inline-block"},void 0,!1,void 0,this),M<Z.length-1?G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>G(M),title:"Move down",children:G4.jsxDEV(NF,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this):G4.jsxDEV("span",{className:"h-5 w-5 inline-block"},void 0,!1,void 0,this),G4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 hover:text-destructive",onClick:()=>q(M),title:"Remove",children:G4.jsxDEV(iZ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)})()]},M,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this);var PI6=G0(s0(),1),yF8=G0(X8(),1),x80=({value:Z,maxWidth:J})=>yF8.jsxDEV("span",{className:"text-sm block",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:J||"100%"},title:Z||"",children:Z||""},void 0,!1,void 0,this);var TX=G0(s0(),1);var I4=G0(X8(),1),gF8=({value:Z,onChange:J,fieldDef:Q,editable:X,projectId:K,storeCode:Y,originalValue:U,rowExtras:z,className:W})=>{let[G,q]=TX.useState(!1),[H,B]=TX.useState(null),[F,M]=TX.useState(!1),[A,w]=TX.useState(""),[N,R]=TX.useState(0),P=Array.isArray(Z)?Z:[],V=Array.isArray(U)?U:[],$=P.length===0,C=TX.useMemo(()=>{let y=new Map;return V.forEach((p)=>y.set(p,(y.get(p)||0)+1)),P.map((p)=>{let l=y.get(p)||0;if(l>0)return y.set(p,l-1),!1;return!0})},[P,V]),D=$?"No values":P.length===1?"1 value":`${P.length} values`,E=Q?.name??"values",S=TX.useCallback((y)=>{if(q(y),!y)B(null),M(!1),w("")},[]),f=TX.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),H===y)B(null)},[P,J,H]),j=TX.useCallback((y)=>{if(y<=0)return;let p=[...P];if([p[y-1],p[y]]=[p[y],p[y-1]],J(p),H===y)B(y-1);else if(H===y-1)B(y)},[P,J,H]),v=TX.useCallback((y)=>{if(y>=P.length-1)return;let p=[...P];if([p[y],p[y+1]]=[p[y+1],p[y]],J(p),H===y)B(y+1);else if(H===y+1)B(y)},[P,J,H]),b=TX.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),H===y)B(null)},[P,J,H]),_=TX.useCallback((y,p)=>{J(P.map((l,d)=>d===y?p:l))},[P,J]),x=TX.useCallback(()=>{B(null)},[]),h=TX.useCallback(()=>{if(A===""||A==null)return;J([...P,A]),w(""),M(!0),R((y)=>y+1)},[A,P,J]),u=TX.useCallback(()=>{w(""),M(!1)},[]);if($&&!X)return I4.jsxDEV("div",{className:W,children:I4.jsxDEV("span",{className:"text-sm italic text-muted-foreground",children:"No values"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let m=()=>I4.jsxDEV("div",{className:"flex flex-col gap-1 border border-border rounded-md p-2",children:[I4.jsxDEV(ry,{value:A,onChange:w,onSubmit:h,fieldName:`${E}-add`,projectId:K,storeCode:Y,autoFocus:!0},void 0,!1,void 0,this),I4.jsxDEV("div",{className:"flex justify-end gap-1",children:[I4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:u,title:"Cancel",children:I4.jsxDEV(iZ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),I4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:h,title:"Done",children:I4.jsxDEV(hX,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},N,!0,void 0,this);return I4.jsxDEV("div",{className:W,children:I4.jsxDEV(E7,{open:G,onOpenChange:S,children:[I4.jsxDEV($j0,{asChild:!0,children:I4.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs font-normal",children:D},void 0,!1,void 0,this)},void 0,!1,void 0,this),I4.jsxDEV(T7,{className:a8("max-w-4xl max-h-[85vh] flex flex-col"),children:[I4.jsxDEV(A7,{children:I4.jsxDEV(N7,{children:["Edit ",E]},void 0,!0,void 0,this)},void 0,!1,void 0,this),I4.jsxDEV(_W,{className:"gap-2",children:$?m():I4.jsxDEV(I4.Fragment,{children:[I4.jsxDEV(f80,{values:P,editable:X,editingRowIndex:H,dirtyFlags:C,rowExtras:z,onEditingRowIndexChange:B,onEditRow:_,onUndoRow:b,onMoveUp:j,onMoveDown:v,onRemove:f,renderEditingCell:({value:y,onChange:p})=>I4.jsxDEV(ry,{value:y,onChange:p,onSubmit:x,fieldName:E,projectId:K,storeCode:Y,autoFocus:!0},void 0,!1,void 0,this),renderReadOnlyCell:({value:y})=>I4.jsxDEV(x80,{value:y},void 0,!1,void 0,this)},void 0,!1,void 0,this),X&&(F?m():I4.jsxDEV(c0,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs self-start",onClick:()=>M(!0),children:[I4.jsxDEV(i5,{className:"w-3 h-3 mr-1"},void 0,!1,void 0,this),"Add"]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var D4=G0(X8(),1),mF8=(Z)=>Z.primitiveType==="text",$I6=(Z)=>{if(Z>=3)return"w-[32rem]";if(Z===2)return"w-96";return"w-72"},KW=({value:Z,onChange:J,fieldDef:Q,editable:X,projectId:K,storeCode:Y,className:U,originalValue:z,onValidationChange:W,rowExtras:G})=>{let[q,H]=cJ.useState(null),[B,F]=cJ.useState(!1),[M,A]=cJ.useState(""),[w,N]=cJ.useState(0),R=cJ.useRef(null),P=Array.isArray(Z)?Z:[],V=Array.isArray(z)?z:[],$=P.length===0,C=cJ.useMemo(()=>{let y=new Map;return V.forEach((p)=>y.set(p,(y.get(p)||0)+1)),P.map((p)=>{let l=y.get(p)||0;if(l>0)return y.set(p,l-1),!1;return!0})},[P,V]),D=$?"No values":P.length===1?"1 value":`${P.length} values`,E=$I6(Q.colSpan??Q.colspan??1),S=cJ.useMemo(()=>{if(!W)return null;return P.map((y,p)=>(l,d,Z0)=>W(p,d,Z0))},[P.length,W]);cJ.useEffect(()=>{if(B&&R.current){let y=R.current.querySelector("input, select, button, [tabindex]");if(y)y.focus()}},[B,w]);let f=cJ.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),q===y)H(null)},[P,J,q]),j=cJ.useCallback((y)=>{if(y<=0)return;let p=[...P];if([p[y-1],p[y]]=[p[y],p[y-1]],J(p),q===y)H(y-1);else if(q===y-1)H(y)},[P,J,q]),v=cJ.useCallback((y)=>{if(y>=P.length-1)return;let p=[...P];if([p[y],p[y+1]]=[p[y+1],p[y]],J(p),q===y)H(y+1);else if(q===y+1)H(y)},[P,J,q]),b=cJ.useCallback((y)=>{let p=P.filter((l,d)=>d!==y);if(J(p),q===y)H(null)},[P,J,q]),_=cJ.useCallback((y,p)=>{let l=[...P];l[y]=p,J(l)},[P,J]),x=cJ.useCallback(()=>{if(M===""||M==null)return;J([...P,M]),A(""),F(!0),N((y)=>y+1)},[M,P,J]),h=cJ.useCallback(()=>{A(""),F(!1)},[]),u=cJ.useCallback((y)=>{if(y.key==="Enter")y.preventDefault(),x();else if(y.key==="Escape")y.preventDefault(),h()},[x,h]),m=(y=!0)=>D4.jsxDEV("div",{ref:R,onKeyDown:u,className:"flex items-center gap-1",children:[D4.jsxDEV("div",{className:"flex-1 min-w-0",children:D4.jsxDEV(Zz,{value:M,onChange:A,fieldDef:Q,readOnly:!1,projectId:K,storeCode:Y},void 0,!1,void 0,this)},void 0,!1,void 0,this),D4.jsxDEV("div",{className:"flex items-center gap-1 shrink-0",children:[D4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:x,title:"Confirm add",children:D4.jsxDEV(i5,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y&&D4.jsxDEV(c0,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6",onClick:h,title:"Cancel",children:D4.jsxDEV(iZ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},w,!0,void 0,this);if(mF8(Q))return D4.jsxDEV(gF8,{value:Z,onChange:J,fieldDef:Q,editable:X,projectId:K,storeCode:Y,originalValue:z,rowExtras:G},void 0,!1,void 0,this);if($&&!X)return D4.jsxDEV("div",{className:U,children:D4.jsxDEV("span",{className:"text-sm italic text-muted-foreground",children:"No values"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return D4.jsxDEV("div",{className:U,children:D4.jsxDEV(jK,{onOpenChange:(y)=>{if(!y)F(!1),A(""),H(null)},children:[D4.jsxDEV(kK,{asChild:!0,children:D4.jsxDEV(c0,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs font-normal",children:D},void 0,!1,void 0,this)},void 0,!1,void 0,this),D4.jsxDEV(sX,{className:a8(E,"p-3 z-[60] flex flex-col"),align:"start",style:{maxHeight:"var(--radix-popover-content-available-height)"},children:$?X?m(!1):D4.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"No values"},void 0,!1,void 0,this):D4.jsxDEV("div",{className:"flex flex-col gap-2 min-h-0 flex-1",children:[D4.jsxDEV("div",{className:"overflow-y-auto min-h-0 flex-1",children:D4.jsxDEV(f80,{values:P,editable:X,editingRowIndex:q,dirtyFlags:C,rowExtras:G,onEditingRowIndexChange:H,onEditRow:_,onUndoRow:b,onMoveUp:j,onMoveDown:v,onRemove:f,renderEditingCell:({index:y,value:p,onChange:l})=>D4.jsxDEV(Zz,{value:p,onChange:l,fieldDef:Q,readOnly:!1,projectId:K,storeCode:Y,onValidationChange:S?.[y]},void 0,!1,void 0,this),renderReadOnlyCell:({index:y,value:p})=>mF8(Q)?D4.jsxDEV(x80,{value:p},void 0,!1,void 0,this):D4.jsxDEV(Zz,{value:p,fieldDef:Q,readOnly:!0,projectId:K,storeCode:Y,onValidationChange:S?.[y]},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),X&&(B?m():D4.jsxDEV(c0,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>F(!0),children:[D4.jsxDEV(i5,{className:"w-3 h-3 mr-1"},void 0,!1,void 0,this),"Add"]},void 0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var h80=G0(s0(),1);function y80({fieldDef:Z,projectId:J,entityId:Q,typeCode:X,subtype:K,parentId:Y,storeCode:U,dependencyValues:z}){let W=Z?.allowed?.type==="function",G=W&&Q!=null,q=W&&!G&&X!=null&&Y!=null&&U!=null,H=Z?.allowed?.dependsOn,B=h80.useMemo(()=>{if(!Array.isArray(H)||H.length===0)return null;let N={};for(let R of H)N[R]=z?.[R]??null;return JSON.stringify(N)},[H,z]),F=h80.useMemo(()=>B===null?null:JSON.parse(B),[B]),M=h80.useMemo(()=>{if(F===null)return;let N={};for(let[R,P]of Object.entries(F))if(P!==null&&P!==void 0)N[R]=P;return N},[F]),{data:A,isLoading:w}=k7({queryKey:["allowed-values",J,Z?.name,Q??null,X??null,K??null,Y??null,U??null,F],queryFn:()=>Ci0(J,{entityId:G?Q:void 0,typeCode:q?X:void 0,subtype:q?K:void 0,parentId:q?Y:void 0,storeCode:q?U:void 0,fieldName:Z.name,dependencyValues:M}),enabled:W&&J!=null&&Z!=null&&(G||q)});if(!Z?.allowed)return{values:null,options:null,isLoading:!1};if(Z.allowed.type==="enum")return{values:Z.allowed.values,options:null,isLoading:!1};if(Z.allowed.type==="function")return{values:A?.values??null,options:A?.options??null,isLoading:w};return{values:null,options:null,isLoading:!1}}var mY=G0(X8(),1),sN0=(Z)=>{switch(Z){case 2:return"sm:col-span-2";case 3:return"sm:col-span-2 lg:col-span-3";case 4:return"sm:col-span-2 lg:col-span-4";default:return""}},uF8=({fieldDef:Z,currentValue:J,onFieldChange:Q,isControlled:X,projectId:K,storeCode:Y,entityId:U,typeCode:z,subtype:W,parentId:G,dependencyValues:q,fieldValues:H,isDirty:B,originalValue:F,editingFieldId:M,setEditingFieldId:A,editSnapshot:w,setEditSnapshot:N,editFieldError:R,setEditFieldError:P,readOnly:V=!1})=>{let $=Z.multiplicity==="multi",C=!Z.editable,D=Z.name==="parent",E=Z.jsonSchema?.$id==="caw:visibility-config",S=Z.primitiveType==="text",f=!V&&M!==void 0,j=f&&M===Z.name,v=f&&!C&&!$&&!D&&!E,b=B&&f&&!C&&!D,_=V?!0:!f?C:$?C:!j,[x,h]=Jz.useState(!1),u=Jz.useRef(null);Jz.useEffect(()=>{u.current=R??null},[R]);let m=Z.classDescription||Z.description,y=$?Array.isArray(J)?J:J?[J]:[]:J??"",[p,l]=Jz.useState(y);Jz.useEffect(()=>{let a=$?Array.isArray(J)?J:J?[J]:[]:J??"";l(a)},[J,$]);let d=Jz.useCallback((a)=>{if(l(a),j&&P){let K0=Z.required&&(a===null||a===void 0||a==="")?"Required":null;P(K0)}if(X&&Q)Q(Z.name,a)},[j,P,Z.required,Z.name,X,Q]),{values:Z0,options:e,isLoading:r}=y80({fieldDef:Z,projectId:K,entityId:U,typeCode:z,subtype:W,parentId:G,storeCode:Y,dependencyValues:q}),W0=Z.allowed?.type==="function"&&Z0!==null?{...Z,allowed:{type:"enum",values:Z0,options:e}}:Z,t=Z.allowed?.type==="function"&&r,U0=Jz.useCallback(()=>{if(R)return;if(S){h(!0);return}if(A)A(Z.name);if(N)N({fieldName:Z.name,value:J});if(P)P(null)},[R,S,Z.name,J,A,N,P]),n=Jz.useCallback((a)=>{if(!j)return;let K0=a.relatedTarget;if(K0&&(K0.closest("[data-radix-popper-content-wrapper]")||K0.closest('[role="listbox"]')))return;requestAnimationFrame(()=>{if(u.current)return;if(A)A((B0)=>B0===Z.name?null:B0);if(N)N((B0)=>B0?.fieldName===Z.name?null:B0)})},[j,Z.name,A,N]),o=Jz.useCallback((a)=>{if(a.key!=="Escape"||!j)return;if(a.preventDefault(),w?.fieldName===Z.name&&X&&Q)Q(Z.name,w.value);if(A)A(null);if(N)N(null);if(P)P(null)},[j,w,Z.name,X,Q,A,N,P]);return mY.jsxDEV("div",{className:a8("space-y-1",sN0(Z.colspan)),children:[mY.jsxDEV("div",{className:"flex items-center gap-1",children:[mY.jsxDEV("label",{className:`text-sm font-medium ${B?"text-dirty":"text-foreground"}`,children:[Z.label||Z.name,Z.required&&mY.jsxDEV("span",{className:"text-destructive ml-1",children:"*"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&mY.jsxDEV("button",{type:"button",onClick:U0,className:"text-muted-foreground hover:text-foreground","aria-label":`Edit ${Z.label||Z.name}`,children:mY.jsxDEV(iQ,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),b&&mY.jsxDEV("button",{type:"button",onClick:()=>Q&&Q(Z.name,F),className:"text-muted-foreground hover:text-foreground","aria-label":`Undo ${Z.label||Z.name}`,children:mY.jsxDEV(mX,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&mY.jsxDEV("p",{className:"text-xs text-muted-foreground",children:m},void 0,!1,void 0,this),$?mY.jsxDEV(KW,{value:p,onChange:(a)=>{if(l(a),X&&Q)Q(Z.name,a)},fieldDef:W0,editable:!C&&!V,projectId:K,storeCode:Y,originalValue:F},void 0,!1,void 0,this):E?mY.jsxDEV(Zz,{value:p,onChange:d,fieldDef:W0,editable:!C,projectId:K,storeCode:Y,isLoading:t,fieldValues:H,onFieldChange:Q},void 0,!1,void 0,this):mY.jsxDEV("div",{onBlur:n,onKeyDown:j?o:void 0,children:_&&!j&&!p&&p!==0?mY.jsxDEV("span",{className:"text-sm text-muted-foreground/60 italic",children:"No value"},void 0,!1,void 0,this):mY.jsxDEV(Zz,{value:p,onChange:d,fieldDef:W0,readOnly:_,projectId:K,storeCode:Y,isLoading:t,fieldValues:H,onFieldChange:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),S&&v&&mY.jsxDEV(S3,{open:x,onOpenChange:h,value:J??"",onSave:(a)=>{if(X&&Q)Q(Z.name,a);h(!1)},projectId:K,storeCode:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var Qz=G0(X8(),1),GS=({sectionKey:Z,sectionLabel:J,fields:Q,fieldValues:X,isExpanded:K,onToggle:Y,onFieldChange:U,isControlled:z,projectId:W,storeCode:G,entityPath:q,entityId:H,typeCode:B,subtype:F,parentId:M,dependencyValues:A,dirtyFieldNames:w,originalFieldValues:N,editingFieldId:R,setEditingFieldId:P,editSnapshot:V,setEditSnapshot:$,editFieldError:C,setEditFieldError:D,readOnly:E=!1})=>{let S=`section-${Z}`;return Qz.jsxDEV("div",{className:"border border-border rounded-md",children:[Qz.jsxDEV("button",{id:`section-header-${Z}`,type:"button",className:"flex items-center gap-2 w-full px-3 py-2 text-left text-sm font-medium text-foreground hover:bg-muted/50 rounded-t-md",onClick:Y,"aria-expanded":K,"aria-controls":S,children:[K?Qz.jsxDEV(CZ,{className:"w-4 h-4 flex-shrink-0"},void 0,!1,void 0,this):Qz.jsxDEV(IZ,{className:"w-4 h-4 flex-shrink-0"},void 0,!1,void 0,this),J]},void 0,!0,void 0,this),K&&Qz.jsxDEV("div",{id:S,role:"region","aria-labelledby":`section-header-${Z}`,className:"px-3 pb-3",children:Qz.jsxDEV("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:Q.map((f)=>Qz.jsxDEV(pF8.default.Fragment,{children:[f.name==="parent"&&q!==void 0&&Qz.jsxDEV("div",{className:a8("space-y-1",sN0(3)),children:[Qz.jsxDEV("label",{className:"text-sm font-medium text-foreground",children:"Path"},void 0,!1,void 0,this),Qz.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Full path in the folder hierarchy"},void 0,!1,void 0,this),q?Qz.jsxDEV("span",{className:"text-sm text-foreground block",children:q},void 0,!1,void 0,this):Qz.jsxDEV("span",{className:"text-sm text-muted-foreground/60 italic",children:"No value"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Qz.jsxDEV(uF8,{fieldDef:f,currentValue:X?.[f.name],onFieldChange:U,isControlled:z,projectId:W,storeCode:G,entityId:H,typeCode:B,subtype:F,parentId:M,dependencyValues:A,isDirty:w?.has(f.name)??!1,originalValue:N?.[f.name],editingFieldId:R,setEditingFieldId:P,editSnapshot:V,setEditSnapshot:$,editFieldError:C,setEditFieldError:D,readOnly:E},void 0,!1,void 0,this)]},f.id,!0,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var TI6=new Set(["base","pathable","versioned"]),g80=(Z,{typeCode:J,typeLabel:Q,subtypeLabel:X})=>{let K=[...Z].filter((U)=>!U.hidden).sort((U,z)=>(U.sortOrder??1/0)-(z.sortOrder??1/0)),Y=new Map;for(let U of K){let z=U.sectionKey||"_ungrouped";if(!Y.has(z))Y.set(z,{sectionKey:z,sectionLabel:U.sectionLabel||"Info",sectionOrder:U.sectionOrder??999,fields:[]});Y.get(z).fields.push(U)}if(Q){let U=[];for(let z of TI6)if(Y.has(z))U.push(...Y.get(z).fields),Y.delete(z);if(U.length>0){if(!Y.has("type"))Y.set("type",{sectionKey:"type",sectionLabel:"Info",sectionOrder:3,fields:[]});let z=Y.get("type");z.fields=[...z.fields,...U].sort((W,G)=>(W.sortOrder??1/0)-(G.sortOrder??1/0))}if(Y.has("type"))Y.get("type").sectionLabel=`${Q} info`;if(X&&Y.has("subtype"))Y.get("subtype").sectionLabel=`${X} extension info`}return Array.from(Y.values()).sort((U,z)=>(U.sectionOrder??999)-(z.sectionOrder??999))};var vG=G0(s0(),1);var IJ=G0(X8(),1),cF8=({projectId:Z,entityId:J,draftVersionId:Q,storeCode:X})=>{let[K,Y]=vG.useState(null),{data:U,isLoading:z,error:W}=xN(Z,J),G=vG.useMemo(()=>{let D=[];if(Q)D.push({versionEntityId:Q,label:"Draft",isDraft:!0});if(U)for(let E of U)D.push({versionEntityId:E.versionEntityId,versionNumber:E.versionNumber,publishedAt:E.publishedAt,label:`v${E.versionNumber}`,isDraft:!1});return D},[Q,U]);vG.useEffect(()=>{if(G.length>0&&!K)Y(G[0].versionEntityId)},[G,K]);let{data:q,isLoading:H,error:B}=tF(Z,"v",null),{data:F,isLoading:M,error:A}=jU(Z,K),w=vG.useMemo(()=>{if(!q)return[];return g80(q,{typeCode:"v",typeLabel:"Version",subtypeLabel:null})},[q]),[N,R]=vG.useState({type:!0}),P=vG.useCallback((D)=>{R((E)=>({...E,[D]:!E[D]}))},[]),V=vG.useCallback((D)=>{Y(D)},[]);if(!z&&G.length===0)return null;if(z)return IJ.jsxDEV("div",{className:"mt-4 border border-border rounded-md p-4",children:IJ.jsxDEV("div",{className:"flex items-center justify-center",children:[IJ.jsxDEV(O9,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this),IJ.jsxDEV("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading versions..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(W)return IJ.jsxDEV("div",{className:"mt-4 border border-border rounded-md p-4",children:[IJ.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error loading versions"},void 0,!1,void 0,this),IJ.jsxDEV("p",{className:"text-sm text-destructive mt-1",children:W.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let $=H||M,C=B||A;return IJ.jsxDEV("div",{className:"mt-4 space-y-4",children:[IJ.jsxDEV("div",{className:"flex items-center gap-2",children:[IJ.jsxDEV("span",{className:"text-sm font-medium text-foreground",children:"Select version:"},void 0,!1,void 0,this),IJ.jsxDEV(g7,{value:K||"",onValueChange:V,children:[IJ.jsxDEV(_7,{className:"text-sm h-auto py-1",children:IJ.jsxDEV(m7,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),IJ.jsxDEV(v7,{children:G.map((D)=>IJ.jsxDEV(l9,{value:D.versionEntityId,children:D.isDraft?`Draft (${D.versionEntityId})`:`${D.label} (${D.versionEntityId}) Published`},D.versionEntityId,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$&&IJ.jsxDEV("div",{className:"flex items-center justify-center p-4",children:[IJ.jsxDEV(O9,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this),IJ.jsxDEV("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading version fields..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!$&&C&&IJ.jsxDEV("div",{className:"p-4 border border-border rounded-md",children:[IJ.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error loading version fields"},void 0,!1,void 0,this),IJ.jsxDEV("p",{className:"text-sm text-destructive mt-1",children:C.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!$&&!C&&w.map((D)=>IJ.jsxDEV(GS,{sectionKey:D.sectionKey,sectionLabel:D.sectionLabel,fields:D.fields,fieldValues:F,isExpanded:N[D.sectionKey]??!1,onToggle:()=>P(D.sectionKey),projectId:Z,storeCode:X,entityId:K,typeCode:"v"},D.sectionKey,!1,void 0,this))]},void 0,!0,void 0,this)};var NH=G0(X8(),1),bG=({projectId:Z,entityId:J,entityType:Q,entitySubtype:X,entityPath:K,onFieldChange:Y,fieldValues:U,dirtyFieldNames:z,originalFieldValues:W,storeCode:G,readOnly:q=!1,excludeFields:H})=>{let[B,F]=Xz.useState(null),[M,A]=Xz.useState(null),[w,N]=Xz.useState(null),R=U!==void 0,{data:P,isLoading:V,error:$}=jU(Z,J),C=R?U:P,{data:D,isLoading:E,error:S}=tF(Z,Q,X),f=Xz.useMemo(()=>{let y=D||[];if(!H)return y;return y.filter((p)=>!H.has(p.name))},[D,H]),j=Xz.useMemo(()=>{let y={};for(let p of f){let l=p.allowed?.dependsOn;if(l)for(let d of l){if(!y[d])y[d]=[];y[d].push(p.name)}}return y},[f]),v=Xz.useCallback((y,p)=>{if(Y)Y(y,p);let l=j[y];if(l){for(let d of l)if(Y)Y(d,null)}},[Y,j]),b=Xz.useMemo(()=>{let y=f.find((d)=>d.sectionKey==="type")?.sectionLabel??null,p=f.find((d)=>d.sectionKey==="subtype")?.sectionLabel??null,l=g80(f,{typeCode:Q,typeLabel:y,subtypeLabel:p});if(!R&&C){let d=new Set(f.map((e)=>e.name)),Z0=Object.keys(C).filter((e)=>!d.has(e)&&(!H||!H.has(e)));if(Z0.length>0)l.push({sectionKey:"entity",sectionLabel:"Entity-scoped",sectionOrder:5,fields:Z0.map((e)=>({id:`entity:${e}`,name:e,label:e,primitiveType:"string",colspan:1,rows:1,multiplicity:"single",editable:!1,isVirtual:!1}))})}return l},[f,R,C,Q,H]),[_,x]=Xz.useState({type:!0,subtype:!0}),h=Xz.useCallback((y)=>{x((p)=>({...p,[y]:!p[y]}))},[]),u=V||E,m=$||S;if(u)return NH.jsxDEV("div",{className:"flex items-center justify-center p-8",children:[NH.jsxDEV(O9,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this),NH.jsxDEV("span",{className:"ml-2 text-muted-foreground",children:"Loading info..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(m)return NH.jsxDEV("div",{className:"p-4 text-destructive",children:[NH.jsxDEV("p",{className:"font-medium",children:"Error loading info"},void 0,!1,void 0,this),NH.jsxDEV("p",{className:"text-sm mt-1",children:m.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(b.length===0)return NH.jsxDEV("div",{className:"p-4 text-muted-foreground text-sm",children:"No info available for this entity type."},void 0,!1,void 0,this);return NH.jsxDEV("div",{className:"space-y-4",children:[b.map((y)=>NH.jsxDEV(GS,{sectionKey:y.sectionKey,sectionLabel:y.sectionLabel,fields:y.fields,fieldValues:C,isExpanded:_[y.sectionKey]??!1,onToggle:()=>h(y.sectionKey),onFieldChange:v,isControlled:R,projectId:Z,storeCode:G,entityPath:y.sectionKey==="type"?K:void 0,entityId:J,typeCode:Q,subtype:X,dependencyValues:C,dirtyFieldNames:z,originalFieldValues:W,editingFieldId:B,setEditingFieldId:F,editSnapshot:M,setEditSnapshot:A,editFieldError:w,setEditFieldError:N,readOnly:q},y.sectionKey,!1,void 0,this)),(Q==="d"||Q==="t")&&NH.jsxDEV(cF8,{projectId:Z,entityId:J,draftVersionId:C?.draft_version??null,storeCode:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var II6=G0(s0(),1);var _3=async(Z,J="Copied")=>{try{await navigator.clipboard.writeText(Z),N6.success(J)}catch{N6.error("Failed to copy")}},lF8=(Z)=>{if(!Z)return"";let J=Z.indexOf("/");return J===-1?Z:Z.slice(J+1)},VI6=(Z)=>Z[0].toUpperCase()+Z.slice(1),CI6=({items:Z,projectId:J,entityType:Q,viewType:X})=>{if(!Z||Z.length===0)return"";let K=Z[0],Y=BZ(K.id),U=Y&&Y!=="A"?`/store/${Y}`:"",z=`${window.location.origin}/project/${J}${U}`;if(Q==="document")return`${z}/documents?id=${K.id}`;if(Q==="template")return`${z}/templates?id=${K.id}`;if(Q==="story")return`${z}/story/${K.id}`;if(Q==="job")return`${z}/jobs/${K.id}`;if(Q==="folder")return`${z}/${X??"documents"}?id=${K.id}`;return""},m80=({items:Z,projectId:J,entityType:Q,jobFields:X,getContent:K,getTranscript:Y,getChildrenIds:U,viewType:z})=>{if(!Z||Z.length===0)return[];let W=Z.length>1,G=[],q=VI6(Q);if(Q!=="story"&&Q!=="folder"&&Q!=="job")G.push({key:"content",label:W?`Copy ${q} Contents`:`Copy ${q} Content`,icon:R5,successMessage:W?`${q} Contents copied`:`${q} Content copied`,getValue:async()=>{if(K)return await K(Z);return Z.map((H)=>H.content??"").filter(Boolean).join(`
|
|
3084
3084
|
|
|
3085
3085
|
`)}});if(Q==="job"&&Y)G.push({key:"transcript",label:`Copy ${q} Transcript`,icon:pk,successMessage:`${q} Transcript copied`,getValue:()=>Y()});if(Q==="folder"&&U)G.push({key:"children-ids",label:`Copy ${q} Children IDs`,icon:Hq,successMessage:`${q} Children IDs copied`,getValue:async()=>await U()});if(G.push({key:"id",label:W?`Copy ${q} IDs`:`Copy ${q} ID`,icon:Hq,successMessage:W?`${q} IDs copied`:`${q} ID copied`,getValue:()=>Z.map((H)=>H.id).join(",")}),G.push({key:"name",label:W?`Copy ${q} Names`:`Copy ${q} Name`,icon:rw,successMessage:W?`${q} Names copied`:`${q} Name copied`,getValue:()=>Z.map((H)=>H.name??"").join(`
|
|
3086
3086
|
`)}),G.push({key:"md-link-id",label:W?`Copy ${q} MD Links (ID based)`:`Copy ${q} MD Link (ID based)`,icon:oM,successMessage:`${q} MD Link copied`,getValue:()=>{if(W)return Z.map((H)=>`- [${H.name??H.id}](${H.id})`).join(`
|