decocms
Version:
Deco CMS โ Self-hostable MCP Gateway for managing AI connections and tools
2 lines โข 71 kB
JavaScript
import{ig as ti,bu as ni,c as wn,b as Rn,r as b,m as le,j as r,cd as si,br as Cs,ih as Mo,B as It,Y as on,ax as ri,_ as oi,bt as ai,Z as ii,q as li,ii as bs,hN as ci,ij as ui,ik as di,h as fi,bv as wt,il as Qr,im as xs,io as mi,ip as pt,iq as Xr,ir as pi,fW as hi,is as gi,it as Yr,iu as vi,t as H,fA as Zr,iv as yi,iw as Bt,ix as Si,iy as bi,iz as xi,fo as eo,iA as _s,iB as _i,iC as ki,iD as wi,fl as Ri,fX as ji,iE as Ei,iF as Vi,fz as Ti,K as Ai,iG as to,eT as Ni,fP as Hn,fU as no,iH as so,iI as Ci,iJ as Pi,iK as Bi,iL as Ki,iM as Di,iN as Mi,iO as ro,iP as Fi,iQ as Ii,fn as oo,iR as Li,iS as Oi,fR as ao,iT as zi,fj as $i}from"./index-DoEtSiIe.js";import{u as Wi}from"./chat-context-vJ6R-Clt.js";import{a as Zn,M as io}from"./save-status-CQe-z40L.js";import{p as kn,f as Hi,n as qi}from"./parse-sections-Bbp8QY_-.js";import{a as Gi}from"./repository-binding-BAQCDq-W.js";import{t as Ui}from"./ChevronDown-Dm2xO7jf.js";import{d as Fo,b as Ji}from"./UserCheck01-CA8kXGn8.js";import{n as Qi}from"./ChevronUp-BKdcyIOm.js";import{b as Yn,e as Xi,Q as lo,L as co}from"./agent-icon-DoabtHNW.js";import{S as an}from"./scroll-area-KLotig-P.js";import{c as Rt,T as jt,a as Et}from"./tooltip-DhlWzeQv.js";import{g as Yi,h as Zi,i as el,E as tl,j as nl,V as sl,k as rl,l as ol,G as al,s as Jn,v as Qn,u as il,a as qn,p as Io,m as ll,n as cl,c as uo,o as ul,q as dl,A as Gn,P as fo,w as mo,x as po,y as ks,z as fl,B as ml,D as ho,F as pl,J as go,K as vo,L as yo,M as hl,Q as So,T as ln,U as gl,W as vl}from"./held-block-view-CRIGJWyy.js";import{j as yl,u as Sl,i as bl,v as xl,aB as _l,U as kl,k as bo,aU as xo,a9 as Kt,aa as Dt,aq as wl,aV as Rl,aW as jl,aO as _o,at as El,aA as Vl}from"./site-editor-toast-B-FDGvtN.js";import{u as Tl,ao as ko,c as wo,k as Al,A as Nl,ad as Cl,ae as Pl,aj as Bl}from"./blocks-tab-states-CTy1iAF5.js";import{u as Kl}from"./use-delete-block-nP_FtjiY.js";import{b as Dl,u as Ml,k as Un,e as xn}from"./use-never-published-C4cAqdmZ.js";import{b as Es,f as Lo}from"./UserSquare-dgrNjiXb.js";import{b as Fl}from"./MessageCircle01-zc37Krdu.js";import{i as Ro}from"./Tool01-D90Wr5xR.js";import{s as jo}from"./Eye-DwRCQHLk.js";import{s as Il}from"./Plus-BoPsX_T8.js";import{s as Ll}from"./Trash01-Ctp9Olbr.js";import{i as Vs}from"./Zap-CxPsn4FS.js";import{u as Ol,a as Eo,n as zl,P as $l,o as Wl,C as Hl,D as ql,c as Gl}from"./task-key-CajjdR3t.js";import{u as Ul,s as Jl,a as Xn,S as Ql,v as Xl}from"./sortable.esm-B0hCRAsX.js";import{s as Yl,g as Zl,u as ec,A as tc}from"./use-section-preview-base-BcIQh9cw.js";import{m as nc,P as sc}from"./mustache-DKc6J7pv.js";import{aR as Vo,aS as rc,X as oc,aT as ac,aU as ic,k as lc}from"./category-tree-CW0acTf_.js";import{u as cc,a as uc,P as To,w as dc,b as fc}from"./seo-editor-D1i_wsxL.js";import{v as mc,k as ws,x as Ao,j as pc,y as hc}from"./named-rule-step-BAentWbs.js";import{u as gc}from"./use-apply-named-rule-CaZ5oLnq.js";import{o as Jt,f as Ts,y as As,q as Ft,h as cn,u as vc,n as Ut,r as Rs,m as Mt,k as _n,b as yc,s as No,z as Sc,A as bc,B as xc}from"./section-array-field-yz7QHNSD.js";import{b as Co,a as _c}from"./variant-matcher-override-BBj0ymp1.js";import"./use-panel-navigate-DHff9CS9.js";import"./thread-route-D-UE3Db_.js";import"./use-project-scope-AMUoXt2c.js";import"./use-view-draft-kind-hbAZo1QG.js";import"./use-blog-view-DJnS2ipo.js";import"./use-organization-settings-CgKOO7Ms.js";import"./schema-CG6ylG0z.js";import"./task-board-BRF3ZwKz.js";import"./thread-intent-R2KI8ie_.js";import"./use-mcp-client-86j-Nolb.js";import"./auth-IBAsOARn.js";import"./delay-CnY5UFtP.js";import"./backoff-CrEUbyZT.js";import"./watch-sse-pool-C0me6Edt.js";import"./session-runtime-CZKHty5X.js";import"./use-entitlements-4v7LU4jM.js";import"./use-ai-providers-BwkzkRi2.js";import"./use-current-view-C2fbVQ-O.js";import"./use-in-settings-LMUeu63D.js";import"./use-decopilot-events-DwNDOIa1.js";import"./use-org-fs-C62_MbqW.js";import"./useInfiniteQuery-9vIAXgqG.js";import"./infiniteQueryObserver-BRGiYBJv.js";import"./Image01-BRABRo3v.js";import"./Upload01-DgxprpI7.js";import"./label-G4Rj_cXa.js";import"./SwitchHorizontal01-CHtrDs50.js";import"./popover-mrQ4T9ru.js";import"./switch-C5tCt-1T.js";import"./toggle-group-CtXgLS7e.js";import"./active-indicator-CCMhAsc_.js";import"./match-site-slug-config-B47_xZCi.js";import"./use-file-configs-J6lDtEfO.js";import"./asset-utils-D7ZsoUjl.js";import"./AlertCircle-GoAGGV0G.js";import"./hosted-reconcile-CTronLZo.js";import"./SearchMd-BGRe_18c.js";import"./textarea-CP9TQ5HN.js";import"./use-copy-CjEnyhFT.js";import"./ChevronSelectorVertical-Cvgyclsz.js";import"./command-D5O7M-Cf.js";import"./index-DRuy-mDa.js";import"./Play-C_9Fb_Ik.js";import"./monaco-editor-BwfJ8i7M.js";import"./editor-UaRoONxx.js";import"./ArrowUp-s5a8DQxj.js";import"./ArrowLeft-DuGHc_Gh.js";import"./ArrowRight-CMJyKdyB.js";import"./BookOpen01-DZs1-yi9.js";import"./Globe04-5yHQa01g.js";import"./CheckCircle-vIQcB0iT.js";import"./LinkBroken01-CyjdgWmP.js";import"./CreditCard01-BUXydXso.js";import"./File02-Y4Nh84qP.js";import"./Fingerprint04-DlIWxzRc.js";import"./Key01-DfLmV_su.js";import"./LayoutLeft-owMYqid0.js";import"./Minus-CFYZtYi9.js";import"./Monitor01-DUhT2Mcw.js";import"./Sun-uwKn4QPm.js";import"./ShoppingBag01-CoN4FBW5.js";import"./Users01-BasqfwpC.js";import"./XClose-BUxhnZ3x.js";import"./index-BdQq_4o_.js";import"./index-BFFHlwFA.js";import"./utils-CzRFs-0R.js";import"./calendar-BRx4DiEx.js";import"./usage-stats-CLeyhHyT.js";import"./utils-CVEq3hMx.js";import"./markdown-DeZATUv_.js";import"./use-mobile-BjsAkqwr.js";import"./gateway-client-C5MrdR_p.js";import"./form-DwGozYbG.js";import"./select-OlcoUSVg.js";import"./editor-classes-DMpdrv32.js";import"./combobox-B9eEiOM0.js";import"./content-changes-DXqxs3Wb.js";import"./sandbox-url-D3mC8qhT.js";import"./use-sandbox-events-A8aB0HnP.js";import"./use-blocks-v8-project-BLAijVCk.js";import"./use-voice-input-DJjQBO4e.js";import"./drawer-DO0sMAej.js";import"./index-BVDmO57n.js";import"./checkbox-CkODjqKt.js";import"./ai-providers-logos-DD3qZ33J.js";import"./openai-compatible-presets-BKGfVqEx.js";import"./sandbox-git-api-DiUyKbJU.js";import"./empty-state-C4MgLcBg.js";import"./search-input-wk0beNbE.js";import"./tabs-Bh3jtZIY.js";import"./use-debounced-value-DqHSmPMR.js";import"./sandbox-start-errors-BK_aDCyt.js";import"./pair-C9Fumckp.js";import"./collapsible-BdVp5Lcb.js";import"./use-task-board-items-BVQx7Wft.js";import"./config-BOn4tvAD.js";import"./task-route-DltlnXMA.js";import"./project-index-BcbyhrUz.js";import"./shell-layout-596_q4a1.js";import"./use-deployment-admin-Bh76rlF7.js";import"./admin-fetch-BhTJlAsX.js";import"./use-org-notice-BzvGZbQ2.js";import"./integration-icon-DvT6X8cI.js";import"./project-icon-BxqBM24K.js";import"./use-navigate-to-agent-C-BC28kE.js";import"./new-project-dialog-CT39WKMt.js";import"./repository-picker-BBkgoOlP.js";import"./github-icon-YYYF_UPl.js";import"./collection-search-DL8nJQx4.js";import"./new-project-store-DYc4RZIM.js";import"./legacy-admin-welcome-dialog-BYL3pyxT.js";import"./required-auth-layout-DPL2sBE1.js";import"./use-org-sso-CypQjzG8.js";import"./content-blocks-o63cs2vh.js";import"./mcp-app-renderer-pvE5c1WF.js";import"./types-rurFGFZy.js";import"./omit-server-managed-metadata-L5IhjRZB.js";import"./sheet-De8qzGNI.js";import"./use-connection-BO-ZUzee.js";import"./use-mcp-prompts-CPXLXWTp.js";import"./use-thread-outputs-BnMyEJ2l.js";import"./file-type-icon-R4tsODq6.js";import"./slider-c-3WdQpH.js";import"./index-D4CqkEu4.js";import"./tooltipContext-BkLzQGib.js";import"./CategoricalChart-iNQ2kTf5.js";import"./index-C_NkXLoh.js";import"./use-move-blocks-CCDsEu9Z.js";const kc={escape:Yi};function wc(g,e){for(const p of Yl(g,e)){const S=typeof p.title=="string"?p.title:void 0;if(S?.includes("{{"))return S}}function Rc(g,e){if(!e)return;const p=ti(g,ni(e));if(p)try{const S=wc(p.resolveType,e);return S&&nc.render(S,p.data,{},kc).trim()||void 0}catch{return}}function jc(g){const e=wn.c(13),{icon:p,label:S,className:x}=g;let V;e[0]!==x?(V=le("size-3.5",x),e[0]=x,e[1]=V):V=e[1];let C;e[2]!==p||e[3]!==V?(C=r.jsx(p,{className:V}),e[2]=p,e[3]=V,e[4]=C):C=e[4];let _;e[5]!==S||e[6]!==C?(_=r.jsx(jt,{asChild:!0,children:r.jsx("span",{role:"img","aria-label":S,className:"shrink-0 cursor-help",children:C})}),e[5]=S,e[6]=C,e[7]=_):_=e[7];let P;e[8]!==S?(P=r.jsx(Et,{className:"max-w-56",children:S}),e[8]=S,e[9]=P):P=e[9];let k;return e[10]!==_||e[11]!==P?(k=r.jsxs(Rt,{children:[_,P]}),e[10]=_,e[11]=P,e[12]=k):k=e[12],k}const Ec="text-global-section-fg focus:bg-global-section/12 focus:text-global-section-fg dark:text-global-section-fg-dark dark:focus:bg-global-section/15 dark:focus:text-global-section-fg-dark [&_svg]:!text-global-section";function Po(g){return Array.from({length:g},(e,p)=>({id:crypto.randomUUID(),index:p}))}function Oo(g){return g.map((e,p)=>({...e,index:p}))}function Vc(g,e){if(e===g.length)return g;if(e<g.length)return Oo(g.slice(0,e));const p=Array.from({length:e-g.length},(S,x)=>({id:crypto.randomUUID(),index:g.length+x}));return[...g,...p]}function zo(g){const e=wn.c(44),{section:p,raw:S,meta:x,decofile:V}=g,C=Rn(),_=Zn(),P=p.isSavedBlock===!0,k=p.isMultivariate===!0;let Y;e[0]!==x||e[1]!==S?(Y=S&&x?Zl(S,x):void 0,e[0]=x,e[1]=S,e[2]=Y):Y=e[2];const ge=Y;let Ue;e[3]!==x||e[4]!==k||e[5]!==S||e[6]!==P?(Ue=S&&x&&!P&&!k?Rc(S,x):void 0,e[3]=x,e[4]=k,e[5]=S,e[6]=P,e[7]=Ue):Ue=e[7];const Le=Ue;let Ce;e[8]!==V||e[9]!==x||e[10]!==S||e[11]!==p?(Ce=rl(S,p,V,x),e[8]=V,e[9]=x,e[10]=S,e[11]=p,e[12]=Ce):Ce=e[12];const Je=Ce;let w;e[13]!==k||e[14]!==S?.__resolveType?(w=!k&&Cs(S?.__resolveType??""),e[13]=k,e[14]=S?.__resolveType,e[15]=w):w=e[15];const c=w,xe=P?Yn:k?Fo:Lo;let G;e[16]!==k||e[17]!==P?(G=P?{color:ai}:k?{color:"oklch(0.65 0.15 160)"}:void 0,e[16]=k,e[17]=P,e[18]=G):G=e[18];const _e=G;let F;e[19]!==xe||e[20]!==_?(F=_?r.jsxs("span",{className:"relative size-4 shrink-0",children:[r.jsx(xe,{className:"absolute inset-0 size-4 text-muted-foreground transition-opacity group-hover:opacity-0 group-has-[:focus-visible]:opacity-0"}),r.jsx(al,{"aria-hidden":!0,className:"absolute inset-0 size-4 opacity-0 transition-opacity group-hover:opacity-100 group-has-[:focus-visible]:opacity-100"})]}):r.jsx(Fl,{className:"h-4 w-4 shrink-0 text-muted-foreground/40"}),e[19]=xe,e[20]=_,e[21]=F):F=e[21];let ke;e[22]!==ge?(ke=ge&&r.jsx("img",{src:ge,alt:"",referrerPolicy:"no-referrer",className:"h-12 max-w-[100px] shrink-0 rounded-[var(--studio-control-radius,var(--radius))] object-cover"}),e[22]=ge,e[23]=ke):ke=e[23];let d;e[24]!==_||e[25]!==_e?(d=!_&&r.jsx(Es,{className:"h-4 w-4 shrink-0",style:_e}),e[24]=_,e[25]=_e,e[26]=d):d=e[26];const Oe=_?"shrink":"flex-1",u=p.isHidden&&"line-through opacity-50";let Ee;e[27]!==u||e[28]!==Oe?(Ee=le("min-w-0 truncate text-sm font-medium",Oe,u),e[27]=u,e[28]=Oe,e[29]=Ee):Ee=e[29];const Z=Le??p.label;let ze;e[30]!==Ee||e[31]!==Z?(ze=r.jsx("span",{className:Ee,children:Z}),e[30]=Ee,e[31]=Z,e[32]=ze):ze=e[32];let nt;e[33]!==c||e[34]!==_||e[35]!==Je||e[36]!==C?(nt=_?r.jsxs(r.Fragment,{children:[c&&r.jsx(jc,{icon:Vs,label:C("sectionsEditor.sectionList.asyncBadge"),className:"text-muted-foreground"}),Je&&r.jsx(io,{}),r.jsx("span",{className:"min-w-0 flex-1"})]}):Je&&r.jsx(io,{className:"absolute -right-0.5 -top-0.5"}),e[33]=c,e[34]=_,e[35]=Je,e[36]=C,e[37]=nt):nt=e[37];let Pe;return e[38]!==ze||e[39]!==nt||e[40]!==F||e[41]!==ke||e[42]!==d?(Pe=r.jsxs(r.Fragment,{children:[F,ke,d,ze,nt]}),e[38]=ze,e[39]=nt,e[40]=F,e[41]=ke,e[42]=d,e[43]=Pe):Pe=e[43],Pe}const Tc="text-global-section-fg hover:bg-global-section/12 dark:text-global-section-fg-dark dark:hover:bg-global-section/15",Ac="text-[oklch(0.45_0.15_160)] hover:bg-[oklch(0.65_0.15_160/0.12)] dark:text-[oklch(0.78_0.15_160)] dark:hover:bg-[oklch(0.65_0.15_160/0.15)]";function $o(g,e,p){if(p)return ol({selected:e});const S=g.isSavedBlock===!0,x=g.isMultivariate===!0;return le("group relative flex select-none items-center gap-2 rounded-[var(--studio-control-radius,var(--radius-md))] px-2 py-2.5",e?"bg-accent text-accent-foreground":S?Tc:x?Ac:"text-foreground/80 hover:bg-accent hover:text-accent-foreground")}function js(g,e){return le("h-7 shrink-0 overflow-hidden",e?"w-7 ml-0 opacity-100 [transition:opacity_150ms_ease-out,width_0ms,margin-left_0ms]":g?"w-7 ml-0 opacity-0 [transition:opacity_150ms_ease-out,width_0ms_150ms,margin-left_0ms_150ms] group-hover:opacity-100 group-has-[:focus-visible]:opacity-100":"w-0 -ml-2 opacity-0 [transition:opacity_150ms_ease-out,width_0ms_150ms,margin-left_0ms_150ms] group-hover:ml-0 group-hover:w-7 group-hover:opacity-100 group-hover:[transition:opacity_150ms_ease-out,width_0ms,margin-left_0ms] group-has-[:focus-visible]:ml-0 group-has-[:focus-visible]:w-7 group-has-[:focus-visible]:opacity-100 group-has-[:focus-visible]:[transition:opacity_150ms_ease-out,width_0ms,margin-left_0ms]")}function Nc(g){const e=wn.c(90),{section:p,raw:S,meta:x,decofile:V,sortableId:C,selected:_,onSelect:P,onDelete:k,onDuplicate:Y,onMakeReusable:ge,onToggleHidden:Ue,onToggleLazy:Le,onAddVariant:Ce,onDetach:Je}=g,w=Rn(),c=Zn(),xe=S?Cs(S.__resolveType??""):!1,G=p.isHidden===!0,_e=xe||G;let F;e[0]!==p?(F=Mo(p),e[0]=p,e[1]=F):F=e[1];const ke=F,d=!!Le&&!p.isMultivariate;let Oe;e[2]!==C?(Oe={id:C,animateLayoutChanges:Bc},e[2]=C,e[3]=Oe):Oe=e[3];const{attributes:u,listeners:Ee,setNodeRef:Z,transform:ze,isDragging:nt}=Ul(Oe);let Pe;e[4]!==ze?(Pe=Hl.Transform.toString(ze?{...ze,x:0}:null),e[4]=ze,e[5]=Pe):Pe=e[5];const st=nt?0:void 0;let de;e[6]!==Pe||e[7]!==st?(de={transform:Pe,opacity:st},e[6]=Pe,e[7]=st,e[8]=de):de=e[8];const v=de;let we;e[9]!==p?(we=el(p),e[9]=p,e[10]=we):we=e[10];const rt=we,ot="button",m=0;let I;e[11]!==P?(I=M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),P())},e[11]=P,e[12]=I):I=e[12];const Ze=nt?"cursor-grabbing":"cursor-pointer";let A;e[13]!==c||e[14]!==p||e[15]!==_||e[16]!==Ze?(A=le("touch-none transition-colors",Ze,$o(p,_,c)),e[13]=c,e[14]=p,e[15]=_,e[16]=Ze,e[17]=A):A=e[17];let Qe;e[18]!==V||e[19]!==x||e[20]!==S||e[21]!==p?(Qe=r.jsx(zo,{section:p,raw:S,meta:x,decofile:V}),e[18]=V,e[19]=x,e[20]=S,e[21]=p,e[22]=Qe):Qe=e[22];const W=!c&&d&&r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx(It,{type:"button",variant:"ghost",size:"icon","aria-label":w(xe?"sectionsEditor.sectionList.disableAsyncRender":"sectionsEditor.sectionList.enableAsyncRender"),className:le(js(_e,xe)),onClick:M=>{M.stopPropagation(),Le?.()},onPointerDown:Pc,children:r.jsx(Vs,{className:le("h-3.5 w-3.5",xe&&"text-warning")})})}),r.jsx(Et,{side:"bottom",children:w(xe?"sectionsEditor.sectionList.disableAsyncRender":"sectionsEditor.sectionList.enableAsyncRender")})]}),at=c?r.jsx(tl,{label:w(G?"sectionsEditor.sectionList.showSection":"sectionsEditor.sectionList.hideSection"),active:G,onToggle:Ue,children:G?r.jsx(Ro,{className:"h-3.5 w-3.5"}):r.jsx(jo,{className:"h-3.5 w-3.5"})}):r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx(It,{type:"button",variant:"ghost",size:"icon","aria-label":w(G?"sectionsEditor.sectionList.showSection":"sectionsEditor.sectionList.hideSection"),className:le(js(_e,G)),onClick:M=>{M.stopPropagation(),Ue()},onPointerDown:Cc,children:G?r.jsx(Ro,{className:"h-3.5 w-3.5"}):r.jsx(jo,{className:"h-3.5 w-3.5"})})}),r.jsx(Et,{side:"bottom",children:w(G?"sectionsEditor.sectionList.showSection":"sectionsEditor.sectionList.hideSection")})]}),fe=oi,Xe=nl;let ve;e[23]!==w?(ve=w("sectionsEditor.sectionList.sectionActionsMenu"),e[23]=w,e[24]=ve):ve=e[24];const it=le(js(_e,!1),"data-[state=open]:ml-0 data-[state=open]:w-7 data-[state=open]:opacity-100 data-[state=open]:[transition:opacity_150ms_ease-out,width_0ms,margin-left_0ms]");let $e;e[25]!==Xe||e[26]!==ve||e[27]!==it?($e=r.jsx(Xe,{label:ve,classicClassName:it}),e[25]=Xe,e[26]=ve,e[27]=it,e[28]=$e):$e=e[28];let Be;e[29]!==c||e[30]!==d||e[31]!==xe||e[32]!==Le||e[33]!==w?(Be=c&&d&&r.jsxs(r.Fragment,{children:[r.jsxs(on,{onClick:M=>{M.stopPropagation(),Le?.()},children:[r.jsx(Vs,{className:"h-4 w-4"}),w(xe?"sectionsEditor.sectionList.disableAsyncRender":"sectionsEditor.sectionList.enableAsyncRender")]}),r.jsx(ri,{})]}),e[29]=c,e[30]=d,e[31]=xe,e[32]=Le,e[33]=w,e[34]=Be):Be=e[34];let Ke;e[35]!==Y?(Ke=M=>{M.stopPropagation(),Y()},e[35]=Y,e[36]=Ke):Ke=e[36];let se;e[37]===Symbol.for("react.memo_cache_sentinel")?(se=r.jsx(Xi,{className:"h-4 w-4"}),e[37]=se):se=e[37];let X;e[38]!==w?(X=w("sectionsEditor.sectionList.duplicateMenuItem"),e[38]=w,e[39]=X):X=e[39];let ee;e[40]!==Ke||e[41]!==X?(ee=r.jsxs(on,{onClick:Ke,children:[se,X]}),e[40]=Ke,e[41]=X,e[42]=ee):ee=e[42];let D;e[43]!==c||e[44]!==ke||e[45]!==Ce||e[46]!==w?(D=ke&&r.jsxs(on,{className:le(!c&&sl),onClick:M=>{M.stopPropagation(),Ce()},children:[r.jsx(Fo,{className:"h-4 w-4"}),w("sectionsEditor.sectionList.addVariantMenuItem")]}),e[43]=c,e[44]=ke,e[45]=Ce,e[46]=w,e[47]=D):D=e[47];let T;e[48]!==c||e[49]!==rt||e[50]!==ge||e[51]!==w?(T=rt&&r.jsxs(on,{className:le(!c&&Ec),onClick:M=>{M.stopPropagation(),ge()},children:[c?r.jsx(Yn,{className:"h-4 w-4"}):r.jsx(Es,{className:"h-4 w-4"}),w("sectionsEditor.sectionList.makeReusableMenuItem")]}),e[48]=c,e[49]=rt,e[50]=ge,e[51]=w,e[52]=T):T=e[52];let me;e[53]!==c||e[54]!==Je||e[55]!==p.isMultivariate||e[56]!==p.isSavedBlock||e[57]!==w?(me=p.isSavedBlock===!0&&!p.isMultivariate&&r.jsxs(on,{onClick:M=>{M.stopPropagation(),Je()},children:[c?r.jsx(Lo,{className:"h-4 w-4"}):r.jsx(Es,{className:"h-4 w-4"}),w("sectionsEditor.sectionList.detachMenuItem")]}),e[53]=c,e[54]=Je,e[55]=p.isMultivariate,e[56]=p.isSavedBlock,e[57]=w,e[58]=me):me=e[58];let We;e[59]!==k?(We=M=>{M.stopPropagation(),k()},e[59]=k,e[60]=We):We=e[60];let et;e[61]===Symbol.for("react.memo_cache_sentinel")?(et=r.jsx(Ll,{className:"h-4 w-4"}),e[61]=et):et=e[61];let De;e[62]!==w?(De=w("sectionsEditor.sectionList.deleteMenuItem"),e[62]=w,e[63]=De):De=e[63];let $;e[64]!==We||e[65]!==De?($=r.jsxs(on,{variant:"destructive",onClick:We,children:[et,De]}),e[64]=We,e[65]=De,e[66]=$):$=e[66];let ie;e[67]!==Be||e[68]!==ee||e[69]!==D||e[70]!==T||e[71]!==me||e[72]!==$?(ie=r.jsxs(ii,{align:"end",className:"w-44",children:[Be,ee,D,T,me,$]}),e[67]=Be,e[68]=ee,e[69]=D,e[70]=T,e[71]=me,e[72]=$,e[73]=ie):ie=e[73];let Ve;e[74]!==fe||e[75]!==$e||e[76]!==ie?(Ve=r.jsxs(fe,{children:[$e,ie]}),e[74]=fe,e[75]=$e,e[76]=ie,e[77]=Ve):Ve=e[77];let Te;return e[78]!==u||e[79]!==Ee||e[80]!==P||e[81]!==Z||e[82]!==v||e[83]!==A||e[84]!==Qe||e[85]!==W||e[86]!==at||e[87]!==Ve||e[88]!==I?(Te=r.jsxs("div",{ref:Z,style:v,...u,...Ee,role:ot,tabIndex:m,onClick:P,onKeyDown:I,className:A,children:[Qe,W,at,Ve]}),e[78]=u,e[79]=Ee,e[80]=P,e[81]=Z,e[82]=v,e[83]=A,e[84]=Qe,e[85]=W,e[86]=at,e[87]=Ve,e[88]=I,e[89]=Te):Te=e[89],Te}function Cc(g){return g.stopPropagation()}function Pc(g){return g.stopPropagation()}function Bc(){return!1}function Ns(g){const e=wn.c(11),{canAddSection:p,onAddSection:S,className:x,size:V}=g,C=Rn();let _;e[0]!==x?(_=le("w-full",x),e[0]=x,e[1]=_):_=e[1];const P=!p;let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx(Il,{size:14}),e[2]=k):k=e[2];let Y;e[3]!==C?(Y=C("sectionsEditor.sectionList.addSectionButton"),e[3]=C,e[4]=Y):Y=e[4];let ge;return e[5]!==S||e[6]!==V||e[7]!==_||e[8]!==P||e[9]!==Y?(ge=r.jsxs(It,{type:"button",variant:"outline",size:V,className:_,disabled:P,onClick:S,children:[k,Y]}),e[5]=S,e[6]=V,e[7]=_,e[8]=P,e[9]=Y,e[10]=ge):ge=e[10],ge}function Kc(g){const e=wn.c(101),{listKey:p,rawSections:S,sections:x,meta:V,decofile:C,selectedIndex:_,onSelect:P,onReorder:k,onDelete:Y,onDuplicate:ge,onMakeReusable:Ue,onToggleHidden:Le,onToggleLazy:Ce,onAddVariant:Je,onDetach:w,onAddSection:c,canAddSection:xe}=g,G=xe===void 0?!0:xe,_e=Rn(),F=Zn();let ke;e[0]!==x.length?(ke=()=>Po(x.length),e[0]=x.length,e[1]=ke):ke=e[1];const[d,Oe]=b.useState(ke),[u,Ee]=b.useState(null),[Z,ze]=b.useState(p),[nt,Pe]=b.useState(x.length),st=b.useRef(!1);Z!==p?(ze(p),Pe(x.length),Oe(Po(x.length))):nt!==x.length&&(Pe(x.length),Oe(tt=>Vc(tt,x.length)));let de;e[2]===Symbol.for("react.memo_cache_sentinel")?(de={activationConstraint:{distance:8}},e[2]=de):de=e[2];let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={coordinateGetter:Jl},e[3]=v):v=e[3];const we=Ol(Eo($l,de),Eo(zl,v));let rt;e[4]!==d?(rt=d.map(Dc),e[4]=d,e[5]=rt):rt=e[5];const ot=rt;let m;e[6]===Symbol.for("react.memo_cache_sentinel")?(m=tt=>{Ee(String(tt.active.id))},e[6]=m):m=e[6];const I=m;let Ze;e[7]!==ot||e[8]!==k?(Ze=tt=>{Ee(null);const{active:O,over:Ae}=tt;if(!Ae||O.id===Ae.id)return;const He=ot.indexOf(String(O.id)),ht=ot.indexOf(String(Ae.id));He===-1||ht===-1||(Oe(bt=>Oo(Xn([...bt],He,ht))),st.current=!0,requestAnimationFrame(()=>{st.current=!1}),k?.(He,ht))},e[7]=ot,e[8]=k,e[9]=Ze):Ze=e[9];const A=Ze;let Qe;e[10]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>{Ee(null)},e[10]=Qe):Qe=e[10];const W=Qe;let at,fe,Xe,ve,it,$e,Be,Ke,se,X,ee,D,T,me,We;if(e[11]!==u||e[12]!==G||e[13]!==F||e[14]!==C||e[15]!==d||e[16]!==ot||e[17]!==A||e[18]!==V||e[19]!==c||e[20]!==Je||e[21]!==Y||e[22]!==w||e[23]!==ge||e[24]!==Ue||e[25]!==P||e[26]!==Le||e[27]!==Ce||e[28]!==S||e[29]!==x||e[30]!==_||e[31]!==we||e[32]!==_e){me=Symbol.for("react.early_return_sentinel");e:{const tt=O=>{st.current||P(O)};if(e[48]!==u||e[49]!==G||e[50]!==F||e[51]!==d||e[52]!==c||e[53]!==S||e[54]!==x||e[55]!==_e){const O=u?d.find(Ae=>Ae.id===u):null;if(ve=O!=null?x[O.index]:null,Xe=O!=null?S[O.index]:void 0,d.length===0){let Ae;e[59]!==_e?(Ae=_e("sectionsEditor.sectionList.noSections"),e[59]=_e,e[60]=Ae):Ae=e[60];let He;e[61]!==Ae?(He=r.jsx("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:Ae}),e[61]=Ae,e[62]=He):He=e[62];const ht=He;let bt;e[63]!==G||e[64]!==F||e[65]!==ht||e[66]!==c?(bt=F?ht:r.jsxs("div",{className:"space-y-2",children:[ht,r.jsx(Ns,{canAddSection:G,onAddSection:c,size:"sm"})]}),e[63]=G,e[64]=F,e[65]=ht,e[66]=c,e[67]=bt):bt=e[67],me=bt;break e}T=le(O&&"cursor-grabbing"),e[48]=u,e[49]=G,e[50]=F,e[51]=d,e[52]=c,e[53]=S,e[54]=x,e[55]=_e,e[56]=Xe,e[57]=ve,e[58]=T}else Xe=e[56],ve=e[57],T=e[58];fe=ql,Ke=we,se=Gl,X=I,ee=A,D=W,at=Ql,$e=ot,Be=Xl,We="space-y-1",it=d.map(O=>{const Ae=x[O.index];return Ae?r.jsx(Nc,{sortableId:O.id,section:Ae,raw:S[O.index],meta:V,decofile:C,selected:_===O.index,onSelect:()=>tt(O.index),onDelete:()=>Y(O.index),onDuplicate:()=>ge(O.index),onMakeReusable:()=>Ue(O.index),onToggleHidden:()=>Le(O.index),onToggleLazy:Ce?()=>Ce(O.index):void 0,onAddVariant:()=>Je(O.index),onDetach:()=>w(O.index)},O.id):null})}e[11]=u,e[12]=G,e[13]=F,e[14]=C,e[15]=d,e[16]=ot,e[17]=A,e[18]=V,e[19]=c,e[20]=Je,e[21]=Y,e[22]=w,e[23]=ge,e[24]=Ue,e[25]=P,e[26]=Le,e[27]=Ce,e[28]=S,e[29]=x,e[30]=_,e[31]=we,e[32]=_e,e[33]=at,e[34]=fe,e[35]=Xe,e[36]=ve,e[37]=it,e[38]=$e,e[39]=Be,e[40]=Ke,e[41]=se,e[42]=X,e[43]=ee,e[44]=D,e[45]=T,e[46]=me,e[47]=We}else at=e[33],fe=e[34],Xe=e[35],ve=e[36],it=e[37],$e=e[38],Be=e[39],Ke=e[40],se=e[41],X=e[42],ee=e[43],D=e[44],T=e[45],me=e[46],We=e[47];if(me!==Symbol.for("react.early_return_sentinel"))return me;let et;e[68]!==it||e[69]!==We?(et=r.jsx("div",{className:We,children:it}),e[68]=it,e[69]=We,e[70]=et):et=e[70];let De;e[71]!==at||e[72]!==$e||e[73]!==Be||e[74]!==et?(De=r.jsx(at,{items:$e,strategy:Be,children:et}),e[71]=at,e[72]=$e,e[73]=Be,e[74]=et,e[75]=De):De=e[75];let $;e[76]!==Xe||e[77]!==ve||e[78]!==F||e[79]!==C||e[80]!==V?($=ve?r.jsx("div",{className:le("cursor-grabbing shadow-lift",$o(ve,!1,F)),children:r.jsx(zo,{section:ve,raw:Xe,meta:V,decofile:C})}):null,e[76]=Xe,e[77]=ve,e[78]=F,e[79]=C,e[80]=V,e[81]=$):$=e[81];let ie;e[82]!==$?(ie=si.createPortal(r.jsx(Wl,{dropAnimation:Zi,children:$}),document.body),e[82]=$,e[83]=ie):ie=e[83];let Ve;e[84]!==fe||e[85]!==Ke||e[86]!==se||e[87]!==X||e[88]!==ee||e[89]!==D||e[90]!==De||e[91]!==ie?(Ve=r.jsxs(fe,{sensors:Ke,collisionDetection:se,onDragStart:X,onDragEnd:ee,onDragCancel:D,children:[De,ie]}),e[84]=fe,e[85]=Ke,e[86]=se,e[87]=X,e[88]=ee,e[89]=D,e[90]=De,e[91]=ie,e[92]=Ve):Ve=e[92];let Te;e[93]!==G||e[94]!==F||e[95]!==c?(Te=!F&&r.jsx(Ns,{canAddSection:G,onAddSection:c,size:"sm",className:"mt-2"}),e[93]=G,e[94]=F,e[95]=c,e[96]=Te):Te=e[96];let M;return e[97]!==T||e[98]!==Ve||e[99]!==Te?(M=r.jsxs("div",{className:T,children:[Ve,Te]}),e[97]=T,e[98]=Ve,e[99]=Te,e[100]=M):M=e[100],M}function Dc(g){return g.id}function Mc(g,e,p,S){if(!g||typeof g!="object")return{kind:"error",reason:"no-matcher-rule"};const x=e.trim();if(!x)return Jt(g,p,S)?{kind:"inline",blockKey:g.__resolveType??"",inlinedRule:Ts(g,p,S)}:{kind:"noop"};const V=As(g,p,S);if(!V)return{kind:"error",reason:"unreadable-rule"};if(V.blockKey)return{kind:"updateBlock",blockKey:V.blockKey,blockData:Ft(V.resolveType,V.data,x)};const C=Jn(x),_=Qn(C,p);return _?{kind:"error",reason:"invalid-block-id",message:_}:{kind:"createBlock",blockId:C,blockData:Ft(V.resolveType,V.data,x),reference:cn(C)}}const Bo="section-form-stale-save",Fc=3;function Ko(g,e,p){const S=e.global&&e.pageKey?[{label:"Default",sections:[{__resolveType:e.pageKey}]}]:Io(e.pageKey?g[e.pageKey]?.sections:void 0,g,p),x=Math.max(0,Math.min(e.pageVariantIndex,S.length-1)),V=S[x]?.sections??[];return{pageVariants:S,variantIndex:x,rawSections:V,parsedSections:kn(V,g,p)}}const Do=new WeakMap;let Ic=0;function Lc(g){let e=Do.get(g);return e===void 0&&(e=++Ic,Do.set(g,e)),e}function Wf({orgSlug:g,virtualMcpId:e,branch:p,previewReady:S=!0,previewUrl:x,currentPath:V,activePageBlockKey:C=null,activeGlobalBlockKey:_=null,externalSelection:P,onSaved:k,initialEditSeo:Y=!1,onExitSeo:ge,onSelectRoot:Ue,onViewJsonFile:Le,onFocusedBlockChange:Ce,onSectionPicked:Je,onVariantPreviewOverride:w}){const c=Rn(),xe=Wi(),G=xe?.taskId??null,_e=S?{orgSlug:g,virtualMcpId:e,branch:p,threadId:G,previewUrl:x}:null,[F,ke]=b.useState([]),{data:d,isLoading:Oe}=yl(_e,{pollWhile:F.length>0}),{data:u,isLoading:Ee}=Tl(_e),Z=Zn(),ze=xe?.virtualMcpId,Pe=Gi(ze===e?e:null)?.metadata?.siteSlug??null,st=ec({virtualMcpId:e,branch:p,sandboxUrl:x}),de=Sl(e,p),v=bl(de),we=Ti(v),rt=!v,ot=!!st||v,[m,I]=b.useState(null),[Ze,A]=b.useState(null),[Qe,W]=b.useState(null),[at,fe]=b.useState(0),[Xe,ve]=b.useState(void 0),[it,$e]=b.useState(null),Be={index:it,remember:$e},[Ke,se]=b.useState(null),[X,ee]=b.useState(null),[D,T]=b.useState([]),me=b.useRef(null),[We,et]=b.useState(D.length);We!==D.length&&(et(D.length),requestAnimationFrame(()=>{me.current&&(me.current.scrollTop=0)}));const[De,$]=b.useState(0),[ie,Ve]=b.useState(null),[Te,M]=b.useState(null),[tt,O]=b.useState(null),[Ae,He]=b.useState(!1),[ht,bt]=b.useState(!1),jn=b.useRef(null),[En,Wo]=b.useState(!0),[Qt,Vn]=b.useState(!1),[Lt,Tn]=b.useState(!1),[Re,un]=b.useState(Y),[Ps,Bs]=b.useState(Y);Y&&!Ps&&(Bs(!0),un(!0),I(null),A(null),W(null),T([])),!Y&&Ps&&Bs(!1);const[Ho,dn]=b.useState(null),[Ks,An]=b.useState(void 0),[Ds,Ot]=b.useState([]),[Ms,Xt]=b.useState(0),[Me,lt]=b.useState(0),[qo,Fe]=b.useState(null),[Yt,qe]=b.useState(null),[Fs,Is]=b.useState(null),Nn=li(),Cn=xl({orgSlug:g,virtualMcpId:e,branch:p},{tunnel:!1}),fn=Dl({orgSlug:g,virtualMcpId:e,branch:p}),[Go,Uo]=b.useState(V),[Jo,Qo]=b.useState(C),[Xo,Yo]=b.useState(_);(Go!==V||Jo!==C||Xo!==_)&&(queueMicrotask(()=>fn.flush()),Uo(V),Qo(C),Yo(_),I(null),A(null),W(null),fe(0),se(null),ee(null),lt(0),Fe(null),qe(null),T([]),$(t=>t+1),un(!1),dn(null),An(void 0),Ot([]),Xt(t=>t+1));const L=Ml({orgSlug:g,virtualMcpId:e,branch:p}),Ls=il({orgSlug:g,virtualMcpId:e,branch:p},d??{},{onSaved:k}),mn=Ls.save,Pn=Kl({orgSlug:g,virtualMcpId:e,branch:p}),Os=gc({orgSlug:g,virtualMcpId:e,branch:p}),[Zt,en]=b.useState(!1),N=b.useRef(null),_t=b.useRef(null),gt=b.useRef(null),vt=b.useRef(null),Bn=b.useRef({}),zt=b.useRef(null),pn=b.useRef(!1),hn=b.useRef(!1),ye=b.useRef(new Map),tn=b.useRef(!1),ct=b.useRef([]),es=b.useRef(new WeakSet);_l(g,e,t=>{const{activePageKey:n,rawSections:s,parsedSections:o,selectedSectionIndex:a}=re.current,i=new Set;n&&i.add(n);for(const l of[_t.current?.sectionIndex,a]){const f=l==null?void 0:s[l],j=l==null?void 0:o[l],h=f&&j?.isSavedBlock?bs(f,j):null;h&&i.add(h)}if([...i].some(l=>t.has(l))){for(const l of[N,gt,vt])l.current&&clearTimeout(l.current),l.current=null;_t.current=null,ye.current.clear(),n&&t.has(n)&&(Bn.current={})}});const re=b.useRef({rawSections:[],parsedSections:[],decofile:{},activePageKey:null,pageVariants:[],variantIndex:0,sectionVariantIndex:0,selectedSectionIndex:null}),[zs,$s]=b.useState(0),[Zo,ea]=b.useState(0),Ws=ci(de,{orgSlug:g,virtualMcpId:e,branch:p}),Hs=ui(Ws,F[0]?.blockKey??null,di(d,F[0]?.blockKey??null)),[ta,na]=b.useState(null),ts=kl(g,e).epoch,[sa,ra]=b.useState(ts);cc(Re?{orgSlug:g,virtualMcpId:e,branch:p}:null,d??void 0,u??void 0);const qs=_??(d&&u?ko(wo(d,u),V,C)?.key??null:null),ns=bo({orgSlug:g,virtualMcpId:e,branch:p},qs?[qs]:[],{withRefs:!0}),[Gs,oa]=b.useState(!1),ss=bo({orgSlug:g,virtualMcpId:e,branch:p},Gs?Al:[]),Us={ready:!(de.kind==="protocol"&&de.hosted)||Gs&&ss.ready,failed:ss.failed,retry:ss.retry,request:()=>oa(!0)};if(ns.failed)return r.jsxs("div",{className:"h-full w-full flex flex-col items-center justify-center gap-3 p-6 text-center text-sm text-muted-foreground",children:[r.jsx("p",{children:c("sectionsEditor.hosted.blockLoadFailed")}),r.jsx("p",{children:c("sectionsEditor.hosted.blockLoadFailedHint")}),r.jsx(It,{variant:"outline",size:"sm",onClick:ns.retry,children:c("sectionsEditor.namedRules.tryAgain")})]});if(!S||Oe||Ee||!ns.ready)return r.jsx("div",{className:"h-full w-full flex items-center justify-center",children:r.jsx(fi,{className:"size-5 text-muted-foreground"})});if(!d||!u)return r.jsx("div",{className:"h-full w-full flex items-center justify-center text-sm text-muted-foreground",children:c("sectionsEditor.sectionsEditor.couldNotLoadSiteData")});const aa=wo(d,u),q=!!_,oe=q?null:ko(aa,V,C),y=q?_:oe?.key??null,rs=q&&_?d[_]:void 0,Js=q&&_&&rs?Nl(_,rs):q&&_?_:"",nn=!q&&y&&d[y]?d[y]:null,os=Re&&d&&u&&y&&oe?Vo(d,{kind:"page",pageKey:y,pageName:String(oe.name??""),path:String(oe.path??"")},u):null,ia=Re?nn?.seo:void 0,Kn=Ks!==void 0?Ks:ia,la=Re?rc(Kn):void 0,Qs=os?.seoTypeOptions??[],Xs=Re&&u?oc(u):"",as=Ho??la??{},Dn=Re&&os?uc(as,os):null,Ys=Re&&Dn&&ac(Kn)?qn(Dn,u):null,Zs=Re?ic(d,u)?.seoData:void 0,pe=q?[{label:"Default",sections:[{__resolveType:_}]}]:Io(nn?.sections,d??{},v),yt=pe.length>1,te=Math.min(at,pe.length-1),Se=pe[te],B=Se?.sections??[],ce=kn(B,d,v),Mn=!q&&vc(nn?.sections,v);if(q&&_&&Fs!==_){Is(_);const t=B[0],n=ce[0];if(t&&n){I(0),lt(0),T([]);const s=wt(t,n,d,v);s&&(A(s.data),W(s.resolveType),qe(null),Fe(null))}}!q&&Fs!==null&&Is(null),re.current={rawSections:B,parsedSections:ce,decofile:d??{},activePageKey:y,pageVariants:pe,variantIndex:te,sectionVariantIndex:Me,selectedSectionIndex:m};const ca=()=>({multivariate:Mn,index:te,variants:pe.map(t=>({rule:t.rule})),lazyValues:v&&Mn&&Ni(nn?.sections?.variants?.[te]?.value)}),is=(t,n)=>{if(!w)return;if(!y||!Mn||t.length<=1){w(null);return}const s={multivariate:!0,index:n,variants:t},o=v?xo(y,s):Co(y,s,d,u);w(o.length>0?o:null)},ls=w&&y&&Mn&&yt&&!Oe&&!Ee?y:null;if(ls!==ta&&(na(ls),ls)){const t=pe.map(s=>({rule:s.rule})),n=te;queueMicrotask(()=>is(t,n))}const $t=(t,n,s)=>{if(!w)return;if(!y){w(null);return}const o=ca(),a=v?xo(y,o):Co(y,o,d,u);if(!t||n<0){w(a.length>0?a:null);return}const i={pageKey:y,page:o,sectionIndex:n,sectionLazy:ce[n]?.isLazy??!1,mvObj:t,selectedVariantIndex:s},l=v?Rl(i):_c({...i,decofile:d,meta:u}),f=v?jl(a,l):[...a,...l];w(f.length>0?f:null)},xt=(t,n,s,o=m??-1,a=!1)=>{const i=pt(t,n);if(!i){A(null),W(null),qe(null),Fe(null),a&&$t(null,o,s);return}const f=Xr(i,we)[s];if(!f){A(null),W(null),qe(null),Fe(null),a&&$t(null,o,s);return}const j=gi(f.value,d);A(j?.data??null),W(j?.resolveType??null);const{resolveType:h,formValue:R}=Ut(f.rule,d,u??void 0);qe(h),Fe(R),a&&$t(i,o,s)},cs=t=>{M(null),fe(t),I(null),A(null),W(null),T([]);const n=pe[t]?.rule,{resolveType:s,formValue:o}=Ut(n,d??{},u??void 0);ee(s),se(o),is(pe.map(a=>({rule:a.rule})),t)},ua=(t,n)=>{const s=B[t],o=ce[t];if(!s||!o)return!1;const a=o.isMultivariate?pt(s,o)?.variants?.length??0:0,i=n<a?n:0;if(I(t),lt(i),T([]),$(l=>l+1),o.isMultivariate)xt(s,o,i,t);else{const l=wt(s,o,d,v);l?(A(l.data),W(l.resolveType)):(A(null),W(null)),qe(null),Fe(null)}return!0},er=P?.index;if(P!==void 0&&(P?.seq??null)!==Xe&&(ve(P?.seq??null),typeof er=="number"&&ua(er,0)),ts!==sa){ra(ts);const t=N.current!==null||ye.current.size>0||vt.current!==null||gt.current!==null||L.isPending||Ls.isPending||fn.isPending||F.length>0,n=m!==null&&Qr(me.current,document.activeElement);if(!t&&n&&(tn.current=!0),!t&&!n&&m!==null){const s=B[m],o=ce[m];if(T([]),$(a=>a+1),!s||!o)I(null),A(null),W(null);else if(o.isMultivariate)xt(s,o,Me,m);else{const a=wt(s,o,d,v);A(a?.data??null),W(a?.resolveType??null)}}!t&&Re&&(dn(null),An(void 0),Xt(s=>s+1))}if(zs!==Zo){ea(zs);const t=m!==null?B[m]:null,n=m!==null?ce[m]:null;if(t&&n&&m!==null)if(T([]),$(s=>s+1),n.isMultivariate)xt(t,n,Me,m);else{const s=wt(t,n,d,v);A(s?.data??null),W(s?.resolveType??null)}}const ut=F[0];if(ut){const{formBase:t,target:n}=ut,s=Ko(d,n,v),o=t.sectionIndex,a=s.rawSections.length===t.sectionCount?xs(s.rawSections[o],s.parsedSections[o],n.sectionVariantIndex,d,v):null,i=mi(ut,a,l=>Yr(t,l));if(i){const f=[{...ut,...i,changedAgain:!0},...F.slice(1)];ct.current=f,ke(f)}}const gn={orgSlug:g,virtualMcpId:e,branch:p,threadId:G,previewUrl:v?void 0:x??void 0,siteSlug:Pe},Fn=Qe&&u?qn(Qe,u):null,dt=(t,n)=>{if(!y)return;N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear(),vt.current&&(clearTimeout(vt.current),vt.current=null),gt.current&&(clearTimeout(gt.current),gt.current=null);const s=ln(d,y,t,te,pe);L.mutate({blockKey:y,data:s},{onSuccess:()=>n?.onSuccess?.()??k?.(),onError:o=>{n?.onError?.(),L.reportError(o)}})},Wt=()=>{Ce?.(null),I(null),Tn(!1),A(null),W(null),lt(0),Fe(null),qe(null),T([]),$(t=>t+1)},tr=()=>Qr(me.current,document.activeElement),us=(t=c("sectionsEditor.sectionsEditor.blockChangedElsewhere"))=>{if(N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear(),_t.current=null,H.error(t,{id:Bo}),tr()){tn.current=!0;return}$s(n=>n+1)},nr=()=>{!tn.current||tr()||ct.current.length>0||N.current!==null||pn.current||hn.current||ye.current.size>0||(tn.current=!1,$s(t=>t+1))},sr=()=>{tn.current&&setTimeout(nr,0)},rr=de.kind==="protocol"&&de.source==="github",or=t=>Vl(Nn,Cn,t,de.kind==="protocol"?de:null),ar=t=>{ye.current.size!==0&&setTimeout(()=>{if(pn.current||hn.current)return;const n=[...ye.current.values()];ye.current.clear();for(const s of n)s()},t)},da=t=>{const{activePageKey:n,variantIndex:s,sectionVariantIndex:o}=re.current,a=zt.current;return{formBase:a?.sectionIndex===t&&a.variantIndex===o?a:null,pageKey:n,global:q,pageVariantIndex:s,sectionVariantIndex:o,schema:Fn}},vn=t=>{ct.current=t,ke(t)},fa=t=>{const n=ct.current,s=n.findIndex(i=>i.formBase===t.formBase),o=s>=0?n[s]:void 0,a=o?n.with(s,{...t,choices:so(o.plan,o.choices,t.plan),fresh:Li(o.plan,t.plan,o.fresh),changedAgain:o.changedAgain||Hn(o.plan.theirs)!==Hn(t.plan.theirs)}):[...n,{...t,changedAgain:es.current.has(t.formBase)}];vn(a)},ir=(t,n)=>{const s=ct.current,o=s.findIndex(l=>l.formBase===t),a=s[o];if(!a)return!1;if(Hn(a.plan.mine)===Hn(n))return!0;const i=no({...a.plan,mine:n});if(i.pointers.length===0){const l=s.filter(f=>f!==a);return vn(l),!1}return vn(s.with(o,{...a,plan:i,choices:so(a.plan,a.choices,i)})),!0},ma=t=>{const n=re.current;return n.selectedSectionIndex===t.formBase.sectionIndex&&n.activePageKey===t.target.pageKey&&n.variantIndex===t.target.pageVariantIndex&&n.sectionVariantIndex===t.target.sectionVariantIndex},pa=()=>{const t=ct.current[0];if(!t)return null;const{formBase:n,target:s}=t;N.current&&_t.current?.sectionIndex===n.sectionIndex&&_t.current.sectionVariantIndex===s.sectionVariantIndex&&(clearTimeout(N.current),N.current=null,_t.current=null),ye.current.delete(`${s.pageKey}:${n.sectionIndex}:${s.sectionVariantIndex}`);const o=n.emitted;return o&&typeof o=="object"&&!ir(n,o)&&yn(o,n.sectionIndex,0,s),ct.current[0]??null},ha=()=>{const t=ct.current[0],n=pa();if(!n||!t||n.formBase!==t.formBase||n.plan.pointers.some(i=>!t.plan.pointers.includes(i)))return;const s=ji(n.plan,n.choices);de.kind==="protocol"&&de.source==="github"&&Ei(n.plan,n.choices)&&wl(c,!1),vn(ct.current.slice(1));const{formBase:o,target:a}=n;o.base=n.plan.theirs,o.version=void 0,o.emitted=s,es.current.add(o),(zt.current===o||ma(n))&&(zt.current=o,A(s),$(i=>i+1)),yn(s,o.sectionIndex,0,a)},ga=t=>{const[n,...s]=ct.current;n&&vn([{...n,choices:t},...s])},yn=(t,n,s=0,o,a=!1)=>{const i=o??da(n),l=i.sectionVariantIndex,f=i.formBase,j=a||to(ct.current,f,i,n,v).runNow,h=_t.current;N.current&&(clearTimeout(N.current),N.current=null,h&&(h.sectionIndex!==n||h.sectionVariantIndex!==l)&&h.write());const R=`${i.pageKey}:${n}:${l}`,E=()=>{if(pn.current||hn.current){ye.current.set(R,E);return}const K=typeof t=="function"?t():t,z=to(ct.current,f,i,n,v).base;if(z&&ir(z,K))return;const ne=re.current.decofile,{rawSections:J,parsedSections:Ne,pageVariants:Q,variantIndex:be}=Ko(ne,i,v),Ie=i.pageKey,he=J[n];if(!he)return;const ue=Ne[n];if(!ue)return;const Ge=f?.base,Ye=xs(he,ue,l,ne,v),Nt=!!Ge&&!!Ye&&Ci(Ge,Ye)&&!(f&&Yr(f,Ye));if(Nt&&Ge&&Ye){if(Pi(Ge,Ye)){us(c("sectionsEditor.sectionsEditor.sectionReplacedElsewhere"));return}const U=ue.isSavedBlock?"here":Bi(Ge,J.map((ae,mt)=>xs(ae,Ne[mt],l,ne,v)),n,f?.sectionCount??J.length);if(U==="unknown"){us(c("sectionsEditor.sectionsEditor.sectionReplacedElsewhere"));return}if(typeof U=="number"&&f){f.sectionCount=J.length,f.sectionIndex=U,zt.current===f&&I(U),yn(K,U,s,i);return}}const Ct=Nt&&Ge&&Ye?no({ancestor:Ge,mine:K,theirs:Ye}):null;if(Ct&&Ct.pointers.length>0&&f){f.sectionCount=J.length,fa({plan:Ct,formBase:f,target:i,sectionIndex:n,choices:Ki(Ct),changedAgain:!1,blockKey:ue.isSavedBlock?bs(he,ue):Ie,fresh:{}});return}const Pt=Ct?Ct.merged:null,rn=Pt??K,Gr=Di({merged:!!Pt,tracked:f,current:zt.current,saved:K});Pt&&H.info(c("sectionsEditor.sectionsEditor.blockMergedWithOthers"),{id:Bo}),Gr&&f&&(f.emitted=Pt,A(Pt));const Ss=Gr||!Pt?rn:K;f&&(f.base=Ss,f.sectionCount=J.length,Mi(f,Ss));const Ur={onSuccess:()=>{f&&es.current.delete(f),k?.()},onError:U=>{if(f?.base===Ss&&Ge&&(f.base=Ge),U instanceof El){if(f&&(f.version=void 0),s<Fc){ye.current.delete(R),hn.current=!0;const ae=Oi(s,U.carriedStored);setTimeout(()=>{hn.current=!1,yn(()=>{const mt=f?.emitted;return mt&&typeof mt=="object"?mt:K},n,s+1,i,ae.immediate),ye.current.delete(R),ar(xn(v))},ae.delay)}else us();return}L.reportError(U)}},Jr=U=>{pn.current=!0;let ae=!1;L.mutateAsync(U).then(()=>Ur.onSuccess(),mt=>{ae=!0,Ur.onError(mt)}).finally(()=>{pn.current=!1,ar(ae?xn(v):0),nr()})};if(ue.isSavedBlock){const U=bs(he,ue);if(!U)return;Jr({blockKey:U,data:rn,...Ge?{base:{value:Fi({startedFrom:Ge,stored:Ye,rebased:!!Pt,refused:s>0})}}:{},rebaseOnConflict:!1,guard:ro({formBase:f,rebased:!!Pt,versionOf:or,productionVersionOf:ae=>ao(Nn,Cn,ae),...rr?{copy:{value:ne[U]}}:{}})});return}if(!Ie)return;const Wn={...ne[Ie]},Gt=[...J];if(ue.isMultivariate){const U=pt(he,ue);if(!U||!Ie)return;const ae=Ii(U,l,rn);Gt[n]=Bt(he,ue,ae)}else if(ue.isHidden){const U=Cs(he.__resolveType),ae=U?{...he.section}:{...he},mt=Array.isArray(ae.variants)?[...ae.variants]:[];mt[0]&&(mt[0]=oo(ae.__resolveType,mt[0],rn)),ae.variants=mt,U?Gt[n]={...he,section:ae}:Gt[n]=ae}else ue.isLazy?Gt[n]={...he,section:rn}:Gt[n]=rn;if(Q.length>1){const U=Wn.sections,ae=[...U?.variants??[]];ae[be]&&(ae[be]=oo(U?.__resolveType,ae[be],Gt)),Wn.sections={...U,variants:ae}}else Wn.sections=Gt;Jr({blockKey:Ie,data:Wn,rebaseOnConflict:!1,guard:ro({formBase:null,rebased:!1,versionOf:or,productionVersionOf:U=>ao(Nn,Cn,U),...rr?{copy:{value:ne[Ie]}}:{}})})};if(_t.current={sectionIndex:n,sectionVariantIndex:l,write:E},j){_t.current=null,E();return}N.current=setTimeout(()=>{N.current=null,E()},xn(v))},va=t=>{tn.current=!1,I(t),lt(0),T([]),$(a=>a+1);const n=B[t],s=ce[t];if(Ce?.(s?.isSavedBlock?s.resolveType??null:null),!n||!s)return;if(s.isMultivariate){xt(n,s,0,t);return}const o=wt(n,s,d,v);if(!o){A(null),W(null),qe(null),Fe(null),$t(null,t,0);return}A(o.data),W(o.resolveType),qe(null),Fe(null),$t(null,t,0)},lr=t=>{const n=t;m!==null&&(zt.current=Vi(zt.current,{sectionIndex:m,variantIndex:re.current.sectionVariantIndex,shown:Ze,next:n,sectionCount:re.current.rawSections.length})),A(n),m!==null&&yn(n,m)},ds=t=>{if(!y||!d||!u||!oe)return;const n={kind:"page",pageKey:y,pageName:String(oe.name??""),path:String(oe.path??"")},s=Vo(d,n,u);s&&fn.save(y,()=>{const o=Nn.getQueryData(Ai.decofile(Cn))?.[y];if(!o||typeof o!="object"||o===null||Array.isArray(o))return null;const a={...o,...Bn.current};return Bn.current={},t?.raw!==void 0?dc(a,t.raw,u):t?.inner!==void 0?fc(n,s,a,t.inner):a})},cr=(t,n)=>{y&&(Bn.current[t]=n,ds())},ya=(t,n)=>{if(!y)return;const s=Xn([...B],t,n);m!==null&&(m===t?I(n):t<m&&n>=m?I(m-1):t>m&&n<=m&&I(m+1)),dt(s)},Sa=t=>{if(!y)return;const n=B.filter((s,o)=>o!==t);m===t?Wt():m!==null&&m>t&&I(m-1),dt(n)},ba=t=>{if(!y)return;const n=B[t];if(!n)return;const s=[...B];s.splice(t+1,0,gl(n)),m!==null&&m>t&&I(m+1),dt(s)},xa=t=>{if(!y)return;const n=B[t],s=ce[t];if(!n||!s)return;const o=s.isHidden?ki(n,v):wi(n,u);if(!o)return;const a=[...B];a[t]=o,m===t&&Wt(),dt(a)},_a=t=>{if(!y)return;const n=B[t],s=ce[t];if(!n||!s||s.isMultivariate)return;const o=_i(n);if(!o)return;const a=[...B];a[t]=o,m===t&&Wt(),dt(a)},ka=t=>{if(!y)return;const n=B[t],s=ce[t];if(!n||!s?.isSavedBlock)return;const o=wt(n,s,d,v);if(!o?.data)return;const{name:a,...i}=o.data,l=[...B];s.isLazy?l[t]={...n,section:i}:l[t]=i,m===t&&Wt(),dt(l)},wa=t=>{if(!y)return;const n=qi(ce),s=[...B.slice(0,n),{__resolveType:t.resolveType},...B.slice(n)];dt(s,{onError:()=>{re.current.selectedSectionIndex===n&&Wt()}}),He(!1),I(n),lt(0),T([]),$(l=>l+1);const o=s[n],a=kn(s,d,v)[n];if(!o||!a)return;if(a.isMultivariate){xt(o,a,0);return}const i=wt(o,a,d,v);if(!i){A(null),W(null),qe(null),Fe(null);return}A(i.data),W(i.resolveType),qe(null),Fe(null)},ur=t=>{jn.current=t.append,He(!0)},Ra=t=>{const n=jn.current;if(!n){wa(t);return}n({__resolveType:t.resolveType}),He(!1),jn.current=null},dr=t=>{if(m===null)return;const n=B[m],s=ce[m];!n||!s?.isMultivariate||(lt(t),T([]),$(o=>o+1),xt(n,s,t,m,!0))},ja=t=>{if(m===null||!y)return;const n=B[m],s=ce[m];if(!n||!s?.isMultivariate)return;const o=pt(n,s);if(!o)return;const a=bi(o,t);if(!a){H.error(c("sectionsEditor.sectionsEditor.cannotDeleteOnlyVariant"));return}const i=[...B];i[m]=Bt(n,s,a);const l=a.variants;let f=Me;t===Me?f=Math.min(t,l.length-1):t<Me&&(f=Me-1),lt(f),T([]),$(j=>j+1),xt(i[m],s,f),dt(i)},Ea=t=>{if(m===null||!y)return;const n=B[m],s=ce[m];if(!n||!s?.isMultivariate)return;const o=pt(n,s);if(!o)return;const a=xi(o,t,v),i=[...B];i[m]=Bt(n,s,a);const l=eo(o.variants??[],t,v);lt(l),T([]),$(f=>f+1),xt(i[m],s,l,m,v),dt(i)},Va=(t,n)=>{if(m===null||!y||t===n)return;const s=B[m],o=ce[m];if(!s||!o?.isMultivariate)return;const a=pt(s,o);if(!a)return;const i=yi(a,t,n),l=[...B];l[m]=Bt(s,o,i);let f=Me;Me===t?f=n:t<Me&&n>=Me?f=Me-1:t>Me&&n<=Me&&(f=Me+1),lt(f),xt(l[m],o,f,m,v),dt(l)},Sn=t=>{const n=t??m;if(n===null||!y)return;const s=B[n],o=ce[n];if(!s||!o)return;const a=vi(s,o,void 0,u,v);if(!a){H.error(c("sectionsEditor.sectionsEditor.sectionCannotHaveVariants"));return}const i=[...B];i[n]=a.section;const l=kn(i,d,v)[n];if(!l?.isMultivariate){H.error(c("sectionsEditor.sectionsEditor.couldNotAddVariant"));return}I(n),lt(a.newVariantIndex),T([]),$(f=>f+1),xt(a.section,l,a.newVariantIndex,n,v),dt(i)},fr=()=>{if(m===null||!y)return;const t=B[m],n=ce[m];if(!t||!n?.isMultivariate)return;const s=pt(t,n);if(!s)return;const o=Si(t,n,s);if(!o){H.error(c("sectionsEditor.sectionsEditor.couldNotRemoveVariants"));return}const a=[...B];a[m]=o;const i=kn(a,d,v)[m];if(!i)return;lt(0),qe(null),Fe(null),T([]),$(f=>f+1);const l=wt(o,i,d,v);l?(A(l.data),W(l.resolveType)):(A(null),W(null)),$t(null,m,0),dt(a)},Ta=async t=>{if(ie===null||!y)return;const n=Qn(t,d,u);if(n){H.error(n);return}const s=B[ie],o=ce[ie];if(!s||!o)return;const a=wt(s,o,d,v);if(!a){H.error(c("sectionsEditor.sectionsEditor.sectionCannotBeSavedAsGlobal"));return}const i={...a.data,name:t};try{const l=await L.mutateAsync({blockKey:t,data:i,create:!0}),f=[...B];f[ie]={__resolveType:t},await L.mutateAsync({blockKey:y,data:ln(d,y,f,te,pe)}),m===ie&&Wt(),Ve(null),Un(l)||H.success(c("sectionsEditor.sectionsEditor.savedGlobalBlock",{blockId:t})),k?.()}catch(l){H.error(c("sectionsEditor.sectionsEditor.failedToSaveGlobalBlock"),{description:Kt(c,Dt(l))})}},mr=Se?.rule;if(yt&&m===null&&X===null&&mr){const{resolveType:t,formValue:n}=Ut(mr,d??{},u??void 0);ee(t),se(n)}const sn=u?ll(u):[],fs=u&&d?cl(u,d):[],Ht=v&&u&&d?mc(u,d):[],ms=(t,n)=>{if(Ht.length===0)return;const s=Cl(t);return{kinds:Ht,selected:s,campaignPrefill:pc(t),onPick:n,load:Us}},pr=!q&&!!(ot&&u&&d),hr=X&&u?qn(X,u):null,St=()=>{gt.current&&(clearTimeout(gt.current),gt.current=null),vt.current&&(clearTimeout(vt.current),vt.current=null)},qt=async(t,n)=>{if(bc(n,t,u,v))try{await Pn.mutateAsync({blockKey:t})}catch(s){H.error(c("sectionsEditor.sectionsEditor.couldNotDeleteMatcherBlock"),{description:Kt(c,Dt(s))})}},gr=t=>{gt.current&&clearTimeout(gt.current),gt.current=setTimeout(()=>{const{activePageKey:n,decofile:s,variantIndex:o}=re.current;if(!n)return;const a={...s[n]},i={...a.sections},l=[...i.variants??[]],f=l[o],j=f?.rule;if(Jt(j,s,u)){const h=j?.__resolveType??"",R=s[h],E=typeof R?.name=="string"?R.name:h,{__resolveType:K,...z}=t;L.mutate({blockKey:h,data:Ft(K??"",z,E)},{onSuccess:()=>k?.(),onError:L.reportError});return}f&&(l[o]={...f,rule:t}),a.sections={...i,variants:l},L.mutate({blockKey:n,data:a},{onSuccess:()=>k?.(),onError:L.reportError})},xn(v))},vr=t=>{ee(t);const n=t?No(t,u):{__resolveType:Zr(u)};se(t?n:{}),gr(n)},yr=t=>{const n=t;se(n);const s=X?{__resolveType:X,...n}:{...n};gr(s)},In=async(t,n,s)=>{const o=hc(n,t);if(!o.ok)return o.reason==="conflict"&&H.info(t.kind==="experiments"?c("sectionsEditor.namedRulePicker.conflictTests"):c("sectionsEditor.namedRulePicker.conflictCampaigns"),_o),null;const a={};if(s){const i=s(o.rule);if(!i)return null;a[i.blockKey]=i.data}return o.blockWrite&&(a[o.blockWrite.blockKey]=o.blockWrite.block),Object.keys(a).length>0&&!(await Os.apply({writes:a})).ok?null:(o.blockWrite&&H.success(t.kind==="experiments"?c("sectionsEditor.namedRulePicker.createdTest",{name:t.name.trim()}):c("sectionsEditor.namedRulePicker.createdCampaign",{name:t.name.trim()}),{..._o,description:c("sectionsEditor.namedRulePicker.createdHint")}),{rule:o.rule,projected:{...n,...a}})},Sr=Ht.length>0?{kinds:Ht,load:Us,prepare:async t=>(await In(t,re.current.decofile,void 0))?.rule??null,ensureBlock:async t=>{const n=Pl(re.current.decofile,t);return n.kind==="saved"?!0:n.kind==="conflict"?!1:(await Os.apply({writes:{[Bl(t).blockKey]:n.block}})).ok}}:null,br=async t=>{St();const{activePageKey:n,decofile:s,variantIndex:o}=re.current;if(!n)return;const a=await In(t,s,f=>{const j=s[n],h=j?.sections;if(!h||typeof h!="object"||Array.isArray(h))return null;const R=h;if(!Array.isArray(R.variants))return null;const E=[...R.variants],K=E[o];return K?(E[o]={...K,rule:f},{blockKey:n,data:{...j,sections:{...R,variants:E}}}):null});if(!a)return;const{resolveType:i,formValue:l}=Ut(a.rule,a.projected,u??void 0);ee(i),se(l),k?.()},xr=async t=>{St();const{activePageKey:n,decofile:s,variantIndex:o}=re.current;if(!n)return;const a=s[n],i=a?.sections;if(!i||typeof i!="object"||Array.isArray(i))return;const l=i;if(!Array.isArray(l.variants))return;const f=[...l.variants],j=f[o];if(!j)return;const h=Mt(j.rule,s,u),R=cn(t);f[o]={...j,rule:R};const E={...s,[n]:{...a,sections:{...l,variants:f}}},{resolveType:K,formValue:z}=Ut(R,E,u??void 0);ee(K),se(z);try{await L.mutateAsync({blockKey:n,data:E[n]}),h&&h!==t&&await qt(h,E),k?.()}catch(ne){H.error(c("sectionsEditor.sectionsEditor.couldNotApplySavedRule"),{description:Kt(c,Dt(ne))})}},_r=t=>{vt.current&&clearTimeout(vt.current);const{selectedSectionIndex:n,sectionVariantIndex:s}=re.current;n!==null&&(vt.current=setTimeout(()=>{const{rawSections:o,parsedSections:a,decofile:i,activePageKey:l,pageVariants:f,variantIndex:j}=re.current;if(!l)return;const h=o[n],R=a[n];if(!h||!R?.isMultivariate)return;const E=pt(h,R);if(!E)return;const z=(E.variants??[])[s]?.rule;if(Jt(z,i,u)){const Q=z?.__resolveType??"",be=i[Q],Ie=typeof be?.name=="string"?be.name:Q,{__resolveType:he,...ue}=t;L.mutate({blockKey:Q,data:Ft(he??"",ue,Ie)},{onSuccess:()=>k?.(),onError:L.reportError});return}const ne=_s(E,s,t),J=[...o];J[n]=Bt(h,R,ne);const Ne=ln(i,l,J,j,f);L.mutate({blockKey:l,data:Ne},{onSuccess:()=>k?.(),onError:L.reportError})},xn(v)))},Aa=t=>{qe(t);const n=t?No(t,u):{__resolveType:Zr(u)};Fe(t?n:{}),_r(n)},Na=t=>{const n=t;Fe(n);const s=Yt?{__resolveType:Yt,...n}:{...n};_r(s)},Ca=async t=>{St();const{selectedSectionIndex:n,sectionVariantIndex:s,rawSections:o,parsedSections:a,decofile:i,activePageKey:l,pageVariants:f,variantIndex:j}=re.current;if(n===null||!l)return;const h=await In(t,i,K=>{const z=o[n],ne=a[n];if(!z||!ne?.isMultivariate)return null;const J=pt(z,ne);if(!J)return null;const Ne=[...o];return Ne[n]=Bt(z,ne,_s(J,s,K)),{blockKey:l,data:ln(i,l,Ne,j,f)}});if(!h)return;const{resolveType:R,formValue:E}=Ut(h.rule,h.projected,u??void 0);qe(R),Fe(E),k?.()},Pa=async t=>{St();const{selectedSectionIndex:n,sectionVariantIndex:s,rawSections:o,parsedSections:a,decofile:i,activePageKey:l,pageVariants:f,variantIndex:j}=re.current;if(n===null||!l)return;const h=o[n],R=a[n];if(!h||!R?.isMultivariate)return;const E=pt(h,R);if(!E)return;const K=E.variants??[],z=Mt(K[s]?.rule,i,u),ne=cn(t),J=_s(E,s,ne),Ne=[...o];Ne[n]=Bt(h,R,J);const Q=ln(i,l,Ne,j,f),be={...i,[l]:Q},{resolveType:Ie,formValue:he}=Ut(ne,be,u??void 0);qe(Ie),Fe(he);try{await L.mutateAsync({blockKey:l,data:Q}),z&&z!==t&&await qt(z,be),k?.()}catch(ue){H.error(c("sectionsEditor.sectionsEditor.couldNotApplySavedRule"),{description:Kt(c,Dt(ue))})}};if(!q&&!oe)return r.jsx("div",{className:"h-full w-full flex items-center justify-center text-sm text-muted-foreground",children:c("sectionsEditor.sectionsEditor.noPageFound",{currentPath:V})});if(q&&!rs)return r.jsx("div",{className:"h-full w-full flex items-center justify-center text-sm text-muted-foreground",children:c("sectionsEditor.sectionsEditor.globalBlockNotFound")});const je=m!==null?ce[m]??null:null,kr=m!==null?B[m]:null,wr=kr&&je?.isMultivariate?pt(kr,je):null,Vt=wr?Xr(wr,we,v):[],Ln=Math.min(Me,Math.max(Vt.length-1,0)),kt=Vt[Ln]??null,Tt=je?.isMultivariate===!0,ps=m!==null&&je!==null,At=ps&&(Tt||!!(Fn&&Ze)),Ba=At&&!q&&je?.isSavedBlock===!0,ft=q||Ba,Rr=q?Js:je?.label??"",Ka=Yt&&u?qn(Yt,u):null,jr=(t,n)=>n&&Z?`${t} ยท ${n}`:t,Er=je?je.variantOf??je.label:"",Da=(()=>{const t=Tt&&kt?kt.label:null;return t?Z?[jr(Er,t)]:[je.label,t]:[je?.label??""]})(),hs=jr(oe?.name??"",yt?Se?.label:null),On=At&&(!q||D.length>0)?q?[Js,...D]:[hs,...Da,...D]:[],Vr=Re&&oe?[oe.name,"SEO",...Ds]:[],Tr=c("sectionsEditor.pageVariantTabs.variantsLabel"),Ar=Qt&&oe?[oe.name,Tr]:Lt&&oe&&je?[hs,Er,Tr]:[],zn=Ar.length>0?Ar:Vr.length>0?Vr:ft?On.length>0?On:[Rr]:On.length>0?On:[hs],Nr=ps&&!Tt&&!je?.isHidden&&!!y,Ma=ft||!q&&yt&&!!Se||Nr,Fa=ps&&!Tt&&!q&&D.length===0&&!!je&&Mo(je)&&!!y,Ia=Z&&At&&!Lt&&Tt&&D.length===0&&!!kt,Cr=Z&&D.length>0?uo(D[D.length-1]):null,La=D.length>1?uo(D[D.length-2]):null,Pr=ft?Rr:At?je?.label??"":oe?.name??"",Oa=Qt||Lt?c("sectionsEditor.pageVariantTabs.variantsLabel"):Re?c("sectionsEditor.panelSections.seo"):Cr??Pr,Br=Lt?je?.variantOf??je?.label??"":Qt||Re?oe?.name??"":Cr?La??Pr:ft?c("sectionsEditor.sectionsEditor.globalSectionSubtitle"):At?oe?.name??"":oe?.path??"",gs=!Qt&&!Lt&&!Re&&!At&&!ft,za=!Z&&!Re&&!q&&Tt&&D.length===0,bn=()=>{if(!y)return;St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const t=d[y],n=yc(t.sections,B,u,v);if(!n)return;const{sections:s,newVariantIndex:o}=n;L.mutate({blockKey:y,data:{...t,sections:s}},{onSuccess:()=>{fe(o),I(null),A(null),W(null),T([]),se(null),ee(null)},onError:L.reportError})},$n=(t,n,s)=>{if(!y)return;St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const o=d[y],a=o.sections;if(!a||typeof a!="object"||Array.isArray(a))return;const i=a;if(!Array.isArray(i.variants))return;const l=t([...i.variants]);if(!l)return;const f=Sc(i,l),j={...d,[y]:{...o,sections:f}};L.mutate({blockKey:y,data:j[y]},{onSuccess:()=>{n?.();const h=typeof s=="string"?[s]:s??[];(async()=>{for(const R of h)await qt(R,j)})()},onError:L.reportError})},Kr=(t,n)=>{if(t===n)return;let s=te;te===t?s=n:t<te&&n>=te?s=te-1:t>te&&n<=te&&(s=te+1),fe(s);const o=Xn(pe.map(a=>({rule:a.rule})),t,n);is(o,s),$n(a=>Xn(a,t,n))},Dr=t=>{const n=pe[t]?.rule,s=Mt(n,d??{},u??void 0);$n(o=>o.length<=1?null:(o.splice(t,1),o),()=>{pe.length-1===1?fe(0):t<te?fe(te-1):t===te&&fe(Math.max(0,t-1)),I(null),A(null),W(null),T([]),se(null),ee(null)},s)},$a=()=>{const t=pe.map((n,s)=>({variant:n,index:s})).filter(({variant:n})=>!Ri(n.rule)).map(({variant:n})=>Mt(n.rule,d??{},u??void 0)).filter(n=>!!n);$n(n=>{const s=zi({variants:n}),o=n[s];return o?[{...o,rule:$i(u)}]:null},()=>{fe(0),I(null),A(null),W(null),T([]),se(null),ee(null),Vn(!1)},t)},Mr=t=>{let n=t+1;$n(s=>(n=eo(s,t,v),xc(s,t,v)),()=>{fe(n),I(null),A(null),W(null),T([]),se(null),ee(null)})},Wa=async(t,n)=>{St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const s=re.current.activePageKey,o=re.current.decofile;if(!s)return;const a=o[s],i=a.sections;if(!i||typeof i!="object"||Array.isArray(i))return;const l=i;if(!Array.isArray(l.variants))return;const f=[...l.variants],j=f[t];if(!j?.rule||typeof j.rule!="object"){H.error(c("sectionsEditor.sectionsEditor.variantHasNoMatcherRule"));return}const h=j.rule,R=n.trim();en(!0);try{if(!R){if(!Jt(h,o,u)){M(null);return}const Q=h.__resolveType??"";f[t]={...j,rule:Ts(h,o,u)};const be={...o,[s]:{...a,sections:{...l,variants:f}}};await L.mutateAsync({blockKey:s,data:be[s]}),await qt(Q,be),M(null),k?.();return}const E=As(h,o,u);if(!E){H.error(c("sectionsEditor.sectionsEditor.couldNotReadVariantMatcherRule"));return}if(E.blockKey){await L.mutateAsync({blockKey:E.blockKey,data:Ft(E.resolveType,E.data,R)}),M(null),k?.();return}const K=Jn(R),z=Qn(K,o,u);if(z){H.error(z);return}const ne=Ft(E.resolveType,E.data,R);let J=null,Ne=!1;try{const Q=await L.mutateAsync({blockKey:K,data:ne,create:!0});Ne=Un(Q),J=Ne?null:K,f[t]={...j,rule:cn(K)},await L.mutateAsync({blockKey:s,data:{...a,sections:{...l,variants:f}}}),J=null}catch(Q){throw J&&await Pn.mutateAsync({blockKey:J}).catch(()=>{}),Q}M(null),Ne||H.success(c("sectionsEditor.sectionsEditor.savedMatcherAsGlobalBlock",{trimmed:R})),k?.()}catch(E){H.error(c("sectionsEditor.sectionsEditor.failedToRenameVariant"),{description:Kt(c,Dt(E))})}finally{en(!1)}},Ha=async(t,n)=>{St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const{selectedSectionIndex:s,rawSections:o,parsedSections:a,decofile:i,activePageKey:l,pageVariants:f,variantIndex:j}=re.current;if(s===null||!l)return;const h=o[s],R=a[s];if(!h||!R?.isMultivariate)return;const E=pt(h,R);if(!E)return;const K=E.variants??[],z=K[t];if(!z?.rule||typeof z.rule!="object"){H.error(c("sectionsEditor.sectionsEditor.variantHasNoMatcherRule"));return}const ne=z.rule,J=n.trim();en(!0);const Ne=async Q=>{const be={...E,variants:Q},Ie=[...o];Ie[s]=Bt(h,R,be);const he=ln(i,l,Ie,j,f);return await L.mutateAsync({blockKey:l,data:he}),{...i,[l]:he}};try{if(!J){if(!Jt(ne,i,u)){O(null);return}const Ye=ne.__resolveType??"",Nt=[...K];Nt[t]={...z,rule:Ts(ne,i,u)};const Ct=await Ne(Nt);await qt(Ye,Ct),O(null),k?.();return}const Q=As(ne,i,u);if(!Q){H.error(c("sectionsEditor.sectionsEditor.couldNotReadVariantMatcherRule"));return}if(Q.blockKey){await L.mutateAsync({blockKey:Q.blockKey,data:Ft(Q.resolveType,Q.data,J)}),O(null),k?.();return}const be=Jn(J),Ie=Qn(be,i,u);if(Ie){H.error(Ie);return}const he=Ft(Q.resolveType,Q.data,J);let ue=null,Ge=!1;try{const Ye=await L.mutateAsync({blockKey:be,data:he,create:!0});Ge=Un(Ye),ue=Ge?null:be;const Nt=[...K];Nt[t]={...z,rule:cn(be)},await Ne(Nt),ue=null}catch(Ye){throw ue&&await Pn.mutateAsync({blockKey:ue}).catch(()=>{}),Ye}O(null),Ge||H.success(c("sectionsEditor.sectionsEditor.savedMatcherAsGlobalBlock",{trimmed:J})),k?.()}catch(Q){H.error(c("sectionsEditor.sectionsEditor.failedToRenameVariant"),{description:Kt(c,Dt(Q))})}finally{en(!1)}},Fr=async(t,n,s)=>{A(s);try{await L.mutateAsync({blockKey:t,data:s})}catch(o){throw A(a=>a===s?n:a),o}},qa={rename:async(t,n,s)=>{St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const{activePageKey:o,decofile:a}=re.current;if(!o)return;const i=Array.isArray(t.variants)?[...t.variants]:[],l=i[n],f=l?.rule&&typeof l.rule=="object"?l.rule:void 0,j=async R=>{const E={...t,variants:R};return await Fr(o,t,E),{...a,[o]:E}},h=Mc(f,s,a,u);if(h.kind!=="noop"){if(h.kind==="error"){H.error(h.reason==="no-matcher-rule"?c("sectionsEditor.sectionsEditor.variantHasNoMatcherRule"):h.reason==="unreadable-rule"?c("sectionsEditor.sectionsEditor.couldNotReadVariantMatcherRule"):h.message??c("sectionsEditor.sectionsEditor.failedToRenameVariant"));return}en(!0);try{if(h.kind==="inline"){const K=[...i];K[n]={...l,rule:h.inlinedRule};const z=await j(K);await qt(h.blockKey,z),k?.();return}if(h.kind==="updateBlock"){await L.mutateAsync({blockKey:h.blockKey,data:h.blockData}),k?.();return}let R=null,E=!1;try{const K=await L.mutateAsync({blockKey:h.blockId,data:h.blockData,create:!0});E=Un(K),R=E?null:h.blockId;const z=[...i];z[n]={...l,rule:h.reference},await j(z),R=null}catch(K){throw R&&await Pn.mutateAsync({blockKey:R}).catch(()=>{}),K}E||H.success(c("sectionsEditor.sectionsEditor.savedMatcherAsGlobalBlock",{trimmed:s.trim()})),k?.()}catch(R){H.error(c("sectionsEditor.sectionsEditor.failedToRenameVariant"),{description:Kt(c,Dt(R))})}finally{en(!1)}}},selectGlobal:async(t,n,s)=>{St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const{activePageKey:o,decofile:a}=re.current;if(!o)return;const i=Array.isArray(t.variants)?[...t.variants]:[],l=i[n];if(!l)return;const f=Mt(l.rule,a,u);i[n]={...l,rule:cn(s)};const j={...t,variants:i},h={...a,[o]:j};try{await Fr(o,t,j),f&&f!==s&&await qt(f,h),k?.()}catch(R){H.error(c("sectionsEditor.sectionsEditor.couldNotApplySavedRule"),{description:Kt(c,Dt(R))})}},selectNamedRule:async(t,n,s)=>{St(),N.current&&(clearTimeout(N.current),N.current=null),ye.current.clear();const{activePageKey:o,decofile:a}=re.current;if(!o)return;let i=null;!await In(s,a,f=>{const j=Array.isArray(t.variants)?[...t.variants]:[],h=j[n];return h?(j[n]={...h,rule:f},i={...t,variants:j},{blockKey:o,data:i}):null})||!i||(A(i),k?.())}},Ir=()=>{Wt(),v&&$t(null,-1,0)},Lr=t=>{dn(t),ds({inner:t})},Or=t=>{An(t),ds({raw:t})},zr=()=>{dn(null),Ot([])},$r=()=>Xt(t=>t+1),Wr=()=>{fn.flush(),un(!1),dn(null),An(void 0),Ot([]),Xt(t=>t+1),ge?.()},Ga=()=>{Vn(!1),Tn(!1),I(null),un(!0)},Ua=()=>{Re&&Wr(),I(null),Vn(!0)},Ja=()=>Tn(!0),vs=t=>{if(Qt&&t===0){Vn(!1);return}if(Lt&&t<2){Tn(!1),t===0&&I(null);return}if(Re){if(t===0){Wr();return}if(t===1){Ot([]),Xt(s=>s+1);return}Ot(Ds.slice(0,t-1)),Xt(s=>s+1);return}if(q){T(D.slice(0,t)),$(s=>s+1);return}if(t===0){Ir();return}if(t===1){T([]),$(s=>s+1);return}const n=!Z&&Tt&&kt?1:0;if(n===1&&t===2){T([]),$(s=>s+1);return}T(D.slice(0,t-1-n))},ys=zn.length>1?r.jsx("button",{type:"button",onClick:()=>vs(vl(zn.length,{isMultivariateSectionTop:za})),title:c("sectionsEditor.sectionsEditor.back"),"aria-label":c("sectionsEditor.sectionsEditor.back"),className:le("shrink-0 inline-flex size-6 items-center justify-center rounded-[var(--studio-control-radius,var(--radius-md))] transition-colors",ft?"text-foreground/80 hover:bg-global-section/15":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:r.jsx(Ji,{className:"size-4"})}):null,Qa=ft||At||Re?Ma&&r.jsxs("div",{className:le("border-b px-3 py-2.5",ft&&"border-global-section/22 bg-global-section/12 dark:bg-global-section/16"),children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",children:[!q&&yt&&Se&&r.jsxs("button",{type:"button",onClick:Ir,title:c("sectionsEditor.sectionsEditor.editingInVariant",{variant:Se.label}),className:le("shrink-0 inline-flex items-center gap-1 rounded-lg h-6 px-1.5 text-xs font-medium cursor-pointer transition-opacity hover:opacity-80",dl),children:[r.jsx(ul,{rule:Rs(Se.rule,d??{},u??void 0),matchers:sn}),r.jsx("span",{className:"max-w-[160px] truncate",children:Se.label})]}),r.jsx("div",{className:"flex-1"}),ft&&r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx("span",{className:"shrink-0 cursor-help",children:r.jsx(Yn,{className:"size-4 text-global-section-fg dark:text-global-section-fg-dark"})})}),r.jsx(Et,{side:"bottom",className:"max-w-[260px]",children:c("sectionsEditor.sectionsEditor.globalSectionTooltip")})]}),Nr&&r.jsx(Gn,{onClick:()=>Sn()})]}),ft&&r.jsx("p",{className:"mt-1.5 py-1.5 pl-1 text-sm leading-snug text-foreground",children:c("sectionsEditor.sectionsEditor.globalSectionBanner")})]}):r.jsxs("div",{className:"flex items-center gap-2 border-b px-3 py-2.5",children:[r.jsx("div",{className:"flex-1 min-w-0",children:r.jsx(fo,{pageKey:y,initialName:oe.name,initialPath:oe.path,onFieldChange:cr,variant:"header"})}),r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx(It,{type:"button",variant:"ghost",size:"icon-sm","aria-label":c("sectionsEditor.sectionsEditor.editSeo"),className:"shrink-0",onClick:()=>un(!0),children:r.jsx(lo,{size:14})})}),r.jsx(Et,{side:"bottom",children:c("sectionsEditor.sectionsEditor.editSeo")})]}),r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx(It,{type:"button",variant:"ghost",size:"icon-sm","aria-label":c("sectionsEditor.sectionsEditor.viewJson"),className:"shrink-0",onClick:()=>Le&&y?Le():bt(!0),children:r.jsx(co,{size:14})})}),r.jsx(Et,{side:"bottom",children:c("sectionsEditor.sectionsEditor.viewJson")})]}),r.jsx(Gn,{onClick:bn})]}),Xa=r.jsxs(r.Fragment,{children:[yt&&y&&r.jsx(mo,{listKey:y,variants:pe,activeIndex:te,decofile:d??{},meta:u,matchers:sn,onSelect:cs,onReorder:Kr,onRename:M,onDuplicate:Mr,onDelete:Dr,onAdd:bn}),yt&&X!==null&&r.jsx(po,{className:"mt-3",children:r.jsx("div",{className:le("space-y-3",Zt&&"pointer-events-none opacity-50"),children:r.jsx(ks,{currentRt:X,currentLabel:_n(Se?.rule,d??{},we,u??void 0),currentGlobalKey:Mt(Se?.rule,d??{},u??void 0)??void 0,matchers:sn,globals:fs,onSelect:vr,onSelectGlobal:xr,named:ms(Se?.rule,br),namedRow:ws(Se?.rule,Ht),rule:Se?.rule,schema:hr,formValue:Ke,onChange:yr,formKey:`${te}:${X??""}`,formWrapperClassName:"space-y-3",meta:u??void 0,decofile:d,onSaveReferencedBlock:mn,sandbox:gn})})})]}),Hr=r.jsxs(r.Fragment,{children:[r.jsx(fl,{listKey:`${y??""}:${m??""}`,variants:Vt.map((t,n)=>({index:n,label:t.label})),selectedIndex:Ln,onSelect:dr,onRename:O,onDuplicate:Ea,onDelete:ja,onRemoveAll:fr,onReorder:Va,onAdd:()=>Sn()}),r.jsx(po,{children:r.jsx(ks,{currentRt:Yt??"",currentLabel:_n(kt?.rule,d??{},we,u??void 0),currentGlobalKey:Mt(kt?.rule,d??{},u??void 0)??void 0,matchers:sn,globals:fs,onSelect:Aa,onSelectGlobal:Pa,named:ms(kt?.rule,Ca),namedRow:ws(kt?.rule,Ht),rule:kt?.rule,schema:Ka,formValue:qo,onChange:Na,formKey:`${m??"none"}:${Ln}:${Yt??""}`,formWrapperClassName:"pt-1",meta:u??void 0,decofile:d,onSaveReferencedBlock:mn,sandbox:gn})})]}),qr=r.jsx("div",{className:le(Z?"px-2":"p-2 pt-3"),children:r.jsx(Kc,{listKey:`${y??""}-${te}`,rawSections:B,sections:ce,meta:u,decofile:d,selectedIndex:m,onSelect:t=>{va(t),Je?.(t)},onReorder:ya,onDelete:Sa,onDuplicate:ba,onMakeReusable:Ve,onToggleHidden:xa,onToggleLazy:rt?_a:void 0,onAddVariant:Sn,onDetach:ka,onAddSection:()=>He(!0),canAddSection:pr})}),Ya=r.jsxs("div",{className:"min-w-0 max-w-full space-y-4 overflow-x-hidden px-3",children:[y&&oe&&r.jsx(fo,{pageKey:y,initialName:oe.name,initialPath:oe.path,onFieldChange:cr}),nn&&y?r.jsx(To,{rawSeo:Kn,innerSeo:as,defaultResolveType:Xs,seoTypesLoading:v&&!u,seoSchema:Ys,activeResolveType:Dn,seoTypeOptions:Qs,formResetKey:Ms,siteDefaultSeo:Zs,onBreadcrumbChange:Ot,onPersistRaw:Or,onInnerChange:Lr,onClearForm:zr,onBumpFormKey:$r,asyncRenderAvailable:rt}):r.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:c("sectionsEditor.sectionsEditor.seoSchemaNotFound")})]}),Za=r.jsx(an,{className:"flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",children:r.jsx("div",{className:"min-w-0 max-w-full overflow-x-hidden px-6 py-4",children:r.jsx("div",{className:"mx-auto max-w-2xl",children:nn&&y?r.jsx(To,{rawSeo:Kn,innerSeo:as,defaultResolveType:Xs,seoTypesLoading:v&&!u,seoSchema:Ys,activeResolveType:Dn,seoTypeOptions:Qs,formResetKey:Ms,siteDefaultSeo:Zs,onBreadcrumbChange:Ot,onPersistRaw:Or,onInnerChange:Lr,onClearForm:zr,onBumpFormKey:$r,asyncRenderAvailable:rt}):r.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:c("sectionsEditor.sectionsEditor.seoSchemaNotFound")})})})},"editor-seo"),ei=r.jsxs(an,{className:"flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",children:[yt&&y&&r.jsx(mo,{listKey:y,variants:pe,activeIndex:te,decofile:d??{},meta:u,matchers:sn,onSelect:cs,onReorder:Kr,onRename:M,onDuplicate:Mr,onDelete:Dr,onAdd:bn}),yt&&X!==null&&r.jsxs("div",{className:le("px-3 border-b",En?"pt-3 pb-5 space-y-3":"py-2"),children:[r.jsxs("button",{type:"button",onClick:()=>Wo(t=>!t),className:"flex w-full items-center justify-between gap-2 text-left cursor-pointer rounded-[var(--studio-control-radius,var(--radius-sm))] py-0.5 hover:bg-accent","aria-expanded":En,children:[r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:c("sectionsEditor.sectionsEditor.variantRule")}),En?r.jsx(Qi,{className:"size-3.5 shrink-0 text-muted-foreground"}):r.jsx(Ui,{className:"size-3.5 shrink-0 text-muted-foreground"})]}),En&&r.jsx("div",{className:le("space-y-3",Zt&&"pointer-events-none opacity-50"),children:r.jsx(ks,{currentRt:X,currentLabel:_n(Se?.rule,d??{},we,u??void 0),currentGlobalKey:Mt(Se?.rule,d??{},u??void 0)??void 0,matchers:sn,globals:fs,onSelect:vr,onSelectGlobal:xr,named:ms(Se?.rule,br),namedRow:ws(Se?.rule,Ht),rule:Se?.rule,schema:hr,formValue:Ke,onChange:yr,formKey:`${te}:${X??""}`,formWrapperClassName:"space-y-3",meta:u??void 0,decofile:d,onSaveReferencedBlock:mn,sandbox:gn})})]}),qr]},"editor-section-list");return r.jsx(lc,{value:v,children:r.jsx(ml,{children:r.jsxs("div",{className:"flex h-full min-w-0 w-full flex-col",children:[!Z&&ys&&r.jsx("div",{className:"flex min-w-0 shrink-0 items-center gap-2 px-3 py-2",children:ys}),(Z||zn.length>1)&&r.jsx(Hi,{crumbs:zn,onSelect:vs,onSelectRoot:()=>{fn.flush(),Ue?Ue():vs(0)}}),r.jsx("div",{className:"shrink-0",children:Z?r.jsxs("div",{className:le("flex items-center gap-2 border-b px-3 py-2.5",ft&&"border-global-section/22 bg-global-section/12 dark:bg-global-section/16"),children:[Z&&ys,ft&&r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx("span",{className:"shrink-0 cursor-help",children:r.jsx(Yn,{className:"size-4 text-global-section-fg dark:text-global-section-fg-dark"})})}),r.jsx(Et,{side:"bottom",className:"max-w-[260px]",children:c("sectionsEditor.sectionsEditor.globalSectionTooltip")})]}),r.jsxs("div",{className:"flex min-w-0 flex-1 flex-col leading-tight",children:[r.jsx("span",{className:"truncate text-sm font-semibold",children:Oa}),Br&&r.jsx("span",{className:"truncate text-xs text-muted-foreground",children:Br})]}),gs&&yt&&Se&&r.jsx(ho,{variants:pe,activeIndex:te,onSelect:cs,onManage:Ua,onRemoveAll:$a}),Ia&&r.jsx(ho,{variants:Vt,activeIndex:Ln,onSelect:dr,onManage:Ja,onRemoveAll:fr}),gs&&!yt&&r.jsx(Gn,{onClick:bn}),Fa&&r.jsx(Gn,{onClick:()=>Sn()}),r.jsx(pl,{}),gs&&r.jsxs(r.Fragment,{children:[r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx(It,{type:"button",variant:"outline",size:"icon-sm","aria-label":c("sectionsEditor.sectionsEditor.editSeo"),className:"shrink-0",onClick:Ga,children:r.jsx(lo,{size:14})})}),r.jsx(Et,{side:"bottom",children:c("sectionsEditor.sectionsEditor.editSeo")})]}),!Le&&r.jsxs(Rt,{children:[r.jsx(jt,{asChild:!0,children:r.jsx(It,{type:"button",variant:"outline",size:"icon-sm","aria-label":c("sectionsEditor.sectionsEditor.viewJson"),className:"shrink-0",onClick:()=>bt(!0),children:r.jsx(co,{size:14})})}),r.jsx(Et,{side:"bottom",children:c("sectionsEditor.sectionsEditor.viewJson")})]})]})]}):Qa}),ut&&r.jsx(pi,{open:!0,fields:hi(ut.plan,ut.target.schema),choices:ut.choices,changedAgain:ut.changedAgain,author:Hs??null,authorPending:Hs===void 0,fieldsAsLabeled:Ws!==null,fresh:ut.fresh,keepTyping:v,onChoose:(t,n)=>ga({...ut.choices,[t]:n}),onApply:ha},Lc(ut.formBase)),Lt?r.jsx(go,{onAdd:()=>Sn(),children:Hr},"editor-section-variants"):At?r.jsxs(an,{viewportRef:me,onBlur:sr,className:"flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",children:[!Z&&Tt&&Vt.length>0&&D.length===0&&Hr,r.jsx(Ao,{value:Sr,children:r.jsx(vo,{value:q&&v?Be:null,children:r.jsx(yo,{activeSchema:Fn,formValue:Ze,formResetKey:De,onFormChange:lr,onBreadcrumbChange:T,breadcrumbPath:D,emptyMessage:c("sectionsEditor.sectionsEditor.noEditableFieldsForVariant"),meta:u,decofile:d,onSaveReferencedBlock:mn,sandbox:gn,previewBaseUrl:st,onRequestAddSection:ur,onVariantMatcherOp:q?qa:void 0})})})]},"editor-section-form"):q?r.jsx(an,{viewportRef:me,onBlur:sr,className:"flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",children:r.jsx(Ao,{value:Sr,children:r.jsx(vo,{value:q&&v?Be:null,children:r.jsx(yo,{activeSchema:Fn,formValue:Ze,formResetKey:De,onFormChange:lr,onBreadcrumbChange:T,breadcrumbPath:D,emptyMessage:c("sectionsEditor.sectionsEditor.noEditableFieldsForGlobalBlock"),meta:u,decofile:d,onSaveReferencedBlock:mn,sandbox:gn,previewBaseUrl:st,onRequestAddSection:ur})})})},"editor-global-block"):Re?Z?r.jsx(an,{className:"flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",children:r.jsx("div",{className:"p-3",children:Ya})},"editor-seo"):Za:Qt?r.jsx(go,{onAdd:bn,children:Xa},"editor-variants"):Z?r.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[r.jsx(an,{className:"flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",children:r.jsx("div",{className:"py-2",children:qr})}),r.jsx("div",{className:"shrink-0 border-t p-2",children:r.jsx(Ns,{canAddSection:pr,onAddSection:()=>He(!0)})})]},"editor-section-list"):ei,r.jsx(hl,{open:ie!==null,onOpenChange:t=>{t||Ve(null)},defaultBlockId:ie!==null?Jn(ce[ie]?.label??""):"",isPending:L.isPending,onSubmit:Ta}),ot&&r.jsx(tc,{open:Ae,onOpenChange:t=>{He(t),t||(jn.current=null)},meta:u,decofile:d,previewBaseUrl:st,onSelect:Ra}),ht&&y&&d&&r.jsx(sc,{open:ht,onOpenChange:bt,pageKey:y,decofile:d}),Te!==null&&r.jsx(So,{open:!0,initialName:Jt(pe[Te]?.rule,d??{},u??void 0)?_n(pe[Te]?.rule,d??{},we,u??void 0):"",autoLabel:we(Rs(pe[Te]?.rule,d??{},u??void 0)),isPending:Zt,onSubmit:async t=>{await Wa(Te,t)},onOpenChange:t=>{!t&&!Zt&&M(null)}}),tt!==null&&r.jsx(So,{open:!0,initialName:Jt(Vt[tt]?.rule,d??{},u??void 0)?_n(Vt[tt]?.rule,d??{},we,u??void 0):"",autoLabel:we(Rs(Vt[tt]?.rule,d??{},u??void 0)),isPending:Zt,onSubmit:async t=>{await Ha(tt,t)},onOpenChange:t=>{!t&&!Zt&&O(null)}})]})})})}export{Wf as SectionsEditor};