import{ae as Qe,aB as F,ac as Te,a6 as g,T as w,Q as e,f as n,a7 as Ue,o as a,N as H,aC as h,w as O,ax as o,O as _,ap as v,p as Ve,G as X,v as ze,g as He,aI as Xe,av as c,aD as A,ar as Y,as as _e,U as Ye,ao as Ze,a8 as ea}from"./index-DiDFsNpN.js";var aa=_('<p class="placeholder svelte-1lpfi31">Loading preview…</p>'),ta=_('<p class="error svelte-1lpfi31" role="alert"> </p>'),la=_("<option> </option>"),sa=_('<select class="svelte-1lpfi31"></select>'),ra=_('<li class="orphan svelte-1lpfi31"><div class="orphan-head svelte-1lpfi31"><code class="orphan-name svelte-1lpfi31"> </code> <span class="orphan-value svelte-1lpfi31"> </span></div> <div class="orphan-actions svelte-1lpfi31" role="radiogroup"><label class="svelte-1lpfi31"><input type="radio" value="drop"/> Drop</label> <label class="svelte-1lpfi31"><input type="radio" value="keep"/> Keep (unrendered)</label> <label class="svelte-1lpfi31"><input type="radio" value="rename"/> Rename to</label> <!></div></li>'),ia=_(`<section class="resolutions svelte-1lpfi31" aria-label="Orphan field resolutions"><h3 class="svelte-1lpfi31">Orphan fields</h3> <p class="hint svelte-1lpfi31">These fields exist in this item's JSON but the current template doesn't render them.
            Pick what to do with each.</p> <ul class="orphans svelte-1lpfi31"></ul></section>`),na=_('<p class="error svelte-1lpfi31" role="alert"> </p>'),oa=_('<div class="diff svelte-1lpfi31"><section class="pane svelte-1lpfi31" aria-label="Previous version (left)"><header class="pane-head svelte-1lpfi31"><!></header> <pre class="source svelte-1lpfi31"> </pre></section> <section class="pane svelte-1lpfi31" aria-label="Current template (right)"><header class="pane-head svelte-1lpfi31"> </header> <pre class="source svelte-1lpfi31"> </pre></section></div> <!> <!> <div class="commit-bar svelte-1lpfi31"><button type="button" class="primary svelte-1lpfi31"> </button></div>',1),va=_('<header class="detail-head svelte-1lpfi31"><button type="button" class="back svelte-1lpfi31">← Back</button> <h2 class="svelte-1lpfi31"> </h2></header> <!>',1),pa=_('<p class="error svelte-1lpfi31" role="alert"> </p>'),ca=_('<p class="placeholder svelte-1lpfi31">Loading…</p>'),fa=_(`<div class="empty svelte-1lpfi31"><h3 class="svelte-1lpfi31">All caught up</h3> <p>Every content item's fields match its bound template. Migrations show up here when a
          destructive template edit (or a manual hand-edit) leaves an item with orphan fields.</p></div>`),da=_('<li class="item"><button class="item-row svelte-1lpfi31" type="button"><span class="item-path svelte-1lpfi31"><code> </code></span> <span class="item-summary svelte-1lpfi31"><!> <!> <!></span> <span class="open-icon svelte-1lpfi31">→</span></button></li>'),ua=_('<section class="group svelte-1lpfi31"><h3 class="group-title svelte-1lpfi31"><code class="svelte-1lpfi31"> </code> <span class="count svelte-1lpfi31"> </span></h3> <ul class="items svelte-1lpfi31"></ul></section>'),ma=_('<header class="list-head svelte-1lpfi31"><h2>Migrations</h2> <button type="button" class="svelte-1lpfi31"> </button></header> <!>',1),_a=_('<div class="migrations svelte-1lpfi31"><!> <!></div>');function ga(Le,Re){Qe(Re,!0);let j=F(null),d=F(null),Z=F(!1),C=F(null),r=F(Te({})),he=F(Te({})),D=F(!1),I=F(null);g.ensureLoaded();async function Ce(s){v(j,s,!0),v(r,{},!0),v(he,{},!0),v(d,null),v(C,null),v(Z,!0);try{v(d,await ea(s),!0);const f={};for(const l of e(d).orphans){const u=Ee(l.name,e(d).currentTemplateFields);f[l.name]=u?{rename:u}:"keep"}v(r,f,!0)}catch(f){v(C,f instanceof Error?f.message:String(f),!0)}finally{v(Z,!1)}}function ge(){v(j,null),v(d,null),v(C,null)}function Ee(s,f){const l=s.toLowerCase();for(const u of f)if(u.toLowerCase().startsWith(l)||u.toLowerCase().endsWith(l))return u;return null}async function Se(){if(!(e(j)===null||e(d)===null)){v(D,!0),v(I,null);try{const s={drop:Object.entries(e(r)).filter(([,l])=>l==="drop").map(([l])=>l),keep:Object.entries(e(r)).filter(([,l])=>l==="keep").map(([l])=>l),rename:Object.fromEntries(Object.entries(e(r)).filter(([,l])=>typeof l=="object"&&l!==null&&"rename"in l).map(([l,u])=>[l,u.rename])),fill:{...e(he)}},f=await He(e(j),s);g.refresh().catch(()=>{}),ge()}catch(s){v(I,s instanceof Error?s.message:String(s),!0)}finally{v(D,!1)}}}function Pe(s){return typeof s=="string"?s:JSON.stringify(s)}const Be=Xe(()=>g.list===null?[]:Object.entries(g.list.byTemplate).map(([s,f])=>({template:s,items:[...f].sort((l,u)=>l.path.localeCompare(u.path))})));var be=_a(),xe=a(be);{var qe=s=>{var f=va(),l=H(f),u=a(l),ee=o(u,2),ae=a(ee),te=o(l,2);{var le=i=>{var m=aa();n(i,m)},se=i=>{var m=ta(),k=a(m);h(()=>c(k,e(C))),n(i,m)},re=i=>{var m=oa(),k=H(m),L=a(k),M=a(L),J=a(M);{var W=p=>{var x=A();h(()=>c(x,`Before — ${e(d).left.template??""}`)),n(p,x)},$=p=>{var x=A("Before — no snapshot available");n(p,x)};w(J,p=>{e(d).left?p(W):p($,-1)})}var ie=o(M,2),ne=a(ie),oe=o(L,2),G=a(oe),E=a(G),b=o(G,2),K=a(b),S=o(k,2);{var Q=p=>{var x=ia(),P=o(a(x),4);X(P,21,()=>e(d).orphans,B=>B.name,(B,t)=>{var y=ra(),V=a(y),ye=a(V),Ie=a(ye),Je=o(ye,2),We=a(Je),we=o(V,2),ke=a(we),fe=a(ke),Fe=o(ke,2),de=a(Fe),Oe=o(Fe,2),ue=a(Oe),$e=o(Oe,2);{var Ge=q=>{var T=sa();X(T,20,()=>e(d).currentTemplateFields,N=>N,(N,me)=>{var z=la(),Ke=a(z),Me={};h(()=>{c(Ke,me),Me!==(Me=me)&&(z.value=(z.__value=me)??"")}),n(N,z)});var je;Ye(T),h(()=>{je!==(je=e(r)[e(t).name].rename)&&(T.value=(T.__value=e(r)[e(t).name].rename)??"",Ze(T,e(r)[e(t).name].rename))}),O("change",T,N=>v(r,{...e(r),[e(t).name]:{rename:N.currentTarget.value}},!0)),n(q,T)};w($e,q=>{typeof e(r)[e(t).name]=="object"&&e(r)[e(t).name]!==null&&"rename"in e(r)[e(t).name]&&q(Ge)})}h(q=>{c(Ie,e(t).name),c(We,q),Y(we,"aria-label",`Resolution for ${e(t).name}`),Y(fe,"name",`d-${e(t).name}`),_e(fe,e(r)[e(t).name]==="drop"),Y(de,"name",`d-${e(t).name}`),_e(de,e(r)[e(t).name]==="keep"),Y(ue,"name",`d-${e(t).name}`),_e(ue,typeof e(r)[e(t).name]=="object"&&e(r)[e(t).name]!==null&&"rename"in e(r)[e(t).name])},[()=>Pe(e(t).value)]),O("change",fe,()=>v(r,{...e(r),[e(t).name]:"drop"},!0)),O("change",de,()=>v(r,{...e(r),[e(t).name]:"keep"},!0)),O("change",ue,()=>v(r,{...e(r),[e(t).name]:{rename:e(d).currentTemplateFields[0]??""}},!0)),n(B,y)}),n(p,x)};w(S,p=>{e(d).orphans.length>0&&p(Q)})}var U=o(S,2);{var ve=p=>{var x=na(),P=a(x);h(()=>c(P,e(I))),n(p,x)};w(U,p=>{e(I)&&p(ve)})}var pe=o(U,2),R=a(pe),ce=a(R);h(()=>{var p;c(ne,((p=e(d).left)==null?void 0:p.html)??"(no snapshot covers this item)"),c(E,`After — ${e(d).right.template??""}`),c(K,e(d).right.html),R.disabled=e(D)||e(d).orphans.length===0,c(ce,e(D)?"Migrating…":"Migrate item")}),O("click",R,Se),n(i,m)};w(te,i=>{e(Z)?i(le):e(C)?i(se,1):e(d)&&i(re,2)})}h(()=>c(ae,e(j))),O("click",u,ge),n(s,f)},Ne=s=>{var f=ma(),l=H(f),u=o(a(l),2),ee=a(u),ae=o(l,2);{var te=i=>{var m=pa(),k=a(m);h(()=>c(k,g.error)),n(i,m)},le=i=>{var m=ca();n(i,m)},se=i=>{var m=fa();n(i,m)},re=i=>{var m=Ve(),k=H(m);X(k,17,()=>e(Be),L=>L.template,(L,M)=>{var J=ua(),W=a(J),$=a(W),ie=a($),ne=o($,2),oe=a(ne),G=o(W,2);X(G,21,()=>e(M).items,E=>E.path,(E,b)=>{var K=da(),S=a(K),Q=a(S),U=a(Q),ve=a(U),pe=o(Q,2),R=a(pe);{var ce=t=>{var y=A();h(V=>c(y,`${e(b).orphanFields.length??""} orphan field${e(b).orphanFields.length===1?"":"s"}:
                      ${V??""}`),[()=>e(b).orphanFields.join(", ")]),n(t,y)};w(R,t=>{e(b).orphanFields.length>0&&t(ce)})}var p=o(R,2);{var x=t=>{var y=A();h(()=>c(y,`· ${e(b).missingRequiredFields.length??""} missing required`)),n(t,y)};w(p,t=>{e(b).missingRequiredFields.length>0&&t(x)})}var P=o(p,2);{var B=t=>{var y=A();h(()=>c(y,`· best-fit: ${e(b).bestFitSnapshot??""}`)),n(t,y)};w(P,t=>{e(b).bestFitSnapshot&&t(B)})}h(()=>c(ve,e(b).path)),O("click",S,()=>Ce(e(b).path)),n(E,K)}),h(()=>{c(ie,e(M).template),c(oe,`${e(M).items.length??""} item${e(M).items.length===1?"":"s"}`)}),n(L,J)}),n(i,m)};w(ae,i=>{g.error?i(te):g.loading&&g.list===null?i(le,1):g.count===0?i(se,2):i(re,-1)})}h(()=>{u.disabled=g.loading,c(ee,g.loading?"Refreshing…":"Refresh")}),O("click",u,()=>g.refresh()),n(s,f)};w(xe,s=>{e(j)!==null?s(qe):s(Ne,-1)})}var Ae=o(xe,2);{var De=s=>{};w(Ae,s=>{!e(j)&&g.list===null&&s(De)})}n(Le,be),Ue()}ze(["click","change"]);export{ga as default};
