var RM=Object.defineProperty;var e5=(un,i,u)=>i in un?RM(un,i,{enumerable:!0,configurable:!0,writable:!0,value:u}):un[i]=u;var Bi=(un,i,u)=>e5(un,typeof i!="symbol"?i+"":i,u);(function(un,i,u,En){"use strict";function Lt(){const e=typeof window<"u"?window.G7Core?.__runtime:void 0;if(!e)throw new Error("[layout-editor] window.G7Core.__runtime 이 없습니다. 코어 번들(template-engine.min.js)이 편집기 번들보다 먼저 로드되어야 합니다.");return e}const Wi=Lt();Wi.TranslationProvider;const et=Wi.useTranslation;Wi.TranslationReactContext;function rt(){return typeof window>"u"?null:window.__g7Devtools??null}function zl(e,t){const n=rt();if(!n?.trackEditorState)return;const o={templateIdentifier:e.templateIdentifier,editMode:e.editMode,selectedRoutePath:e.selectedRoute?.path??null,selectedLayoutName:e.selectedRoute?.layoutName??null,routeTreeSize:e.routeTree.length,isRouteTreeCollapsed:e.isRouteTreeCollapsed,locale:e.locale,previewDevice:e.previewDevice,previewZoom:e.previewZoom,lastAction:t,timestamp:Date.now()};try{n.trackEditorState(o)}catch{}}function gy(){const e=rt();if(e?.clearEditorStateData)try{e.clearEditorStateData()}catch{}}function hy(e){const t=rt();if(t?.trackEditorSampleMatch)try{t.trackEditorSampleMatch(e)}catch{}}function yy(){const e=rt();if(e?.clearEditorSampleData)try{e.clearEditorSampleData()}catch{}}function by(e){const t=rt();if(t?.trackEditorHistoryEntry)try{t.trackEditorHistoryEntry(e)}catch{}}function my(){const e=rt();if(e?.clearEditorHistoryData)try{e.clearEditorHistoryData()}catch{}}function Nl(e){const t=rt();if(t?.trackEditorSelection)try{t.trackEditorSelection(e)}catch{}}function vy(){const e=rt();if(e?.clearEditorSelectionData)try{e.clearEditorSelectionData()}catch{}}function pr(e){const t=rt();if(t?.trackEditorPropertyPatch)try{t.trackEditorPropertyPatch(e)}catch{}}function pn(e){const t=rt();if(t?.trackEditorDnd)try{t.trackEditorDnd(e)}catch{}}function _y(){const e=rt();if(e?.clearEditorDndData)try{e.clearEditorDndData()}catch{}}function st(e){const t=rt();if(t?.trackEditorDocument)try{t.trackEditorDocument(e)}catch{}}function xy(){const e=rt();if(e?.clearEditorDocumentData)try{e.clearEditorDocumentData()}catch{}}function wy(e){const t=rt();if(t?.trackEditorSpecMerge)try{t.trackEditorSpecMerge(e)}catch{}}function ky(){const e=rt();if(e?.clearEditorSpecMergeData)try{e.clearEditorSpecMergeData()}catch{}}function ji(e){let t=5381;for(let n=0;n>>0;return t}function Et(e){const t=rt();if(t?.trackEditorI18n)try{t.trackEditorI18n(e)}catch{}}function Sy(){const e=rt();if(e?.clearEditorI18nData)try{e.clearEditorI18nData()}catch{}}function Ml(e){const t=rt();if(t?.trackPageState)try{t.trackPageState(e)}catch{}}function Cy(){const e=rt();if(e?.clearPageStateData)try{e.clearPageStateData()}catch{}}const Ll="g7le.routeTree.collapsed";function $y(){if(typeof window>"u")return!1;try{return window.localStorage?.getItem(Ll)==="1"}catch{return!1}}function Ey(e){if(!(typeof window>"u"))try{window.localStorage?.setItem(Ll,e?"1":"0")}catch{}}function Iy(e,t){return{templateIdentifier:e,routeTree:[],routesError:null,selectedRoute:null,isRouteTreeCollapsed:$y(),editMode:"route",returnRoute:null,returnEditMode:null,locale:t,previewDevice:"desktop",previewZoom:1,previewCustomWidth:1024,previewColorScheme:"light",history:{canUndo:!1,canRedo:!1},isPaletteOpen:!1,availableStates:[],activeStateId:null,layoutVersions:{},extensionVersions:{}}}function Ay(e,t){switch(t.type){case"SET_ROUTE_TREE":return{...e,routeTree:t.tree,routesError:null};case"SET_ROUTES_ERROR":return{...e,routesError:t.error};case"SELECT_ROUTE":return{...e,editMode:"route",selectedRoute:t.route,returnRoute:null,returnEditMode:null};case"TOGGLE_ROUTE_TREE":return{...e,isRouteTreeCollapsed:!e.isRouteTreeCollapsed};case"SET_LOCALE":return{...e,locale:t.locale};case"ENTER_BASE_EDIT":return{...e,editMode:"base",returnRoute:t.returnRoute!==void 0?t.returnRoute:e.selectedRoute,selectedRoute:{path:`__base__/${t.layoutName}`,layoutName:t.layoutName}};case"EXIT_BASE_EDIT":return{...e,editMode:"route",selectedRoute:e.returnRoute,returnRoute:null};case"ENTER_MODAL_EDIT":return{...e,editMode:"modal",returnRoute:t.returnRoute!==void 0?t.returnRoute:e.selectedRoute,selectedRoute:{path:`__modal__/${t.modalId}`,layoutName:t.hostLayout}};case"EXIT_MODAL_EDIT":return{...e,editMode:"route",selectedRoute:e.returnRoute,returnRoute:null};case"ENTER_EXTENSION_EDIT":return{...e,editMode:"extension",returnRoute:t.returnRoute!==void 0?t.returnRoute:e.selectedRoute,selectedRoute:{path:`__extension__/${t.extensionId}`,layoutName:t.extensionHost??null}};case"SET_RETURN_ROUTE":return e.editMode==="route"||e.returnRoute!==null?e:{...e,returnRoute:t.route};case"EXIT_EXTENSION_EDIT":return{...e,editMode:"route",selectedRoute:e.returnRoute,returnRoute:null};case"ENTER_ITERATION_ITEM_EDIT":return{...e,editMode:"iteration_item",returnRoute:t.returnRoute!==void 0?t.returnRoute:e.selectedRoute,returnEditMode:e.editMode,selectedRoute:{path:`__iteration__/${t.sourcePath}`,layoutName:t.hostLayout??e.selectedRoute?.layoutName??null}};case"EXIT_ITERATION_ITEM_EDIT":return{...e,editMode:e.returnEditMode??"route",selectedRoute:e.returnRoute,returnRoute:null,returnEditMode:null};case"SET_PREVIEW_DEVICE":return{...e,previewDevice:t.device};case"SET_PREVIEW_ZOOM":return{...e,previewZoom:t.zoom};case"SET_PREVIEW_CUSTOM_WIDTH":return{...e,previewCustomWidth:t.width};case"SET_PREVIEW_COLOR_SCHEME":return{...e,previewColorScheme:t.scheme};case"TOGGLE_PALETTE":return{...e,isPaletteOpen:!e.isPaletteOpen};case"SET_PALETTE_OPEN":return{...e,isPaletteOpen:t.open};case"SET_AVAILABLE_STATES":return{...e,availableStates:t.states,activeStateId:t.activeStateId};case"SET_ACTIVE_STATE":return{...e,activeStateId:t.activeStateId};case"SET_LAYOUT_VERSIONS":return{...e,layoutVersions:t.versions};case"SET_LAYOUT_VERSION":return{...e,layoutVersions:{...e.layoutVersions,[t.layoutName]:t.version}};case"SET_EXTENSION_VERSIONS":return{...e,extensionVersions:t.versions};case"SET_EXTENSION_VERSION":return{...e,extensionVersions:{...e.extensionVersions,[t.extensionId]:t.version}};default:return e}}function Ty(e,t){const n=Ay(e,t);return((n.selectedRoute?.path??null)!==(e.selectedRoute?.path??null)||n.editMode!==e.editMode)&&(n.availableStates.length>0||n.activeStateId!==null)?{...n,availableStates:[],activeStateId:null}:n}const Pl=u.createContext(null);function Dy(e,t){const n=Ty(e,t);return zl(n,t.type),n}function zy({templateIdentifier:e,initialLocale:t,children:n}){const[o,r]=u.useReducer(Dy,void 0,()=>{const a=Iy(e,t);return zl(a,void 0),a});u.useEffect(()=>{Ey(o.isRouteTreeCollapsed)},[o.isRouteTreeCollapsed]);const s=u.useMemo(()=>({state:o,dispatch:r}),[o]);return u.createElement(Pl.Provider,{value:s},n)}function Qe(){const e=u.useContext(Pl);if(!e)throw new Error("useLayoutEditor must be used within LayoutEditorProvider");return e}const Ol=u.createContext(null);function Ny({value:e,children:t}){return u.createElement(Ol.Provider,{value:e},t)}function Kt(){return u.useContext(Ol)}const Hi=u.createContext(null);let My=1;function Ly({children:e,t}){const[n,o]=u.useState([]),r=u.useRef([]),[s,a]=u.useState({}),l=u.useCallback(y=>{const _=y.id??`editor-modal-${My++}`,w={id:_,content:y.content,ariaLabel:y.ariaLabel??"",closeOnBackdrop:y.closeOnBackdrop??!0,closeOnEscape:y.closeOnEscape??!0,width:y.width??"auto",height:y.height??"auto",maxHeightRatio:y.maxHeightRatio??.85,draggable:y.draggable??!1,avoidRect:y.avoidRect,onClose:y.onClose};return o(k=>{const $=[...k.filter(C=>C.id!==_),w];return r.current=$,$}),_},[]),d=u.useCallback(y=>{o(_=>{const w=_.find(x=>x.id===y),k=_.filter(x=>x.id!==y);return r.current=k,w?.onClose&&queueMicrotask(()=>w.onClose?.()),k})},[]),c=u.useCallback(()=>{const y=r.current[r.current.length-1];y&&d(y.id)},[d]),p=u.useCallback(()=>{o(y=>{for(let _=y.length-1;_>=0;_--){const w=y[_];w?.onClose&&queueMicrotask(()=>w.onClose?.())}return r.current=[],[]})},[]),f=u.useCallback((y,_)=>{a(w=>{const k=r.current.find($=>$.id===y),x=_??k?.ariaLabel??"";return{...w,[y]:x}})},[]),b=u.useCallback(y=>{a(_=>{if(!(y in _))return _;const w={..._};return delete w[y],w})},[]),g=u.useCallback(y=>{b(y),d(y)},[b,d]),m=u.useCallback(()=>{a({}),p()},[p]),h=u.useMemo(()=>Object.keys(s),[s]),v=u.useMemo(()=>({open:l,close:g,closeTop:c,closeAll:m,stack:n,minimize:f,restore:b,minimizedStack:h}),[l,g,c,m,n,f,b,h]);return u.createElement(Hi.Provider,{value:v},e,u.createElement(Oy,{minimized:s,onRestore:b,t,key:"__min_bar"}))}function vo(){const e=u.useContext(Hi);if(!e)throw new Error("useEditorModal must be used within EditorModalProvider");return e}function Py(){const e=u.useContext(Hi);if(!e)return null;const{stack:t,close:n,minimizedStack:o}=e,r=u.useMemo(()=>new Set(o),[o]);return u.useEffect(()=>{if(t.length===0)return;const s=a=>{if(a.key!=="Escape"&&a.key!=="Esc")return;const l=t.filter(c=>!r.has(c.id)),d=l[l.length-1];d?.closeOnEscape&&(a.preventDefault(),a.stopPropagation(),n(d.id))};return window.addEventListener("keydown",s,!0),()=>window.removeEventListener("keydown",s,!0)},[t,n,r]),t.length===0?null:i.jsx(i.Fragment,{children:t.map((s,a)=>i.jsx(Wy,{entry:s,depth:a,hidden:r.has(s.id),onClose:()=>n(s.id)},s.id))})}function Oy({minimized:e,onRestore:t,t:n}){const o=n??(s=>s),r=Object.keys(e);return r.length===0?null:i.jsx("div",{className:"g7le-minimized-bar","data-testid":"g7le-minimized-bar",style:{position:"fixed",left:16,bottom:16,display:"flex",gap:8,zIndex:9300},children:r.map(s=>i.jsxs("button",{type:"button","data-testid":`g7le-minimized-${s}`,onClick:()=>t(s),style:{display:"flex",alignItems:"center",gap:6,padding:"8px 12px",background:"#1e293b",color:"#fff",border:"none",borderRadius:8,boxShadow:"0 8px 24px rgba(15, 23, 42, 0.3)",cursor:"pointer",fontSize:13},children:[i.jsx("span",{"aria-hidden":"true",children:"🗗"}),i.jsx("span",{children:e[s]||o("layout_editor.modal.minimized_default")}),i.jsx("span",{style:{opacity:.7},children:o("layout_editor.modal.restore")})]},s))})}function By(e,t,n){if(!e||typeof window>"u")return null;const o=window.innerWidth,r=window.innerHeight,s=16,a=e.left,l=o-(e.left+e.width),d=t+s;let c;if(l>=a&&l>=d)c=e.left+e.width+s;else if(a>=d)c=Math.max(s,e.left-s-t);else return null;c=Math.min(Math.max(s,c),Math.max(s,o-t-s));let p=e.top;return p=Math.min(Math.max(s,p),Math.max(s,r-n-s)),{left:c,top:p}}const Bl="clamp(16px, 6vh, 56px)";function Wy({entry:e,depth:t,hidden:n,onClose:o}){const r=9100+t*10,s=e.maxHeightRatio>0?`${e.maxHeightRatio*100}vh`:void 0,a=e.draggable?s:`calc(100vh - (${Bl}) * 2)`,[l,d]=u.useState(null),c=u.useRef(null),p=u.useRef(null);u.useEffect(()=>{if(!e.draggable)return;const v=c.current;if(!v)return;const y=v.getBoundingClientRect(),_=By(e.avoidRect,y.width,y.height);_&&d(_)},[e.id,e.draggable]);const f=u.useCallback(v=>{if(!e.draggable)return;const y=v.target;if(!y.closest("[data-modal-drag-handle]")||y.closest("button, a, input, textarea, select"))return;const w=c.current,k=w?.getBoundingClientRect(),x=l?.left??k?.left??0,$=l?.top??k?.top??0;p.current={startX:v.clientX,startY:v.clientY,baseLeft:x,baseTop:$};const C=D=>{const E=p.current;if(!E)return;const I=window.innerWidth,N=window.innerHeight,T=w?.offsetWidth??0,B=w?.offsetHeight??0;let M=E.baseLeft+(D.clientX-E.startX),O=E.baseTop+(D.clientY-E.startY);M=Math.min(Math.max(0,M),Math.max(0,I-T)),O=Math.min(Math.max(0,O),Math.max(0,N-B)),d({left:M,top:O})},S=()=>{p.current=null,window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",S)};window.addEventListener("pointermove",C),window.addEventListener("pointerup",S)},[e.draggable,l]),b=v=>{e.closeOnBackdrop&&v.target===v.currentTarget&&o()},g=e.draggable&&l!==null,m=e.draggable?{position:"fixed",inset:0,background:"transparent",pointerEvents:"none",zIndex:r,...n?{display:"none"}:{}}:{position:"fixed",inset:0,background:"rgba(15, 23, 42, 0.45)",display:n?"none":"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:Bl,boxSizing:"border-box",zIndex:r},h={background:"#fff",borderRadius:10,boxShadow:"0 20px 60px rgba(15, 23, 42, 0.25)",width:e.width,height:e.height,maxHeight:a,maxWidth:"92vw",overflow:"hidden",display:"flex",flexDirection:"column",...e.draggable?{position:"absolute",pointerEvents:"auto",left:g?l.left:"50%",top:g?l.top:"50%",transform:g?void 0:"translate(-50%, -50%)"}:{}};return i.jsx("div",{className:"g7le-modal-backdrop",role:"presentation","data-testid":`g7le-modal-backdrop-${e.id}`,"data-draggable":e.draggable?"true":"false",onClick:b,style:m,children:i.jsx("div",{ref:c,className:"g7le-modal",role:"dialog","aria-modal":"true","aria-label":e.ariaLabel||void 0,"data-testid":`g7le-modal-${e.id}`,"data-positioned":g?"true":"false",onClick:v=>v.stopPropagation(),onPointerDown:e.draggable?f:void 0,style:h,children:e.content})})}function ht({baseStyle:e,hoverStyle:t,disabled:n,style:o,children:r,...s}){const[a,l]=u.useState(!1),d={outline:"none",...e,...o,...a&&!n?t:{}};return i.jsx("button",{type:"button",disabled:n,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),style:d,...s,children:r})}function jy({templateIdentifier:e,templateName:t,templateVersion:n,templateList:o,onSwitch:r}){const{t:s}=et(),[a,l]=u.useState(!1),[d,c]=u.useState(!1),p=u.useRef(null);u.useEffect(()=>{if(!a)return;const v=_=>{p.current&&!p.current.contains(_.target)&&l(!1)},y=_=>{_.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",y),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",y)}},[a]);const f=o??[],b=f.some(v=>v.identifier!==e),g=!!r&&b,m=t||e,h=v=>{if(v===e){l(!1);return}l(!1),r?.(v)};return i.jsxs("div",{ref:p,className:"g7le-toolbar__template-switcher",style:{position:"relative",display:"inline-flex"},children:[i.jsxs("button",{type:"button",className:"g7le-toolbar__template","data-testid":"g7le-toolbar-template-label","data-can-switch":g?"true":"false","aria-haspopup":g?"listbox":void 0,"aria-expanded":g?a:void 0,disabled:!g,onClick:()=>g&&l(v=>!v),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),title:g?s("layout_editor.chrome.toolbar.switch_template"):m,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 8px",fontSize:13,fontWeight:600,color:"#0f172a",letterSpacing:.1,borderRadius:6,borderWidth:1,borderStyle:"solid",borderColor:g&&(d||a)?"#cbd5e1":"transparent",backgroundColor:g&&(d||a)?"#f1f5f9":"transparent",cursor:g?"pointer":"default",outline:"none",transition:"background-color 120ms, border-color 120ms"},children:[i.jsx("span",{className:"g7le-toolbar__template-name","data-testid":"g7le-toolbar-template-name",children:m}),n&&i.jsxs("span",{className:"g7le-toolbar__template-version","data-testid":"g7le-toolbar-template-version",style:{fontSize:11,fontWeight:500,color:"#64748b",padding:"1px 6px",borderRadius:999,background:"#f1f5f9",border:"1px solid #e2e8f0"},children:["v",n]}),g&&i.jsx("span",{className:"g7le-toolbar__template-caret","aria-hidden":"true",style:{fontSize:9,color:"#94a3b8",marginLeft:1},children:"▼"})]}),g&&a&&i.jsx("div",{className:"g7le-toolbar__template-menu","data-testid":"g7le-toolbar-template-menu",role:"listbox",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:240,maxWidth:360,maxHeight:360,overflowY:"auto",background:"#ffffff",border:"1px solid #e2e8f0",borderRadius:8,boxShadow:"0 8px 24px rgba(15, 23, 42, 0.14)",zIndex:30,padding:4},children:f.map(v=>{const y=v.identifier===e;return i.jsxs("button",{type:"button",role:"option","aria-selected":y,"aria-current":y?"true":void 0,className:"g7le-toolbar__template-menu-item","data-testid":"g7le-toolbar-template-menu-item","data-identifier":v.identifier,"data-current":y?"true":"false",onClick:()=>h(v.identifier),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,width:"100%",padding:"8px 10px",fontSize:13,color:"#1e293b",background:y?"#eff6ff":"transparent",border:"none",borderRadius:6,cursor:y?"default":"pointer",textAlign:"left",outline:"none"},onMouseEnter:_=>{y||(_.currentTarget.style.background="#f1f5f9")},onMouseLeave:_=>{_.currentTarget.style.background=y?"#eff6ff":"transparent"},children:[i.jsxs("span",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[i.jsx("span",{"aria-hidden":"true",style:{width:12,flex:"0 0 auto",color:"#2563eb",fontSize:12,textAlign:"center"},children:y?"✓":""}),i.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:2,minWidth:0},children:[i.jsx("span",{style:{fontWeight:600,color:y?"#1d4ed8":"#1e293b",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name||v.identifier}),i.jsx("span",{style:{fontSize:11,color:"#94a3b8",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.identifier})]})]}),i.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,flex:"0 0 auto"},children:[i.jsx("span",{style:{fontSize:10,fontWeight:600,color:v.type==="admin"?"#7c3aed":"#0891b2",textTransform:"uppercase",letterSpacing:.4},children:v.type}),v.version&&i.jsxs("span",{style:{fontSize:11,color:"#64748b"},children:["v",v.version]})]})]},v.identifier)})})]})}function Hy(e={}){const{onSave:t,isDirty:n=!1,onExit:o,onEditCode:r,onManageImages:s,onManageTranslations:a,onPageSettings:l,onReset:d,onShowShortcuts:c,onPreview:p,onShowVersions:f,templateName:b,templateVersion:g,templateList:m,onSwitchTemplate:h,onToggleCustomAssets:v,customAssetsDisabled:y=!1,onManageCustomAssets:_}=e,[w,k]=u.useState(!1),[x,$]=u.useState(!1),{t:C}=et(),{state:S,dispatch:D}=Qe(),[E,I]=u.useState(null);u.useEffect(()=>{const V=()=>{const Z=window.__g7LayoutEditorHistory;I(Z?{undo:Z.undo,redo:Z.redo,canUndo:!!Z.canUndo,canRedo:!!Z.canRedo}:null)};V();const X=window.setInterval(V,250);return()=>window.clearInterval(X)},[]);const N=()=>{D({type:"TOGGLE_ROUTE_TREE"})},T=()=>S.editMode==="base"?C("layout_editor.chrome.toolbar.mode_badge.base"):S.editMode==="modal"?C("layout_editor.chrome.toolbar.mode_badge.modal"):S.editMode==="extension"?C("layout_editor.chrome.toolbar.mode_badge.extension"):S.editMode==="iteration_item"?C("layout_editor.chrome.toolbar.mode_badge.iteration_item"):null,B=()=>{S.editMode==="base"?D({type:"EXIT_BASE_EDIT"}):S.editMode==="modal"?D({type:"EXIT_MODAL_EDIT"}):S.editMode==="extension"?D({type:"EXIT_EXTENSION_EDIT"}):S.editMode==="iteration_item"&&D({type:"EXIT_ITERATION_ITEM_EDIT"})},M=T(),O=S.editMode!=="route",z={display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",fontSize:13,fontWeight:500,borderRadius:6,borderWidth:1,borderStyle:"solid",borderColor:"transparent",backgroundColor:"transparent",color:"#475569",cursor:"pointer",transition:"background-color 120ms, color 120ms, border-color 120ms"},H={...z,backgroundColor:"#2563eb",color:"#ffffff",borderColor:"#2563eb",fontWeight:600},P={backgroundColor:"#fef3c7",borderColor:"#f59e0b",color:"#92400e",fontWeight:600},A={...z,borderColor:"#e2e8f0",backgroundColor:"#ffffff",color:"#0f172a"},L={backgroundColor:"#f1f5f9",color:"#0f172a",borderColor:"#cbd5e1"},F={backgroundColor:"#1d4ed8",borderColor:"#1d4ed8"},Y={backgroundColor:"#f8fafc",borderColor:"#cbd5e1"};return i.jsxs("div",{className:"g7le-toolbar","data-testid":"g7le-toolbar",role:"toolbar",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 12px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",boxShadow:"0 1px 2px rgba(15, 23, 42, 0.04)"},children:[i.jsx("style",{children:"@keyframes g7le-spin { to { transform: rotate(360deg); } }.g7le-toolbar > * { flex-shrink: 0; white-space: nowrap; }"}),i.jsx("button",{type:"button",className:"g7le-toolbar__route-tree-toggle","data-testid":"g7le-toolbar-toggle-route-tree","aria-label":C("layout_editor.chrome.toolbar.toggle_route_tree"),title:C("layout_editor.chrome.toolbar.toggle_route_tree"),onClick:N,style:{...z,outline:"none",padding:"6px 10px",fontSize:16,lineHeight:1,color:"#64748b"},children:"☰"}),i.jsx(jy,{templateIdentifier:S.templateIdentifier,templateName:b,templateVersion:g,templateList:m,onSwitch:h}),M&&i.jsx("span",{className:"g7le-toolbar__mode-badge","data-testid":"g7le-toolbar-mode-badge","data-mode":S.editMode,style:{padding:"2px 8px",borderRadius:999,background:"#fef3c7",color:"#92400e",fontSize:11,fontWeight:600,border:"1px solid #fde68a"},children:M}),i.jsx("div",{style:{flex:1}}),i.jsxs(i.Fragment,{children:[i.jsx(ht,{"data-testid":"g7le-toolbar-undo","aria-label":C("layout_editor.chrome.toolbar.undo"),title:C("layout_editor.chrome.toolbar.undo"),disabled:!E?.canUndo,onClick:()=>E?.undo?.(),baseStyle:z,hoverStyle:L,style:{opacity:E?.canUndo?1:.4},children:"↶"}),i.jsx(ht,{"data-testid":"g7le-toolbar-redo","aria-label":C("layout_editor.chrome.toolbar.redo"),title:C("layout_editor.chrome.toolbar.redo"),disabled:!E?.canRedo,onClick:()=>E?.redo?.(),baseStyle:z,hoverStyle:L,style:{opacity:E?.canRedo?1:.4},children:"↷"}),i.jsxs(ht,{"data-testid":"g7le-toolbar-add-element","data-open":S.isPaletteOpen?"true":"false",disabled:!S.selectedRoute,onClick:()=>D({type:"TOGGLE_PALETTE"}),"aria-pressed":S.isPaletteOpen,baseStyle:z,hoverStyle:L,style:S.isPaletteOpen?{backgroundColor:"#eff6ff",color:"#1d4ed8",borderColor:"#93c5fd"}:void 0,children:["+ ",C("layout_editor.chrome.toolbar.add_element")]}),i.jsx(ht,{"data-testid":"g7le-toolbar-preview","data-previewing":x?"true":"false",disabled:!p||!S.selectedRoute?.layoutName||x,onClick:()=>{const V=p?.();V&&typeof V.then=="function"&&($(!0),V.finally(()=>$(!1)))},baseStyle:z,hoverStyle:L,style:{opacity:x?.7:1},children:x?i.jsxs(i.Fragment,{children:[i.jsx("span",{"data-testid":"g7le-toolbar-preview-spinner","aria-hidden":"true",style:{display:"inline-block",width:12,height:12,border:"2px solid rgba(71,85,105,0.35)",borderTopColor:"#475569",borderRadius:"50%",animation:"g7le-spin 600ms linear infinite"}}),C("layout_editor.chrome.toolbar.previewing")]}):i.jsxs(i.Fragment,{children:["👁 ",C("layout_editor.chrome.toolbar.preview")]})}),i.jsxs(ht,{"data-testid":"g7le-toolbar-versions",disabled:!f||!(S.selectedRoute?.layoutName||S.selectedRoute?.path?.startsWith("__extension__/")),onClick:()=>f?.(),"aria-label":C("layout_editor.chrome.toolbar.version_history"),title:C("layout_editor.chrome.toolbar.version_history"),baseStyle:z,hoverStyle:L,children:["🕘 ",C("layout_editor.chrome.toolbar.version_history")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-edit-code",disabled:!r,onClick:()=>r?.(),baseStyle:z,hoverStyle:L,children:["⟨/⟩ ",C("layout_editor.chrome.toolbar.edit_code")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-images",disabled:!s||!S.selectedRoute,onClick:()=>s?.(),baseStyle:z,hoverStyle:L,children:["🖼 ",C("layout_editor.chrome.toolbar.images")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-translations",disabled:!a||!S.selectedRoute,onClick:()=>a?.(),baseStyle:z,hoverStyle:L,children:["🌐 ",C("layout_editor.chrome.toolbar.translations")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-custom-assets",disabled:!_,onClick:()=>_?.(),title:C("layout_editor.chrome.toolbar.custom_assets_hint"),baseStyle:z,hoverStyle:L,children:["🎨 ",C("layout_editor.chrome.toolbar.custom_assets")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-toggle-custom-assets","data-custom-disabled":y?"true":"false",disabled:!v,onClick:()=>v?.(),"aria-pressed":y,title:C(y?"layout_editor.chrome.toolbar.custom_assets_on_hint":"layout_editor.chrome.toolbar.custom_assets_off_hint"),baseStyle:z,hoverStyle:L,style:y?{...z,...P}:void 0,children:[y?"👁":"🚫"," ",C(y?"layout_editor.chrome.toolbar.custom_assets_on":"layout_editor.chrome.toolbar.custom_assets_off")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-page-settings",disabled:!l||!S.selectedRoute||S.editMode==="extension"||S.editMode==="iteration_item",onClick:()=>l?.(),baseStyle:z,hoverStyle:L,children:["⚙ ",C("layout_editor.chrome.toolbar.page_settings")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-reset",disabled:!d||!n,onClick:()=>d?.(),"aria-label":C("layout_editor.chrome.toolbar.reset"),title:C("layout_editor.chrome.toolbar.reset"),baseStyle:z,hoverStyle:L,style:{opacity:n?1:.4},children:["↺ ",C("layout_editor.chrome.toolbar.reset")]}),i.jsx(ht,{"data-testid":"g7le-toolbar-save","data-dirty":n?"true":"false","data-saving":w?"true":"false",disabled:!t||w,onClick:()=>{const V=t?.();V&&typeof V.then=="function"&&(k(!0),V.finally(()=>k(!1)))},baseStyle:H,hoverStyle:F,style:{opacity:w?.7:n?1:.7},children:w?i.jsxs(i.Fragment,{children:[i.jsx("span",{"data-testid":"g7le-toolbar-save-spinner","aria-hidden":"true",className:"g7le-toolbar__spinner",style:{display:"inline-block",width:12,height:12,border:"2px solid rgba(255,255,255,0.4)",borderTopColor:"#ffffff",borderRadius:"50%",animation:"g7le-spin 600ms linear infinite"}}),C("layout_editor.chrome.toolbar.saving")]}):i.jsxs(i.Fragment,{children:["💾 ",C("layout_editor.chrome.toolbar.save")]})}),i.jsx(ht,{"data-testid":"g7le-toolbar-shortcuts",disabled:!c,onClick:()=>c?.(),"aria-label":C("layout_editor.shortcuts.title"),title:C("layout_editor.shortcuts.title"),baseStyle:z,hoverStyle:L,children:"⌨"}),i.jsxs(ht,{"data-testid":"g7le-toolbar-exit",disabled:!o,onClick:()=>o?.(),baseStyle:A,hoverStyle:Y,children:["✕ ",C("layout_editor.chrome.toolbar.exit")]})]}),O&&i.jsxs(ht,{"data-testid":"g7le-toolbar-exit-alt-mode",onClick:B,baseStyle:A,hoverStyle:Y,children:["← ",S.editMode==="base"&&C("layout_editor.chrome.toolbar.exit_base_edit"),S.editMode==="modal"&&C("layout_editor.chrome.toolbar.exit_modal_edit"),S.editMode==="extension"&&C("layout_editor.chrome.toolbar.exit_extension_edit"),S.editMode==="iteration_item"&&C("layout_editor.chrome.toolbar.exit_iteration_item_edit")]})]})}function fr(){if(typeof window>"u")return null;try{return window.localStorage?.getItem("auth_token")??null}catch{return null}}function Me(e){const t={Accept:"application/json",...e??{}},n=fr();return n&&(t.Authorization=`Bearer ${n}`),t}function Fi(e){return encodeURIComponent(e)}async function Wl(e,t){const n=`/api/admin/templates/${Fi(e)}/layout-attachments?layout_name=${encodeURIComponent(t)}`;try{const o=await fetch(n,{method:"GET",headers:Me(),credentials:"same-origin"}),r=await o.json().catch(()=>null);return!o.ok||!r?.success?{ok:!1,status:o.status,message:Ki(r,o.status)}:{ok:!0,data:Array.isArray(r?.data)?r.data:[]}}catch(o){return{ok:!1,status:0,message:o instanceof Error?o.message:"network error"}}}async function jl(e,t,n){const o=`/api/admin/templates/${Fi(e)}/layout-attachments`,r=new FormData;r.append("file",n),r.append("layout_name",t);try{const s=await fetch(o,{method:"POST",headers:Me(),body:r,credentials:"same-origin"}),a=await s.json().catch(()=>null);return!s.ok||!a?.success||!a?.data?.url?{ok:!1,status:s.status,message:Ki(a,s.status)}:{ok:!0,data:a.data}}catch(s){return{ok:!1,status:0,message:s instanceof Error?s.message:"network error"}}}async function Hl(e){const t=`/api/admin/templates/layout-attachments/${Fi(String(e))}`;try{const n=await fetch(t,{method:"DELETE",headers:Me(),credentials:"same-origin"}),o=await n.json().catch(()=>null);return!n.ok||o&&o.success===!1?{ok:!1,status:n.status,message:Ki(o,n.status)}:{ok:!0,data:!0}}catch(n){return{ok:!1,status:0,message:n instanceof Error?n.message:"network error"}}}function Ki(e,t){if(e&&typeof e=="object"&&"message"in e){const n=e.message;if(typeof n=="string"&&n.length>0)return n}return`HTTP ${t}`}function Fy(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ky(e){if(!e)return"";const t=e.match(/^(\d{4})-(\d{2})-(\d{2})/);return t?`${t[2]}-${t[3]}`:""}function Fl({templateIdentifier:e,layoutName:t,t:n,onSelect:o,onChanged:r,onClose:s}){const[a,l]=u.useState([]),[d,c]=u.useState("idle"),[p,f]=u.useState(!1),[b,g]=u.useState(null),m=u.useRef(null),h=u.useCallback(async()=>{c("loading"),g(null);const _=await Wl(e,t);_.ok?(l(_.data),c("idle")):(g(_.message),c("error"))},[e,t]);u.useEffect(()=>{h()},[h]);const v=async _=>{const w=_.target.files?.[0];if(!w)return;f(!0),g(null);const k=await jl(e,t,w);k.ok?(l(x=>[k.data,...x.filter($=>$.id!==k.data.id)]),r?.()):g(k.message),f(!1),m.current&&(m.current.value="")},y=async _=>{if(!(typeof window<"u"&&typeof window.confirm=="function"?window.confirm(n("layout_editor.attachment_manager.delete_confirm")):!0))return;const k=await Hl(_.id);k.ok?(l(x=>x.filter($=>$.id!==_.id)),r?.()):g(k.message)};return i.jsxs("div",{className:"g7le-attachment-manager","data-testid":"g7le-attachment-manager",style:Vy,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:Uy,children:[i.jsx("span",{style:{fontSize:14,fontWeight:700},"data-testid":"g7le-attachment-manager-title",children:n("layout_editor.attachment_manager.title")}),i.jsx("button",{type:"button","aria-label":"close",onClick:s,style:qy,"data-testid":"g7le-attachment-manager-close",children:"✕"})]}),i.jsx("div",{style:Gy,children:i.jsxs("label",{style:Yy,"data-testid":"g7le-attachment-upload",children:[p?"…":`⬆ ${n("layout_editor.attachment_manager.upload")}`,i.jsx("input",{ref:m,type:"file",accept:"image/*",onChange:v,disabled:p,style:{display:"none"},"data-testid":"g7le-attachment-upload-input"})]})}),b&&i.jsx("div",{style:Xy,"data-testid":"g7le-attachment-manager-error",children:b}),i.jsx("div",{style:Jy,children:d==="loading"?i.jsx("div",{style:Kl,"data-testid":"g7le-attachment-manager-loading",children:n("layout_editor.attachment_manager.loading")}):a.length===0&&d!=="error"?i.jsx("div",{style:Kl,"data-testid":"g7le-attachment-manager-empty",children:n("layout_editor.attachment_manager.empty")}):i.jsx("div",{style:Zy,"data-testid":"g7le-attachment-grid",children:a.map(_=>i.jsxs("div",{style:Qy,"data-testid":`g7le-attachment-card-${_.id}`,children:[i.jsx("div",{style:{...Ry,backgroundImage:`url(${_.url})`}}),i.jsx("div",{style:eb,title:_.original_name,children:_.original_name}),i.jsxs("div",{style:tb,children:[Fy(_.size),_.created_at?` · ${Ky(_.created_at)}`:""]}),i.jsxs("div",{style:nb,children:[o&&i.jsx("button",{type:"button",onClick:()=>o(_.url),style:ob,"data-testid":`g7le-attachment-use-${_.id}`,children:n("layout_editor.attachment_manager.use_as_bg")}),i.jsx("button",{type:"button",onClick:()=>y(_),style:rb,"data-testid":`g7le-attachment-delete-${_.id}`,children:"🗑"})]})]},_.id))})}),i.jsx("div",{style:ib,children:i.jsx("button",{type:"button",onClick:s,style:sb,"data-testid":"g7le-attachment-manager-footer-close",children:n("layout_editor.attachment_manager.close")})})]})}const Vy={display:"flex",flexDirection:"column",minHeight:0,flex:1},Uy={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #e2e8f0"},qy={border:"none",background:"transparent",fontSize:16,color:"#94a3b8",cursor:"pointer"},Gy={padding:"10px 16px",borderBottom:"1px solid #f1f5f9",display:"flex",gap:8},Yy={padding:"6px 12px",fontSize:13,border:"1px solid #2563eb",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",display:"inline-flex",alignItems:"center"},Xy={padding:"8px 16px",fontSize:12,color:"#b91c1c",background:"#fef2f2"},Jy={padding:16,overflow:"auto",flex:1,minHeight:120},Kl={fontSize:13,color:"#94a3b8",textAlign:"center",padding:"32px 0"},Zy={display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:12},Qy={display:"flex",flexDirection:"column",gap:4,border:"1px solid #e2e8f0",borderRadius:8,padding:8},Ry={width:"100%",height:88,borderRadius:6,border:"1px solid #cbd5e1",backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f8fafc"},eb={fontSize:12,fontWeight:600,color:"#0f172a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},tb={fontSize:11,color:"#64748b"},nb={display:"flex",gap:6,marginTop:2},ob={flex:1,padding:"4px 6px",fontSize:11,border:"1px solid #2563eb",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},rb={padding:"4px 8px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},ib={padding:"10px 16px",borderTop:"1px solid #e2e8f0",display:"flex",justifyContent:"flex-end"},sb={padding:"6px 14px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"};function gr(e){return encodeURIComponent(e)}async function ab(e,t,n){const o=new URLSearchParams;t&&o.set("layout_name",t);const r=o.toString(),s=`/api/admin/templates/${gr(e)}/custom-translations`+(r?`?${r}`:"");try{const a=await fetch(s,{method:"GET",headers:Me(),credentials:"same-origin"}),l=await a.json().catch(()=>null);return!a.ok||!l?.success?{ok:!1,status:a.status,message:hr(l,a.status)}:{ok:!0,data:Array.isArray(l?.data)?l.data:[]}}catch(a){return{ok:!1,status:0,message:a instanceof Error?a.message:"network error"}}}async function lb(e,t,n,o){const r=`/api/admin/templates/${gr(e)}/custom-translations/${t}`;try{const s=await fetch(r,{method:"PUT",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({values:n,expected_lock_version:o}),credentials:"same-origin"}),a=await s.json().catch(()=>null);return!s.ok||!a?.success||!a?.data?{ok:!1,status:s.status,message:hr(a,s.status)}:{ok:!0,data:a.data}}catch(s){return{ok:!1,status:0,message:s instanceof Error?s.message:"network error"}}}async function db(e,t){const n=`/api/admin/templates/${gr(e)}/custom-translations/${t}`;try{const o=await fetch(n,{method:"DELETE",headers:Me(),credentials:"same-origin"}),r=await o.json().catch(()=>null);return!o.ok||r&&r.success===!1?{ok:!1,status:o.status,message:hr(r,o.status)}:{ok:!0,data:!0}}catch(o){return{ok:!1,status:0,message:o instanceof Error?o.message:"network error"}}}async function cb(e,t){const n=`/api/admin/templates/${gr(e)}/custom-translations`;try{const o=await fetch(n,{method:"DELETE",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({ids:t}),credentials:"same-origin"}),r=await o.json().catch(()=>null);return!o.ok||!r?.success?{ok:!1,status:o.status,message:hr(r,o.status)}:{ok:!0,data:{deleted:typeof r?.data?.deleted=="number"?r.data.deleted:t.length}}}catch(o){return{ok:!1,status:0,message:o instanceof Error?o.message:"network error"}}}const Vl=/\$t:(custom\.[A-Za-z0-9_\-]+\.\d+)/g;function ub(e){const t=new Set,n=o=>{if(typeof o=="string"){if(o.includes("$t:custom.")){let r;for(Vl.lastIndex=0;(r=Vl.exec(o))!==null;)t.add(r[1])}return}if(Array.isArray(o)){for(const r of o)n(r);return}if(o&&typeof o=="object")for(const r of Object.values(o))n(r)};return n(e),t}function hr(e,t){if(e&&typeof e=="object"&&"message"in e){const n=e.message;if(typeof n=="string"&&n.length>0)return n}return`HTTP ${t}`}const Pt=Lt().TranslationEngine,_o=Lt().createLogger,Vi=_o("EditorSpecLoader"),pb=["controls","componentCapabilities","actionRecipes","conditionRecipes","pageSettings","initActionRecipes","errorRecipes","computedRecipes","loadingComponents"],fb=["actionRecipes","initActionRecipes","errorRecipes","computedRecipes","loadingComponents"];function Ul(e){if(typeof window>"u")return[];const n=window.G7Config?.[e];if(!Array.isArray(n))return[];const o=[];for(const r of n){const s=r?.identifier;typeof s=="string"&&s.length>0&&o.push(s)}return o}async function gb(e,t,n,o){const s=`${n}/${e==="template"?"templates":e==="module"?"modules":"plugins"}/${encodeURIComponent(t)}/editor-spec`;try{const a=await o(s);if(!a.ok)return a.status!==404&&Vi.warn(`fetchOneSpec: HTTP ${a.status}`,s),null;const l=await a.json();return!l?.success||!l.data?null:l.data.spec??null}catch(a){return Vi.warn("fetchOneSpec: fetch failed",s,a),null}}function hb(e){return fb.includes(e)}function yb(e,t){return e==null||typeof e!="object"?e:{...e,__source:t}}function bb(e,t,n,o){const r=t[n];if(!r||typeof r!="object")return;const s=e[n]??{};if(o&&hb(n)){const a={};for(const[l,d]of Object.entries(r))a[l]=yb(d,o);e[n]={...s,...a};return}e[n]={...s,...r}}function mb(e,t){if(!t.nesting)return;const n=e.nesting??{},o=new Set(n.draggable??[]);for(const r of t.nesting.draggable??[])o.add(r);n.draggable=Array.from(o),n.containers={...n.containers??{},...t.nesting.containers??{}},e.nesting=n}function vb(e,t){if(!t.componentPalette)return;const n=e.componentPalette??{},o=[...n.groups??[],...t.componentPalette.groups??[]];n.groups=o,n.entries={...n.entries??{},...t.componentPalette.entries??{}},e.componentPalette=n}function _b(e,t){if(!t.states)return;const n=e.states??{},o=[...n.groups??[],...t.states.groups??[]];n.groups=o,e.states=n}function xb(e,t){if(!Array.isArray(t.stateLabels)||t.stateLabels.length===0)return;const n=[...e.stateLabels??[],...t.stateLabels],o=new Map;for(const r of n)!r||typeof r.key!="string"||typeof r.scope!="string"||o.set(`${r.scope}:${r.key}`,r);e.stateLabels=Array.from(o.values())}function wb(e,t){if(!t.actionChipCandidates)return;const n=e.actionChipCandidates??{};for(const o of["response","error","payload"]){const r=t.actionChipCandidates[o];!Array.isArray(r)||r.length===0||(n[o]=[...n[o]??[],...r])}e.actionChipCandidates=n}function kb(e,t){if(!t.sampleData)return;const n=e.sampleData??{};n.byDataSourceId={...n.byDataSourceId??{},...t.sampleData.byDataSourceId??{}},n.byEndpointPattern={...n.byEndpointPattern??{},...t.sampleData.byEndpointPattern??{}},e.sampleData=n}function ql(e,t,n){for(const o of pb)bb(e,t,o,n);mb(e,t),vb(e,t),_b(e,t),xb(e,t),wb(e,t),kb(e,t),t.version&&(e.version=t.version)}async function Sb(e){const t=e.apiBaseUrl??"/api",n=e.fetcher??(typeof fetch<"u"?fetch:void 0);if(!n)return Vi.warn("loadEditorSpecBundle: fetch unavailable, returning null spec"),{spec:null,sampleGlobalSources:[]};const o=e.activeModuleIdentifiers??Ul("activeModules"),r=e.activePluginIdentifiers??Ul("activePlugins"),s=[...o.map(p=>({kind:"module",id:p})),...r.map(p=>({kind:"plugin",id:p})),{kind:"template",id:e.templateIdentifier}],a=await Promise.all(s.map(p=>gb(p.kind,p.id,t,n)));let l=null;const d=[],c={};if(e.coreSeed&&(l={},ql(l,e.coreSeed,{kind:"core"})),s.forEach((p,f)=>{const b=a[f];if(!b)return;b.sampleGlobal&&typeof b.sampleGlobal=="object"&&d.push({id:p.id,kind:p.kind,sampleGlobal:b.sampleGlobal});const g=b.sampleData?.byDataSourceId;if(g&&typeof g=="object"){const m=p.kind==="template"?"template":`${p.kind}:${p.id}`;c[m]={...c[m]??{},...g}}l===null&&(l={}),ql(l,b,{kind:p.kind,id:p.id})}),l!==null&&Object.keys(c).length>0){const p=l;p.sampleData={...p.sampleData??{},bySource:c}}return{spec:l,sampleGlobalSources:d}}function Ui(e,t){return e?.componentCapabilities?.[t]??null}function Ct(e,t){return e?.controls?.[t]??null}function Cb(e){return e?.initActionRecipes??{}}function $b(e){return e?.computedRecipes??{}}function Eb(e){return e?.errorRecipes??{}}function Ib(e){const t=e?.loadingComponents;return!t||typeof t!="object"?[]:Object.values(t).filter(n=>n!=null&&typeof n=="object"&&typeof n.name=="string")}function Ab(e,t,n){const o=e?.stateLabels;if(!Array.isArray(o))return null;for(const r of o)if(r?.scope===t&&r?.key===n)return typeof r.label_key=="string"?r.label_key:null;return null}function qi(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Tb(e){return e===null?"null":typeof e=="string"?e.length>40?`${e.slice(0,40)}…`:e:typeof e=="number"||typeof e=="boolean"?String(e):""}function Db(e){const t=e.find(n=>qi(n));if(qi(t))return Object.keys(t).slice(0,8)}function zb(e){return Object.keys(e).slice(0,8)}function Nb(e){const t=Object.entries(e);return t.length===0?!1:t.some(([,n])=>n===null||typeof n!="object")}function Gi(e,t,n,o,r){if(Array.isArray(e)){r(t,"array",`[${e.length}]`,Db(e));return}if(qi(e)){if(t&&Nb(e)){const s=zb(e);r(t,"object",`{${s.length}}`,s)}if(n>=o)return;for(const[s,a]of Object.entries(e)){const l=t?`${t}.${s}`:s;Gi(a,l,n+1,o,r)}return}r(t,"scalar",Tb(e))}function Mb(e,t,n){const o=[];let r=e;for(const s of t){if(!r||(r=(Array.isArray(r.children)?r.children:[])[s],!r))break;const l=r.iteration;if(!(!l||l.source===void 0)&&(typeof l.index_var=="string"&&l.index_var.length>0&&o.push({name:l.index_var,kind:"index"}),typeof l.item_var=="string"&&l.item_var.length>0)){const d=typeof l.source=="string"?l.source:"",c=d&&n?.get(Gl(d))||[];o.push({name:l.item_var,kind:"item",itemFields:c})}}return o}function Gl(e){return e.replace(/^\{\{|\}\}$/g,"").trim()}function Lb(e){const t=new Map;for(const n of e)n.shape==="array"&&n.itemFields&&n.itemFields.length>0&&t.set(Gl(n.expression),n.itemFields);return t}function Yi(e){const t=e.maxDepth??4,n=[];for(const o of e.dataSources??[])!o||typeof o.id!="string"||o.id.length===0||Gi(o.sample,"",0,t,(r,s,a,l)=>{const d=r?`{{${o.id}.${r}}}`:`{{${o.id}}}`;n.push({expression:d,source:"data_source",sourceId:o.id,path:r,shape:s,groupLabelKey:o.labelKey?.startsWith("$t:")?o.labelKey.slice(3):o.labelKey,preview:a,itemFields:l})});for(const o of e.states??[])!o||typeof o.scope!="string"||Gi(o.tree,"",0,t,(r,s,a,l)=>{if(!r)return;const d=Ab(e.spec,o.scope,r)??void 0;n.push({expression:`{{${o.scope}.${r}}}`,source:o.scope,sourceId:o.scope,path:r,shape:s,labelKey:d?.startsWith("$t:")?d.slice(3):d,preview:a,itemFields:l})});for(const o of e.iterationVars??[])if(!(!o||typeof o.name!="string"||o.name.length===0)){if(o.kind==="index"){n.push({expression:`{{${o.name}}}`,source:"iteration",sourceId:o.name,path:"",shape:"scalar",preview:"0"});continue}for(const r of o.itemFields??[])n.push({expression:`{{${o.name}.${r}}}`,source:"iteration",sourceId:o.name,path:r,shape:"scalar",preview:""})}return n}const Pb=["$localized"];function Ob(e){const t=e.trim(),n=t.indexOf("(");if(n===-1||!t.endsWith(")"))return{fn:null,inner:t};const o=t.slice(0,n).trim();if(!Pb.includes(o))return{fn:null,inner:t};const r=t.slice(n+1,-1);let s=0,a=null;for(let l=0;ln.shape===t)}function Zi(e,t){const n=t.trim().toLowerCase();return n===""?e:e.filter(o=>[o.resolvedLabel??"",o.sourceId,o.path,o.preview].join(" ").toLowerCase().includes(n))}function Yl(e,t,n){const o={response:[{path:"data",labelKey:"layout_editor.action_chip.response_data",shape:"object"},{path:"message",labelKey:"layout_editor.action_chip.response_message",shape:"scalar"}],error:[{path:"status",labelKey:"layout_editor.action_chip.error_status",shape:"scalar"},{path:"message",labelKey:"layout_editor.action_chip.error_message",shape:"scalar"},{path:"errors",labelKey:"layout_editor.action_chip.error_errors",shape:"object"},{path:"data",labelKey:"layout_editor.action_chip.error_data",shape:"object"},{path:"statusText",labelKey:"layout_editor.action_chip.error_status_text",shape:"scalar"}],payload:[{path:"data",labelKey:"layout_editor.action_chip.payload_data",shape:"object"}]},r=e==="response"?"response":e==="error"?"error":"message",s=new Set,a=[];for(const d of o[e])s.has(d.path)||(s.add(d.path),a.push(d));const l=n?.[e];if(Array.isArray(l))for(const d of l)!d||typeof d.path!="string"||typeof d.labelKey!="string"||s.has(d.path)||(s.add(d.path),a.push({path:d.path,labelKey:d.labelKey,shape:d.shape??"scalar"}));return a.map(d=>({expression:`{{${r}.${d.path}}}`,source:"_local",sourceId:r,path:d.path,shape:d.shape,labelKey:d.labelKey,preview:t(d.labelKey)}))}const Qi=/\{\{(?:[^}]|\}(?!\}))*\}\}/g;function An(e){const t=[];if(typeof e!="string"||e.length===0)return t;let n=0,o=0;const r=new RegExp(Qi.source,"g");let s;for(;(s=r.exec(e))!==null;){const a=s.index,l=a+s[0].length;a>n&&t.push({kind:"literal",raw:e.slice(n,a),start:n,end:a}),t.push({kind:"binding",raw:s[0],start:a,end:l,parsed:Vt(s[0]),bindingIndex:o++}),n=l}return nt.kind==="binding")}function br(e){return typeof e!="string"?!1:new RegExp(Qi.source).test(e)}function Wb(e){const t=new Set(e.map(o=>o.trim()));let n=0;for(;t.has(`p${n}`);)n+=1;return`p${n}`}function Xl(e,t,n){const o=typeof e=="string"?e:"",r=Math.max(0,Math.min(t,o.length)),s=o.slice(0,r),a=o.slice(r),l=s.length>0&&!/\s$/.test(s)?" ":"",d=a.length>0&&!/^\s/.test(a)?" ":"";return`${s}${l}{${n}}${d}${a}`}function Ri(e,t){const n=typeof e=="string"?e:"";return Tn(n).includes(t)?n:n.length===0?`{${t}}`:/\s$/.test(n)?`${n}{${t}}`:`${n} {${t}}`}function Jl(e){return yr(e).map(t=>({bindingIndex:t.bindingIndex??0,expression:t.raw,parsed:t.parsed??null,isComplex:(t.parsed??null)===null}))}function mr(e){return typeof e!="string"?"":e.replace(new RegExp(Qi.source,"g")," ").replace(/\s+/g," ").trim()}const jb=/\$t:([a-zA-Z0-9._-]+)/g,Zl="custom.";function es(e,t){return typeof e!="string"||e.length===0?typeof e=="string"?e:"":t?An(e).map(n=>n.kind!=="literal"?n.raw:n.raw.replace(jb,(o,r)=>{if(r.startsWith(Zl))return o;const s=t(r);return s&&s!==r?s:o})).join(""):e}const Un="(?:(?!\\|[a-zA-Z0-9_]+=).)*",Hb=new RegExp(`^\\s*\\$t:([a-zA-Z0-9._-]+)((?:\\|[a-zA-Z0-9_]+=${Un})*)`),Fb=new RegExp(`\\|([a-zA-Z0-9_]+)=(${Un})`,"g");function Ut(e){if(typeof e!="string")return"";const t=Vt(e);if(t)return t.path||t.sourceId;const n=e.trim().replace(/^\{\{\s*/,"").replace(/\s*\}\}$/,"");let o=-1;for(let l=0;l0){const l=n.slice(0,o).trim(),d=Vt(`{{${l}}}`);if(d)return d.path||d.sourceId;const c=l.replace(/\?\./g,".").replace(/\s*\?\?.*$/,"").trim();if(/^[A-Za-z_$][\w$.]*$/.test(c)){const p=c.split(".").filter(Boolean);return p.length>1&&p.slice(1).join(".")||c}}const r=n.replace(/\s+/g," ").trim(),s=r.replace(/\s*(\?\?|\|\|)\s*(\[\s*\]|\{\s*\}|'[^']*'|"[^"]*"|\d+|null|undefined)\s*$/,"").trim(),a=/\.([A-Za-z_$][\w$]*)\s*$/.exec(s);return a?a[1]:r}const Ql=/\$(?:core|module|plugin)_settings:[a-zA-Z0-9._:-]+/g;function ts(e){return typeof e=="string"&&new RegExp(Ql.source).test(e)}function Kb(e){return typeof e!="string"?"":e.replace(/^\$(?:core|module|plugin)_settings:/,"").split(/[.:]/).filter(Boolean).pop()||e}function Rl(e){const t=[];for(const n of An(e)){if(n.kind==="binding"){t.push({kind:"chip",label:Ut(n.raw)});continue}let o=0;const r=n.raw,s=new RegExp(Ql.source,"g");let a;for(;(a=s.exec(r))!==null;)a.index>o&&t.push({kind:"text",label:r.slice(o,a.index)}),t.push({kind:"chip",label:Kb(a[0])}),o=a.index+a[0].length;o{const m=`p${o.length}`;return o.push(g),r[m]=Ut(g),`{${m}}`};let a=e,l="";const d=Hb.exec(e);if(d&&!d[1].startsWith(Zl)){const g=d[1],m=d[2]??"",h=e.slice(d[0].length),v=new Map,y=new RegExp(Fb.source,"g");let _;for(;(_=y.exec(m))!==null;)_[2]&&_[2].includes("{{")&&v.set(_[1],_[2]);const w=t?t(g):"";if(w&&w!==g&&!w.startsWith("$t:"))l=w.replace(/\{\{?([a-zA-Z0-9_]+)\}?\}/g,(k,x)=>{const $=v.get(x);return $?s($):k});else return n;a=h}const c=es(a,t),p=An(c).map(g=>g.kind==="binding"?s(g.raw):g.raw).join(""),f=`${l}${p}`;return/\$t:[a-zA-Z0-9._-]+/.test(f)||o.length===0?n:{chipValue:f,bindings:o,paramLabels:r,keyifiable:!0}}function ed(e,t){return t.bindings.length?e+t.bindings.map((n,o)=>`|p${o}=${n}`).join(""):e}function td(e,t){const n=yr(t).map(r=>r.raw);if(n.length===0)return e;const o=n.map((r,s)=>`|p${s}=${r}`).join("");return`${e}${o}`}function nd(e){if(typeof e!="string")return"";const t=An(e);let n=0;return t.map(o=>o.kind==="binding"?`{p${n++}}`:o.raw).join("")}const od=new RegExp(`^\\s*\\$t:([a-zA-Z0-9._-]+)((?:\\|[a-zA-Z0-9_]+=${Un})+)\\s*$`),Ub=new RegExp(`\\|([a-zA-Z0-9_]+)=(${Un})`,"g");function vt(e){if(typeof e!="string")return null;const t=od.exec(e);if(!t)return null;const n=t[1],o=t[2],r=[],s=new RegExp(Ub.source,"g");let a;for(;(a=s.exec(o))!==null;){const l=a[1],d=a[2];r.push({name:l,expression:d,parsed:Vt(d)})}return{key:n,params:r}}function rd(e){return typeof e=="string"&&od.test(e)}function Tn(e){if(typeof e!="string")return[];const t=[],n=/\{\{?(p\d+)\}?\}/g;let o;for(;(o=n.exec(e))!==null;)t.push(o[1]);return t.sort()}function qb(e,t,n){if(typeof e!="string")return e;const o=new RegExp(`(\\|${t}=)${Un}`);return o.test(e)?e.replace(o,`$1${n}`):e}function xo(e,t){if(typeof e!="string")return e;const n=new RegExp(`\\|${t}=${Un}`);return e.replace(n,"")}function id(e,t){return typeof e!="string"?e:e.replace(new RegExp(`\\s*\\{\\{?${t}\\}?\\}\\s*`,"g")," ").replace(/\s+/g," ").trim()}function Gb(e,t){const n=s=>yr(typeof s=="string"?s:"").map(a=>a.raw.replace(/\s+/g,"")).sort(),o=n(e),r=n(t);return o.length!==r.length?!1:o.every((s,a)=>s===r[a])}function sd(e){return e.__source?.kind==="base"}function ad(e){return e.__source?.kind==="partial"}function Yb(e){return e.__source?.kind==="route"}function vr(e,t){return e.__source?.kind!=="extension"?!1:t==null?!0:e.__source.extensionId!==t}function ld(e){return e.type==="extension_point"}function os(e=[]){for(const t of e)if(t.iteration&&t.iteration.source!==void 0)return!0;return!1}function Xb(e,t=[]){for(const n of t)if(n.iteration&&n.iteration.source!==void 0)return!0;return e.iteration&&e.iteration.source!==void 0?!0:dd(e)}function dd(e){if(typeof e.text=="string"&&cd(e.text)&&!Jb(e.text))return!0;if(e.props&&typeof e.props=="object"){for(const t of Object.values(e.props))if(typeof t=="string"&&cd(t))return!0}return!1}function cd(e){return/\{\{[\s\S]*?\}\}/.test(e)}function Jb(e){const t=vt(e);return t!==null&&t.key.startsWith("custom.")}function Zb(e,t){return e??t??null}function ud(e,t,n){if(ld(e))return!0;switch(t){case"route":return sd(e)||ad(e)||vr(e);case"base":return vr(e);case"modal":return vr(e);case"extension":return vr(e,n)?!0:sd(e)||Yb(e)||ad(e);default:return!1}}function tt(e){return typeof e=="object"&&e!==null&&typeof e.responsive=="string"}function _r(e,t){return tt(e)?tt(t)&&e.responsive===t.responsive:!tt(t)&&e===t}function at(e){const t=[];let n=!1;for(const o of e){if(tt(o)){t.push("responsive",o.responsive),n=!0;continue}n?t.push("children",String(o)):(t.push(String(o)),n=!0)}return t.join(".")}function Ot(e){return Array.isArray(e.children)?e.children:[]}function wo(e,t){const n=e.responsive?.[t];return n&&Array.isArray(n.children)?n.children:[]}function Dn(e,t){const n=[];let o=e,r=Ot(e);for(let s=0;s=o.length||(n=o[r],!n))return null;o=Ot(n)}return n}function Qb(e,t,n){if(!e||t.length===0)return t;let o=e,r=Ot(e),s;for(let a=0;a=2?t[t.length-2]:void 0;if(r!==void 0&&tt(r)){const a=Pe(e,t.slice(0,-2));return a?{owner:a,children:wo(a,r.responsive),branchKey:r.responsive,index:o}:null}const s=Pe(e,t.slice(0,-1));return s?{owner:s,children:Ot(s),index:o}:null}function rs(e,t){if(e.branchKey!==void 0){const n={...e.owner.responsive??{}};n[e.branchKey]={...n[e.branchKey]??{},children:t},e.owner.responsive=n}else e.owner.children=t}function tn(e){const t={...e};t.props&&typeof t.props=="object"&&(t.props={...t.props});const n=Ot(e);if(n.length>0&&(t.children=n.map(tn)),e.responsive&&typeof e.responsive=="object"){const o={};for(const r of Object.keys(e.responsive)){const s=e.responsive[r];if(!s||typeof s!="object"){o[r]=s;continue}const a={...s};Array.isArray(s.children)&&(a.children=s.children.map(tn)),a.props&&typeof a.props=="object"&&(a.props={...a.props}),o[r]=a}t.responsive=o}return t}function is(e,t,n,o){const r=tn(e),s=t.length>0?t[t.length-1]:void 0;if(s!==void 0&&tt(s)){const p=Pe(r,t.slice(0,-1));if(!p)return r;const f=wo(p,s.responsive),b=Math.max(0,Math.min(n,f.length)),g=[...f];return g.splice(b,0,o),rs({owner:p,branchKey:s.responsive},g),r}const a=Pe(r,t);if(!a)return r;const l=Ot(a),d=Math.max(0,Math.min(n,l.length)),c=[...l];return c.splice(d,0,o),a.children=c,r}function ss(e,t){if(t.length===0)return e;const n=tn(e),o=pd(n,t);if(!o||o.index<0||o.index>=o.children.length)return n;const r=[...o.children];return r.splice(o.index,1),rs(o,r),n}function Rb(e,t,n,o){if(t.length===0||!n||tt(t[t.length-1]))return e;const r=tn(e),s=Pe(r,t);if(!s)return r;const a=s.responsive&&typeof s.responsive=="object"?s.responsive[n]:void 0;if(a&&Array.isArray(a.children))return r;const l=o&&s.responsive&&typeof s.responsive=="object"?s.responsive[o]:void 0,c=(l&&Array.isArray(l.children)?l.children:Ot(s)).map(tn),p={...s.responsive??{}};return p[n]={...p[n]??{},children:c},s.responsive=p,r}function em(e,t,n){if(t.length===0||!n||tt(t[t.length-1]))return e;const o=tn(e),r=Pe(o,t);if(!r||!r.responsive||typeof r.responsive!="object")return o;const s=r.responsive[n];if(!s||!Array.isArray(s.children))return o;const a={...r.responsive},l={...a[n]};return delete l.children,Object.keys(l).length===0?delete a[n]:a[n]=l,r.responsive=Object.keys(a).length>0?a:void 0,o}function tm(e,t,n,o){if(t.length===0)return e;const r=Pe(e,t);if(!r||nm(t,n))return e;const s=tn(r),a=ss(e,t),l=fd(n,t);let d=o;const c=t.slice(0,-1);if(gd(c,n)){const p=t[t.length-1];(typeof p=="number"?p:0)o){const s=[...e];return s[n]=r-1,s}return e}function gd(e,t){if(e.length!==t.length)return!1;for(let n=0;ne.length||gd(e,t)}function as(e){const t={...e};if(t.props&&typeof t.props=="object"&&(t.props={...t.props}),typeof t.id=="string"&&t.id.length>0){const o=typeof t.name=="string"?t.name:"node";t.id=`${o}_${om()}`}const n=Ot(e);return n.length>0&&(t.children=n.map(as)),t}function Bt(e,t,n){if(t.length===0)return n(e);const o=tn(e),r=Pe(o,t);if(!r)return o;const s=n(r),a=pd(o,t);if(!a||a.index<0||a.index>=a.children.length)return o;const l=[...a.children];return l[a.index]=s,rs(a,l),o}function om(){return Math.floor(Math.random()*2821109907456).toString(36).padStart(8,"0")}function qn(e){if(!Array.isArray(e)||e.length===0)return[];const t=[];for(const n of e){const o=rm(n);o.length>0&&t.push(...o)}return t}function rm(e){if(!e||typeof e!="object")return[];const t=e.__source,n=e._fromBase===!0,o=t?.kind;if(o==="extension"||o==="partial")return[];if(o==="base"||n){const s=Array.isArray(e.children)?e.children:[];return qn(s)}const r={...e};return delete r.__source,delete r._fromBase,delete r.__injectedProps,Array.isArray(r.children)&&(r.children=qn(r.children)),[r]}function ko(e){if(!e||typeof e!="object")return e;const t=e.__editor,n=t&&typeof t=="object"&&!Array.isArray(t)?t.original:void 0,o=n&&typeof n=="object"&&!Array.isArray(n)?n:void 0,r=Array.isArray(e.components)?e.components:[],s=r.length>0,a=qn(r),l=o?{...o}:{...e};if(typeof l.extends=="string"&&l.extends.length>0){delete l.components;const c=l.slots&&typeof l.slots=="object"&&!Array.isArray(l.slots)?l.slots:{},p=Object.keys(c);if(!s&&p.length>0){const f={};for(const[b,g]of Object.entries(c))f[b]=Array.isArray(g)?qn(g):g;l.slots=f}else if(p.length===1)l.slots={[p[0]]:a};else if(p.length===0)l.slots={content:a};else{const f={};for(const[b,g]of Object.entries(c))f[b]=Array.isArray(g)?qn(g):g;l.slots=f}}else l.components=a,delete l.slots;return delete l.lock_version,delete l.__editor,l}const hd="extension",Gn="extensionless";function im(){const e=globalThis?.G7Config;if(globalThis?.__g7AssetUrlMode===Gn)return Gn;const n=e?.assetUrlMode;return n===Gn||n===hd?n:e?.settings?.general?.asset_url_mode===Gn?Gn:hd}function sm(){return im()===Gn}function nn(e,t,n,o){const r=e.replace(/\/+$/,""),s=t.replace(/^\.+/,""),a=sm()?r:`${r}.${s}`,l=[];return o&&l.push(o.replace(/^[?&]+/,"")),n!=null&&n!==""&&l.push(`v=${n}`),l.length>0?`${a}?${l.join("&")}`:a}const yd=/^\s*\$t:([a-zA-Z0-9._-]+)\s*$/,xr="custom.",am=/\{\{.*?\}\}/;function lm(e){return!!(!e||e.iteration&&typeof e.iteration=="object")}function bd(e,t){const n=e?.text,o=typeof n=="string"?n:"";if(lm(e)||typeof n!="string")return{sourceState:"plain_text",editable:!1,customKey:null,displayValue:o};const r=vt(o);if(r&&r.key.startsWith(xr)){const a=t?t(r.key):r.key;return{sourceState:"custom_key",editable:!0,customKey:r.key,displayValue:a,isParamKey:!0}}const s=yd.exec(o);if(s){const a=s[1];if(a.startsWith(xr)){const d=t?t(a):a;return{sourceState:"custom_key",editable:!0,customKey:a,displayValue:d}}const l=t?t(a):"";return{sourceState:"plain_text",editable:!0,customKey:null,displayValue:l&&l!==a?l:""}}if(am.test(o)){const a=mr(o),l=yd.exec(a);if(l&&l[1].startsWith(xr)){const f=l[1],b=t?t(f):f;return{sourceState:"custom_key",editable:!0,customKey:f,displayValue:b}}const d=es(o,t),c=mr(d),p=/\$t:[a-zA-Z0-9._-]+/.test(c);if(c.length>0){const f=ns(o,t);return{sourceState:"plain_with_binding",editable:!0,customKey:null,displayValue:p?"":c,chipValue:f.keyifiable?f.chipValue:void 0,chipParamLabels:f.keyifiable?f.paramLabels:void 0}}return{sourceState:"binding_expression",editable:!1,customKey:null,displayValue:o}}return{sourceState:"plain_text",editable:!0,customKey:null,displayValue:o}}function dm(){const{state:e}=Qe(),t=Kt(),n=e.templateIdentifier,o=e.locale,r=e.selectedRoute?.layoutName??null,s=u.useCallback(p=>{try{const b=Pt.getInstance().translate(p,{templateId:n,locale:o});return b&&b!==p?b:""}catch{return""}},[n,o]),a=u.useCallback(p=>bd(p,s),[s]),l=u.useCallback(p=>{Et({op:"inline_edit_cancel",componentPath:p?at(p):null,timestamp:Date.now()})},[]),d=u.useCallback(async(p,f)=>{if(!t)return{kind:"error",message:"no document context"};const g={children:t.document?.raw?.components??[]},m=Pe(g,p),h=bd(m,s);if(!h.editable)return Et({op:"inline_edit_blocked_binding",sourceState:h.sourceState,componentPath:at(p),timestamp:Date.now()}),{kind:"blocked"};if(h.customKey){if(f===h.displayValue)return{kind:"noop",translationKey:h.customKey};So(n,o,h.customKey,f);const C=await wr(n,h.customKey,o,f);return C.kind==="error"?{kind:"error",message:C.message}:(await on(n,o),Et({op:"inline_edit_update_value",sourceState:"custom_key",componentPath:at(p),translationKey:h.customKey,toLocale:o,valueLength:f.length,valueHash:ji(f),timestamp:Date.now()}),{kind:"updated",translationKey:h.customKey})}const v=typeof m?.text=="string"?m.text:"",y=h.sourceState==="plain_with_binding",_=es(v,s),w=y?nd(_):f,k=C=>y?td(C,v):C;t.patchLayout(C=>Bt({children:C},p,E=>({...E,text:f})).children??[]);const x=await Yn(n,r,o,w);if(x.kind==="error"||!x.resource)return{kind:"error",message:x.message};const $=x.resource.translation_key;return So(n,o,$,w),t.patchLayout(C=>Bt({children:C},p,E=>({...E,text:k(`$t:${$}`)})).children??[]),await on(n,o),Et({op:"inline_edit_create_key",sourceState:h.sourceState,componentPath:at(p),translationKey:$,toLocale:o,valueLength:f.length,valueHash:ji(f),timestamp:Date.now()}),{kind:"created",translationKey:$,id:x.resource.id}},[t,n,o,r,s]),c=u.useCallback(async(p,f)=>{if(!t)return{kind:"error",message:"no document context"};const g={children:t.document?.raw?.components??[]},m=Pe(g,p),h=typeof m?.text=="string"?m.text:"",v=vt(h);if(v&&v.key.startsWith(xr))return kr(n,v.key,o,f),So(n,o,v.key,f),t.markDirty?.(),{kind:"updated",translationKey:v.key};const y=ns(h,s),_=mr(f.replace(/\{\{?p\d+\}?\}/g," ")).replace(/\s+/g," ").trim(),w=await Yn(n,r,o,_);if(w.kind==="error"||!w.resource)return{kind:"error",message:w.message};const k=w.resource.translation_key,x=Tn(f),$=w.resource.values??{},C={[o]:f};for(const S of Object.keys($)){if(S===o)continue;let D=$[S]??"";for(const E of x)D=Ri(D,E);C[S]=D}return Co(n,k,C),So(n,o,k,f),t.patchLayout(S=>Bt({children:S},p,I=>({...I,text:ed(`$t:${k}`,y)})).children??[]),t.markDirty?.(),await on(n,o),So(n,o,k,f),Et({op:"inline_edit_create_key",sourceState:"plain_with_binding",componentPath:at(p),translationKey:k,toLocale:o,valueLength:f.length,valueHash:ji(f),timestamp:Date.now()}),{kind:"created",translationKey:k}},[t,n,o,r]);return{classify:a,commit:d,trackCancel:l,keyifyChipValue:c}}async function Yn(e,t,n,o){const r=`/api/admin/templates/${encodeURIComponent(e)}/custom-translations`;try{const s=await fetch(r,{method:"POST",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({layout_name:t,locale:n,value:o})}),a=await s.json().catch(()=>null);if(!s.ok)return{kind:"error",message:a?.message??`HTTP ${s.status}`};const l=a?.data;return!l||typeof l.translation_key!="string"?{kind:"error",message:"invalid response"}:{kind:"ok",resource:l}}catch(s){return{kind:"error",message:s instanceof Error?s.message:"network error"}}}async function wr(e,t,n,o){const r=await fn(e,t);if(!r)return{kind:"error",message:"custom key not found"};const s=`/api/admin/templates/${encodeURIComponent(e)}/custom-translations/${r.id}`,a={...r.values??{},[n]:o};try{const l=await fetch(s,{method:"PUT",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({values:a,expected_lock_version:r.lock_version})}),d=await l.json().catch(()=>null);return l.status===409?{kind:"error",message:"concurrent_modification"}:l.ok?{kind:"ok"}:{kind:"error",message:d?.message??`HTTP ${l.status}`}}catch(l){return{kind:"error",message:l instanceof Error?l.message:"network error"}}}async function fn(e,t){const n=`/api/admin/templates/${encodeURIComponent(e)}/custom-translations`;try{const o=await fetch(n,{method:"GET",credentials:"same-origin",headers:Me()});if(!o.ok)return null;const s=(await o.json().catch(()=>null))?.data;return Array.isArray(s)?s.find(a=>a.translation_key===t)??null:null}catch{return null}}function So(e,t,n,o){try{Pt.getInstance().setTranslationValue(e,t,n,o)}catch{}if(typeof window<"u")try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:e,locale:t}}))}catch{}}const kt="g7le:translations-refreshed";async function on(e,t){if(typeof window>"u")return;const n=t??window.__g7EditorContentLocale;if(n){try{const o=Pt.getInstance();try{const r=await fetch(nn(`/api/templates/${encodeURIComponent(e)}/config`,"json"),{headers:{Accept:"application/json"},credentials:"same-origin"}).then(a=>a.ok?a.json():null),s=r?.data?.cache_version??r?.cache_version;if(typeof s=="number"&&s>0){o.setCacheVersion(s);const a=window;a.G7Config&&(a.G7Config.cache_version=s)}}catch{}await o.loadTranslations(e,n,"/api",!0)}catch{}try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:e,locale:n}}))}catch{}}}const rn=new Map;function kr(e,t,n,o){const r=rn.get(t)??{};r[n]=o,rn.set(t,r);try{Pt.getInstance().setTranslationValue(e,n,t,o)}catch{}if(typeof window<"u")try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:e,locale:n}}))}catch{}}function Co(e,t,n){for(const[o,r]of Object.entries(n))kr(e,t,o,r)}function It(e,t){return rn.get(e)?.[t]}function cm(e){const t=rn.get(e);return t?{...t}:void 0}function um(){return rn.size>0}function md(e,t){for(const[n,o]of rn.entries())for(const[r,s]of Object.entries(o))try{e.setTranslationValue(t,r,n,s)}catch{}}async function pm(e){if(rn.size===0)return{ok:0,failed:[]};const t=Array.from(rn.entries());let n=0;const o=[];for(const[r,s]of t)try{const a=await fn(e,r);if(!a){o.push(r);continue}const l={...a.values??{},...s},d=`/api/admin/templates/${encodeURIComponent(e)}/custom-translations/${a.id}`;if(!(await fetch(d,{method:"PUT",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({values:l,expected_lock_version:a.lock_version})})).ok){o.push(r);continue}n+=1}catch{o.push(r)}for(const[r]of t)o.includes(r)||rn.delete(r);try{await on(e)}catch{}return{ok:n,failed:o}}function Xn(e,t){const n=`layout_editor.locale.${e}`,o=t(n);return o&&o!==n?o:e.toUpperCase()}function vd(){if(typeof window>"u")return[];const t=window.G7Config?.appConfig?.supportedLocales;return Array.isArray(t)?t.filter(n=>typeof n=="string"&&n.length>0):[]}function fm({locales:e}={}){const{t}=et(),{state:n,dispatch:o}=Qe();u.useEffect(()=>{window.__g7EditorContentLocale=n.locale},[n.locale]);const r=e??vd(),s=r.includes(n.locale)?r:[n.locale,...r];if(s.length<=1)return i.jsxs("span",{className:"g7le-locale-switcher g7le-locale-switcher--single","data-testid":"g7le-locale-switcher-single",style:{fontSize:11,color:"#475569",padding:"0 4px"},children:[t("layout_editor.chrome.toolbar.locale_switcher_label"),": ",Xn(n.locale,t)]});const a=l=>{if(l===n.locale)return;const d=n.locale;o({type:"SET_LOCALE",locale:l}),Et({op:"locale_switch",fromLocale:d,toLocale:l,timestamp:Date.now()})};return i.jsxs("div",{className:"g7le-locale-switcher","data-testid":"g7le-locale-switcher",role:"group","aria-label":t("layout_editor.chrome.toolbar.locale_switcher_label"),style:{display:"inline-flex",alignItems:"center",gap:4},children:[i.jsx("span",{style:{fontSize:11,color:"#475569"},children:t("layout_editor.chrome.toolbar.locale_switcher_label")}),i.jsx("div",{style:{display:"inline-flex",gap:2},children:s.map(l=>{const d=l===n.locale;return i.jsx("button",{type:"button","data-testid":`g7le-locale-${l}`,"aria-pressed":d,onClick:()=>a(l),style:{padding:"2px 8px",fontSize:12,cursor:"pointer",background:d?"#0f172a":"#f8fafc",color:d?"#fff":"#0f172a",border:"1px solid #cbd5e1",borderRadius:4},children:Xn(l,t)},l)})})]})}const gm=/\{\{?(p\d+)\}?\}/g;function hm(e){const t=[];if(typeof e!="string"||e.length===0)return t;const n=new RegExp(gm.source,"g");let o=0,r;for(;(r=n.exec(e))!==null;){const s=r.index,a=s+r[0].length;s>o&&t.push({kind:"text",raw:e.slice(o,s),start:o,end:s}),t.push({kind:"chip",raw:r[0],paramName:r[1],start:s,end:a}),o=a}return o{n.push({kind:"text",text:a}),r=!0};for(const a of t)a.kind==="text"?(o=a.raw,s(o),o=""):(r||s(""),n.push({kind:"chip",paramName:a.paramName}),r=!1);return r||s(""),n}function bm(e,t,n,o){const r=[];return e.forEach((s,a)=>{if(s.kind==="chip"){if(s.paramName===t)return;r.push(`{${s.paramName}}`)}else{const l=s.text??"";if(a===n){const d=Math.max(0,Math.min(o,l.length));r.push(l.slice(0,d),`{${t}}`,l.slice(d))}else r.push(l)}}),r.join("")}function Sr({value:e,onChange:t,t:n,paramLabels:o,onRequestInsert:r,onRemoveChip:s,testIdSuffix:a="pc",disabled:l=!1,hideInsertButton:d=!1,caretRef:c}){const p=u.useMemo(()=>ym(e),[e]),f=u.useRef(null),[b,g]=u.useState(null),[m,h]=u.useState(null),[v,y]=u.useState(null),_=u.useMemo(()=>p.map(O=>O.kind==="chip"?`c:${O.paramName}`:"t").join("|"),[p]),w=u.useRef(null),k=u.useRef([]),x=u.useRef(!1);u.useLayoutEffect(()=>{const O=x.current;x.current=!1,!(!O&&w.current===_)&&(w.current=_,p.forEach((z,H)=>{if(z.kind!=="text")return;const P=k.current[H];P&&P.textContent!==(z.text??"")&&(P.textContent=z.text??"")}))},[_,p,e]);const $=()=>{const O=f.current;if(!O)return e;const z=[];for(const H of Array.from(O.querySelectorAll("[data-seg]")))H.dataset.seg==="chip"?z.push(`{${H.dataset.param??""}}`):z.push(H.textContent??"");return z.join("")},C=()=>{l||t($())},S=u.useRef(null),D=u.useRef(!1),E=(O,z)=>{if(!l){O.preventDefault(),O.stopPropagation(),S.current={param:z,pointerId:O.pointerId},D.current=!1,g(z);try{O.currentTarget.setPointerCapture(O.pointerId)}catch{}}},I=O=>{const z=S.current;if(!z||O.pointerId!==z.pointerId)return;D.current=!0;const H=B(O.clientX,O.clientY);H&&(h({slotIdx:H.slotIdx,offset:H.offset}),y(vm(f.current,H.slotIdx,H.offset)))},N=(O,z)=>{if(O.stopPropagation(),D.current){D.current=!1;return}s?.(z)},T=O=>{const z=S.current;if(!z||O.pointerId!==z.pointerId)return;try{O.currentTarget.releasePointerCapture(O.pointerId)}catch{}S.current=null,D.current&&typeof setTimeout=="function"&&setTimeout(()=>{D.current=!1},0);const H=B(O.clientX,O.clientY);if(g(null),h(null),y(null),!H)return;const P=f.current;if(!P)return;const L=Array.from(P.querySelectorAll("[data-seg]")).map(Y=>Y.dataset.seg==="chip"?{kind:"chip",paramName:Y.dataset.param??""}:{kind:"text",text:Y.textContent??""}),F=bm(L,z.param,H.slotIdx,H.offset);F!==e&&(x.current=!0,t(F))},B=(O,z)=>{const H=f.current;if(!H)return null;const P=Array.from(H.querySelectorAll("[data-seg]")),A=H.ownerDocument,L=A.elementFromPoint(O,z);let F=L?.closest('[data-seg="text"]');if(F)return{slotIdx:P.indexOf(F),offset:mm(A,F,O,z)};const Y=L?.closest('[data-seg="chip"]');if(Y){const X=P.indexOf(Y),Z=Y.getBoundingClientRect();if(O=0){const ie=P[X-1];return{slotIdx:X-1,offset:(ie.textContent??"").length}}if(X+1({s:X,i:Z})).filter(X=>X.s.dataset.seg==="text").pop();return V?{slotIdx:V.i,offset:(V.s.textContent??"").length}:null},M=()=>{l||!r||r(_d(f.current,e.length))};return u.useEffect(()=>{if(c)return c.current=()=>_d(f.current,e.length),()=>{c.current=null}},[c,e.length]),i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[i.jsxs("div",{ref:f,"data-testid":`g7le-chip-input-${a}`,className:"g7le-chip-input",style:_m,children:[p.map((O,z)=>O.kind==="chip"?i.jsxs("span",{"data-seg":"chip","data-param":O.paramName,"data-testid":`g7le-chip-${a}-${O.paramName}`,contentEditable:!1,onPointerDown:H=>E(H,O.paramName??""),onPointerMove:I,onPointerUp:T,title:n("layout_editor.translation.placeholder_locked"),style:{...Sm,...b===O.paramName?Cm:null,touchAction:"none"},children:[i.jsx("span",{"aria-hidden":"true",style:$m,children:"⠿"}),i.jsx("span",{"aria-hidden":"true",style:{marginRight:3},children:"🔗"}),i.jsx("span",{style:Em,children:o?.[O.paramName??""]??O.paramName}),s&&!l&&i.jsx("button",{type:"button","data-testid":`g7le-chip-remove-${a}-${O.paramName}`,"aria-label":n("layout_editor.inline_binding.clear"),title:n("layout_editor.inline_binding.clear"),onPointerDown:H=>{H.stopPropagation(),H.preventDefault()},onClick:H=>N(H,O.paramName??""),style:Im,children:"✕"})]},`chip-${O.paramName}`):i.jsx("span",{ref:H=>{k.current[z]=H},"data-seg":"text",contentEditable:!l,suppressContentEditableWarning:!0,onInput:C,"data-testid":`g7le-chip-text-${a}-${z}`,style:{...xm,...b?wm:null,...m?.slotIdx===z?km:null}},`text-slot-${z}`)),v&&i.jsx("span",{"aria-hidden":"true","data-testid":`g7le-chip-caret-${a}`,style:{position:"absolute",left:v.left,top:v.top,width:2,height:v.height,background:"#2563eb",borderRadius:1,pointerEvents:"none",boxShadow:"0 0 0 1px rgba(37,99,235,0.3)"}})]}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[r&&!d&&i.jsxs("button",{type:"button","data-testid":`g7le-chip-insert-${a}`,onClick:M,disabled:l,style:Am,children:["+ ",n("layout_editor.inline_binding.insert_data")]}),i.jsx("span",{style:Tm,children:n("layout_editor.translation.placeholder_locked")})]})]})}function mm(e,t,n,o){const r=(t.textContent??"").length;try{const a=e;let l=null,d=0;if(typeof a.caretRangeFromPoint=="function"){const c=a.caretRangeFromPoint(n,o);c&&(l=c.startContainer,d=c.startOffset)}else if(typeof a.caretPositionFromPoint=="function"){const c=a.caretPositionFromPoint(n,o);c&&(l=c.offsetNode,d=c.offset)}if(l&&t.contains(l))return Math.max(0,Math.min(d,r))}catch{}const s=t.getBoundingClientRect();return n>s.left+s.width/2?r:0}function vm(e,t,n){if(!e)return null;const r=Array.from(e.querySelectorAll("[data-seg]"))[t];if(!r)return null;const s=e.getBoundingClientRect();try{const d=r.firstChild,c=e.ownerDocument;if(d&&d.nodeType===Node.TEXT_NODE&&(d.textContent??"").length>0){const p=c.createRange(),f=Math.max(0,Math.min(n,(d.textContent??"").length));p.setStart(d,f),p.setEnd(d,f);const b=p.getClientRects(),g=b.length>0?b[0]:p.getBoundingClientRect();if(g&&(g.height>0||g.width>=0))return{left:g.left-s.left,top:g.top-s.top,height:g.height||r.getBoundingClientRect().height}}}catch{}const a=r.getBoundingClientRect();return{left:(n>0?a.right:a.left)-s.left,top:a.top-s.top,height:a.height||16}}function _d(e,t){if(!e)return t;try{const n=e.ownerDocument.defaultView?.getSelection();if(!n||n.rangeCount===0)return t;const o=n.getRangeAt(0);let r=o.startContainer,s=null;for(;r&&r!==e;){if(r instanceof HTMLElement&&r.dataset.seg==="text"){s=r;break}r=r.parentNode}if(!s||!e.contains(s))return t;const a=Array.from(e.querySelectorAll("[data-seg]"));let l=0;for(const d of a){if(d===s)break;l+=d.dataset.seg==="chip"?`{${d.dataset.param??""}}`.length:(d.textContent??"").length}return l+o.startOffset}catch{return t}}const _m={position:"relative",display:"flex",flexWrap:"wrap",alignItems:"center",gap:2,minHeight:30,padding:"4px 8px",border:"1px solid #cbd5e1",borderRadius:4,background:"#fff",fontSize:13,lineHeight:1.6},xm={outline:"none",minWidth:8,minHeight:"1.2em",whiteSpace:"pre-wrap",color:"#0f172a",display:"inline-block"},wm={boxShadow:"inset 0 -2px 0 #93c5fd",background:"#eff6ff",borderRadius:2},km={background:"#dbeafe",boxShadow:"inset 0 -2px 0 #2563eb"},Sm={display:"inline-flex",alignItems:"center",gap:1,background:"linear-gradient(180deg,#eff6ff,#dbeafe)",color:"#1d4ed8",border:"1px dashed #60a5fa",borderRadius:9999,padding:"1px 8px 1px 4px",margin:"0 1px",fontSize:12,fontWeight:600,cursor:"grab",userSelect:"none",whiteSpace:"nowrap",boxShadow:"0 1px 2px rgba(37,99,235,0.18)",verticalAlign:"middle"},Cm={opacity:.5,borderStyle:"solid",cursor:"grabbing"},$m={color:"#2563eb",opacity:.7,fontSize:11,marginRight:1,cursor:"grab"},Em={textDecoration:"none"},Im={marginLeft:4,width:14,height:14,lineHeight:"12px",padding:0,border:"none",borderRadius:9999,background:"rgba(29,78,216,0.12)",color:"#1d4ed8",fontSize:9,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto"},Am={fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#334155",padding:"3px 10px",cursor:"pointer"},Tm={fontSize:10,color:"#94a3b8"};function xd(e){e&&(e.style.height="auto",e.style.height=`${Math.max(e.scrollHeight,28)}px`)}function Dm(e){xd(e)}function zm(e){const t=new Set;for(const n of e)for(const o of Object.keys(n.values??{}))t.add(o);return Array.from(t).sort()}function Nm({templateIdentifier:e,layoutName:t,t:n,referencedKeys:o,onClose:r}){const[s,a]=u.useState([]),[l,d]=u.useState("idle"),[c,p]=u.useState(null),[f,b]=u.useState("all"),[g,m]=u.useState(new Set),[h,v]=u.useState({}),[y,_]=u.useState(null),[w,k]=u.useState({}),x=u.useCallback(async()=>{d("loading"),p(null);const z=await ab(e,t);z.ok?(a(z.data),v({}),m(new Set),k({}),d("idle")):(p(z.message),d("error"))},[e,t]);u.useEffect(()=>{x()},[x]);const $=u.useMemo(()=>zm(s),[s]),C=u.useMemo(()=>s.filter(z=>f==="all"?!0:z.status===f).slice().sort((z,H)=>{const P=z.updated_at?Date.parse(z.updated_at):0,A=H.updated_at?Date.parse(H.updated_at):0;return A!==P?A-P:H.id-z.id}),[s,f]),S=u.useMemo(()=>s.filter(z=>z.status==="orphaned"),[s]),D=u.useCallback(z=>{const H={...z.values??{}};for(const P of Object.keys(H)){const A=It(z.translation_key,P);A!==void 0&&(H[P]=A)}return H},[]),E=u.useCallback(z=>h[z.id]??D(z),[h,D]),I=u.useCallback((z,H,P)=>{v(A=>{const L=A[z]??s.find(F=>F.id===z)?.values??{};return{...A,[z]:{...L,[H]:P}}})},[s]),N=u.useCallback(async z=>{_(z.id),k(A=>({...A,[z.id]:""}));const H=E(z),P=await lb(e,z.id,H,z.lock_version);if(P.ok)a(A=>A.map(L=>L.id===z.id?P.data:L)),v(A=>{const L={...A};return delete L[z.id],L});else{const A=P.status===409?n("layout_editor.translation_manager.conflict"):P.message;k(L=>({...L,[z.id]:A}))}_(null)},[e,E,n]),T=u.useCallback(z=>typeof window<"u"&&typeof window.confirm=="function"?window.confirm(n("layout_editor.translation_manager.delete_confirm",{count:z})):!0,[n]),B=u.useCallback(async z=>{if(!T(1))return;const H=await db(e,z.id);H.ok?(a(P=>P.filter(A=>A.id!==z.id)),m(P=>{const A=new Set(P);return A.delete(z.id),A})):p(H.message)},[e,T]),M=u.useCallback(async z=>{if(z.length===0||!T(z.length))return;const H=await cb(e,z);if(H.ok){const P=new Set(z);a(A=>A.filter(L=>!P.has(L.id))),m(new Set)}else p(H.message)},[e,T]),O=u.useCallback(z=>{m(H=>{const P=new Set(H);return P.has(z)?P.delete(z):P.add(z),P})},[]);return i.jsxs("div",{className:"g7le-translation-manager","data-testid":"g7le-translation-manager",style:Mm,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:Lm,children:[i.jsx("span",{style:{fontSize:14,fontWeight:700},"data-testid":"g7le-translation-manager-title",children:n("layout_editor.translation_manager.title")}),i.jsx("button",{type:"button","aria-label":"close",onClick:r,style:Pm,"data-testid":"g7le-translation-manager-close",children:"✕"})]}),i.jsxs("div",{style:Om,children:[i.jsx("div",{style:{display:"inline-flex",gap:4},role:"tablist","aria-label":n("layout_editor.translation_manager.filter_label"),children:["all","active","orphaned"].map(z=>i.jsx("button",{type:"button",role:"tab","aria-selected":f===z,"data-active":f===z?"true":"false",onClick:()=>b(z),style:f===z?Bm:wd,"data-testid":`g7le-translation-filter-${z}`,children:n(`layout_editor.translation_manager.filter_${z}`)},z))}),i.jsx("div",{style:{flex:1}}),g.size>0&&i.jsxs("button",{type:"button",onClick:()=>void M(Array.from(g)),style:kd,"data-testid":"g7le-translation-bulk-delete",children:["🗑 ",n("layout_editor.translation_manager.delete_selected",{count:g.size})]}),S.length>0&&i.jsxs("button",{type:"button",onClick:()=>void M(S.map(z=>z.id)),style:kd,"data-testid":"g7le-translation-purge-orphaned",children:["🧹 ",n("layout_editor.translation_manager.purge_orphaned",{count:S.length})]})]}),c&&i.jsx("div",{style:Wm,"data-testid":"g7le-translation-manager-error",children:c}),i.jsx("div",{style:jm,children:l==="loading"?i.jsx("div",{style:Sd,"data-testid":"g7le-translation-manager-loading",children:n("layout_editor.translation_manager.loading")}):C.length===0&&l!=="error"?i.jsx("div",{style:Sd,"data-testid":"g7le-translation-manager-empty",children:n("layout_editor.translation_manager.empty")}):i.jsx("div",{"data-testid":"g7le-translation-list",style:Hm,children:C.map(z=>{const H=E(z),P=z.status==="orphaned",A=o?o.has(z.translation_key):null;return i.jsxs("div",{style:Fm,"data-testid":`g7le-translation-row-${z.id}`,children:[i.jsxs("div",{style:Km,children:[i.jsx("input",{type:"checkbox",checked:g.has(z.id),onChange:()=>O(z.id),"aria-label":n("layout_editor.translation_manager.select_aria",{key:z.translation_key}),"data-testid":`g7le-translation-select-${z.id}`}),i.jsx("code",{style:Vm,children:z.translation_key}),P&&i.jsx("span",{style:Um,"data-testid":`g7le-translation-badge-orphaned-${z.id}`,children:n("layout_editor.translation_manager.badge_orphaned")}),A===!0&&i.jsx("span",{style:qm,"data-testid":`g7le-translation-badge-live-inuse-${z.id}`,children:n("layout_editor.translation_manager.badge_live_in_use")}),A===!1&&i.jsx("span",{style:Gm,"data-testid":`g7le-translation-badge-live-unused-${z.id}`,children:n("layout_editor.translation_manager.badge_live_unused")}),i.jsx("div",{style:{flex:1}}),i.jsx("button",{type:"button",onClick:()=>void B(z),style:ev,"data-testid":`g7le-translation-delete-${z.id}`,children:"🗑"})]}),i.jsxs("div",{style:Ym,children:[$.map(L=>{const F=H[L]??"",Y=Tn(F).length>0;return i.jsxs("div",{style:Xm,"data-testid":`g7le-translation-field-${z.id}-${L}`,children:[i.jsxs("label",{style:Jm,title:L,children:[Xn(L,n),i.jsxs("span",{style:Zm,children:["(",L,")"]})]}),Y?i.jsx("div",{style:{flex:1},"data-testid":`g7le-translation-chip-${z.id}-${L}`,children:i.jsx(Sr,{value:F,onChange:V=>I(z.id,L,V),t:n,testIdSuffix:`${z.id}-${L}`})}):i.jsx("textarea",{value:F,rows:1,ref:Dm,onChange:V=>{I(z.id,L,V.currentTarget.value),xd(V.currentTarget)},style:Qm,"data-testid":`g7le-translation-input-${z.id}-${L}`})]},L)}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[i.jsx("button",{type:"button",disabled:y===z.id,onClick:()=>void N(z),style:Rm,"data-testid":`g7le-translation-save-${z.id}`,children:y===z.id?n("layout_editor.translation_manager.saving"):n("layout_editor.translation_manager.save")}),w[z.id]?i.jsx("span",{style:{fontSize:11,color:"#dc2626"},"data-testid":`g7le-translation-row-error-${z.id}`,children:w[z.id]}):null]})]})]},z.id)})})}),i.jsx("div",{style:tv,children:i.jsx("button",{type:"button",onClick:r,style:nv,"data-testid":"g7le-translation-manager-footer-close",children:n("layout_editor.translation_manager.close")})})]})}const Mm={display:"flex",flexDirection:"column",minHeight:0,flex:1},Lm={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #e2e8f0"},Pm={border:"none",background:"transparent",fontSize:16,color:"#94a3b8",cursor:"pointer"},Om={padding:"10px 16px",borderBottom:"1px solid #f1f5f9",display:"flex",gap:8,alignItems:"center"},wd={padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},Bm={...wd,borderColor:"#2563eb",background:"#eff6ff",color:"#1d4ed8",fontWeight:600},kd={padding:"4px 10px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},Wm={padding:"8px 16px",fontSize:12,color:"#b91c1c",background:"#fef2f2"},jm={padding:16,overflow:"auto",flex:1,minHeight:120,display:"flex",flexDirection:"column",gap:12},Sd={fontSize:13,color:"#94a3b8",textAlign:"center",padding:"32px 0"},Hm={display:"flex",flexDirection:"column",gap:20},Fm={border:"1px solid #e2e8f0",borderRadius:8,padding:10,display:"flex",flexDirection:"column",gap:6},Km={display:"flex",alignItems:"center",gap:8},Vm={fontSize:11,background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a"},Um={fontSize:10,color:"#b45309",background:"#fef3c7",padding:"1px 6px",borderRadius:4,fontWeight:600},qm={fontSize:10,color:"#15803d",background:"#dcfce7",padding:"1px 6px",borderRadius:4,fontWeight:600},Gm={fontSize:10,color:"#9f1239",background:"#ffe4e6",padding:"1px 6px",borderRadius:4,fontWeight:600},Ym={display:"flex",flexDirection:"column",gap:6},Xm={display:"flex",alignItems:"flex-start",gap:8},Jm={fontSize:12,color:"#475569",minWidth:88,fontWeight:600,paddingTop:4,display:"flex",flexDirection:"column",lineHeight:1.2},Zm={fontSize:10,color:"#94a3b8",fontWeight:400},Qm={flex:1,padding:"4px 8px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:4,color:"#0f172a",resize:"vertical",overflow:"hidden",minHeight:28,lineHeight:1.4,fontFamily:"inherit",boxSizing:"border-box"},Rm={padding:"5px 12px",fontSize:12,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},ev={padding:"4px 8px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},tv={padding:"10px 16px",borderTop:"1px solid #e2e8f0",display:"flex",justifyContent:"flex-end"},nv={padding:"6px 14px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"};function ov(){const e=Kt(),{state:t}=Qe(),n=e?.document?.raw??null,o=t.templateIdentifier??"",r=t.selectedRoute?.layoutName??"",s=u.useCallback((c,p)=>{const f=n?.[c];return f===void 0?p:f},[n]),a=u.useCallback((c,p,...f)=>{e&&(f.length>=1?e.patchDocumentRaw(c,p,f[0]):e.patchDocumentRaw(c,p))},[e]),l=u.useCallback(async(c,p)=>!o||!r?null:Yn(o,r,c,p),[o,r]),d=u.useCallback(async(c,p,f)=>o?wr(o,c,p,f):null,[o]);return{raw:n,getValue:s,patch:a,createI18nKey:l,updateI18nKeyValue:d}}function rv(e){const t=e.__source;return t&&(t.kind==="module"||t.kind==="plugin")&&t.identifier?`${t.kind}:${t.identifier}`:"template"}function Cd(e,t){if(!t)return null;const n=rv(e);if(n&&t.bySource){const a=t.bySource[n]?.[e.id];if(a!==void 0)return{value:a,match:{dataSourceId:e.id,resolvedBy:"spec_byId",sourceKey:n}}}const o=t.byDataSourceId?.[e.id];if(o!==void 0)return{value:o,match:{dataSourceId:e.id,resolvedBy:"spec_byId"}};const r=e.endpoint??"";if(t.byEndpointPattern&&typeof r=="string"&&r.length>0){for(const[s,a]of Object.entries(t.byEndpointPattern))if(iv(r,s))return{value:a,match:{dataSourceId:e.id,resolvedBy:"spec_byEndpoint"}}}return null}function ls(e,t){const n=Cd(e,t);if(n)return n;const o=e.fallback?.data;return o!==void 0?{value:{data:Array.isArray(o)?o:[o]},match:{dataSourceId:e.id,resolvedBy:"fallback"}}:{value:{},match:{dataSourceId:e.id,resolvedBy:"inferred"}}}function iv(e,t){const n=t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${n}$`).test(e)}function sv(e={}){const{spec:t,overrideSpec:n,onMatch:o}=e;return{has(r){return!0},resolve(r){const s=n?Cd(r,n):null,{value:a,match:l}=s??ls(r,t);if(o)try{o(l)}catch{}return a}}}const $d=Lt(),Ed=$d.DataBindingEngine,Id=$d.dataBindingEngine;_o("PipeRegistry");function av(e){let t=null,n=0;for(let o=0;o0?e[o-1]:"",a=o{const a=t[r],l=a==null?[]:String(a).split(",").map(d=>d.trim()).filter(Boolean);return l.length===0?"":l.join(" ?? ")+(s?" ?? ":"")});return n=n.replace(/\{(\w+)\}/g,(o,r)=>{const s=t[r];return s===void 0?o:s}),n}function Cr(e){const t=e.trim(),n=/^\{\{([\s\S]*)\}\}$/.exec(t);return n?n[1].trim():t}function Td(e){const t=e.trim();return/^\{\{[\s\S]*\}\}$/.test(t)?t:`{{ ${t} }}`}function Dd(e,t){const n={};for(const[r,s]of Object.entries(t))n[r]=typeof s=="string"?Cr(s):s;const o=dv(e.expr,n);return Td(o)}function cv(e,t){if(typeof e!="string")return null;const n=zd(Cr(e));for(const o of t){const r=uv(n,o.expr,o.params);if(r)return{recipeId:o.id,params:r}}return null}function zd(e){return e.replace(/\s+/g," ").trim()}function Nd(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function uv(e,t,n){const o=[],r=new Set;let s="";const a=/\{(\w+)(\*?)\}(\s*\?\?\s*)?/g;let l=0,d;const c=zd(t);for(;(d=a.exec(c))!==null;){const g=c.slice(l,d.index);s+=Nd(g).replace(/\\ /g,"\\s*");const m=d[2]==="*",h=!!d[3];m?(r.add(d[1]),s+="(.*?)",h&&(s+="(?:\\s*\\?\\?\\s*)?")):(s+="(.+?)",h&&(s+="\\s*\\?\\?\\s*")),o.push(d[1]),l=a.lastIndex}s+=Nd(c.slice(l)).replace(/\\ /g,"\\s*");let p;try{p=new RegExp(`^${s}$`)}catch{return null}const f=p.exec(e);if(!f)return null;const b={};if(o.forEach((g,m)=>{let h=(f[m+1]??"").trim();r.has(g)&&(h=h.split(/\s*\?\?\s*/).map(v=>v.trim()).filter(Boolean).join(", ")),b[g]=h}),n.length>0){const g=new Set(n.map(m=>m.key));for(const m of Object.keys(b))g.has(m)||delete b[m]}return b}function pv(e){const t=`x.${e.field}`,n=fv(e.value);switch(e.cmp){case"=":return`${t} === ${n}`;case"!=":return`${t} !== ${n}`;case">":return`${t} > ${n}`;case"<":return`${t} < ${n}`;case">=":return`${t} >= ${n}`;case"<=":return`${t} <= ${n}`;case"includes":return`(${t} ?? []).includes(${n})`;default:return`${t} === ${n}`}}function fv(e){const t=e.trim();return t==="true"||t==="false"||t!==""&&!Number.isNaN(Number(t))||/^['"].*['"]$/.test(t)||/[.([{]/.test(t)?t:`'${t.replace(/'/g,"\\'")}'`}function ds(e){return!e||e.length===0?"true":e.map(pv).join(" && ")}function gv(e){const n=`(${(e.source??"").trim()||"[]"} ?? [])`;let o;switch(e.op){case"count":o=`${n}.filter(x => ${ds(e.conditions)}).length`;break;case"sum":{const r=(e.sumField??"").trim()||"value";o=`${n}.filter(x => ${ds(e.conditions)}).reduce((s, x) => s + (x.${r} ?? 0), 0)`;break}case"filter":o=`${n}.filter(x => ${ds(e.conditions)})`;break;case"toOptions":{const r=(e.valueField??"").trim()||"value",s=(e.labelField??"").trim()||"label";o=`${n}.map(x => ({ value: x.${r}, label: x.${s} }))`;break}case"nth":{const r=(e.index??"").trim()||"0",s=(e.prop??"").trim();o=`${n}[${r}]${s?`?.${s}`:""}`;break}case"firstOf":{const r=(e.candidates??[]).map(l=>l.trim()).filter(Boolean),s=r.length>0?r.join(" ?? "):"''",a=(e.fallback??"").trim();o=a?`${s} ?? '${a.replace(/'/g,"\\'")}'`:s;break}case"literal":{const r=e.literalKind??"string",s=(e.literalValue??"").trim();r==="number"?o=s===""?"0":s:r==="boolean"?o=s==="true"?"true":"false":o=`'${s.replace(/'/g,"\\'")}'`;break}default:o="[]"}return Td(o)}function hv(e){if(typeof e!="string")return null;const t=Cr(e).trim();let n=/^\((.+?)\s*\?\?\s*\[\]\)\.filter\(x => (.+)\)\.length$/.exec(t);return n?{key:"",op:"count",source:n[1].trim(),conditions:cs(n[2])}:(n=/^\((.+?)\s*\?\?\s*\[\]\)\.filter\(x => (.+)\)\.reduce\(\(s, x\) => s \+ \(x\.(\w+(?:\.\w+)*) \?\? 0\), 0\)$/.exec(t),n?{key:"",op:"sum",source:n[1].trim(),conditions:cs(n[2]),sumField:n[3]}:(n=/^\((.+?)\s*\?\?\s*\[\]\)\.filter\(x => (.+)\)$/.exec(t),n?{key:"",op:"filter",source:n[1].trim(),conditions:cs(n[2])}:(n=/^\((.+?)\s*\?\?\s*\[\]\)\.map\(x => \(\{ value: x\.(\w+(?:\.\w+)*), label: x\.(\w+(?:\.\w+)*) \}\)\)$/.exec(t),n?{key:"",op:"toOptions",source:n[1].trim(),valueField:n[2],labelField:n[3]}:(n=/^\((.+?)\s*\?\?\s*\[\]\)\[(.+?)\](?:\?\.(\w+(?:\.\w+)*))?$/.exec(t),n?{key:"",op:"nth",source:n[1].trim(),index:n[2].trim(),prop:n[3]}:null))))}function cs(e){const t=e.trim();if(t==="true")return[];const n=[];for(const o of yv(t)){const r=bv(o.trim());r&&n.push(r)}return n}function yv(e){const t=[];let n=0,o=0;for(let r=0;r=|<=|>|<)\s*(.+)$/.exec(e),t){const n={"===":"=","!==":"!=",">":">","<":"<",">=":">=","<=":"<="};return{field:t[1],cmp:n[t[2]]??"=",value:Md(t[3])}}return null}function Md(e){const t=e.trim(),n=/^'(.*)'$/.exec(t)||/^"(.*)"$/.exec(t);return n?n[1]:t}function Ld(e,t){const n=cv(e,t);if(n)return{kind:"preset",recipeId:n.recipeId,params:n.params};const o=hv(e);return o?{kind:"custom",model:o}:{kind:"advanced"}}function mv(e){if(e==null)return"null";if(Array.isArray(e))return"list";switch(typeof e){case"number":return"number";case"boolean":return"boolean";case"string":return"string";default:return"object"}}function Pd(e,t){if(typeof e!="string"||e.trim()==="")return{ok:!1,reason:"empty"};const n=Cr(e);try{const o=av(n)?Id.evaluatePipeExpression(n,t??{},{skipCache:!0}):Id.evaluateExpression(n,t??{},{skipCache:!0});return{ok:!0,value:o,type:mv(o)}}catch(o){return{ok:!1,reason:o instanceof Error?o.message:String(o)}}}function Od(e,t){const n=Array.isArray(e?.data_sources)?e.data_sources:[],o=[];for(const r of n){const s=r?.id;if(typeof s!="string"||s.length===0)continue;const{value:a}=ls(r,t?.sampleData),l=typeof r.label_key=="string"?r.label_key:void 0;o.push({id:s,sample:a,labelKey:l})}return o}function Bd(e,t){const n=[];t?.sampleGlobal&&typeof t.sampleGlobal=="object"&&n.push({scope:"_global",tree:t.sampleGlobal});const o={},r={},s={},a=(l,d)=>{if(!(!d||typeof d!="object"||Array.isArray(d)))for(const[c,p]of Object.entries(d))if(p&&typeof p=="object"&&!Array.isArray(p)){const f=l[c]&&typeof l[c]=="object"&&!Array.isArray(l[c])?l[c]:l[c]={};a(f,p)}else c in l||(l[c]=p)};for(const l of t?.states?.groups??[])for(const d of l.items??[]){const c=d.initialState;c?.local&&a(o,c.local),c?.query&&a(r,c.query),c?.route&&a(s,c.route)}return Object.keys(o).length&&n.push({scope:"_local",tree:o}),Object.keys(r).length&&n.push({scope:"query",tree:r}),Object.keys(s).length&&n.push({scope:"route",tree:s}),e?.computed&&typeof e.computed=="object"&&!Array.isArray(e.computed)&&n.push({scope:"_computed",tree:e.computed}),n}function Wd(e,t){const n={};for(const r of t)r.scope!=="_computed"&&(n[r.scope]=r.tree);const o={};for(const[r,s]of Object.entries(e)){if(typeof s!="string"){o[r]=s;continue}const a=Pd(s,n);o[r]=a.ok?a.value:s}return o}function vv(e,t){const n=Od(e,t),o=Bd(e,t),r={};for(const s of n)s.sample!==void 0&&(r[s.id]=s.sample);for(const s of o)s.scope==="_computed"?r[s.scope]=Wd(s.tree,o):r[s.scope]=s.tree;return r}function jd(e){const{raw:t,spec:n,evaluateComputed:o}=e;return u.useMemo(()=>{const r=Od(t,n),s=Bd(t,n);if(o){const a=s.findIndex(l=>l.scope==="_computed");if(a>=0){const l=Wd(s[a].tree,s);s[a]={scope:"_computed",tree:l}}}return Yi({dataSources:r,states:s,spec:n??void 0})},[t,n,o])}function _v(e){const{raw:t,spec:n,pageType:o}=e;return u.useMemo(()=>{const r=Array.isArray(t?.data_sources)?t.data_sources:[],s=[];for(const d of r){const c=d?.id;if(typeof c!="string"||c.length===0)continue;const{value:p}=ls(d,n?.sampleData),f=typeof d.label_key=="string"?d.label_key:void 0;s.push({id:c,sample:p,labelKey:f})}const a=[];n?.sampleGlobal&&typeof n.sampleGlobal=="object"&&a.push({scope:"_global",tree:n.sampleGlobal}),t?.computed&&typeof t.computed=="object"&&!Array.isArray(t.computed)&&a.push({scope:"_computed",tree:t.computed});const l=Yi({dataSources:s,states:a,spec:n??void 0});if(typeof o=="string"&&o!=="")for(const d of["title","description"])l.push({expression:`{{_seo.${o}.${d}}}`,source:"_seo",sourceId:"_seo",path:`${o}.${d}`,shape:"scalar",preview:""});return l},[t,n,o])}function Hd(e,t){const n=[],o=new Set,r=s=>{for(const a of s??[]){if(a.kind==="route"&&!a.isRedirect&&typeof a.path=="string"&&a.path.startsWith("/")&&!o.has(a.path)){o.add(a.path);const l=a.label.startsWith("$t:")?a.label.slice(3):a.label,d=a.label.startsWith("$t:")?t(l):l,c=d&&d!==l&&!d.startsWith("$t:")?d:"";n.push({value:a.path,label:c?`${c} (${a.path})`:a.path})}r(a.children)}};return r(e),n}function Fd(e){const t=Array.isArray(e?.data_sources)?e.data_sources:[],n=[];for(const o of t){const r=o?.id;typeof r=="string"&&r.length>0&&n.push({value:r,label:r})}return n}function us(e,t){const n=typeof e.id=="string"?e.id:"",o=typeof e.label_key=="string"?e.label_key:"";if(!o)return null;const r=o.startsWith("$t:")?o.slice(3):o,s=t(r);return s&&s!==r&&!s.startsWith("$t:")&&s!==n?s:null}function ps(e,t){const n=e.__source;if(!n||typeof n!="object"||Array.isArray(n))return null;const o=n;if(o.kind!=="extension")return null;const r=o.extensionSourceType==="plugin"?t("layout_editor.data_sources.source.plugin"):t("layout_editor.data_sources.source.module"),s=typeof o.extensionIdentifier=="string"?o.extensionIdentifier:"",a=typeof o.extensionName=="string"?o.extensionName:"",l=a&&a!==s?`${a} (${s})`:s;return l?`${r}: ${l}`:r}function xv(e,t,n){const o=Array.isArray(e?.data_sources)?e.data_sources:[],r=[],s=new Set;for(const a of o){const l=a?.id;typeof l!="string"||l.length===0||s.has(l)||(s.add(l),r.push({id:l,friendly:us(a,t),source:ps(a,n)}))}return r}function Kd(e){const t=e?.states?.groups??[],n=new Set;for(const o of t)for(const r of o.items??[]){for(const s of Object.keys(r.initialState?.local??{}))n.add(s);for(const s of Object.keys(r.initialState?.global??{}))n.add(s)}return Array.from(n).map(o=>({value:o,label:o}))}function wv(e,t){const n=Array.isArray(e?.modals)?e.modals:[],o=[],r=new Set;for(const s of n){const a=s?.id;typeof a!="string"||a.length===0||r.has(a)||(r.add(a),o.push({value:a,label:kv(s,a,t)}))}return o}function kv(e,t,n){const r=e?.meta?.editor_label;if(typeof r=="string"&&r.length>0)return Vd(r,n);const s=e?.title;return typeof s=="string"&&s.length>0?Vd(s,n):t}function Vd(e,t){if(e.startsWith("$t:")){const n=e.slice(3),o=t?t(n):n;return o&&o!==n?o:n}return e}const Ud=_o("ActionRecipeEngine"),Sv={api:"apiCall",nav:"navigate",showToast:"toast",setLocalState:"setState"},Cv=new Set(["comment"]);function $o(e){if(!e||typeof e!="object")return[];const t=[];for(const[n,o]of Object.entries(e)){if(Cv.has(n)||!o||typeof o!="object")continue;const r=o,s=r.build&&typeof r.build=="object"?r.build:typeof r.handler=="string"?{handler:r.handler}:void 0;!s||typeof s.handler!="string"||s.handler.length===0||t.push({id:n,label:typeof r.label=="string"?r.label:void 0,params:Array.isArray(r.params)?r.params:[],build:s})}return t}function sn(e){const t=/^\{\{\s*([\w.]+)\s*\}\}$/.exec(e);return t?t[1]:null}const $r="...";function $v(e,t){return e.replace(/\{\{\s*([\w.]+)\s*\}\}/g,(n,o)=>{const r=t[o];return r==null?"":String(r)})}function fs(e,t){if(typeof e=="string"){const n=sn(e);return n!==null?n in t?t[n]:void 0:e.includes("{{")?$v(e,t):e}if(Array.isArray(e))return e.map(n=>fs(n,t)).filter(n=>n!==void 0);if(e&&typeof e=="object"){const n={};for(const[o,r]of Object.entries(e)){if(o===$r&&typeof r=="string"){const d=sn(r),c=d!==null?t[d]:void 0;if(c&&typeof c=="object"&&!Array.isArray(c))for(const[p,f]of Object.entries(c))f===void 0||p===""||(n[p]=f);continue}const s=fs(r,t);if(s===void 0||Array.isArray(s)&&s.length===0&&(o==="onSuccess"||o==="onError"))continue;const a=sn(o),l=a!==null?a in t?String(t[a]):null:o;l===null||l===""||s&&typeof s=="object"&&!Array.isArray(s)&&Object.keys(s).length===0||(n[l]=s)}return n}return e}function Ev(e){const t=e.handler;if(typeof t!="string")return e;const n=Sv[t];if(n)return Ud.warn(`action recipe used forbidden handler "${t}" — corrected to "${n}" (core handler rules)`),{...e,handler:n};if(t==="apiCall"||t==="navigate"){const o=e.params;if(o&&typeof o=="object")for(const r of["target","onSuccess","onError"])r in o&&Ud.warn(`action recipe build placed "${r}" inside params for handler "${t}" — should be top-level (core handler rules)`)}return e}function Er(e,t){const n=fs(e.build,t);if(typeof n.handler!="string"&&e.build.handler.includes("{{")&&(n.handler=e.build.handler),e.build.handler.includes("{{")){const o=new Set(e.params.filter(r=>r.required).map(r=>r.key));o.size>0&&qd(e.build,n,o)}return Ev(n)}function qd(e,t,n){if(!e||typeof e!="object"||Array.isArray(e)||!t||typeof t!="object"||Array.isArray(t))return;const o=e,r=t;for(const[s,a]of Object.entries(o))if(s!=="handler"){if(typeof a=="string"){const l=sn(a);l!==null&&n.has(l)&&!(s in r)&&(r[s]=a)}else if(a&&typeof a=="object"){if(!(s in r)||typeof r[s]!="object"||r[s]===null)if(JSON.stringify(a).includes("{{"))r[s]={};else continue;qd(a,r[s],n)}}}function Iv(e,t){if(!e||typeof e!="object")return null;const n=e.handler;if(typeof n!="string")return null;let o=null,r=-1;for(const s of t){const a=s.build.handler.includes("{{");if(!a&&s.build.handler!==n||a&&!Av(s.build,e))continue;const l=Tv(s.build,e);if(l===null)continue;const d=Object.keys(l).length;d>r&&(r=d,o={recipeId:s.id,values:l})}return o}function Av(e,t){if(typeof t.handler=="string"&&t.handler===e.handler)return!0;const n=e.params;if(!n||typeof n!="object")return!1;const o=t.params;if(!o||typeof o!="object")return!1;const r=o,s=Object.entries(n).filter(([,a])=>typeof a=="string"&&sn(a)!==null);return s.length===0?!1:s.every(([a])=>a in r)}function Tv(e,t){const n={},o=(r,s)=>{if(typeof r=="string"){const a=sn(r);return a!==null?(n[a]=s,!0):r.includes("{{")?typeof s=="string":r===s}if(Array.isArray(r))return Array.isArray(s);if(r&&typeof r=="object"){if(!s||typeof s!="object"||Array.isArray(s))return!1;const a=s,l=r[$r],d=typeof l=="string"?sn(l):null,c=new Set(Object.keys(r).filter(p=>p!==$r));for(const[p,f]of Object.entries(r))if(p!==$r){if(typeof f=="string"&&sn(f)!==null){const b=sn(f);p in a&&(n[b]=a[p]);continue}if(!(p in a)){if(p==="onSuccess"||p==="onError"||p==="params"||p==="identity_target")continue;return!1}if(!o(f,a[p]))return!1}if(d!==null){const p={};for(const[f,b]of Object.entries(a))c.has(f)||(p[f]=b);Object.keys(p).length>0&&(n[d]=p)}return!0}return r===s};return o(e,t)?n:null}function Jn(e,t){const n=typeof e?.handler=="string"?e.handler:"",o=Iv(e,t);return o?{kind:"preset",recipeId:o.recipeId,values:o.values,handler:n}:{kind:"advanced",handler:n}}function Gd(e,t,n){const o=e?.label,r=o?n?n(o):o:"",s=[],a=e?.params??[];for(const l of a){if(l.advanced||l.widget==="action-list")continue;const d=t[l.key];if(d==null||d==="")continue;const c=Dv(d);if(c!==""&&(s.push(c),s.length>=2))break}return s.length===0?r:`${r} (${s.join(", ")})`}function Dv(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):Array.isArray(e)?`[${e.length}]`:e&&typeof e=="object"?"{…}":""}function Yd(e,t){const n={...e};return typeof t=="string"&&t.trim().length>0?n.if=t.trim():delete n.if,n}function gs(e){const t=e?.if;return typeof t=="string"&&t.trim().length>0?t:null}const zv=/^\s*\$t:(custom\.[a-zA-Z0-9._-]+)\s*$/,Nv=/^\s*\$t:([a-zA-Z0-9._-]+)\s*$/,Mv=/\{\{.*?\}\}/;function Xd(e,t){const n=typeof e=="string"?e:"",o=zv.exec(n);if(o){const a=o[1],l=t?t(a):"";return{customKey:a,binding:!1,paramKey:!1,displayValue:l}}const r=vt(n);if(r&&r.key.startsWith("custom.")){const a=t?t(r.key):"";return{customKey:r.key,binding:!1,paramKey:!0,displayValue:a}}if(Mv.test(n))return{customKey:null,binding:!0,paramKey:!1,displayValue:n};const s=Nv.exec(n);if(s){const a=s[1],l=t?t(a):"";return{customKey:null,binding:!1,paramKey:!1,displayValue:l&&l!==a?l:""}}return{customKey:null,binding:!1,paramKey:!1,displayValue:n}}function Lv(){const{state:e}=Qe(),t=e.templateIdentifier,n=e.locale,o=e.selectedRoute?.layoutName??null,r=u.useCallback(l=>{try{const c=Pt.getInstance().translate(l,{templateId:t,locale:n});return c&&c!==l?c:""}catch{return""}},[t,n]),s=u.useCallback(l=>Xd(l,r),[r]),a=u.useCallback(async(l,d)=>{const c=Xd(l,r);if(c.binding)return{kind:"blocked"};if(c.customKey){if(d===c.displayValue)return{kind:"noop",customKey:c.customKey};const b=await wr(t,c.customKey,n,d);return b.kind==="error"?{kind:"error",message:b.message}:(await on(t,n),{kind:"updated",customKey:c.customKey})}const p=await Yn(t,o,n,d);if(p.kind==="error"||!p.resource)return{kind:"error",message:p.message};const f=p.resource.translation_key;return await on(t,n),{kind:"created",customKey:f,token:`$t:${f}`}},[t,n,o,r]);return{locale:n,templateIdentifier:t,translate:r,classify:s,commitText:a}}async function hs(e,t,n,o,r,s,a,l,d,c){const p=c?ns(o,c):null,f=!!(p&&p.keyifiable),b=d?d(o):o,g=f?p.chipValue:nd(b),h=`p${f?p.bindings.length:yr(b).length}`,v=Math.max(0,Math.min(r,g.length)),y=Xl(g,v,h),_=mr(y).replace(/\{\{?p\d+\}?\}/g," ").replace(/\s+/g," ").trim(),w=_.length>0?_:y,k=await Yn(e,t,n,w);if(k.kind==="error"||!k.resource)return{kind:"error",message:k.message};const x=k.resource.translation_key,$=Tn(y),C=k.resource.values??{},S={[n]:y};for(const N of Object.keys(C)){if(N===n)continue;let T=C[N]??"";for(const B of $)T=Ri(T,B);S[N]=T}Co(e,x,S);const D=In(s,a,l);return{kind:"ok",text:`${f?ed(`$t:${x}`,p):td(`$t:${x}`,b)}|${h}=${D}`,key:x}}async function Ir(e,t,n,o,r,s,a){let l=vt(n);if(!l&&typeof n=="string"){const h=/^\s*\$t:(custom\.[A-Za-z0-9._-]+)\s*$/.exec(n);h&&(l={key:h[1],params:[]})}if(!l)return{kind:"error",message:"not a param key"};if(!l.key.startsWith("custom."))return{kind:"error",message:"not a custom param key"};const d=Wb(l.params.map(h=>h.name)),c=In(r,s,a),p=`${n.trim()}|${d}=${c}`,f=await fn(e,l.key),b=cm(l.key)??{},g=new Set([...Object.keys(f?.values??{}),...Object.keys(b),t]);if(g.size===0)return{kind:"error",message:"custom key not found"};const m={};for(const h of g){const v=It(l.key,h)??f?.values?.[h]??"";m[h]=h===t?Xl(v,o,d):Ri(v,d)}return Co(e,l.key,m),{kind:"ok",text:p,paramName:d}}async function Eo(e,t,n,o){return kr(e,t,n,o),{kind:"ok"}}async function Pv(e,t,n){const o=await fn(e,t);if(!o)return{kind:"error",message:"custom key not found"};const r={};for(const[s,a]of Object.entries(o.values??{})){const l=It(t,s)??a;r[s]=n(l)}Co(e,t,r);try{const s=Pt.getInstance();for(const[a,l]of Object.entries(r))s.setTranslationValue(e,a,t,l)}catch{}return{kind:"ok"}}function Jd(e,t,n){return Pv(e,t,o=>id(o,n))}function Zd(e,t){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:e,locale:t}}))}catch{}}async function Ar(e,t,n,o){const r=await Jd(e,t,n);return Zd(e,o),r}const Ov=/^\s*\$t:(custom\.[a-zA-Z0-9._-]+)\s*$/;function Bv(e,t){const n=s=>{const a=[],l=/\{\{?(p\d+)\}?\}/g;let d;for(;(d=l.exec(s))!==null;)a.push(d[1]);return a},o=n(e),r=n(t);return o.length!==r.length?!0:o.some((s,a)=>s!==r[a])}function Qd(e){const t=e.text;if(typeof t!="string")return null;const n=Ov.exec(t);if(n)return n[1];const o=vt(t);return o&&o.key.startsWith("custom.")?o.key:null}function ys(e){const t={},n=vt(typeof e=="string"?e:"");for(const o of n?.params??[])t[o.name]=Ut(o.expression);return t}function Wv(e){return ys(typeof e.text=="string"?e.text:"")}function Rd({customKey:e,templateIdentifier:t,t:n,paramLabels:o,locales:r,onRemoveParam:s}){const a=r??vd(),l=Kt(),d=o??{},[c,p]=u.useState({status:"idle",values:{}}),[f,b]=u.useState(!1),[g,m]=u.useState(!1),[h,v]=u.useState(null),y=u.useRef({});u.useEffect(()=>{let E=!1;if(!e){p({status:"not_a_key",values:{}});return}return p({status:"loading",values:{}}),(async()=>{const I=await fn(t,e);if(E)return;if(!I){p({status:"error",values:{}});return}const N={...I.values??{}};for(const T of Object.keys(N)){const B=It(e,T);B!==void 0&&(N[T]=B)}for(const T of a){const B=It(e,T);B!==void 0&&(N[T]=B)}y.current={...N},p({status:"loaded",id:I.id,lockVersion:I.lock_version,values:N})})(),()=>{E=!0}},[e,t]),u.useEffect(()=>{if(typeof window>"u"||!e)return;const E=I=>{const N=I.detail;N?.templateIdentifier&&N.templateIdentifier!==t||p(T=>{if(T.status!=="loaded")return T;let B=!1;const M={...T.values};for(const O of Object.keys(M)){const z=It(e,O);z!==void 0&&z!==M[O]&&(M[O]=z,B=!0)}return B?(y.current={...y.current,...M},{...T,values:M}):T})};return window.addEventListener(kt,E),()=>window.removeEventListener(kt,E)},[e,t]);const _=u.useCallback((E,I)=>{p(N=>{const T=N.values[E]??"",B={...N,values:{...N.values,[E]:I}};return e&&Bv(T,I)&&(kr(t,e,E,I),y.current={...y.current,[E]:I},l?.markDirty?.(),Zd(t,E)),B})},[e,t,l]),w=u.useCallback(E=>{p(I=>{const N={};for(const[T,B]of Object.entries(I.values))N[T]=id(B,E);return y.current={...N},{...I,values:N}}),s?.(E)},[s]),k=u.useMemo(()=>[...Object.values(c.values),...Object.values(y.current)].some(I=>Tn(I).length>0),[c.values]),x=u.useRef(null),$=u.useCallback(()=>{m(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>m(!1),1500)},[]);u.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]);const C=u.useCallback(async()=>{if(m(!1),c.status!=="loaded"||c.id===void 0)return;const E=y.current;for(const[N,T]of Object.entries(c.values)){const B=E[N]??"";if(k){const M=Tn(B);if(M.length===0)continue;const O=Tn(T);if(!(M.length===O.length&&M.every((H,P)=>H===O[P]))){v(n("layout_editor.translation.placeholder_mismatch"));return}continue}if(br(B)&&!Gb(B,T)){v(n("layout_editor.translation.token_mismatch"));return}}if(b(!0),v(null),k){Co(t,e??"",c.values),y.current={...c.values},l?.markDirty?.(),Et({op:"translation_field_update",translationKey:e,changedLocales:Object.keys(c.values),timestamp:Date.now()}),await new Promise(N=>setTimeout(N,0)),b(!1),$();return}const I=`/api/admin/templates/${encodeURIComponent(t)}/custom-translations/${c.id}`;try{const N=await fetch(I,{method:"PUT",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({values:c.values,expected_lock_version:c.lockVersion??0})}),T=await N.json().catch(()=>null);if(N.status===409){v(n("layout_editor.translation.conflict"));return}if(!N.ok){v(T?.message??n("layout_editor.translation.save_failed"));return}const B=typeof T?.data?.lock_version=="number"?T.data.lock_version:(c.lockVersion??0)+1;p(M=>({...M,lockVersion:B})),y.current={...c.values},await on(t),Et({op:"translation_field_update",translationKey:e,changedLocales:Object.keys(c.values),timestamp:Date.now()}),$()}catch(N){v(N instanceof Error?N.message:n("layout_editor.translation.save_failed"))}finally{b(!1)}},[c,t,e,n]);if(c.status==="not_a_key"||!e)return i.jsx("div",{"data-testid":"g7le-translation-not-a-key",style:bs,children:n("layout_editor.translation.not_a_key")});if(c.status==="loading"||c.status==="idle")return i.jsx("div",{"data-testid":"g7le-translation-loading",style:bs,children:n("layout_editor.translation.loading")});if(c.status==="error")return i.jsx("div",{"data-testid":"g7le-translation-error",style:bs,children:n("layout_editor.translation.load_failed")});const S=new Set([...a,...Object.keys(c.values)]),D=Array.from(S);return i.jsxs("div",{"data-testid":"g7le-translation-field",style:{display:"flex",flexDirection:"column",gap:8},children:[i.jsxs("div",{"data-testid":"g7le-translation-key",style:jv,children:[n("layout_editor.translation.key_label"),": ",i.jsx("code",{style:Hv,children:e})]}),D.map(E=>{const I=c.values[E]??"",N=I.trim().length===0;return i.jsxs("div",{className:"g7le-translation-row","data-testid":`g7le-translation-row-${E}`,style:Fv,children:[i.jsxs("label",{htmlFor:`g7le-translation-input-${E}`,style:{fontSize:12,color:"#475569",minWidth:72,display:"inline-flex",alignItems:"center",gap:4},children:[Xn(E,n),N&&i.jsx("span",{"data-testid":`g7le-translation-missing-${E}`,style:Kv,children:n("layout_editor.translation.needs_translation")})]}),k?i.jsx("div",{style:{flex:1},"data-testid":`g7le-translation-chip-${E}`,children:i.jsx(Sr,{value:I,onChange:T=>_(E,T),t:n,paramLabels:d,testIdSuffix:E,onRemoveChip:s?w:void 0})}):i.jsx("input",{id:`g7le-translation-input-${E}`,type:"text","data-testid":`g7le-translation-input-${E}`,value:I,placeholder:N?n("layout_editor.translation.needs_translation"):"",onChange:T=>_(E,T.currentTarget.value),onBlur:C,style:{flex:1,padding:"4px 8px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:4,color:N?"#94a3b8":"#0f172a"}})]},E)}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[i.jsx("button",{type:"button","data-testid":"g7le-translation-save",disabled:f,onClick:C,style:Vv,children:n(f?"layout_editor.translation.saving":"layout_editor.translation.save")}),g&&!f&&i.jsxs("span",{"data-testid":"g7le-translation-saved",style:{fontSize:11,color:"#16a34a",display:"inline-flex",alignItems:"center",gap:4},children:["✓ ",n("layout_editor.translation.saved")]}),h&&i.jsx("span",{"data-testid":"g7le-translation-save-error",style:{fontSize:11,color:"#dc2626"},children:h})]})]})}const bs={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},jv={fontSize:12,color:"#475569"},Hv={fontSize:11,background:"#f1f5f9",padding:"1px 4px",borderRadius:3,color:"#0f172a"},Fv={display:"flex",alignItems:"center",gap:8},Kv={fontSize:10,color:"#b45309",background:"#fef3c7",padding:"0 4px",borderRadius:3},Vv={padding:"6px 12px",fontSize:12,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"};function Zn({anchorRef:e,open:t,onClose:n,children:o,placement:r="bottom",minWidth:s=240,maxWidth:a=360,margin:l=8,testid:d}){const c=u.useRef(null),[p,f]=u.useState(null),b=u.useCallback(()=>{const m=e.current,h=c.current;if(!m||!h)return;const v=m.getBoundingClientRect(),y=window.innerWidth,_=window.innerHeight,w=h.getBoundingClientRect(),k=Math.min(Math.max(w.width,s),a),x=w.height;let $=v.left;$+k+l>y&&($=v.right-k),$=Math.min(Math.max($,l),y-k-l);const C=_-v.bottom-l,S=v.top-l;let D,E;const I=r==="bottom",N=C>=Math.min(x,160),T=S>=Math.min(x,160);I&&N||I&&!T?(D=v.bottom+4,E=C):!I&&T||T?(D=v.top-4-Math.min(x,S),E=S):C>=S?(D=v.bottom+4,E=C):(D=l,E=S),f({left:$,top:D,maxHeight:Math.max(E,120)})},[e,r,s,a,l]);if(u.useLayoutEffect(()=>{if(!t){f(null);return}b()},[t,b]),u.useEffect(()=>{if(!t)return;const m=()=>b();window.addEventListener("resize",m),window.addEventListener("scroll",m,!0);const h=y=>{const _=c.current,w=e.current,k=y.target;_?.contains(k)||w?.contains(k)||n()},v=y=>{y.key==="Escape"&&n()};return document.addEventListener("pointerdown",h,!0),document.addEventListener("keydown",v),()=>{window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0),document.removeEventListener("pointerdown",h,!0),document.removeEventListener("keydown",v)}},[t,b,n,e]),!t)return null;const g={...Uv,minWidth:s,maxWidth:`min(${a}px, calc(100vw - ${l*2}px))`,...p?{left:p.left,top:p.top,maxHeight:p.maxHeight,visibility:"visible"}:{left:-9999,top:-9999,visibility:"hidden"}};return i.jsx("div",{ref:c,"data-testid":d,style:g,role:"dialog",children:o})}const Uv={position:"fixed",zIndex:1e3,background:"#fff",border:"1px solid #cbd5e1",borderRadius:8,boxShadow:"0 4px 16px rgba(0,0,0,0.14)",padding:6,overflowY:"auto",boxSizing:"border-box"};function ec(e,t,n){if(!t)return n;const o=e(t);return!o||o===t||o.startsWith("$t:")?n:o}function $t({candidates:e,t,onSelect:n,testIdSuffix:o,defaultOpen:r=!1,floating:s=!0}){const[a,l]=u.useState(r),[d,c]=u.useState(""),p=u.useRef(null),f=u.useMemo(()=>Ji(e,"scalar").map(h=>({...h,resolvedLabel:ec(t,h.labelKey,h.path||h.sourceId)})),[e,t]),b=u.useMemo(()=>Zi(f,d),[f,d]),g=i.jsxs(i.Fragment,{children:[i.jsx("input",{type:"text",autoFocus:!0,"data-testid":`g7le-inline-binding-search-input-${o}`,value:d,placeholder:t("layout_editor.inline_binding.search_placeholder"),onChange:m=>c(m.target.value),style:Xv}),i.jsx("div",{style:Jv,children:b.length===0?i.jsx("div",{style:Zv,children:t("layout_editor.inline_binding.no_results")}):b.map(m=>i.jsxs("button",{type:"button","data-testid":`g7le-inline-binding-candidate-${m.expression}`,onClick:()=>{n(m),l(!1),c("")},style:Qv,children:[i.jsxs("span",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[i.jsx("span",{style:{fontSize:12},children:m.resolvedLabel}),i.jsxs("span",{style:Rv,children:[ec(t,m.groupLabelKey,m.sourceId)," · ",m.path||m.sourceId]})]}),i.jsx("span",{style:e_,children:m.preview})]},m.expression))})]});return i.jsxs("div",{style:s?Yv:{marginTop:4},children:[i.jsx("button",{ref:p,type:"button","data-testid":`g7le-inline-binding-search-toggle-${o}`,onClick:()=>l(m=>!m),title:t("layout_editor.inline_binding.search"),"aria-label":t("layout_editor.inline_binding.search"),"aria-expanded":a,style:qv,children:"🔍"}),s?i.jsx(Zn,{anchorRef:p,open:a,onClose:()=>l(!1),testid:`g7le-inline-binding-picker-${o}`,children:g}):a&&i.jsx("div",{"data-testid":`g7le-inline-binding-picker-${o}`,style:Gv,children:g})]})}const qv={fontSize:13,lineHeight:1,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#334155",padding:"4px 8px",cursor:"pointer",textAlign:"center",whiteSpace:"nowrap"},Gv={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6},Yv={display:"inline-block"},Xv={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},Jv={marginTop:4,maxHeight:200,overflowY:"auto",display:"flex",flexDirection:"column",gap:2},Zv={fontSize:11,color:"#94a3b8",padding:"8px 0",textAlign:"center"},Qv={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:"none",background:"transparent",cursor:"pointer",padding:"6px 8px",borderRadius:4,textAlign:"left"},Rv={fontSize:10,color:"#94a3b8"},e_={fontSize:10,color:"#64748b",fontFamily:"monospace",whiteSpace:"nowrap"},t_=["$localized"];function Qn(e){const t=e.trim();if(!t.startsWith("{{")||!t.endsWith("}}")||t.length<4)return null;let n=0;for(let o=0;ogn(n).decomposed)}function Io(e,t,n,o){switch(e.kind){case"leaf":nc(e.text,t,n,o);return;case"conditional":Io(e.then,t,n,o),o.push({kind:"ellipsis",text:"⋯"});return;case"fallback":Io(e.primary,t,n,o);return;case"concat":e.parts.forEach(r=>Io(r,t,n,o));return;case"raw":default:o.push({kind:"text",text:e.source});return}}function nc(e,t,n,o){const r=e.trim();if(/^\{\{([\s\S]*)\}\}$/.exec(r)&&!r.slice(2,-2).includes("}}")){o.push({kind:"chip",text:n(r)});return}if(r.startsWith("$t:")){const a=r.slice(3).split("|")[0];o.push({kind:"text",text:t(a)||a});return}for(const a of e.split(/(\{\{(?:[^}]|\}(?!\}))*\}\})/g))a!==""&&(/^\{\{[\s\S]*\}\}$/.test(a)?o.push({kind:"chip",text:n(a)}):o.push({kind:"text",text:a}))}function ms(e,t,n){const o=[];if(typeof e!="string"||e==="")return o;if(Qn(e)===null&&/\{\{/.test(e)){for(const a of e.split(/(\{\{(?:[^}]|\}(?!\}))*\}\})/g))if(!(a===void 0||a===""))if(/^\{\{[\s\S]*\}\}$/.test(a)){const l=gn(a);Io(l.node,t,n,o)}else nc(a,t,n,o);return o}const s=gn(e);return Io(s.node,t,n,o),o}function n_(e){if(typeof e!="string"||e.trim()==="")return"empty";const t=e.trim();if(Qn(t)===null)return"simple";const n=gn(e);return n.node.kind==="leaf"?"simple":n.decomposed?"expression":"raw"}function gn(e){const t=typeof e=="string"?e:"",n=t.trim();if(n==="")return{node:{kind:"leaf",text:t},decomposed:!1,original:t};const o=Qn(n);if(o===null)return{node:{kind:"leaf",text:t},decomposed:!1,original:t};let r;try{r=u_(o)}catch{r=null}if(r===null)return{node:{kind:"raw",source:o},decomposed:!1,original:t};if(r.kind==="leaf"||r.kind==="raw")return{node:r,decomposed:!1,original:t};if(r.kind==="fallback"&&r.op==="??"&&o_(r.primary)&&r_(r.fallback))return{node:{kind:"leaf",text:t},decomposed:!1,original:t};const s=Rn(r,!0);return y_(o,s)?{node:r,decomposed:!0,original:t}:{node:{kind:"raw",source:o},decomposed:!1,original:t}}function Rn(e,t=!1){const n=rc(e);return t?n:e.kind==="leaf"?e.text:`{{${n}}}`}function Ao(e){return Rn({kind:"conditional",condition:{kind:"simple",left:"",op:"truthy",right:""},then:{kind:"leaf",text:typeof e=="string"?e:""},else:{kind:"leaf",text:""}},!1)}function vs(e){return Rn({kind:"fallback",op:"??",primary:{kind:"leaf",text:typeof e=="string"?e:""},fallback:{kind:"leaf",text:""}},!1)}function To(e){switch(e.kind){case"leaf":return e.text;case"conditional":return To(e.then);case"fallback":return To(e.primary);case"concat":return e.parts.map(To).join("");case"raw":default:return e.kind==="raw"?`{{${e.source}}}`:""}}function t5(e){return e}function Tr(e){if(typeof e!="string"||e.trim()==="")return"";if(Qn(e)===null&&/\{\{/.test(e)){for(const n of e.split(/(\{\{(?:[^}]|\}(?!\}))*\}\})/g))if(!(n===void 0||n===""))return/^\{\{[\s\S]*\}\}$/.test(n)?To(gn(n).node):n;return""}return To(gn(e).node)}function o_(e){if(e.kind!=="leaf")return!1;const t=/^\{\{([\s\S]*)\}\}$/.exec(e.text.trim());return t?eo(t[1].trim()):!1}function r_(e){if(e.kind!=="leaf")return!1;const t=e.text.trim();return!(/\{\{/.test(t)||t.startsWith("$t:"))}function Dr(e){return`'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function i_(e){const t=[];let n=0,o=0;const r=e.length;for(;on&&t.push(Dr(e.slice(n,o)));let s=o+2;for(;s=r)break;const a=e.slice(o+2,s).trim();t.push(a),o=s+2,n=o;continue}o++}return nDo(t,"concat")).join(" + ");case"fallback":return`${Do(e.primary,"fallback")} ${e.op} ${Do(e.fallback,"fallback")}`;case"conditional":return`${a_(e.condition)} ? ${Do(e.then,"conditional")} : ${Do(e.else,"conditional")}`;default:return""}}function Do(e,t){const n=rc(e);return e.kind==="leaf"||e.kind==="raw"?n:e.kind==="conditional"?t==="conditional"?n:`(${n})`:e.kind==="fallback"?t==="concat"?`(${n})`:n:(e.kind==="concat",n)}const d_=["===","!==","??","||","&&","==","!=",">=","<="];function ic(e){const t=[];let n=0;const o=e.length;for(;n=o)throw new Error("unterminated-binding-in-string");d+=e.slice(l,c+2),l=c+2;continue}if(e[l]===a){d+=a,l++;break}if(a==="`"&&e[l]==="$"&&e[l+1]==="{")throw new Error("template-literal-interpolation-unsupported");d+=e[l],l++}if(l>o||d[d.length-1]!==a)throw new Error("unterminated-string");t.push({kind:"string",value:d,start:n,end:l}),n=l;continue}if(r==="{"&&e[n+1]==="{"){let a=n+2;for(;a"||r==="<"){t.push({kind:"op",value:r,start:n,end:n+1}),n++;continue}if(r==="!"){t.push({kind:"op",value:"!",start:n,end:n+1}),n++;continue}if(r==="("){t.push({kind:"lparen",value:"(",start:n,end:n+1}),n++;continue}if(r===")"){t.push({kind:"rparen",value:")",start:n,end:n+1}),n++;continue}if(r==="["){t.push({kind:"lbracket",value:"[",start:n,end:n+1}),n++;continue}if(r==="]"){t.push({kind:"rbracket",value:"]",start:n,end:n+1}),n++;continue}if(r==="."){t.push({kind:"dot",value:".",start:n,end:n+1}),n++;continue}if(/[0-9]/.test(r)){let a=n;for(;a=n)return"";const o=this.toks[t].start,r=this.toks[n-1].end;return this.src.slice(o,r)}parseFallback(){let t=this.parseConcat(),n=this.peek();for(;n&&n.kind==="op"&&(n.value==="??"||n.value==="||");){const o=n.value;this.next();const r=this.parseConcat();t={kind:"fallback",op:o,primary:t,fallback:r},n=this.peek()}return t}parseConcat(){const t=this.parseUnaryOrPrimary(),n=[t];let o=this.peek();for(;o&&o.kind==="op"&&o.value==="+";)this.next(),n.push(this.parseUnaryOrPrimary()),o=this.peek();return n.length===1?t:{kind:"concat",parts:n}}parseUnaryOrPrimary(){return this.parsePrimary()}parsePrimary(){const t=this.peek();if(!t)throw new Error("unexpected-end");if(t.kind==="lparen"){this.next();const n=this.parseTernary(),o=this.next();if(!o||o.kind!=="rparen")throw new Error("expected-rparen");return n}if(t.kind==="string")return this.next(),{kind:"leaf",text:ac(t.value)};if(t.kind==="tkey")return this.next(),{kind:"leaf",text:t.value};if(t.kind==="binding")return this.next(),{kind:"leaf",text:t.value};if(t.kind==="ident"&&t_.includes(t.value)&&this.toks[this.pos+1]?.kind==="lparen"){const n=this.tryParsePathWrapperCall(t.value);if(n!==null)return n;throw new Error("path-wrapper-non-simple-arg")}if(t.kind==="ident")return{kind:"leaf",text:`{{${this.parsePath()}}}`};if(t.kind==="number")return this.next(),{kind:"leaf",text:t.value};throw new Error(`unparseable-primary:${t.kind}`)}parsePath(){let t="";const n=this.next();if(!n||n.kind!=="ident")throw new Error("expected-ident");for(t+=n.value;;){const o=this.peek();if(!o)break;if(o.kind==="op"&&o.value==="?"&&this.toks[this.pos+1]?.kind==="dot"){this.next(),this.next();const r=this.next();if(!r||r.kind!=="ident")throw new Error("expected-ident-after-optional");t+="?."+r.value;continue}if(o.kind==="dot"){this.next();const r=this.next();if(!r||r.kind!=="ident")throw new Error("expected-ident-after-dot");t+="."+r.value;continue}if(o.kind==="lbracket"){this.next();const r=this.next(),s=this.next();if(!s||s.kind!=="rbracket")throw new Error("expected-rbracket");if(r&&(r.kind==="number"||r.kind==="string")){t+=`[${r.value}]`;continue}throw new Error("non-literal-index")}if(o.kind==="lparen")throw new Error("call-expression");break}return t}tryParsePathWrapperCall(t){const n=this.pos;this.next();const o=this.next();if(!o||o.kind!=="lparen")return this.pos=n,null;let r;try{if(this.peek()?.kind!=="ident")return this.pos=n,null;r=this.parsePath()}catch{return this.pos=n,null}const s=this.next();return!s||s.kind!=="rparen"?(this.pos=n,null):{kind:"leaf",text:`{{${t}(${r})}}`}}}function u_(e){return new c_(e).parse()}const p_=["===","!==","==","!=",">=","<=",">","<"];function f_(e,t){const n=e.trim();if(n==="")return{kind:"raw",source:n};if(n===oc)return{kind:"simple",left:"",op:"truthy",right:""};if(n.startsWith("!")){const s=n.slice(1).trim(),a=sc(s);return eo(a)?{kind:"simple",left:a,op:"falsy",right:""}:{kind:"raw",source:n}}const o=g_(n);if(o){const{left:s,op:a,right:l}=o,d=s.trim(),c=l.trim();return eo(d)&&(c==="''"||c==='""')?{kind:"simple",left:d,op:a,right:""}:eo(d)&&h_(c)?{kind:"simple",left:d,op:a,right:c}:{kind:"raw",source:n}}const r=sc(n);return eo(r)?{kind:"simple",left:r,op:"truthy",right:""}:{kind:"raw",source:n}}function g_(e){let t=0,n=null;for(let o=0;o=o||!/[A-Za-z_$]/.test(t[n]))return!1;for(n++;n=o||!/[A-Za-z_$]/.test(t[n]))return!1;for(n++;n=2&&(t[0]==="'"||t[0]==='"'||t[0]==="`")?t.slice(1,-1).replace(/\\(['"`\\])/g,"$1"):t}function y_(e,t){try{return zr(e)===zr(t)}catch{return!1}}function zr(e){const t=Qn(e);return t!==null?zr(t):ic(e).map(o=>{if(o.kind==="string")return`S:${ac(o.value)}`;if(o.kind==="binding"){const r=/^\{\{([\s\S]*)\}\}$/.exec(o.value);return`B:${r?zr(r[1].trim()):o.value.replace(/\s+/g,"")}`}return o.kind==="tkey"?`S:${o.value}`:o.kind==="op"?`O:${o.value}`:o.kind==="ident"||o.kind==="number"?`I:${o.value}`:o.kind==="dot"?".":o.kind==="lbracket"?"[":o.kind==="rbracket"?"]":o.kind==="lparen"||o.kind==="rparen"?"":`X:${o.value}`}).join("")}function to({active:e,testid:t}){return i.jsx("div",{"data-testid":t,"data-active":e?"true":"false","aria-hidden":"true",style:e?m_:b_})}const b_={height:0,margin:0,transition:"height 80ms"},m_={height:3,margin:"1px 0",borderRadius:2,background:"#2563eb",boxShadow:"0 0 0 1px #93c5fd"};function _s(e){const{length:t,onMove:n,canDrag:o,canDropAt:r}=e,[s,a]=u.useState(null),[l,d]=u.useState(null),c=u.useCallback(m=>{o&&!o(m)||(a(m),d(m))},[o]),p=u.useCallback(()=>{a(null),d(null)},[]),f=u.useCallback((m,h)=>{if(s===null)return;const v=h==="before"?m:m+1;if(r&&!r(s,v)){d(null);return}d(v)},[s,r]),b=u.useCallback(()=>{if(s!==null&&l!==null){const m=l>s?l-1:l;m!==s&&(!r||r(s,l))&&n(s,m)}a(null),d(null)},[s,l,n,r]),g=u.useCallback(m=>s!==null&&l===m&&m<=t,[s,l,t]);return{dragIndex:s,dropIndex:l,dragging:s!==null,onDragStart:c,onDragEnd:p,onDragOverItem:f,onDrop:b,isDropTarget:g}}const v_={text:"",expression:"{{false ? '' : ''}}",fallback:"{{'' ?? ''}}",data:""};function lc(e,t){const n=An(e);let o=t;const r=n.map(s=>({id:o++,kind:s.kind==="literal"?"text":"expression",value:s.raw}));return r.length===0&&r.push({id:o++,kind:"text",value:""}),{segs:r,nextSeq:o}}function xs({value:e,onChange:t,t:n,candidates:o,testidPrefix:r="g7le-seg-value",renderLeafInput:s}){const a=u.useRef(0),l=u.useRef(e),d=u.useMemo(()=>{const w=lc(e,a.current);return a.current=w.nextSeq,w.segs},[]),[c,p]=u.useState(d),[f,b]=u.useState(!1);if(e!==l.current){l.current=e;const w=c.map(k=>k.value).join("");if(e!==w){const k=lc(e,a.current);a.current=k.nextSeq,p(k.segs)}}const g=u.useCallback(w=>{p(w);const k=w.map(x=>x.value).join("");l.current=k,t(k)},[t]),m=u.useCallback((w,k)=>{g(c.map(x=>x.id===w?{...x,value:k??""}:x))},[c,g]),h=u.useCallback(w=>{const k=c.filter(x=>x.id!==w);g(k.length>0?k:[{id:a.current++,kind:"text",value:""}])},[c,g]),v=u.useCallback(w=>{g([...c,{id:a.current++,kind:w,value:v_[w]}])},[c,g]),y=u.useCallback((w,k)=>{if(w===k||w<0||k<0||w>=c.length||k>=c.length)return;const x=c.slice(),[$]=x.splice(w,1);x.splice(k,0,$),g(x)},[c,g]),_=_s({length:c.length,onMove:y});return i.jsxs("div",{"data-testid":r,style:w_,children:[i.jsx("div",{style:k_,children:n("layout_editor.value_tree.segmented_hint")}),c.map((w,k)=>i.jsxs(u.Fragment,{children:[i.jsx(to,{active:_.isDropTarget(k),testid:`${r}-dropline-${k}`}),i.jsx(x_,{seg:w,index:k,t:n,candidates:o,testidPrefix:r,renderLeafInput:s,onValueChange:x=>m(w.id,x),onRemove:()=>h(w.id),dragging:_.dragIndex===k,onDragStartCard:()=>_.onDragStart(k),onDragEndCard:_.onDragEnd,onDragOverCard:x=>_.onDragOverItem(k,x),onDropCard:_.onDrop})]},w.id)),i.jsx(to,{active:_.isDropTarget(c.length),testid:`${r}-dropline-end`}),i.jsxs("div",{style:A_,"data-testid":`${r}-add-row`,children:[i.jsxs("button",{type:"button","data-testid":`${r}-add-text`,onClick:()=>v("text"),style:Nr,children:["+ ",n("layout_editor.value_tree.segment.text")]}),i.jsxs("button",{type:"button","data-testid":`${r}-add-expression`,onClick:()=>v("expression"),style:Nr,children:["+ ",n("layout_editor.value_tree.segment.expression")]}),i.jsxs("button",{type:"button","data-testid":`${r}-add-fallback`,onClick:()=>v("fallback"),style:Nr,children:["+ ",n("layout_editor.value_tree.segment.fallback")]}),i.jsxs("button",{type:"button","data-testid":`${r}-add-data`,onClick:()=>v("data"),style:Nr,children:["+ ",n("layout_editor.value_tree.segment.data")]})]}),i.jsxs("div",{style:z_,children:[i.jsxs("button",{type:"button","data-testid":`${r}-source-toggle`,"aria-expanded":f,onClick:()=>b(w=>!w),style:N_,children:[""," ",n("layout_editor.value_tree.show_source")," ",f?"▴":"▾"]}),f&&i.jsx("code",{"data-testid":`${r}-source-code`,style:M_,children:c.map(w=>w.value).join("")})]})]})}function __({t:e,candidates:t,onPick:n,testidPrefix:o}){return!t||t.length===0?i.jsx("div",{"data-testid":`${o}-data-empty`,style:D_,children:e("layout_editor.value_tree.segment.data_no_candidates")}):i.jsxs("div",{"data-testid":`${o}-data-picker`,style:{minWidth:0},children:[i.jsx("div",{style:T_,children:e("layout_editor.value_tree.segment.data_pick_hint")}),i.jsx($t,{candidates:t,t:e,onSelect:r=>{n(In(r.sourceId,r.path,"scalar"))},testIdSuffix:`${o}-data`,defaultOpen:!0,floating:!0})]})}function x_({seg:e,index:t,t:n,candidates:o,testidPrefix:r,renderLeafInput:s,onValueChange:a,onRemove:l,dragging:d,onDragStartCard:c,onDragEndCard:p,onDragOverCard:f,onDropCard:b}){const g=e.kind==="text"?"layout_editor.value_tree.segment.text":e.kind==="data"?"layout_editor.value_tree.segment.data":e.kind==="fallback"?"layout_editor.value_tree.segment.fallback":"layout_editor.value_tree.segment.expression";return i.jsxs("div",{"data-testid":`${r}-card-${t}`,"data-seg-kind":e.kind,style:d?{...dc,opacity:.5}:dc,onDragOver:m=>{m.preventDefault();const h=m.currentTarget.getBoundingClientRect();f(m.clientY{m.preventDefault(),b()},children:[i.jsxs("div",{style:S_,children:[i.jsx("span",{"data-testid":`${r}-drag-${t}`,style:E_,draggable:!0,onDragStart:c,onDragEnd:p,title:n("layout_editor.value_tree.drag_reorder"),"aria-label":n("layout_editor.value_tree.drag_reorder"),role:"button",children:"⠿"}),i.jsx("span",{style:C_,children:n(g)}),i.jsx("button",{type:"button","data-testid":`${r}-remove-${t}`,onClick:l,title:n("layout_editor.value_tree.segment.remove"),"aria-label":n("layout_editor.value_tree.segment.remove"),style:I_,children:"✕"})]}),i.jsx("div",{style:$_,children:e.kind==="data"&&e.value.trim()===""?i.jsx(__,{t:n,candidates:o,onPick:a,testidPrefix:`${r}-field-${t}`}):s?s({value:e.value,onChange:a,t:n,candidates:o,testidPrefix:`${r}-field-${t}`}):i.jsx(_t,{value:e.value,onChange:a,t:n,candidates:o,testidPrefix:`${r}-field-${t}`,enableExpressionTree:!0,expressionSourceToggle:!1})})]})}const w_={display:"flex",flexDirection:"column",gap:6,width:"100%",minWidth:0},k_={fontSize:11,color:"#64748b"},dc={display:"flex",flexDirection:"column",gap:4,padding:"6px 8px",border:"1px solid #e2e8f0",borderLeft:"3px solid #6366f1",borderRadius:6,background:"#f8fafc",minWidth:0},S_={display:"flex",alignItems:"center",gap:6,minWidth:0},C_={fontSize:10,fontWeight:600,color:"#6366f1",flex:1,minWidth:0},$_={minWidth:0},E_={color:"#94a3b8",cursor:"grab",fontSize:14,userSelect:"none"},I_={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12,padding:2,flexShrink:0},A_={display:"flex",flexWrap:"wrap",gap:6,marginTop:2},T_={fontSize:11,color:"#64748b",marginBottom:2},D_={fontSize:11,color:"#94a3b8",padding:"4px 0"},Nr={padding:"4px 10px",fontSize:11,border:"1px dashed #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},z_={display:"flex",flexDirection:"column",gap:4,marginTop:2},N_={alignSelf:"flex-start",padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",fontFamily:"monospace"},M_={fontSize:11,background:"#0f172a",color:"#e2e8f0",padding:"6px 8px",borderRadius:4,wordBreak:"break-all",fontFamily:"monospace"},L_=[{value:"truthy",labelKey:"layout_editor.value_tree.cond.op_truthy"},{value:"falsy",labelKey:"layout_editor.value_tree.cond.op_falsy"},{value:"===",labelKey:"layout_editor.value_tree.cond.op_eq"},{value:"!==",labelKey:"layout_editor.value_tree.cond.op_neq"},{value:">",labelKey:"layout_editor.value_tree.cond.op_gt"},{value:"<",labelKey:"layout_editor.value_tree.cond.op_lt"},{value:">=",labelKey:"layout_editor.value_tree.cond.op_gte"},{value:"<=",labelKey:"layout_editor.value_tree.cond.op_lte"}];function cc({node:e,onChange:t,t:n,candidates:o,testidPrefix:r="g7le-value-tree",depth:s=0,showSourceToggle:a=!0,renderLeafInput:l}){const[d,c]=u.useState(!1),p=s===0,f=i.jsx(no,{node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:l});return p?a?i.jsxs("div",{"data-testid":r,style:pc,children:[f,i.jsxs("div",{style:tx,children:[i.jsxs("button",{type:"button","data-testid":`${r}-source-toggle`,"aria-expanded":d,onClick:()=>c(b=>!b),style:nx,children:[""," ",n("layout_editor.value_tree.show_source")," ",d?"▴":"▾"]}),d&&i.jsx("code",{"data-testid":`${r}-source-code`,style:ox,children:Rn(e,!1)})]})]}):i.jsx("div",{"data-testid":r,style:pc,children:f}):f}function no({node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a}){switch(e.kind){case"leaf":return i.jsx(xs,{value:e.text,onChange:l=>t({kind:"leaf",text:l}),t:n,candidates:o,testidPrefix:`${r}-leaf`,renderLeafInput:a});case"conditional":return i.jsx(P_,{node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a});case"fallback":return i.jsx(O_,{node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a});case"concat":return i.jsx(W_,{node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a});case"raw":default:return i.jsxs("div",{"data-testid":`${r}-raw`,style:rx,children:[i.jsx("code",{style:hc,children:e.source??""}),i.jsxs("span",{style:yc,children:["🔒 ",n("layout_editor.value_tree.raw_code_only")]})]})}}function P_({node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a}){const l=u.useCallback(p=>t({...e,condition:p}),[e,t]),d=u.useCallback(p=>t({...e,then:p}),[e,t]),c=u.useCallback(p=>t({...e,else:p}),[e,t]);return i.jsxs("div",{"data-testid":`${r}-conditional`,style:ws(s),children:[i.jsx(j_,{condition:e.condition,onChange:l,t:n,candidates:o,testidPrefix:r}),i.jsx(Mr,{label:n("layout_editor.value_tree.cond.when_true"),testid:`${r}-then`,children:i.jsx(no,{node:e.then,onChange:d,t:n,candidates:o,testidPrefix:`${r}-then`,depth:s+1,renderLeafInput:a})}),i.jsx(Mr,{label:n("layout_editor.value_tree.cond.when_false"),testid:`${r}-else`,children:i.jsx(no,{node:e.else,onChange:c,t:n,candidates:o,testidPrefix:`${r}-else`,depth:s+1,renderLeafInput:a})})]})}function O_({node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a}){const l=u.useCallback(c=>t({...e,primary:c}),[e,t]),d=u.useCallback(c=>t({...e,fallback:c}),[e,t]);return i.jsxs("div",{"data-testid":`${r}-fallback`,style:ws(s),children:[i.jsx(Mr,{label:n("layout_editor.value_tree.fallback.primary"),testid:`${r}-primary`,children:i.jsx(no,{node:e.primary,onChange:l,t:n,candidates:o,testidPrefix:`${r}-primary`,depth:s+1,renderLeafInput:a})}),i.jsx(Mr,{label:n(e.op==="??"?"layout_editor.value_tree.fallback.when_empty":"layout_editor.value_tree.fallback.when_falsy"),testid:`${r}-fallback-branch`,children:i.jsx(no,{node:e.fallback,onChange:d,t:n,candidates:o,testidPrefix:`${r}-fallbackb`,depth:s+1,renderLeafInput:a})})]})}const B_={text:()=>({kind:"leaf",text:""}),data:()=>({kind:"leaf",text:""}),expression:()=>({kind:"conditional",condition:{kind:"simple",left:"",op:"truthy",right:""},then:{kind:"leaf",text:""},else:{kind:"leaf",text:""}}),fallback:()=>({kind:"fallback",op:"??",primary:{kind:"leaf",text:""},fallback:{kind:"leaf",text:""}})};function W_({node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a}){const l=u.useCallback((g,m)=>{const h=e.parts.slice();h[g]=m,t({...e,parts:h})},[e,t]),d=u.useCallback(g=>{g.length===0?t({kind:"leaf",text:""}):g.length===1?t(g[0]):t({...e,parts:g})},[e,t]),c=u.useCallback(g=>d(e.parts.filter((m,h)=>h!==g)),[e.parts,d]),p=u.useCallback(g=>d([...e.parts,B_[g]()]),[e.parts,d]),f=u.useCallback((g,m)=>{if(g===m||g<0||m<0||g>=e.parts.length||m>=e.parts.length)return;const h=e.parts.slice(),[v]=h.splice(g,1);h.splice(m,0,v),d(h)},[e.parts,d]),b=_s({length:e.parts.length,onMove:f});return i.jsxs("div",{"data-testid":`${r}-concat`,style:ws(s),children:[i.jsx("div",{style:X_,children:n("layout_editor.value_tree.concat.hint")}),e.parts.map((g,m)=>i.jsxs(u.Fragment,{children:[i.jsx(to,{active:b.isDropTarget(m),testid:`${r}-part-dropline-${m}`}),i.jsxs("div",{"data-testid":`${r}-part-card-${m}`,style:b.dragIndex===m?{...gc,opacity:.5}:gc,onDragOver:h=>{h.preventDefault();const v=h.currentTarget.getBoundingClientRect();b.onDragOverItem(m,h.clientY{h.preventDefault(),b.onDrop()},children:[i.jsxs("div",{style:J_,children:[i.jsx("span",{"data-testid":`${r}-part-handle-${m}`,style:R_,draggable:!0,onDragStart:()=>b.onDragStart(m),onDragEnd:b.onDragEnd,title:n("layout_editor.value_tree.drag_reorder"),"aria-label":n("layout_editor.value_tree.drag_reorder"),role:"button",children:"⠿"}),i.jsx("span",{style:Z_,children:n("layout_editor.value_tree.concat.part",{n:m+1})}),i.jsx("button",{type:"button","data-testid":`${r}-part-remove-${m}`,onClick:()=>c(m),title:n("layout_editor.value_tree.segment.remove"),"aria-label":n("layout_editor.value_tree.segment.remove"),style:ex,children:"✕"})]}),i.jsx("div",{style:{minWidth:0},children:i.jsx(no,{node:g,onChange:h=>l(m,h),t:n,candidates:o,testidPrefix:`${r}-part-${m}`,depth:s+1,renderLeafInput:a})})]})]},m)),i.jsx(to,{active:b.isDropTarget(e.parts.length),testid:`${r}-part-dropline-end`}),i.jsxs("div",{style:Q_,"data-testid":`${r}-part-add-row`,children:[i.jsxs("button",{type:"button","data-testid":`${r}-part-add-text`,onClick:()=>p("text"),style:Lr,children:["+ ",n("layout_editor.value_tree.segment.text")]}),i.jsxs("button",{type:"button","data-testid":`${r}-part-add-expression`,onClick:()=>p("expression"),style:Lr,children:["+ ",n("layout_editor.value_tree.segment.expression")]}),i.jsxs("button",{type:"button","data-testid":`${r}-part-add-fallback`,onClick:()=>p("fallback"),style:Lr,children:["+ ",n("layout_editor.value_tree.segment.fallback")]}),i.jsxs("button",{type:"button","data-testid":`${r}-part-add-data`,onClick:()=>p("data"),style:Lr,children:["+ ",n("layout_editor.value_tree.segment.data")]})]})]})}function j_({condition:e,onChange:t,t:n,candidates:o,testidPrefix:r}){if(e.kind==="raw")return i.jsxs("div",{"data-testid":`${r}-cond-raw`,style:U_,children:[i.jsx("span",{style:fc,children:n("layout_editor.value_tree.cond.label")}),i.jsx("code",{style:hc,children:e.source}),i.jsxs("span",{style:yc,children:["🔒 ",n("layout_editor.value_tree.cond.code_only")]})]});const s=e,a=s.op!=="truthy"&&s.op!=="falsy";return i.jsxs("div",{"data-testid":`${r}-cond`,style:V_,children:[i.jsx("span",{style:fc,children:n("layout_editor.value_tree.cond.label")}),i.jsx(uc,{testid:`${r}-cond-left`,value:s.left,onCommit:l=>t({...s,left:l}),placeholder:n("layout_editor.value_tree.cond.field_placeholder"),candidates:o,t:n}),i.jsx("select",{"data-testid":`${r}-cond-op`,value:s.op,onChange:l=>t({...s,op:l.target.value}),style:Y_,children:L_.map(l=>i.jsx("option",{value:l.value,children:n(l.labelKey)},l.value))}),a&&i.jsx(uc,{testid:`${r}-cond-right`,value:s.right,onCommit:l=>t({...s,right:l}),placeholder:n("layout_editor.value_tree.cond.value_placeholder"),candidates:o,t:n,quoteDataPick:!0})]})}function uc({testid:e,value:t,onCommit:n,placeholder:o,candidates:r,t:s,quoteDataPick:a=!1}){const[l,d]=u.useState(null),c=l!==null?l:t,p=()=>{l!==null&&(l!==t&&n(l),d(null))},f=(b,g)=>{const m=In(b,g,"scalar"),h=/^\{\{\s*([\s\S]*?)\s*\}\}$/.exec(m.trim());let v=h?h[1]:m;v=v.replace(/\s*\?\?\s*''$/,"").trim(),n(a?`'${v}'`:v),d(null)};return i.jsxs("span",{style:q_,children:[i.jsx("input",{type:"text","data-testid":e,value:c,onChange:b=>d(b.target.value),onBlur:p,onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),p())},placeholder:o,style:G_}),r&&r.length>0&&s&&i.jsx($t,{candidates:r,t:s,onSelect:b=>f(b.sourceId,b.path),testIdSuffix:`${e}-data`,floating:!0})]})}function Mr({label:e,testid:t,children:n}){return i.jsxs("div",{"data-testid":t,style:H_,children:[i.jsx("span",{style:F_,children:e}),i.jsx("div",{style:K_,children:n})]})}const pc={display:"flex",flexDirection:"column",gap:6,width:"100%",minWidth:0},ws=e=>({display:"flex",flexDirection:"column",gap:6,padding:"8px",border:"1px solid #e2e8f0",borderLeft:`3px solid ${e%2===0?"#6366f1":"#0ea5e9"}`,borderRadius:6,background:e%2===0?"#f8fafc":"#fefefe",minWidth:0}),H_={display:"flex",flexDirection:"column",gap:3,minWidth:0},F_={fontSize:11,fontWeight:600,color:"#475569"},K_={paddingLeft:8,minWidth:0},V_={display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",minWidth:0},U_={display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",minWidth:0},fc={fontSize:11,fontWeight:600,color:"#0f172a",whiteSpace:"nowrap"},q_={display:"inline-flex",alignItems:"flex-start",gap:2,flex:"1 1 80px",minWidth:60},G_={flex:"1 1 80px",minWidth:60,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},Y_={padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff"},X_={fontSize:11,color:"#94a3b8"},gc={display:"flex",flexDirection:"column",gap:4,padding:"6px 8px",border:"1px solid #e2e8f0",borderLeft:"3px solid #6366f1",borderRadius:6,background:"#fff",minWidth:0},J_={display:"flex",alignItems:"center",gap:6,minWidth:0},Z_={fontSize:10,fontWeight:600,color:"#6366f1",flex:1,minWidth:0},Q_={display:"flex",flexWrap:"wrap",gap:6,marginTop:2},R_={color:"#94a3b8",cursor:"grab",fontSize:14,userSelect:"none"},ex={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12,padding:2,flexShrink:0},Lr={padding:"4px 10px",fontSize:11,border:"1px dashed #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},tx={display:"flex",flexDirection:"column",gap:4,marginTop:2},nx={alignSelf:"flex-start",padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",fontFamily:"monospace"},ox={fontSize:11,background:"#0f172a",color:"#e2e8f0",padding:"6px 8px",borderRadius:4,wordBreak:"break-all",fontFamily:"monospace"},rx={display:"flex",flexDirection:"column",gap:2,minWidth:0},hc={fontSize:11,background:"#f1f5f9",padding:"3px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all",fontFamily:"monospace"},yc={fontSize:10,color:"#64748b"};function _t({value:e,onChange:t,t:n,placeholder:o,testidPrefix:r="g7le-i18n-text-field",locales:s,candidates:a,enableExpressionTree:l=!1,expressionTreeCollapsible:d=!1,expressionSourceToggle:c=!0}){const{locale:p,templateIdentifier:f,commitText:b,classify:g,translate:m}=Lv(),[h,v]=u.useState(null),[y,_]=u.useState(!1),[w,k]=u.useState(!1),[x,$]=u.useState(!1),[C,S]=u.useState(!1),[D,E]=u.useState(!1),[,I]=u.useState(0);u.useEffect(()=>{if(typeof window>"u")return;const z=H=>{const P=H.detail;P?.templateIdentifier&&P.templateIdentifier!==f||I(A=>A+1)};return window.addEventListener(kt,z),()=>window.removeEventListener(kt,z)},[f]);const N=g(e);u.useEffect(()=>{v(null),E(!1)},[p,e]);const T=h!==null?h:N.displayValue,B=u.useCallback(async()=>{if(h!==null){if(h===N.displayValue){v(null);return}_(!0);try{const z=await b(e,h);z.kind==="created"&&z.token?(t(z.token),Et({op:"prop_i18n_create_key",sourceState:"plain_text",translationKey:z.customKey,toLocale:p,valueLength:h.length,timestamp:Date.now()})):z.kind==="updated"&&Et({op:"prop_i18n_update_value",sourceState:"custom_key",translationKey:z.customKey,toLocale:p,valueLength:h.length,timestamp:Date.now()})}finally{_(!1),v(null)}}},[h,N.displayValue,b,e,t,p]),M=u.useCallback(z=>{typeof e=="string"&&(t(xo(e,z)),N.customKey&&Ar(f,N.customKey,z,p))},[e,t,N.customKey,f,p]);if(N.binding){if(l&&typeof e=="string"){const z=tc(e),H=gn(e),P=!z&&Vt(e)!==null,A=(z||H.decomposed)&&!P;if(A&&d&&!x)return i.jsx(ax,{value:e,t:n,translate:m,onEdit:()=>$(!0),testidPrefix:`${r}-preview`});const F=A&&(d||z)?i.jsx(xs,{value:e,onChange:Y=>t(Y),t:n,candidates:a,testidPrefix:`${r}-seg`}):H.decomposed?i.jsx(cc,{node:H.node,onChange:Y=>t(Rn(Y,!1)),t:n,candidates:a,testidPrefix:`${r}-tree`,showSourceToggle:c}):null;if(F){if(!d)return F;const Y=Tr(e),V=Y?ms(Y,X=>{const Z=m(X);return Z&&Z!==X&&!Z.startsWith("$t:")?Z:""},X=>Ut(X)):[];return i.jsxs("div",{"data-testid":`${r}-builder`,style:{display:"flex",flexDirection:"column",gap:6,width:"100%",minWidth:0},children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:6},children:[i.jsxs("button",{type:"button","data-testid":`${r}-to-plain`,onClick:()=>S(!0),style:gx,title:n("layout_editor.value_tree.to_plain"),"aria-label":n("layout_editor.value_tree.to_plain"),children:["↩ ",n("layout_editor.value_tree.to_plain")]}),i.jsxs("button",{type:"button","data-testid":`${r}-builder-collapse`,onClick:()=>$(!1),style:vc,title:n("layout_editor.value_tree.collapse"),"aria-label":n("layout_editor.value_tree.collapse"),children:["▴ ",n("layout_editor.value_tree.collapse")]})]}),C&&i.jsxs("div",{"data-testid":`${r}-to-plain-confirm`,style:hx,children:[i.jsx("p",{style:yx,children:n("layout_editor.value_tree.to_plain_lead")}),i.jsx("div",{style:bx,children:V.length===0?i.jsx("span",{style:{color:"#94a3b8"},children:n("layout_editor.prop_i18n.placeholder")}):V.map((X,Z)=>X.kind==="chip"?i.jsxs("span",{style:bc,children:["🔗 ",X.text]},Z):i.jsx("span",{style:X.kind==="ellipsis"?mc:void 0,children:X.text},Z))}),i.jsxs("p",{style:mx,children:["⚠ ",n("layout_editor.value_tree.to_plain_warn")]}),i.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[i.jsx("button",{type:"button","data-testid":`${r}-to-plain-confirm-cancel`,onClick:()=>S(!1),style:vc,children:n("layout_editor.value_tree.to_plain_cancel")}),i.jsx("button",{type:"button","data-testid":`${r}-to-plain-confirm-ok`,onClick:()=>{S(!1),$(!1),t(Tr(e)||void 0)},style:vx,children:n("layout_editor.value_tree.to_plain_ok")})]})]}),F]})}}return l&&typeof e=="string"&&a&&a.length>0&&Vt(e)!==null?i.jsx(lx,{value:e,onChange:t,t:n,candidates:a,testidPrefix:`${r}-data`}):i.jsxs("div",{"data-testid":`${r}-binding`,style:Cx,children:[i.jsx("code",{style:$x,children:typeof e=="string"?e:""}),i.jsxs("span",{style:Ex,children:["🔗 ",n("layout_editor.prop_i18n.bound_code_only")]})]})}if(!D&&typeof e=="string"&&ts(e)){const z=Rl(e);return i.jsxs("div",{"data-testid":`${r}-settings-ref`,style:wx,children:[i.jsx("div",{"data-testid":`${r}-settings-ref-chips`,style:kx,children:z.map((H,P)=>H.kind==="chip"?i.jsxs("span",{style:Sx,children:["🔗 ",H.label]},P):i.jsx("span",{children:H.label},P))}),i.jsxs("button",{type:"button","data-testid":`${r}-settings-ref-edit`,onClick:()=>E(!0),style:_c,title:n("layout_editor.value_tree.edit"),"aria-label":n("layout_editor.value_tree.edit"),children:["✎ ",n("layout_editor.value_tree.edit")]})]})}const O=i.jsxs("button",{type:"button","data-testid":`${r}-toggle`,title:`${n("layout_editor.prop_i18n.edit_languages")} (${Xn(p,n)})`,"aria-label":`${n("layout_editor.prop_i18n.edit_languages")} (${Xn(p,n)})`,"aria-expanded":w,onClick:()=>k(z=>!z),style:_c,children:["🌐 ",N.customKey?w?"⌃":"⌄":"+"]});return i.jsxs("div",{"data-testid":r,style:{display:"flex",flexDirection:"column",gap:4,width:"100%"},children:[i.jsx("div",{style:_x,children:N.paramKey&&N.customKey?i.jsx(ix,{customKey:N.customKey,value:typeof e=="string"?e:"",onChange:t,t:n,candidates:a,testidPrefix:r,showExprButton:l&&d,onToExpression:()=>{$(!0),t(Ao(typeof e=="string"?e:""))},langToggle:O}):i.jsxs(i.Fragment,{children:[i.jsx("input",{type:"text","data-testid":`${r}-preview`,value:T,placeholder:o??n("layout_editor.prop_i18n.placeholder"),onChange:z=>v(z.target.value),onBlur:()=>{B(),D&&E(!1)},disabled:y,style:xx}),a&&a.length>0&&i.jsx(sx,{value:typeof e=="string"?e:"",customKey:N.customKey,onChange:t,t:n,candidates:a,testidPrefix:r}),l&&d&&i.jsx("button",{type:"button","data-testid":`${r}-to-expr`,onClick:()=>{$(!0),t(Ao(typeof e=="string"?e:""))},title:n("layout_editor.value_tree.to_expression"),"aria-label":n("layout_editor.value_tree.to_expression"),style:zo,children:"ƒx"}),O]})}),w&&(N.customKey?i.jsx(Rd,{customKey:N.customKey,templateIdentifier:f,t:n,paramLabels:ys(e),locales:s,onRemoveParam:M},N.customKey):i.jsx("div",{"data-testid":`${r}-expand-hint`,style:Ix,children:n("layout_editor.prop_i18n.create_first")}))]})}function ix({customKey:e,value:t,onChange:n,t:o,candidates:r,testidPrefix:s,showExprButton:a=!1,onToExpression:l,langToggle:d}){const{state:c}=Qe(),p=c.templateIdentifier,f=c.locale,b=Kt(),[g,m]=u.useState(null),h=u.useRef(""),v=u.useRef(null),y=u.useRef(null),_=u.useRef(null),[w,k]=u.useState(null),[x,$]=u.useState(!1),C=ys(t),S=u.useCallback(async()=>{const T=It(e,f);if(T!==void 0){h.current=T,m(T);return}const M=(await fn(p,e))?.values?.[f]??"";h.current=M,m(M)},[e,p,f]);u.useEffect(()=>{let T=!1;return(async()=>{const B=It(e,f);if(B!==void 0){T||(h.current=B,m(B));return}const M=await fn(p,e);if(T)return;const O=M?.values?.[f]??"";h.current=O,m(O)})(),()=>{T=!0}},[e,p,f]),u.useEffect(()=>{if(typeof window>"u")return;const T=B=>{const M=B.detail;if(M?.templateIdentifier&&M.templateIdentifier!==p)return;const O=It(e,f);O!==void 0&&O!==g&&(h.current=O,m(O))};return window.addEventListener(kt,T),()=>window.removeEventListener(kt,T)},[e,p,f,g]);const D=u.useCallback(T=>{m(T),Eo(p,e,f,T).then(()=>{b?.markDirty?.()})},[p,e,f,b]),E=u.useCallback(T=>{n(xo(t,T)),Ar(p,e,T,f).then(()=>{S(),b?.markDirty?.()})},[t,n,p,e,f,S,b]),I=u.useCallback(async T=>{if(!(w===null||x)){$(!0);try{g!==null&&g!==h.current&&(await Eo(p,e,f,g),h.current=g);const B=await Ir(p,f,t,w,T.sourceId,T.path,"scalar");B.kind==="ok"&&(n(B.text),await S(),b?.markDirty?.())}finally{$(!1),k(null)}}},[w,x,g,t,p,e,f,n,S,b]),N=!!r&&r.length>0;return i.jsxs("div",{"data-testid":`${s}-chipfield-wrap`,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:4},children:[i.jsx("div",{ref:v,"data-testid":`${s}-chipfield`,style:{flex:1,minWidth:0},children:g===null?i.jsx("div",{"data-testid":`${s}-chipfield-loading`,style:{fontSize:11,color:"#94a3b8",padding:"4px 0"},children:o("layout_editor.translation.loading")}):i.jsx(Sr,{value:g,onChange:D,t:o,paramLabels:C,testIdSuffix:`${s}-field`,onRequestInsert:N?T=>k(T):void 0,onRemoveChip:E,hideInsertButton:!0,caretRef:_})}),N&&i.jsx("button",{ref:y,type:"button","data-testid":`${s}-plus-data-btn`,onClick:()=>k(_.current?_.current():g?.length??0),title:o("layout_editor.inline_binding.insert_data"),"aria-label":o("layout_editor.inline_binding.insert_data"),style:zo,children:"+"}),a&&l&&i.jsx("button",{type:"button","data-testid":`${s}-to-expr`,onClick:l,title:o("layout_editor.value_tree.to_expression"),"aria-label":o("layout_editor.value_tree.to_expression"),style:zo,children:"ƒx"}),d,N&&i.jsx(Zn,{anchorRef:y,open:w!==null,onClose:()=>k(null),children:i.jsx("div",{"data-testid":`${s}-chipfield-picker`,children:i.jsx($t,{candidates:r,t:o,onSelect:T=>void I(T),testIdSuffix:`${s}-field-insert`,defaultOpen:!0,floating:!1})})})]})}function sx({value:e,customKey:t,onChange:n,t:o,candidates:r,testidPrefix:s}){const{state:a}=Qe(),l=a.templateIdentifier,d=a.selectedRoute?.layoutName??null,c=a.locale,p=Kt(),[f,b]=u.useState(!1),[g,m]=u.useState(!1),h=u.useRef(null),v=u.useCallback(w=>{const k=o(w);return k&&k!==w&&!k.startsWith("$t:")?k:""},[o]),y=u.useCallback(w=>w.replace(/\$t:[a-zA-Z0-9._-]+/g,k=>v(k.slice(3))).replace(/\s+/g," ").trim(),[v]),_=u.useCallback(async w=>{if(!g){m(!0);try{if(t){const k=await Ir(l,c,e,Number.MAX_SAFE_INTEGER,w.sourceId,w.path,"scalar");k.kind==="ok"&&(n(k.text),p?.markDirty?.())}else{const k=await hs(l,d,c,e,e.length,w.sourceId,w.path,"scalar",y,x=>o(x));k.kind==="ok"&&(n(k.text),p?.markDirty?.())}}finally{m(!1),b(!1)}}},[g,t,l,d,c,e,n,p,o,y]);return i.jsxs("div",{"data-testid":`${s}-plus-data`,style:{display:"inline-block"},children:[i.jsx("button",{ref:h,type:"button","data-testid":`${s}-plus-data-btn`,disabled:g,onClick:()=>b(w=>!w),title:o("layout_editor.inline_binding.insert_data"),"aria-label":o("layout_editor.inline_binding.insert_data"),style:zo,children:"+"}),i.jsx(Zn,{anchorRef:h,open:f,onClose:()=>b(!1),children:i.jsx($t,{candidates:r,t:o,onSelect:w=>void _(w),testIdSuffix:`${s}-plus-insert`,defaultOpen:!0,floating:!1})})]})}function ax({value:e,t,translate:n,onEdit:o,testidPrefix:r}){const s=ms(e,a=>{const l=n(a);return l&&l!==a&&!l.startsWith("$t:")?l:""},a=>Ut(a));return i.jsxs("div",{"data-testid":r,style:ux,children:[i.jsx("div",{"data-testid":`${r}-text`,style:px,children:s.length===0?i.jsx("span",{style:{color:"#94a3b8"},children:t("layout_editor.prop_i18n.placeholder")}):s.map((a,l)=>a.kind==="chip"?i.jsxs("span",{style:bc,children:["🔗 ",a.text]},l):i.jsx("span",{style:a.kind==="ellipsis"?mc:void 0,children:a.text},l))}),i.jsxs("button",{type:"button","data-testid":`${r}-edit`,onClick:o,style:fx,title:t("layout_editor.value_tree.edit"),"aria-label":t("layout_editor.value_tree.edit"),children:["✎ ",t("layout_editor.value_tree.edit")]})]})}function lx({value:e,onChange:t,t:n,candidates:o,testidPrefix:r}){const[s,a]=u.useState(!1),l=u.useRef(null),d=Ut(e);return i.jsxs("div",{"data-testid":r,style:{display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0},children:[i.jsxs("div",{style:dx,children:[i.jsxs("span",{"data-testid":`${r}-chip`,style:cx,children:["🔗 ",d]}),i.jsx("button",{ref:l,type:"button","data-testid":`${r}-change`,onClick:()=>a(c=>!c),style:zo,title:n("layout_editor.value_tree.change_data"),"aria-label":n("layout_editor.value_tree.change_data"),children:n("layout_editor.value_tree.change_data")})]}),i.jsx(Zn,{anchorRef:l,open:s,onClose:()=>a(!1),children:i.jsx($t,{candidates:o,t:n,onSelect:c=>{const p=c.path?c.path.split(".").filter(Boolean):[],f=[c.sourceId,...p].join("?.");t(`{{${f}}}`),a(!1)},testIdSuffix:`${r}-pick`,defaultOpen:!0,floating:!1})})]})}const dx={display:"flex",alignItems:"center",gap:6,width:"100%",minWidth:0,flexWrap:"wrap"},cx={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"3px 8px",borderRadius:12,wordBreak:"break-all"},ux={display:"flex",alignItems:"center",gap:8,width:"100%",minWidth:0},px={flex:1,minWidth:0,display:"flex",flexWrap:"wrap",alignItems:"center",gap:4,padding:"5px 8px",fontSize:12,color:"#334155",border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",overflow:"hidden"},bc={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"1px 6px",borderRadius:10,whiteSpace:"nowrap"},mc={color:"#94a3b8"},fx={padding:"4px 10px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",whiteSpace:"nowrap",flexShrink:0},vc={padding:"3px 10px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},gx={padding:"3px 10px",fontSize:11,border:"1px solid #fca5a5",borderRadius:6,background:"#fef2f2",color:"#b91c1c",cursor:"pointer",whiteSpace:"nowrap"},hx={display:"flex",flexDirection:"column",gap:6,padding:10,border:"1px solid #fca5a5",borderRadius:8,background:"#fffbeb"},yx={margin:0,fontSize:12,color:"#334155"},bx={padding:"5px 8px",fontSize:12,color:"#0f172a",background:"#fff",border:"1px solid #e2e8f0",borderRadius:6,wordBreak:"break-all"},mx={margin:0,fontSize:11,color:"#b45309"},vx={padding:"3px 12px",fontSize:11,border:"1px solid #dc2626",borderRadius:6,background:"#dc2626",color:"#fff",cursor:"pointer",whiteSpace:"nowrap"},_x={display:"flex",gap:4,alignItems:"center",width:"100%",minWidth:0},xx={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%"},_c={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},zo={padding:"4px 8px",fontSize:13,lineHeight:1,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},wx={display:"flex",alignItems:"center",gap:6,width:"100%",minWidth:0,flexWrap:"wrap"},kx={flex:1,minWidth:0,display:"flex",flexWrap:"wrap",alignItems:"center",gap:4,fontSize:12,color:"#334155"},Sx={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"2px 8px",borderRadius:12,whiteSpace:"nowrap"},Cx={display:"flex",flexDirection:"column",gap:2,width:"100%"},$x={fontSize:11,background:"#f1f5f9",padding:"3px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},Ex={fontSize:10,color:"#64748b"},Ix={fontSize:11,color:"#94a3b8",padding:"6px 8px",border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc"};function ks({value:e,onChange:t,candidates:n,t:o}){const r=Array.isArray(e)?e:[],s=n??[],[a,l]=u.useState(!1),d=g=>s.find(m=>m.value===g)?.label??g,c=g=>d(g)!==g,p=g=>{const m=r.filter(h=>h!==g);t(m.length===0?void 0:m)},f=g=>{r.includes(g)||(t([...r,g]),l(!1))},b=s.filter(g=>!r.includes(g.value));return i.jsxs("div",{className:"g7le-widget g7le-widget--tag-input","data-testid":"g7le-widget-tag-input",style:Ax,children:[i.jsxs("div",{style:Tx,children:[r.map(g=>i.jsxs("span",{"data-testid":`g7le-tag-chip-${g}`,style:Dx,children:[i.jsx("span",{style:zx,children:d(g)}),c(g)&&i.jsx("code",{"data-testid":`g7le-tag-chip-id-${g}`,style:Nx,children:g}),i.jsx("button",{type:"button","aria-label":`remove ${g}`,"data-testid":`g7le-tag-remove-${g}`,onClick:()=>p(g),style:Mx,children:"✕"})]},g)),i.jsx("button",{type:"button","data-testid":"g7le-tag-add",onClick:()=>l(g=>!g),disabled:b.length===0,style:Lx,children:o("layout_editor.control.tag_add")})]}),a&&b.length>0&&i.jsx("div",{"data-testid":"g7le-tag-candidates",style:Px,children:b.map(g=>{const m=g.value!==g.label;return i.jsxs("button",{type:"button","data-testid":`g7le-tag-candidate-${g.value}`,onClick:()=>f(g.value),style:Ox,children:[i.jsx("span",{style:Bx,children:g.label}),m&&i.jsx("code",{"data-testid":`g7le-tag-candidate-id-${g.value}`,style:Wx,children:g.value})]},g.value)})})]})}const Ax={display:"flex",flexDirection:"column",gap:6},Tx={display:"flex",flexWrap:"wrap",gap:4,alignItems:"center"},Dx={display:"inline-flex",alignItems:"center",gap:4,padding:"2px 6px",fontSize:12,background:"#e0e7ff",color:"#1d4ed8",borderRadius:12},zx={fontSize:12},Nx={fontSize:10,color:"#4f46e5",background:"#c7d2fe",borderRadius:4,padding:"0 4px",fontFamily:"monospace"},Mx={border:"none",background:"transparent",color:"#1d4ed8",cursor:"pointer",fontSize:10,padding:0,lineHeight:1},Lx={padding:"2px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:12,background:"#fff",cursor:"pointer",color:"#475569"},Px={display:"flex",flexDirection:"column",maxHeight:180,overflowY:"auto",border:"1px solid #cbd5e1",borderRadius:6,background:"#fff"},Ox={display:"flex",flexDirection:"column",gap:1,textAlign:"left",padding:"6px 10px",fontSize:12,border:"none",borderBottom:"1px solid #f1f5f9",background:"transparent",cursor:"pointer",color:"#0f172a"},Bx={fontSize:12,color:"#0f172a"},Wx={fontSize:10,color:"#64748b",fontFamily:"monospace"},xc=new Map;function Ge(e,t){xc.set(e,t)}function zn(e){return e?xc.get(e)??null:null}function Pr(e,t){const o=e("meta",{})?.[t];return typeof o=="string"?o:""}function jx({getValue:e,patch:t,t:n,fieldT:o,spec:r,permissionCandidates:s,bindingCandidates:a}){const l=o??n,d=Pr(e,"title"),c=Pr(e,"description"),p=Pr(e,"icon"),f=Pr(e,"editor_label"),b=e("permissions",[]),g=u.useCallback((y,_)=>{const w={...e("meta",{})??{}};_===void 0||_===""?delete w[y]:w[y]=_,t("meta",w)},[e,t]),m=u.useCallback(y=>{const _=Array.isArray(y)?y:[];_.length===0?t("permissions",void 0):t("permissions",_)},[t]),h=zn("icon-picker"),v=Ct(r,"icon-picker")??Ct(r,"icon")??(r?.controls?Object.values(r.controls).find(y=>y&&typeof y=="object"&&y.widget==="icon-picker")??null:null);return i.jsxs("div",{className:"g7le-meta-form","data-testid":"g7le-meta-form",style:Fx,children:[i.jsx(No,{label:n("layout_editor.page_settings.meta.title"),children:i.jsx(_t,{value:d,onChange:y=>g("title",y),t:l,testidPrefix:"g7le-meta-title",candidates:a,enableExpressionTree:!0,expressionTreeCollapsible:!0})}),i.jsx(No,{label:n("layout_editor.page_settings.meta.description"),children:i.jsx(_t,{value:c,onChange:y=>g("description",y),t:l,testidPrefix:"g7le-meta-description",candidates:a,enableExpressionTree:!0,expressionTreeCollapsible:!0})}),i.jsx(No,{label:n("layout_editor.page_settings.meta.icon"),children:h?i.jsx(Hx,{icon:p,t:n,onChange:y=>g("icon",typeof y=="string"?y:void 0),IconWidget:h,iconControl:v??{widget:"icon-picker"}}):i.jsx("input",{type:"text","data-testid":"g7le-meta-icon",value:p,placeholder:n("layout_editor.page_settings.meta.icon_placeholder"),onChange:y=>g("icon",y.target.value),style:qx})}),i.jsx(No,{label:n("layout_editor.page_settings.meta.editor_label"),hint:n("layout_editor.page_settings.meta.editor_label_hint"),children:i.jsx(_t,{value:f,onChange:y=>g("editor_label",y),t:l,testidPrefix:"g7le-meta-editor-label",candidates:a,enableExpressionTree:!0,expressionTreeCollapsible:!0})}),i.jsx(No,{label:n("layout_editor.page_settings.meta.permissions"),hint:n("layout_editor.page_settings.meta.permissions_hint"),children:i.jsx("div",{"data-testid":"g7le-meta-permissions",children:i.jsx(ks,{control:{widget:"tag-input"},value:b,onChange:m,t:n,candidates:s})})})]})}function No({label:e,hint:t,children:n}){return i.jsxs("div",{className:"g7le-meta-field",style:Kx,children:[i.jsx("label",{style:Vx,children:e}),n,t?i.jsxs("p",{style:Ux,children:["ⓘ ",t]}):null]})}function Hx({icon:e,onChange:t,t:n,IconWidget:o,iconControl:r}){const[s,a]=u.useState(!1),l=e?/\bfa-/.test(e)?i.jsx("i",{className:e,"aria-hidden":"true"}):e:"📄";return i.jsxs("div",{"data-testid":"g7le-meta-icon",style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:[i.jsxs("button",{type:"button","data-testid":"g7le-meta-icon-toggle","aria-expanded":s,onClick:()=>a(d=>!d),style:{display:"flex",alignItems:"center",gap:8,padding:"5px 8px",border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",cursor:"pointer",fontSize:12,color:"#475569",width:"fit-content"},children:[i.jsx("span",{style:{fontSize:16},"aria-hidden":"true",children:l}),i.jsx("span",{children:e||n("layout_editor.page_settings.meta.icon_placeholder")}),i.jsx("span",{"aria-hidden":"true",children:s?"▴":"▾"})]}),s?i.jsx(o,{control:r,value:e,onChange:d=>{t(d),a(!1)},t:n}):null]})}const Fx={display:"flex",flexDirection:"column",gap:16,minWidth:0},Kx={display:"flex",flexDirection:"column",gap:6,minWidth:0},Vx={fontSize:13,fontWeight:600,color:"#0f172a"},Ux={margin:0,fontSize:11,color:"#94a3b8"},qx={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%"};function Or({checked:e,onChange:t,label:n,testid:o,ariaLabel:r,disabled:s=!1}){return i.jsxs("label",{style:{...Zx,...s?{cursor:"not-allowed"}:{}},children:[i.jsx("button",{type:"button","data-testid":o,role:"switch","aria-checked":e,"aria-label":r,disabled:s,onClick:()=>t(!e),style:Qx(e,s),children:i.jsx("span",{style:Rx(e)})}),n!=null?i.jsx("span",{style:ew(s),children:n}):null]})}function Br({disabled:e,children:t,testid:n,style:o}){return i.jsx("div",{"data-testid":n,"data-disabled":e?"true":"false","aria-disabled":e,style:{...o,...e?{opacity:.5,pointerEvents:"none",userSelect:"none"}:{}},children:t})}function Gx({filled:e,sourceLabel:t,onRevert:n,revertLabel:o,hint:r,children:s,testid:a}){const l=e&&typeof n=="function",d=!e&&t!=null&&t!=="";return i.jsxs("div",{"data-testid":a,style:Yx,children:[s,l?i.jsxs("button",{type:"button","data-testid":a?`${a}-revert`:void 0,onClick:n,title:r??o,"aria-label":o,style:Jx,children:["↩ ",o]}):d?i.jsx("span",{"data-testid":a?`${a}-source`:void 0,title:r,style:Xx,children:t}):null]})}const Yx={position:"relative",minWidth:0,width:"100%"},Xx={position:"absolute",right:8,top:"50%",transform:"translateY(-50%)",fontSize:10,color:"#94a3b8",background:"#f1f5f9",borderRadius:4,padding:"1px 6px",pointerEvents:"none",maxWidth:"45%",overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},Jx={position:"absolute",right:6,top:"50%",transform:"translateY(-50%)",fontSize:10,color:"#0369a1",background:"#e0f2fe",border:"1px solid #bae6fd",borderRadius:4,padding:"1px 6px",cursor:"pointer",whiteSpace:"nowrap"},Zx={display:"inline-flex",alignItems:"center",gap:8,cursor:"pointer"},Qx=(e,t)=>({position:"relative",width:38,height:22,flexShrink:0,borderRadius:999,border:"none",padding:0,background:t?"#e2e8f0":e?"#2563eb":"#cbd5e1",cursor:t?"not-allowed":"pointer",transition:"background 0.15s ease"}),Rx=e=>({position:"absolute",top:2,left:e?18:2,width:18,height:18,borderRadius:"50%",background:"#fff",boxShadow:"0 1px 2px rgba(0,0,0,0.2)",transition:"left 0.15s ease"}),ew=e=>({fontSize:13,fontWeight:600,color:e?"#94a3b8":"#0f172a"}),tw=/\$(?:core|module|plugin)_settings:[a-zA-Z0-9._:-]+/;function nw(e){const t=[];let n=!1;const o=s=>{t.push({kind:"text",text:s}),n=!0},r=(s,a,l)=>{n||o(""),t.push({kind:"chip",raw:s,text:a,removable:l}),n=!1};for(const s of ow(e))s.kind==="text"?o(s.raw):r(s.raw,s.label,s.removable);return n||o(""),t}function ow(e){const t=[];if(typeof e!="string"||e.length===0)return t;const n=e.length;let o=0,r=0;const s=a=>{a>r&&t.push({kind:"text",raw:e.slice(r,a),label:"",removable:!1})};for(;o=n){o++;continue}s(o);const l=e.slice(o,a+2);t.push({kind:"chip",raw:l,label:Ut(l),removable:!0}),o=a+2,r=o;continue}if(e[o]==="$"){const a=tw.exec(e.slice(o));if(a&&a.index===0){s(o);const l=a[0],d=l.split(":").pop()||l;t.push({kind:"chip",raw:l,label:d,removable:!1}),o+=l.length,r=o;continue}}o++}return s(n),t}function rw(e,t,n,o){const r=[];let s=!1;return e.forEach((a,l)=>{if(a.kind==="chip"){if(!s&&a.raw===t){s=!0;return}r.push(a.raw??"")}else{const d=a.text??"";if(l===n){const c=Math.max(0,Math.min(o,d.length));r.push(d.slice(0,c),t,d.slice(c))}else r.push(d)}}),r.join("")}function iw(e,t,n){const o=Math.max(0,Math.min(t,e.length));return e.slice(0,o)+n+e.slice(o)}function sw(e,t){const n=e.indexOf(t);return n<0?e:e.slice(0,n)+e.slice(n+t.length)}function Ss({value:e,onChange:t,t:n,candidates:o,onDone:r,testidPrefix:s="g7le-binding-chip-text",disabled:a=!1}){const l=u.useMemo(()=>nw(e),[e]),d=u.useRef(null),c=!!o&&o.length>0,[p,f]=u.useState(null),[b,g]=u.useState(null),[m,h]=u.useState(null),[v,y]=u.useState(!1),_=u.useRef(0),w=u.useRef(null),k=u.useMemo(()=>l.map(P=>P.kind==="chip"?`c:${P.raw}`:"t").join("|"),[l]),x=u.useRef(null),$=u.useRef([]),C=u.useRef(!1);u.useLayoutEffect(()=>{const P=C.current;C.current=!1,!(!P&&x.current===k)&&(x.current=k,l.forEach((A,L)=>{if(A.kind!=="text")return;const F=$.current[L];F&&F.textContent!==(A.text??"")&&(F.textContent=A.text??"")}))},[k,l,e]);const S=u.useCallback(()=>{const P=d.current;if(!P)return e;const A=[];for(const L of Array.from(P.querySelectorAll("[data-seg]")))L.dataset.seg==="chip"?A.push(L.dataset.raw??""):A.push(L.textContent??"");return A.join("")},[e]),D=u.useCallback(()=>{a||t(S())},[a,t,S]),E=u.useRef(null),I=u.useRef(!1),N=(P,A)=>{if(!a){P.preventDefault(),P.stopPropagation(),E.current={raw:A,pointerId:P.pointerId},I.current=!1,f(A);try{P.currentTarget.setPointerCapture(P.pointerId)}catch{}}},T=P=>{const A=E.current;if(!A||P.pointerId!==A.pointerId)return;I.current=!0;const L=O(P.clientX,P.clientY);L&&(g({slotIdx:L.slotIdx,offset:L.offset}),h(lw(d.current,L.slotIdx,L.offset)))},B=(P,A)=>{if(P.stopPropagation(),I.current){I.current=!1;return}C.current=!0,t(sw(e,A))},M=P=>{const A=E.current;if(!A||P.pointerId!==A.pointerId)return;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}E.current=null,I.current&&typeof setTimeout=="function"&&setTimeout(()=>{I.current=!1},0);const L=O(P.clientX,P.clientY);if(f(null),g(null),h(null),!L)return;const F=d.current;if(!F)return;const V=Array.from(F.querySelectorAll("[data-seg]")).map(Z=>Z.dataset.seg==="chip"?{kind:"chip",raw:Z.dataset.raw??""}:{kind:"text",text:Z.textContent??""}),X=rw(V,A.raw,L.slotIdx,L.offset);X!==e&&(C.current=!0,t(X))},O=(P,A)=>{const L=d.current;if(!L)return null;const F=Array.from(L.querySelectorAll("[data-seg]")),Y=L.ownerDocument,V=Y.elementFromPoint(P,A),X=V?.closest('[data-seg="text"]');if(X)return{slotIdx:F.indexOf(X),offset:aw(Y,X,P,A)};const Z=V?.closest('[data-seg="chip"]');if(Z){const oe=F.indexOf(Z),G=Z.getBoundingClientRect();if(P=0){const ee=F[oe-1];return{slotIdx:oe-1,offset:(ee.textContent??"").length}}if(oe+1({s:oe,i:G})).filter(oe=>oe.s.dataset.seg==="text").pop();return ie?{slotIdx:ie.i,offset:(ie.s.textContent??"").length}:null},z=()=>{a||!c||(_.current=dw(d.current,e.length),y(P=>!P))},H=P=>{const A=P.path?P.path.split(".").filter(Boolean):[],L=[P.sourceId,...A].join("?.");C.current=!0,t(iw(e,_.current,`{{${L}}}`)),y(!1)};return i.jsxs("div",{"data-testid":s,style:{display:"flex",flexDirection:"column",gap:4},children:[i.jsxs("div",{ref:d,"data-testid":`${s}-box`,className:"g7le-binding-chip-input",style:cw,children:[l.map((P,A)=>P.kind==="chip"?i.jsxs("span",{"data-seg":"chip","data-raw":P.raw,"data-testid":`${s}-chip-${A}`,contentEditable:!1,onPointerDown:L=>N(L,P.raw??""),onPointerMove:T,onPointerUp:M,title:P.removable?n("layout_editor.value_tree.change_data"):n("layout_editor.prop_i18n.bound_code_only"),style:{...gw,...p===P.raw?hw:null,touchAction:"none"},children:[i.jsx("span",{"aria-hidden":"true",style:yw,children:"⠿"}),i.jsx("span",{"aria-hidden":"true",style:{marginRight:3},children:"🔗"}),i.jsx("span",{children:P.text}),P.removable&&!a&&i.jsx("button",{type:"button","data-testid":`${s}-chip-remove-${A}`,"aria-label":n("layout_editor.inline_binding.clear"),title:n("layout_editor.inline_binding.clear"),onPointerDown:L=>{L.stopPropagation(),L.preventDefault()},onClick:L=>B(L,P.raw??""),style:bw,children:"✕"})]},`chip-${P.raw}-${A}`):i.jsx("span",{ref:L=>{$.current[A]=L},"data-seg":"text",contentEditable:!a,suppressContentEditableWarning:!0,onInput:D,"data-testid":`${s}-text-${A}`,style:{...uw,...p?pw:null,...b?.slotIdx===A?fw:null}},`text-slot-${A}`)),m&&i.jsx("span",{"aria-hidden":"true","data-testid":`${s}-caret`,style:{position:"absolute",left:m.left,top:m.top,width:2,height:m.height,background:"#2563eb",borderRadius:1,pointerEvents:"none",boxShadow:"0 0 0 1px rgba(37,99,235,0.3)"}})]}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[r&&i.jsxs("button",{type:"button","data-testid":`${s}-done`,onClick:r,style:wc,title:n("layout_editor.value_tree.done"),"aria-label":n("layout_editor.value_tree.done"),children:["✓ ",n("layout_editor.value_tree.done")]}),c&&i.jsxs("div",{style:{position:"relative"},children:[i.jsxs("button",{ref:w,type:"button","data-testid":`${s}-insert`,onClick:z,disabled:a,style:wc,title:n("layout_editor.inline_binding.insert_data"),"aria-label":n("layout_editor.inline_binding.insert_data"),children:["+ ",n("layout_editor.inline_binding.insert_data")]}),i.jsx(Zn,{anchorRef:w,open:v,onClose:()=>y(!1),children:i.jsx($t,{candidates:o,t:n,onSelect:H,testIdSuffix:`${s}-insert`,defaultOpen:!0,floating:!1})})]}),i.jsx("span",{style:mw,children:n("layout_editor.translation.placeholder_locked")})]})]})}function aw(e,t,n,o){const r=(t.textContent??"").length;try{const a=e;let l=null,d=0;if(typeof a.caretRangeFromPoint=="function"){const c=a.caretRangeFromPoint(n,o);c&&(l=c.startContainer,d=c.startOffset)}else if(typeof a.caretPositionFromPoint=="function"){const c=a.caretPositionFromPoint(n,o);c&&(l=c.offsetNode,d=c.offset)}if(l&&t.contains(l))return Math.max(0,Math.min(d,r))}catch{}const s=t.getBoundingClientRect();return n>s.left+s.width/2?r:0}function lw(e,t,n){if(!e)return null;const r=Array.from(e.querySelectorAll("[data-seg]"))[t];if(!r)return null;const s=e.getBoundingClientRect();try{const d=r.firstChild,c=e.ownerDocument;if(d&&d.nodeType===Node.TEXT_NODE&&(d.textContent??"").length>0){const p=c.createRange(),f=Math.max(0,Math.min(n,(d.textContent??"").length));p.setStart(d,f),p.setEnd(d,f);const b=p.getClientRects(),g=b.length>0?b[0]:p.getBoundingClientRect();if(g&&(g.height>0||g.width>=0))return{left:g.left-s.left,top:g.top-s.top,height:g.height||r.getBoundingClientRect().height}}}catch{}const a=r.getBoundingClientRect();return{left:(n>0?a.right:a.left)-s.left,top:a.top-s.top,height:a.height||16}}function dw(e,t){if(!e)return t;try{const n=e.ownerDocument.defaultView?.getSelection();if(!n||n.rangeCount===0)return t;const o=n.getRangeAt(0);let r=o.startContainer,s=null;for(;r&&r!==e;){if(r instanceof HTMLElement&&r.dataset.seg==="text"){s=r;break}r=r.parentNode}if(!s||!e.contains(s))return t;const a=Array.from(e.querySelectorAll("[data-seg]"));let l=0;for(const d of a){if(d===s)break;l+=d.dataset.seg==="chip"?(d.dataset.raw??"").length:(d.textContent??"").length}return l+o.startOffset}catch{return t}}const cw={position:"relative",display:"flex",flexWrap:"wrap",alignItems:"center",gap:2,minHeight:30,padding:"4px 8px",border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",fontSize:12,lineHeight:1.6,minWidth:0,width:"100%",boxSizing:"border-box"},uw={outline:"none",minWidth:8,minHeight:"1.2em",whiteSpace:"pre-wrap",color:"#0f172a",display:"inline-block",wordBreak:"break-all"},pw={boxShadow:"inset 0 -2px 0 #93c5fd",background:"#eff6ff",borderRadius:2},fw={background:"#dbeafe",boxShadow:"inset 0 -2px 0 #2563eb"},gw={display:"inline-flex",alignItems:"center",gap:1,background:"linear-gradient(180deg,#eff6ff,#dbeafe)",color:"#1d4ed8",border:"1px dashed #60a5fa",borderRadius:9999,padding:"1px 8px 1px 4px",margin:"0 1px",fontSize:11,fontWeight:600,cursor:"grab",userSelect:"none",whiteSpace:"nowrap",boxShadow:"0 1px 2px rgba(37,99,235,0.18)",verticalAlign:"middle"},hw={opacity:.5,borderStyle:"solid",cursor:"grabbing"},yw={color:"#2563eb",opacity:.7,fontSize:11,marginRight:1,cursor:"grab"},bw={marginLeft:4,width:14,height:14,lineHeight:"12px",padding:0,border:"none",borderRadius:9999,background:"rgba(29,78,216,0.12)",color:"#1d4ed8",fontSize:9,fontWeight:700,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto"},wc={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},mw={fontSize:10,color:"#94a3b8"},vw=Rl;function Cs(e){return Vb(e)}function Ke({value:e,onChange:t,t:n,candidates:o,placeholder:r,testidPrefix:s="g7le-data-chip-value",readOnly:a=!1,enableExpressionTree:l=!0}){const d=typeof e=="string"?e:"",c=!!o&&o.length>0,[p,f]=u.useState(!1),[b,g]=u.useState(!1),[m,h]=u.useState(!1),v=u.useCallback(C=>i.jsx(Ke,{value:C.value,onChange:S=>C.onChange(S),t:C.t,candidates:C.candidates,testidPrefix:C.testidPrefix,enableExpressionTree:!0}),[]),y=()=>i.jsx("div",{style:{display:"flex",gap:4,alignItems:"center",width:"100%",minWidth:0},children:i.jsx("input",{type:"text","data-testid":`${s}-input`,value:d,placeholder:r??n("layout_editor.page_settings.seo.value_placeholder"),readOnly:a,onChange:C=>t(C.target.value),onFocus:()=>f(!0),onBlur:()=>f(!1),style:{flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%",background:a?"#f1f5f9":"#fff",color:a?"#64748b":"#0f172a"}})}),_=u.useCallback(C=>{const S=d?`${d} ${C.expression}`:C.expression;t(S)},[d,t]);if(!l||a)return i.jsxs("div",{"data-testid":s,style:hn,children:[y(),!a&&c&&i.jsx($t,{candidates:o,t:n,onSelect:_,testIdSuffix:`${s}-pick`})]});const w=n_(d),k=tc(d),x=Vt(d),$=C=>{const S=Tr(d),D=S?ms(S,()=>"",E=>Ut(E)):[];return i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{display:"flex",justifyContent:"flex-start"},children:i.jsxs("button",{type:"button","data-testid":`${C}-to-plain`,onClick:()=>h(!0),style:kw,title:n("layout_editor.value_tree.to_plain"),"aria-label":n("layout_editor.value_tree.to_plain"),children:["↩ ",n("layout_editor.value_tree.to_plain")]})}),m&&i.jsxs("div",{"data-testid":`${C}-to-plain-confirm`,style:Sw,children:[i.jsx("p",{style:Cw,children:n("layout_editor.value_tree.to_plain_lead")}),i.jsx("div",{style:$w,children:D.length===0?i.jsx("span",{style:{color:"#94a3b8"},children:n("layout_editor.page_settings.seo.value_placeholder")}):D.map((E,I)=>E.kind==="chip"?i.jsxs("span",{style:$s,children:["🔗 ",E.text]},I):i.jsx("span",{style:E.kind==="ellipsis"?{color:"#94a3b8"}:void 0,children:E.text},I))}),i.jsxs("p",{style:Ew,children:["⚠ ",n("layout_editor.value_tree.to_plain_warn")]}),i.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[i.jsx("button",{type:"button","data-testid":`${C}-to-plain-confirm-cancel`,onClick:()=>h(!1),style:qt,children:n("layout_editor.value_tree.to_plain_cancel")}),i.jsx("button",{type:"button","data-testid":`${C}-to-plain-confirm-ok`,onClick:()=>{h(!1),t(Tr(d)||"")},style:Iw,children:n("layout_editor.value_tree.to_plain_ok")})]})]})]})};if(!p&&(w==="expression"||k)){if(k)return i.jsxs("div",{"data-testid":s,style:hn,children:[!a&&$(`${s}-seg`),i.jsx(xs,{value:d,onChange:S=>t(S),t:n,candidates:o,testidPrefix:`${s}-seg`,renderLeafInput:v})]});const C=gn(d);return i.jsxs("div",{"data-testid":s,style:hn,children:[!a&&$(`${s}-tree`),i.jsx(cc,{node:C.node,onChange:S=>t(Rn(S,!1)),t:n,candidates:o,testidPrefix:`${s}-tree`,renderLeafInput:v})]})}if(x&&!p&&!b)return i.jsx(_w,{value:d,onChange:t,t:n,candidates:o,testidPrefix:s,onEditRaw:()=>g(!0)});if(!p&&!b&&Cs(d)){const C=vw(d);return i.jsx("div",{"data-testid":s,style:hn,children:i.jsxs("div",{style:kc,children:[i.jsx("div",{"data-testid":`${s}-chips`,style:xw,children:C.map((S,D)=>S.kind==="chip"?i.jsxs("span",{style:$s,children:["🔗 ",S.label]},D):i.jsx("span",{children:S.label},D))}),i.jsxs("button",{type:"button","data-testid":`${s}-edit-raw`,onClick:()=>g(!0),style:qt,title:n("layout_editor.value_tree.edit"),"aria-label":n("layout_editor.value_tree.edit"),children:["✎ ",n("layout_editor.value_tree.edit")]})]})})}return b&&Cs(d)?i.jsxs("div",{"data-testid":s,style:hn,children:[i.jsx(Ss,{value:d,onChange:t,t:n,candidates:o,disabled:a,onDone:()=>g(!1),testidPrefix:`${s}-chipedit`}),!a&&w!=="raw"&&i.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:[i.jsxs("button",{type:"button","data-testid":`${s}-to-expr`,onClick:()=>t(Ao(d)),style:qt,title:n("layout_editor.value_tree.to_expression"),"aria-label":n("layout_editor.value_tree.to_expression"),children:["ƒx ",n("layout_editor.value_tree.to_expression")]}),i.jsxs("button",{type:"button","data-testid":`${s}-to-fallback`,onClick:()=>t(vs(d)),style:qt,title:n("layout_editor.value_tree.segment.fallback"),"aria-label":n("layout_editor.value_tree.segment.fallback"),children:["?? ",n("layout_editor.value_tree.segment.fallback")]})]}),w==="raw"&&i.jsxs("p",{"data-testid":`${s}-raw-hint`,style:Es,children:["ⓘ ",n("layout_editor.value_tree.raw_expression_hint")]})]}):!p&&Cs(d)?i.jsxs("div",{"data-testid":s,style:hn,children:[i.jsx(Ss,{value:d,onChange:t,t:n,candidates:o,disabled:a,onDone:()=>{g(!1),f(!1)},testidPrefix:`${s}-chipedit`}),!a&&w!=="raw"&&i.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:[i.jsxs("button",{type:"button","data-testid":`${s}-to-expr`,onClick:()=>t(Ao(d)),style:qt,title:n("layout_editor.value_tree.to_expression"),"aria-label":n("layout_editor.value_tree.to_expression"),children:["ƒx ",n("layout_editor.value_tree.to_expression")]}),i.jsxs("button",{type:"button","data-testid":`${s}-to-fallback`,onClick:()=>t(vs(d)),style:qt,title:n("layout_editor.value_tree.segment.fallback"),"aria-label":n("layout_editor.value_tree.segment.fallback"),children:["?? ",n("layout_editor.value_tree.segment.fallback")]})]}),w==="raw"&&i.jsxs("p",{"data-testid":`${s}-raw-hint`,style:Es,children:["ⓘ ",n("layout_editor.value_tree.raw_expression_hint")]})]}):i.jsxs("div",{"data-testid":s,style:hn,children:[y(),i.jsxs("div",{style:ww,children:[c&&i.jsx($t,{candidates:o,t:n,onSelect:_,testIdSuffix:`${s}-pick`}),w!=="raw"&&i.jsxs("div",{style:{display:"flex",gap:4},children:[i.jsxs("button",{type:"button","data-testid":`${s}-to-expr`,onClick:()=>t(Ao(d)),style:qt,title:n("layout_editor.value_tree.to_expression"),"aria-label":n("layout_editor.value_tree.to_expression"),children:["ƒx ",n("layout_editor.value_tree.to_expression")]}),i.jsxs("button",{type:"button","data-testid":`${s}-to-fallback`,onClick:()=>t(vs(d)),style:qt,title:n("layout_editor.value_tree.segment.fallback"),"aria-label":n("layout_editor.value_tree.segment.fallback"),children:["?? ",n("layout_editor.value_tree.segment.fallback")]})]})]}),w==="raw"&&!p&&i.jsxs("p",{"data-testid":`${s}-raw-hint`,style:Es,children:["ⓘ ",n("layout_editor.value_tree.raw_expression_hint")]})]})}function _w({value:e,onChange:t,t:n,candidates:o,testidPrefix:r,onEditRaw:s}){const[a,l]=u.useState(!1),d=u.useRef(null),c=Ut(e),p=!!o&&o.length>0,f=Vt(e)?.localeFn;return i.jsxs("div",{"data-testid":r,style:hn,children:[i.jsxs("div",{style:kc,children:[i.jsxs("span",{"data-testid":`${r}-chip`,style:$s,children:["🔗 ",c]}),p&&i.jsx("button",{ref:d,type:"button","data-testid":`${r}-change`,onClick:()=>l(b=>!b),style:qt,title:n("layout_editor.value_tree.change_data"),"aria-label":n("layout_editor.value_tree.change_data"),children:n("layout_editor.value_tree.change_data")}),i.jsx("button",{type:"button","data-testid":`${r}-edit-raw`,onClick:s,style:qt,title:n("layout_editor.value_tree.edit"),"aria-label":n("layout_editor.value_tree.edit"),children:"✎"})]}),p&&i.jsx(Zn,{anchorRef:d,open:a,onClose:()=>l(!1),children:i.jsx($t,{candidates:o,t:n,onSelect:b=>{if(f){const h=[b.sourceId,...b.path?b.path.split(".").filter(Boolean):[]].join(".");t(`{{${f}(${h})}}`),l(!1);return}const g=b.path?b.path.split(".").filter(Boolean):[],m=[b.sourceId,...g].join("?.");t(`{{${m}}}`),l(!1)},testIdSuffix:`${r}-pick`,defaultOpen:!0,floating:!1})})]})}const hn={display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0},kc={display:"flex",alignItems:"center",gap:6,width:"100%",minWidth:0,flexWrap:"wrap"},xw={flex:1,minWidth:0,display:"flex",flexWrap:"wrap",alignItems:"center",gap:4,padding:"5px 8px",fontSize:12,color:"#334155",border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc"},$s={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"2px 8px",borderRadius:12,whiteSpace:"nowrap"},qt={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},ww={display:"flex",flexWrap:"wrap",alignItems:"center",gap:6},Es={margin:"2px 0 0",fontSize:11,color:"#94a3b8",lineHeight:1.4},kw={padding:"3px 10px",fontSize:11,border:"1px solid #fca5a5",borderRadius:6,background:"#fef2f2",color:"#b91c1c",cursor:"pointer",whiteSpace:"nowrap"},Sw={display:"flex",flexDirection:"column",gap:6,padding:10,border:"1px solid #fca5a5",borderRadius:8,background:"#fffbeb"},Cw={margin:0,fontSize:12,color:"#334155"},$w={padding:"5px 8px",fontSize:12,color:"#0f172a",background:"#fff",border:"1px solid #e2e8f0",borderRadius:6,wordBreak:"break-all",display:"flex",flexWrap:"wrap",gap:4,alignItems:"center"},Ew={margin:0,fontSize:11,color:"#b45309"},Iw={padding:"3px 12px",fontSize:11,border:"1px solid #dc2626",borderRadius:6,background:"#dc2626",color:"#fff",cursor:"pointer",whiteSpace:"nowrap"};let Sc=0;function Wr({value:e,onChange:t,keyField:n,valueField:o="content",t:r,candidates:s,testidPrefix:a="g7le-kv-chip-editor",keyPlaceholder:l,valuePlaceholder:d,addLabel:c,renderKeyInput:p}){const f=u.useMemo(()=>(Array.isArray(e)?e:[]).map(w=>({id:Sc++,k:typeof w[n]=="string"?w[n]:"",v:typeof w[o]=="string"?w[o]:""})),[]),[b,g]=u.useState(f),m=u.useCallback(w=>{g(w);const k=w.filter(x=>x.k.trim()!=="").map(x=>({[n]:x.k,[o]:x.v}));t(k)},[n,o,t]),h=u.useCallback(()=>{m([...b,{id:Sc++,k:"",v:""}])},[b,m]),v=u.useCallback(w=>{m(b.filter(k=>k.id!==w))},[b,m]),y=u.useCallback((w,k)=>{m(b.map(x=>x.id===w?{...x,k}:x))},[b,m]),_=u.useCallback((w,k)=>{m(b.map(x=>x.id===w?{...x,v:k}:x))},[b,m]);return i.jsxs("div",{"data-testid":a,style:{display:"flex",flexDirection:"column",gap:6},children:[b.map(w=>i.jsxs("div",{"data-testid":`${a}-row-${w.id}`,style:{display:"flex",gap:6,alignItems:"flex-start",border:"1px solid #e2e8f0",borderRadius:8,padding:8},children:[i.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:6},children:[i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,minWidth:0},children:p?i.jsx("div",{style:{minWidth:0},children:p({value:w.k,onChange:k=>y(w.id,k),testid:`${a}-key-${w.id}`,placeholder:l??r(`layout_editor.page_settings.seo.extra_${n}`)})}):i.jsx("input",{type:"text","data-testid":`${a}-key-${w.id}`,value:w.k,placeholder:l??r(`layout_editor.page_settings.seo.extra_${n}`),onChange:k=>y(w.id,k.target.value),style:{width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,boxSizing:"border-box"}})}),i.jsx("div",{style:{minWidth:0},children:i.jsx(Ke,{value:w.v,onChange:k=>_(w.id,k),t:r,candidates:s,placeholder:d??r("layout_editor.page_settings.seo.extra_content"),testidPrefix:`${a}-value-${w.id}`})})]}),i.jsx("button",{type:"button","data-testid":`${a}-remove-${w.id}`,onClick:()=>v(w.id),title:r("layout_editor.page_settings.seo.remove"),"aria-label":r("layout_editor.page_settings.seo.remove"),style:{flex:"0 0 auto",padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},children:"✕"})]},w.id)),i.jsxs("button",{type:"button","data-testid":`${a}-add`,onClick:h,style:{alignSelf:"flex-start",padding:"5px 10px",fontSize:12,border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},children:["+ ",c??r("layout_editor.page_settings.seo.add_extra")]})]})}const Aw=["website","article","product","profile"],Tw=["summary","summary_large_image","app","player"];function Dw(e){switch(e){case"core":return"layout_editor.page_settings.seo.og_source_core";case"inherited":return"layout_editor.page_settings.seo.og_source_inherited";case"filter":return"layout_editor.page_settings.seo.og_source_filter";case"layout":return null;default:return e?"layout_editor.page_settings.seo.og_source_module":null}}function Cc(e){const t={};for(const n of e??[])t[n.key]=n;return t}function $c(e,t){return!!e&&t&&typeof e.sourceExpr=="string"&&e.sourceExpr!==""&&!e.overriddenByLayout&&!e.lockedByFilter}function Ec({label:e,sourceExpr:t,onReplace:n,t:o,testid:r}){return i.jsxs("div",{"data-testid":r,style:Hw,children:[i.jsxs("span",{"data-testid":`${r}-chip`,style:Fw,title:t,children:["🔗 ",e||t]}),i.jsx("span",{"data-testid":`${r}-badge`,style:Kw,children:o("layout_editor.page_settings.seo.auto_chip_source")}),i.jsx("button",{type:"button","data-testid":`${r}-replace`,onClick:n,style:Vw,children:o("layout_editor.page_settings.seo.auto_chip_replace")})]})}function zw({og:e,twitter:t,onChangeOg:n,onChangeTwitter:o,ogPreview:r,twitterPreview:s,defaultsAvailable:a=!1,candidates:l,t:d,testidPrefix:c="g7le-seo-og"}){const p=e&&typeof e=="object"?e:{},f=t&&typeof t=="object"?t:{},[b,g]=u.useState(p.image_height!=null||p.image_type!=null||p.image_secure_url!=null),m=Cc(r),h=Cc(s),v=u.useCallback((D,E)=>{const I={...p};E===void 0||E===""||E===null?delete I[D]:I[D]=E,n(I)},[p,n]),y=u.useCallback((D,E)=>{const I={...f};E===void 0||E===""||E===null?delete I[D]:I[D]=E,o(I)},[f,o]),_=(D,E,I)=>!I||!a||!I.lockedByFilter?null:i.jsx("div",{style:{display:"flex",gap:6,alignItems:"center",marginTop:2},children:i.jsxs("span",{"data-testid":`${D}-locked-${E}`,style:Bw,children:["🔒 ",d("layout_editor.page_settings.seo.og_locked")]})}),w=D=>{if(!D||!a||D.lockedByFilter||D.overriddenByLayout)return;const E=Dw(D.source);return E?d(E):void 0},k=(D,E)=>D&&a?D.overriddenByLayout===!0:E!=="",x=(D,E,I,N,T,B)=>{const M=B[E],O=!!M?.lockedByFilter,z=typeof N[E]=="string"?N[E]:"";return i.jsxs("div",{"data-testid":`${D}-${E}`,style:Nn,children:[i.jsx("label",{style:oo,children:d(I)}),O?i.jsx("div",{"data-testid":`${D}-locked-value-${E}`,style:Ow,children:String(M?.effectiveValue??"")}):$c(M,a)?i.jsx(Ec,{label:M.label??"",sourceExpr:M.sourceExpr,onReplace:()=>T(E,M.sourceExpr),t:d,testid:`${D}-${E}-auto`}):i.jsx(_t,{value:z,onChange:H=>T(E,H??""),t:d,candidates:l,placeholder:a&&M?.effectiveValue!=null?String(M.effectiveValue):void 0,testidPrefix:`${D}-${E}-field`,enableExpressionTree:!0,expressionTreeCollapsible:!0}),_(D,E,M)]})},$=(D,E,I,N,T,B)=>{const M=B[E],O=!!M?.lockedByFilter,z=typeof N[E]=="string"?N[E]:"";return i.jsxs("div",{"data-testid":`${D}-${E}`,style:Nn,children:[i.jsx("label",{style:oo,children:d(I)}),$c(M,a)?i.jsx(Ec,{label:M.label??"",sourceExpr:M.sourceExpr,onReplace:()=>T(E,M.sourceExpr),t:d,testid:`${D}-${E}-auto`}):i.jsx(Ke,{value:z,onChange:H=>T(E,H),t:d,candidates:l,readOnly:O,placeholder:a&&M?.effectiveValue!=null?String(M.effectiveValue):void 0,testidPrefix:`${D}-${E}-field`}),_(D,E,M)]})},C=(D,E,I,N,T,B)=>{const M=B[E],O=!!M?.lockedByFilter,z=typeof N[E]=="string"?N[E]:"",H=k(M,z),P=H?z:"";return i.jsxs("div",{"data-testid":`${D}-${E}`,style:Nn,children:[i.jsx("label",{style:oo,children:d(I)}),i.jsx(Gx,{filled:H,sourceLabel:w(M),onRevert:O?void 0:()=>T(E,void 0),revertLabel:d("layout_editor.page_settings.seo.revert_default"),testid:`${D}-${E}-overlay`,children:i.jsx("div",{"data-testid":`${D}-${E}-input`,style:{minWidth:0},children:i.jsx(Ke,{value:P,onChange:A=>T(E,A),t:d,candidates:l,readOnly:O,placeholder:a&&M?.effectiveValue!=null?String(M.effectiveValue):void 0,testidPrefix:`${D}-${E}-chip`})})}),_(D,E,M)]})},S=(D,E,I,N,T,B,M)=>{const O=M[E],z=typeof T[E]=="string"?T[E]:"",H=k(O,z),P=w(O),A=H?z:"";return i.jsxs("div",{"data-testid":`${D}-${E}`,style:Nn,children:[i.jsxs("div",{style:Mw,children:[i.jsx("label",{style:oo,children:d(I)}),P?i.jsxs("span",{"data-testid":`${D}-${E}-source-inline`,style:Lw,children:["· ",P]}):null]}),i.jsxs("select",{"data-testid":`${D}-${E}-select`,value:A,onChange:L=>B(E,L.target.value),style:Pw,children:[i.jsx("option",{value:"",children:a&&O?.effectiveValue!=null&&O.effectiveValue!==""?`${d("layout_editor.page_settings.seo.use_default")} (${String(O.effectiveValue)})`:d("layout_editor.page_settings.seo.use_default")}),N.map(L=>i.jsx("option",{value:L,children:L},L))]}),_(D,E,O)]})};return i.jsxs("div",{"data-testid":c,style:{display:"flex",flexDirection:"column",gap:12},children:[i.jsxs("div",{"data-testid":`${c}-og-section`,style:Ic,children:[i.jsx("div",{style:Ac,children:d("layout_editor.page_settings.seo.og_section")}),i.jsxs("p",{"data-testid":`${c}-intro`,style:Nw,children:["ⓘ ",d("layout_editor.page_settings.seo.og_intro")]}),S(c,"type","layout_editor.page_settings.seo.og_type",Aw,p,v,m),x(c,"title","layout_editor.page_settings.seo.og_title",p,v,m),x(c,"description","layout_editor.page_settings.seo.og_description",p,v,m),$(c,"image","layout_editor.page_settings.seo.og_image",p,v,m),x(c,"image_alt","layout_editor.page_settings.seo.og_image_alt",p,v,m),i.jsxs("div",{style:Nn,children:[i.jsxs("button",{type:"button","data-testid":`${c}-image-adv-toggle`,"aria-expanded":b,onClick:()=>g(D=>!D),style:Ww,children:[b?"▾":"▸"," ",d("layout_editor.page_settings.seo.og_image_adv")]}),b?i.jsxs("div",{"data-testid":`${c}-image-adv`,style:jw,children:[C(c,"image_height","layout_editor.page_settings.seo.og_image_height",p,v,m),C(c,"image_type","layout_editor.page_settings.seo.og_image_type",p,v,m),C(c,"image_secure_url","layout_editor.page_settings.seo.og_image_secure_url",p,v,m)]}):null]}),C(c,"site_name","layout_editor.page_settings.seo.og_site_name",p,v,m),C(c,"locale","layout_editor.page_settings.seo.og_locale",p,v,m),i.jsxs("div",{"data-testid":`${c}-extra`,style:Nn,children:[i.jsx("label",{style:oo,children:d("layout_editor.page_settings.seo.og_extra")}),i.jsx(Wr,{value:Array.isArray(p.extra)?p.extra:[],onChange:D=>v("extra",D.length>0?D:void 0),keyField:"property",t:d,candidates:l,testidPrefix:`${c}-extra-editor`})]})]}),i.jsxs("div",{"data-testid":`${c}-tw-section`,style:Ic,children:[i.jsx("div",{style:Ac,children:d("layout_editor.page_settings.seo.tw_section")}),i.jsx("p",{style:{margin:"0 0 6px",fontSize:11,color:"#94a3b8"},children:d("layout_editor.page_settings.seo.tw_fallback_note")}),S("g7le-seo-tw","card","layout_editor.page_settings.seo.tw_card",Tw,f,y,h),C("g7le-seo-tw","site","layout_editor.page_settings.seo.tw_site",f,y,h),C("g7le-seo-tw","creator","layout_editor.page_settings.seo.tw_creator",f,y,h),x("g7le-seo-tw","title","layout_editor.page_settings.seo.tw_title",f,y,h),x("g7le-seo-tw","description","layout_editor.page_settings.seo.tw_description",f,y,h),$("g7le-seo-tw","image","layout_editor.page_settings.seo.tw_image",f,y,h),x("g7le-seo-tw","image_alt","layout_editor.page_settings.seo.tw_image_alt",f,y,h),i.jsxs("div",{"data-testid":"g7le-seo-tw-extra",style:Nn,children:[i.jsx("label",{style:oo,children:d("layout_editor.page_settings.seo.tw_extra")}),i.jsx(Wr,{value:Array.isArray(f.extra)?f.extra:[],onChange:D=>y("extra",D.length>0?D:void 0),keyField:"name",t:d,candidates:l,testidPrefix:"g7le-seo-tw-extra-editor"})]})]})]})}const Ic={border:"1px solid #e2e8f0",borderRadius:8,padding:12,display:"flex",flexDirection:"column",gap:10},Ac={fontSize:13,fontWeight:600,color:"#0f172a"},Nw={margin:0,fontSize:11,color:"#64748b",background:"#f8fafc",borderRadius:6,padding:"6px 8px"},Nn={display:"flex",flexDirection:"column",gap:4},oo={fontSize:12,color:"#475569"},Mw={display:"flex",alignItems:"center",gap:6},Lw={fontSize:11,color:"#94a3b8"},Pw={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",minWidth:0,boxSizing:"border-box"},Ow={padding:"5px 8px",fontSize:12,border:"1px solid #e2e8f0",borderRadius:6,background:"#f1f5f9",color:"#64748b"},Bw={fontSize:11,color:"#7c3aed"},Ww={alignSelf:"flex-start",padding:"2px 0",fontSize:12,fontWeight:600,color:"#475569",background:"transparent",border:"none",cursor:"pointer"},jw={display:"flex",flexDirection:"column",gap:8,paddingLeft:14,marginTop:4,minWidth:0},Hw={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",minWidth:0},Fw={display:"inline-flex",alignItems:"center",maxWidth:"100%",padding:"3px 8px",fontSize:12,color:"#1d4ed8",background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:6,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Kw={fontSize:11,color:"#94a3b8"},Vw={padding:"2px 8px",fontSize:11,color:"#475569",background:"#fff",border:"1px solid #cbd5e1",borderRadius:6,cursor:"pointer"},Uw=["WebPage","WebSite","ItemList","BreadcrumbList","Organization","Person","CollectionPage","AboutPage","ContactPage","SearchAction"];function jr(e){const t=[],n=(o,r)=>{for(const[s,a]of Object.entries(o)){if(s==="@type"||s==="@context")continue;const l=r?`${r}.${s}`:s;a!==null&&typeof a=="object"&&!Array.isArray(a)?n(a,l):t.push({key:l,value:a==null?"":String(a)})}};return n(e,""),t}function Tc(e,t){const n={"@type":e};for(const{key:o,value:r}of t){if(o.trim()==="")continue;const s=o.split(".");let a=n;for(let l=0;lp?jr(e).map(T=>({id:Is++,...T})):[]),_=u.useCallback((T,B)=>{h(T),y(B),t(Tc(T,B.map(M=>({key:M.key,value:M.value}))))},[t]),w=u.useCallback(()=>{const T=n,B=typeof T["@type"]=="string"?T["@type"]:m,M=jr(T).map(O=>({id:Is++,key:O.key,value:o?.[O.key]?.expr??O.value}));return{type:B,rows:M}},[n,o,m]),k=u.useCallback(T=>{if(b(T),T){if(v.length===0&&n&&typeof n=="object"){const B=w();_(B.type,B.rows);return}t(Tc(m,v.map(B=>({key:B.key,value:B.value}))))}else t(null)},[m,v,n,w,_,t]),x=u.useCallback(()=>{if(!n)return;const T=w();_(T.type,T.rows)},[n,w,_]),$=u.useCallback(()=>{_(m,[...v,{id:Is++,key:"",value:""}])},[m,v,_]),C=u.useCallback(T=>{_(m,v.filter(B=>B.id!==T))},[m,v,_]),S=u.useCallback((T,B)=>{_(m,v.map(M=>M.id===T?{...M,key:B}:M))},[m,v,_]),D=u.useCallback((T,B)=>{_(m,v.map(M=>M.id===T?{...M,value:B}:M))},[m,v,_]),E=u.useMemo(()=>n?jr(n):[],[n]),I=u.useMemo(()=>s?jr(s):[],[s]),N=v.some(T=>T.key.trim()!==""&&T.value.trim()==="");if(r){const T=s&&typeof s["@type"]=="string"?s["@type"]:"";return i.jsxs("div",{"data-testid":c,style:Dc,children:[i.jsxs("div",{style:zc,children:[i.jsx("span",{style:Gw,children:"🔒"}),i.jsx("span",{style:{fontSize:13,fontWeight:600},children:d("layout_editor.page_settings.seo.sd_mode")}),i.jsx("span",{"data-testid":`${c}-locked-badge`,style:Yw,children:d("layout_editor.page_settings.seo.sd_filter_locked")})]}),i.jsxs("div",{"data-testid":`${c}-locked`,style:Xw,children:[i.jsxs("p",{style:{margin:"0 0 6px",fontSize:12,color:"#475569"},children:["ⓘ ",d("layout_editor.page_settings.seo.sd_filter_locked_note")]}),i.jsxs("div",{"data-testid":`${c}-filtered-block`,children:[T?i.jsxs("div",{style:{fontSize:12,fontWeight:600,marginBottom:4},children:["@type: ",T]}):null,I.map(B=>i.jsxs("div",{"data-testid":`${c}-filtered-row-${B.key}`,style:Nc,children:[i.jsx("code",{style:Mc,children:B.key}),i.jsx("span",{style:Lc,children:B.value})]},B.key))]})]})]})}return i.jsxs("div",{"data-testid":c,style:Dc,children:[i.jsx("div",{style:zc,children:i.jsx(Or,{checked:f,onChange:k,testid:`${c}-mode`,label:d("layout_editor.page_settings.seo.sd_manual_toggle")})}),!f&&i.jsxs("div",{"data-testid":`${c}-auto`,style:{marginTop:8},children:[i.jsxs("div",{"data-testid":`${c}-auto-preview`,style:Jw,children:[i.jsxs("div",{style:{fontSize:12,fontWeight:600,marginBottom:6},children:[d("layout_editor.page_settings.seo.sd_auto_title"),n&&typeof n["@type"]=="string"?`: ${n["@type"]}`:"",a?i.jsxs("span",{style:{marginLeft:6,color:"#94a3b8",fontWeight:400},children:["(",a,")"]}):null]}),E.length===0?i.jsx("p",{style:{margin:0,fontSize:12,color:"#94a3b8"},children:d("layout_editor.page_settings.seo.sd_auto_empty")}):E.map(T=>{const B=o?.[T.key];return i.jsxs("div",{"data-testid":`${c}-auto-row-${T.key}`,style:Nc,children:[i.jsx("code",{style:Mc,children:T.key}),B?i.jsxs("span",{"data-testid":`${c}-auto-chip-${T.key}`,style:Zw,title:B.expr,children:["🔗 ",B.label||B.expr]}):i.jsx("span",{style:Lc,children:T.value})]},T.key)})]}),i.jsxs("p",{"data-testid":`${c}-replace-warn`,style:Qw,children:["ⓘ ",d("layout_editor.page_settings.seo.sd_replace_pre_warn")]})]}),f&&i.jsxs("div",{"data-testid":`${c}-manual`,style:{marginTop:8},children:[i.jsxs("p",{"data-testid":`${c}-replace-warn`,style:Rw,children:["⚠ ",d("layout_editor.page_settings.seo.sd_replace_warn")]}),i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[i.jsx("label",{style:{fontSize:12,color:"#475569"},children:d("layout_editor.page_settings.seo.sd_type")}),i.jsx("input",{type:"text","data-testid":`${c}-type`,list:`${c}-type-options`,value:m,onChange:T=>_(T.target.value,v),style:e0}),i.jsx("datalist",{id:`${c}-type-options`,children:Uw.map(T=>i.jsx("option",{value:T},T))})]}),i.jsx("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:6},children:v.map(T=>i.jsxs("div",{"data-testid":`${c}-prop-${T.id}`,style:t0,children:[i.jsx("input",{type:"text","data-testid":`${c}-prop-key-${T.id}`,value:T.key,placeholder:d("layout_editor.page_settings.seo.sd_prop_key"),onChange:B=>S(T.id,B.target.value),style:{width:160,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0}}),i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:T.value,onChange:B=>D(T.id,B),t:d,candidates:l,placeholder:d("layout_editor.page_settings.seo.sd_prop_value"),testidPrefix:`${c}-prop-value-${T.id}`})}),i.jsx("button",{type:"button","data-testid":`${c}-prop-remove-${T.id}`,onClick:()=>C(T.id),title:d("layout_editor.page_settings.seo.remove"),"aria-label":d("layout_editor.page_settings.seo.remove"),style:n0,children:"✕"})]},T.id))}),i.jsxs("div",{style:{marginTop:8,display:"flex",gap:8},children:[i.jsxs("button",{type:"button","data-testid":`${c}-add`,onClick:$,style:Pc,children:["+ ",d("layout_editor.page_settings.seo.sd_add_prop")]}),n?i.jsxs("button",{type:"button","data-testid":`${c}-seed-from-module`,onClick:x,style:Pc,children:["↩ ",d("layout_editor.page_settings.seo.sd_seed_from_module")]}):null]}),i.jsxs("p",{"data-testid":`${c}-empty-note`,style:o0,children:["ⓘ ",d("layout_editor.page_settings.seo.sd_empty_note"),N?i.jsxs("span",{style:{color:"#b45309"},children:[" ",d("layout_editor.page_settings.seo.sd_has_empty")]}):null]})]})]})}const Dc={display:"flex",flexDirection:"column"},zc={display:"flex",alignItems:"center",gap:8},Gw={fontSize:14},Yw={fontSize:11,padding:"2px 6px",borderRadius:4,background:"#f1f5f9",color:"#64748b"},Xw={marginTop:8,border:"1px solid #fcd34d",borderRadius:8,padding:10,background:"#fffbeb"},Jw={border:"1px solid #e2e8f0",borderRadius:8,padding:10,background:"#f8fafc"},Nc={display:"flex",gap:8,alignItems:"center",padding:"2px 0"},Mc={fontSize:11,color:"#475569",background:"#fff",padding:"2px 6px",borderRadius:4,minWidth:120},Lc={fontSize:11,color:"#0f172a",fontFamily:"monospace",wordBreak:"break-all"},Zw={display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:11,color:"#1d4ed8",background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:6},Qw={margin:"6px 0 0",fontSize:12,color:"#64748b"},Rw={margin:"0 0 8px",fontSize:12,color:"#b45309",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,padding:"6px 8px"},e0={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",minWidth:0},t0={display:"flex",gap:6,alignItems:"flex-start",border:"1px solid #e2e8f0",borderRadius:8,padding:8},n0={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},Pc={padding:"5px 10px",fontSize:12,border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},o0={margin:"8px 0 0",fontSize:11,color:"#94a3b8"},Oc=new Set(["core_setting","setting","query","route"]);function r0({vars:e,onChange:t,varCandidates:n,gatingMet:o=!1,candidates:r,t:s,testidPrefix:a="g7le-seo-vars"}){const l=u.useMemo(()=>e&&typeof e=="object"?{...e}:{},[e]),d=u.useMemo(()=>Array.isArray(n)?n:[],[n]),c=u.useMemo(()=>o?d.filter(x=>Oc.has(x.source)):[],[d,o]),p=u.useMemo(()=>o?d.filter(x=>x.source==="data"):[],[d,o]);u.useMemo(()=>new Set(c.map(x=>x.name)),[c]);const f=u.useMemo(()=>new Set(p.map(x=>x.name)),[p]),b=u.useMemo(()=>{const x=new Set;for(const $ of d)Oc.has($.source)&&x.add($.name);return x},[d]),g=u.useMemo(()=>Object.keys(l).filter(x=>!f.has(x)),[l,f]),m=u.useCallback((x,$)=>{const C={...l};$===void 0?delete C[x]:C[x]=$,t(C)},[l,t]),[h,v]=u.useState(""),y=h.trim()!==""&&b.has(h.trim()),_=h.trim()!==""&&Object.prototype.hasOwnProperty.call(l,h.trim()),w=h.trim()!==""&&!y&&!_&&!f.has(h.trim()),k=u.useCallback(()=>{const x=h.trim();x===""||b.has(x)||Object.prototype.hasOwnProperty.call(l,x)||(t({...l,[x]:""}),v(""))},[h,b,l,t]);return i.jsxs("div",{"data-testid":a,style:{display:"flex",flexDirection:"column",gap:10},children:[i.jsx("span",{"data-testid":"g7le-seo-var-list",hidden:!0,"data-gating":o?"1":"0"}),!o&&i.jsxs("div",{"data-testid":`${a}-precondition`,style:i0,children:["⚠ ",s("layout_editor.page_settings.seo.vars_precondition")]}),c.length>0&&i.jsxs("div",{"data-testid":`${a}-auto-group`,style:As,children:[i.jsx("div",{style:Ts,children:s("layout_editor.page_settings.seo.vars_auto_group")}),c.map(x=>i.jsxs("div",{"data-testid":`g7le-seo-var-auto-${x.name}`,style:s0,children:[i.jsx("span",{style:a0,children:"🔒"}),i.jsx("code",{style:Ds,children:x.name}),i.jsxs("span",{style:l0,children:["〔",s("layout_editor.page_settings.seo.vars_auto"),"·",x.source,"〕"]}),x.owner?.name?i.jsx("span",{style:d0,children:x.owner.name}):null]},x.name))]}),p.length>0&&i.jsxs("div",{"data-testid":`${a}-data-group`,style:As,children:[i.jsx("div",{style:Ts,children:s("layout_editor.page_settings.seo.vars_data_group")}),p.map(x=>{const $=l[x.name]??"",C=$.trim()==="";return i.jsxs("div",{"data-testid":`g7le-seo-var-data-${x.name}`,style:Bc,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[i.jsx("code",{style:Ds,children:x.name}),x.required?i.jsx("span",{"data-testid":`g7le-seo-var-required-${x.name}`,style:c0,children:"*"}):null]}),i.jsx(Ke,{value:$,onChange:S=>m(x.name,S??""),t:s,candidates:r,testidPrefix:`g7le-seo-var-data-field-${x.name}`}),x.required&&C?i.jsxs("p",{"data-testid":`g7le-seo-var-empty-warn-${x.name}`,style:zs,children:["⚠ ",s("layout_editor.page_settings.seo.vars_required_empty")]}):null]},x.name)})]}),i.jsxs("div",{"data-testid":`${a}-custom-group`,style:As,children:[i.jsx("div",{style:Ts,children:s("layout_editor.page_settings.seo.vars_custom_group")}),g.map(x=>i.jsxs("div",{"data-testid":`g7le-seo-var-custom-${x}`,style:Bc,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[i.jsx("code",{style:Ds,children:x}),i.jsx("button",{type:"button","data-testid":`g7le-seo-var-custom-remove-${x}`,onClick:()=>m(x,void 0),title:s("layout_editor.page_settings.seo.remove"),"aria-label":s("layout_editor.page_settings.seo.remove"),style:{marginLeft:"auto",padding:"2px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},children:"✕"})]}),i.jsx(Ke,{value:l[x]??"",onChange:$=>m(x,$??""),t:s,candidates:r,testidPrefix:`g7le-seo-var-custom-field-${x}`})]},x)),i.jsxs("div",{"data-testid":"g7le-seo-var-add",style:{display:"flex",flexDirection:"column",gap:4,marginTop:6},children:[i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("input",{type:"text","data-testid":"g7le-seo-var-add-name",value:h,placeholder:s("layout_editor.page_settings.seo.vars_add_name"),onChange:x=>v(x.target.value),style:{flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0}}),i.jsxs("button",{type:"button","data-testid":"g7le-seo-var-add-confirm",onClick:k,disabled:h.trim()===""||y||_,style:u0,children:["+ ",s("layout_editor.page_settings.seo.vars_add")]})]}),y?i.jsxs("p",{"data-testid":"g7le-seo-var-add-reserved-warn",style:zs,children:["⚠ ",s("layout_editor.page_settings.seo.vars_name_reserved",{name:h.trim()})]}):null,_&&!y?i.jsxs("p",{"data-testid":"g7le-seo-var-add-duplicate-warn",style:zs,children:["⚠ ",s("layout_editor.page_settings.seo.vars_name_duplicate",{name:h.trim()})]}):null,w?i.jsxs("p",{"data-testid":"g7le-seo-var-add-not-provided-hint",style:{margin:0,fontSize:11,color:"#94a3b8"},children:["ⓘ ",s("layout_editor.page_settings.seo.vars_name_not_provided",{name:h.trim()})]}):null]})]}),i.jsxs("p",{style:{margin:0,fontSize:11,color:"#94a3b8"},children:["ⓘ ",s("layout_editor.page_settings.seo.vars_value_hint")]})]})}const i0={fontSize:12,color:"#b45309",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,padding:"6px 8px"},As={border:"1px solid #e2e8f0",borderRadius:8,padding:10,display:"flex",flexDirection:"column",gap:6},Ts={fontSize:12,fontWeight:600,color:"#475569"},s0={display:"flex",alignItems:"center",gap:6,padding:"2px 0"},Bc={display:"flex",flexDirection:"column",border:"1px solid #f1f5f9",borderRadius:6,padding:8},a0={fontSize:13},Ds={fontSize:12,color:"#0f172a",background:"#f1f5f9",padding:"2px 6px",borderRadius:4},l0={fontSize:11,color:"#64748b"},d0={fontSize:11,color:"#94a3b8"},c0={color:"#dc2626",fontWeight:700},zs={margin:"4px 0 0",fontSize:11,color:"#b45309"},u0={padding:"5px 10px",fontSize:12,border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"};function p0({templateIdentifier:e,layout:t,url:n,locale:o,seedContext:r,routeParams:s,settingsSignature:a,t:l,debounceMs:d=400,fetchImpl:c,testidPrefix:p="g7le-seo-bot-preview"}){const[f,b]=u.useState(!0),[g,m]=u.useState(null),[h,v]=u.useState(!1),[y,_]=u.useState(null),w=u.useRef(null),k=u.useRef({templateIdentifier:e,layout:t,url:n,locale:o,seedContext:r,routeParams:s});k.current={templateIdentifier:e,layout:t,url:n,locale:o,seedContext:r,routeParams:s};const x=u.useCallback(async()=>{const D=c??(typeof fetch<"u"?fetch:void 0);if(!D)return;const{templateIdentifier:E,layout:I,url:N,locale:T,seedContext:B,routeParams:M}=k.current;v(!0),_(null);try{const O=`/api/admin/templates/${encodeURIComponent(E)}/editor/seo-bot-preview`,z=await D(O,{method:"POST",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({layout:I,url:N,locale:T,seed_context:B??{},route_params:M??{}})}),H=await z.json().catch(()=>null);if(!z.ok){_(H?.message??`HTTP ${z.status}`);return}const P=H?.data??null;m(P)}catch(O){_(O instanceof Error?O.message:String(O))}finally{v(!1)}},[c]);u.useEffect(()=>{if(f)return w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{x()},d),()=>{w.current&&clearTimeout(w.current)}},[a,f,d,x]);const $=u.useCallback(()=>{w.current&&clearTimeout(w.current),x()},[x]),C=g?.html??null,S=g?.enabled??!0;return i.jsxs("div",{"data-testid":p,style:f0,children:[i.jsxs("div",{style:g0,children:[i.jsxs("button",{type:"button","data-testid":`${p}-toggle`,onClick:()=>b(D=>!D),"aria-expanded":f,style:h0,children:[f?"▾":"▸"," ",l("layout_editor.page_settings.seo.bot_preview_title")]}),f?i.jsxs("button",{type:"button","data-testid":`${p}-refresh`,onClick:$,disabled:h,style:y0,children:["⟳ ",l("layout_editor.page_settings.seo.bot_preview_refresh")]}):null]}),f&&i.jsxs("div",{style:{marginTop:8},children:[g&&!S?i.jsxs("p",{"data-testid":`${p}-disabled`,style:b0,children:["ⓘ ",l("layout_editor.page_settings.seo.bot_preview_disabled")]}):i.jsx("div",{"data-testid":`${p}-body`,style:m0,children:h&&!C?i.jsx("p",{style:Ns,children:l("layout_editor.translation.loading")}):y?i.jsx("p",{"data-testid":`${p}-error`,style:{...Ns,color:"#dc2626"},children:y}):C==null?i.jsx("p",{style:Ns,children:l("layout_editor.page_settings.seo.bot_preview_empty")}):i.jsx("pre",{"data-testid":`${p}-code`,style:v0,children:C})}),i.jsxs("p",{"data-testid":`${p}-sample-note`,style:_0,children:["ⓘ ",l("layout_editor.page_settings.seo.bot_preview_sample_note")]})]})]})}const f0={borderTop:"1px solid #e2e8f0",paddingTop:10,marginTop:12},g0={display:"flex",alignItems:"center",gap:8},h0={background:"none",border:"none",cursor:"pointer",fontSize:13,fontWeight:600,color:"#0f172a",padding:0},y0={marginLeft:"auto",padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},b0={margin:0,fontSize:12,color:"#64748b",background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,padding:"8px 10px"},m0={border:"1px solid #e2e8f0",borderRadius:8,background:"#0b1020",padding:0,minHeight:80,overflow:"hidden"},v0={margin:0,padding:12,fontSize:11,lineHeight:1.5,color:"#d1fae5",fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto"},Ns={margin:0,padding:12,fontSize:12,color:"#94a3b8"},_0={margin:"8px 0 0",fontSize:11,color:"#94a3b8"};function Wc({option:e,testIdPrefix:t}){const{id:n,friendly:o,source:r}=e;return i.jsxs("span",{style:x0,children:[i.jsx("span",{"data-testid":t?`${t}-title`:void 0,style:w0,children:o??n}),o?i.jsx("span",{"data-testid":t?`${t}-id`:void 0,style:k0,children:n}):null,r?i.jsx("span",{"data-testid":t?`${t}-source`:void 0,style:S0,children:r}):null]})}const x0={display:"inline-flex",alignItems:"baseline",gap:4,flexWrap:"wrap",minWidth:0},w0={fontSize:12,color:"#0f172a"},k0={fontSize:10,color:"#94a3b8",fontFamily:"ui-monospace, monospace"},S0={fontSize:9,fontWeight:600,color:"#7c3aed",background:"#f5f3ff",border:"1px solid #ddd6fe",borderRadius:4,padding:"0 5px",whiteSpace:"nowrap"},C0=["always","hourly","daily","weekly","monthly","yearly","never"];function $0({getValue:e,patch:t,t:n,templateIdentifier:o,candidates:r,availableExtensions:s=[],dataSourceOptions:a=[],previewUrl:l="/",previewLocale:d="ko",seedContext:c,candidatesFetcher:p,ogPreviewFetcher:f,botFetchImpl:b,testidPrefix:g="g7le-seo"}){const m=e("meta",{}).seo,h=m&&typeof m=="object"?m:{},v=u.useCallback((K,te)=>{const ye={...e("meta",{})},Se={...ye.seo??{}};te==null||te===""?delete Se[K]:Se[K]=te,ye.seo=Se,t("meta",ye)},[e,t]),y=h.enabled===!0,_=typeof h.page_type=="string"?h.page_type:"",w=Array.isArray(h.extensions)?h.extensions:[],k=Array.isArray(h.data_sources)?h.data_sources:[],x=w.length>0&&_!=="",[$,C]=u.useState(null),[S,D]=u.useState(null),E=u.useCallback(async(K,te)=>{if(p)return p(K,te);if(typeof fetch>"u")return null;const ye=new URLSearchParams;K&&ye.set("page_type",K),Array.isArray(te)&&te.length>0&&ye.set("extensions",JSON.stringify(te.map(Ve=>({type:Ve.type,id:Ve.id}))));const Se=ye.toString()?`?${ye.toString()}`:"",De=await fetch(nn(`/api/admin/templates/${encodeURIComponent(o)}/editor/seo-candidates`,"json",null,Se.replace(/^[?&]+/,"")),{credentials:"same-origin",headers:Me()}),Ie=await De.json().catch(()=>null);return De.ok?Ie?.data??null:null},[p,o]),I=u.useMemo(()=>{const ye=(e("__editor",{})??{}).original?.meta?.seo;return ye&&typeof ye=="object"?ye:void 0},[e]),N=u.useRef(I);N.current=I;const T=u.useCallback(async K=>{if(f)return f(K);if(typeof fetch>"u")return null;const te=await fetch(`/api/admin/templates/${encodeURIComponent(o)}/editor/seo-og-preview`,{method:"POST",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({seo:K,own_seo:N.current??null,seed_context:c??{},route_params:{}})}),ye=await te.json().catch(()=>null);return te.ok?ye?.data??null:null},[f,o,c]),B=u.useMemo(()=>JSON.stringify(w),[w]),M=u.useRef(h);M.current=h,u.useEffect(()=>{let K=!1;return(async()=>{const te=await E(_,w);K||C(te)})(),()=>{K=!0}},[_,B]);const O=u.useMemo(()=>JSON.stringify({og:h.og??null,twitter:h.twitter??null,structured_data:h.structured_data??null}),[h.og,h.twitter,h.structured_data]),z=u.useRef(!1);u.useEffect(()=>{let K=!1;const te=()=>{(async()=>{const Se=await T(M.current);K||D(Se)})()};if(!z.current)return z.current=!0,te(),()=>{K=!0};const ye=setTimeout(te,180);return()=>{K=!0,clearTimeout(ye)}},[_,B,O]);const H=$?.page_types??[],P=$?.toggle_settings??[],A=$?.vars??[],L=u.useMemo(()=>JSON.stringify(h),[h]),F=u.useMemo(()=>e("meta")?{meta:e("meta"),components:e("components",[])}:{meta:{},components:[]},[e]),Y=u.useCallback(K=>{w.some(te=>te.type===K.type&&te.id===K.id)||v("extensions",[...w,{type:K.type,id:K.id}])},[w,v]),V=u.useCallback(K=>{const te=w.filter(ye=>!(ye.type===K.type&&ye.id===K.id));v("extensions",te.length>0?te:void 0)},[w,v]),[X,Z]=u.useState(!1),[ie,oe]=u.useState(""),G=u.useMemo(()=>{const K=ie.trim().toLowerCase();return K?P.filter(te=>`${te.ref} ${te.label??""}`.toLowerCase().includes(K)):P},[P,ie]),ee=typeof h.toggle_setting=="string"?h.toggle_setting:"",fe=u.useCallback(K=>{const ye=k.includes(K)?k.filter(Se=>Se!==K):[...k,K];v("data_sources",ye.length>0?ye:void 0)},[k,v]);return i.jsxs("div",{"data-testid":g,style:{display:"flex",flexDirection:"column",gap:14},children:[i.jsxs("div",{style:Wt,children:[i.jsx(Or,{checked:y,onChange:K=>v("enabled",K),testid:`${g}-enabled`,label:n("layout_editor.page_settings.seo.enabled")}),y?null:i.jsxs("p",{"data-testid":`${g}-disabled-note`,style:ro,children:["ⓘ ",n("layout_editor.page_settings.seo.disabled_note")]})]}),i.jsx(Br,{disabled:!y,testid:`${g}-body`,style:{display:"flex",flexDirection:"column",gap:14},children:i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.page_type")}),H.length>0?i.jsxs("select",{"data-testid":`${g}-page-type`,value:_,onChange:K=>v("page_type",K.target.value),style:Hr,children:[i.jsx("option",{value:"",children:n("layout_editor.page_settings.seo.page_type_none")}),H.map(K=>i.jsxs("option",{value:K.value,children:[K.label??K.value,K.owner?.name?` (${K.owner.name})`:""]},K.value))]}):i.jsxs(i.Fragment,{children:[i.jsx("input",{type:"text","data-testid":`${g}-page-type-free`,value:_,placeholder:n("layout_editor.page_settings.seo.page_type_free_placeholder"),onChange:K=>v("page_type",K.target.value),style:Hr}),i.jsxs("p",{"data-testid":`${g}-page-type-free-note`,style:ro,children:["ⓘ ",n("layout_editor.page_settings.seo.page_type_free_note")]})]})]}),i.jsxs("div",{style:Wt,children:[i.jsxs("label",{style:Gt,children:["★ ",n("layout_editor.page_settings.seo.extensions")]}),i.jsxs("div",{"data-testid":`${g}-extensions`,style:{display:"flex",flexWrap:"wrap",gap:6},children:[w.map(K=>i.jsxs("span",{"data-testid":`${g}-extension-${K.type}-${K.id}`,style:jc,children:[K.name??`${K.type}:${K.id}`,i.jsx("button",{type:"button","data-testid":`${g}-extension-remove-${K.type}-${K.id}`,onClick:()=>V(K),style:Hc,children:"✕"})]},`${K.type}:${K.id}`)),i.jsxs("button",{type:"button","data-testid":`${g}-extension-add`,onClick:()=>Z(K=>!K),style:A0,children:["+ ",n("layout_editor.page_settings.seo.add_extension")]})]}),X&&i.jsx("div",{"data-testid":`${g}-extension-picker`,style:Fc,children:s.length===0?i.jsx("p",{style:ro,children:n("layout_editor.page_settings.seo.no_extension_candidate")}):s.map(K=>i.jsx("button",{type:"button","data-testid":`${g}-extension-option-${K.type}-${K.id}`,onClick:()=>{Y(K),Z(!1)},style:Kc,children:K.name??`${K.type}:${K.id}`},`${K.type}:${K.id}`))})]}),!x&&i.jsxs("div",{"data-testid":`${g}-defaults-precondition`,style:I0,children:["⚠ ",n("layout_editor.page_settings.seo.defaults_precondition"),i.jsxs("div",{"data-testid":`${g}-defaults-missing`,style:{fontSize:11,marginTop:4},children:[w.length===0?n("layout_editor.page_settings.seo.missing_extensions"):"",_===""?` ${n("layout_editor.page_settings.seo.missing_page_type")}`:""]})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.toggle_setting")}),i.jsxs("div",{"data-testid":`${g}-toggle-setting`,children:[ee?i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",marginBottom:4},children:[i.jsx("code",{style:jc,children:ee}),i.jsx("button",{type:"button","data-testid":`${g}-toggle-setting-clear`,onClick:()=>v("toggle_setting",void 0),style:Hc,children:"✕"})]}):null,i.jsx("input",{type:"text","data-testid":`${g}-toggle-setting-search`,value:ie,placeholder:n("layout_editor.page_settings.seo.toggle_setting_search"),onChange:K=>oe(K.target.value),style:Hr}),ie.trim()!==""&&i.jsx("div",{"data-testid":`${g}-toggle-setting-results`,style:Fc,children:G.length===0?i.jsx("p",{style:ro,children:n("layout_editor.inline_binding.no_results")}):G.map(K=>i.jsx("button",{type:"button","data-testid":`${g}-toggle-setting-option-${K.ref}`,onClick:()=>{v("toggle_setting",K.ref),oe("")},style:Kc,children:K.label??K.ref},K.ref))})]})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.data_sources")}),i.jsx("p",{style:ro,children:n("layout_editor.page_settings.seo.data_sources_hint")}),i.jsx("div",{"data-testid":`${g}-data-sources`,style:{display:"flex",flexDirection:"column",gap:6},children:a.length===0?i.jsx("span",{style:ro,children:n("layout_editor.page_settings.seo.data_sources_empty")}):a.map(K=>{const te=k.includes(K.id);return i.jsxs("label",{"data-testid":`${g}-data-source-${K.id}`,style:E0(te),children:[i.jsx("input",{type:"checkbox","data-testid":`${g}-data-source-check-${K.id}`,checked:te,onChange:()=>fe(K.id)}),i.jsx(Wc,{option:K,testIdPrefix:`${g}-data-source-${K.id}`})]},K.id)})})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.priority")}),i.jsx("input",{type:"range","data-testid":`${g}-priority`,min:0,max:1,step:.1,value:typeof h.priority=="number"?h.priority:.5,onChange:K=>v("priority",Number(K.target.value))}),i.jsx("span",{"data-testid":`${g}-priority-value`,style:{fontSize:12,color:"#475569"},children:typeof h.priority=="number"?h.priority:.5})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.changefreq")}),i.jsxs("select",{"data-testid":`${g}-changefreq`,value:typeof h.changefreq=="string"?h.changefreq:"",onChange:K=>v("changefreq",K.target.value),style:Hr,children:[i.jsx("option",{value:"",children:n("layout_editor.page_settings.seo.use_default")}),C0.map(K=>i.jsx("option",{value:K,children:K},K))]})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.title")}),i.jsx(_t,{value:typeof h.title=="string"?h.title:"",onChange:K=>v("title",K??""),t:n,candidates:r,testidPrefix:`${g}-title`,enableExpressionTree:!0,expressionTreeCollapsible:!0})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.description")}),i.jsx(_t,{value:typeof h.description=="string"?h.description:"",onChange:K=>v("description",K??""),t:n,candidates:r,testidPrefix:`${g}-description`,enableExpressionTree:!0,expressionTreeCollapsible:!0})]}),i.jsx(zw,{og:h.og,twitter:h.twitter,onChangeOg:K=>v("og",Object.keys(K).length>0?K:void 0),onChangeTwitter:K=>v("twitter",Object.keys(K).length>0?K:void 0),ogPreview:S?.og,twitterPreview:S?.twitter,defaultsAvailable:S?.defaultsAvailable??!1,candidates:r,t:n}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.structured_data")}),i.jsx(qw,{value:h.structured_data,onChange:K=>v("structured_data",K??void 0),autoBlock:S?.structured?.autoBlock,autoMeta:S?.structured?.autoMeta,lockedByFilter:S?.structured?.lockedByFilter,filteredBlock:S?.structured?.filteredBlock,pageType:_,candidates:r,t:n})]}),i.jsxs("div",{style:Wt,children:[i.jsx("label",{style:Gt,children:n("layout_editor.page_settings.seo.vars")}),i.jsx(r0,{vars:h.vars,onChange:K=>v("vars",Object.keys(K).length>0?K:void 0),varCandidates:A,gatingMet:x,candidates:r,t:n})]}),i.jsx(p0,{templateIdentifier:o,layout:F,url:l,locale:d,seedContext:c,settingsSignature:L,t:n,fetchImpl:b})]})})]})}const Wt={display:"flex",flexDirection:"column",gap:4},Gt={fontSize:12,fontWeight:600,color:"#334155"},Hr={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",minWidth:0,boxSizing:"border-box"},ro={margin:"4px 0 0",fontSize:11,color:"#94a3b8"},E0=e=>({display:"flex",alignItems:"center",gap:8,padding:"6px 10px",fontSize:12,border:`1px solid ${e?"#3b82f6":"#e2e8f0"}`,borderRadius:8,background:e?"#eff6ff":"#fff",cursor:"pointer",minWidth:0}),I0={fontSize:12,color:"#b45309",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,padding:"8px 10px"},jc={display:"inline-flex",alignItems:"center",gap:4,fontSize:11,padding:"3px 8px",borderRadius:999,background:"#eef2ff",color:"#3730a3"},Hc={border:"none",background:"transparent",cursor:"pointer",color:"#6366f1",fontSize:11,padding:0},A0={fontSize:11,padding:"3px 10px",borderRadius:999,border:"1px dashed #cbd5e1",background:"#f8fafc",color:"#475569",cursor:"pointer"},Fc={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6,display:"flex",flexDirection:"column",gap:2},Kc={textAlign:"left",border:"none",background:"transparent",cursor:"pointer",padding:"5px 8px",borderRadius:4,fontSize:12,color:"#0f172a"},T0={setState:"state",loadFromLocalStorage:"state",saveToLocalStorage:"state",navigate:"nav",openWindow:"nav",navigateBack:"nav",navigateForward:"nav",replaceUrl:"nav",toast:"notify",openModal:"notify",closeModal:"notify",showAlert:"notify",setError:"notify",refetchDataSource:"data",appendDataSource:"data",updateDataSource:"data",apiCall:"data",scrollIntoView:"etc",login:"etc",loginTwoFactor:"etc",loginTwoFactorResend:"etc",logout:"etc",setLocale:"locale",emitEvent:"etc",conditions:"flow",sequence:"flow",parallel:"flow",switch:"flow",suppress:"flow",showErrorPage:"error"},D0={state:"layout_editor.action.group.state",nav:"layout_editor.action.group.nav",notify:"layout_editor.action.group.notify",data:"layout_editor.action.group.data",locale:"layout_editor.action.group.locale",etc:"layout_editor.action.group.etc",flow:"layout_editor.action.group.flow",error:"layout_editor.action.group.error",extension:"layout_editor.action.group.extension"},z0={init:["state","data","notify","nav","locale","etc","flow","error","extension"],component:["nav","notify","data","state","locale","etc","flow","error","extension"]};function N0(e,t){const n=e?.[t];if(n&&typeof n=="object"){const o=n.__source;if(o&&typeof o=="object")return o}return null}function M0(e,t){return!e||e.kind==="core"?t("layout_editor.action.source_core"):e.id??t(`layout_editor.action.source_${e.kind}`)}function Vc(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function L0({recipes:e,t,onAdd:n,context:o="init",testIdPrefix:r="g7le-action-add"}){const[s,a]=u.useState(!1),[l,d]=u.useState(""),c=u.useMemo(()=>$o(e),[e]),p=u.useMemo(()=>{const f=z0[o],b=new Map;for(const m of c){const h=N0(e,m.id),y=h!=null&&h.kind!=="core"?"extension":T0[m.id]??"etc",_=b.get(y)??[];_.push({recipe:m,source:h}),b.set(y,_)}const g=l.trim().toLowerCase();return f.map(m=>{let h=b.get(m)??[];return g&&(h=h.filter(({recipe:v})=>Vc(v.label,t,v.id).toLowerCase().includes(g)||v.id.toLowerCase().includes(g)||v.build.handler.toLowerCase().includes(g))),{groupKey:m,items:h}}).filter(m=>m.items.length>0)},[c,e,o,l,t]);return c.length===0?i.jsx("div",{"data-testid":`${r}-empty`,style:U0,children:t("layout_editor.action.no_recipes")}):i.jsxs("div",{className:r,"data-testid":r,style:{minWidth:0},children:[i.jsxs("button",{type:"button","data-testid":`${r}-toggle`,onClick:()=>a(f=>!f),style:P0,children:[t("layout_editor.action.add_action")," ▾"]}),s?i.jsxs("div",{"data-testid":`${r}-list`,style:O0,children:[i.jsx("input",{type:"text","data-testid":`${r}-search`,value:l,placeholder:t("layout_editor.action.add_search"),onChange:f=>d(f.target.value),style:B0}),p.map(({groupKey:f,items:b})=>i.jsxs("div",{"data-testid":`${r}-group-${f}`,children:[i.jsxs("div",{style:W0,children:["━━ ",t(D0[f]??f)," ━━"]}),b.map(({recipe:g,source:m})=>i.jsxs("button",{type:"button","data-testid":`g7le-init-action-spec-${g.id}`,onClick:()=>{n(Er(g,{})),a(!1),d("")},style:j0,children:[i.jsx("span",{style:H0,children:Vc(g.label,t,g.id)}),i.jsxs("span",{"data-testid":`g7le-init-action-spec-source-${g.id}`,style:F0,children:["〔",M0(m,t),"〕"]}),i.jsx("code",{style:K0,children:g.build.handler})]},g.id))]},f)),p.length===0?i.jsx("div",{"data-testid":`${r}-no-match`,style:V0,children:t("layout_editor.action.add_no_match")}):null]}):null]})}const P0={padding:"6px 12px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},O0={marginTop:6,border:"1px solid #cbd5e1",borderRadius:8,background:"#fff",maxHeight:320,overflowY:"auto",padding:8},B0={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,marginBottom:6,boxSizing:"border-box"},W0={fontSize:11,fontWeight:700,color:"#94a3b8",padding:"6px 4px 2px"},j0={display:"flex",alignItems:"center",gap:6,width:"100%",textAlign:"left",padding:"6px 8px",fontSize:12,border:"none",background:"transparent",cursor:"pointer",borderRadius:6},H0={flex:1,minWidth:0,color:"#0f172a"},F0={fontSize:10,color:"#64748b",whiteSpace:"nowrap"},K0={fontSize:10,color:"#cbd5e1",fontFamily:"monospace",whiteSpace:"nowrap"},V0={fontSize:12,color:"#94a3b8",padding:"8px 4px"},U0={fontSize:12,color:"#94a3b8",padding:"8px 0"};function q0(e,t){return t.startsWith("$t:")?e(t.slice(3)):t}function G0({action:e,recipe:t,values:n={},t:o,missingRequired:r=!1,showCodeButton:s=!0,testIdPrefix:a="g7le-action-preview"}){const[l,d]=u.useState(!1),c=t?Gd(t,n,p=>q0(o,p)):typeof e.handler=="string"?e.handler:o("layout_editor.action.advanced_action");return i.jsxs("div",{className:a,"data-testid":a,style:Y0,children:[r?i.jsxs("span",{"data-testid":`${a}-missing`,style:J0,children:["⚠ ",o("layout_editor.action.summary_missing_required")]}):i.jsx("span",{"data-testid":`${a}-summary`,style:X0,children:c}),s?i.jsx("button",{type:"button","data-testid":`${a}-code-toggle`,onClick:()=>d(p=>!p),style:Z0,"aria-expanded":l,"aria-label":o("layout_editor.action.view_code"),children:""}):null,s&&l?i.jsx("pre",{"data-testid":`${a}-code`,style:Q0,children:JSON.stringify(e,null,2)}):null]})}const Y0={display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,minWidth:0},X0={flex:1,minWidth:0,fontSize:12,color:"#475569"},J0={flex:1,minWidth:0,fontSize:12,color:"#b45309"},Z0={border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",fontSize:11,padding:"2px 6px",whiteSpace:"nowrap"},Q0={flexBasis:"100%",margin:"6px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:11,overflow:"auto"},Uc="__g7le_custom__";function Fr({value:e,onChange:t,candidates:n,placeholder:o,testid:r,t:s,bindingCandidates:a}){const l=e==null?"":String(e),d=Array.isArray(n)&&n.length>0,c=d&&n.some(b=>b.value===l),[p,f]=u.useState(!d||l!==""&&!c);return u.useEffect(()=>{l!==""&&d&&!c&&f(!0)},[l,d,c]),d&&!p?i.jsxs("div",{style:Xc,children:[i.jsxs("select",{className:"g7le-widget g7le-widget--picker","data-testid":r,value:c?l:"",onChange:b=>{const g=b.target.value;if(g===Uc){f(!0);return}t(g===""?void 0:g)},style:{...Gc,flex:1,minWidth:0},children:[i.jsx("option",{value:"",children:s("layout_editor.control.default")}),n.map(b=>i.jsx("option",{value:b.value,children:b.label},b.value)),i.jsx("option",{value:Uc,children:s("layout_editor.recipe.custom_input")})]}),i.jsx("button",{type:"button","data-testid":`${r}-to-custom`,title:s("layout_editor.recipe.custom_input"),"aria-label":s("layout_editor.recipe.custom_input"),onClick:()=>f(!0),style:Jc,children:"✎"})]}):i.jsxs("div",{style:Xc,children:[i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:l,onChange:b=>t(b===""?void 0:b),t:s,candidates:a,placeholder:o,testidPrefix:`${r}-input`})}),d&&i.jsx("button",{type:"button","data-testid":`${r}-pick`,title:s("layout_editor.recipe.pick_from_list"),onClick:()=>{f(!1),t(void 0)},style:Jc,children:"≡"})]})}function R0({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Fr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.page_placeholder"),testid:"g7le-widget-page-picker",t:o,bindingCandidates:r})}function qc({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Fr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.datasource_placeholder"),testid:"g7le-widget-datasource-picker",t:o,bindingCandidates:r})}function Ms({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Fr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.state_key_placeholder"),testid:"g7le-widget-state-key-picker",t:o,bindingCandidates:r})}function ek({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Fr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.modal_placeholder"),testid:"g7le-widget-modal-picker",t:o,bindingCandidates:r})}function tk({value:e,onChange:t,t:n,bindingCandidates:o}){const r=typeof e=="string"?e:e==null?"":String(e);return i.jsx("div",{className:"g7le-widget g7le-widget--i18n-text","data-testid":"g7le-widget-i18n-text",style:{flex:1,minWidth:100,width:"100%"},children:i.jsx(_t,{value:r,onChange:s=>t(s===""?void 0:s),t:n,placeholder:n("layout_editor.recipe.i18n_text_placeholder"),testidPrefix:"g7le-widget-i18n-text-field",candidates:o,enableExpressionTree:!0,expressionTreeCollapsible:!0})})}function nk({value:e,onChange:t,candidates:n,t:o}){const r=e==null?"":String(e),s=r.split(",").map(d=>d.trim()).filter(Boolean),a=Array.isArray(n)&&n.length>0,l=d=>{if(!d)return;const c=[...s,d];t(c.join(", "))};return i.jsxs("div",{className:"g7le-widget g7le-widget--binding-list","data-testid":"g7le-widget-binding-list",style:{display:"flex",flexDirection:"column",gap:4,width:"100%"},children:[i.jsx("input",{type:"text","data-testid":"g7le-widget-binding-list-input",value:r,placeholder:o("layout_editor.recipe.datasource_placeholder"),onChange:d=>t(d.target.value===""?void 0:d.target.value),style:Yc}),a?i.jsxs("select",{className:"g7le-widget g7le-widget--picker","data-testid":"g7le-widget-binding-list-add",value:"",onChange:d=>{l(d.target.value),d.target.value=""},style:{...Gc,minWidth:0},children:[i.jsx("option",{value:"",children:o("layout_editor.recipe.pick_from_list")}),n.map(d=>i.jsx("option",{value:d.value,children:d.label},d.value))]}):null]})}function ok({value:e,onChange:t}){const n=e==null?"":String(e);return i.jsx("input",{type:"text",className:"g7le-widget g7le-widget--text","data-testid":"g7le-widget-text",value:n,onChange:o=>t(o.target.value===""?void 0:o.target.value),style:Yc})}const Gc={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",minWidth:140,width:"100%"},Yc={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:100,width:"100%"},Xc={display:"flex",gap:4,alignItems:"flex-start",width:"100%"},Jc={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"};function rk(e){if(e==null)return"null";if(Array.isArray(e))return"list";switch(typeof e){case"number":return"number";case"boolean":return"boolean";case"string":return"string";default:return"object"}}function Zc(e){switch(e){case"string":return"";case"number":return 0;case"boolean":return!1;case"null":return null;case"list":return[];case"object":return{};default:return null}}function Ls(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function ik(e,t,n){return t.includes(n)?"self":e.includes(n)?"inherited":"self"}function sk(e){const t=e.state&&typeof e.state=="object"&&Object.keys(e.state).length>0,n=e.initLocal&&typeof e.initLocal=="object"?e.initLocal:void 0;if(!t)return{initLocal:n??{},migrated:!1};const o={...e.state};if(n)for(const[r,s]of Object.entries(n))o[r]=s;return{initLocal:o,migrated:!0}}const Qc=[{kind:"string",labelKey:"layout_editor.initstate.kind_string"},{kind:"number",labelKey:"layout_editor.initstate.kind_number"},{kind:"boolean",labelKey:"layout_editor.initstate.kind_boolean"},{kind:"null",labelKey:"layout_editor.initstate.kind_null"},{kind:"list",labelKey:"layout_editor.initstate.kind_list"},{kind:"object",labelKey:"layout_editor.initstate.kind_object"}];function Mn({value:e,onChange:t,t:n,path:o,scope:r,depth:s=0,renderStringLeaf:a}){const l=rk(e),d=c=>{t(Zc(c))};return i.jsxs("div",{className:"g7le-initstate-value",style:{paddingLeft:s>0?12:0,minWidth:0},children:[i.jsxs("div",{style:lk,children:[i.jsx("select",{"data-testid":`g7le-initstate-type-${o}`,value:l,onChange:c=>d(c.target.value),style:Rc,children:Qc.map(({kind:c,labelKey:p})=>i.jsx("option",{value:c,children:n(p)},c))}),l==="string"?a?i.jsx("div",{style:{flex:1,minWidth:0},children:a({value:String(e??""),onChange:c=>t(c),testidPrefix:`g7le-initstate-value-${o}`})}):i.jsx("input",{type:"text","data-testid":`g7le-initstate-value-${o}`,value:String(e??""),onChange:c=>t(c.target.value),style:eu}):l==="number"?i.jsx("input",{type:"number","data-testid":`g7le-initstate-value-${o}`,value:typeof e=="number"?e:"",onChange:c=>{const p=parseFloat(c.target.value);t(Number.isNaN(p)?0:p)},style:eu}):l==="boolean"?i.jsx(Or,{checked:!!e,onChange:t,testid:`g7le-initstate-value-${o}`,label:n(e?"layout_editor.overlay.on":"layout_editor.overlay.off")}):l==="null"?i.jsx("span",{"data-testid":`g7le-initstate-value-${o}`,style:dk,children:"null"}):null]}),l==="list"?i.jsxs("div",{style:tu,children:[e.map((c,p)=>i.jsxs("div",{style:ck,children:[i.jsxs("span",{style:uk,children:["[",p,"]"]}),i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(Mn,{value:c,onChange:f=>{const b=e.slice();b[p]=f,t(b)},t:n,path:`${o}.${p}`,scope:r,depth:s+1,renderStringLeaf:a})}),i.jsx("button",{type:"button","data-testid":`g7le-initstate-item-remove-${o}.${p}`,onClick:()=>t(e.filter((f,b)=>b!==p)),style:nu,children:"✕"})]},p)),i.jsxs("button",{type:"button","data-testid":`g7le-initstate-item-add-${o}`,onClick:()=>t([...e,""]),style:ou,children:["+ ",n("layout_editor.initstate.add_item")]})]}):null,l==="object"?i.jsx(ak,{value:e,onChange:t,t:n,path:o,scope:r,depth:s+1,renderStringLeaf:a}):null]})}function ak({value:e,onChange:t,t:n,path:o,scope:r,depth:s,renderStringLeaf:a}){const[l,d]=u.useState(""),[c,p]=u.useState("string"),[f,b]=u.useState(null),g=Object.entries(e),m=()=>{const h=l.trim();if(!h){b(n("layout_editor.initstate.name_required"));return}if(!Ls(h)){b(n("layout_editor.initstate.name_invalid"));return}if(h in e){b(n("layout_editor.initstate.name_duplicate"));return}t({...e,[h]:Zc(c)}),d(""),b(null)};return i.jsxs("div",{style:tu,children:[g.map(([h,v])=>i.jsxs("div",{style:pk,children:[i.jsx("code",{style:fk,children:h}),i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(Mn,{value:v,onChange:y=>t({...e,[h]:y}),t:n,path:`${o}.${h}`,scope:r,depth:s,renderStringLeaf:a})}),i.jsx("button",{type:"button","data-testid":`g7le-initstate-subremove-${o}.${h}`,onClick:()=>{const y={...e};delete y[h],t(y)},style:nu,children:"✕"})]},h)),i.jsxs("div",{style:gk,children:[i.jsx("input",{type:"text","data-testid":`g7le-initstate-subkey-input-${o}`,value:l,placeholder:n("layout_editor.initstate.subkey_name"),onChange:h=>{d(h.target.value),f&&b(null)},onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),m())},"aria-invalid":f?!0:void 0,style:{...hk,...f?yk:null}}),i.jsx("select",{"data-testid":`g7le-initstate-subkey-kind-${o}`,value:c,onChange:h=>p(h.target.value),"aria-label":n("layout_editor.initstate.value_kind"),style:Rc,children:Qc.map(({kind:h,labelKey:v})=>i.jsx("option",{value:h,children:n(v)},h))}),i.jsxs("button",{type:"button","data-testid":`g7le-initstate-subkey-add-${o}`,onClick:m,style:ou,children:["+ ",n("layout_editor.initstate.add_subkey")]})]}),f?i.jsx("p",{"data-testid":`g7le-initstate-subkey-error-${o}`,style:bk,children:f}):null]})}const lk={display:"flex",gap:6,alignItems:"center",minWidth:0},Rc={padding:"4px 6px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,color:"#64748b"},eu={flex:1,minWidth:0,padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},dk={fontSize:12,color:"#94a3b8",fontFamily:"monospace"},tu={display:"flex",flexDirection:"column",gap:6,marginTop:6,paddingLeft:8,borderLeft:"2px solid #e2e8f0"},ck={display:"flex",gap:6,alignItems:"flex-start",minWidth:0},uk={fontSize:11,color:"#94a3b8",minWidth:28,paddingTop:4},pk={display:"flex",gap:6,alignItems:"flex-start",minWidth:0},fk={fontSize:11,color:"#475569",fontFamily:"monospace",minWidth:72,paddingTop:4},nu={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12},ou={alignSelf:"flex-start",padding:"2px 8px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},gk={display:"flex",gap:6,alignItems:"center"},hk={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6},yk={border:"1px solid #dc2626"},bk={margin:"2px 0 0",fontSize:11,color:"#dc2626"},mk=new Set(["text","data-chip","number"]),vk=new Set(["select","toggle","page-picker","datasource-picker","state-key-picker","modal-picker","component-target-picker","tag-input","locale-picker","i18n-text","segmented","slider","color","image"]);function _k(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function xk(e,t){if(e==="page-picker")return t.pageCandidates;if(e==="datasource-picker")return t.dataSourceCandidates;if(e==="state-key-picker")return t.stateKeyCandidates;if(e==="modal-picker")return t.modalCandidates}function wk({param:e,value:t,t:n,pools:o,onChange:r,testIdPrefix:s,renderActionList:a,siblingValues:l}){const d=_k(e.label,n,e.key);if(e.advanced)return i.jsxs("div",{"data-testid":`${s}-locked-${e.key}`,style:zk,children:[i.jsx("span",{style:Nk,children:d}),i.jsxs("span",{style:Mk,children:["[",n("layout_editor.action.advanced"),"] ",n("layout_editor.init_actions.advanced_param_hint")]})]});if(e.widget==="action-list"&&a){const f=Array.isArray(t)?t.filter(b=>!!b&&typeof b=="object"):[];return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:{display:"flex",flexDirection:"column",gap:4},children:[i.jsx("span",{style:io,children:d}),a(f,b=>r(b.length===0?void 0:b),`${s}-${e.key}`,e.key)]})}if(e.widget==="branch-list"&&a){const f=Array.isArray(t)?t.filter(b=>!!b&&typeof b=="object"):[];return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:{display:"flex",flexDirection:"column",gap:4},children:[i.jsx("span",{style:io,children:d}),i.jsx(kk,{branches:f,onChange:b=>r(b.length===0?void 0:b),t:n,pools:o,renderActionList:a,testIdPrefix:`${s}-${e.key}`})]})}if(e.widget==="key-value")return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:{display:"flex",flexDirection:"column",gap:4},children:[i.jsx("span",{style:io,children:d}),i.jsx(Ik,{value:t,onChange:r,t:n,candidates:o.bindingCandidates,testIdPrefix:`${s}-kv-${e.key}`})]});if(e.widget==="state-key-value")return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:{display:"flex",flexDirection:"column",gap:4},children:[i.jsx("span",{style:io,children:d}),i.jsx(Ak,{value:t,onChange:r,t:n,candidates:o.bindingCandidates,stateKeyCandidates:o.stateKeyCandidates,param:e,siblingTarget:l?.target,testIdPrefix:`${s}-skv-${e.key}`})]});if(mk.has(e.widget??"")||!vk.has(e.widget??""))return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:iu,children:[i.jsx("span",{style:io,children:d}),i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:typeof t=="string"?t:t==null?"":String(t),onChange:f=>r(f===""?void 0:f),t:n,candidates:o.bindingCandidates,placeholder:e.widget==="number"?n("layout_editor.action_param.number_placeholder"):void 0,testidPrefix:`${s}-chip-${e.key}`})})]});const p=zn(e.widget);return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:iu,children:[i.jsx("span",{style:io,children:d}),i.jsx("div",{style:{flex:1,minWidth:0},children:p?i.jsx(p,{control:{...e},value:t,onChange:r,t:n,candidates:xk(e.widget,o),bindingCandidates:o.bindingCandidates}):i.jsx(Ke,{value:typeof t=="string"?t:t==null?"":String(t),onChange:f=>r(f===""?void 0:f),t:n,candidates:o.bindingCandidates,testidPrefix:`${s}-chip-${e.key}`})})]})}function kk({branches:e,onChange:t,t:n,pools:o,renderActionList:r,testIdPrefix:s}){const a=b=>Array.isArray(b)?b.filter(g=>!!g&&typeof g=="object"):b&&typeof b=="object"?[b]:[],l=b=>{if(b.length!==0)return b.length===1?b[0]:b},d=(b,g)=>{const m=e.slice();m[b]=g,t(m)},c=b=>{t(e.filter((g,m)=>m!==b))},p=(b,g)=>{if(g<0||g>=e.length)return;const m=e.slice(),[h]=m.splice(b,1);m.splice(g,0,h),t(m)},f=()=>{t([...e,{if:"",then:void 0}])};return i.jsxs("div",{"data-testid":`${s}-branches`,style:{display:"flex",flexDirection:"column",gap:8},children:[e.map((b,g)=>{const m=typeof b.if=="string"?b.if:"",h=a(b.then);return i.jsxs("div",{"data-testid":`${s}-branch-${g}`,style:Sk,children:[i.jsxs("div",{style:Ck,children:[i.jsxs("span",{style:$k,children:[n(m?"layout_editor.action_recipe.conditions.branch_when":"layout_editor.action_recipe.conditions.branch_else")," ",g+1]}),i.jsxs("span",{style:{display:"flex",gap:4},children:[i.jsx("button",{type:"button","data-testid":`${s}-branch-${g}-up`,onClick:()=>p(g,g-1),disabled:g===0,style:Ps,title:n("layout_editor.action_recipe.conditions.move_up"),children:"↑"}),i.jsx("button",{type:"button","data-testid":`${s}-branch-${g}-down`,onClick:()=>p(g,g+1),disabled:g===e.length-1,style:Ps,title:n("layout_editor.action_recipe.conditions.move_down"),children:"↓"}),i.jsx("button",{type:"button","data-testid":`${s}-branch-${g}-remove`,onClick:()=>c(g),style:Ps,title:n("layout_editor.action_recipe.conditions.remove_branch"),children:"✕"})]})]}),i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:3},children:[i.jsx("span",{style:ru,children:n("layout_editor.action_recipe.conditions.param_if")}),i.jsx(Ke,{value:m,onChange:v=>d(g,{...b,if:v}),t:n,candidates:o.bindingCandidates,testidPrefix:`${s}-branch-${g}-if`})]}),i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:3},children:[i.jsx("span",{style:ru,children:n("layout_editor.action_recipe.conditions.param_then")}),r(h,v=>d(g,{...b,then:l(v)}),`${s}-branch-${g}-then`)]})]},g)}),i.jsxs("button",{type:"button","data-testid":`${s}-add-branch`,onClick:f,style:Ek,children:["+ ",n("layout_editor.action_recipe.conditions.add_branch")]})]})}const Sk={border:"1px solid #e2e8f0",borderRadius:6,padding:8,display:"flex",flexDirection:"column",gap:6,background:"#f8fafc"},Ck={display:"flex",justifyContent:"space-between",alignItems:"center"},$k={fontSize:12,fontWeight:700,color:"#475569"},ru={fontSize:11,color:"#64748b"},Ps={border:"1px solid #cbd5e1",background:"#fff",borderRadius:4,width:22,height:22,cursor:"pointer",fontSize:12,lineHeight:"1",color:"#475569"},Ek={border:"1px dashed #94a3b8",background:"#fff",borderRadius:6,padding:"6px 10px",cursor:"pointer",fontSize:12,color:"#475569",alignSelf:"flex-start"};function Ik({value:e,onChange:t,t:n,candidates:o,testIdPrefix:r,renderKeyInput:s}){const a=e&&typeof e=="object"&&!Array.isArray(e)?Object.entries(e).map(([l,d])=>({key:l,value:typeof d=="string"?d:d==null?"":String(d)})):[];return i.jsx(Wr,{value:a,onChange:l=>{const d={};for(const c of l)c.key.trim()!==""&&(d[c.key]=c.value??"");t(Object.keys(d).length===0?void 0:d)},keyField:"key",valueField:"value",t:n,candidates:o,testidPrefix:r,keyPlaceholder:n("layout_editor.action_param.key_placeholder"),valuePlaceholder:n("layout_editor.action_param.value_placeholder"),addLabel:n("layout_editor.action_param.add_pair"),renderKeyInput:s})}function Ak({value:e,onChange:t,t:n,candidates:o,stateKeyCandidates:r,param:s,siblingTarget:a,testIdPrefix:l}){const d=e&&typeof e=="object"&&!Array.isArray(e)?Object.entries(e):[],c=typeof a=="string"?a:"";if((c.startsWith("_local.")||c.startsWith("global.")||c.startsWith("$parent._local.")||c.startsWith("$root._local."))&&d.length===1&&d[0][0]==="value"){const y=d[0][1];return i.jsx("div",{"data-testid":`${l}-path-value`,style:{display:"flex",flexDirection:"column",gap:4},children:i.jsx(Mn,{value:y,onChange:_=>t(_===void 0?void 0:{value:_}),t:n,path:"value",scope:`${l}-path-value-val`,renderStringLeaf:_=>i.jsx(Ke,{value:_.value,onChange:_.onChange,t:n,candidates:o,testidPrefix:_.testidPrefix})})})}const b=(y,_)=>{const w={};for(const[k,x]of d)w[k]=k===y?_:x;t(Object.keys(w).length===0?void 0:w)},g=y=>{const _={};for(const[w,k]of d)w!==y&&(_[w]=k);t(Object.keys(_).length===0?void 0:_)},[m,h]=u.useState(""),v=()=>{const y=m.trim();if(y===""||d.some(([w])=>w===y))return;const _={};for(const[w,k]of d)_[w]=k;_[y]="",t(_),h("")};return i.jsxs("div",{"data-testid":l,style:{display:"flex",flexDirection:"column",gap:6},children:[d.map(([y,_])=>i.jsxs("div",{"data-testid":`${l}-row-${y}`,style:{display:"flex",gap:6,alignItems:"flex-start",border:"1px solid #e2e8f0",borderRadius:8,padding:8},children:[i.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:6},children:[i.jsx("div",{style:{minWidth:0},children:i.jsx(Ms,{control:{...s},value:y,onChange:w=>{const k=w==null?"":String(w);if(k===""||k===y||d.some(([$])=>$===k))return;const x={};for(const[$,C]of d)x[$===y?k:$]=C;t(x)},t:n,candidates:r})}),i.jsx("div",{style:{minWidth:0},children:i.jsx(Mn,{value:_,onChange:w=>b(y,w),t:n,path:y,scope:`${l}-val`,renderStringLeaf:w=>i.jsx(Ke,{value:w.value,onChange:w.onChange,t:n,candidates:o,testidPrefix:w.testidPrefix})})})]}),i.jsx("button",{type:"button","data-testid":`${l}-remove-${y}`,onClick:()=>g(y),title:n("layout_editor.page_settings.seo.remove"),"aria-label":n("layout_editor.page_settings.seo.remove"),style:{flex:"0 0 auto",padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},children:"✕"})]},y)),i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(Ms,{control:{...s},value:m,onChange:y=>h(y==null?"":String(y)),t:n,candidates:r})}),i.jsxs("button",{type:"button","data-testid":`${l}-add`,onClick:v,style:{flex:"0 0 auto",padding:"5px 10px",fontSize:12,border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},children:["+ ",n("layout_editor.action_param.add_pair")]})]})]})}function Os({raw:e,recipe:t,values:n,t:o,pools:r,onChange:s,testIdPrefix:a,renderActionList:l}){const d=(c,p)=>{const f={...n,[c]:p},b=Er(t,f),g=gs(e);s(g?Yd(b,g):b)};return i.jsx(i.Fragment,{children:t.params.filter(c=>Tk(c,n)).map(c=>i.jsx(wk,{param:c,value:n[c.key],t:o,pools:r,onChange:p=>d(c.key,p),testIdPrefix:a,renderActionList:l,siblingValues:n},c.key))})}function Tk(e,t){const n=e.dependsOn;return!n||typeof n!="object"||typeof n.param!="string"?!0:t[n.param]===n.equals}function Dk({raw:e,t,onChange:n,testIdPrefix:o,candidates:r}){const[s,a]=u.useState(!1);return i.jsxs("div",{"data-testid":`${o}-if`,style:Lk,children:[i.jsxs("button",{type:"button",onClick:()=>a(l=>!l),style:Pk,children:["▸ ",t("layout_editor.init_actions.if_label")]}),s?i.jsx("div",{"data-testid":`${o}-if-input`,style:{minWidth:0},children:i.jsx(Ke,{value:gs(e)??"",onChange:l=>n(Yd(e,l)),t,candidates:r,placeholder:t("layout_editor.init_actions.if_placeholder"),testidPrefix:`${o}-if-chip`})}):null]})}const iu={display:"flex",alignItems:"center",gap:8,minWidth:0},io={fontSize:11,color:"#64748b",minWidth:80},zk={display:"flex",alignItems:"center",gap:8,padding:"4px 0"},Nk={fontSize:11,color:"#64748b",minWidth:80},Mk={fontSize:11,color:"#92400e"},Lk={display:"flex",flexDirection:"column",gap:4},Pk={textAlign:"left",border:"none",background:"transparent",color:"#475569",cursor:"pointer",fontSize:11,padding:0};function Ok(e,t,n){if(!t)return n("layout_editor.action.source_core");const o=e?.[t],r=o&&typeof o=="object"&&o.__source?o.__source:null;return!r||r.kind==="core"?n("layout_editor.action.source_core"):r.id??n(`layout_editor.action.source_${r.kind}`)}function Bk(e,t,n){const o=Jn(e,t);if(o.kind==="preset"){const r=t.find(s=>s.id===o.recipeId);return Gd(r??null,o.values,s=>n(s.startsWith("$t:")?s.slice(3):s))}return typeof e.handler=="string"?e.handler:n("layout_editor.action_list.unknown")}function Yt({actions:e,onChange:t,t:n,recipes:o,chipContext:r,actionChipCandidates:s,addContext:a="init",renderAddPicker:l,renderEditor:d,candidatePools:c,showSourceBadge:p=!1,canDrag:f,canDropAt:b,isLocked:g,hideAddPicker:m=!1,testIdPrefix:h="g7le-action-list"}){const v=u.useMemo(()=>$o(o),[o]),y=u.useMemo(()=>{if(r==null||r==="init")return c;const B=Yl(r,n,s??null);if(B.length===0)return c;const M=c??{},O=new Set((M.bindingCandidates??[]).map(H=>H.expression)),z=B.filter(H=>!O.has(H.expression));return z.length===0?c:{...M,bindingCandidates:[...z,...M.bindingCandidates??[]]}},[r,s,c,n]),[_,w]=u.useState(null),[k,x]=u.useState(null),$=u.useCallback((B,M)=>{if(B===M||B<0||M<0||B>=e.length||M>=e.length)return;const O=e.slice(),[z]=O.splice(B,1);O.splice(M,0,z),t(O)},[e,t]),C=_s({length:e.length,onMove:$,canDrag:f,canDropAt:b}),S=u.useCallback(B=>{t(e.filter((M,O)=>O!==B))},[e,t]),D=u.useCallback((B,M)=>{const O=e.slice();O[B]=M,t(O)},[e,t]),E=u.useCallback(B=>{t([...e,B])},[e,t]),I=u.useCallback((B,M)=>{const O=Jn(B,v),z=O.kind==="preset"?v.find(P=>P.id===O.recipeId)??null:null;if(!z)return null;const H=O.kind==="preset"?O.values:{};return i.jsxs("div",{style:Fk,children:[i.jsx(Os,{raw:B,recipe:z,values:H,t:n,pools:y??{},onChange:M,testIdPrefix:`${h}-edit`,renderActionList:(P,A,L,F)=>{const Y=F==="onSuccess"?"response":F==="onError"?"error":void 0;return i.jsx(Yt,{actions:P,onChange:A,t:n,recipes:o,chipContext:Y,actionChipCandidates:Y?s:void 0,candidatePools:Y?c:y,addContext:a,showSourceBadge:p,testIdPrefix:L})}}),i.jsx(Dk,{raw:B,t:n,onChange:M,testIdPrefix:`${h}-edit`,candidates:y?.bindingCandidates})]})},[v,n,y,c,s,h,o,a,p]),N=d??(o?I:void 0),T=m?null:l?l(E):o?i.jsx(L0,{recipes:o,t:n,onAdd:E,context:a,testIdPrefix:`${h}-add-picker`}):null;return i.jsxs("div",{className:h,"data-testid":h,children:[i.jsxs("ul",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:6},children:[e.map((B,M)=>{const O=Jn(B,v),z=O.kind==="preset"?O.recipeId:null,H=z?v.find(Y=>Y.id===z)??null:null,P=H===null,A=g?.(M)??!1,L=gs(B)!==null,F=N?N(B,Y=>D(M,Y)):null;return i.jsxs(u.Fragment,{children:[A?null:i.jsx("li",{"aria-hidden":"true",style:{listStyle:"none",margin:0,padding:0},children:i.jsx(to,{active:C.isDropTarget(M),testid:`${h}-dropline-${M}`})}),i.jsxs("li",{"data-testid":`${h}-item-${M}`,"data-drag-source":C.dragIndex===M?"true":void 0,style:{border:"1px solid #e2e8f0",borderRadius:8,padding:"8px 10px",...C.dragIndex===M?{opacity:.5}:{}},onDragOver:C.dragging&&!A?Y=>{Y.preventDefault();const V=Y.currentTarget.getBoundingClientRect();C.onDragOverItem(M,Y.clientY{Y.preventDefault(),C.onDrop()}:void 0,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[A?i.jsx("span",{style:{fontSize:12},children:"🔒"}):i.jsx("span",{"data-testid":`${h}-drag-${M}`,style:{color:"#94a3b8",cursor:"grab",fontSize:14,userSelect:"none"},draggable:!0,onDragStart:()=>C.onDragStart(M),onDragEnd:C.onDragEnd,"aria-label":n("layout_editor.action_list.drag_reorder"),role:"button",children:"⠿"}),i.jsx("span",{style:{flex:1,minWidth:0,fontSize:13},"data-testid":`${h}-summary-${M}`,children:Bk(B,v,n)}),p?i.jsxs("span",{"data-testid":`${h}-source-${M}`,style:Wk,children:["〔",Ok(o,z,n),"〕"]}):null,L?i.jsxs("span",{"data-testid":`${h}-cond-badge-${M}`,style:jk,children:["〔",n("layout_editor.init_actions.cond_badge"),"〕"]}):null,P?i.jsxs("span",{"data-testid":`${h}-advanced-${M}`,style:Hk,children:["[",n("layout_editor.action.advanced"),"]"]}):null,!A&&F?i.jsxs("button",{type:"button","data-testid":`${h}-edit-${M}`,onClick:()=>x(k===M?null:M),"aria-label":n("layout_editor.init_actions.edit"),title:n("layout_editor.init_actions.edit"),style:k===M?Kk:su,children:["✎ ",n("layout_editor.init_actions.edit")]}):null,i.jsx("button",{type:"button","data-testid":`${h}-code-${M}`,onClick:()=>w(_===M?null:M),"aria-label":n("layout_editor.action_list.view_code"),title:n("layout_editor.action_list.view_code"),style:_===M?Vk:Bs,children:""}),A?null:i.jsx("button",{type:"button","data-testid":`${h}-remove-${M}`,onClick:()=>S(M),"aria-label":n("layout_editor.action_list.remove"),title:n("layout_editor.action_list.remove"),style:Uk,children:"✕"})]}),H?i.jsx(G0,{action:B,recipe:H,values:O.kind==="preset"?O.values:{},t:n,showCodeButton:!1,testIdPrefix:`${h}-preview-${M}`}):null,k===M&&!A&&F?i.jsx("div",{"data-testid":`${h}-edit-body-${M}`,children:F}):null,d&&k!==M?d(B,Y=>D(M,Y)):null,_===M?i.jsx("pre",{"data-testid":`${h}-code-view-${M}`,style:{margin:"8px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:12,overflow:"auto"},children:JSON.stringify(B,null,2)}):null]})]},M)}),i.jsx("li",{"aria-hidden":"true",style:{listStyle:"none",margin:0,padding:0},children:i.jsx(to,{active:C.isDropTarget(e.length),testid:`${h}-dropline-end`})})]}),T?i.jsx("div",{style:{marginTop:8},children:T}):null]})}const Wk={fontSize:10,color:"#64748b",whiteSpace:"nowrap"},jk={fontSize:10,color:"#7c3aed",whiteSpace:"nowrap"},Hk={fontSize:10,color:"#92400e",whiteSpace:"nowrap"},Fk={display:"flex",flexDirection:"column",gap:6,paddingTop:6,borderTop:"1px dashed #e2e8f0",marginTop:6},su={flex:"0 0 auto",padding:"3px 8px",fontSize:11,fontWeight:500,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap",lineHeight:1.4},Kk={...su,background:"#eff6ff",borderColor:"#bfdbfe",color:"#2563eb"},Bs={flex:"0 0 auto",width:26,height:24,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:11,border:"1px solid #e2e8f0",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer",fontFamily:"ui-monospace, monospace"},Vk={...Bs,background:"#0f172a",borderColor:"#0f172a",color:"#e2e8f0"},Uk={...Bs,color:"#dc2626",borderColor:"#fecaca",fontFamily:"inherit"};function au(e){const t=e.__source;return t&&typeof t=="object"?t:null}function qk({actions:e,onChange:t,recipes:n,t:o,bindingCandidates:r,pageCandidates:s,dataSourceCandidates:a,stateKeyCandidates:l,modalCandidates:d}){const c=u.useMemo(()=>({pageCandidates:s,dataSourceCandidates:a,stateKeyCandidates:l,modalCandidates:d,bindingCandidates:r}),[s,a,l,d,r]),p=u.useMemo(()=>e.filter(h=>au(h)?.kind==="base"),[e]),f=u.useMemo(()=>e.filter(h=>au(h)?.kind!=="base"),[e]),b=p.length>0,g=u.useCallback(h=>{t(b?[...p,...h]:h)},[t,b,p]),m=u.useCallback(()=>{},[]);return i.jsxs("div",{className:"g7le-init-actions-form","data-testid":"g7le-init-actions-form",style:Gk,children:[i.jsx("p",{style:Yk,children:o("layout_editor.page_settings.init_actions.heading")}),b?i.jsxs(i.Fragment,{children:[i.jsxs("div",{"data-testid":"g7le-init-action-group-base",style:lu,children:[i.jsx("div",{style:du,children:o("layout_editor.init_actions.group_base")}),i.jsx(Yt,{actions:p,onChange:m,t:o,recipes:n,candidatePools:c,addContext:"init",showSourceBadge:!0,isLocked:()=>!0,hideAddPicker:!0,testIdPrefix:"g7le-init-action-base"}),i.jsxs("p",{"data-testid":"g7le-init-action-base-hint",style:Xk,children:["ⓘ ",o("layout_editor.init_actions.base_readonly_hint")]})]}),i.jsxs("div",{"data-testid":"g7le-init-action-group-self",style:lu,children:[i.jsx("div",{style:du,children:o("layout_editor.init_actions.group_self")}),f.length===0?i.jsx("p",{style:cu,children:o("layout_editor.init_actions.empty_self")}):null,i.jsx(Yt,{actions:f,onChange:g,t:o,recipes:n,candidatePools:c,addContext:"init",showSourceBadge:!0,testIdPrefix:"g7le-init-action-self"})]}),i.jsxs("p",{"data-testid":"g7le-init-action-merge-order",style:Jk,children:["ⓘ ",o("layout_editor.init_actions.merge_order")]})]}):i.jsxs(i.Fragment,{children:[e.length===0?i.jsx("p",{"data-testid":"g7le-init-action-empty",style:cu,children:o("layout_editor.init_actions.empty")}):null,i.jsx(Yt,{actions:e,onChange:t,t:o,recipes:n,candidatePools:c,addContext:"init",showSourceBadge:!0,testIdPrefix:"g7le-init-action"})]})]})}const Gk={display:"flex",flexDirection:"column",gap:12,minWidth:0},Yk={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},lu={border:"1px solid #e2e8f0",borderRadius:10,padding:10,display:"flex",flexDirection:"column",gap:8},du={fontSize:12,fontWeight:700,color:"#475569"},Xk={margin:0,fontSize:11,color:"#64748b"},cu={margin:0,fontSize:12,color:"#94a3b8"},Jk={margin:0,fontSize:11,color:"#64748b"};function Zk(e){return e==="spinner"?new Set(["spinner","page"]):new Set(["skeleton"])}function uu(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function pu({candidates:e,value:t,onSelect:n,styleKind:o,t:r,testIdPrefix:s="g7le-loading-component-picker"}){const a=vo(),l=()=>{const d=a.open({ariaLabel:r("layout_editor.overlay.loading_picker.select"),width:520,maxHeightRatio:.7,content:i.jsx(Qk,{candidates:e,value:t,styleKind:o,t:r,testIdPrefix:s,onPick:c=>{n(c),a.close(d)},onClose:()=>a.close(d)})})};return i.jsx("div",{className:s,"data-testid":s,style:{minWidth:0},children:i.jsxs("div",{style:Rk,children:[i.jsx("span",{"data-testid":`${s}-current`,style:e1,children:t&&t.length>0?t:r("layout_editor.overlay.loading_picker.none")}),i.jsxs("button",{type:"button","data-testid":`${s}-open`,onClick:l,style:t1,children:["🔍 ",r("layout_editor.overlay.loading_picker.select")]})]})})}function Qk({candidates:e,value:t,styleKind:n,t:o,testIdPrefix:r,onPick:s,onClose:a}){const[l,d]=u.useState(""),c=Zk(n),p=u.useMemo(()=>{const f=l.trim().toLowerCase();return e.filter(b=>c.has(b.role)).filter(b=>f?uu(b.label,o,b.name).toLowerCase().includes(f)||b.name.toLowerCase().includes(f):!0)},[e,n,l,o]);return i.jsxs("div",{"data-testid":`${r}-modal`,style:n1,children:[i.jsxs("div",{style:o1,children:[i.jsxs("span",{style:r1,children:["🔍 ",o("layout_editor.overlay.loading_picker.select")]}),i.jsx("button",{type:"button","data-testid":`${r}-close`,onClick:a,"aria-label":o("layout_editor.overlay.loading_picker.select"),style:i1,children:"✕"})]}),i.jsx("input",{type:"text","data-testid":`${r}-search`,value:l,placeholder:o("layout_editor.overlay.loading_picker.search"),onChange:f=>d(f.target.value),style:s1,autoFocus:!0}),p.length===0?i.jsx("p",{"data-testid":`${r}-empty`,style:f1,children:o("layout_editor.overlay.loading_picker.empty")}):i.jsx("ul",{style:a1,children:p.map(f=>i.jsx("li",{children:i.jsxs("button",{type:"button","data-testid":`${r}-item-${f.name}`,onClick:()=>s(f.name),style:{...l1,...t===f.name?d1:{}},children:[i.jsx("span",{style:c1,children:uu(f.label,o,f.name)}),i.jsx("code",{style:u1,children:f.name}),i.jsx("span",{style:p1,children:f.role})]})},f.name))})]})}const Rk={display:"flex",alignItems:"center",gap:6,minWidth:0},e1={flex:1,minWidth:0,fontSize:12,color:"#0f172a",fontFamily:"monospace"},t1={padding:"4px 10px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},n1={display:"flex",flexDirection:"column",minHeight:0,padding:16,boxSizing:"border-box",fontFamily:"system-ui, -apple-system, sans-serif"},o1={display:"flex",alignItems:"center",gap:8,paddingBottom:8,borderBottom:"1px solid #e2e8f0",marginBottom:10},r1={flex:1,fontSize:14,fontWeight:700,color:"#0f172a",minWidth:0},i1={border:"none",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:15,lineHeight:1,padding:4},s1={width:"100%",padding:"6px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,marginBottom:8,boxSizing:"border-box"},a1={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:2,overflowY:"auto",minHeight:0},l1={display:"flex",alignItems:"center",gap:6,width:"100%",textAlign:"left",padding:"8px 10px",fontSize:12,border:"1px solid transparent",background:"transparent",cursor:"pointer",borderRadius:6},d1={border:"1px solid #3b82f6",background:"#eff6ff"},c1={flex:1,minWidth:0,color:"#0f172a"},u1={fontSize:10,color:"#94a3b8",fontFamily:"monospace"},p1={fontSize:10,color:"#64748b",background:"#f1f5f9",borderRadius:4,padding:"0 4px"},f1={margin:0,fontSize:12,color:"#94a3b8",padding:"8px 4px"};function fu(e){return e===!0?{enabled:!0}:e===!1||e===void 0?{}:e}const g1=["opaque","blur","fade","skeleton","spinner"];function h1({value:e,patch:t,t:n,baseValue:o,ownValue:r,loadingComponents:s=[],progressiveDataSources:a=[],bindingCandidates:l}){const d=fu(e),c=d.enabled??!1,p=!!o&&Object.keys(o).length>0,f=zn("component-target-picker"),[b,g]=u.useState((d.wait_for??[]).length>0),m=u.useCallback(k=>{const x={...fu(e)};k(x),t(x)},[e,t]),h=r&&typeof r=="object"?r:e&&typeof e=="object"?e:{},v=u.useCallback(k=>p&&o!==void 0&&k in o&&!(k in h),[p,o,h]),y=u.useCallback(k=>{o&&m(x=>{x[k]=o[k]})},[o,m]),_=u.useCallback(k=>m(x=>{x.enabled=k}),[m]),w=d.target!==void 0?"region":"full";return i.jsxs("div",{className:"g7le-overlay-form","data-testid":"g7le-overlay-form",style:y1,children:[p?i.jsxs("p",{"data-testid":"g7le-overlay-inherit-banner",style:b1,children:["ⓘ ",n("layout_editor.overlay.inherit_banner")]}):null,i.jsxs("div",{style:Vr,children:[i.jsx(Ws,{label:n("layout_editor.overlay.enabled_label"),inherited:v("enabled"),hasInheritance:p,onOverride:()=>y("enabled"),testidKey:"enabled",t:n}),i.jsx(Br,{disabled:v("enabled"),children:i.jsx(Or,{checked:c,onChange:_,testid:"g7le-overlay-enabled",ariaLabel:n("layout_editor.overlay.enabled_label"),label:n(c?"layout_editor.overlay.on":"layout_editor.overlay.off")})}),i.jsxs("p",{style:Ur,children:["ⓘ ",n("layout_editor.overlay.enabled_hint")]})]}),i.jsx(Br,{disabled:!c,testid:"g7le-overlay-body",style:{display:"flex",flexDirection:"column",gap:16,minWidth:0},children:i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:Vr,children:[i.jsx(Ws,{label:n("layout_editor.overlay.scope_label"),inherited:v("target"),hasInheritance:p,onOverride:()=>y("target"),testidKey:"target",t:n}),i.jsxs("div",{"data-testid":"g7le-overlay-scope",style:js,children:[i.jsx(Kr,{active:w==="full",onClick:()=>m(k=>{delete k.target,delete k.fallback_target}),testid:"g7le-overlay-scope-full",children:n("layout_editor.overlay.scope_full")}),i.jsx(Kr,{active:w==="region",onClick:()=>m(k=>{k.target=k.target??""}),testid:"g7le-overlay-scope-region",children:n("layout_editor.overlay.scope_region")})]}),i.jsx(Br,{disabled:w!=="region",testid:"g7le-overlay-region-box",style:x1,children:i.jsxs(i.Fragment,{children:[i.jsx(Ln,{label:n("layout_editor.overlay.target_label"),children:i.jsx("div",{"data-testid":"g7le-overlay-target-picker",children:f?i.jsx(f,{control:{label:n("layout_editor.overlay.target_label")},value:d.target??"",onChange:k=>m(x=>{x.target=typeof k=="string"?k:""}),t:n}):i.jsx("input",{type:"text","data-testid":"g7le-overlay-target-input",value:d.target??"",onChange:k=>m(x=>{x.target=k.target.value}),style:S1})})}),i.jsx(Ln,{label:n("layout_editor.overlay.fallback_label"),children:i.jsx("div",{"data-testid":"g7le-overlay-fallback-picker",children:f?i.jsx(f,{control:{label:n("layout_editor.overlay.fallback_label")},value:d.fallback_target??"",onChange:k=>m(x=>{const $=typeof k=="string"?k:"";$===""?delete x.fallback_target:x.fallback_target=$}),t:n}):null})}),i.jsxs("p",{style:Ur,children:["ⓘ ",n("layout_editor.overlay.fallback_hint")]})]})})]}),i.jsxs("div",{style:Vr,children:[i.jsx(Ws,{label:n("layout_editor.overlay.style_label"),inherited:v("style"),hasInheritance:p,onOverride:()=>y("style"),testidKey:"style",t:n}),i.jsx("div",{"data-testid":"g7le-overlay-style",style:js,children:g1.map(k=>i.jsx(Kr,{active:(d.style??"opaque")===k,onClick:()=>m(x=>{x.style=k}),testid:`g7le-overlay-style-${k}`,children:n(`layout_editor.overlay.style_${k}`)},k))}),d.style==="skeleton"?i.jsxs("div",{style:gu,children:[i.jsx(Ln,{label:n("layout_editor.overlay.skeleton_component"),children:i.jsx(pu,{candidates:s,value:d.skeleton?.component,styleKind:"skeleton",onSelect:k=>m(x=>{x.skeleton={...x.skeleton,component:k}}),t:n,testIdPrefix:"g7le-overlay-skeleton-component"})}),i.jsx(Ln,{label:n("layout_editor.overlay.skeleton_animation"),children:i.jsx("div",{"data-testid":"g7le-overlay-skeleton-anim",style:js,children:["wave","pulse","none"].map(k=>i.jsx(Kr,{active:(d.skeleton?.animation??"wave")===k,onClick:()=>m(x=>{x.skeleton={...x.skeleton,animation:k}}),testid:`g7le-overlay-skeleton-anim-${k}`,children:n(`layout_editor.overlay.anim_${k}`)},k))})}),i.jsx(Ln,{label:n("layout_editor.overlay.skeleton_count"),children:i.jsx("input",{type:"number","data-testid":"g7le-overlay-skeleton-count",value:d.skeleton?.iteration_count??"",onChange:k=>m(x=>{const $=parseInt(k.target.value,10);x.skeleton={...x.skeleton,iteration_count:Number.isNaN($)?void 0:$}}),style:C1})})]}):null,d.style==="spinner"?i.jsxs("div",{style:gu,children:[i.jsx(Ln,{label:n("layout_editor.overlay.spinner_component"),children:i.jsx(pu,{candidates:s,value:d.spinner?.component,styleKind:"spinner",onSelect:k=>m(x=>{x.spinner={...x.spinner,component:k}}),t:n,testIdPrefix:"g7le-overlay-spinner-component"})}),i.jsx(Ln,{label:n("layout_editor.overlay.spinner_text"),children:i.jsx("div",{"data-testid":"g7le-overlay-spinner-text",style:{minWidth:0},children:i.jsx(_t,{value:d.spinner?.text??"",onChange:k=>m(x=>{x.spinner={...x.spinner,text:k===void 0||k===""?void 0:k}}),t:n,candidates:l,enableExpressionTree:!0,expressionTreeCollapsible:!0,testidPrefix:"g7le-overlay-spinner-text-field"})})})]}):null]}),i.jsxs("div",{style:Vr,children:[i.jsxs("button",{type:"button","data-testid":"g7le-overlay-waitfor-toggle","aria-expanded":b,onClick:()=>g(k=>!k),style:I1,children:[b?"▾":"▸"," ",n("layout_editor.overlay.waitfor_label")]}),b?i.jsxs("div",{"data-testid":"g7le-overlay-waitfor-body",style:A1,children:[i.jsxs("p",{"data-testid":"g7le-overlay-waitfor-hint",style:Ur,children:["ⓘ ",n("layout_editor.overlay.waitfor_hint")]}),a.length===0?i.jsx("p",{"data-testid":"g7le-overlay-waitfor-empty",style:Ur,children:n("layout_editor.overlay.waitfor_empty")}):i.jsx("div",{"data-testid":"g7le-overlay-waitfor",style:{display:"flex",flexWrap:"wrap",gap:6},children:a.map(k=>{const x=(d.wait_for??[]).includes(k.id);return i.jsxs("label",{"data-testid":`g7le-overlay-waitfor-${k.id}`,style:$1(x),children:[i.jsx("input",{type:"checkbox",checked:x,onChange:()=>m($=>{const C=new Set($.wait_for??[]);C.has(k.id)?C.delete(k.id):C.add(k.id);const S=Array.from(C);S.length===0?delete $.wait_for:$.wait_for=S})}),i.jsx(Wc,{option:k,testIdPrefix:`g7le-overlay-waitfor-${k.id}`})]},k.id)})})]}):null]}),p?i.jsxs("button",{type:"button","data-testid":"g7le-overlay-reset-inherit",onClick:()=>t(void 0),style:E1,children:["⟲ ",n("layout_editor.overlay.reset_inherit")]}):null]})})]})}function Kr({active:e,onClick:t,children:n,testid:o}){return i.jsx("button",{type:"button","data-testid":o,"aria-pressed":e,onClick:t,style:{...v1,...e?_1:{}},children:n})}function Ws({label:e,inherited:t,hasInheritance:n,onOverride:o,testidKey:r,t:s}){return i.jsxs("div",{style:T1,children:[i.jsx("label",{style:m1,children:e}),n?t?i.jsxs(i.Fragment,{children:[i.jsxs("span",{"data-testid":`g7le-overlay-inherited-${r}`,style:D1,children:["〔",s("layout_editor.overlay.inherited_badge"),"〕"]}),i.jsx("button",{type:"button","data-testid":`g7le-overlay-override-${r}`,onClick:o,style:N1,children:s("layout_editor.overlay.override_field")})]}):i.jsxs("span",{"data-testid":`g7le-overlay-overridden-${r}`,style:z1,children:["〔",s("layout_editor.overlay.overridden_badge"),"〕"]}):null]})}function Ln({label:e,children:t}){return i.jsxs("div",{style:w1,children:[i.jsx("span",{style:k1,children:e}),i.jsx("div",{style:{flex:1,minWidth:0},children:t})]})}const y1={display:"flex",flexDirection:"column",gap:16,minWidth:0},b1={margin:0,fontSize:12,color:"#1d4ed8",background:"#eff6ff",padding:"8px 10px",borderRadius:6},Vr={display:"flex",flexDirection:"column",gap:6,minWidth:0},m1={fontSize:13,fontWeight:600,color:"#0f172a"},Ur={margin:0,fontSize:11,color:"#94a3b8"},js={display:"flex",gap:4,flexWrap:"wrap"},v1={padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},_1={border:"1px solid #3b82f6",background:"#eff6ff",color:"#1d4ed8"},x1={display:"flex",flexDirection:"column",gap:8,padding:8,border:"1px dashed #e2e8f0",borderRadius:8},gu={display:"flex",flexDirection:"column",gap:8,padding:8,border:"1px dashed #e2e8f0",borderRadius:8},w1={display:"flex",alignItems:"center",gap:8,minWidth:0},k1={fontSize:11,color:"#64748b",minWidth:90},S1={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},C1={width:80,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},$1=e=>({display:"inline-flex",alignItems:"center",gap:4,padding:"4px 8px",fontSize:12,border:`1px solid ${e?"#3b82f6":"#cbd5e1"}`,borderRadius:12,background:e?"#eff6ff":"#fff",cursor:"pointer"}),E1={alignSelf:"flex-start",padding:"6px 12px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},I1={alignSelf:"flex-start",padding:"4px 0",fontSize:13,fontWeight:600,color:"#0f172a",background:"transparent",border:"none",cursor:"pointer"},A1={display:"flex",flexDirection:"column",gap:6,paddingLeft:14,minWidth:0},T1={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",minWidth:0},D1={fontSize:11,color:"#64748b",background:"#f1f5f9",borderRadius:4,padding:"1px 6px"},z1={fontSize:11,color:"#0369a1",background:"#e0f2fe",borderRadius:4,padding:"1px 6px"},N1={padding:"2px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},M1="g7le:computed-effect-preview",L1={number:"layout_editor.computed.type_number",string:"layout_editor.computed.type_string",boolean:"layout_editor.computed.type_boolean",list:"layout_editor.computed.type_list",object:"layout_editor.computed.type_object",null:"layout_editor.computed.type_null"};function P1(e,t,n){if(t==="list"){const o=e,r=o.slice(0,2).map(s=>JSON.stringify(s)).join(", ");return o.length<=2?`[${r}]`:`[${r}, ${n("layout_editor.computed.list_more",{count:o.length})}]`}return t==="object"?JSON.stringify(e):t==="boolean"?e?"true":"false":t==="null"?n("layout_editor.computed.value_none"):String(e)}function hu({expr:e,computedKey:t,sampleContext:n,t:o,isEffect:r=!1,testIdPrefix:s="g7le-computed-preview"}){const a=Pd(e,n),l=()=>{typeof window>"u"||!t||window.dispatchEvent(new CustomEvent(M1,{detail:{key:t}}))};return a.ok?i.jsxs("div",{className:s,"data-testid":s,style:O1,children:[i.jsx("span",{style:B1,children:o("layout_editor.computed.preview_label")}),i.jsx("span",{"data-testid":`${s}-value`,style:W1,children:P1(a.value,a.type,o)}),i.jsxs("span",{"data-testid":`${s}-type`,style:j1,children:["(",o(L1[a.type]),")"]}),r&&a.type==="boolean"?i.jsxs("button",{type:"button","data-testid":`${s}-effect`,onClick:l,style:H1,children:["▷ ",o("layout_editor.computed.effect_preview")]}):null]}):i.jsxs("div",{"data-testid":`${s}-error`,style:F1,children:["⚠ ",o("layout_editor.computed.preview_error")]})}const O1={display:"flex",alignItems:"center",flexWrap:"wrap",gap:6,minWidth:0},B1={fontSize:11,color:"#94a3b8"},W1={fontSize:12,color:"#0f172a",fontFamily:"monospace",wordBreak:"break-all"},j1={fontSize:10,color:"#64748b"},H1={padding:"2px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},F1={fontSize:12,color:"#b45309"},K1=[{op:"count",labelKey:"layout_editor.computed.op_count"},{op:"sum",labelKey:"layout_editor.computed.op_sum"},{op:"filter",labelKey:"layout_editor.computed.op_filter"},{op:"toOptions",labelKey:"layout_editor.computed.op_to_options"},{op:"nth",labelKey:"layout_editor.computed.op_nth"},{op:"firstOf",labelKey:"layout_editor.computed.op_first_of"},{op:"literal",labelKey:"layout_editor.computed.op_literal"}],V1=["=","!=",">","<",">=","<=","includes"],U1=new Set(["count","sum","filter"]);function yu({model:e,onChange:t,t:n,dataSourceCandidates:o,bindingCandidates:r,existingKeys:s=[]}){const a=u.useCallback(g=>{const m={...e};g(m),t(m)},[e,t]),l=e.conditions??[],d=zn("datasource-picker"),c=e.key!==""&&s.includes(e.key),p=()=>a(g=>{g.conditions=[...g.conditions??[],{field:"",cmp:"=",value:""}]}),f=(g,m)=>a(h=>{const v=(h.conditions??[]).slice(),y={...v[g]};m(y),v[g]=y,h.conditions=v}),b=g=>a(m=>{m.conditions=(m.conditions??[]).filter((h,v)=>v!==g)});return i.jsxs("div",{className:"g7le-computed-custom","data-testid":"g7le-computed-custom",style:q1,children:[i.jsx(Hs,{label:`① ${n("layout_editor.computed.custom_step1")}`,children:i.jsx("div",{"data-testid":"g7le-computed-custom-source",children:d?i.jsx(d,{control:{},value:e.source,onChange:g=>a(m=>{m.source=typeof g=="string"?g:void 0}),t:n,candidates:o}):i.jsx("input",{type:"text",value:e.source??"",onChange:g=>a(m=>{m.source=g.target.value}),style:so})})}),i.jsxs(Hs,{label:`② ${n("layout_editor.computed.custom_step2")}`,children:[i.jsx("select",{"data-testid":"g7le-computed-custom-op",value:e.op,onChange:g=>a(m=>{m.op=g.target.value}),style:so,children:K1.map(({op:g,labelKey:m})=>i.jsx("option",{value:g,children:n(m)},g))}),e.op==="sum"?i.jsx("div",{"data-testid":"g7le-computed-custom-sumfield",style:{minWidth:0},children:i.jsx(Ke,{value:e.sumField??"",onChange:g=>a(m=>{m.sumField=g}),t:n,candidates:r,placeholder:n("layout_editor.computed.custom_sum_field"),testidPrefix:"g7le-computed-custom-sumfield-chip"})}):null,e.op==="toOptions"?i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("div",{"data-testid":"g7le-computed-custom-valuefield",style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:e.valueField??"",onChange:g=>a(m=>{m.valueField=g}),t:n,candidates:r,placeholder:n("layout_editor.computed.custom_value_field"),testidPrefix:"g7le-computed-custom-valuefield-chip"})}),i.jsx("div",{"data-testid":"g7le-computed-custom-labelfield",style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:e.labelField??"",onChange:g=>a(m=>{m.labelField=g}),t:n,candidates:r,placeholder:n("layout_editor.computed.custom_label_field"),testidPrefix:"g7le-computed-custom-labelfield-chip"})})]}):null,e.op==="nth"?i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("input",{type:"text","data-testid":"g7le-computed-custom-index",value:e.index??"",placeholder:"0",onChange:g=>a(m=>{m.index=g.target.value}),style:so}),i.jsx("div",{"data-testid":"g7le-computed-custom-prop",style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:e.prop??"",onChange:g=>a(m=>{m.prop=g}),t:n,candidates:r,placeholder:n("layout_editor.computed.custom_prop"),testidPrefix:"g7le-computed-custom-prop-chip"})})]}):null,e.op==="literal"?i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsxs("select",{"data-testid":"g7le-computed-custom-literalkind",value:e.literalKind??"string",onChange:g=>a(m=>{m.literalKind=g.target.value}),style:so,children:[i.jsx("option",{value:"string",children:n("layout_editor.computed.kind_string")}),i.jsx("option",{value:"number",children:n("layout_editor.computed.kind_number")}),i.jsx("option",{value:"boolean",children:n("layout_editor.computed.kind_boolean")})]}),i.jsx("div",{"data-testid":"g7le-computed-custom-literalvalue",style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:e.literalValue??"",onChange:g=>a(m=>{m.literalValue=g}),t:n,candidates:r,testidPrefix:"g7le-computed-custom-literalvalue-chip"})})]}):null,e.op==="firstOf"?i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[i.jsx("input",{type:"text","data-testid":"g7le-computed-custom-candidates",value:(e.candidates??[]).join(", "),placeholder:n("layout_editor.computed.custom_candidates"),onChange:g=>a(m=>{m.candidates=g.target.value.split(",").map(h=>h.trim()).filter(Boolean)}),style:so}),i.jsx("div",{"data-testid":"g7le-computed-custom-fallback",style:{minWidth:0},children:i.jsx(Ke,{value:e.fallback??"",onChange:g=>a(m=>{m.fallback=g}),t:n,candidates:r,placeholder:n("layout_editor.computed.custom_fallback"),testidPrefix:"g7le-computed-custom-fallback-chip"})})]}):null,U1.has(e.op)?i.jsxs("div",{style:J1,children:[l.map((g,m)=>i.jsxs("div",{"data-testid":`g7le-computed-custom-cond-${m}`,style:Z1,children:[i.jsx("div",{"data-testid":`g7le-computed-custom-cond-field-${m}`,style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:g.field,onChange:h=>f(m,v=>{v.field=h}),t:n,candidates:r,placeholder:n("layout_editor.computed.cond_field"),testidPrefix:`g7le-computed-custom-cond-field-${m}-chip`})}),i.jsx("select",{value:g.cmp,onChange:h=>f(m,v=>{v.cmp=h.target.value}),style:Q1,children:V1.map(h=>i.jsx("option",{value:h,children:h},h))}),i.jsx("div",{"data-testid":`g7le-computed-custom-cond-value-${m}`,style:{flex:1,minWidth:0},children:i.jsx(Ke,{value:g.value,onChange:h=>f(m,v=>{v.value=h}),t:n,candidates:r,placeholder:n("layout_editor.computed.cond_value"),testidPrefix:`g7le-computed-custom-cond-value-${m}-chip`})}),i.jsx("button",{type:"button","data-testid":`g7le-computed-custom-cond-remove-${m}`,onClick:()=>b(m),style:R1,children:"✕"})]},m)),i.jsxs("button",{type:"button","data-testid":"g7le-computed-custom-cond-add",onClick:p,style:eS,children:["+ ",n("layout_editor.computed.cond_add")]})]}):null]}),i.jsxs(Hs,{label:`③ ${n("layout_editor.computed.custom_step3")}`,children:[i.jsx("input",{type:"text","data-testid":"g7le-computed-custom-key",value:e.key,onChange:g=>a(m=>{m.key=g.target.value}),style:{...so,...c?X1:{}}}),c?i.jsxs("p",{"data-testid":"g7le-computed-custom-key-dup",style:tS,children:["⚠ ",n("layout_editor.computed.key_duplicate")]}):null]})]})}function Hs({label:e,children:t}){return i.jsxs("div",{style:G1,children:[i.jsx("div",{style:Y1,children:e}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:t})]})}function Fs(e){return gv(e)}const q1={display:"flex",flexDirection:"column",gap:12,padding:10,border:"1px solid #cbd5e1",borderRadius:8,background:"#fff"},G1={display:"flex",flexDirection:"column",gap:4,minWidth:0},Y1={fontSize:12,fontWeight:600,color:"#475569"},so={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%",boxSizing:"border-box"},X1={border:"1px solid #ef4444"},J1={display:"flex",flexDirection:"column",gap:6,marginTop:4},Z1={display:"flex",gap:4,alignItems:"center",minWidth:0},Q1={padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},R1={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12},eS={alignSelf:"flex-start",padding:"2px 8px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},tS={margin:0,fontSize:11,color:"#b45309"};function Ks(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function nS(e){if(e&&typeof e=="object"){const t=e.__source;if(t&&typeof t=="object")return t}return null}function oS({computed:e,onChange:t,recipes:n,t:o,sampleContext:r,dataSourceCandidates:s,bindingCandidates:a,computedSource:l={},effectKeys:d=[],onRevert:c}){const p=u.useMemo(()=>Ad(n),[n]),[f,b]=u.useState(!1),[g,m]=u.useState(null),h=Object.keys(e),v=u.useCallback((x,$)=>{t({...e,[x]:$})},[e,t]),y=u.useCallback(x=>{const $={...e};delete $[x],t($)},[e,t]),_=u.useCallback((x,$,C)=>{const S={...e};x&&x!==$&&delete S[x],S[$]=C,t(S)},[e,t]),w=u.useCallback(x=>{const $=Dd(x,{});let C=x.id,S=1;for(;C in e;)C=`${x.id}${++S}`;t({...e,[C]:$}),b(!1)},[e,t]),k=u.useCallback(()=>{!g||!g.key||(t({...e,[g.key]:Fs(g)}),m(null),b(!1))},[g,e,t]);return i.jsxs("div",{className:"g7le-computed-form","data-testid":"g7le-computed-form",style:aS,children:[i.jsx("p",{style:lS,children:o("layout_editor.page_settings.computed.heading")}),h.length>0?h.map(x=>i.jsx(rS,{computedKey:x,expr:e[x],recipes:p,rawRecipes:n,t:o,sampleContext:r,dataSourceCandidates:s,bindingCandidates:a,source:l[x],isEffect:d.includes(x),existingKeys:h,onPatchExpr:$=>v(x,$),onRename:($,C)=>_(x,$,C),onRemove:()=>y(x),onRevert:c?()=>c(x):void 0},x)):i.jsx("p",{"data-testid":"g7le-computed-empty",style:DS,children:o("layout_editor.computed.empty")}),i.jsxs("div",{style:{minWidth:0},children:[i.jsxs("button",{type:"button","data-testid":"g7le-computed-add",onClick:()=>b(x=>!x),style:kS,children:["+ ",o("layout_editor.computed.add")," ▾"]}),f?i.jsxs("div",{"data-testid":"g7le-computed-add-list",style:SS,children:[["common","more"].map(x=>{const $=p.filter(C=>(C.group??"more")===x);return $.length===0?null:i.jsxs("div",{children:[i.jsxs("div",{style:CS,children:["━━ ",o(`layout_editor.computed.group_${x}`)," ━━"]}),$.map(C=>{const S=nS(n?.[C.id]);return i.jsxs("button",{type:"button","data-testid":`g7le-computed-preset-${C.id}`,onClick:()=>w(C),style:$S,children:[i.jsx("span",{style:ES,children:Ks(C.label,o,C.id)}),S&&S.kind!=="core"?i.jsxs("span",{"data-testid":`g7le-computed-preset-source-${C.id}`,style:IS,children:["〔",S.id??S.kind,"〕"]}):null]},C.id)})]},x)}),i.jsxs("div",{style:{borderTop:"1px solid #e2e8f0",marginTop:6,paddingTop:6},children:[i.jsxs("button",{type:"button","data-testid":"g7le-computed-custom-open",onClick:()=>m(g?null:{key:"",op:"count",source:"",conditions:[]}),style:AS,children:["⚙ ",o("layout_editor.computed.custom_open")," ▾"]}),g?i.jsxs("div",{style:{marginTop:6},children:[i.jsx(yu,{model:g,onChange:m,t:o,dataSourceCandidates:s,bindingCandidates:a,existingKeys:h}),i.jsx("div",{"data-testid":"g7le-computed-custom-preview",style:{marginTop:6},children:i.jsx(hu,{expr:Fs(g),sampleContext:r,t:o,testIdPrefix:"g7le-computed-custom-preview-eval"})}),i.jsx("button",{type:"button","data-testid":"g7le-computed-custom-commit",disabled:!g.key||h.includes(g.key),onClick:k,style:TS,children:o("layout_editor.computed.custom_add")})]}):null]})]}):null]})]})}function rS({computedKey:e,expr:t,recipes:n,rawRecipes:o,t:r,sampleContext:s,dataSourceCandidates:a,bindingCandidates:l,source:d,isEffect:c,existingKeys:p,onPatchExpr:f,onRename:b,onRemove:g,onRevert:m}){const[h,v]=u.useState(!1),[y,_]=u.useState(!1),w=u.useMemo(()=>Ld(t,n),[t,n]),k=d==="base",x=d==="route-override",$=w.kind==="advanced",C=w.kind==="preset"?n.find(E=>E.id===w.recipeId)??null:null,S=C?Ks(C.label,r,e):e,D=(E,I)=>{if(w.kind!=="preset"||!C)return;const N={...w.params,[E]:I};f(Dd(C,N))};return i.jsxs("div",{"data-testid":`g7le-computed-item-${e}`,style:dS,children:[i.jsxs("div",{style:cS,children:[i.jsx("span",{style:uS,children:S}),i.jsx("code",{style:pS,children:e}),k?i.jsxs("span",{"data-testid":`g7le-computed-source-${e}`,style:fS,children:["〔",r("layout_editor.computed.source_base"),"〕"]}):null,x?i.jsxs("span",{"data-testid":`g7le-computed-overridden-${e}`,style:gS,children:["〔",r("layout_editor.computed.source_overridden"),"〕"]}):null,$?i.jsxs("span",{"data-testid":"g7le-computed-advanced",style:hS,children:["[",r("layout_editor.action.advanced"),"]"]}):null,i.jsx("span",{style:{flex:1}}),i.jsx("button",{type:"button","data-testid":`g7le-computed-code-${e}`,onClick:()=>_(E=>!E),style:Vs,"aria-label":r("layout_editor.value_tree.show_source"),title:r("layout_editor.value_tree.show_source"),children:""}),$?null:i.jsx("button",{type:"button","data-testid":`g7le-computed-edit-${e}`,onClick:()=>v(E=>!E),style:Vs,children:r("layout_editor.init_actions.edit")}),i.jsx("button",{type:"button","data-testid":`g7le-computed-remove-${e}`,onClick:g,style:Vs,"aria-label":r("layout_editor.init_actions.remove"),children:"✕"})]}),y?i.jsx("pre",{"data-testid":`g7le-computed-code-block-${e}`,style:zS,children:t}):null,i.jsx("div",{"data-testid":`g7le-computed-preview-${e}`,children:i.jsx(hu,{expr:t,computedKey:e,sampleContext:s,t:r,isEffect:c,testIdPrefix:`g7le-computed-preview-${e}-eval`})}),x&&m?i.jsxs("div",{style:yS,children:[i.jsxs("span",{style:bS,children:["ⓘ ",r("layout_editor.computed.overridden_hint")]}),i.jsx("button",{type:"button","data-testid":`g7le-computed-revert-${e}`,onClick:m,style:mS,children:r("layout_editor.computed.revert")})]}):null,h&&!$?i.jsxs("div",{style:vS,children:[k?i.jsxs("p",{"data-testid":`g7le-computed-override-notice-${e}`,style:_S,children:["⚠ ",r("layout_editor.computed.override_notice")]}):null,w.kind==="preset"&&C?i.jsx(i.Fragment,{children:C.params.map(E=>i.jsx(sS,{param:E,value:w.params[E.key]??"",t:r,dataSourceCandidates:a,bindingCandidates:l,onChange:I=>D(E.key,I)},E.key))}):w.kind==="custom"?i.jsx(yu,{model:{...w.model,key:e},onChange:E=>b(E.key,Fs(E)),t:r,dataSourceCandidates:a,bindingCandidates:l,existingKeys:p.filter(E=>E!==e)}):null]}):null]})}const iS=new Set(["datasource-picker","binding-picker","select","toggle","state-key-picker","page-picker"]);function sS({param:e,value:t,t:n,dataSourceCandidates:o,bindingCandidates:r,onChange:s}){const a=Ks(e.label,n,e.key),l=e.widget??"",c=iS.has(l)?zn(e.widget):null,p=l==="datasource-picker"||l==="binding-picker"?o:void 0;return i.jsxs("div",{"data-testid":`g7le-computed-param-${e.key}`,style:xS,children:[i.jsx("span",{style:wS,children:a}),i.jsx("div",{style:{flex:1,minWidth:0},children:c?i.jsx(c,{control:{...e},value:t,onChange:f=>s(typeof f=="string"?f:""),t:n,candidates:p}):i.jsx(Ke,{value:t,onChange:f=>s(f),t:n,candidates:r,testidPrefix:`g7le-computed-param-${e.key}-chip`})})]})}const aS={display:"flex",flexDirection:"column",gap:12,minWidth:0},lS={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},dS={border:"1px solid #e2e8f0",borderRadius:8,padding:"8px 10px",display:"flex",flexDirection:"column",gap:6,background:"#f8fafc"},cS={display:"flex",alignItems:"center",gap:6},uS={fontSize:13,fontWeight:600,color:"#0f172a"},pS={fontSize:10,color:"#64748b",fontFamily:"monospace"},fS={fontSize:10,color:"#0891b2",whiteSpace:"nowrap"},gS={fontSize:10,color:"#7c3aed",whiteSpace:"nowrap"},hS={fontSize:10,color:"#92400e",whiteSpace:"nowrap"},yS={display:"flex",alignItems:"center",gap:8,marginTop:4,minWidth:0},bS={fontSize:11,color:"#7c3aed",flex:1,minWidth:0},mS={border:"1px solid #c4b5fd",borderRadius:6,background:"#f5f3ff",color:"#6d28d9",cursor:"pointer",fontSize:11,padding:"2px 8px",whiteSpace:"nowrap"},Vs={border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",fontSize:11,padding:"2px 6px"},vS={display:"flex",flexDirection:"column",gap:6,paddingTop:6,borderTop:"1px dashed #e2e8f0"},_S={margin:0,fontSize:11,color:"#b45309",background:"#fef3c7",padding:"6px 8px",borderRadius:6},xS={display:"flex",alignItems:"center",gap:8,minWidth:0},wS={fontSize:11,color:"#64748b",minWidth:90},kS={padding:"6px 12px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},SS={marginTop:6,border:"1px solid #cbd5e1",borderRadius:8,background:"#fff",padding:8,maxHeight:380,overflowY:"auto"},CS={fontSize:11,fontWeight:700,color:"#94a3b8",padding:"6px 4px 2px"},$S={display:"flex",alignItems:"center",gap:6,width:"100%",textAlign:"left",padding:"6px 8px",fontSize:12,border:"none",background:"transparent",cursor:"pointer",borderRadius:6},ES={flex:1,minWidth:0,color:"#0f172a"},IS={fontSize:10,color:"#64748b",whiteSpace:"nowrap"},AS={padding:"6px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},TS={marginTop:6,padding:"6px 12px",fontSize:12,border:"1px solid #3b82f6",borderRadius:6,background:"#3b82f6",color:"#fff",cursor:"pointer"},DS={margin:0,fontSize:12,color:"#94a3b8"},zS={margin:"2px 0 0",padding:"6px 8px",fontSize:11,fontFamily:"monospace",color:"#0f172a",background:"#f1f5f9",border:"1px solid #e2e8f0",borderRadius:6,whiteSpace:"pre-wrap",wordBreak:"break-all",overflowX:"auto"};function NS(e,t){return t==="any"?!0:e===null||typeof e!="object"?!1:t==="object"?!Array.isArray(e):!0}function Us({value:e,onChange:t,onValidityChange:n,t:o,shape:r="any",emptyValue:s=void 0,placeholder:a,minHeight:l=80,testidPrefix:d="g7le-json-block",shapeErrorKey:c,invalidErrorKey:p,ariaLabel:f,id:b,validate:g}){const[m,h]=u.useState(()=>qr(e)),[v,y]=u.useState(null),_=u.useRef(!1),w=u.useRef(e);u.useEffect(()=>{if(!_.current&&!Object.is(e,w.current)){if(qr(e)===qr(w.current)){w.current=e;return}h(qr(e)),y(null),w.current=e,n?.(!0)}},[e]);const k=x=>{if(_.current=!0,h(x),x.trim()===""){y(null),w.current=s,n?.(!0),t(s);return}let $;try{$=JSON.parse(x)}catch{y(o(p??"layout_editor.json_block.invalid")),n?.(!1);return}if(!NS($,r)){y(o(c??"layout_editor.json_block.invalid")),n?.(!1);return}const C=g?.($)??null;if(C){y(C),n?.(!1);return}y(null),w.current=$,n?.(!0),t($)};return i.jsxs("div",{className:"g7le-json-block",style:MS,children:[i.jsx("textarea",{id:b,"data-testid":d,style:{...LS,minHeight:l},value:m,spellCheck:!1,"aria-label":f,"aria-invalid":v?!0:void 0,placeholder:a,onChange:x=>k(x.target.value),onBlur:()=>{_.current=!1}}),v?i.jsx("div",{"data-testid":`${d}-error`,style:PS,children:v}):null]})}function qr(e){if(e===void 0)return"";try{return JSON.stringify(e,null,2)??""}catch{return""}}const MS={display:"flex",flexDirection:"column",gap:4,minWidth:0},LS={width:"100%",boxSizing:"border-box",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:12,lineHeight:1.5,color:"#0f172a",background:"#fff",border:"1px solid #cbd5e1",borderRadius:6,padding:"6px 8px",resize:"vertical"},PS={fontSize:11,color:"#dc2626"},OS=[{kind:"string",labelKey:"layout_editor.initstate.kind_string"},{kind:"number",labelKey:"layout_editor.initstate.kind_number"},{kind:"boolean",labelKey:"layout_editor.initstate.kind_boolean"},{kind:"null",labelKey:"layout_editor.initstate.kind_null"},{kind:"list",labelKey:"layout_editor.initstate.kind_list"},{kind:"object",labelKey:"layout_editor.initstate.kind_object"}],qs={local:"initLocal",global:"initGlobal",isolated:"initIsolated"};function BS({raw:e,own:t,patch:n,t:o,isolatedOrphan:r={}}){const s=u.useMemo(()=>{const f=t?.state&&typeof t.state=="object"?t.state:void 0,b=e?.state&&typeof e.state=="object"?e.state:void 0;if(!(!f&&!b))return{...b??{},...f??{}}},[t,e]),{initLocal:a,migrated:l}=u.useMemo(()=>sk({initLocal:e?.initLocal,state:s}),[e,s]),d=f=>{if(f==="local")return a;const b=e?.[qs[f]];return b&&typeof b=="object"?b:{}},c=f=>{if(f==="local"){const b=t?.initLocal??{},g=s?Object.keys(s):[];return Array.from(new Set([...Object.keys(b),...g]))}return Object.keys(t?.[qs[f]]??{})},p=u.useCallback((f,b)=>{const g=qs[f];f==="local"&&l&&n("state",void 0),n(g,Object.keys(b).length===0?void 0:b)},[n,l]);return i.jsxs("div",{className:"g7le-initstate-form","data-testid":"g7le-initstate-form",style:jS,children:[i.jsx("p",{style:HS,children:o("layout_editor.page_settings.initstate.heading")}),l?i.jsxs("p",{"data-testid":"g7le-initstate-legacy-state",style:FS,children:["ⓘ ",o("layout_editor.initstate.legacy_state")]}):null,i.jsx(Gs,{scope:"local",label:o("layout_editor.initstate.section_local"),value:d("local"),ownKeys:c("local"),patchSection:p,t:o}),i.jsx(Gs,{scope:"global",label:o("layout_editor.initstate.section_global"),value:d("global"),ownKeys:c("global"),patchSection:p,t:o}),i.jsx(Gs,{scope:"isolated",label:o("layout_editor.initstate.section_isolated"),description:o("layout_editor.initstate.section_isolated_desc"),value:d("isolated"),ownKeys:c("isolated"),patchSection:p,t:o,orphan:r}),i.jsxs("p",{style:sC,children:["ⓘ ",o("layout_editor.initstate.isolated_dynamic_hint")]})]})}function Gs({scope:e,label:t,description:n,value:o,ownKeys:r,patchSection:s,t:a,orphan:l={}}){const[d,c]=u.useState(""),[p,f]=u.useState("string"),[b,g]=u.useState(null),[m,h]=u.useState(!1),v=Object.keys(o),y=v,_=(x,$)=>{s(e,{...o,[x]:$})},w=x=>{const $={...o};delete $[x],s(e,$)},k=()=>{const x=d.trim();if(!x){g(a("layout_editor.initstate.name_required"));return}if(!Ls(x)){g(a("layout_editor.initstate.name_invalid"));return}if(x in o){g(a("layout_editor.initstate.name_duplicate"));return}const $={string:"",number:0,boolean:!1,null:null,list:[],object:{}};s(e,{...o,[x]:$[p]}),c(""),g(null)};return i.jsxs("div",{"data-testid":`g7le-initstate-section-${e}`,style:KS,children:[i.jsxs("div",{style:VS,children:[i.jsx("div",{style:US,children:t}),i.jsx("button",{type:"button","data-testid":`g7le-initstate-${e}-mode-toggle`,onClick:()=>h(x=>!x),style:GS,children:a(m?"layout_editor.json_block.mode_block":"layout_editor.json_block.mode_code")})]}),n?i.jsxs("p",{style:qS,children:["ⓘ ",n]}):null,m?i.jsx(Us,{value:o,shape:"object",emptyValue:{},onChange:x=>s(e,x??{}),t:a,testidPrefix:`g7le-initstate-${e}-code`,placeholder:`{ "keyword": "", "page": 1 }`,shapeErrorKey:"layout_editor.json_block.must_be_object",validate:x=>{const $=Object.keys(x??{}).filter(C=>!Ls(C));return $.length?a("layout_editor.json_block.invalid_keys",{keys:$.join(", ")}):null}}):i.jsxs(i.Fragment,{children:[v.length===0?i.jsx("p",{"data-testid":`g7le-initstate-${e}-empty`,style:iC,children:a("layout_editor.initstate.no_values")}):v.map(x=>{const C=ik(y,r,x)==="inherited",S=e==="isolated"&&l[x];return i.jsx(WS,{scope:e,itemKey:x,value:o[x],inherited:C,isOrphan:!!S,onChangeValue:D=>_(x,D),onRemove:()=>w(x),t:a},x)}),i.jsxs("div",{style:RS,children:[i.jsx("input",{type:"text","data-testid":`g7le-initstate-${e}-add-name`,value:d,placeholder:a("layout_editor.initstate.value_name"),onChange:x=>{c(x.target.value),b&&g(null)},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),k())},"aria-invalid":b?!0:void 0,style:{...eC,...b?tC:null}}),i.jsx("select",{"data-testid":`g7le-initstate-${e}-add-kind`,value:p,onChange:x=>f(x.target.value),"aria-label":a("layout_editor.initstate.value_kind"),style:oC,children:OS.map(x=>i.jsx("option",{value:x.kind,children:a(x.labelKey)},x.kind))}),i.jsxs("button",{type:"button","data-testid":`g7le-initstate-${e}-add`,onClick:k,style:rC,children:["+ ",a("layout_editor.initstate.add_value")]})]}),b?i.jsx("p",{"data-testid":`g7le-initstate-${e}-add-error`,style:nC,children:b}):null]})]})}function WS({scope:e,itemKey:t,value:n,inherited:o,isOrphan:r,onChangeValue:s,onRemove:a,t:l}){const[d,c]=u.useState(!1);let p;try{p=JSON.stringify(n,null,2)??String(n)}catch{p=String(n)}return i.jsxs("div",{"data-testid":`g7le-initstate-${e}-item-${t}`,style:YS,children:[i.jsxs("div",{style:XS,children:[o?i.jsx("span",{"data-testid":`g7le-initstate-inherited-${t}`,style:JS,children:"🔗"}):null,i.jsx("code",{style:ZS,children:t}),i.jsx("span",{style:{flex:1}}),i.jsx("button",{type:"button","data-testid":`g7le-initstate-code-${t}`,onClick:()=>c(f=>!f),style:Ys,"aria-label":l("layout_editor.value_tree.show_source"),title:l("layout_editor.value_tree.show_source"),children:""}),o?i.jsx("button",{type:"button","data-testid":`g7le-initstate-revert-${t}`,onClick:a,style:Ys,children:l("layout_editor.initstate.revert")}):i.jsx("button",{type:"button","data-testid":`g7le-initstate-remove-${t}`,onClick:a,style:Ys,"aria-label":l("layout_editor.init_actions.remove"),children:"✕"})]}),d?i.jsx("pre",{"data-testid":`g7le-initstate-code-block-${t}`,style:aC,children:p}):null,i.jsx(Mn,{value:n,onChange:s,t:l,path:t,scope:e}),r?i.jsxs("p",{"data-testid":`g7le-initstate-isolated-orphan-${t}`,style:QS,children:["⚠ ",l("layout_editor.initstate.isolated_orphan")]}):null]})}const jS={display:"flex",flexDirection:"column",gap:14,minWidth:0},HS={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},FS={margin:0,fontSize:11,color:"#1d4ed8",background:"#eff6ff",padding:"6px 8px",borderRadius:6},KS={display:"flex",flexDirection:"column",gap:8,padding:10,border:"1px solid #e2e8f0",borderRadius:10,minWidth:0},VS={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},US={fontSize:12,fontWeight:700,color:"#475569"},qS={margin:0,fontSize:11,color:"#94a3b8"},GS={padding:"2px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},YS={display:"flex",flexDirection:"column",gap:4,padding:"6px 8px",border:"1px solid #f1f5f9",borderRadius:6,minWidth:0},XS={display:"flex",alignItems:"center",gap:6},JS={fontSize:12},ZS={fontSize:12,color:"#0f172a",fontFamily:"monospace"},Ys={border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",fontSize:11,padding:"2px 6px"},QS={margin:0,fontSize:11,color:"#b45309",background:"#fef3c7",padding:"4px 6px",borderRadius:6},RS={display:"flex",gap:6,alignItems:"center"},eC={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},tC={border:"1px solid #dc2626"},nC={margin:0,fontSize:11,color:"#dc2626"},oC={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#0f172a"},rC={padding:"2px 10px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},iC={margin:0,fontSize:12,color:"#94a3b8"},sC={margin:0,fontSize:11,color:"#94a3b8"},aC={margin:"2px 0",padding:"6px 8px",fontSize:11,fontFamily:"monospace",color:"#0f172a",background:"#f1f5f9",border:"1px solid #e2e8f0",borderRadius:6,whiteSpace:"pre-wrap",wordBreak:"break-all",overflowX:"auto"},lC={self:"layout_editor.error_rows.source_self",inherited:"layout_editor.error_rows.source_inherited",template:"layout_editor.error_rows.source_template",none:"layout_editor.error_rows.source_none"};function Xs({value:e,onChange:t,t:n,codes:o,mode:r="local",sourceOf:s,renderActionList:a,testIdPrefix:l="g7le-error-rows"}){const d=o??Object.keys(e),c=u.useCallback((f,b)=>{t({...e,[f]:b})},[e,t]),p=u.useCallback(f=>{const b={...e};delete b[f],t(b)},[e,t]);return i.jsx("div",{className:l,"data-testid":l,children:d.map(f=>{const b=e[f],g=b!==void 0,m=r==="badge"&&s?s(f):null;return i.jsxs("div",{"data-testid":`${l}-row-${f}`,style:{border:"1px solid #e2e8f0",borderRadius:8,padding:"8px 10px",marginBottom:6},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[i.jsx("strong",{"data-testid":`${l}-code-${f}`,style:{fontSize:13},children:f==="default"?n("layout_editor.error_rows.default"):f}),m?i.jsxs("span",{"data-testid":`${l}-source-${f}`,style:{fontSize:11,padding:"2px 6px",borderRadius:4,background:"#f1f5f9",color:"#475569"},children:["〔",n(lC[m]),"〕"]}):null,g?i.jsx("button",{type:"button","data-testid":`${l}-clear-${f}`,onClick:()=>p(f),style:{marginLeft:"auto",fontSize:12},children:n("layout_editor.error_rows.clear")}):i.jsx("span",{style:{marginLeft:"auto",fontSize:12,color:"#94a3b8"},children:n("layout_editor.error_rows.no_action")})]}),m==="inherited"||m==="template"?i.jsxs("div",{"data-testid":`${l}-override-${f}`,style:{marginTop:6,display:"flex",alignItems:"flex-start",gap:8},children:[i.jsxs("p",{style:{margin:0,flex:1,fontSize:12,color:"#64748b"},children:["ⓘ ",n(m==="inherited"?"layout_editor.error_rows.override_inherited":"layout_editor.error_rows.override_template")]}),g?i.jsx("button",{type:"button","data-testid":`${l}-revert-${f}`,onClick:()=>p(f),style:{fontSize:12,padding:"2px 8px",border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},children:n("layout_editor.error_rows.revert")}):i.jsx("button",{type:"button","data-testid":`${l}-override-here-${f}`,onClick:()=>c(f,{}),style:{fontSize:12,padding:"2px 8px",border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},children:n("layout_editor.error_rows.override_here")})]}):null,f==="default"?i.jsxs("p",{"data-testid":`${l}-default-warn-${f}`,style:{margin:"6px 0 0",fontSize:12,color:"#b45309"},children:["⚠ ",n("layout_editor.error_rows.default_warning")]}):null,i.jsx("div",{style:{marginTop:6},children:a?a(f,b,h=>c(f,h)):i.jsx("pre",{"data-testid":`${l}-json-${f}`,style:{margin:0,fontSize:12,color:"#475569"},children:g?JSON.stringify(b):""})})]},f)})})}function dC(e){return[...e.filter(n=>n!=="maintenance"),"default"]}function cC({value:e,onChange:t,t:n,errorConfigCodes:o=[],ownCodes:r=[],templateCodes:s=[],recipes:a,pageCandidates:l,modalCandidates:d,dataSourceCandidates:c,stateKeyCandidates:p}){const f=u.useMemo(()=>$o(a),[a]),b=u.useMemo(()=>dC(o),[o]),g=f.length>0,m=u.useMemo(()=>Yl("error",n),[n]),h=u.useMemo(()=>({pageCandidates:l,dataSourceCandidates:c,stateKeyCandidates:p,modalCandidates:d,bindingCandidates:m}),[l,c,p,d,m]),v=u.useCallback(y=>r.includes(y)?"self":y in e?"inherited":s.includes(y)?"template":"none",[r,e,s]);return g?i.jsxs("div",{className:"g7le-error-form","data-testid":"g7le-error-form",style:bu,children:[i.jsx("p",{style:mu,children:n("layout_editor.page_settings.error.heading")}),i.jsxs("p",{style:pC,children:["ⓘ ",n("layout_editor.error.intro")]}),i.jsx(Xs,{value:e,onChange:t,t:n,codes:b,mode:"badge",sourceOf:v,testIdPrefix:"g7le-error-rows",renderActionList:(y,_,w)=>i.jsx(uC,{code:y,action:_,recipes:a,normalized:f,t:n,pools:h,onPatch:w})})]}):i.jsxs("div",{className:"g7le-error-form","data-testid":"g7le-error-form",style:bu,children:[i.jsx("p",{style:mu,children:n("layout_editor.page_settings.error.heading")}),i.jsxs("p",{"data-testid":"g7le-error-degrade",style:fC,children:["ⓘ ",n("layout_editor.error.degrade")]}),i.jsx(Xs,{value:e,onChange:t,t:n,codes:b,mode:"badge",sourceOf:v,testIdPrefix:"g7le-error-rows"})]})}function uC({code:e,action:t,recipes:n,normalized:o,t:r,pools:s,onPatch:a}){const[l,d]=u.useState(!1),c=Array.isArray(t)?t[0]:t,p=typeof c?.handler=="string"?c.handler:"",f=o.find(_=>_.id===p)??null,b=c?Jn(c,o):null,g=b?.kind==="preset"?b.values:{},m=p==="sequence"||p==="parallel",h=_=>{if(_===""){a({});return}const w=o.find(k=>k.id===_);w&&a(Er(w,{}))},v=["","showErrorPage","navigate","openModal","toast","setState","sequence","parallel"],y=m&&c?Array.isArray(c.params?.actions)?c.params.actions:[]:[];return i.jsxs("div",{"data-testid":`g7le-error-action-${e}`,style:gC,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[i.jsx("select",{"data-testid":`g7le-error-handler-${e}`,value:p,onChange:_=>h(_.target.value),style:{...hC,flex:1},children:v.map(_=>i.jsx("option",{value:_,children:r(_===""?"layout_editor.error.handler_none":`layout_editor.error.handler_${_}`)},_))}),p!==""?i.jsx("button",{type:"button","data-testid":`g7le-error-code-${e}`,onClick:()=>d(_=>!_),"aria-label":r("layout_editor.action_list.view_code"),title:r("layout_editor.action_list.view_code"),style:l?yC:vu,children:""}):null]}),m?i.jsx("div",{"data-testid":`g7le-error-actions-${e}`,children:i.jsx(Yt,{actions:y,onChange:_=>a({handler:p,params:{actions:_}}),t:r,recipes:n,candidatePools:s,chipContext:"error",testIdPrefix:`g7le-error-seq-${e}`})}):f&&c?i.jsx(Os,{raw:c,recipe:f,values:g,t:r,pools:s,onChange:_=>a(_),testIdPrefix:`g7le-error-action-${e}-edit`}):null,l&&c?i.jsx("pre",{"data-testid":`g7le-error-code-view-${e}`,style:bC,children:JSON.stringify(t,null,2)}):null]})}const bu={display:"flex",flexDirection:"column",gap:12,minWidth:0},mu={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},pC={margin:0,fontSize:11,color:"#94a3b8"},fC={margin:0,fontSize:12,color:"#b45309",background:"#fef3c7",padding:"8px 10px",borderRadius:6},gC={display:"flex",flexDirection:"column",gap:6,minWidth:0},hC={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},vu={flex:"0 0 auto",width:26,height:26,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:11,border:"1px solid #e2e8f0",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer",fontFamily:"ui-monospace, monospace"},yC={...vu,background:"#0f172a",borderColor:"#0f172a",color:"#e2e8f0"},bC={margin:"4px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:12,overflow:"auto",fontFamily:"ui-monospace, monospace"};function Gr(e){const t=e.trim(),n=/^\{\{([\s\S]*)\}\}$/.exec(t);return n?n[1].trim():t}function mC(e){let t=e;for(;t.length>=2&&t[0]==="("&&t[t.length-1]===")";){let n=0,o=!0;for(let r=0;r!!o&&typeof o.value=="string"&&typeof o.expr=="string").map(o=>({value:o.value,label:typeof o.label=="string"?o.label:void 0,params:Array.isArray(o.params)?o.params:[],expr:Gr(o.expr),aliases:_u(o.aliases)}));const n=[];for(const[o,r]of Object.entries(e)){if(o==="comment"||o==="operators"||!r||typeof r!="object")continue;const s=r;typeof s.expr=="string"&&n.push({value:o,label:typeof s.label=="string"?s.label:void 0,params:Array.isArray(s.params)?s.params:[],expr:Gr(s.expr),aliases:_u(s.aliases)})}return n}function _u(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(typeof n!="string")continue;const o=Gr(n);o.trim().length>0&&t.push(o)}return t}function _C(e){const t=e.params.length*1e3;return Yr(e.expr).replace(/\{\w+\}/g,"").length-t}function xC(e){return e.map((t,n)=>({op:t,idx:n,score:_C(t)})).sort((t,n)=>n.score-t.score||t.idx-n.idx).map(t=>t.op)}function wC(e,t){return e.replace(/\{(\w+)\}/g,(n,o)=>{const r=t[o];return r===void 0?n:r})}function kC(e,t){const n=t.find(o=>o.value===e.operator);return n?wC(n.expr,e.params??{}):null}function xu(e,t,n){const o=e.map(a=>kC(a,n)).filter(a=>typeof a=="string"&&a.trim().length>0);if(o.length===0)return"";if(o.length===1)return`{{ ${o[0]} }}`;const r=t==="or"?" || ":" && ";return`{{ ${o.map(a=>`(${a})`).join(r)} }}`}function wu(e,t){const n=Yr(e);for(const o of xC(t)){if(o.params.length===0){for(const r of[o.expr,...o.aliases])if(Yr(r)===n)return{operator:o.value,params:{}};continue}for(const r of[o.expr,...o.aliases]){const s=SC(o,r,n);if(s)return s}}return null}function SC(e,t,n){const o=t.trim(),r=[];let s="",a=0;for(;a=|<=|>|<|\?|:|\(|\)|!/.test(b))return null;return{operator:e.value,params:c}}function CC(e){const t=new Set,n=/(['"])\{(\w+)\}\1/g;let o;for(;(o=n.exec(e))!==null;)t.add(o[2]);return t}function $C(e,t){if(typeof e!="string"||e.trim()==="")return null;const n=Gr(e),o=wu(n,t);if(o)return{clauses:[o],combinator:"and"};const r=n.includes(") || (")?"or":(n.includes(") && ("),"and"),s=r==="or"?") || (":") && (";if(!n.startsWith("(")||!n.endsWith(")")||!n.includes(s))return null;const l=n.slice(1,-1).split(s),d=[];for(const c of l){const p=wu(c.trim(),t);if(!p)return null;d.push(p)}return{clauses:d,combinator:r}}const ku=Lt(),Pn=ku.responsiveManager,Mo=ku.BREAKPOINT_PRESETS;function Su(e){const t=e.groupPrefixes;return{group:typeof e.group=="string"?e.group:void 0,widget:typeof e.widget=="string"?e.widget:void 0,apply:e.apply&&typeof e.apply=="object"?e.apply:void 0,options:Array.isArray(e.options)?e.options:void 0,scale:Array.isArray(e.scale)?e.scale:void 0,groupPrefixes:Array.isArray(t)?t.filter(n=>typeof n=="string"&&n.length>0):void 0,groupTokens:Array.isArray(e.groupTokens)?e.groupTokens.filter(n=>typeof n=="string"&&n.length>0):void 0}}function Cu(e){const t={...e??{}},n=t.style&&typeof t.style=="object"&&!Array.isArray(t.style)?{...t.style}:{};return t.style=n,{props:t,style:n}}function Xr(e){return typeof e!="string"?[]:e.split(/\s+/).filter(t=>t.length>0)}function $u(e,t=!1){const n=new Set,o=[],r=s=>{if(s){for(const a of s.tokens??[])n.add(a);s.tokenTemplate&&s.tokenTemplate.includes("{value}")&&o.push(s.tokenTemplate.split("{value}")[0]??"")}};r(e.apply);for(const s of e.options??[])r(s.apply);for(const s of e.groupPrefixes??[])o.push(s);for(const s of e.groupTokens??[])n.add(s);return s=>{if(t){if(!Xt(s))return!1;const a=ea(s);return n.has(a)?!0:o.some(l=>l.length>0&&a.startsWith(l))}return Xt(s)?!1:n.has(s)?!0:o.some(a=>a.length>0&&s.startsWith(a))}}function EC(e,t,n,o,r=!1){const s=$u(t,r),a=Xr(e.className).filter(p=>!s(p)),l=[];if(Array.isArray(n.tokens))l.push(...n.tokens);else if(n.tokenTemplate&&n.tokenTemplate.includes("{value}")&&o!=null){const p=String(o).split(/\s+/).filter(f=>f.length>0);for(const f of p)l.push(n.tokenTemplate.replace("{value}",f))}const d=r?l.map(Mu):l,c=[...a,...d];c.length===0?delete e.className:e.className=c.join(" ")}const Js={url:"backgroundImage",size:"backgroundSize",repeat:"backgroundRepeat",position:"backgroundPosition"};function Eu(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.keys(Js).some(t=>t in e)}function Iu(e){return/^url\(/i.test(e.trim())?e:`url(${e})`}function Jr(e){const t=/^url\(\s*(['"]?)(.*?)\1\s*\)$/i.exec(e.trim());return t?t[2]:e}function IC(e){return e.includes("backgroundImage")}function Zs(e,t){if(!Eu(e))return e;const n=e.url;if(typeof n!="string"||n.trim()==="")return"";const o=Jr(n);return t?Iu(o):o}function Qs(e,t){if(e!=null){if(typeof e=="object"){const n=e[t];return typeof n=="string"||typeof n=="number"?n:void 0}return e}}function AC(e){const t=e.backgroundImage,n=Qs(e.backgroundSize,"size"),o=Qs(e.backgroundRepeat,"repeat"),r=Qs(e.backgroundPosition,"position");let s;if(typeof t=="string"?s=Jr(t):t&&typeof t=="object"?s=t.url:s=void 0,s===void 0&&n===void 0&&o===void 0&&r===void 0)return;const a={};return s!==void 0&&(a.url=typeof s=="string"?Jr(s):s),n!==void 0&&(a.size=n),o!==void 0&&(a.repeat=o),r!==void 0&&(a.position=r),a}const Au=new Set(["type","name","props","children","text","if","iteration","responsive","__source","__injectedProps"]);function TC(e,t,n){const o=t.nodeKey;if(typeof o!="string"||o===""||Au.has(o))return e;const r={...e};return n==null||n===""?delete r[o]:r[o]=n,r}function DC(e,t,n,o=!1){const r=(s,a)=>{a==null||a===""?delete e[s]:e[s]=a};if(Array.isArray(t.props)){if(!t.values&&Eu(n)){for(const s of t.props){const a=Object.keys(Js).find(c=>Js[c]===s);let l=a?n[a]:void 0;l!==null&&typeof l=="object"&&(l=void 0);const d=s==="backgroundImage"&&typeof l=="string"&&l!==""?Iu(l):l;r(s,d)}return}for(const s of t.props){const a=t.values&&s in t.values?t.values[s]:n;r(s,a)}return}if(typeof t.prop=="string"){const s=t.value!==void 0?t.value:n;r(t.prop,o?Zs(s,!0):s)}}function zC(e,t,n,o=!1){if(typeof t.varName!="string")return;const r=t.value!==void 0?t.value:n,s=o?Zs(r,!0):r;s==null||s===""?delete e[t.varName]:e[t.varName]=s}function NC(e,t,n,o=!1){if(typeof t.propKey!="string")return;const r=t.value!==void 0?t.value:n,s=o?Zs(r,!1):r;s==null||s===""?delete e[t.propKey]:e[t.propKey]=s}function yn(e,t,n,o=jt){const r=Su(t),s=o.colorScheme==="dark";let a,l=!1;if(r.options){const b=r.options.find(g=>g.value===n);l=b!==void 0,a=b?.apply??r.apply}else a=r.apply;const d=n==null||n===""||l&&a===void 0,c=d?r.apply:a,p=c?.type==="classToken"||(r.options?.some(b=>b.apply?.type==="classToken")??!1);if(s&&!p)return e;if(c?.type==="nodeKey")return TC(e,c,d?void 0:n);const f=o.breakpoint!=="base"&&p?(()=>{const b=e.props??{};return typeof b.className=="string"?b.className:void 0})():void 0;return Nu(e,o,(b,g)=>{if(f!==void 0&&typeof b.className!="string"&&(b.className=f),d){const m=$u(r,s),h=Xr(b.className).filter(v=>!m(v));if(h.length===0?delete b.className:b.className=h.join(" "),!s&&r.apply){const v=r.apply;if(v.type==="styleProp")for(const y of v.props??(v.prop?[v.prop]:[]))delete g[y];else v.type==="cssVar"&&v.varName?delete g[v.varName]:v.type==="propValue"&&v.propKey&&delete b[v.propKey]}}else if(a){const m=r.widget==="image";switch(a.type){case"classToken":EC(b,r,a,n,s);break;case"styleProp":DC(g,a,n,m);break;case"cssVar":zC(g,a,n,m);break;case"propValue":NC(b,a,n,m);break}}})}function Zr(e,t){const n=Xr(e);return t?n.filter(Xt).map(ea):n.filter(o=>!Xt(o))}function MC(e,t,n,o){const r=new Set(t.filter(l=>typeof l=="string"&&l.length>0)),s=l=>o?Xt(l)?r.has(ea(l)):!1:Xt(l)?!1:r.has(l),a=Xr(e).filter(l=>!s(l));return n&&n.length>0&&a.push(o?Mu(n):n),a.join(" ").trim()}function Tu(e,t,n,o){if(e.options&&e.options.some(s=>s.apply)){const s=Zr(t.className,o),a=[];for(const l of e.options)l.apply&&PC(l.apply,s,n,t)&&a.push(l.value);if(a.length>0)return{value:a[0],matched:!0,conflict:a.length>1?!0:void 0};if(!e.apply)return{value:void 0,matched:!1}}const r=e.apply;if(!r)return{value:void 0,matched:!1};switch(r.type){case"styleProp":{if(!r.values&&Array.isArray(r.props)&&IC(r.props)){const l=AC(n);return l===void 0?{value:void 0,matched:!1}:{value:l,matched:!0}}const s=r.prop??r.props?.[0];if(!s)return{value:void 0,matched:!1};const a=n[s];return a===void 0?{value:void 0,matched:!1}:{value:a,matched:!0}}case"cssVar":{if(!r.varName)return{value:void 0,matched:!1};const s=n[r.varName];return s===void 0?{value:void 0,matched:!1}:{value:s,matched:!0}}case"propValue":{if(!r.propKey)return{value:void 0,matched:!1};const s=t[r.propKey];return s===void 0?{value:void 0,matched:!1}:e.widget==="image"&&typeof s=="string"?{value:{url:Jr(s)},matched:!0}:{value:s,matched:!0}}case"classToken":{const s=Zr(t.className,o);if(r.tokenTemplate&&r.tokenTemplate.includes("{value}")){const[a,l]=r.tokenTemplate.split("{value}");if((a??"")===""&&(l??"")===""&&e.groupPrefixes?.length){const d=s.filter(c=>e.groupPrefixes.some(p=>c.startsWith(p)));return d.length>0?{value:d.join(" "),matched:!0}:{value:void 0,matched:!1}}for(const d of s)if(d.startsWith(a)&&d.endsWith(l??""))return{value:d.slice(a.length,l?d.length-l.length:void 0),matched:!0}}return Array.isArray(r.tokens)&&r.tokens.every(a=>s.includes(a))?{value:!0,matched:!0}:{value:void 0,matched:!1}}default:return{value:void 0,matched:!1}}}function Du(e){return e.style&&typeof e.style=="object"&&!Array.isArray(e.style)?e.style:{}}function Lo(e,t,n=jt){const o=Su(t),r=n.colorScheme==="dark";if(r&&!Rs(o.apply)&&!o.options?.some(m=>Rs(m.apply)))return{value:void 0,matched:!1,darkReadonly:!0};if(o.apply?.type==="nodeKey"){const m=o.apply.nodeKey;if(typeof m!="string"||m===""||Au.has(m))return{value:void 0,matched:!1};const h=e[m];return h===void 0?{value:void 0,matched:!1}:{value:h,matched:!0}}const s=HC(e,n),a=Du(s),l=Tu(o,s,a,r);if(n.breakpoint==="base")return l;const d=l.matched?l.value:void 0,c=e.props??{},p=Du(c),f=Tu(o,c,p,r),b=l.matched&&l.value!==void 0,g=b&&!LC(l.value,f.value);return{value:b?l.value:f.value,matched:g?l.matched:f.matched,conflict:g?l.conflict:f.conflict,scopedValue:g?l.value:void 0,baseFallback:g?void 0:f.value,scopedRawValue:d}}function LC(e,t){if(e===t)return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object")return!1;try{return JSON.stringify(e)===JSON.stringify(t)}catch{return!1}}function PC(e,t,n,o){switch(e.type){case"classToken":return Array.isArray(e.tokens)&&e.tokens.length>0?e.tokens.every(r=>t.includes(r)):!1;case"styleProp":{const r=e.prop??e.props?.[0];if(!r)return!1;const s=e.value;return s!==void 0?n[r]===s:n[r]!==void 0}case"cssVar":return e.varName?n[e.varName]!==void 0:!1;case"propValue":return e.propKey?e.value!==void 0?o[e.propKey]===e.value:o[e.propKey]!==void 0:!1;default:return!1}}const jt={colorScheme:"base",breakpoint:"base"},Po="dark:";function OC(e){return e==="base"?!0:Pn.parseRange(e)!==null}function zu(e){return e in Mo}function Qr(e,t,n){if(e==="custom"){if(typeof n=="number"){const o=t.responsive;if(o&&typeof o=="object"){const r=Pn.getMatchingKey(o,n);if(r)return r}}return"base"}return e}function BC(e){return!!e&&typeof e=="object"&&Array.isArray(e.children)}function WC(e,t,n){let o,r,s;if(e!=="custom"&&e in Mo){o=e;const l=Mo[e];r=l.min,s=l.max}else if(e!=="custom"){const l=Pn.parseRange(e);if(l)o=e,r=l.min,s=l.max;else{const d=typeof n=="number"?n:Pn.getWidth();o=`${d}-${d}`,r=d,s=d}}else{const l=typeof n=="number"?n:Pn.getWidth();r=l,s=l,o=`${l}-${l}`}const a=t.responsive;if(a&&typeof a=="object"){let l=null,d=1/0;for(const c of Object.keys(a)){if(!BC(a[c]))continue;const p=Pn.parseRange(c);if(p){if(p.min===r&&p.max===s)return{mode:"merge",key:c};if(p.min<=r&&p.max>=s){const f=p.max-p.min;ft.length>0):[]}function VC(e,t){if(t.colorScheme==="dark")return Nu(e,t,l=>{const d=Rr(l.className).filter(c=>!Xt(c));d.length===0?delete l.className:l.className=d.join(" ")});if(t.breakpoint==="base")return e;const o=t.breakpoint;if(!e.responsive?.[o])return e;const r={...e.responsive},s={...r[o]};delete s.props,Object.keys(s).length===0?delete r[o]:r[o]=s;const a={...e};return Object.keys(r).length===0?delete a.responsive:a.responsive=r,a}function ta(e,t){if(t.colorScheme==="dark"){const c=t.breakpoint==="base"?e.props:e.responsive?.[t.breakpoint]?.props;return Rr(c?.className).some(Xt)}if(t.breakpoint==="base")return!1;const o=e.responsive?.[t.breakpoint];if(!o)return!1;const r=o.props;if(Object.keys(o).filter(c=>c!=="props").length>0)return!0;if(!r)return!1;if(Object.keys(r).filter(c=>c!=="className").length>0)return!0;const l=new Set(Rr(e.props?.className).filter(c=>!Xt(c))),d=Rr(r.className).filter(c=>!Xt(c));return d.length!==l.size?!0:d.some(c=>!l.has(c))}function Lu(e,t,n=""){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function Pu(e,t,n){if(n.breakpoint!=="base")return KC(e,n,t.trim());const o={...e};if(o.props&&typeof o.props=="object"&&"if"in o.props){const r={...o.props};delete r.if,o.props=r}return t.trim()===""?delete o.if:o.if=t,o}function Ou({node:e,spec:t,t:n,onPatchNode:o,dataSourceCandidates:r,stateKeyCandidates:s,scope:a=jt}){const l=u.useMemo(()=>vC(t?.conditionRecipes),[t]),d=a.breakpoint!=="base"?FC(e,a):e.if??e.props?.if,c=u.useMemo(()=>$C(d,l),[d,l]),p=c?.clauses??[],f=c?.combinator??"and",b=typeof d=="string"&&d.trim()!==""&&c===null;if(l.length===0)return i.jsx("div",{"data-testid":"g7le-condition-no-recipes",style:UC,children:n("layout_editor.visibility.no_recipes")});const g=(w,k)=>{o(Pu(e,xu(w,k,l),a))},m=(w,k)=>{g(p.map((x,$)=>$===w?k:x),f)},h=w=>{g(p.filter((k,x)=>x!==w),f)},v=w=>{const k=l[0];g([...p,{operator:k.value,params:{}}],w)},y=w=>{if(w==="datasource-picker")return r;if(w==="state-key-picker")return s};if(b)return i.jsxs("div",{className:"g7le-condition-advanced","data-testid":"g7le-condition-advanced",style:{display:"flex",flexDirection:"column",gap:8},children:[i.jsx("div",{style:e$,children:n("layout_editor.visibility.advanced_preserved")}),i.jsx("code",{"data-testid":"g7le-condition-advanced-expr",style:Wu,children:String(d)}),i.jsx("button",{type:"button","data-testid":"g7le-condition-clear-advanced",onClick:()=>o(Pu(e,"",a)),style:t$,children:n("layout_editor.visibility.clear")})]});const _=xu(p,f,l);return i.jsxs("div",{className:"g7le-condition-builder","data-testid":"g7le-condition-builder",style:{display:"flex",flexDirection:"column",gap:10},children:[i.jsx("div",{style:qC,children:n("layout_editor.visibility.show_when")}),p.map((w,k)=>{const x=l.find($=>$.value===w.operator)??l[0];return i.jsxs("div",{className:"g7le-condition-clause","data-testid":`g7le-condition-clause-${k}`,style:GC,children:[i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[k>0&&i.jsx("span",{"data-testid":`g7le-condition-combinator-${k}`,style:XC,children:n(f==="or"?"layout_editor.visibility.or":"layout_editor.visibility.and")}),i.jsx("select",{"data-testid":`g7le-condition-select-${k}`,value:w.operator,onChange:$=>m(k,{operator:$.target.value,params:{}}),style:YC,children:l.map($=>i.jsx("option",{value:$.value,children:Lu($.label,n,$.value)},$.value))}),i.jsx("button",{type:"button","data-testid":`g7le-condition-remove-${k}`,"aria-label":n("layout_editor.visibility.remove"),onClick:()=>h(k),style:JC,children:"✕"})]}),x.params.map($=>{const C=zn($.widget);return i.jsxs("div",{className:"g7le-condition-param","data-testid":`g7le-condition-param-${k}-${$.key}`,style:ZC,children:[i.jsx("span",{style:QC,children:Lu($.label,n,$.key)}),i.jsx("div",{style:{flex:1},children:C?i.jsx(C,{control:{...$},value:w.params[$.key],onChange:S=>m(k,{operator:w.operator,params:{...w.params,[$.key]:S===void 0?"":String(S)}}),t:n,candidates:y($.widget)}):i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:n("layout_editor.property_modal.unsupported_widget")})})]},$.key)})]},k)}),i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsxs("button",{type:"button","data-testid":"g7le-condition-add-and",onClick:()=>v("and"),style:Bu,children:["+ ",n("layout_editor.visibility.and")]}),i.jsxs("button",{type:"button","data-testid":"g7le-condition-add-or",onClick:()=>v("or"),style:Bu,children:["+ ",n("layout_editor.visibility.or")]})]}),_!==""&&i.jsxs("div",{"data-testid":"g7le-condition-preview",style:RC,children:[i.jsx("span",{style:{fontSize:11,color:"#64748b"},children:n("layout_editor.visibility.preview")}),i.jsx("code",{style:Wu,children:_})]})]})}const UC={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},qC={fontSize:12,fontWeight:600,color:"#0f172a"},GC={border:"1px solid #e2e8f0",borderRadius:8,padding:10,display:"flex",flexDirection:"column",gap:8,background:"#f8fafc"},YC={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff"},XC={fontSize:11,fontWeight:700,color:"#2563eb",background:"#dbeafe",padding:"2px 8px",borderRadius:999},JC={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12},Bu={padding:"5px 12px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},ZC={display:"flex",alignItems:"center",gap:8},QC={fontSize:11,color:"#64748b",minWidth:64},RC={display:"flex",flexDirection:"column",gap:4,padding:10,background:"#f1f5f9",borderRadius:6},Wu={fontSize:11,color:"#0f172a",fontFamily:"monospace",wordBreak:"break-all"},e$={fontSize:11,color:"#92400e",background:"#fef3c7",padding:"6px 8px",borderRadius:6},t$={padding:"5px 12px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer",alignSelf:"flex-start"};function n$(e){return typeof e=="string"?e:e===void 0?"":JSON.stringify(e)}function o$(e){const t=e.trim();if(t==="")return"";if(/^-?\d+(\.\d+)?$/.test(t)||t==="true"||t==="false"||t==="null")try{return JSON.parse(t)}catch{return e}return e}function ju(e){return!e||typeof e!="object"||Array.isArray(e)?[]:Object.entries(e).map(([t,n])=>({key:t,value:n$(n)}))}function na(e){const t={};for(const n of e){const o=n.key.trim();o!==""&&(t[o]=o$(n.value))}return t}function Hu(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.values(e).some(t=>t!==null&&typeof t=="object")}function r$(e){const t={};return typeof e.if=="string"&&e.if.trim().length>0&&(t.if=e.if),t}function i$(e,t){const n={...t},o=e.if;return typeof o=="string"&&o.trim().length>0?n.if=o:delete n.if,n}const s$=["api","static","route_params","query_params","websocket"],a$=["GET","POST","PUT","PATCH","DELETE"],l$=["none","optional","required"],d$=["progressive","blocking","background"],c$=["application/json","multipart/form-data"],u$=["public","private","presence"];function p$(e){if(!e||typeof e!="object")return{own:[],inherited:[]};const t=e.__editor,n=t&&typeof t=="object"&&!Array.isArray(t)?t.original:void 0,o=n&&typeof n=="object"&&!Array.isArray(n)?n.data_sources:e.data_sources,r=Array.isArray(o)?o.filter(c=>c&&typeof c=="object"):[],s=new Set(r.map(c=>typeof c.id=="string"?c.id:"").filter(Boolean)),a=e.data_sources,d=(Array.isArray(a)?a.filter(c=>c&&typeof c=="object"):[]).filter(c=>typeof c.id=="string"&&!s.has(c.id));return{own:r,inherited:d}}function f$(e,t){const n=(o,r="")=>typeof o=="string"?o:r;return{index:t,id:n(e.id),type:n(e.type,"api"),label_key:n(e.label_key),endpoint:n(e.endpoint),method:n(e.method,"GET"),auth_mode:n(e.auth_mode,"none"),loading_strategy:n(e.loading_strategy,"progressive"),auto_fetch:e.auto_fetch!==!1,paramRows:ju(e.params),paramsRaw:Hu(e.params),paramsRawValue:e.params&&typeof e.params=="object"&&!Array.isArray(e.params)?e.params:{},paramsRawValid:!0,fallbackEnabled:e.fallback!==void 0,fallbackValue:e.fallback,if:n(e.if),contentType:n(e.contentType),refetchOnMount:e.refetchOnMount===!0,onSuccess:Array.isArray(e.onSuccess)?e.onSuccess.filter(o=>!!o&&typeof o=="object"):[],onError:Array.isArray(e.onError)?e.onError.filter(o=>!!o&&typeof o=="object"):[],errorHandling:e.errorHandling&&typeof e.errorHandling=="object"&&!Array.isArray(e.errorHandling)?e.errorHandling:{},channel:n(e.channel),event:n(e.event),channel_type:n(e.channel_type,"public"),target_source:n(e.target_source),onReceive:Array.isArray(e.onReceive)?e.onReceive.filter(o=>!!o&&typeof o=="object"):[]}}function g$(){return{index:-1,id:"",type:"api",label_key:"",endpoint:"",method:"GET",auth_mode:"none",loading_strategy:"progressive",auto_fetch:!0,paramRows:[],paramsRaw:!1,paramsRawValue:{},paramsRawValid:!0,fallbackEnabled:!1,fallbackValue:void 0,if:"",contentType:"",refetchOnMount:!1,onSuccess:[],onError:[],errorHandling:{},channel:"",event:"",channel_type:"public",target_source:"",onReceive:[]}}function h$(e,t,n,o){const r=e.id.trim();if(!r)return{error:o("layout_editor.data_sources.error.id_required")};if(!/^[A-Za-z_][\w]*$/.test(r))return{error:o("layout_editor.data_sources.error.id_invalid")};if(n.has(r))return{error:o("layout_editor.data_sources.error.id_duplicate",{id:r})};const s=t?{...t}:{};if(s.id=r,s.type=e.type,e.label_key.trim()?s.label_key=e.label_key.trim():delete s.label_key,e.type==="api"||e.type==="websocket"?(e.endpoint.trim()?s.endpoint=e.endpoint.trim():delete s.endpoint,s.method=e.method,s.auth_mode=e.auth_mode,s.loading_strategy=e.loading_strategy):(delete s.endpoint,delete s.method),s.auto_fetch=e.auto_fetch,e.paramsRaw){if(!e.paramsRawValid)return{error:o("layout_editor.data_sources.error.params_json")};const a=e.paramsRawValue;a&&typeof a=="object"&&Object.keys(a).length>0?s.params=a:delete s.params}else{const a=na(e.paramRows);Object.keys(a).length>0?s.params=a:delete s.params}return e.fallbackEnabled?s.fallback=e.fallbackValue===void 0?{}:e.fallbackValue:delete s.fallback,e.if.trim()?s.if=e.if.trim():delete s.if,e.type==="api"&&e.contentType?s.contentType=e.contentType:delete s.contentType,e.refetchOnMount?s.refetchOnMount=!0:delete s.refetchOnMount,e.onSuccess.length>0?s.onSuccess=e.onSuccess:delete s.onSuccess,e.onError.length>0?s.onError=e.onError:delete s.onError,Object.keys(e.errorHandling).length>0?s.errorHandling=e.errorHandling:delete s.errorHandling,e.type==="websocket"?(e.channel?s.channel=e.channel:delete s.channel,e.event?s.event=e.event:delete s.event,s.channel_type=e.channel_type,e.target_source?s.target_source=e.target_source:delete s.target_source,e.onReceive.length>0?s.onReceive=e.onReceive:delete s.onReceive):(delete s.channel,delete s.event,delete s.channel_type,delete s.target_source,delete s.onReceive),{entry:s}}const Ht={width:"100%",padding:"6px 8px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:6,outline:"none",boxSizing:"border-box",fontFamily:"inherit",color:"#0f172a",background:"#ffffff"},ct={display:"block",fontSize:12,fontWeight:600,color:"#475569",marginBottom:4},ut={marginBottom:12},an={padding:"6px 12px",fontSize:13,fontWeight:500,borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#0f172a",cursor:"pointer"},Fu={...an,background:"#2563eb",borderColor:"#2563eb",color:"#ffffff",fontWeight:600},Oo={marginTop:12,padding:10,border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc"},Bo={fontSize:12,fontWeight:700,color:"#475569",marginBottom:8},y$={margin:"0 0 6px",fontSize:11,color:"#94a3b8"},Ku={marginTop:8},Vu={alignSelf:"flex-start",padding:"2px 0",fontSize:11,border:"none",background:"none",color:"#64748b",cursor:"pointer"},Uu={margin:0,padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:11,lineHeight:1.5,overflow:"auto",fontFamily:"ui-monospace, monospace"};function b$({code:e,action:t,recipes:n,pools:o,t:r,onPatch:s}){const[a,l]=u.useState(!1),d=u.useMemo(()=>$o(n),[n]),c=Array.isArray(t)?t[0]:t,p=typeof c?.handler=="string"?c.handler:"",f=d.find(_=>_.id===p)??null,b=c?Jn(c,d):null,g=b?.kind==="preset"?b.values:{},m=p==="sequence"||p==="parallel",h=["","showErrorPage","navigate","openModal","toast","setState","sequence","parallel"],v=_=>{if(_===""){s({});return}const w=d.find(k=>k.id===_);s(w?Er(w,{}):{handler:_})},y=m&&c?Array.isArray(c.params?.actions)?c.params.actions:[]:[];return i.jsxs("div",{"data-testid":`g7le-ds-errorhandling-${e}`,style:{display:"flex",flexDirection:"column",gap:6},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[i.jsx("select",{"data-testid":`g7le-ds-eh-handler-${e}`,style:{...Ht,flex:1},value:p,onChange:_=>v(_.target.value),children:h.map(_=>i.jsx("option",{value:_,children:r(_===""?"layout_editor.error.handler_none":`layout_editor.error.handler_${_}`)},_))}),p!==""?i.jsx("button",{type:"button","data-testid":`g7le-ds-eh-code-${e}`,onClick:()=>l(_=>!_),"aria-label":r("layout_editor.action_list.view_code"),title:r("layout_editor.action_list.view_code"),style:a?m$:qu,children:""}):null]}),m?i.jsx("div",{"data-testid":`g7le-ds-eh-actions-${e}`,children:i.jsx(Yt,{actions:y,onChange:_=>s({handler:p,params:{actions:_}}),t:r,recipes:n,candidatePools:o,chipContext:"error",testIdPrefix:`g7le-ds-eh-seq-${e}`})}):f&&c?i.jsx(Os,{raw:c,recipe:f,values:g,t:r,pools:o,onChange:_=>s(_),testIdPrefix:`g7le-ds-eh-action-${e}-edit`}):null,a&&c?i.jsx("pre",{"data-testid":`g7le-ds-eh-code-view-${e}`,style:v$,children:JSON.stringify(t,null,2)}):null]})}const qu={flex:"0 0 auto",width:26,height:26,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:11,border:"1px solid #e2e8f0",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer",fontFamily:"ui-monospace, monospace"},m$={...qu,background:"#0f172a",borderColor:"#0f172a",color:"#e2e8f0"},v$={margin:"4px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:12,overflow:"auto",fontFamily:"ui-monospace, monospace"};function _$({raw:e,onChange:t,t:n,resolveLabel:o,onClose:r,actionRecipes:s,errorRecipes:a,conditionSpec:l,bindingCandidates:d,pageCandidates:c,dataSourceCandidates:p,stateKeyCandidates:f}){const b=o??n,g=u.useMemo(()=>p$(e),[e]),m=g.inherited,[h,v]=u.useState(g.own),[y,_]=u.useState(null),[w,k]=u.useState(null),[x,$]=u.useState(!1),[C,S]=u.useState(!1),[D,E]=u.useState(()=>new Set),I=u.useCallback(A=>{E(L=>{const F=new Set(L);return F.has(A)?F.delete(A):F.add(A),F})},[]),N=u.useMemo(()=>({pageCandidates:c,dataSourceCandidates:p,stateKeyCandidates:f,bindingCandidates:d}),[c,p,f,d]),T=u.useCallback(A=>{v(A),t([...m,...A],A)},[m,t]),B=u.useCallback(()=>{k(null),_(g$())},[]),M=u.useCallback((A,L)=>{k(null),_(f$(A,L))},[]),O=u.useCallback(A=>{const L=h.filter((F,Y)=>Y!==A);T(L)},[h,T]),z=u.useCallback(()=>{_(null),k(null)},[]),H=u.useCallback(()=>{if(!y)return;const A=new Set;h.forEach((V,X)=>{X!==y.index&&typeof V.id=="string"&&A.add(V.id)}),m.forEach(V=>{typeof V.id=="string"&&A.add(V.id)});const L=y.index>=0?h[y.index]??null:null,F=h$(y,L,A,n);if("error"in F){k(F.error);return}const Y=y.index>=0?h.map((V,X)=>X===y.index?F.entry:V):[...h,F.entry];T(Y),_(null),k(null)},[y,h,m,T,n]),P=y?.type==="api"||y?.type==="websocket";return i.jsxs("div",{className:"g7le-data-sources","data-testid":"g7le-data-sources-panel",style:{flex:"1 1 auto",minHeight:0,display:"flex",flexDirection:"column",fontSize:13,color:"#0f172a",boxSizing:"border-box"},children:[i.jsxs("div",{className:"g7le-data-sources__header",style:{flex:"0 0 auto",padding:"16px 16px 12px",borderBottom:"1px solid #e2e8f0"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[i.jsx("h2",{style:{margin:0,fontSize:16,fontWeight:700},children:n("layout_editor.data_sources.title")}),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-close",onClick:r,"aria-label":n("layout_editor.data_sources.close"),style:{...an,padding:"4px 10px"},children:"✕"})]}),i.jsx("p",{style:{margin:0,fontSize:12,color:"#64748b",lineHeight:1.5},children:n("layout_editor.data_sources.description")})]}),i.jsxs("div",{className:"g7le-data-sources__body",style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",padding:16},children:[y&&i.jsxs("div",{className:"g7le-data-sources__form","data-testid":"g7le-data-sources-form",children:[i.jsx("div",{style:{fontSize:13,fontWeight:700,marginBottom:12},children:y.index>=0?n("layout_editor.data_sources.form.edit_title"):n("layout_editor.data_sources.form.add_title")}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-id",children:n("layout_editor.data_sources.field.id")}),i.jsx("input",{id:"g7le-ds-id","data-testid":"g7le-data-sources-field-id",style:Ht,value:y.id,onChange:A=>_({...y,id:A.target.value}),placeholder:"products"})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-label",children:n("layout_editor.data_sources.field.label_key")}),i.jsx(_t,{value:y.label_key,onChange:A=>_({...y,label_key:A??""}),t:n,placeholder:n("layout_editor.data_sources.field.label_key_placeholder"),testidPrefix:"g7le-data-sources-field-label",candidates:d,enableExpressionTree:!0,expressionTreeCollapsible:!0}),i.jsx("div",{style:{fontSize:11,color:"#94a3b8",marginTop:4},children:n("layout_editor.data_sources.field.label_key_hint")})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-type",children:n("layout_editor.data_sources.field.type")}),i.jsx("select",{id:"g7le-ds-type","data-testid":"g7le-data-sources-field-type",style:Ht,value:y.type,onChange:A=>_({...y,type:A.target.value}),children:s$.map(A=>i.jsx("option",{value:A,children:n(`layout_editor.data_sources.ds_type.${A}`)},A))})]}),P&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.endpoint")}),i.jsx("div",{"data-testid":"g7le-data-sources-field-endpoint",children:i.jsx(Ke,{value:y.endpoint,onChange:A=>_({...y,endpoint:A}),t:n,candidates:d,placeholder:"/api/shop/products/{{route.id}}",testidPrefix:"g7le-ds-endpoint"})})]}),i.jsxs("div",{style:{display:"flex",gap:12},children:[i.jsxs("div",{style:{...ut,flex:1},children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-method",children:n("layout_editor.data_sources.field.method")}),i.jsx("select",{id:"g7le-ds-method","data-testid":"g7le-data-sources-field-method",style:Ht,value:y.method,onChange:A=>_({...y,method:A.target.value}),children:a$.map(A=>i.jsx("option",{value:A,children:A},A))})]}),i.jsxs("div",{style:{...ut,flex:1},children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-auth",children:n("layout_editor.data_sources.field.auth_mode")}),i.jsx("select",{id:"g7le-ds-auth","data-testid":"g7le-data-sources-field-auth",style:Ht,value:y.auth_mode,onChange:A=>_({...y,auth_mode:A.target.value}),children:l$.map(A=>i.jsx("option",{value:A,children:n(`layout_editor.data_sources.auth_mode.${A}`)},A))})]})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-loading",children:n("layout_editor.data_sources.field.loading_strategy")}),i.jsx("select",{id:"g7le-ds-loading","data-testid":"g7le-data-sources-field-loading",style:Ht,value:y.loading_strategy,onChange:A=>_({...y,loading_strategy:A.target.value}),children:d$.map(A=>i.jsx("option",{value:A,children:n(`layout_editor.data_sources.loading_strategy.${A}`)},A))})]}),y.type==="api"&&i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-contenttype",children:n("layout_editor.data_sources.field.content_type")}),i.jsx("select",{id:"g7le-ds-contenttype","data-testid":"g7le-ds-contenttype",style:Ht,value:y.contentType||"application/json",onChange:A=>_({...y,contentType:A.target.value}),children:c$.map(A=>i.jsx("option",{value:A,children:A},A))})]})]}),i.jsx("div",{style:ut,children:i.jsxs("label",{style:{...ct,display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[i.jsx("input",{type:"checkbox","data-testid":"g7le-data-sources-field-autofetch",checked:y.auto_fetch,onChange:A=>_({...y,auto_fetch:A.target.checked})}),n("layout_editor.data_sources.field.auto_fetch")]})}),i.jsx("div",{style:ut,children:i.jsxs("label",{style:{...ct,display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[i.jsx("input",{type:"checkbox","data-testid":"g7le-ds-refetch",checked:y.refetchOnMount,onChange:A=>_({...y,refetchOnMount:A.target.checked})}),n("layout_editor.data_sources.field.refetch_on_mount")]})}),i.jsxs("div",{style:ut,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i.jsx("label",{style:ct,htmlFor:"g7le-ds-params",children:n("layout_editor.data_sources.field.params")}),i.jsx("button",{type:"button","data-testid":"g7le-ds-params-mode-toggle",onClick:()=>{if(y.paramsRaw){if(y.paramsRawValid){const A=y.paramsRawValue;A&&typeof A=="object"&&!Array.isArray(A)&&!Hu(A)&&_({...y,paramsRaw:!1,paramRows:ju(A)})}}else{const A=na(y.paramRows);_({...y,paramsRaw:!0,paramsRawValue:A,paramsRawValid:!0})}},style:{...an,padding:"2px 8px",fontSize:11},children:y.paramsRaw?n("layout_editor.data_sources.field.params_mode_block"):n("layout_editor.data_sources.field.params_mode_code")})]}),y.paramsRaw?i.jsx(Us,{id:"g7le-ds-params",value:y.paramsRawValue,shape:"object",emptyValue:{},minHeight:64,testidPrefix:"g7le-data-sources-field-params",placeholder:`{ "page": "{{query.page ?? 1}}" }`,shapeErrorKey:"layout_editor.data_sources.error.params_object",invalidErrorKey:"layout_editor.data_sources.error.params_json",t:n,onChange:A=>_(L=>L&&{...L,paramsRawValue:A??{},paramsRawValid:!0}),onValidityChange:A=>_(L=>L&&{...L,paramsRawValid:A})}):i.jsxs("div",{"data-testid":"g7le-data-sources-field-params",children:[y.paramRows.length===0&&i.jsx("p",{"data-testid":"g7le-ds-params-empty",style:y$,children:n("layout_editor.data_sources.field.params_empty")}),i.jsx(Wr,{value:y.paramRows.map(A=>({key:A.key,value:A.value})),onChange:A=>_({...y,paramRows:A.map(L=>({key:L.key??"",value:L.value??""}))}),keyField:"key",valueField:"value",t:n,candidates:d,testidPrefix:"g7le-ds-params-kv",keyPlaceholder:n("layout_editor.data_sources.field.param_key_placeholder"),valuePlaceholder:"{{query.page ?? 1}}",addLabel:n("layout_editor.data_sources.field.param_add")}),(()=>{const A=na(y.paramRows);return Object.keys(A).length===0?null:i.jsxs("div",{style:Ku,children:[i.jsxs("button",{type:"button","data-testid":"g7le-ds-params-preview-toggle","aria-expanded":x,onClick:()=>$(L=>!L),style:Vu,children:[x?"▴":"▾"," ",n("layout_editor.data_sources.field.params_preview")]}),x&&i.jsx("pre",{"data-testid":"g7le-ds-params-preview",style:{...Uu,marginTop:4},children:JSON.stringify(A,null,2)})]})})()]}),i.jsx("div",{style:{fontSize:11,color:"#94a3b8",marginTop:4},children:n("layout_editor.data_sources.field.params_hint")})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.fallback")}),y.fallbackEnabled?i.jsxs("div",{"data-testid":"g7le-data-sources-field-fallback",style:{display:"flex",flexDirection:"column",gap:6},children:[i.jsx(Mn,{value:y.fallbackValue===void 0?{}:y.fallbackValue,onChange:A=>_({...y,fallbackValue:A}),t:n,path:"fallback",scope:"ds-fallback",renderStringLeaf:A=>i.jsx(Ke,{value:A.value,onChange:A.onChange,t:n,candidates:d,testidPrefix:A.testidPrefix})}),(()=>{const A=y.fallbackValue===void 0?{}:y.fallbackValue;return i.jsxs("div",{style:Ku,children:[i.jsxs("button",{type:"button","data-testid":"g7le-ds-fallback-preview-toggle","aria-expanded":C,onClick:()=>S(L=>!L),style:Vu,children:[C?"▴":"▾"," ",n("layout_editor.data_sources.field.fallback_preview")]}),C&&i.jsx("pre",{"data-testid":"g7le-ds-fallback-preview",style:{...Uu,marginTop:4},children:JSON.stringify(A,null,2)})]})})(),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-field-fallback-clear",onClick:()=>_({...y,fallbackEnabled:!1,fallbackValue:void 0}),style:{...an,padding:"2px 8px",fontSize:11,alignSelf:"flex-start",color:"#dc2626",borderColor:"#fecaca"},children:n("layout_editor.data_sources.field.fallback_clear")})]}):i.jsxs("button",{type:"button","data-testid":"g7le-data-sources-field-fallback-add",onClick:()=>_({...y,fallbackEnabled:!0,fallbackValue:{}}),style:{...an,padding:"4px 10px",display:"block"},children:["+ ",n("layout_editor.data_sources.field.fallback_add")]})]}),y.type==="websocket"&&i.jsxs("div",{"data-testid":"g7le-ds-ws-section",style:Oo,children:[i.jsx("div",{style:Bo,children:n("layout_editor.data_sources.section.websocket")}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.channel")}),i.jsx("input",{"data-testid":"g7le-ds-ws-channel",style:Ht,value:y.channel,onChange:A=>_({...y,channel:A.target.value}),placeholder:"core.admin.dashboard"})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.event")}),i.jsx("input",{"data-testid":"g7le-ds-ws-event",style:Ht,value:y.event,onChange:A=>_({...y,event:A.target.value}),placeholder:"dashboard.stats.updated"})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.channel_type")}),i.jsx("select",{"data-testid":"g7le-ds-ws-channeltype",style:Ht,value:y.channel_type,onChange:A=>_({...y,channel_type:A.target.value}),children:u$.map(A=>i.jsx("option",{value:A,children:A},A))})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.target_source")}),i.jsx("input",{"data-testid":"g7le-ds-ws-target",style:Ht,value:y.target_source,onChange:A=>_({...y,target_source:A.target.value}),list:"g7le-ds-ws-target-list"}),i.jsx("datalist",{id:"g7le-ds-ws-target-list",children:h.filter(A=>A.id!==y.id).map(A=>typeof A.id=="string"?i.jsx("option",{value:A.id},A.id):null)})]}),i.jsxs("div",{style:ut,children:[i.jsx("label",{style:ct,children:n("layout_editor.data_sources.field.on_receive")}),i.jsx("div",{"data-testid":"g7le-ds-ws-onreceive",children:i.jsx(Yt,{actions:y.onReceive,onChange:A=>_({...y,onReceive:A}),t:n,recipes:s,candidatePools:N,chipContext:"payload",actionChipCandidates:l?.actionChipCandidates??null,testIdPrefix:"g7le-ds-onreceive-list"})})]})]}),i.jsxs("div",{style:Oo,children:[i.jsx("div",{style:Bo,children:n("layout_editor.data_sources.section.on_success")}),i.jsx("div",{"data-testid":"g7le-ds-onsuccess",children:i.jsx(Yt,{actions:y.onSuccess,onChange:A=>_({...y,onSuccess:A}),t:n,recipes:s,candidatePools:N,chipContext:"response",actionChipCandidates:l?.actionChipCandidates??null,testIdPrefix:"g7le-ds-onsuccess-list"})})]}),i.jsxs("div",{style:Oo,children:[i.jsx("div",{style:Bo,children:n("layout_editor.data_sources.section.on_error")}),i.jsx("div",{"data-testid":"g7le-ds-onerror",children:i.jsx(Yt,{actions:y.onError,onChange:A=>_({...y,onError:A}),t:n,recipes:s,candidatePools:N,chipContext:"error",actionChipCandidates:l?.actionChipCandidates??null,testIdPrefix:"g7le-ds-onerror-list"})})]}),i.jsxs("div",{style:Oo,children:[i.jsx("div",{style:Bo,children:n("layout_editor.data_sources.section.error_handling")}),i.jsxs("div",{"data-testid":"g7le-ds-errorhandling",children:[i.jsx(Xs,{value:y.errorHandling,onChange:A=>_({...y,errorHandling:A}),t:n,mode:"local",testIdPrefix:"g7le-ds-eh",renderActionList:(A,L,F)=>i.jsx(b$,{code:A,action:L,recipes:a,pools:N,t:n,onPatch:F})}),i.jsxs("button",{type:"button","data-testid":"g7le-ds-errorhandling-add",onClick:()=>{const A=Object.keys(y.errorHandling),L=["403","404","500","422","default"].find(F=>!A.includes(F))??"default";_({...y,errorHandling:{...y.errorHandling,[L]:{handler:"toast"}}})},style:{...an,padding:"4px 10px",marginTop:6},children:["+ ",n("layout_editor.data_sources.add_error_code")]})]})]}),i.jsxs("div",{style:Oo,children:[i.jsx("div",{style:Bo,children:n("layout_editor.data_sources.section.load_condition")}),i.jsx("div",{"data-testid":"g7le-ds-loadcondition",children:i.jsx(Ou,{node:r$({if:y.if||void 0}),spec:l??null,t:n,dataSourceCandidates:p,stateKeyCandidates:f,onPatchNode:A=>{const L=i$(A,{});_({...y,if:typeof L.if=="string"?L.if:""})}})})]})]}),!y&&i.jsxs("button",{type:"button","data-testid":"g7le-data-sources-add",onClick:B,style:{...Fu,marginBottom:16},children:["+ ",n("layout_editor.data_sources.add")]}),i.jsxs("div",{className:"g7le-data-sources__list","data-testid":"g7le-data-sources-list",style:{display:"flex",flexDirection:"column",gap:8},children:[h.length===0&&!y&&i.jsx("div",{"data-testid":"g7le-data-sources-empty",style:{fontSize:12,color:"#94a3b8",padding:"12px 0",textAlign:"center"},children:n("layout_editor.data_sources.empty")}),h.map((A,L)=>{const F=typeof A.id=="string"?A.id:`#${L}`,Y=typeof A.endpoint=="string"?A.endpoint:"",V=typeof A.label_key=="string"?A.label_key:"",X=us(A,b);return i.jsxs("div",{"data-testid":"g7le-data-sources-item","data-ds-id":F,style:{border:"1px solid #e2e8f0",borderRadius:8,padding:"10px 12px",display:"flex",alignItems:"center",gap:8,background:"#ffffff"},children:[i.jsxs("div",{style:{flex:1,minWidth:0},children:[i.jsxs("div",{"data-testid":"g7le-data-sources-item-title",style:{fontWeight:600,fontSize:13,display:"flex",alignItems:"baseline",gap:6,flexWrap:"wrap"},children:[i.jsx("span",{children:X??F}),X&&i.jsx("span",{"data-testid":"g7le-data-sources-item-id",style:{fontSize:11,fontWeight:400,color:"#94a3b8"},children:F}),(()=>{const Z=ps(A,n);return Z?i.jsx("span",{"data-testid":"g7le-data-sources-ext-badge",style:{fontSize:10,fontWeight:600,color:"#7c3aed",background:"#f5f3ff",border:"1px solid #ddd6fe",borderRadius:4,padding:"1px 6px"},children:Z}):null})()]}),Y&&i.jsx("div",{style:{fontSize:11,color:"#94a3b8",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Y}),!V&&i.jsx("div",{"data-testid":"g7le-data-sources-nolabel",style:{fontSize:11,color:"#f59e0b"},children:n("layout_editor.data_sources.no_label")})]}),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-edit",onClick:()=>M(A,L),style:{...an,padding:"4px 10px"},children:n("layout_editor.data_sources.edit")}),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-remove",onClick:()=>O(L),style:{...an,padding:"4px 10px",color:"#dc2626",borderColor:"#fecaca"},children:n("layout_editor.data_sources.remove")})]},`${F}-${L}`)})]}),m.length>0&&i.jsxs("div",{style:{marginTop:16},children:[i.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#64748b",textTransform:"uppercase",letterSpacing:.4,marginBottom:8},children:n("layout_editor.data_sources.inherited_title")}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:m.map((A,L)=>{const F=typeof A.id=="string"?A.id:`#${L}`,Y=D.has(F),V=[],X=(Z,ie)=>{const oe=A[Z];oe!=null&&V.push([ie,typeof oe=="object"?JSON.stringify(oe):String(oe)])};return X("type",n("layout_editor.data_sources.field.type")),X("endpoint",n("layout_editor.data_sources.field.endpoint")),X("method",n("layout_editor.data_sources.field.method")),X("auth_mode",n("layout_editor.data_sources.field.auth_mode")),X("loading_strategy",n("layout_editor.data_sources.field.loading_strategy")),X("auto_fetch",n("layout_editor.data_sources.field.auto_fetch")),X("params",n("layout_editor.data_sources.field.params")),i.jsxs("div",{"data-testid":"g7le-data-sources-inherited-item","data-ds-id":F,"data-expanded":Y?"true":"false",style:{border:"1px dashed #e2e8f0",borderRadius:6,fontSize:12,color:"#64748b",background:"#f8fafc",overflow:"hidden"},children:[i.jsxs("button",{type:"button","data-testid":"g7le-data-sources-inherited-toggle",onClick:()=>I(F),"aria-expanded":Y,style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 12px",background:"transparent",border:"none",cursor:"pointer",color:"inherit",fontSize:12,textAlign:"left",outline:"none"},children:[i.jsx("span",{style:{flex:"0 0 auto",width:12,transition:"transform 120ms",transform:Y?"rotate(90deg)":"none"},children:"▶"}),(()=>{const Z=us(A,b),ie=ps(A,n);return i.jsxs("span",{style:{flex:1,display:"inline-flex",alignItems:"baseline",gap:6,flexWrap:"wrap"},children:[i.jsx("span",{style:{fontWeight:600},children:Z??F}),Z&&i.jsx("span",{style:{fontSize:11,fontWeight:400,color:"#94a3b8"},children:F}),ie&&i.jsx("span",{"data-testid":"g7le-data-sources-ext-badge",style:{fontSize:10,fontWeight:600,color:"#7c3aed",background:"#f5f3ff",border:"1px solid #ddd6fe",borderRadius:4,padding:"1px 6px"},children:ie})]})})()]}),Y&&i.jsxs("div",{"data-testid":"g7le-data-sources-inherited-info",style:{padding:"0 12px 10px 32px",display:"flex",flexDirection:"column",gap:3},children:[V.length===0&&i.jsx("span",{style:{color:"#94a3b8"},children:"—"}),V.map(([Z,ie])=>i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsxs("span",{style:{flex:"0 0 auto",color:"#94a3b8"},children:[Z,":"]}),i.jsx("span",{style:{flex:1,minWidth:0,wordBreak:"break-all",color:"#475569"},children:ie})]},Z))]})]},`inh-${F}-${L}`)})})]})]}),y&&i.jsxs("div",{className:"g7le-data-sources__footer",style:{flex:"0 0 auto",padding:"12px 16px",borderTop:"1px solid #e2e8f0",background:"#ffffff"},children:[w&&i.jsx("div",{"data-testid":"g7le-data-sources-form-error",role:"alert",style:{fontSize:12,color:"#dc2626",marginBottom:10},children:w}),i.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[i.jsx("button",{type:"button","data-testid":"g7le-data-sources-form-cancel",onClick:z,style:an,children:n("layout_editor.data_sources.form.cancel")}),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-form-submit",onClick:H,style:Fu,children:n("layout_editor.data_sources.form.save")})]})]})]})}function x$(e){const t=e?.globalHeaders;return Array.isArray(t)?t:[]}function w$(e){const t=e?.scripts;return Array.isArray(t)?t:[]}function k$(e){const t=x$(e.raw),n=w$(e.raw);return i.jsxs("div",{className:"g7le-data-source-tab","data-testid":"g7le-data-source-tab",style:S$,children:[i.jsx(_$,{...e}),i.jsxs("div",{style:Gu,"data-testid":"g7le-global-headers",children:[i.jsx("div",{style:Yu,children:e.t("layout_editor.data_sources.global_headers")}),t.length===0?i.jsx("p",{"data-testid":"g7le-global-header-empty",style:Ru,children:e.t("layout_editor.data_sources.global_headers_empty")}):t.map((o,r)=>i.jsxs("div",{"data-testid":`g7le-global-header-${r}`,style:Xu,children:[i.jsx("code",{style:Ju,children:o.pattern??"*"}),i.jsx("span",{style:C$,children:"→"}),i.jsx("span",{style:Zu,children:Object.keys(o.headers??{}).join(", ")})]},r)),i.jsxs("p",{style:Qu,children:["ⓘ ",e.t("layout_editor.data_sources.global_headers_hint")]})]}),i.jsxs("div",{style:Gu,"data-testid":"g7le-scripts",children:[i.jsx("div",{style:Yu,children:e.t("layout_editor.data_sources.scripts")}),n.length===0?i.jsx("p",{"data-testid":"g7le-script-empty",style:Ru,children:e.t("layout_editor.data_sources.scripts_empty")}):n.map((o,r)=>i.jsxs("div",{"data-testid":`g7le-script-${o.id??r}`,style:Xu,children:[i.jsx("code",{style:Ju,children:o.id??`#${r}`}),i.jsx("span",{style:Zu,children:o.src??""}),o.loading?i.jsx("span",{style:$$,children:o.loading}):null]},o.id??r)),i.jsxs("p",{style:Qu,children:["ⓘ ",e.t("layout_editor.data_sources.scripts_hint")]})]})]})}const S$={display:"flex",flexDirection:"column",gap:16,minWidth:0},Gu={borderTop:"1px solid #e2e8f0",paddingTop:12,display:"flex",flexDirection:"column",gap:6},Yu={fontSize:12,fontWeight:700,color:"#475569"},Xu={display:"flex",alignItems:"center",gap:8,fontSize:12,padding:"4px 8px",border:"1px solid #f1f5f9",borderRadius:6},Ju={fontSize:11,color:"#0f172a",fontFamily:"monospace"},C$={color:"#94a3b8"},Zu={flex:1,minWidth:0,color:"#475569",wordBreak:"break-all"},$$={fontSize:10,color:"#64748b",background:"#f1f5f9",borderRadius:4,padding:"0 4px"},Qu={margin:0,fontSize:11,color:"#94a3b8"},Ru={margin:0,fontSize:12,color:"#94a3b8"},E$=["meta","seo","init","overlay","computed","state","error","data"],I$=["401","403","404","500","503"],A$={meta:"layout_editor.page_settings.tab.meta",seo:"layout_editor.page_settings.tab.seo",init:"layout_editor.page_settings.tab.init",overlay:"layout_editor.page_settings.tab.overlay",computed:"layout_editor.page_settings.tab.computed",state:"layout_editor.page_settings.tab.state",error:"layout_editor.page_settings.tab.error",data:"layout_editor.page_settings.tab.data"};async function T$(e){if(typeof fetch!="function"||!e)return[];try{const t=await fetch(nn(`/api/admin/templates/${encodeURIComponent(e)}/editor/seo-candidates`,"json"),{credentials:"same-origin",headers:Me()});if(!t.ok)return[];const o=(await t.json().catch(()=>null))?.data?.extensions;if(!Array.isArray(o))return[];const r=[];for(const s of o)if(s&&typeof s=="object"){const a=s.type,l=s.id,d=s.label;typeof a=="string"&&typeof l=="string"&&l.length>0&&r.push({type:a,id:l,name:typeof d=="string"?d:l})}return r}catch{return[]}}function D$(e,t){let n=0;for(const o of e)Jn(o,t).kind==="advanced"&&(n+=1);return n}function z$(e,t){let n=0;for(const o of Object.keys(e))Ld(e[o],t).kind==="advanced"&&(n+=1);return n}function N$(e,t,n){const o=e("meta",{})??{},r=o.title;if(typeof r=="string"&&r.length>0){if(r.startsWith("$t:")){const a=n(r.slice(3));if(a&&a!==r.slice(3))return a}else if(!/\{\{[\s\S]*\}\}/.test(r))return r}const s=o.editor_label;return typeof s=="string"&&s.length>0?s.startsWith("$t:")?n(s.slice(3)):s:t||""}function M$({templateIdentifier:e,spec:t,t:n,resolveLabel:o,permissionCandidates:r,onClose:s,initialTab:a="meta",extensionsFetcher:l}){const{state:d}=Qe(),{raw:c,getValue:p,patch:f}=ov(),[b,g]=u.useState(a),m=d.selectedRoute?.path??"",h=u.useMemo(()=>Hd(d.routeTree,o),[d.routeTree,o]),v=u.useMemo(()=>Fd(c),[c]),y=u.useMemo(()=>Kd(t),[t]),_=u.useMemo(()=>wv(c,o),[c,o]),w=jd({raw:c,spec:t}),k=u.useMemo(()=>Cb(t),[t]),x=u.useMemo(()=>$b(t),[t]),$=u.useMemo(()=>Eb(t),[t]),C=u.useMemo(()=>Ib(t),[t]),S=u.useMemo(()=>$o(k),[k]),D=u.useMemo(()=>Ad(x),[x]),E=p("init_actions",void 0)??p("initActions",[]),I=p("computed",{}),N=p("__computedSource",{}),T=p("errorHandling",{}),B=p("transition_overlay",void 0),M=(p("__editor",{})??{}).original,O=u.useMemo(()=>{if(M===void 0)return;const G=M.transition_overlay;return G&&typeof G=="object"&&!Array.isArray(G)?G:{}},[M]),z=u.useMemo(()=>{const G=B;if(!G||typeof G!="object"||Array.isArray(G))return;const ee=O??{},fe={};for(const[K,te]of Object.entries(G))K in ee||(fe[K]=te);return Object.keys(fe).length>0?fe:void 0},[B,O]),[H,P]=u.useState([]);u.useEffect(()=>{let G=!1;const ee=l??T$;return(async()=>{const fe=await ee(e);G||P(fe)})(),()=>{G=!0}},[e,l]);const A=(p("meta",{})??{}).seo?.page_type,L=_v({raw:c,spec:t,pageType:typeof A=="string"?A:null}),F=u.useMemo(()=>vv(c,t),[c,t]),Y=u.useMemo(()=>({meta:0,seo:0,init:D$(E,S),overlay:0,computed:z$(I,D),state:0,error:0,data:0}),[E,S,I,D]),V=u.useMemo(()=>Object.values(Y).reduce((G,ee)=>G+ee,0),[Y]),X=u.useMemo(()=>xv(c,o,n),[c,o,n]),Z=u.useCallback(G=>{const fe={...M?.computed??{}};delete fe[G];const K={...I};delete K[G],f("computed",K,Object.keys(fe).length===0?void 0:fe)},[M,I,f]),ie=N$(p,m,n),oe=()=>{switch(b){case"meta":return i.jsx(jx,{getValue:p,patch:f,t:n,fieldT:o,spec:t,permissionCandidates:r,bindingCandidates:w});case"seo":return i.jsx($0,{getValue:p,patch:f,t:n,templateIdentifier:e,candidates:L,availableExtensions:H,dataSourceOptions:X,previewUrl:m||"/",seedContext:F});case"init":return i.jsx(qk,{actions:E,onChange:G=>f("init_actions",G),recipes:k,t:o,bindingCandidates:w,pageCandidates:h,dataSourceCandidates:v,stateKeyCandidates:y,modalCandidates:_});case"overlay":return i.jsx(h1,{value:B,ownValue:O,baseValue:z,patch:G=>f("transition_overlay",G),t:o,loadingComponents:C,progressiveDataSources:X,bindingCandidates:w});case"computed":return i.jsx(oS,{computed:I,onChange:G=>f("computed",G),recipes:x,t:o,sampleContext:F,dataSourceCandidates:v,bindingCandidates:w,computedSource:N,onRevert:Z});case"state":return i.jsx(BS,{raw:c,own:M?{initLocal:M.initLocal,initGlobal:M.initGlobal,initIsolated:M.initIsolated,state:M.state}:void 0,patch:f,t:n});case"error":return i.jsx(cC,{value:T,onChange:G=>f("errorHandling",G),t:o,errorConfigCodes:I$,templateCodes:Object.keys(T),ownCodes:Object.keys(M?.errorHandling??{}),recipes:$,pageCandidates:h,modalCandidates:_,dataSourceCandidates:v,stateKeyCandidates:y});case"data":return i.jsx(k$,{raw:c,t:n,resolveLabel:o,onChange:(G,ee)=>f("data_sources",G,ee),onClose:s,actionRecipes:k,errorRecipes:$,conditionSpec:t,bindingCandidates:w,pageCandidates:h,dataSourceCandidates:v,stateKeyCandidates:y});default:return i.jsx("div",{})}};return i.jsxs("div",{className:"g7le-page-settings","data-testid":"g7le-page-settings",style:L$,children:[i.jsxs("div",{style:P$,children:[i.jsx("span",{"data-testid":"g7le-page-settings-title",style:O$,children:n("layout_editor.page_settings.title",{name:ie})}),i.jsx("button",{type:"button","data-testid":"g7le-page-settings-close-x",onClick:s,"aria-label":n("layout_editor.page_settings.close"),style:B$,children:"✕"})]}),i.jsx("div",{role:"tablist",style:W$,children:E$.map(G=>{const ee=Y[G];return i.jsxs("button",{type:"button",role:"tab","aria-selected":b===G,"data-testid":`g7le-page-settings-tab-${G}`,"data-active":b===G?"true":"false",onClick:()=>g(G),style:b===G?j$:ep,children:[n(A$[G]),ee>0?i.jsxs("span",{"data-testid":`g7le-page-settings-tab-badge-${G}`,style:H$,children:["(",ee,")"]}):null]},G)})}),V>0?i.jsxs("p",{"data-testid":"g7le-page-settings-advanced-summary",style:F$,children:["⚠ ",n("layout_editor.page_settings.advanced_summary",{count:V})," ⓘ"]}):null,i.jsx("div",{"data-testid":"g7le-page-settings-panel",style:K$,children:oe()}),i.jsx("div",{style:V$,children:i.jsx("button",{type:"button","data-testid":"g7le-page-settings-close",onClick:s,style:U$,children:n("layout_editor.page_settings.close")})})]})}const L$={display:"flex",flexDirection:"column",minWidth:0,maxWidth:"100%",padding:"20px 24px",boxSizing:"border-box",flex:1,minHeight:0,maxHeight:"100%",overflow:"hidden",fontFamily:"system-ui, -apple-system, sans-serif"},P$={display:"flex",alignItems:"center",gap:8,paddingBottom:8,borderBottom:"1px solid #e2e8f0"},O$={flex:1,fontSize:15,fontWeight:700,color:"#0f172a",minWidth:0},B$={border:"none",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:16,lineHeight:1,padding:4},W$={display:"flex",gap:2,paddingTop:8,borderBottom:"1px solid #e2e8f0",flexWrap:"nowrap",overflowX:"auto",overflowY:"hidden",flexShrink:0,minWidth:0},ep={border:"none",borderBottomWidth:"2px",borderBottomStyle:"solid",borderBottomColor:"transparent",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:12,padding:"6px 10px",whiteSpace:"nowrap"},j$={...ep,color:"#2563eb",borderBottomColor:"#2563eb",fontWeight:600},H$={marginLeft:4,fontSize:10,color:"#b45309"},F$={margin:0,marginTop:8,fontSize:11,color:"#b45309",background:"#fffbeb",padding:"6px 8px",borderRadius:6},K$={flex:1,overflowY:"auto",paddingTop:12,minWidth:0,minHeight:0},V$={display:"flex",justifyContent:"flex-end",paddingTop:8,borderTop:"1px solid #e2e8f0"},U$={border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",fontSize:13,padding:"6px 16px"};function oa(e,t){const n=`/api/admin/templates/${encodeURIComponent(e)}`;return t.kind==="layout"?`${n}/layouts/${t.layoutName}/versions`:`${n}/layout-extensions/${encodeURIComponent(t.extensionId)}/versions`}const tp=100,np=500;function q$(e,t,n){const[o,r]=u.useState([]),[s,a]=u.useState(!1),[l,d]=u.useState(!1),[c,p]=u.useState(null),[f,b]=u.useState(null),[g,m]=u.useState(tp),[h,v]=u.useState(!1),y=u.useCallback(async($,C)=>{if(!t){r([]),p(null),v(!1);return}C==="more"?d(!0):a(!0),p(null);try{const S=`${oa(e,t)}?limit=${$}`,D=await fetch(S,{credentials:"same-origin",headers:Me()}),E=await D.json().catch(()=>null);if(!D.ok){p(E?.message??`HTTP ${D.status}`),C==="reload"&&r([]);return}const I=E?.data,N=Array.isArray(I)?I:[];r(N),v(N.length>=$&&${await y(g,"reload")},[y,g]),w=u.useCallback(async()=>{const $=Math.min(g+tp,np);if($<=g){v(!1);return}await y($,"more")},[y,g]),k=u.useCallback(async $=>{if(!t)return{kind:"not_found"};b($);try{const C=`${oa(e,t)}/${$}/restore`,S=await fetch(C,{method:"POST",credentials:"same-origin",headers:Me({"Content-Type":"application/json"})}),D=await S.json().catch(()=>null);if(S.status===404)return{kind:"not_found"};if(!S.ok)return{kind:"network_error",message:D?.message??`HTTP ${S.status}`};const E=typeof D?.data?.version=="number"?D.data.version:-1;return await n?.(E>=0?E:void 0),{kind:"success",newVersion:E}}catch(C){return{kind:"network_error",message:C instanceof Error?C.message:"network error"}}finally{b(null)}},[e,t,n]),x=u.useCallback(async $=>{if(!t)return{kind:"not_found"};try{const C=`${oa(e,t)}/${$}`,S=await fetch(C,{credentials:"same-origin",headers:Me()}),D=await S.json().catch(()=>null);if(S.status===404)return{kind:"not_found"};if(!S.ok)return{kind:"network_error",message:D?.message??`HTTP ${S.status}`};const E=D?.data;if(!E)return{kind:"not_found"};if(t.kind==="extension"&&!E.full_content){const I=E.content;if(typeof I=="string")try{const N=JSON.parse(I);N&&typeof N=="object"&&(E.full_content=N)}catch{}}return{kind:"success",detail:E}}catch(C){return{kind:"network_error",message:C instanceof Error?C.message:"network error"}}},[e,t]);return{versions:o,isLoading:s,isLoadingMore:l,error:c,restoringId:f,hasMore:h,loadVersions:_,loadMore:w,restore:k,loadVersionDetail:x}}function G$(e,t){const n=e.length,o=t.length,r=Array.from({length:n+1},()=>new Array(o+1).fill(0));for(let s=n-1;s>=0;s--)for(let a=o-1;a>=0;a--)e[s]===t[a]?r[s][a]=r[s+1][a+1]+1:r[s][a]=Math.max(r[s+1][a],r[s][a+1]);return r}function Y$(e,t,n){const o=[];let r=0,s=0;const a=e.length,l=t.length;for(;r=n[r][s+1]?(o.push({kind:"remove",oldIndex:r,content:e[r]}),r++):(o.push({kind:"add",newIndex:s,content:t[s]}),s++);for(;r0&&t[t.length-1]===""&&t.pop(),t}const rp=4e3;function X$(e,t,n=3){const o=op(e),r=op(t);let s=0;const a=Math.min(o.length,r.length);for(;srp||p.length>rp)return{hunks:[],addedCount:-1,removedCount:-1,identical:!1};const f=G$(c,p),b=Y$(c,p,f),g=[];let m=s,h=s,v=0,y=0;for(let k=0;k{const s=e.slice(r.start,r.end+1);let a=0,l=0,d=0,c=0;for(const g of s)g.oldLine!==null&&(a===0&&(a=g.oldLine),d++),g.newLine!==null&&(l===0&&(l=g.newLine),c++);const p=a||(d===0?0:1),f=l||(c===0?0:1);return{header:`@@ -${p},${d} +${f},${c} @@`,oldStart:p,oldCount:d,newStart:f,newCount:c,lines:s}})}function ip(e){return JSON.stringify(ra(e),null,2)}function ra(e){if(Array.isArray(e))return e.map(ra);if(e&&typeof e=="object"){const t=e,n={};for(const o of Object.keys(t).sort())n[o]=ra(t[o]);return n}return e}const Z$={display:"flex",flexDirection:"column",height:"100%",minHeight:0},Q$={display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc"},R$={display:"inline-flex",alignItems:"center",gap:4,padding:"4px 10px",borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#0f172a",fontSize:12,fontWeight:600,cursor:"pointer",outline:"none"},eE={marginLeft:"auto",border:"none",background:"transparent",fontSize:16,color:"#64748b",cursor:"pointer",outline:"none"},tE={display:"flex",alignItems:"center",gap:12,padding:"8px 16px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",fontSize:12,fontWeight:600},nE={flex:1,minHeight:0,overflow:"auto",background:"#ffffff",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:12,lineHeight:1.5},sp={padding:"24px 12px",textAlign:"center",color:"#94a3b8",fontSize:13},oE={padding:"2px 12px",background:"#f1f5f9",color:"#64748b",borderTop:"1px solid #e2e8f0",borderBottom:"1px solid #e2e8f0",userSelect:"none"};function rE(e){return e==="add"?{row:{background:"#e6ffed"},gutter:{background:"#cdffd8",color:"#22863a"},sign:"+",signColor:"#22863a"}:e==="remove"?{row:{background:"#ffeef0"},gutter:{background:"#ffdce0",color:"#b31d28"},sign:"-",signColor:"#b31d28"}:{row:{background:"#ffffff"},gutter:{background:"#f8fafc",color:"#94a3b8"},sign:" ",signColor:"#94a3b8"}}const ap={display:"inline-block",width:44,textAlign:"right",padding:"0 6px",color:"#94a3b8",userSelect:"none",borderRight:"1px solid #e2e8f0",whiteSpace:"nowrap"};function iE({oldVersion:e,newVersion:t,oldContent:n,newContent:o,t:r,onBack:s,onClose:a}){const l=u.useMemo(()=>{const c=ip(n),p=ip(o);return X$(c,p)},[n,o]),d=l.addedCount<0;return i.jsxs("div",{className:"g7le-version-diff","data-testid":"g7le-version-diff",style:Z$,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:Q$,children:[i.jsxs("button",{type:"button",onClick:s,style:R$,"data-testid":"g7le-version-diff-back",children:["← ",r("layout_editor.version_history.diff_back")]}),i.jsx("span",{style:{fontSize:14,fontWeight:700},"data-testid":"g7le-version-diff-title",children:r("layout_editor.version_history.diff_title",{old:e,new:t})}),i.jsx("button",{type:"button","aria-label":r("layout_editor.version_history.close"),onClick:a,style:eE,"data-testid":"g7le-version-diff-close",children:"✕"})]}),!d&&i.jsxs("div",{style:tE,"data-testid":"g7le-version-diff-summary",children:[i.jsx("span",{style:{color:"#16a34a"},"data-testid":"g7le-version-diff-added",children:r("layout_editor.version_history.added",{count:Math.max(0,l.addedCount)})}),i.jsx("span",{style:{color:"#dc2626"},"data-testid":"g7le-version-diff-removed",children:r("layout_editor.version_history.removed",{count:Math.max(0,l.removedCount)})})]}),i.jsx("div",{style:nE,children:d?i.jsx("div",{style:sp,"data-testid":"g7le-version-diff-too-large",children:r("layout_editor.version_history.diff_too_large")}):l.identical?i.jsx("div",{style:sp,"data-testid":"g7le-version-diff-identical",children:r("layout_editor.version_history.diff_identical")}):l.hunks.map((c,p)=>i.jsxs("div",{"data-testid":`g7le-version-diff-hunk-${p}`,children:[i.jsx("div",{style:oE,"data-testid":`g7le-version-diff-hunk-header-${p}`,children:c.header}),c.lines.map((f,b)=>{const g=rE(f.kind);return i.jsxs("div",{style:{display:"flex",alignItems:"stretch",...g.row},"data-kind":f.kind,"data-testid":`g7le-version-diff-line-${p}-${b}`,children:[i.jsx("span",{style:{...ap,...g.gutter},"aria-hidden":"true",children:f.oldLine??""}),i.jsx("span",{style:{...ap,...g.gutter},"aria-hidden":"true",children:f.newLine??""}),i.jsx("span",{style:{display:"inline-block",width:16,textAlign:"center",color:g.signColor,userSelect:"none",fontWeight:700},"aria-hidden":"true",children:g.sign}),i.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",flex:1,padding:"0 4px"},children:f.content})]},b)})]},p))})]})}const sE={display:"flex",flexDirection:"column",height:"100%",minHeight:0},aE={display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc"},lE={marginLeft:"auto",border:"none",background:"transparent",fontSize:16,color:"#64748b",cursor:"pointer",outline:"none"},dE={flex:1,minHeight:0,overflowY:"auto",padding:12},lp={padding:"24px 12px",textAlign:"center",color:"#94a3b8",fontSize:13},cE={margin:"8px 16px 0",padding:"8px 12px",borderRadius:6,background:"#fef2f2",color:"#b91c1c",fontSize:12,border:"1px solid #fecaca"},uE={display:"flex",flexDirection:"column",gap:8},pE={display:"flex",alignItems:"center",gap:12,padding:"10px 12px",borderRadius:8,border:"1px solid #e2e8f0",background:"#ffffff"},fE={display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:44,padding:"2px 8px",borderRadius:999,background:"#eff6ff",color:"#1d4ed8",fontSize:12,fontWeight:700},gE={display:"inline-flex",alignItems:"center",padding:"1px 8px",borderRadius:999,background:"#0f172a",color:"#ffffff",fontSize:10,fontWeight:700,letterSpacing:.3},hE={display:"flex",alignItems:"center",gap:10,fontSize:11,fontWeight:600},yE={display:"flex",flexDirection:"column",gap:2,minWidth:0,flex:1},dp={padding:"6px 12px",borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#0f172a",fontSize:12,fontWeight:600,cursor:"pointer",outline:"none",whiteSpace:"nowrap"};function cp(e){return e.full_content&&typeof e.full_content=="object"?e.full_content:{endpoint:e.endpoint,components:e.components,data_sources:e.data_sources,metadata:e.metadata}}function bE(e){if(!e)return"";const t=Date.parse(e);if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}function mE({templateIdentifier:e,target:t,t:n,onRestored:o,onClose:r}){const{versions:s,isLoading:a,isLoadingMore:l,error:d,restoringId:c,hasMore:p,loadVersions:f,loadMore:b,restore:g,loadVersionDetail:m}=q$(e,t,o),[h,v]=u.useState(null),[y,_]=u.useState(null),[w,k]=u.useState(null);u.useEffect(()=>{f()},[f]);const x=u.useCallback(async S=>{v(null),k(S.version);try{const D=await m(S.version);if(D.kind!=="success"){v(D.kind==="not_found"?n("layout_editor.version_history.restore_not_found"):D.message);return}const E=S.version-1,I=s.some(T=>T.version===E);let N={};if(I){const T=await m(E);if(T.kind==="success")N=cp(T.detail);else if(T.kind==="network_error"){v(T.message);return}}_({oldVersion:I?E:0,newVersion:S.version,oldContent:N,newContent:cp(D.detail)})}finally{k(null)}},[m,s,n]),$=u.useCallback(async S=>{v(null);const D=n("layout_editor.version_history.restore_confirm");if(!(typeof window<"u"?window.confirm(D):!0))return;const I=await g(S);I.kind==="success"?r():I.kind==="not_found"?v(n("layout_editor.version_history.restore_not_found")):v(I.message)},[g,r,n]),C=h??d;return y?i.jsx(iE,{oldVersion:y.oldVersion,newVersion:y.newVersion,oldContent:y.oldContent,newContent:y.newContent,t:n,onBack:()=>_(null),onClose:r}):i.jsxs("div",{className:"g7le-version-history","data-testid":"g7le-version-history",style:sE,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:aE,children:[i.jsxs("span",{style:{fontSize:14,fontWeight:700},"data-testid":"g7le-version-history-title",children:["🕘 ",n("layout_editor.version_history.title")]}),i.jsx("button",{type:"button","aria-label":n("layout_editor.version_history.close"),onClick:r,style:lE,"data-testid":"g7le-version-history-close",children:"✕"})]}),C&&i.jsx("div",{style:cE,"data-testid":"g7le-version-history-error",children:C}),i.jsx("div",{style:dE,children:a?i.jsx("div",{style:lp,"data-testid":"g7le-version-history-loading",children:n("layout_editor.version_history.loading")}):s.length===0?i.jsx("div",{style:lp,"data-testid":"g7le-version-history-empty",children:n("layout_editor.version_history.empty")}):i.jsxs("div",{"data-testid":"g7le-version-history-list",style:uE,children:[s.map((S,D)=>{const E=S.changes_summary,I=E?.added_count??0,N=E?.removed_count??0,T=E?.char_diff??0,B=bE(S.created_at),M=c===S.id,O=D===0;return i.jsxs("div",{style:pE,"data-testid":`g7le-version-row-${S.id}`,children:[i.jsxs("span",{style:fE,"data-testid":`g7le-version-badge-${S.id}`,children:["v",S.version]}),i.jsxs("div",{style:yE,children:[i.jsxs("span",{style:{display:"flex",alignItems:"center",gap:8},children:[B&&i.jsx("span",{style:{fontSize:12,color:"#475569",fontWeight:600},children:B}),O&&i.jsx("span",{style:gE,"data-testid":`g7le-version-latest-${S.id}`,children:n("layout_editor.version_history.latest")})]}),i.jsxs("span",{style:hE,"data-testid":`g7le-version-summary-${S.id}`,children:[i.jsx("span",{style:{color:"#16a34a"},"data-testid":`g7le-version-added-${S.id}`,children:n("layout_editor.version_history.added",{count:I})}),i.jsx("span",{style:{color:"#dc2626"},"data-testid":`g7le-version-removed-${S.id}`,children:n("layout_editor.version_history.removed",{count:N})}),i.jsx("span",{style:{color:"#94a3b8",fontWeight:500},"data-testid":`g7le-version-chars-${S.id}`,children:n("layout_editor.version_history.chars",{diff:`${T>=0?"+":""}${T}`})})]}),i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},"data-testid":`g7le-version-author-${S.id}`,children:n("layout_editor.version_history.saved_by",{name:S.created_by_name??n("layout_editor.version_history.unknown_author")})})]}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[i.jsx("button",{type:"button",onClick:()=>void x(S),disabled:w!==null,style:{...dp,background:"#f8fafc",opacity:w!==null?.6:1},"data-testid":`g7le-version-compare-${S.id}`,children:w===S.version?n("layout_editor.version_history.comparing"):n("layout_editor.version_history.compare")}),!O&&i.jsx("button",{type:"button",onClick:()=>void $(S.id),disabled:M||c!==null,style:{...dp,opacity:M||c!==null?.6:1},"data-testid":`g7le-version-restore-${S.id}`,children:n(M?"layout_editor.version_history.restoring":"layout_editor.version_history.restore")})]})]},S.id)}),p&&i.jsx("button",{type:"button","data-testid":"g7le-version-history-load-more",style:vE,disabled:l,onClick:()=>{b()},children:n(l?"layout_editor.version_history.loading":"layout_editor.version_history.load_more")})]})})]})}const vE={width:"100%",marginTop:8,padding:"8px 12px",fontSize:12,color:"#475569",background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,cursor:"pointer"};function Wo(e){return`/api/admin/extensions/${encodeURIComponent(e.type)}/${encodeURIComponent(e.identifier)}/custom-assets`}function jo(e,t){const n=e?.message;return typeof n=="string"&&n!==""?n:`HTTP ${t}`}function _E(e){const[t,n]=u.useState([]),[o,r]=u.useState(null),[s,a]=u.useState(!1),[l,d]=u.useState(!1),[c,p]=u.useState(null),f=u.useCallback(async()=>{a(!0),p(null);try{const v=await fetch(Wo(e),{credentials:"same-origin",headers:Me()}),y=await v.json().catch(()=>null);if(v.status===401||v.status===403){d(!0),n([]);return}if(d(!1),!v.ok){p(jo(y,v.status)),n([]);return}const _=y?.data??{},w=_.files;n(Array.isArray(w)?w:[]),r({editable_extensions:_.editable_extensions??[],uploadable_extensions:_.uploadable_extensions??[],max_text_bytes:_.max_text_bytes??0,max_upload_bytes:_.max_upload_bytes??0})}catch(v){p(v instanceof Error?v.message:"network error"),n([])}finally{a(!1)}},[e.type,e.identifier]),b=u.useCallback(async v=>{p(null);try{const y=`${Wo(e)}/content?path=${encodeURIComponent(v)}`,_=await fetch(y,{credentials:"same-origin",headers:Me()}),w=await _.json().catch(()=>null);if(!_.ok)return p(jo(w,_.status)),null;const k=w?.data?.content;return typeof k=="string"?k:""}catch(y){return p(y instanceof Error?y.message:"network error"),null}},[e.type,e.identifier]),g=u.useCallback(async(v,y)=>{p(null);try{const _=await fetch(`${Wo(e)}/content`,{method:"PUT",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({path:v,content:y})}),w=await _.json().catch(()=>null);return _.ok?(await f(),!0):(p(jo(w,_.status)),!1)}catch(_){return p(_ instanceof Error?_.message:"network error"),!1}},[e.type,e.identifier,f]),m=u.useCallback(async(v,y)=>{p(null);try{const _=new FormData;_.append("file",v),y&&_.append("directory",y);const w=await fetch(`${Wo(e)}/upload`,{method:"POST",credentials:"same-origin",headers:Me(),body:_}),k=await w.json().catch(()=>null);return w.ok?(await f(),!0):(p(jo(k,w.status)),!1)}catch(_){return p(_ instanceof Error?_.message:"network error"),!1}},[e.type,e.identifier,f]),h=u.useCallback(async v=>{p(null);try{const y=`${Wo(e)}?path=${encodeURIComponent(v)}`,_=await fetch(y,{method:"DELETE",credentials:"same-origin",headers:Me()}),w=await _.json().catch(()=>null);return _.ok?(await f(),!0):(p(jo(w,_.status)),!1)}catch(y){return p(y instanceof Error?y.message:"network error"),!1}},[e.type,e.identifier,f]);return{files:t,meta:o,isLoading:s,forbidden:l,error:c,reload:f,read:b,save:g,upload:m,remove:h}}const xE={display:"flex",flexDirection:"column",height:"100%",minHeight:0},wE={display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc",fontWeight:600,color:"#0f172a"},kE={marginLeft:"auto",border:"none",background:"transparent",fontSize:16,color:"#64748b",cursor:"pointer",outline:"none"},SE={flex:1,minHeight:0,display:"flex"},CE={width:260,flexShrink:0,borderRight:"1px solid #e2e8f0",overflowY:"auto",padding:8},$E={flex:1,minWidth:0,display:"flex",flexDirection:"column",padding:12,gap:8},up={display:"flex",alignItems:"center",gap:6,width:"100%",padding:"6px 8px",borderRadius:6,borderWidth:1,borderStyle:"solid",borderColor:"transparent",backgroundColor:"transparent",fontSize:12,color:"#334155",cursor:"pointer",textAlign:"left"},EE={...up,backgroundColor:"#eff6ff",borderColor:"#bfdbfe",color:"#1d4ed8",fontWeight:600},IE={margin:16,padding:16,borderRadius:8,border:"1px solid #fcd34d",background:"#fffbeb",color:"#92400e",fontSize:13,lineHeight:1.7},AE={padding:"8px 12px",borderRadius:6,border:"1px solid #fecaca",background:"#fef2f2",color:"#b91c1c",fontSize:12},TE={flex:1,minHeight:220,width:"100%",boxSizing:"border-box",padding:10,borderRadius:6,borderWidth:1,borderStyle:"solid",borderColor:"#cbd5e1",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12,lineHeight:1.6,resize:"vertical"},pp={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},ao={padding:"6px 12px",borderRadius:6,borderWidth:1,borderStyle:"solid",borderColor:"#cbd5e1",backgroundColor:"#ffffff",color:"#334155",fontSize:12,cursor:"pointer"},DE={...ao,backgroundColor:"#2563eb",borderColor:"#2563eb",color:"#ffffff",fontWeight:600},zE={...ao,borderColor:"#fca5a5",color:"#b91c1c"},NE={...ao,cursor:"text",minWidth:200},ME={...ao,cursor:"pointer",minWidth:220};function LE(e,t){if(typeof e=="string"&&e!=="")return e;if(e&&typeof e=="object"){const n=e,o=window?.G7Config?.locale??"ko",r=n[o]??n.ko??n.en??Object.values(n)[0];if(typeof r=="string"&&r!=="")return r}return t}function PE(e){const t=(typeof window<"u"?window.G7Config:null)??{},n=[{type:"template",identifier:e,label:e}];for(const[o,r]of[["module",t.activeModules],["plugin",t.activePlugins]])if(Array.isArray(r))for(const s of r){const a=typeof s?.identifier=="string"?s.identifier:"";a&&n.push({type:o,identifier:a,label:LE(s?.display_name,a)})}return n}function OE(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function BE(e){const{templateIdentifier:t,t:n,onClose:o}=e,r=u.useMemo(()=>PE(t),[t]),[s,a]=u.useState(`template:${t}`),l=u.useMemo(()=>r.find(C=>`${C.type}:${C.identifier}`===s)??r[0],[r,s]),d=_E({type:l.type,identifier:l.identifier}),{reload:c}=d,[p,f]=u.useState(null),[b,g]=u.useState(""),[m,h]=u.useState(""),[v,y]=u.useState(!1),_=u.useRef(null);u.useEffect(()=>{c()},[c]),u.useEffect(()=>{f(null),g(""),h("")},[s]);const w=u.useCallback(async C=>{if(f(C),!C.editable){g("");return}y(!0);const S=await d.read(C.path);y(!1),g(S??"")},[d]),k=u.useCallback(async()=>{const C=p?.path??m.trim();if(!C)return;y(!0);const S=await d.save(C,b);y(!1),S&&!p&&(h(""),f({path:C,name:C.split("/").pop()??C,extension:(C.split(".").pop()??"").toLowerCase(),size:b.length,modified_at:new Date().toISOString(),editable:!0,loaded:!0}))},[d,p,m,b]),x=u.useCallback(async()=>{if(!p||typeof window<"u"&&!window.confirm(n("layout_editor.custom_assets.delete_confirm")))return;y(!0);const C=await d.remove(p.path);y(!1),C&&(f(null),g(""))},[d,p,n]),$=u.useCallback(async C=>{const S=C.target.files?.[0];S&&(y(!0),await d.upload(S),y(!1),_.current&&(_.current.value=""))},[d]);return i.jsxs("div",{className:"g7le-custom-assets",style:xE,"data-testid":"g7le-custom-assets-modal",children:[i.jsxs("div",{style:wE,children:[i.jsxs("span",{children:["🎨 ",n("layout_editor.custom_assets.title")]}),i.jsx("select",{value:s,onChange:C=>a(C.target.value),style:ME,"aria-label":n("layout_editor.custom_assets.target_label"),"data-testid":"g7le-custom-assets-target",children:r.map(C=>i.jsxs("option",{value:`${C.type}:${C.identifier}`,children:[n(`layout_editor.custom_assets.type_${C.type}`)," · ",C.label]},`${C.type}:${C.identifier}`))}),i.jsx("button",{type:"button",style:kE,onClick:o,"aria-label":n("layout_editor.custom_assets.close"),"data-testid":"g7le-custom-assets-close",children:"✕"})]}),d.forbidden?i.jsx("div",{style:IE,"data-testid":"g7le-custom-assets-forbidden",children:n("layout_editor.custom_assets.forbidden")}):i.jsxs("div",{style:SE,children:[i.jsxs("div",{style:CE,"data-testid":"g7le-custom-assets-list",children:[d.isLoading&&d.files.length===0?i.jsx("div",{style:{padding:12,color:"#94a3b8",fontSize:12},children:n("layout_editor.custom_assets.loading")}):null,!d.isLoading&&d.files.length===0?i.jsx("div",{style:{padding:12,color:"#94a3b8",fontSize:12},children:n("layout_editor.custom_assets.empty")}):null,d.files.map(C=>i.jsxs("button",{type:"button",style:p?.path===C.path?EE:up,onClick:()=>void w(C),"data-testid":`g7le-custom-asset-row-${C.path}`,"data-loaded":C.loaded?"true":"false",children:[i.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:C.path}),i.jsx("span",{style:{color:"#94a3b8",fontSize:11},children:OE(C.size)})]},C.path))]}),i.jsxs("div",{style:$E,children:[d.error?i.jsx("div",{style:AE,"data-testid":"g7le-custom-assets-error",children:d.error}):null,i.jsxs("div",{style:pp,children:[i.jsx("input",{type:"text",value:p?p.path:m,readOnly:!!p,onChange:C=>h(C.target.value),placeholder:n("layout_editor.custom_assets.new_path_placeholder"),style:NE,"aria-label":n("layout_editor.custom_assets.path_label"),"data-testid":"g7le-custom-assets-path"}),p?i.jsx("button",{type:"button",style:ao,onClick:()=>{f(null),g("")},"data-testid":"g7le-custom-assets-new",children:n("layout_editor.custom_assets.new_file")}):null]}),p&&!p.editable?i.jsx("div",{style:{color:"#64748b",fontSize:12,lineHeight:1.7},children:n("layout_editor.custom_assets.binary_hint",{extension:p.extension})}):i.jsx("textarea",{value:b,onChange:C=>g(C.target.value),style:TE,spellCheck:!1,"aria-label":n("layout_editor.custom_assets.content_label"),"data-testid":"g7le-custom-assets-content"}),i.jsxs("div",{style:pp,children:[i.jsx("button",{type:"button",style:DE,disabled:v||(p?!p.editable:m.trim()===""),onClick:()=>void k(),"data-testid":"g7le-custom-assets-save",children:n("layout_editor.custom_assets.save")}),i.jsx("button",{type:"button",style:ao,disabled:v,onClick:()=>_.current?.click(),"data-testid":"g7le-custom-assets-upload",children:n("layout_editor.custom_assets.upload")}),i.jsx("input",{ref:_,type:"file",style:{display:"none"},onChange:C=>void $(C),"data-testid":"g7le-custom-assets-file-input"}),i.jsx("button",{type:"button",style:zE,disabled:v||!p,onClick:()=>void x(),"data-testid":"g7le-custom-assets-delete",children:n("layout_editor.custom_assets.delete")}),i.jsx("span",{style:{color:"#94a3b8",fontSize:11},children:n("layout_editor.custom_assets.apply_hint")})]})]})]})]})}const fp=[{id:"copy",group:"clipboard",combos:[{key:"c",mod:!0}],labelKey:"layout_editor.shortcuts.action.copy",requiresSelection:!0},{id:"cut",group:"clipboard",combos:[{key:"x",mod:!0}],labelKey:"layout_editor.shortcuts.action.cut",requiresSelection:!0},{id:"paste",group:"clipboard",combos:[{key:"v",mod:!0}],labelKey:"layout_editor.shortcuts.action.paste"},{id:"openProps",group:"element",combos:[{key:"enter"}],labelKey:"layout_editor.shortcuts.action.open_props",requiresSelection:!0},{id:"delete",group:"element",combos:[{key:"delete"},{key:"backspace"}],labelKey:"layout_editor.shortcuts.action.delete",requiresSelection:!0},{id:"selectParent",group:"element",combos:[{key:"arrowup"}],labelKey:"layout_editor.shortcuts.action.select_parent",requiresSelection:!0},{id:"deselect",group:"element",combos:[{key:"escape"}],labelKey:"layout_editor.shortcuts.action.deselect"},{id:"addElement",group:"element",combos:[{key:"/",mod:!0}],labelKey:"layout_editor.shortcuts.action.add_element"},{id:"undo",group:"history",combos:[{key:"z",mod:!0}],labelKey:"layout_editor.shortcuts.action.undo"},{id:"redo",group:"history",combos:[{key:"z",mod:!0,shift:!0},{key:"y",mod:!0}],labelKey:"layout_editor.shortcuts.action.redo"},{id:"editCode",group:"view",combos:[{key:"e",mod:!0}],labelKey:"layout_editor.shortcuts.action.edit_code"},{id:"preview",group:"view",combos:[{key:"p",mod:!0}],labelKey:"layout_editor.shortcuts.action.preview"},{id:"translations",group:"view",combos:[{key:"l",mod:!0}],labelKey:"layout_editor.shortcuts.action.translations"},{id:"help",group:"view",combos:[{key:"?"}],labelKey:"layout_editor.shortcuts.action.help"},{id:"reset",group:"document",combos:[{key:"r",mod:!0,shift:!0}],labelKey:"layout_editor.shortcuts.action.reset"},{id:"save",group:"document",combos:[{key:"s",mod:!0}],labelKey:"layout_editor.shortcuts.action.save"},{id:"exit",group:"document",combos:[{key:"escape"}],labelKey:"layout_editor.shortcuts.action.exit"}];function WE(e){return{key:(e.key||"").toLowerCase(),mod:e.ctrlKey||e.metaKey,shift:e.shiftKey,alt:e.altKey}}function jE(e,t){return e.key===t.key&&!!e.mod==!!t.mod&&!!e.shift==!!t.shift&&!!e.alt==!!t.alt}function HE(e){for(const t of fp)if(t.combos.some(n=>jE(n,e)))return t;return null}function FE(e,t){const n=[];return e.mod&&n.push(t?"⌘":"Ctrl"),e.shift&&n.push(t?"⇧":"Shift"),e.alt&&n.push(t?"⌥":"Alt"),n.push(KE(e.key)),n.join(" + ")}function KE(e){return{arrowup:"↑",arrowdown:"↓",arrowleft:"←",arrowright:"→",enter:"Enter",escape:"Esc",delete:"Delete",backspace:"Backspace"," ":"Space"}[e]??(e.length===1?e.toUpperCase():e)}const VE=["clipboard","element","history","view","document"],UE={clipboard:"layout_editor.shortcuts.group.clipboard",element:"layout_editor.shortcuts.group.element",history:"layout_editor.shortcuts.group.history",view:"layout_editor.shortcuts.group.view",document:"layout_editor.shortcuts.group.document"};function qE(){return typeof navigator>"u"?!1:/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent||"")}function GE({t:e,onClose:t,isMac:n}){const o=n??qE(),r=u.useMemo(()=>{const s=new Map;for(const a of fp){const l=s.get(a.group)??[];l.push(a),s.set(a.group,l)}return s},[]);return i.jsxs("div",{className:"g7le-shortcut-help","data-testid":"g7le-shortcut-help",style:YE,children:[i.jsxs("div",{style:XE,children:[i.jsx("span",{style:JE,children:e("layout_editor.shortcuts.title")}),i.jsx("button",{type:"button","data-testid":"g7le-shortcut-help-close",onClick:t,"aria-label":e("layout_editor.shortcuts.close"),style:ZE,children:"✕"})]}),i.jsx("div",{style:QE,children:VE.map(s=>{const a=r.get(s);return!a||a.length===0?null:i.jsxs("div",{style:RE,"data-testid":`g7le-shortcut-group-${s}`,children:[i.jsx("div",{style:e7,children:e(UE[s])}),i.jsx("table",{style:t7,children:i.jsx("tbody",{children:a.map(l=>i.jsxs("tr",{"data-testid":`g7le-shortcut-row-${l.id}`,children:[i.jsx("td",{style:n7,children:e(l.labelKey)}),i.jsx("td",{style:o7,children:l.combos.map((d,c)=>i.jsxs(u.Fragment,{children:[c>0&&i.jsx("span",{style:i7,children:e("layout_editor.shortcuts.or")}),i.jsx("kbd",{style:r7,children:FE(d,o)})]},c))})]},l.id))})})]},s)})}),i.jsx("div",{style:s7,children:e("layout_editor.shortcuts.footnote")})]})}const YE={display:"flex",flexDirection:"column",padding:20,gap:16,width:"100%",boxSizing:"border-box"},XE={display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:12,borderBottom:"1px solid #e2e8f0"},JE={fontSize:15,fontWeight:700,color:"#0f172a"},ZE={width:28,height:28,border:"none",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:14,borderRadius:6},QE={display:"grid",gridTemplateColumns:"1fr 1fr",columnGap:28,rowGap:18,alignItems:"start"},RE={display:"flex",flexDirection:"column",gap:6},e7={fontSize:12,fontWeight:700,color:"#2563eb"},t7={width:"100%",borderCollapse:"collapse"},n7={padding:"4px 0",fontSize:12.5,color:"#334155",textAlign:"left",whiteSpace:"nowrap",verticalAlign:"middle"},o7={padding:"4px 0",paddingLeft:12,textAlign:"right",verticalAlign:"middle"},r7={display:"inline-block",padding:"1px 6px",fontSize:11,fontFamily:"ui-monospace, monospace",color:"#0f172a",background:"#f1f5f9",border:"1px solid #cbd5e1",borderBottomWidth:2,borderRadius:5,whiteSpace:"nowrap"},i7={fontSize:11,color:"#94a3b8",margin:"0 4px"},s7={fontSize:11,color:"#94a3b8",paddingTop:12,borderTop:"1px solid #f1f5f9"};function a7(e){if(!e||!(e instanceof HTMLElement))return!1;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable)}function l7(){return typeof document>"u"?!1:!!document.querySelector(".g7le-modal-backdrop, .g7le-modal")}function gp(e){const{handlers:t,hasSelection:n,enabled:o=!0}=e;u.useEffect(()=>{if(!o||typeof window>"u")return;const r=s=>{if(a7(s.target))return;const a=WE(s),l=HE(a);if(!l||l7()||l.requiresSelection&&!n)return;if(l.key==="escape"||a.key==="escape"){if(n){const c=t.deselect;c&&(s.preventDefault(),c())}else{const c=t.exit;c&&(s.preventDefault(),c())}return}const d=t[l.id];d&&(s.preventDefault(),d())};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[t,n,o])}function d7(e){const{result:t,onDismiss:n,onLoadLatest:o,onKeepMyChanges:r}=e,{t:s}=et();if(u.useEffect(()=>{if(!t||t.kind==="concurrent_modification"||t.kind==="validation_failed")return;const a=setTimeout(n,5e3);return()=>clearTimeout(a)},[t,n]),!t)return null;if(t.kind==="success")return i.jsx(Ho,{tone:"success",testId:"g7le-save-banner-success",onDismiss:n,children:s("layout_editor.save.success")});if(t.kind==="validation_failed"){const a=t.errors??{},l=Object.entries(a);return i.jsxs(Ho,{tone:"error",testId:"g7le-save-banner-validation",onDismiss:n,children:[i.jsx("strong",{children:s("layout_editor.save.validation_failed")}),l.length>0&&i.jsx("ul",{style:hp,"data-testid":"g7le-save-banner-validation-errors",children:l.map(([d,c])=>i.jsxs("li",{children:[i.jsx("code",{style:yp,children:d}),": ",c.join(", ")]},d))})]})}return t.kind==="blocked_inactive_extension"?i.jsxs(Ho,{tone:"warning",testId:"g7le-save-banner-blocked",onDismiss:n,children:[i.jsx("strong",{children:s("layout_editor.save.blocked_inactive_extension")}),t.blockedPaths.length>0&&i.jsx("ul",{style:hp,"data-testid":"g7le-save-banner-blocked-paths",children:t.blockedPaths.map(a=>i.jsx("li",{children:i.jsx("code",{style:yp,children:a})},a))})]}):t.kind==="network_error"?i.jsxs(Ho,{tone:"error",testId:"g7le-save-banner-network",onDismiss:n,children:[i.jsx("strong",{children:s("layout_editor.save.network_error_title")}),i.jsx("div",{style:{marginTop:4,fontSize:12},children:t.message})]}):t.kind==="guard_no_document"?i.jsx(Ho,{tone:"neutral",testId:"g7le-save-banner-guard-no-document",onDismiss:n,children:s("layout_editor.save.guard_no_document")}):i.jsx("div",{role:"dialog","aria-modal":"true","aria-label":s("layout_editor.save.concurrent.title"),"data-testid":"g7le-save-banner-concurrent",style:f7,children:i.jsxs("div",{style:g7,children:[i.jsx("h2",{style:h7,children:s("layout_editor.save.concurrent.title")}),i.jsx("p",{style:y7,children:s("layout_editor.save.concurrent.message")}),i.jsx("div",{style:b7,children:s("layout_editor.save.concurrent.version_info",{current:String(t.currentVersion),yours:String(t.yourVersion)})}),i.jsxs("div",{style:m7,children:[i.jsx("button",{type:"button","data-testid":"g7le-save-banner-concurrent-load-latest",onClick:()=>{o?.(),n()},style:v7,children:s("layout_editor.save.concurrent.load_latest")}),i.jsx("button",{type:"button","data-testid":"g7le-save-banner-concurrent-keep-mine",onClick:()=>{r?.(),n()},style:_7,children:s("layout_editor.save.concurrent.view_my_changes")}),i.jsx("button",{type:"button","data-testid":"g7le-save-banner-concurrent-cancel",onClick:n,style:x7,children:s("layout_editor.save.concurrent.cancel")})]})]})})}function Ho(e){const{tone:t,testId:n,onDismiss:o,children:r}=e,s=c7[t];return i.jsxs("div",{role:"status","data-testid":n,style:{...u7,background:s.bg,borderColor:s.border,color:s.fg},children:[i.jsx("div",{style:{flex:1,minWidth:0},children:r}),i.jsx("button",{type:"button",onClick:o,"aria-label":"close","data-testid":`${n}-close`,style:p7,children:"×"})]})}const c7={success:{bg:"#dcfce7",border:"#86efac",fg:"#14532d"},error:{bg:"#fee2e2",border:"#fca5a5",fg:"#7f1d1d"},warning:{bg:"#fef3c7",border:"#fcd34d",fg:"#78350f"},neutral:{bg:"#f1f5f9",border:"#cbd5e1",fg:"#334155"}},u7={display:"flex",alignItems:"flex-start",gap:12,padding:"12px 16px",border:"1px solid",borderRadius:0,fontSize:13,lineHeight:1.5},p7={background:"transparent",border:"none",fontSize:18,cursor:"pointer",lineHeight:1,color:"inherit",padding:"0 4px",flexShrink:0},hp={margin:"8px 0 0",paddingLeft:20,fontSize:12},yp={background:"rgba(0, 0, 0, 0.06)",padding:"1px 4px",borderRadius:3,fontFamily:"monospace"},f7={position:"fixed",inset:0,background:"rgba(15, 23, 42, 0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e4},g7={background:"#fff",borderRadius:8,padding:24,width:"min(480px, 90vw)",boxShadow:"0 10px 25px rgba(0,0,0,0.15)"},h7={margin:"0 0 8px",fontSize:16,fontWeight:600,color:"#0f172a"},y7={margin:"0 0 12px",color:"#334155",fontSize:13,lineHeight:1.5},b7={marginBottom:16,padding:"8px 12px",background:"#f8fafc",borderRadius:6,fontSize:12,color:"#64748b",fontFamily:"monospace"},m7={display:"flex",gap:8,justifyContent:"flex-end"},v7={padding:"8px 14px",background:"#2563eb",color:"#fff",border:"none",borderRadius:6,fontSize:13,fontWeight:600,cursor:"pointer"},_7={padding:"8px 14px",background:"#fff",color:"#334155",border:"1px solid #cbd5e1",borderRadius:6,fontSize:13,fontWeight:500,cursor:"pointer"},x7={padding:"8px 14px",background:"transparent",color:"#64748b",border:"none",borderRadius:6,fontSize:13,cursor:"pointer"};function bp(e){if(!e)return null;const n=new URLSearchParams(e).get("route");return n&&n.length>0?n:null}function ia(e,t,n){const o=`/admin/layout-editor/${encodeURIComponent(e)}`;if(!t||t.length===0)return o;if(t.startsWith("__")){let r=`${o}?edit=${encodeURIComponent(t)}`;return(t.startsWith("__modal__/")||t.startsWith("__iteration__/"))&&n&&(r+=`&host=${encodeURIComponent(n)}`),r}return`${o}?route=${encodeURIComponent(t)}`}function mp(e){if(!e)return null;const n=new URLSearchParams(e).get("host");return n&&n.length>0?n:null}function vp(e){if(!e)return null;const n=new URLSearchParams(e).get("edit");return n&&n.length>0&&n.startsWith("__")?n:null}function w7(e,t){const n=`/admin/templates/${encodeURIComponent(e)}/edit`;if(!t||t.length===0||t.startsWith("__"))return n;const o=t.replace(/^\*+/,"");return o.length===0?n:`${n}?route=${encodeURIComponent(o)}`}const k7="g7le-editor-route",S7=new Set;function sa(e){return e.path.startsWith("__group__/")||e.path.startsWith("__conngroup__/")}function _p(e,t){const{t:n,translationEngine:o,translationContext:r,templateIdentifier:s}=t,a=sa(e);if(!e.label.startsWith("$t:"))return e.label;const l=e.label.slice(3),d=l.indexOf("|"),c=d===-1?l:l.slice(0,d),p={};if(d!==-1)for(const b of l.slice(d+1).split("|")){const g=b.indexOf("=");g!==-1&&(p[b.slice(0,g)]=b.slice(g+1))}if((e.kind==="route"||e.kind==="modal")&&!a&&o&&r&&s!==r.templateId){const b={templateId:s,locale:r.locale},g=Object.keys(p).length>0?"|"+Object.entries(p).map(([h,v])=>`${h}=${v}`).join("|"):void 0,m=o.translate(c,b,g);if(m!==c)return m}const f=n(c,p);if(f===c&&typeof window<"u"){const b=window.G7Core?.t;if(typeof b=="function")try{const g=b(c,p);if(g!==c)return g}catch{}}if(f===c&&e.kind==="route"&&!a){const b=e.path;if(b&&b!=="/"){const g=b.split("/").filter(Boolean);return g[g.length-1]??b}return b==="/"?"/":c}return f}function C7(e){return e.trim().toLocaleLowerCase()}function xp(e,t){if(!t)return e;const n=e.toLocaleLowerCase(),o=[];let r=0,s=n.indexOf(t,r);if(s===-1)return e;let a=0;for(;s!==-1;)s>r&&o.push(e.slice(r,s)),o.push(i.jsx("mark",{className:"g7le-route-tree__highlight",style:{background:"#fde68a",color:"inherit",borderRadius:2,padding:"0 1px"},children:e.slice(s,s+t.length)},`m${a++}`)),r=s+t.length,s=n.indexOf(t,r);return r{const z=f.selectedRoute?.path??"";return z.startsWith("__extension__/")||z.startsWith("__modal__/")?z.slice(z.lastIndexOf("/")+1):null},[f.selectedRoute?.path]),h=u.useMemo(()=>!g||!m?!1:(e.children??[]).some(z=>z.kind==="extension"&&z.extensionId===m||z.kind==="modal"&&z.modalId===m),[g,m,e.children]),[v,y]=u.useState(!0);u.useEffect(()=>{h&&y(!1)},[h]);const _=f.editMode==="extension"?f.selectedRoute?.layoutName??null:null,w=e.kind==="extension"?kp(e,f.routeTree)??null:null,k=e.kind==="extension"&&o===e.path&&(_===null||w===null||_===w),x=f.editMode==="modal"&&o?.startsWith("__modal__/")?o.slice(o.lastIndexOf("/")+1):null,$=f.editMode==="modal"?f.selectedRoute?.layoutName??null:null,C=e.kind==="modal"&&!!x&&e.modalId===x&&($===null||e.modalHostLayout==null||$===e.modalHostLayout),S=e.kind!=="extension"&&e.kind!=="modal"&&o===e.path||k||C||e.kind==="route"&&!b&&r===e.path,E=(e.children?.length??0)>0&&(!g||l||!v),I=!b&&!!e.layoutName&&s.has(e.layoutName),N=b?void 0:e.kind==="extension"?e.extensionId?f.extensionVersions[e.extensionId]:void 0:e.layoutName?f.layoutVersions[e.layoutName]:void 0,T=()=>{if(g){y(z=>!z);return}b||n(e)},B=_p(e,{t:d,translationEngine:c,translationContext:p,templateIdentifier:f.templateIdentifier}),M=b?null:$7(e),O={paddingLeft:12+t*14,paddingRight:12,paddingTop:4,paddingBottom:4,opacity:e.isHidden?.55:1,cursor:g?"pointer":b?"default":"pointer",background:S?"#eff6ff":"transparent",borderLeft:S?"2px solid #2563eb":"2px solid transparent",fontWeight:b||S?600:400,fontSize:b?11:13,color:b?"#64748b":S?"#1d4ed8":"#1e293b",textTransform:b?"uppercase":"none",letterSpacing:b?.6:void 0,transition:"background-color 100ms, color 100ms",display:"flex",flexDirection:"column",alignItems:"stretch",gap:2,userSelect:"none"};return i.jsxs("li",{children:[i.jsxs("div",{"data-testid":b?"g7le-route-tree-group":"g7le-route-tree-item","data-route-path":e.path,"data-route-kind":e.kind,"data-conn-collapsed":g?l?"false":String(v):void 0,role:g||!b?"button":void 0,tabIndex:g||!b?0:void 0,"aria-expanded":g?l?!0:!v:void 0,onClick:T,onKeyDown:z=>{g&&(z.key==="Enter"||z.key===" ")?(z.preventDefault(),y(H=>!H)):!b&&(z.key==="Enter"||z.key===" ")&&(z.preventDefault(),n(e))},style:O,children:[i.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[g&&i.jsx("span",{"aria-hidden":"true",style:{flex:"0 0 auto",fontSize:9,color:"#94a3b8",width:10,display:"inline-block"},children:l||!v?"▾":"▸"}),I&&i.jsx("span",{className:"g7le-route-tree__dirty-dot","data-testid":"g7le-route-tree-dirty",title:d("layout_editor.chrome.route_tree.badge.modified"),"aria-label":d("layout_editor.chrome.route_tree.badge.modified"),style:{width:7,height:7,borderRadius:"50%",background:"#f59e0b",flex:"0 0 auto"}}),b?B:xp(B,a),typeof N=="number"&&i.jsxs("span",{className:"g7le-route-tree__version-badge","data-testid":"g7le-route-tree-version",title:d("layout_editor.chrome.route_tree.badge.version_tooltip",{version:String(N)}),style:{flex:"0 0 auto",padding:"0 5px",fontSize:10,fontWeight:600,lineHeight:"16px",borderRadius:4,background:"#eef2ff",color:"#4f46e5",border:"1px solid #e0e7ff",letterSpacing:.2},children:["v",N]}),i.jsx(E7,{node:e})]}),M&&i.jsx("span",{className:"g7le-route-tree__layout-path","data-testid":"g7le-route-tree-layout-path",title:M,style:{fontSize:11,fontWeight:400,color:"#94a3b8",textTransform:"none",letterSpacing:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:xp(M,a)})]}),E&&i.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:e.children.map(z=>i.jsx(wp,{node:z,depth:t+1,onSelect:n,selectedRoutePath:o,activeHostRoutePath:r,dirtyLayoutNames:s,query:a,forceExpand:l},z.path))})]})}function I7(e,t){if(!t||!t.startsWith("__"))return null;const n=t.startsWith("__modal__/"),o=t.startsWith("__extension__/");if(!n&&!o)return null;const r=t.slice(t.lastIndexOf("/")+1),s=a=>{for(const l of a){if(l.connectedHostRoutePath&&(n&&l.kind==="modal"&&l.modalId===r||o&&l.kind==="extension"&&l.extensionId===r))return l.connectedHostRoutePath;if(l.children&&l.children.length>0){const d=s(l.children);if(d)return d}}return null};return s(e)}function kp(e,t){if(e.connectedHostRoutePath){const n=Sp(t,e.connectedHostRoutePath);if(n?.layoutName)return n.layoutName}if(e.extensionType==="overlay"&&e.extensionTargetName)return e.extensionTargetName}function Sp(e,t){for(const n of e){if(n.kind==="route"&&n.path===t)return n;if(n.children&&n.children.length>0){const o=Sp(n.children,t);if(o)return o}}return null}function Cp(e,t,n){const o=[];for(const r of e){const s=sa(r),a=r.children&&r.children.length>0?Cp(r.children,t,n):[];if(s){a.length>0&&o.push({...r,children:a});continue}const l=_p(r,n).toLocaleLowerCase(),d=r.path.toLocaleLowerCase();(l.includes(t)||!d.startsWith("__")&&d.includes(t)||a.length>0)&&o.push({...r,children:a})}return o}function A7(){const{t:e,translationEngine:t,translationContext:n}=et(),{state:o,dispatch:r}=Qe(),a=Kt()?.dirtyLayoutNames??S7,[l,d]=u.useState(""),c=C7(l),p=u.useMemo(()=>c?Cp(o.routeTree,c,{t:e,translationEngine:t,translationContext:n,templateIdentifier:o.templateIdentifier}):o.routeTree,[c,o.routeTree,o.templateIdentifier,e,t,n]),f=h=>{if(h.kind==="base"&&h.layoutName){r({type:"ENTER_BASE_EDIT",layoutName:h.layoutName});return}if(h.kind==="modal"&&h.modalId&&h.modalHostLayout){r({type:"ENTER_MODAL_EDIT",modalId:h.modalId,hostLayout:h.modalHostLayout});return}if(h.kind==="extension"&&h.extensionId){const v=kp(h,o.routeTree);r({type:"ENTER_EXTENSION_EDIT",extensionId:h.extensionId,extensionHost:v});return}if(r({type:"SELECT_ROUTE",route:{path:h.path,layoutName:h.layoutName}}),typeof window<"u"&&window.history?.pushState){const v=ia(o.templateIdentifier,h.path);`${window.location.pathname}${window.location.search}`!==v&&window.history.pushState({source:k7,routePath:h.path},"",v)}},b=o.selectedRoute?.path??null,g=u.useMemo(()=>I7(o.routeTree,b),[o.routeTree,b]);if(o.isRouteTreeCollapsed)return i.jsx("aside",{className:"g7le-route-tree g7le-route-tree--collapsed","data-testid":"g7le-route-tree-panel","data-collapsed":"true",style:{width:28,borderRight:"1px solid #e2e8f0",background:"#ffffff"}});const m=o.routeTree.length>0;return i.jsxs("aside",{className:"g7le-route-tree","data-testid":"g7le-route-tree-panel","data-collapsed":"false",style:{width:280,borderRight:"1px solid #e2e8f0",background:"#ffffff",position:"sticky",top:"var(--g7le-header-h, 0px)",alignSelf:"start",height:"calc(100vh - var(--g7le-header-h, 0px))",overflow:"hidden",minHeight:0,display:"flex",flexDirection:"column"},"aria-label":e("layout_editor.chrome.route_tree.panel_title"),children:[i.jsx("div",{className:"g7le-route-tree__title",style:{padding:"10px 14px",fontSize:12,fontWeight:600,color:"#475569",textTransform:"uppercase",letterSpacing:.6,borderBottom:"1px solid #e2e8f0",background:"#f8fafc",flex:"0 0 auto"},children:e("layout_editor.chrome.route_tree.panel_title")}),m&&i.jsxs("div",{className:"g7le-route-tree__search",style:{padding:"8px 10px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",flex:"0 0 auto",position:"relative"},children:[i.jsx("input",{type:"text",className:"g7le-route-tree__search-input","data-testid":"g7le-route-tree-search",value:l,onChange:h=>d(h.target.value),placeholder:e("layout_editor.chrome.route_tree.search_placeholder"),"aria-label":e("layout_editor.chrome.route_tree.search_placeholder"),style:{width:"100%",boxSizing:"border-box",padding:l?"6px 26px 6px 10px":"6px 10px",fontSize:12,lineHeight:1.4,color:"#1e293b",border:"1px solid #cbd5e1",borderRadius:6,outline:"none",background:"#f8fafc"}}),l&&i.jsx("button",{type:"button",className:"g7le-route-tree__search-clear","data-testid":"g7le-route-tree-search-clear",onClick:()=>d(""),"aria-label":e("layout_editor.chrome.route_tree.search_clear"),title:e("layout_editor.chrome.route_tree.search_clear"),style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:14,lineHeight:1,padding:0},children:"✕"})]}),!m&&i.jsx("div",{className:"g7le-route-tree__empty","data-testid":"g7le-route-tree-empty",style:{padding:16,fontSize:12,color:"#94a3b8",textAlign:"center"},children:e("layout_editor.chrome.route_tree.empty")}),m&&c&&p.length===0&&i.jsx("div",{className:"g7le-route-tree__no-results","data-testid":"g7le-route-tree-no-results",style:{padding:16,fontSize:12,color:"#94a3b8",textAlign:"center"},children:e("layout_editor.chrome.route_tree.search_no_results")}),m&&p.length>0&&i.jsx("nav",{className:"g7le-route-tree__scroll","data-testid":"g7le-route-tree-scroll",style:{flex:"1 1 auto",minHeight:0,overflowY:"auto"},children:i.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:p.map(h=>i.jsx(wp,{node:h,depth:0,onSelect:f,selectedRoutePath:b,activeHostRoutePath:g,dirtyLayoutNames:a,query:c,forceExpand:!!c},h.path))})})]})}const T7=Lt().DynamicRenderer,aa=Lt(),D7=aa.ResponsiveProvider;aa.useResponsive,aa.ResponsiveContext;const z7=Lt().ActionDispatcher,$p=Lt(),N7=$p.DataSourceManager;$p.dataSourceManager;function ei(e,t,n){const o=t??{},r=o.message||o.error||`HTTP ${e}`,s=o?.data?.required_permissions??o?.required_permissions;let a;return e===401?a="unauthorized":e===403?a="forbidden":e===404?a="not_found":e>=500?a="server_error":a="unknown",{kind:a,status:e,message:String(r),requiredPermissions:s?String(s):void 0,source:n}}function lo(e,t){return{kind:"network",status:0,message:e instanceof Error?e.message:String(e??"Unknown network error"),source:t}}function Ep(e){if(typeof e!="object"||e===null)return!1;const t=e;return typeof t.kind=="string"&&typeof t.status=="number"&&typeof t.message=="string"}function Re(e){if(!e)return[];const t=[],n=e.split(".");for(let o=0;o0&&(t.push({responsive:a}),o+=1);continue}const s=Number(r);Number.isFinite(s)&&Number.isInteger(s)&&s>=0&&t.push(s)}return t}function M7(e,t){if(!e)return{affordance:"none",targetPath:null};const n=L7(e);return n?P7(n)?{affordance:"dynamic_path",targetPath:n}:/^(https?:)?\/\//.test(n)?{affordance:"external_url",targetPath:n}:n.startsWith("/")?t?{affordance:t(n),targetPath:n}:{affordance:"route_not_in_tree",targetPath:n}:{affordance:"route_not_in_tree",targetPath:n}:{affordance:"none",targetPath:null}}function L7(e){const t=e.actions;if(Array.isArray(t)){for(const n of t)if(n&&typeof n=="object"&&n.handler==="navigate"){const o=n.params?.path;if(typeof o=="string"&&o.length>0)return o}}if(e.name==="A"||e.type==="A"){const n=e.props?.href;if(typeof n=="string"&&n.length>0)return n}return null}function P7(e){return/\{\{[\s\S]*?\}\}/.test(e)}function O7(e,t,n){const o=s=>!!(s?.iteration&&s.iteration.source!==void 0),r=s=>{if(!s)return s;const a=s.indexOf(".iteration."),l=s.indexOf(".sortable."),d=[a,l].filter(c=>c>=0).sort((c,p)=>c-p)[0];return d===void 0?s:s.slice(0,d)};return o(e)?{isIteration:!0,iterationSourcePath:r(n)}:n&&n.includes(".iteration.")?{isIteration:!0,iterationSourcePath:r(n)}:t.some(o)?{isIteration:!0,iterationSourcePath:r(n)}:{isIteration:!1,iterationSourcePath:null}}function B7(e,t){const n=a=>{const l=a?.iteration&&a.iteration.source;return typeof l=="string"&&l.length>0?l:null},o=n(e)??t.map(n).find(a=>a!==null)??null;if(o!==null){const a=j7(o);if(a!==null)return a}const r=[];if(typeof e.text=="string"&&r.push(...Ip(e.text)),e.props&&typeof e.props=="object")for(const a of Object.values(e.props))typeof a=="string"&&r.push(...Ip(a));return r.length===0?null:r.find(a=>!W7.has(a))??r[0]}const W7=new Set(["_local","_global","_computed","route","query","props","item","index","event","$event","$response","response"]);function Ip(e){const t=[],n=/\{\{([\s\S]*?)\}\}/g;let o;for(;(o=n.exec(e))!==null;){const r=Ap(o[1]);r!==null&&t.push(r)}return t}function j7(e){const t=e.replace(/\{\{|\}\}/g,"");return Ap(t)}function Ap(e){const t=/[A-Za-z_$][A-Za-z0-9_$]*/.exec(e.trim());return t?t[0]:null}function Jt(e,t,n,o=[]){if(!e)return"none";if(ld(e)||typeof e.slot=="string"||typeof e.__editorSlotName=="string")return"extension_point";if(ud(e,t,n)){const r=e.__source?.kind;return r==="base"?"base":r==="partial"?"partial":r==="extension"?"extension":"base"}return Xb(e,o)?"data_bound":"none"}function Zt(e){return e==="none"||e==="data_bound"}function Tp(e){return Zt(e)?null:e==="extension"||e==="extension_point"?"denied_extension_locked":"denied_base_locked"}function Dp(e){if(!e)return null;if(e.__source?.kind==="extension"&&typeof e.__source.extensionId=="number")return e.__source.extensionId;const t=e.__injectedProps;if(Array.isArray(t)&&t.length>0){const n=t[0]?.extensionId;if(typeof n=="number")return n}return null}function H7(e,t){if(t<=0)return e;const n=e.split(".");let o=0;const r=[];for(let s=0;s=t)break;r.push(a);continue}if(a==="iteration"||a==="sortable"){if(o>=t)break;r.push(a);continue}r.push(a);const l=n[s-1];if((l===void 0||l==="children")&&(o+=1),o>=t)break}return r.join(".")}function zp(e,t,n,o){if(!e||!t)return t;const r=n(t),s=Qb(e,r,o);return s.length===r.length?t:H7(t,s.length)}function Np(e){return Zt(e)}function F7(e){const{rootNode:t,editMode:n,currentExtensionId:o,editableRootPath:r,pathParser:s=Re,resolveRouteMatch:a}=e,[l,d]=u.useState(null),[c,p]=u.useState(null),f=u.useCallback(_=>{if(_===null||n==="route")return!0;if(n==="iteration_item"||n==="modal"){if(!r||r.length===0)return!0;const $=s(_);return Mp($,r)}const w=la(t,_,s);if(!w)return!0;const k=da(t,_,s),x=Jt(w,n,o,k);return Zt(x)},[t,s,n,o,r]),b=u.useCallback((_,w)=>{const x=(w?.currentTarget?.dataset??w?.dataset)?.editorPath??null,$=zp(t,x,s,o);f($)&&d($)},[t,s,o,f]),g=u.useCallback((_,w)=>{if(_===null){p(null);return}const x=(w?.currentTarget?.dataset??w?.dataset)?.editorPath??null,$=zp(t,x,s,o);if(!f($)){p(null);return}p($)},[t,s,o,f]),m=u.useCallback(()=>{d(null)},[]),h=u.useMemo(()=>{const _=la(t,l,s),w=la(t,c,s),k=_?da(t,l,s):[];let x=Jt(_,n,o,k);(n==="iteration_item"||n==="modal")&&l!==null&&_&&r&&r.length>0&&Mp(s(l),r)&&(dd(_)?x="data_bound":x==="data_bound"&&(x="none"));const{affordance:$,targetPath:C}=M7(_,a),S=x==="base"&&typeof _?.__source?.layout=="string"?_.__source.layout:null,D=x==="data_bound"&&_?B7(_,k):null,{isIteration:E,iterationSourcePath:I}=x==="data_bound"&&_?O7(_,k,l):{isIteration:!1,iterationSourcePath:null};return{selectedNode:_,hoverNode:w,selectedLockKind:x,selectedNavAffordance:$,selectedNavTargetPath:C,selectedBaseLayout:S,selectedDataSourceId:D,selectedIsIteration:E,selectedIterationSourcePath:I}},[t,l,c,n,o,r,s,a]),v=u.useRef(void 0);v.current!==l&&(v.current=l,Nl({op:l===null?"clear":"select",componentPath:l,componentName:Lp(h.selectedNode),lockKind:h.selectedLockKind,navAffordance:h.selectedNavAffordance,sourceExtensionId:Dp(h.selectedNode),timestamp:Date.now()}));const y=u.useRef(void 0);return y.current!==c&&(y.current=c,c!==null&&Nl({op:"hover",componentPath:c,componentName:Lp(h.hoverNode),lockKind:Jt(h.hoverNode,n,o,da(t,c,s)),navAffordance:"none",sourceExtensionId:Dp(h.hoverNode),timestamp:Date.now()})),{selectedPath:l,hoverPath:c,...h,handleSelect:b,handleHover:g,clearSelection:m}}function la(e,t,n){if(!e||!t)return null;const o=n(t);return Pe(e,o)}function Mp(e,t){if(e.length0?e.name:typeof e.type=="string"&&e.type.length>0?e.type:null:null}let Pp=0;function Op(){return Pp}function ca(){Pp+=1}function K7(e){if(typeof e!="string")return null;const t="__modal__/";if(!e.startsWith(t))return null;const n=e.slice(t.length);return n===""||n.includes("/")?null:n}function V7(e){if(typeof e!="string")return null;const t="__iteration__/";if(!e.startsWith(t))return null;const n=e.slice(t.length);return n!==""?n:null}function Bp(){const{state:e}=Qe(),t=e.templateIdentifier,n=e.selectedRoute?.layoutName??null,o=e.editMode,r=o==="modal"?K7(e.selectedRoute?.path):null,s=o==="iteration_item"?V7(e.selectedRoute?.path):null,[a,l]=u.useState(null),[d,c]=u.useState(!1),[p,f]=u.useState(null),[b,g]=u.useState(!1),[m,h]=u.useState(0),[v,y]=u.useState(0),_=u.useRef(new Map),[w,k]=u.useState(()=>new Set),x=u.useCallback((P,A)=>`${P}|${A??""}`,[]),$=u.useRef(null);u.useEffect(()=>{$.current=a},[a]);const C=u.useCallback((P,A)=>{const L=x(o,n);_.current.set(L,{raw:P,lockVersion:A}),k(F=>{if(F.has(L))return F;const Y=new Set(F);return Y.add(L),Y})},[x,o,n]),S=u.useCallback(P=>{_.current.delete(P),k(A=>{if(!A.has(P))return A;const L=new Set(A);return L.delete(P),L})},[]),D=u.useCallback(P=>{const A=`|${P??""}`,L=[];for(const F of _.current.keys())F.endsWith(A)&&L.push(F);for(const F of L)_.current.delete(F);L.length>0&&k(F=>{let Y=!1;const V=new Set(F);for(const X of L)V.delete(X)&&(Y=!0);return Y?V:F})},[]),E=u.useCallback(async()=>{if(!n){l(null),f(null),g(!1);return}const P=x(o,n),A=_.current.get(P);if(A){l({layoutName:n,raw:A.raw,lockVersion:A.lockVersion}),g(!0),f(null),c(!1),st({op:"load",layoutName:n,editMode:o,statusCode:0,isDirty:!0,timestamp:Date.now()});return}c(!0),f(null);try{const L=window.G7Config?.cache_version??0,F=nn(`/api/layouts/${encodeURIComponent(t)}/${n}`,"json",`${L}.${Op()}`,"with_source_meta=1"),Y=fr(),V={Accept:"application/json"};Y&&(V.Authorization=`Bearer ${Y}`);const X=await fetch(F,{headers:V,credentials:"same-origin"}),Z=await X.json().catch(()=>null);if(!X.ok){f(ei(X.status,Z,"layout")),l(null),g(!1);return}const ie=(Z&&(Z.data||Z))??{},oe=typeof ie.lock_version=="number"?ie.lock_version:0;if(o==="modal"&&r){const ee=ie,fe=Array.isArray(ee.modals)?ee.modals:[],K=fe.findIndex(te=>te&&(te.id===r||te.modal_id===r));if(K>=0){const te=fe[K],ye={...te,props:{...te.props??{},isOpen:!0}},De=[...Array.isArray(ee.components)?ee.components:[],ye],Ie=[De.length-1];l({layoutName:n,raw:{...ee,components:De},lockVersion:oe,modalContext:{modalId:r,modalIndex:K,hostRaw:ee,originalModalNode:te,editIndexPath:Ie}}),g(!1),st({op:"load",layoutName:n,editMode:o,statusCode:X.status,timestamp:Date.now()});return}}if(o==="iteration_item"&&s){const ee=ie,fe=Re(s),K={children:ee.components??[]},te=Pe(K,fe);if(te&&Array.isArray(te.children)){l({layoutName:n,raw:ee,lockVersion:oe,iterationContext:{sourcePath:s,sourceIndexPath:fe,hostRaw:ee}}),g(!1),st({op:"load",layoutName:n,editMode:o,statusCode:X.status,timestamp:Date.now()});return}}l({layoutName:n,raw:ie,lockVersion:oe}),g(!1),st({op:"load",layoutName:n,editMode:o,statusCode:X.status,timestamp:Date.now()})}catch(L){f(lo(L,"layout")),l(null),g(!1)}finally{c(!1)}},[t,n,o,r,s,x]);u.useEffect(()=>{E()},[E]);const I=u.useCallback(async()=>{S(x(o,n)),ca(),y(P=>P+1),await E()},[S,x,o,n,E]),N=u.useCallback(()=>{S(x(o,n))},[S,x,o,n]),T=u.useCallback(P=>{l(A=>{if(!A)return A;const L=A.raw.components??[],F=P(L),Y={...A.raw,components:F};return C(Y,A.lockVersion),{...A,raw:Y}}),g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o,C]),B=u.useCallback(()=>{g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o]),M=u.useCallback(P=>{l(A=>{if(!A)return A;const L={...A.raw,components:P};return C(L,A.lockVersion),{...A,raw:L}}),g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o,C]),O=u.useCallback((P,A,...L)=>{const F=L.length>=1?L[0]:A;l(Y=>{if(!Y)return Y;const V={...Y.raw,[P]:A},X=Y.raw.__editor;if(X&&typeof X=="object"&&!Array.isArray(X)){const Z=X,ie=Z.original;ie&&typeof ie=="object"&&!Array.isArray(ie)&&(V.__editor={...Z,original:{...ie,[P]:F}})}return C(V,Y.lockVersion),{...Y,raw:V}}),g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o,C]),z=u.useCallback(async P=>{const A=$.current;if(!A)return st({op:"save_guard_result",layoutName:n,editMode:o,guardBlocked:!1,timestamp:Date.now()}),{kind:"guard_no_document"};if(P?.resolveActiveExtensions&&P.sessionAddedPaths?.length)try{const fe=await P.resolveActiveExtensions(),K=U7(A.raw.components,P.sessionAddedPaths,fe);if(K.length>0)return st({op:"save_guard_result",layoutName:n,editMode:o,guardBlocked:!0,guardBlockedPaths:K,timestamp:Date.now()}),{kind:"blocked_inactive_extension",blockedPaths:K}}catch{}if(um())try{await pm(t)}catch{}const L=`/api/admin/templates/${encodeURIComponent(t)}/layouts/${A.layoutName}`,F=fr(),Y={Accept:"application/json","Content-Type":"application/json"};F&&(Y.Authorization=`Bearer ${F}`);const V=!!A.modalContext,X=!!A.iterationContext,Z=V||X?"host_layout_modal_patch":"layout";st({op:"save",layoutName:A.layoutName,editMode:o,saveTarget:Z,endpoint:L,isDirty:b,timestamp:Date.now()});let ie;if(V&&A.modalContext){const{modalIndex:fe,hostRaw:K,originalModalNode:te,editIndexPath:ye}=A.modalContext,Se=Array.isArray(K.modals)?[...K.modals]:[],De=Array.isArray(A.raw.components)?A.raw.components:[],Ie=ye&&ye.length===1?ye[0]:0,Ve=De.length>Ie?De[Ie]:void 0,ze=Ve?qn([Ve]):[],Be=ze.length>0?{...ze[0]}:void 0;if(fe>=0&&fe({...Ne,children:De})).children??[];ie={...Ie,components:Xe}}else ie=ko(A.raw);const oe=ie;let G;try{G=await fetch(L,{method:"PUT",headers:Y,credentials:"same-origin",body:JSON.stringify({content:JSON.stringify(oe),expected_lock_version:A.lockVersion})})}catch(fe){const K=fe instanceof Error?fe.message:"network error";return st({op:"save_response",layoutName:A.layoutName,editMode:o,endpoint:L,statusCode:0,timestamp:Date.now()}),{kind:"network_error",message:K}}const ee=await G.json().catch(()=>null);if(st({op:"save_response",layoutName:A.layoutName,editMode:o,endpoint:L,statusCode:G.status,conflict:G.status===409?{currentVersion:ee?.current_version,yourVersion:ee?.your_version}:void 0,timestamp:Date.now()}),G.ok){const fe=typeof ee?.data?.lock_version=="number"?ee.data.lock_version:A.lockVersion+1;l({...A,lockVersion:fe}),g(!1),S(x(o,A.layoutName)),D(A.layoutName),ca(),h(te=>te+1);const K=typeof ee?.data?.current_version=="number"?ee.data.current_version:void 0;return{kind:"success",newLockVersion:fe,newContentVersion:K,savedLayoutName:A.layoutName}}return G.status===409?{kind:"concurrent_modification",currentVersion:ee?.current_version??-1,yourVersion:ee?.your_version??A.lockVersion}:G.status===422?{kind:"validation_failed",status:422,errors:ee?.errors??null}:{kind:"network_error",message:ee?.message??`HTTP ${G.status}`}},[t,n,o,b,S,D,x,r,s]),H=u.useMemo(()=>{const P=new Set,A="route|";for(const L of w)if(L.startsWith(A)){const F=L.slice(A.length);F&&P.add(F)}return P},[w]);return{document:a,isLoading:d,error:p,isDirty:b,saveSuccessCounter:m,reloadCounter:v,dirtyKeys:w,dirtyLayoutNames:H,invalidateCurrentCache:N,reload:I,patchLayout:T,setLayoutComponents:M,patchDocumentRaw:O,save:z,markDirty:B}}function U7(e,t,n){if(!e||e.length===0)return[];const o=[],r=new Set([...n.moduleIds,...n.pluginIds]);for(const s of t){const a=q7(e,s);if(!a)continue;const l=a.__source;if(!l||l.kind!=="extension")continue;const d=String(l.extensionId??"");d.length!==0&&(r.has(d)||o.push(s))}return o}function q7(e,t){const n=Re(t);return n.length===0?null:Pe({children:e},n)}function co(e,t){if(!e)return null;const n=e.getBoundingClientRect();if(n.width===0&&n.height===0)return null;if(!t)return{left:n.left,top:n.top,width:n.width,height:n.height,scale:1};const o=t.getBoundingClientRect();return{left:n.left-o.left,top:n.top-o.top,width:n.width,height:n.height,scale:1}}function uo(e,t){if(!e)return!1;if(!t)return!0;const n=t.getBoundingClientRect(),o=1;return!(e.left>=n.width-o||e.left+e.width<=o||e.top>=n.height-o||e.top+e.height<=o)}function Wp(e,t){if(typeof window>"u")return()=>{};const n=()=>{e()};window.addEventListener("scroll",n,!0),window.addEventListener("resize",n);let o=null;t&&typeof ResizeObserver<"u"&&(o=new ResizeObserver(()=>e()),o.observe(t));let r=null,s=null;const a=typeof requestAnimationFrame<"u",l=()=>{if(!a){e();return}s===null&&(s=requestAnimationFrame(()=>{s=null,e()}))};return t&&typeof MutationObserver<"u"&&(r=new MutationObserver(l),r.observe(t,{childList:!0,subtree:!0})),()=>{window.removeEventListener("scroll",n,!0),window.removeEventListener("resize",n),o&&(o.disconnect(),o=null),r&&(r.disconnect(),r=null),s!==null&&a&&typeof cancelAnimationFrame<"u"&&(cancelAnimationFrame(s),s=null)}}const jp=44;function Hp(e){if(!e)return"inside";const t=e.scale||1,n=e.width*t,o=e.height*t;return n"u"||typeof window.getComputedStyle!="function")return{kind:"unknown",display:"",flexDirection:"",flexWrap:""};let t=e,n=(window.getComputedStyle(t).display??"").toLowerCase();for(;n==="contents"&&t.parentElement;)t=t.parentElement,n=(window.getComputedStyle(t).display??"").toLowerCase();const o=window.getComputedStyle(t),r=(o.display??"").toLowerCase(),s=(o.flexDirection??"").toLowerCase(),a=(o.flexWrap??"").toLowerCase(),l=r==="flex"||r==="inline-flex";if(r==="grid"||r==="inline-grid"){const f=Array.from(e.children).filter(h=>h.offsetParent!==null||h.getClientRects().length>0);if(f.length<=1)return{kind:"grid_2d",display:r,flexDirection:s,flexWrap:a};const b=f.map(h=>h.getBoundingClientRect()),g=new Set(b.map(h=>Math.round(h.top))),m=new Set(b.map(h=>Math.round(h.left)));return g.size===1?{kind:"grid_single_row",display:r,flexDirection:s,flexWrap:a}:m.size===1?{kind:"grid_single_column",display:r,flexDirection:s,flexWrap:a}:{kind:"grid_2d",display:r,flexDirection:s,flexWrap:a}}if(!l)return{kind:"block",display:r,flexDirection:s,flexWrap:a};const c=a==="wrap"||a==="wrap-reverse";return s==="column"||s==="column-reverse"?{kind:c?"flex_column_wrap":"flex_column_single",display:r,flexDirection:s,flexWrap:a}:{kind:c?"flex_row_wrap":"flex_row_single",display:r,flexDirection:s,flexWrap:a}}function Y7(e){const{parentEl:t,selectedPath:n,selectedEl:o,explicitFlow:r}=e;return u.useMemo(()=>{if(!n||n.length===0)return{points:[],flow:"unknown"};const s=r??Vp(t).kind,a=n.slice(0,-1),l=n[n.length-1]??0;if((s==="flex_row_wrap"||s==="flex_column_wrap"||s==="grid_2d")&&!!o){const p=X7(s,o,a,l);if(p)return{points:p,flow:s}}return{points:J7(s,a,l),flow:s}},[t,n,o,r])}function X7(e,t,n,o){let r=t.parentElement;for(;r&&Up(r)==="contents";)r=r.parentElement;if(!r)return null;const s=[];if(qp(r,s),s.length===0)return null;const a=t.getBoundingClientRect(),l=a.top+a.height/2,d=[],c=[],p=[];for(const v of s){const y=v.rect,_=y.top+y.height/2,w=Math.min(a.bottom,y.bottom)-Math.max(a.top,y.top),k=Math.min(a.height,y.height)||1;w/k>.4?d.push({rect:y,path:v.path}):_v.rect.left-y.rect.left),c.sort((v,y)=>v.rect.top-y.rect.top),p.sort((v,y)=>v.rect.top-y.rect.top);const f=d.findIndex(v=>Math.abs(v.rect.left-a.left)<1&&Math.abs(v.rect.top-a.top)<1),b={direction:"above",disabled:!0,insertion:null},g={direction:"below",disabled:!0,insertion:null},m={direction:"left",disabled:!0,insertion:null},h={direction:"right",disabled:!0,insertion:null};if(f>0){const v=d[f-1],y=ni(v.path);y&&(m.disabled=!1,m.insertion=y)}else if(d.length>0){const v=d[0],y=ti(v.path);y&&(m.disabled=!1,m.insertion=y)}if(f>=0&&f0){const v=d[d.length-1],y=ni(v.path);y&&(h.disabled=!1,h.insertion=y)}if(c.length>0){const v=c[c.length-1],y=ni(v.path);y&&(b.disabled=!1,b.insertion=y)}else if(s.length>0){const v=s[0],y=ti(v.path);y&&(b.disabled=!1,b.insertion=y)}if(p.length>0){const v=p[0],y=ti(v.path);y&&(g.disabled=!1,g.insertion=y)}else if(s.length>0){const v=s[s.length-1],y=ni(v.path);y&&(g.disabled=!1,g.insertion=y)}else g.disabled=!1,g.insertion={parentPath:n,index:o+1};return b.disabled&&g.disabled&&m.disabled&&h.disabled?null:[b,g,m,h]}function Up(e){return typeof window>"u"?"":(window.getComputedStyle(e).display??"").toLowerCase()}function qp(e,t){const n=Array.from(e.children);for(const o of n){if(Up(o)==="contents"){qp(o,t);continue}const s=o.getAttribute("data-editor-path");if(s&&/\.iteration\.\d+(?:$|\.)/.test(s)||!s)continue;const a=o.getBoundingClientRect();a.width===0&&a.height===0||t.push({el:o,rect:a,path:Re(s)})}}function ti(e){if(!e||e.length===0)return null;const t=e[e.length-1];return typeof t!="number"?null:{parentPath:e.slice(0,-1),index:t}}function ni(e){if(!e||e.length===0)return null;const t=e[e.length-1];return typeof t!="number"?null:{parentPath:e.slice(0,-1),index:t+1}}function J7(e,t,n){const o={direction:"above",disabled:!0,insertion:null},r={direction:"below",disabled:!0,insertion:null},s={direction:"left",disabled:!0,insertion:null},a={direction:"right",disabled:!0,insertion:null},l=d=>({parentPath:t,index:d});switch(e){case"block":case"unknown":{o.disabled=!1,o.insertion=l(n),r.disabled=!1,r.insertion=l(n+1);break}case"flex_row_single":case"grid_single_row":{s.disabled=!1,s.insertion=l(n),a.disabled=!1,a.insertion=l(n+1);break}case"flex_column_single":case"grid_single_column":{o.disabled=!1,o.insertion=l(n),r.disabled=!1,r.insertion=l(n+1);break}case"flex_row_wrap":case"grid_2d":{s.disabled=!1,s.insertion=l(n),a.disabled=!1,a.insertion=l(n+1),o.disabled=!1,o.insertion=l(0),r.disabled=!1,r.insertion=l(-1);break}case"flex_column_wrap":{o.disabled=!1,o.insertion=l(n),r.disabled=!1,r.insertion=l(n+1),s.disabled=!1,s.insertion=l(0),a.disabled=!1,a.insertion=l(-1);break}}return[o,r,s,a]}function Z7(e=50){const t=u.useRef([]),n=u.useRef(-1),[,o]=u.useState(0),r=()=>{o(p=>(p+1)%1e6)},s=(p,f)=>{const b=t.current.length,g=n.current;by({op:p,actionKind:f?.actionKind,label:f?.label,stackSize:b,cursor:g,canUndo:g>0,canRedo:g>=0&&g{const b=t.current.slice(0,n.current+1);for(b.push(p);b.length>e;)b.shift();t.current=b,n.current=b.length-1,r(),s("push",p)},[e]),l=u.useCallback(()=>{if(n.current<=0)return null;n.current-=1,r();const p=t.current[n.current]??null;return s("undo",p??void 0),p},[]),d=u.useCallback(()=>{const p=n.current+1;if(p>=t.current.length)return null;n.current=p,r();const f=t.current[p]??null;return s("redo",f??void 0),f},[]),c=u.useCallback(()=>{t.current=[],n.current=-1,r(),s("clear")},[]);return{push:a,undo:l,redo:d,clear:c,canUndo:n.current>0,canRedo:n.current>=0&&n.current{if(!o||typeof window>"u")return;const r=s=>{if(Q7(s.target)||!(s.ctrlKey||s.metaKey))return;const l=s.key.toLowerCase();if(l==="z"&&!s.shiftKey){s.preventDefault(),t();return}if(l==="z"&&s.shiftKey||l==="y"){s.preventDefault(),n();return}};return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[t,n,o])}const e2=20,Gp=50,t2=90,On=120,n2=130,Yp=80,o2=9e3,Xp=1e4;function r2(e){const t=e<0?0:e>Gp?Gp:e;return e2+t}function i2(e){const{anchor:t,open:n,onClose:o,onEditProps:r,onDuplicate:s,onDelete:a,onSeparateBranch:l,separateBranchLabel:d,onMergeBranch:c,mergeBranchLabel:p}=e,{t:f}=et(),[b,g]=u.useState(null);if(!n||!t)return null;const m=[{index:0,testid:"g7le-context-menu-edit-props",label:f("layout_editor.context_menu.edit_props"),onSelect:r},{index:1,testid:"g7le-context-menu-duplicate",label:f("layout_editor.context_menu.duplicate"),onSelect:s}];return l?m.push({index:m.length,testid:"g7le-context-menu-separate-branch",label:d??f("layout_editor.context_menu.separate_branch"),onSelect:l,hint:f("layout_editor.context_menu.separate_branch_hint")}):c&&m.push({index:m.length,testid:"g7le-context-menu-merge-branch",label:p??f("layout_editor.context_menu.merge_branch"),onSelect:c,hint:f("layout_editor.context_menu.merge_branch_hint")}),m.push({index:m.length,testid:"g7le-context-menu-delete",label:f("layout_editor.context_menu.delete"),onSelect:a,danger:!0}),i.jsx("div",{className:"g7le-context-menu","data-testid":"g7le-context-menu",role:"menu",style:{position:"absolute",left:t.left,top:t.top,background:"#fff",border:"1px solid #cbd5e1",borderRadius:6,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:1200,minWidth:160,padding:4,pointerEvents:"auto"},onMouseLeave:()=>{g(null),o()},children:m.map(h=>{const v=b===h.index,y=h.danger?"#dc2626":"#0f172a",_=h.danger?"#fee2e2":"#e0e7ff",w=h.danger?"#b91c1c":"#1d4ed8";return i.jsx("button",{type:"button",role:"menuitem","data-testid":h.testid,title:h.hint,onClick:k=>{k.stopPropagation(),h.onSelect(),g(null),o()},onMouseEnter:()=>g(h.index),onFocus:()=>g(h.index),style:{...s2,color:v?w:y,background:v?_:"transparent"},children:h.label},h.testid)})})}const s2={display:"block",width:"100%",textAlign:"left",padding:"6px 12px",border:"none",fontSize:13,cursor:"pointer",borderRadius:4,pointerEvents:"auto",transition:"background-color 120ms ease, color 120ms ease"};function a2(e){const{hoverBox:t,selectedBox:n,lockKind:o,navAffordance:r,onEditProps:s,onDuplicate:a,onDelete:l,onSeparateBranch:d,separateBranchLabel:c,onMergeBranch:p,mergeBranchLabel:f,definedDeviceBranches:b,onJumpToDevice:g,onLinkEditDestination:m,onEditBase:h,onEditExtension:v,extensionLabel:y,baseLayoutLabel:_,dataSourceLabel:w,branchLabel:k,onEditIteration:x,resizeEnabledAxes:$,onResizeHandlePointerDown:C,selectedName:S,onSelectParent:D}=e,{t:E}=et(),[I,N]=u.useState(!1),T=Np(o),B=I&&T,M=Hp(n),O=M==="outside",z=O&&n?Kp(n):null,H=z?{left:z.right.left,top:z.above.top}:{right:-30,top:-30},P={top:-28,left:0},L=O&&!!S?{top:-50,left:0}:P,F=z?{top:z.below.top+28,left:0}:{top:"auto",bottom:-28},Y=z?{top:z.below.top+56,left:0}:{top:"auto",bottom:-56};return i.jsxs("div",{className:"g7le-element-overlay","data-testid":"g7le-element-overlay",style:{position:"absolute",inset:0,pointerEvents:"none"},children:[t&&i.jsx("div",{"data-testid":"g7le-overlay-hover",style:{position:"absolute",left:t.left,top:t.top,width:t.width,height:t.height,border:"1px dashed #2563eb",pointerEvents:"none"}}),n&&i.jsxs("div",{"data-testid":"g7le-overlay-selected","data-lock-kind":o,style:{position:"absolute",left:n.left,top:n.top,width:n.width,height:n.height,border:o==="none"?"2px solid #2563eb":"2px dashed #f59e0b",pointerEvents:"none"},children:[k?i.jsxs("span",{"data-testid":"g7le-overlay-branch-badge",style:d2,children:["📱 ",k]}):null,S&&(D?i.jsxs("button",{type:"button","data-testid":"g7le-overlay-type-label","data-placement":O?"outside":"inside",title:E("layout_editor.overlay.select_parent"),"aria-label":E("layout_editor.overlay.select_parent"),onClick:V=>{V.preventDefault(),V.stopPropagation(),D()},style:O?u2:c2,children:[i.jsx("span",{"aria-hidden":!0,style:{marginRight:3,opacity:.85},children:"↑"}),S]}):i.jsx("span",{"data-testid":"g7le-overlay-type-label","data-placement":O?"outside":"inside",style:O?Zp:Jp,children:S})),T&&i.jsx("button",{type:"button","data-testid":"g7le-overlay-info-button","aria-label":"info",onClick:V=>{V.stopPropagation(),N(X=>!X)},"data-placement":M,style:{position:"absolute",...H,width:20,height:20,borderRadius:10,border:"1px solid #2563eb",background:"#fff",color:"#2563eb",fontSize:12,fontWeight:700,cursor:"pointer",pointerEvents:"auto",padding:0,lineHeight:"18px",zIndex:On},children:"ⓘ"}),o==="none"&&i.jsx(l2,{enabledAxes:$,onHandlePointerDown:C}),o==="base"&&h&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-edit-base",onClick:V=>{V.stopPropagation(),h()},style:{...Fo,...P},children:["🔒 ",E("layout_editor.overlay.edit_common_layout"),_?i.jsx("span",{"data-testid":"g7le-overlay-base-layout-label",style:pa,children:_}):null]}),o==="extension"&&v&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-edit-extension",onClick:V=>{V.stopPropagation(),v()},style:{...Fo,...P},children:["🔒 ",E("layout_editor.overlay.edit_extension"),y?i.jsx("span",{"data-testid":"g7le-overlay-extension-label",style:pa,children:y}):null]}),o==="data_bound"&&i.jsxs("span",{"data-testid":"g7le-overlay-data-bound-notice",style:{...Fo,...L,pointerEvents:"none",cursor:"default"},children:[E("layout_editor.overlay.locked_data_bound"),w?i.jsx("span",{"data-testid":"g7le-overlay-data-source-label",style:pa,children:w}):null]}),o==="data_bound"&&x&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-edit-iteration",onClick:V=>{V.stopPropagation(),x()},style:{...Fo,...F},children:["↳ ",E("layout_editor.overlay.edit_iteration_item")]}),r==="route_in_tree"&&i.jsx("button",{type:"button","data-testid":"g7le-overlay-link-edit-destination",onClick:V=>{V.stopPropagation(),m()},style:{...Fo,...F},children:E("layout_editor.overlay.edit_destination_route")}),(d||p||g&&(b??[]).length>0)&&i.jsxs("div",{"data-testid":"g7le-overlay-branch-affordances",style:{position:"absolute",...Y,display:"flex",flexDirection:"column",alignItems:"flex-start",gap:4,pointerEvents:"none"},children:[g&&(b??[]).map(V=>i.jsxs("button",{type:"button","data-testid":`g7le-overlay-jump-device-${V.key}`,title:E("layout_editor.overlay.jump_device_hint",{device:V.label}),onClick:X=>{X.stopPropagation(),g(V.key)},style:ua,children:["↗ ",E("layout_editor.overlay.jump_device",{device:V.label})]},V.key)),d&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-separate-branch",title:E("layout_editor.context_menu.separate_branch_hint"),onClick:V=>{V.stopPropagation(),d()},style:ua,children:["📱 ",c??E("layout_editor.context_menu.separate_branch")]}),p&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-merge-branch",title:E("layout_editor.context_menu.merge_branch_hint"),onClick:V=>{V.stopPropagation(),p()},style:ua,children:["↩️ ",f??E("layout_editor.context_menu.merge_branch")]})]})]}),i.jsx(i2,{anchor:n&&B?{left:n.left+n.width+8,top:n.top-4}:null,open:B,onClose:()=>N(!1),onEditProps:s,onDuplicate:a,onDelete:l,onSeparateBranch:d,separateBranchLabel:c,onMergeBranch:p,mergeBranchLabel:f})]})}function l2(e){const{enabledAxes:t,onHandlePointerDown:n}=e,o=t?.width??!1,r=t?.height??!1,s=[{key:"nw",style:{left:-4,top:-4},cursor:"nwse-resize",needsWidth:!0,needsHeight:!0},{key:"n",style:{left:"50%",top:-4,transform:"translateX(-50%)"},cursor:"ns-resize",needsWidth:!1,needsHeight:!0},{key:"ne",style:{right:-4,top:-4},cursor:"nesw-resize",needsWidth:!0,needsHeight:!0},{key:"e",style:{right:-4,top:"50%",transform:"translateY(-50%)"},cursor:"ew-resize",needsWidth:!0,needsHeight:!1},{key:"se",style:{right:-4,bottom:-4},cursor:"nwse-resize",needsWidth:!0,needsHeight:!0},{key:"s",style:{left:"50%",bottom:-4,transform:"translateX(-50%)"},cursor:"ns-resize",needsWidth:!1,needsHeight:!0},{key:"sw",style:{left:-4,bottom:-4},cursor:"nesw-resize",needsWidth:!0,needsHeight:!0},{key:"w",style:{left:-4,top:"50%",transform:"translateY(-50%)"},cursor:"ew-resize",needsWidth:!0,needsHeight:!1}];return i.jsx(i.Fragment,{children:s.map(a=>{const l=!a.needsWidth||o,d=!a.needsHeight||r,c=l&&d&&!!n;return!l||!d?null:i.jsx("span",{"data-testid":`g7le-resize-handle-${a.key}`,"data-resize-handle-active":c?"true":"false",onPointerDown:c?p=>{p.preventDefault(),p.stopPropagation(),n?.(a.key,{clientX:p.clientX,clientY:p.clientY})}:void 0,style:{position:"absolute",...a.style,width:8,height:8,background:"#fff",border:"1px solid #2563eb",cursor:a.cursor,pointerEvents:c?"auto":"none",zIndex:On}},a.key)})})}const Fo={position:"absolute",top:-28,left:0,background:"#fff",border:"1px solid #2563eb",color:"#2563eb",padding:"2px 6px",fontSize:11,borderRadius:4,cursor:"pointer",pointerEvents:"auto",whiteSpace:"nowrap",zIndex:On},ua={background:"#fff",border:"1px solid #2563eb",color:"#2563eb",padding:"2px 6px",fontSize:11,borderRadius:4,cursor:"pointer",pointerEvents:"auto",whiteSpace:"nowrap",zIndex:On},pa={marginLeft:6,padding:"0 5px",borderRadius:3,background:"#eef2ff",border:"1px solid #c7d2fe",fontSize:10,fontWeight:600,color:"#3730a3"},d2={position:"absolute",top:0,right:0,transform:"translateY(-100%)",background:"rgba(124,58,237,0.92)",color:"#fff",padding:"1px 6px",borderRadius:"3px 3px 0 0",fontSize:10,fontWeight:600,whiteSpace:"nowrap",pointerEvents:"none"},Jp={position:"absolute",top:0,left:0,background:"rgba(37,99,235,0.55)",color:"#fff",padding:"1px 6px",fontSize:10,fontWeight:600,lineHeight:"14px",borderBottomRightRadius:4,letterSpacing:"0.02em",whiteSpace:"nowrap",pointerEvents:"none",userSelect:"none",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis"},Zp={position:"absolute",bottom:"100%",left:0,marginBottom:2,background:"rgba(37,99,235,0.55)",color:"#fff",padding:"1px 6px",fontSize:10,fontWeight:600,lineHeight:"14px",borderRadius:4,letterSpacing:"0.02em",whiteSpace:"nowrap",pointerEvents:"none",userSelect:"none"},c2={...Jp,pointerEvents:"auto",cursor:"pointer",background:"rgba(37,99,235,0.82)",border:"none",display:"inline-flex",alignItems:"center",font:"inherit",fontSize:10,fontWeight:600,zIndex:On},u2={...Zp,pointerEvents:"auto",cursor:"pointer",background:"rgba(37,99,235,0.82)",border:"none",display:"inline-flex",alignItems:"center",font:"inherit",fontSize:10,fontWeight:600,zIndex:On},p2={above:{top:-30,left:"50%",transform:"translateX(-50%)"},below:{bottom:-30,left:"50%",transform:"translateX(-50%)"},left:{left:-30,top:"50%",transform:"translateY(-50%)"},right:{right:-30,top:"50%",transform:"translateY(-50%)"}};function f2(e){const{selectedBox:t,points:n,onAddRequest:o}=e,{t:r}=et();if(!t||n.length===0)return null;const s=Hp(t),l=s==="outside"?Kp(t):null;return i.jsx("div",{className:"g7le-insertion-affordances","data-testid":"g7le-insertion-affordances",style:{position:"absolute",left:t.left,top:t.top,width:t.width,height:t.height,pointerEvents:"none"},children:n.map(d=>{const c=l?{left:l[d.direction].left,top:l[d.direction].top}:p2[d.direction],p=r(`layout_editor.insertion.${d.direction}`);return i.jsx("button",{type:"button",disabled:d.disabled,"data-testid":`g7le-insertion-${d.direction}`,"data-disabled":d.disabled?"true":"false","data-placement":s,"aria-label":p,title:p,onClick:f=>{f.stopPropagation(),d.disabled||o(d)},style:{position:"absolute",...c,width:24,height:24,borderRadius:12,border:"1px solid #2563eb",background:d.disabled?"#cbd5e1":"#fff",color:d.disabled?"#94a3b8":"#2563eb",cursor:d.disabled?"not-allowed":"pointer",opacity:d.disabled?.4:1,fontSize:16,fontWeight:700,lineHeight:"20px",padding:0,pointerEvents:"auto",boxShadow:"0 1px 3px rgba(0,0,0,0.15)",zIndex:On},children:"+"},d.direction)})})}const oi=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function po(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function fa(e){return"nodeType"in e}function xt(e){var t,n;return e?po(e)?e:fa(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function ga(e){const{Document:t}=xt(e);return e instanceof t}function Ko(e){return po(e)?!1:e instanceof xt(e).HTMLElement}function Qp(e){return e instanceof xt(e).SVGElement}function fo(e){return e?po(e)?e.document:fa(e)?ga(e)?e:Ko(e)||Qp(e)?e.ownerDocument:document:document:document}const ln=oi?u.useLayoutEffect:u.useEffect;function ri(e){const t=u.useRef(e);return ln(()=>{t.current=e}),u.useCallback(function(){for(var n=arguments.length,o=new Array(n),r=0;r{e.current=setInterval(o,r)},[]),n=u.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function Vo(e,t){t===void 0&&(t=[e]);const n=u.useRef(e);return ln(()=>{n.current!==e&&(n.current=e)},t),n}function Uo(e,t){const n=u.useRef();return u.useMemo(()=>{const o=e(n.current);return n.current=o,o},[...t])}function ii(e){const t=ri(e),n=u.useRef(null),o=u.useCallback(r=>{r!==n.current&&t?.(r,n.current),n.current=r},[]);return[n,o]}function si(e){const t=u.useRef();return u.useEffect(()=>{t.current=e},[e]),t.current}let ha={};function ai(e,t){return u.useMemo(()=>{if(t)return t;const n=ha[e]==null?0:ha[e]+1;return ha[e]=n,e+"-"+n},[e,t])}function Rp(e){return function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r{const l=Object.entries(a);for(const[d,c]of l){const p=s[d];p!=null&&(s[d]=p+e*c)}return s},{...t})}}const go=Rp(1),li=Rp(-1);function h2(e){return"clientX"in e&&"clientY"in e}function ya(e){if(!e)return!1;const{KeyboardEvent:t}=xt(e.target);return t&&e instanceof t}function y2(e){if(!e)return!1;const{TouchEvent:t}=xt(e.target);return t&&e instanceof t}function di(e){if(y2(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return h2(e)?{x:e.clientX,y:e.clientY}:null}const qo=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[qo.Translate.toString(e),qo.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:o}=e;return t+" "+n+"ms "+o}}}),ef="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function b2(e){return e.matches(ef)?e:e.querySelector(ef)}const m2={display:"none"};function v2(e){let{id:t,value:n}=e;return u.createElement("div",{id:t,style:m2},n)}function _2(e){let{id:t,announcement:n,ariaLiveType:o="assertive"}=e;const r={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return u.createElement("div",{id:t,style:r,role:"status","aria-live":o,"aria-atomic":!0},n)}function x2(){const[e,t]=u.useState("");return{announce:u.useCallback(o=>{o!=null&&t(o)},[]),announcement:e}}const tf=u.createContext(null);function w2(e){const t=u.useContext(tf);u.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of ");return t(e)},[e,t])}function k2(){const[e]=u.useState(()=>new Set),t=u.useCallback(o=>(e.add(o),()=>e.delete(o)),[e]);return[u.useCallback(o=>{let{type:r,event:s}=o;e.forEach(a=>{var l;return(l=a[r])==null?void 0:l.call(a,s)})},[e]),t]}const S2={draggable:` To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel. `},C2={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function $2(e){let{announcements:t=C2,container:n,hiddenTextDescribedById:o,screenReaderInstructions:r=S2}=e;const{announce:s,announcement:a}=x2(),l=ai("DndLiveRegion"),[d,c]=u.useState(!1);if(u.useEffect(()=>{c(!0)},[]),w2(u.useMemo(()=>({onDragStart(f){let{active:b}=f;s(t.onDragStart({active:b}))},onDragMove(f){let{active:b,over:g}=f;t.onDragMove&&s(t.onDragMove({active:b,over:g}))},onDragOver(f){let{active:b,over:g}=f;s(t.onDragOver({active:b,over:g}))},onDragEnd(f){let{active:b,over:g}=f;s(t.onDragEnd({active:b,over:g}))},onDragCancel(f){let{active:b,over:g}=f;s(t.onDragCancel({active:b,over:g}))}}),[s,t])),!d)return null;const p=u.createElement(u.Fragment,null,u.createElement(v2,{id:o,value:r.draggable}),u.createElement(_2,{id:l,announcement:a}));return n?En.createPortal(p,n):p}var it;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(it||(it={}));function ci(){}function E2(e,t){return u.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function I2(){for(var e=arguments.length,t=new Array(e),n=0;n[...t].filter(o=>o!=null),[...t])}const Ft=Object.freeze({x:0,y:0});function A2(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function T2(e,t){const n=di(e);if(!n)return"0 0";const o={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return o.x+"% "+o.y+"%"}function D2(e,t){let{data:{value:n}}=e,{data:{value:o}}=t;return n-o}function z2(e,t){let{data:{value:n}}=e,{data:{value:o}}=t;return o-n}function N2(e){let{left:t,top:n,height:o,width:r}=e;return[{x:t,y:n},{x:t+r,y:n},{x:t,y:n+o},{x:t+r,y:n+o}]}function M2(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function L2(e,t){const n=Math.max(t.top,e.top),o=Math.max(t.left,e.left),r=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),a=r-o,l=s-n;if(o{let{collisionRect:t,droppableRects:n,droppableContainers:o}=e;const r=[];for(const s of o){const{id:a}=s,l=n.get(a);if(l){const d=L2(l,t);d>0&&r.push({id:a,data:{droppableContainer:s,value:d}})}}return r.sort(z2)};function O2(e,t){const{top:n,left:o,bottom:r,right:s}=t;return n<=e.y&&e.y<=r&&o<=e.x&&e.x<=s}const B2=e=>{let{droppableContainers:t,droppableRects:n,pointerCoordinates:o}=e;if(!o)return[];const r=[];for(const s of t){const{id:a}=s,l=n.get(a);if(l&&O2(o,l)){const c=N2(l).reduce((f,b)=>f+A2(o,b),0),p=Number((c/4).toFixed(4));r.push({id:a,data:{droppableContainer:s,value:p}})}}return r.sort(D2)};function W2(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function nf(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Ft}function j2(e){return function(n){for(var o=arguments.length,r=new Array(o>1?o-1:0),s=1;s({...a,top:a.top+e*l.y,bottom:a.bottom+e*l.y,left:a.left+e*l.x,right:a.right+e*l.x}),{...n})}}const H2=j2(1);function of(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function F2(e,t,n){const o=of(t);if(!o)return e;const{scaleX:r,scaleY:s,x:a,y:l}=o,d=e.left-a-(1-r)*parseFloat(n),c=e.top-l-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),p=r?e.width/r:e.width,f=s?e.height/s:e.height;return{width:p,height:f,top:c,right:d+p,bottom:c+f,left:d}}const K2={ignoreTransform:!1};function Go(e,t){t===void 0&&(t=K2);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:c,transformOrigin:p}=xt(e).getComputedStyle(e);c&&(n=F2(n,c,p))}const{top:o,left:r,width:s,height:a,bottom:l,right:d}=n;return{top:o,left:r,width:s,height:a,bottom:l,right:d}}function rf(e){return Go(e,{ignoreTransform:!0})}function V2(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function U2(e,t){return t===void 0&&(t=xt(e).getComputedStyle(e)),t.position==="fixed"}function q2(e,t){t===void 0&&(t=xt(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const s=t[r];return typeof s=="string"?n.test(s):!1})}function ba(e,t){const n=[];function o(r){if(t!=null&&n.length>=t||!r)return n;if(ga(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!Ko(r)||Qp(r)||n.includes(r))return n;const s=xt(e).getComputedStyle(r);return r!==e&&q2(r,s)&&n.push(r),U2(r,s)?n:o(r.parentNode)}return e?o(e):n}function sf(e){const[t]=ba(e,1);return t??null}function ma(e){return!oi||!e?null:po(e)?e:fa(e)?ga(e)||e===fo(e).scrollingElement?window:Ko(e)?e:null:null}function af(e){return po(e)?e.scrollX:e.scrollLeft}function lf(e){return po(e)?e.scrollY:e.scrollTop}function va(e){return{x:af(e),y:lf(e)}}var lt;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(lt||(lt={}));function df(e){return!oi||!e?!1:e===document.scrollingElement}function cf(e){const t={x:0,y:0},n=df(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},o={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},r=e.scrollTop<=t.y,s=e.scrollLeft<=t.x,a=e.scrollTop>=o.y,l=e.scrollLeft>=o.x;return{isTop:r,isLeft:s,isBottom:a,isRight:l,maxScroll:o,minScroll:t}}const G2={x:.2,y:.2};function Y2(e,t,n,o,r){let{top:s,left:a,right:l,bottom:d}=n;o===void 0&&(o=10),r===void 0&&(r=G2);const{isTop:c,isBottom:p,isLeft:f,isRight:b}=cf(e),g={x:0,y:0},m={x:0,y:0},h={height:t.height*r.y,width:t.width*r.x};return!c&&s<=t.top+h.height?(g.y=lt.Backward,m.y=o*Math.abs((t.top+h.height-s)/h.height)):!p&&d>=t.bottom-h.height&&(g.y=lt.Forward,m.y=o*Math.abs((t.bottom-h.height-d)/h.height)),!b&&l>=t.right-h.width?(g.x=lt.Forward,m.x=o*Math.abs((t.right-h.width-l)/h.width)):!f&&a<=t.left+h.width&&(g.x=lt.Backward,m.x=o*Math.abs((t.left+h.width-a)/h.width)),{direction:g,speed:m}}function X2(e){if(e===document.scrollingElement){const{innerWidth:s,innerHeight:a}=window;return{top:0,left:0,right:s,bottom:a,width:s,height:a}}const{top:t,left:n,right:o,bottom:r}=e.getBoundingClientRect();return{top:t,left:n,right:o,bottom:r,width:e.clientWidth,height:e.clientHeight}}function uf(e){return e.reduce((t,n)=>go(t,va(n)),Ft)}function J2(e){return e.reduce((t,n)=>t+af(n),0)}function Z2(e){return e.reduce((t,n)=>t+lf(n),0)}function pf(e,t){if(t===void 0&&(t=Go),!e)return;const{top:n,left:o,bottom:r,right:s}=t(e);sf(e)&&(r<=0||s<=0||n>=window.innerHeight||o>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const Q2=[["x",["left","right"],J2],["y",["top","bottom"],Z2]];class _a{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const o=ba(n),r=uf(o);this.rect={...t},this.width=t.width,this.height=t.height;for(const[s,a,l]of Q2)for(const d of a)Object.defineProperty(this,d,{get:()=>{const c=l(o),p=r[s]-c;return this.rect[d]+p},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Yo{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var o;return(o=this.target)==null?void 0:o.removeEventListener(...n)})},this.target=t}add(t,n,o){var r;(r=this.target)==null||r.addEventListener(t,n,o),this.listeners.push([t,n,o])}}function R2(e){const{EventTarget:t}=xt(e);return e instanceof t?e:fo(e)}function xa(e,t){const n=Math.abs(e.x),o=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+o**2)>t:"x"in t&&"y"in t?n>t.x&&o>t.y:"x"in t?n>t.x:"y"in t?o>t.y:!1}var At;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(At||(At={}));function ff(e){e.preventDefault()}function eI(e){e.stopPropagation()}var Fe;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Fe||(Fe={}));const gf={start:[Fe.Space,Fe.Enter],cancel:[Fe.Esc],end:[Fe.Space,Fe.Enter,Fe.Tab]},tI=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Fe.Right:return{...n,x:n.x+25};case Fe.Left:return{...n,x:n.x-25};case Fe.Down:return{...n,y:n.y+25};case Fe.Up:return{...n,y:n.y-25}}};class hf{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new Yo(fo(n)),this.windowListeners=new Yo(xt(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(At.Resize,this.handleCancel),this.windowListeners.add(At.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(At.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,o=t.node.current;o&&pf(o),n(Ft)}handleKeyDown(t){if(ya(t)){const{active:n,context:o,options:r}=this.props,{keyboardCodes:s=gf,coordinateGetter:a=tI,scrollBehavior:l="smooth"}=r,{code:d}=t;if(s.end.includes(d)){this.handleEnd(t);return}if(s.cancel.includes(d)){this.handleCancel(t);return}const{collisionRect:c}=o.current,p=c?{x:c.left,y:c.top}:Ft;this.referenceCoordinates||(this.referenceCoordinates=p);const f=a(t,{active:n,context:o.current,currentCoordinates:p});if(f){const b=li(f,p),g={x:0,y:0},{scrollableAncestors:m}=o.current;for(const h of m){const v=t.code,{isTop:y,isRight:_,isLeft:w,isBottom:k,maxScroll:x,minScroll:$}=cf(h),C=X2(h),S={x:Math.min(v===Fe.Right?C.right-C.width/2:C.right,Math.max(v===Fe.Right?C.left:C.left+C.width/2,f.x)),y:Math.min(v===Fe.Down?C.bottom-C.height/2:C.bottom,Math.max(v===Fe.Down?C.top:C.top+C.height/2,f.y))},D=v===Fe.Right&&!_||v===Fe.Left&&!w,E=v===Fe.Down&&!k||v===Fe.Up&&!y;if(D&&S.x!==f.x){const I=h.scrollLeft+b.x,N=v===Fe.Right&&I<=x.x||v===Fe.Left&&I>=$.x;if(N&&!b.y){h.scrollTo({left:I,behavior:l});return}N?g.x=h.scrollLeft-I:g.x=v===Fe.Right?h.scrollLeft-x.x:h.scrollLeft-$.x,g.x&&h.scrollBy({left:-g.x,behavior:l});break}else if(E&&S.y!==f.y){const I=h.scrollTop+b.y,N=v===Fe.Down&&I<=x.y||v===Fe.Up&&I>=$.y;if(N&&!b.x){h.scrollTo({top:I,behavior:l});return}N?g.y=h.scrollTop-I:g.y=v===Fe.Down?h.scrollTop-x.y:h.scrollTop-$.y,g.y&&h.scrollBy({top:-g.y,behavior:l});break}}this.handleMove(t,go(li(f,this.referenceCoordinates),g))}}}handleMove(t,n){const{onMove:o}=this.props;t.preventDefault(),o(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}hf.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:o=gf,onActivation:r}=t,{active:s}=n;const{code:a}=e.nativeEvent;if(o.start.includes(a)){const l=s.activatorNode.current;return l&&e.target!==l?!1:(e.preventDefault(),r?.({event:e.nativeEvent}),!0)}return!1}}];function yf(e){return!!(e&&"distance"in e)}function bf(e){return!!(e&&"delay"in e)}class wa{constructor(t,n,o){var r;o===void 0&&(o=R2(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:s}=t,{target:a}=s;this.props=t,this.events=n,this.document=fo(a),this.documentListeners=new Yo(this.document),this.listeners=new Yo(o),this.windowListeners=new Yo(xt(a)),this.initialCoordinates=(r=di(s))!=null?r:Ft,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:o}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(At.Resize,this.handleCancel),this.windowListeners.add(At.DragStart,ff),this.windowListeners.add(At.VisibilityChange,this.handleCancel),this.windowListeners.add(At.ContextMenu,ff),this.documentListeners.add(At.Keydown,this.handleKeydown),n){if(o!=null&&o({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(bf(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(yf(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:o,onPending:r}=this.props;r(o,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(At.Click,eI,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(At.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:o,initialCoordinates:r,props:s}=this,{onMove:a,options:{activationConstraint:l}}=s;if(!r)return;const d=(n=di(t))!=null?n:Ft,c=li(r,d);if(!o&&l){if(yf(l)){if(l.tolerance!=null&&xa(c,l.tolerance))return this.handleCancel();if(xa(c,l.distance))return this.handleStart()}if(bf(l)&&xa(c,l.tolerance))return this.handleCancel();this.handlePending(l,c);return}t.cancelable&&t.preventDefault(),a(d)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Fe.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const nI={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ka extends wa{constructor(t){const{event:n}=t,o=fo(n.target);super(t,nI,o)}}ka.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:o}=t;return!n.isPrimary||n.button!==0?!1:(o?.({event:n}),!0)}}];const oI={move:{name:"mousemove"},end:{name:"mouseup"}};var Sa;(function(e){e[e.RightClick=2]="RightClick"})(Sa||(Sa={}));class rI extends wa{constructor(t){super(t,oI,fo(t.event.target))}}rI.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:o}=t;return n.button===Sa.RightClick?!1:(o?.({event:n}),!0)}}];const Ca={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class iI extends wa{constructor(t){super(t,Ca)}static setup(){return window.addEventListener(Ca.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Ca.move.name,t)};function t(){}}}iI.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:o}=t;const{touches:r}=n;return r.length>1?!1:(o?.({event:n}),!0)}}];var Xo;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Xo||(Xo={}));var ui;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(ui||(ui={}));function sI(e){let{acceleration:t,activator:n=Xo.Pointer,canScroll:o,draggingRect:r,enabled:s,interval:a=5,order:l=ui.TreeOrder,pointerCoordinates:d,scrollableAncestors:c,scrollableAncestorRects:p,delta:f,threshold:b}=e;const g=lI({delta:f,disabled:!s}),[m,h]=g2(),v=u.useRef({x:0,y:0}),y=u.useRef({x:0,y:0}),_=u.useMemo(()=>{switch(n){case Xo.Pointer:return d?{top:d.y,bottom:d.y,left:d.x,right:d.x}:null;case Xo.DraggableRect:return r}},[n,r,d]),w=u.useRef(null),k=u.useCallback(()=>{const $=w.current;if(!$)return;const C=v.current.x*y.current.x,S=v.current.y*y.current.y;$.scrollBy(C,S)},[]),x=u.useMemo(()=>l===ui.TreeOrder?[...c].reverse():c,[l,c]);u.useEffect(()=>{if(!s||!c.length||!_){h();return}for(const $ of x){if(o?.($)===!1)continue;const C=c.indexOf($),S=p[C];if(!S)continue;const{direction:D,speed:E}=Y2($,S,_,t,b);for(const I of["x","y"])g[I][D[I]]||(E[I]=0,D[I]=0);if(E.x>0||E.y>0){h(),w.current=$,m(k,a),v.current=E,y.current=D;return}}v.current={x:0,y:0},y.current={x:0,y:0},h()},[t,k,o,h,s,a,JSON.stringify(_),JSON.stringify(g),m,c,x,p,JSON.stringify(b)])}const aI={x:{[lt.Backward]:!1,[lt.Forward]:!1},y:{[lt.Backward]:!1,[lt.Forward]:!1}};function lI(e){let{delta:t,disabled:n}=e;const o=si(t);return Uo(r=>{if(n||!o||!r)return aI;const s={x:Math.sign(t.x-o.x),y:Math.sign(t.y-o.y)};return{x:{[lt.Backward]:r.x[lt.Backward]||s.x===-1,[lt.Forward]:r.x[lt.Forward]||s.x===1},y:{[lt.Backward]:r.y[lt.Backward]||s.y===-1,[lt.Forward]:r.y[lt.Forward]||s.y===1}}},[n,t,o])}function dI(e,t){const n=t!=null?e.get(t):void 0,o=n?n.node.current:null;return Uo(r=>{var s;return t==null?null:(s=o??r)!=null?s:null},[o,t])}function cI(e,t){return u.useMemo(()=>e.reduce((n,o)=>{const{sensor:r}=o,s=r.activators.map(a=>({eventName:a.eventName,handler:t(a.handler,o)}));return[...n,...s]},[]),[e,t])}var Jo;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Jo||(Jo={}));var $a;(function(e){e.Optimized="optimized"})($a||($a={}));const mf=new Map;function uI(e,t){let{dragging:n,dependencies:o,config:r}=t;const[s,a]=u.useState(null),{frequency:l,measure:d,strategy:c}=r,p=u.useRef(e),f=v(),b=Vo(f),g=u.useCallback(function(y){y===void 0&&(y=[]),!b.current&&a(_=>_===null?y:_.concat(y.filter(w=>!_.includes(w))))},[b]),m=u.useRef(null),h=Uo(y=>{if(f&&!n)return mf;if(!y||y===mf||p.current!==e||s!=null){const _=new Map;for(let w of e){if(!w)continue;if(s&&s.length>0&&!s.includes(w.id)&&w.rect.current){_.set(w.id,w.rect.current);continue}const k=w.node.current,x=k?new _a(d(k),k):null;w.rect.current=x,x&&_.set(w.id,x)}return _}return y},[e,s,n,f,d]);return u.useEffect(()=>{p.current=e},[e]),u.useEffect(()=>{f||g()},[n,f]),u.useEffect(()=>{s&&s.length>0&&a(null)},[JSON.stringify(s)]),u.useEffect(()=>{f||typeof l!="number"||m.current!==null||(m.current=setTimeout(()=>{g(),m.current=null},l))},[l,f,g,...o]),{droppableRects:h,measureDroppableContainers:g,measuringScheduled:s!=null};function v(){switch(c){case Jo.Always:return!1;case Jo.BeforeDragging:return n;default:return!n}}}function Ea(e,t){return Uo(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function pI(e,t){return Ea(e,t)}function fI(e){let{callback:t,disabled:n}=e;const o=ri(t),r=u.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:s}=window;return new s(o)},[o,n]);return u.useEffect(()=>()=>r?.disconnect(),[r]),r}function pi(e){let{callback:t,disabled:n}=e;const o=ri(t),r=u.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:s}=window;return new s(o)},[n]);return u.useEffect(()=>()=>r?.disconnect(),[r]),r}function gI(e){return new _a(Go(e),e)}function vf(e,t,n){t===void 0&&(t=gI);const[o,r]=u.useState(null);function s(){r(d=>{if(!e)return null;if(e.isConnected===!1){var c;return(c=d??n)!=null?c:null}const p=t(e);return JSON.stringify(d)===JSON.stringify(p)?d:p})}const a=fI({callback(d){if(e)for(const c of d){const{type:p,target:f}=c;if(p==="childList"&&f instanceof HTMLElement&&f.contains(e)){s();break}}}}),l=pi({callback:s});return ln(()=>{s(),e?(l?.observe(e),a?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),a?.disconnect())},[e]),o}function hI(e){const t=Ea(e);return nf(e,t)}const _f=[];function yI(e){const t=u.useRef(e),n=Uo(o=>e?o&&o!==_f&&e&&t.current&&e.parentNode===t.current.parentNode?o:ba(e):_f,[e]);return u.useEffect(()=>{t.current=e},[e]),n}function bI(e){const[t,n]=u.useState(null),o=u.useRef(e),r=u.useCallback(s=>{const a=ma(s.target);a&&n(l=>l?(l.set(a,va(a)),new Map(l)):null)},[]);return u.useEffect(()=>{const s=o.current;if(e!==s){a(s);const l=e.map(d=>{const c=ma(d);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,va(c)]):null}).filter(d=>d!=null);n(l.length?new Map(l):null),o.current=e}return()=>{a(e),a(s)};function a(l){l.forEach(d=>{const c=ma(d);c?.removeEventListener("scroll",r)})}},[r,e]),u.useMemo(()=>e.length?t?Array.from(t.values()).reduce((s,a)=>go(s,a),Ft):uf(e):Ft,[e,t])}function xf(e,t){t===void 0&&(t=[]);const n=u.useRef(null);return u.useEffect(()=>{n.current=null},t),u.useEffect(()=>{const o=e!==Ft;o&&!n.current&&(n.current=e),!o&&n.current&&(n.current=null)},[e]),n.current?li(e,n.current):Ft}function mI(e){u.useEffect(()=>{if(!oi)return;const t=e.map(n=>{let{sensor:o}=n;return o.setup==null?void 0:o.setup()});return()=>{for(const n of t)n?.()}},e.map(t=>{let{sensor:n}=t;return n}))}function vI(e,t){return u.useMemo(()=>e.reduce((n,o)=>{let{eventName:r,handler:s}=o;return n[r]=a=>{s(a,t)},n},{}),[e,t])}function wf(e){return u.useMemo(()=>e?V2(e):null,[e])}const kf=[];function _I(e,t){t===void 0&&(t=Go);const[n]=e,o=wf(n?xt(n):null),[r,s]=u.useState(kf);function a(){s(()=>e.length?e.map(d=>df(d)?o:new _a(t(d),d)):kf)}const l=pi({callback:a});return ln(()=>{l?.disconnect(),a(),e.forEach(d=>l?.observe(d))},[e]),r}function Sf(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Ko(t)?t:e}function xI(e){let{measure:t}=e;const[n,o]=u.useState(null),r=u.useCallback(c=>{for(const{target:p}of c)if(Ko(p)){o(f=>{const b=t(p);return f?{...f,width:b.width,height:b.height}:b});break}},[t]),s=pi({callback:r}),a=u.useCallback(c=>{const p=Sf(c);s?.disconnect(),p&&s?.observe(p),o(p?t(p):null)},[t,s]),[l,d]=ii(a);return u.useMemo(()=>({nodeRef:l,rect:n,setRef:d}),[n,l,d])}const wI=[{sensor:ka,options:{}},{sensor:hf,options:{}}],kI={current:{}},fi={draggable:{measure:rf},droppable:{measure:rf,strategy:Jo.WhileDragging,frequency:$a.Optimized},dragOverlay:{measure:Go}};class Zo extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,o;return(n=(o=this.get(t))==null?void 0:o.node.current)!=null?n:void 0}}const SI={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Zo,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:ci},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:fi,measureDroppableContainers:ci,windowRect:null,measuringScheduled:!1},Cf={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:ci,draggableNodes:new Map,over:null,measureDroppableContainers:ci},Qo=u.createContext(Cf),$f=u.createContext(SI);function CI(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Zo}}}function $I(e,t){switch(t.type){case it.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case it.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case it.DragEnd:case it.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case it.RegisterDroppable:{const{element:n}=t,{id:o}=n,r=new Zo(e.droppable.containers);return r.set(o,n),{...e,droppable:{...e.droppable,containers:r}}}case it.SetDroppableDisabled:{const{id:n,key:o,disabled:r}=t,s=e.droppable.containers.get(n);if(!s||o!==s.key)return e;const a=new Zo(e.droppable.containers);return a.set(n,{...s,disabled:r}),{...e,droppable:{...e.droppable,containers:a}}}case it.UnregisterDroppable:{const{id:n,key:o}=t,r=e.droppable.containers.get(n);if(!r||o!==r.key)return e;const s=new Zo(e.droppable.containers);return s.delete(n),{...e,droppable:{...e.droppable,containers:s}}}default:return e}}function EI(e){let{disabled:t}=e;const{active:n,activatorEvent:o,draggableNodes:r}=u.useContext(Qo),s=si(o),a=si(n?.id);return u.useEffect(()=>{if(!t&&!o&&s&&a!=null){if(!ya(s)||document.activeElement===s.target)return;const l=r.get(a);if(!l)return;const{activatorNode:d,node:c}=l;if(!d.current&&!c.current)return;requestAnimationFrame(()=>{for(const p of[d.current,c.current]){if(!p)continue;const f=b2(p);if(f){f.focus();break}}})}},[o,t,r,a,s]),null}function Ef(e,t){let{transform:n,...o}=t;return e!=null&&e.length?e.reduce((r,s)=>s({transform:r,...o}),n):n}function II(e){return u.useMemo(()=>({draggable:{...fi.draggable,...e?.draggable},droppable:{...fi.droppable,...e?.droppable},dragOverlay:{...fi.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function AI(e){let{activeNode:t,measure:n,initialRect:o,config:r=!0}=e;const s=u.useRef(!1),{x:a,y:l}=typeof r=="boolean"?{x:r,y:r}:r;ln(()=>{if(!a&&!l||!t){s.current=!1;return}if(s.current||!o)return;const c=t?.node.current;if(!c||c.isConnected===!1)return;const p=n(c),f=nf(p,o);if(a||(f.x=0),l||(f.y=0),s.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const b=sf(c);b&&b.scrollBy({top:f.y,left:f.x})}},[t,a,l,o,n])}const gi=u.createContext({...Ft,scaleX:1,scaleY:1});var bn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(bn||(bn={}));const TI=u.memo(function(t){var n,o,r,s;let{id:a,accessibility:l,autoScroll:d=!0,children:c,sensors:p=wI,collisionDetection:f=P2,measuring:b,modifiers:g,...m}=t;const h=u.useReducer($I,void 0,CI),[v,y]=h,[_,w]=k2(),[k,x]=u.useState(bn.Uninitialized),$=k===bn.Initialized,{draggable:{active:C,nodes:S,translate:D},droppable:{containers:E}}=v,I=C!=null?S.get(C):null,N=u.useRef({initial:null,translated:null}),T=u.useMemo(()=>{var Q;return C!=null?{id:C,data:(Q=I?.data)!=null?Q:kI,rect:N}:null},[C,I]),B=u.useRef(null),[M,O]=u.useState(null),[z,H]=u.useState(null),P=Vo(m,Object.values(m)),A=ai("DndDescribedBy",a),L=u.useMemo(()=>E.getEnabled(),[E]),F=II(b),{droppableRects:Y,measureDroppableContainers:V,measuringScheduled:X}=uI(L,{dragging:$,dependencies:[D.x,D.y],config:F.droppable}),Z=dI(S,C),ie=u.useMemo(()=>z?di(z):null,[z]),oe=pe(),G=pI(Z,F.draggable.measure);AI({activeNode:C!=null?S.get(C):null,config:oe.layoutShiftCompensation,initialRect:G,measure:F.draggable.measure});const ee=vf(Z,F.draggable.measure,G),fe=vf(Z?Z.parentElement:null),K=u.useRef({activatorEvent:null,active:null,activeNode:Z,collisionRect:null,collisions:null,droppableRects:Y,draggableNodes:S,draggingNode:null,draggingNodeRect:null,droppableContainers:E,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),te=E.getNodeFor((n=K.current.over)==null?void 0:n.id),ye=xI({measure:F.dragOverlay.measure}),Se=(o=ye.nodeRef.current)!=null?o:Z,De=$?(r=ye.rect)!=null?r:ee:null,Ie=!!(ye.nodeRef.current&&ye.rect),Ve=hI(Ie?null:ee),ze=wf(Se?xt(Se):null),Be=yI($?te??Z:null),Xe=_I(Be),Ne=Ef(g,{transform:{x:D.x-Ve.x,y:D.y-Ve.y,scaleX:1,scaleY:1},activatorEvent:z,active:T,activeNodeRect:ee,containerNodeRect:fe,draggingNodeRect:De,over:K.current.over,overlayNodeRect:ye.rect,scrollableAncestors:Be,scrollableAncestorRects:Xe,windowRect:ze}),Je=ie?go(ie,D):null,ve=bI(Be),qe=xf(ve),We=xf(ve,[ee]),ce=go(Ne,qe),q=De?H2(De,Ne):null,se=T&&q?f({active:T,collisionRect:q,droppableRects:Y,droppableContainers:L,pointerCoordinates:Je}):null,ae=M2(se,"id"),[be,Ce]=u.useState(null),$e=Ie?Ne:go(Ne,We),U=W2($e,(s=be?.rect)!=null?s:null,ee),ue=u.useRef(null),ge=u.useCallback((Q,de)=>{let{sensor:Ae,options:dt}=de;if(B.current==null)return;const pt=S.get(B.current);if(!pt)return;const ot=Q.nativeEvent,Le=new Ae({active:B.current,activeNode:pt,event:ot,options:dt,context:K,onAbort(Ze){if(!S.get(Ze))return;const{onDragAbort:Dt}=P.current,zt={id:Ze};Dt?.(zt),_({type:"onDragAbort",event:zt})},onPending(Ze,Tt,Dt,zt){if(!S.get(Ze))return;const{onDragPending:Sn}=P.current,en={id:Ze,constraint:Tt,initialCoordinates:Dt,offset:zt};Sn?.(en),_({type:"onDragPending",event:en})},onStart(Ze){const Tt=B.current;if(Tt==null)return;const Dt=S.get(Tt);if(!Dt)return;const{onDragStart:zt}=P.current,kn={activatorEvent:ot,active:{id:Tt,data:Dt.data,rect:N}};En.unstable_batchedUpdates(()=>{zt?.(kn),x(bn.Initializing),y({type:it.DragStart,initialCoordinates:Ze,active:Tt}),_({type:"onDragStart",event:kn}),O(ue.current),H(ot)})},onMove(Ze){y({type:it.DragMove,coordinates:Ze})},onEnd:je(it.DragEnd),onCancel:je(it.DragCancel)});ue.current=Le;function je(Ze){return async function(){const{active:Dt,collisions:zt,over:kn,scrollAdjustedTranslate:Sn}=K.current;let en=null;if(Dt&&Sn){const{cancelDrop:Kn}=P.current;en={activatorEvent:ot,active:Dt,collisions:zt,delta:Sn,over:kn},Ze===it.DragEnd&&typeof Kn=="function"&&await Promise.resolve(Kn(en))&&(Ze=it.DragCancel)}B.current=null,En.unstable_batchedUpdates(()=>{y({type:Ze}),x(bn.Uninitialized),Ce(null),O(null),H(null),ue.current=null;const Kn=Ze===it.DragEnd?"onDragEnd":"onDragCancel";if(en){const cn=P.current[Kn];cn?.(en),_({type:Kn,event:en})}})}}},[S]),ke=u.useCallback((Q,de)=>(Ae,dt)=>{const pt=Ae.nativeEvent,ot=S.get(dt);if(B.current!==null||!ot||pt.dndKit||pt.defaultPrevented)return;const Le={active:ot};Q(Ae,de.options,Le)===!0&&(pt.dndKit={capturedBy:de.sensor},B.current=dt,ge(Ae,de))},[S,ge]),he=cI(p,ke);mI(p),ln(()=>{ee&&k===bn.Initializing&&x(bn.Initialized)},[ee,k]),u.useEffect(()=>{const{onDragMove:Q}=P.current,{active:de,activatorEvent:Ae,collisions:dt,over:pt}=K.current;if(!de||!Ae)return;const ot={active:de,activatorEvent:Ae,collisions:dt,delta:{x:ce.x,y:ce.y},over:pt};En.unstable_batchedUpdates(()=>{Q?.(ot),_({type:"onDragMove",event:ot})})},[ce.x,ce.y]),u.useEffect(()=>{const{active:Q,activatorEvent:de,collisions:Ae,droppableContainers:dt,scrollAdjustedTranslate:pt}=K.current;if(!Q||B.current==null||!de||!pt)return;const{onDragOver:ot}=P.current,Le=dt.get(ae),je=Le&&Le.rect.current?{id:Le.id,rect:Le.rect.current,data:Le.data,disabled:Le.disabled}:null,Ze={active:Q,activatorEvent:de,collisions:Ae,delta:{x:pt.x,y:pt.y},over:je};En.unstable_batchedUpdates(()=>{Ce(je),ot?.(Ze),_({type:"onDragOver",event:Ze})})},[ae]),ln(()=>{K.current={activatorEvent:z,active:T,activeNode:Z,collisionRect:q,collisions:se,droppableRects:Y,draggableNodes:S,draggingNode:Se,draggingNodeRect:De,droppableContainers:E,over:be,scrollableAncestors:Be,scrollAdjustedTranslate:ce},N.current={initial:De,translated:q}},[T,Z,se,q,S,Se,De,Y,E,be,Be,ce]),sI({...oe,delta:D,draggingRect:q,pointerCoordinates:Je,scrollableAncestors:Be,scrollableAncestorRects:Xe});const j=u.useMemo(()=>({active:T,activeNode:Z,activeNodeRect:ee,activatorEvent:z,collisions:se,containerNodeRect:fe,dragOverlay:ye,draggableNodes:S,droppableContainers:E,droppableRects:Y,over:be,measureDroppableContainers:V,scrollableAncestors:Be,scrollableAncestorRects:Xe,measuringConfiguration:F,measuringScheduled:X,windowRect:ze}),[T,Z,ee,z,se,fe,ye,S,E,Y,be,V,Be,Xe,F,X,ze]),ne=u.useMemo(()=>({activatorEvent:z,activators:he,active:T,activeNodeRect:ee,ariaDescribedById:{draggable:A},dispatch:y,draggableNodes:S,over:be,measureDroppableContainers:V}),[z,he,T,ee,y,A,S,be,V]);return u.createElement(tf.Provider,{value:w},u.createElement(Qo.Provider,{value:ne},u.createElement($f.Provider,{value:j},u.createElement(gi.Provider,{value:U},c)),u.createElement(EI,{disabled:l?.restoreFocus===!1})),u.createElement($2,{...l,hiddenTextDescribedById:A}));function pe(){const Q=M?.autoScrollEnabled===!1,de=typeof d=="object"?d.enabled===!1:d===!1,Ae=$&&!Q&&!de;return typeof d=="object"?{...d,enabled:Ae}:{enabled:Ae}}}),DI=u.createContext(null),If="button",zI="Draggable";function NI(e){let{id:t,data:n,disabled:o=!1,attributes:r}=e;const s=ai(zI),{activators:a,activatorEvent:l,active:d,activeNodeRect:c,ariaDescribedById:p,draggableNodes:f,over:b}=u.useContext(Qo),{role:g=If,roleDescription:m="draggable",tabIndex:h=0}=r??{},v=d?.id===t,y=u.useContext(v?gi:DI),[_,w]=ii(),[k,x]=ii(),$=vI(a,t),C=Vo(n);ln(()=>(f.set(t,{id:t,key:s,node:_,activatorNode:k,data:C}),()=>{const D=f.get(t);D&&D.key===s&&f.delete(t)}),[f,t]);const S=u.useMemo(()=>({role:g,tabIndex:h,"aria-disabled":o,"aria-pressed":v&&g===If?!0:void 0,"aria-roledescription":m,"aria-describedby":p.draggable}),[o,g,h,v,m,p.draggable]);return{active:d,activatorEvent:l,activeNodeRect:c,attributes:S,isDragging:v,listeners:o?void 0:$,node:_,over:b,setNodeRef:w,setActivatorNodeRef:x,transform:y}}function MI(){return u.useContext($f)}const LI="Droppable",PI={timeout:25};function OI(e){let{data:t,disabled:n=!1,id:o,resizeObserverConfig:r}=e;const s=ai(LI),{active:a,dispatch:l,over:d,measureDroppableContainers:c}=u.useContext(Qo),p=u.useRef({disabled:n}),f=u.useRef(!1),b=u.useRef(null),g=u.useRef(null),{disabled:m,updateMeasurementsFor:h,timeout:v}={...PI,...r},y=Vo(h??o),_=u.useCallback(()=>{if(!f.current){f.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{c(Array.isArray(y.current)?y.current:[y.current]),g.current=null},v)},[v]),w=pi({callback:_,disabled:m||!a}),k=u.useCallback((S,D)=>{w&&(D&&(w.unobserve(D),f.current=!1),S&&w.observe(S))},[w]),[x,$]=ii(k),C=Vo(t);return u.useEffect(()=>{!w||!x.current||(w.disconnect(),f.current=!1,w.observe(x.current))},[x,w]),u.useEffect(()=>(l({type:it.RegisterDroppable,element:{id:o,key:s,disabled:n,node:x,rect:b,data:C}}),()=>l({type:it.UnregisterDroppable,key:s,id:o})),[o]),u.useEffect(()=>{n!==p.current.disabled&&(l({type:it.SetDroppableDisabled,id:o,key:s,disabled:n}),p.current.disabled=n)},[o,s,n,l]),{active:a,rect:b,isOver:d?.id===o,node:x,over:d,setNodeRef:$}}function BI(e){let{animation:t,children:n}=e;const[o,r]=u.useState(null),[s,a]=u.useState(null),l=si(n);return!n&&!o&&l&&r(l),ln(()=>{if(!s)return;const d=o?.key,c=o?.props.id;if(d==null||c==null){r(null);return}Promise.resolve(t(c,s)).then(()=>{r(null)})},[t,o,s]),u.createElement(u.Fragment,null,n,o?u.cloneElement(o,{ref:a}):null)}const WI={x:0,y:0,scaleX:1,scaleY:1};function jI(e){let{children:t}=e;return u.createElement(Qo.Provider,{value:Cf},u.createElement(gi.Provider,{value:WI},t))}const HI={position:"fixed",touchAction:"none"},FI=e=>ya(e)?"transform 250ms ease":void 0,KI=u.forwardRef((e,t)=>{let{as:n,activatorEvent:o,adjustScale:r,children:s,className:a,rect:l,style:d,transform:c,transition:p=FI}=e;if(!l)return null;const f=r?c:{...c,scaleX:1,scaleY:1},b={...HI,width:l.width,height:l.height,top:l.top,left:l.left,transform:qo.Transform.toString(f),transformOrigin:r&&o?T2(o,l):void 0,transition:typeof p=="function"?p(o):p,...d};return u.createElement(n,{className:a,style:b,ref:t},s)}),VI={duration:250,easing:"ease",keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:qo.Transform.toString(t)},{transform:qo.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:o}=t;const r={},{styles:s,className:a}=e;if(s!=null&&s.active)for(const[l,d]of Object.entries(s.active))d!==void 0&&(r[l]=n.node.style.getPropertyValue(l),n.node.style.setProperty(l,d));if(s!=null&&s.dragOverlay)for(const[l,d]of Object.entries(s.dragOverlay))d!==void 0&&o.node.style.setProperty(l,d);return a!=null&&a.active&&n.node.classList.add(a.active),a!=null&&a.dragOverlay&&o.node.classList.add(a.dragOverlay),function(){for(const[d,c]of Object.entries(r))n.node.style.setProperty(d,c);a!=null&&a.active&&n.node.classList.remove(a.active)}})({styles:{active:{opacity:"0"}}})};function UI(e){let{config:t,draggableNodes:n,droppableContainers:o,measuringConfiguration:r}=e;return ri((s,a)=>{if(t===null)return;const l=n.get(s);if(!l)return;const d=l.node.current;if(!d)return;const c=Sf(a);if(!c)return;const{transform:p}=xt(a).getComputedStyle(a),f=of(p);if(!f)return;const b=typeof t=="function"?t:qI(t);return pf(d,r.draggable.measure),b({active:{id:s,data:l.data,node:d,rect:r.draggable.measure(d)},draggableNodes:n,dragOverlay:{node:a,rect:r.dragOverlay.measure(c)},droppableContainers:o,measuringConfiguration:r,transform:f})})}function qI(e){const{duration:t,easing:n,sideEffects:o,keyframes:r}={...VI,...e};return s=>{let{active:a,dragOverlay:l,transform:d,...c}=s;if(!t)return;const p={x:l.rect.left-a.rect.left,y:l.rect.top-a.rect.top},f={scaleX:d.scaleX!==1?a.rect.width*d.scaleX/l.rect.width:1,scaleY:d.scaleY!==1?a.rect.height*d.scaleY/l.rect.height:1},b={x:d.x-p.x,y:d.y-p.y,...f},g=r({...c,active:a,dragOverlay:l,transform:{initial:d,final:b}}),[m]=g,h=g[g.length-1];if(JSON.stringify(m)===JSON.stringify(h))return;const v=o?.({active:a,dragOverlay:l,...c}),y=l.node.animate(g,{duration:t,easing:n,fill:"forwards"});return new Promise(_=>{y.onfinish=()=>{v?.(),_()}})}}let Af=0;function GI(e){return u.useMemo(()=>{if(e!=null)return Af++,Af},[e])}const YI=u.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:o,style:r,transition:s,modifiers:a,wrapperElement:l="div",className:d,zIndex:c=999}=e;const{activatorEvent:p,active:f,activeNodeRect:b,containerNodeRect:g,draggableNodes:m,droppableContainers:h,dragOverlay:v,over:y,measuringConfiguration:_,scrollableAncestors:w,scrollableAncestorRects:k,windowRect:x}=MI(),$=u.useContext(gi),C=GI(f?.id),S=Ef(a,{activatorEvent:p,active:f,activeNodeRect:b,containerNodeRect:g,draggingNodeRect:v.rect,over:y,overlayNodeRect:v.rect,scrollableAncestors:w,scrollableAncestorRects:k,transform:$,windowRect:x}),D=Ea(b),E=UI({config:o,draggableNodes:m,droppableContainers:h,measuringConfiguration:_}),I=D?v.setRef:void 0;return u.createElement(jI,null,u.createElement(BI,{animation:E},f&&C?u.createElement(KI,{key:C,id:f.id,ref:I,as:l,activatorEvent:p,adjustScale:t,className:d,transition:s,rect:D,style:{zIndex:c,...r},transform:S},n):null))});function Ro(e,t){return!t||!Array.isArray(t.draggable)?!1:t.draggable.includes(e)}function XI({draggedComponentName:e,targetContainerName:t,nesting:n}){if(!n||!Ro(e,n))return!1;const o=n.containers;if(!o||typeof o!="object")return!1;const r=o[t];return!r||!Array.isArray(r.accepts)?!1:r.accepts.includes(e)}function Tf(e,t){if(!t?.containers)return!1;const n=t.containers[e];return!!(n&&Array.isArray(n.accepts)&&n.accepts.length>0)}function JI(e,t,n,o,r){if(!n||n.length===0)return{parentPath:[],index:r};if(e&&Tf(e,o))return{parentPath:n,index:t};const s=n.slice(0,-1),a=n[n.length-1]??0;return{parentPath:s,index:a+1}}function Df(e,t){return e===t||e.startsWith(`${t}.`)}function zf(e,t){if(e==="")return/^\d+$/.test(t)?Number(t):null;const n=`${e}.children.`;if(!t.startsWith(n))return null;const o=t.slice(n.length);return/^\d+$/.test(o)?Number(o):null}function ZI(e,t){const n=[];return e.querySelectorAll("[data-editor-path]").forEach(o=>{if(o.hasAttribute("data-dnd-placeholder")||o.closest("[data-dnd-placeholder]"))return;const r=o.dataset.editorPath;typeof r=="string"&&n.push({path:t(r),domPath:r,rect:o.getBoundingClientRect()})}),n}const QI=16;function RI(e){const{frameEl:t,draggedPath:n,acceptsContainer:o,allowsNestSlot:r,includeContainer:s}=e,a=e.normalizeContainerPath??(g=>g),l=t.getBoundingClientRect(),d=ZI(t,a),c=new Map;for(const g of d)c.has(g.path)||c.set(g.path,g.domPath);const p=a(n),f=new Set([""]);for(const g of d){const m=tA(g.path);m!==null&&f.add(m)}for(const g of d)f.add(g.path);const b=[];for(const g of f){const m=g==="",h=m?null:c.get(g)??g,v=m?t:t.querySelector(`[data-editor-path="${Lf(h)}"]`);if(!v&&!m||!m&&Df(g,p))continue;const y=g;if(!m&&s&&!s(y))continue;const _=$=>{const C=c.get($);if(!C||typeof window>"u")return!1;const S=t.querySelector(`[data-editor-path="${Lf(C)}"]`);return S?(window.getComputedStyle(S).display??"").toLowerCase()==="contents":!1},w=d.filter($=>zf(g,$.path)!==null).filter($=>!Df($.path,p)).filter($=>!_($.path)).map($=>({origIndex:zf(g,$.path),rect:eA($.rect,$.path,d)})).filter($=>$.rect.width>0||$.rect.height>0).sort(($,C)=>$.origIndex-C.origIndex),k=Vp(m?t:v).kind,x=k==="flex_row_single"||k==="flex_row_wrap"||k==="grid_single_row"||k==="grid_2d";if(w.length>0){if(o(y)){w.forEach(C=>{b.push(Nf(y,C.origIndex,C.rect,l,x,"before"))});const $=w[w.length-1];b.push(Nf(y,$.origIndex+1,$.rect,l,x,"after"))}}else if(!m&&r(y)&&v){const $=v.getBoundingClientRect();$.width>0&&$.height>0&&b.push({id:`slot:${y}:0`,kind:"nest",containerPath:y,index:0,box:Mf($,l),orientation:"area"})}else m&&b.push({id:"slot::0",kind:"gap",containerPath:"",index:0,box:Mf(l,l),orientation:"area"})}return b.filter(g=>uo(g.box,t))}function Nf(e,t,n,o,r,s){const a=QI;let l;if(r)l={left:(s==="before"?n.left:n.right)-a/2,top:n.top,width:a,height:n.height};else{const d=s==="before"?n.top:n.bottom;l={left:n.left,top:d-a/2,width:n.width,height:a}}return{id:`slot:${e}:${t}`,kind:"gap",containerPath:e,index:t,box:{left:l.left-o.left,top:l.top-o.top,width:l.width,height:l.height,scale:1},orientation:r?"vertical":"horizontal"}}function eA(e,t,n){if(e.width>0||e.height>0)return e;const o=`${t}.children.`;let r=1/0,s=1/0,a=-1/0,l=-1/0;for(const d of n)d.path.startsWith(o)&&(d.rect.width===0&&d.rect.height===0||(r=Math.min(r,d.rect.left),s=Math.min(s,d.rect.top),a=Math.max(a,d.rect.right),l=Math.max(l,d.rect.bottom)));return r===1/0?e:{left:r,top:s,width:a-r,height:l-s,right:a,bottom:l,x:r,y:s,toJSON:()=>({})}}function Mf(e,t){return{left:e.left-t.left,top:e.top-t.top,width:e.width,height:e.height,scale:1}}function tA(e){if(e==="")return null;const t=e.lastIndexOf(".children.");return t<0?"":e.slice(0,t)}function nA(e){if(!e.startsWith("slot:"))return null;const t=e.slice(5),n=t.lastIndexOf(":");if(n<0)return null;const o=t.slice(0,n),r=Number(t.slice(n+1));return Number.isFinite(r)?{containerPath:o,index:r}:null}function Lf(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[^a-zA-Z0-9_\-.]/g,t=>`\\${t}`)}function Ia(e){return typeof e=="string"&&e.length>0?e:null}function Aa(e,t){return t&&e.startsWith(`${t}.`)?t:e}function Pf(e){if(typeof e!="string")return null;const t=nA(e);return t?{containerPath:t.containerPath,index:t.index}:null}function Ta(e,t){return t?e.startsWith(`${t}.iteration.`):!1}function Da(e,t,n){return t?n==="iteration_item"?Ta(e,t):e===t||e.startsWith(`${t}.`):!1}function oA(e){const{frameEl:t,nesting:n,editMode:o,currentExtensionId:r,editableRootPath:s,components:a,patchLayout:l,pushHistory:d,onMovePath:c,selectedPath:p,showBranchBoundaryHint:f}=e,b=(o==="iteration_item"||o==="modal")&&s&&s.length>0?at(s):null,[g,m]=u.useState(null),[h,v]=u.useState(null),[y,_]=u.useState(null),w=u.useRef({components:a,nesting:n,editMode:o,currentExtensionId:r,selectedPath:p,editableRootSourcePath:b});w.current={components:a,nesting:n,editMode:o,currentExtensionId:r,selectedPath:p,editableRootSourcePath:b};const k=u.useRef(null),x=u.useCallback(M=>({children:M}),[]),$=u.useCallback((M,O)=>{const z=Pe(x(M),O);return z?typeof z.name=="string"?z.name:typeof z.type=="string"?z.type:null:null},[x]),C=u.useCallback(M=>O=>{const z=w.current;if(O==="")return Ro(M,z.nesting);const H=Re(O),P=Pe(x(z.components),H);if(!P)return!1;const A=typeof P.name=="string"?P.name:typeof P.type=="string"?P.type:"";if(!A)return!1;const L=!!z.editableRootSourcePath&&(O===z.editableRootSourcePath||O.startsWith(`${z.editableRootSourcePath}.`));if(z.editableRootSourcePath&&!L)return!1;if(!L){const F=Dn(x(z.components),H);if(Jt(P,z.editMode,z.currentExtensionId,F)!=="none")return!1}return Tf(A,z.nesting)?XI({draggedComponentName:M,targetContainerName:A,nesting:z.nesting}):!1},[x]),S=u.useCallback(M=>{if(M==="")return!0;const O=w.current,z=Re(M),H=k.current;if(H&&H.length>0){const L=H.slice(0,-1);if(hi(z,L))return!0}const P=Pe(x(O.components),z);return P?(typeof P.name=="string"?P.name:typeof P.type=="string"?P.type:"").length>0:!1},[x]),D=u.useCallback(M=>{const O=C(M),z=w.current,H=k.current,P=H?H.slice(0,-1):null,A=new Set;if(P)for(let V=P.length;V>=0;V--)A.add(yi(P.slice(0,V)));const L=yi(H??[]),F=V=>!!H&&(V===L||V.startsWith(`${L}.`)),Y=(V,X)=>{for(let Z=0;ZV===""?!0:F(V)?!1:A.has(V),allowsNestSlot:V=>{if(!O(V))return!1;if(P){const X=Re(V);if(hi(X,P))return!1}return S(V)}}},[C,S,x]),E=u.useCallback(M=>{const O=Ia(M.active.id),z=w.current;if(!O)return;const H=Aa(O,z.selectedPath),P=Re(H),A=Pe(x(z.components),P),L=A&&typeof A.name=="string"?A.name:A&&typeof A.type=="string"?A.type:null;m(H),v(L),_(null),k.current=A?P:null;let F="allowed";if(!L||!Ro(L,z.nesting))F="denied_no_draggable";else if(A){const Y=Dn(x(z.components),P),V=Jt(A,z.editMode,z.currentExtensionId,Y);if(z.editableRootSourcePath&&!Da(H,z.editableRootSourcePath,z.editMode))F="denied_data_bound";else if(os(Y)&&!Ta(H,z.editableRootSourcePath))F="denied_data_bound";else{const X=Tp(V);X&&(F=X)}}F!=="allowed"&&m(null),pn({source:"drag",draggedComponentName:L,targetContainerName:null,targetContainerPath:null,decision:F,result:F==="allowed"?"completed":"denied",timestamp:Date.now()})},[x]),I=u.useCallback(M=>{if(!t)return;const O=Ia(M.active.id);if(!O)return;const z=h;if(!z){_(null);return}const H=w.current,P=Aa(O,H.selectedPath),A=Re(P),L=Pe(x(H.components),A);if(!L||!Ro(z,H.nesting)){_(null);return}const F=Dn(x(H.components),A);if(H.editableRootSourcePath&&!Da(P,H.editableRootSourcePath,H.editMode)){_(null);return}const Y=Jt(L,H.editMode,H.currentExtensionId,F),V=Ta(P,H.editableRootSourcePath);if(os(F)&&!V||!Zt(Y)&&!V){_(null);return}_(Pf(M.over?.id))},[t,h,x]),N=u.useCallback(()=>{m(null),v(null),_(null),k.current=null},[]),T=u.useCallback(M=>{const O=Ia(M.active.id),z=h,H=w.current,P=O?Aa(O,H.selectedPath):null;if(!t||!P||!z){N();return}const A=Pf(M.over?.id),L=Re(P);if(!A){pn({source:"drag",draggedComponentName:z,targetContainerName:null,targetContainerPath:null,decision:"denied_no_accepts",result:"cancelled",timestamp:Date.now()}),N();return}const F=A.containerPath===""?[]:Re(A.containerPath),Y=A.containerPath===""?null:$(H.components,F);if(!rA(L.slice(0,-1),F)){pn({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:A.containerPath||null,decision:"denied_responsive_branch_boundary",result:"denied",timestamp:Date.now()}),f?.(),N();return}if(H.editableRootSourcePath&&!Da(A.containerPath,H.editableRootSourcePath,H.editMode)){pn({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:A.containerPath||null,decision:"denied_data_bound",result:"denied",timestamp:Date.now()}),N();return}const V=Pe(x(H.components),L),X=V?Tp(Jt(V,H.editMode,H.currentExtensionId,Dn(x(H.components),L))):null;if(X){pn({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:A.containerPath||null,decision:X,result:"denied",timestamp:Date.now()}),N();return}const Z=L.slice(0,-1),ie=L[L.length-1]??-1;if(hi(Z,F)&&(A.index===ie||A.index===ie+1)){pn({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:A.containerPath||null,decision:"allowed",insertionIndex:A.index,result:"cancelled",timestamp:Date.now()}),N();return}const ee=hi(Z,F),fe=A.index;let K=[];l(De=>{const ze=tm({children:De},L,F,fe).children??[];return K=ze,ze}),d(K,`move ${z}`);const te=fd(F,L),ye=ee&&ie{N()},[N]);return{activeDragPath:g,activeDragName:h,activeDropZone:y,onDragStart:E,onDragMove:I,onDragEnd:T,onDragCancel:B,buildSlotPredicates:D}}function hi(e,t){if(e.length!==t.length)return!1;for(let n=0;n0?at(s):null,{t:m}=et(),[h,v]=u.useState(!1),y=u.useRef(null),_=u.useCallback(()=>{v(!0),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>v(!1),2600)},[]);u.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]);const w=oA({frameEl:t,nesting:n,editMode:o,currentExtensionId:r,editableRootPath:s,components:a,patchLayout:l,pushHistory:d,onMovePath:p,selectedPath:b,showBranchBoundaryHint:_}),k=I2(E2(ka,{activationConstraint:{distance:8}})),[x,$]=u.useState([]),C=u.useCallback(()=>{if(!t){$([]);return}if(w.activeDragPath!==null)return;const P={children:a},A=t.querySelectorAll("[data-editor-path]"),L=[],F=new Map;A.forEach(Y=>{const V=Y.dataset.editorPath;if(typeof V!="string"||o!=="iteration_item"&&g&&!aA(V,g,o))return;const X=iA(V);if(X!==null&&!er(V,g)){if(/\.iteration\.\d+$/.test(V)){const K=co(Y,t);if(K&&uo(K,t)){const te=F.get(X)??[];te.push(K),F.set(X,te)}}return}if(er(V,g)&&/\.iteration\.\d+$/.test(V))return;const Z=Re(V),ie=Pe(P,Z);if(!ie||ie.iteration&&ie.iteration.source!==void 0)return;const oe=typeof ie.name=="string"?ie.name:typeof ie.type=="string"?ie.type:null;if(!oe||!Ro(oe,n))return;const G=Dn(P,Z);if(os(G)&&!er(V,g))return;const ee=Jt(ie,o,r,G);if(!Zt(ee)&&!er(V,g))return;const fe=co(Y,t);fe&&uo(fe,t)&&L.push({path:V,name:oe,box:fe})});for(const[Y,V]of F){const X=Re(Y),Z=Pe(P,X);if(!Z)continue;const ie=typeof Z.name=="string"?Z.name:typeof Z.type=="string"?Z.type:null;if(!ie)continue;const oe=Dn(P,X),G=Jt(Z,o,r,oe);if(!Zt(G))continue;const ee=lA(V);ee&&uo(ee,t)&&L.push({path:Y,name:ie,box:ee,isIterationGroup:!0})}$(L)},[t,a,n,o,r,g,w.activeDragPath]);u.useEffect(()=>{C()},[C]),u.useEffect(()=>{if(t)return Wp(C,t)},[t,C]);const S=w.activeDragPath!==null,D=w.activeDragName,E=w.activeDragPath,[I,N]=u.useState(null),T=u.useRef(null);u.useEffect(()=>{if(!E||!t){E||(T.current=null,N(null));return}if(T.current===E)return;T.current=E;const P=t.querySelector(`[data-editor-path="${Of(E)}"]`);if(P){const oe=P.getBoundingClientRect();N({node:P.cloneNode(!0),width:oe.width,height:oe.height});return}const A=Array.from(t.querySelectorAll(`[data-editor-path^="${Of(E)}.iteration."]`)).filter(oe=>/\.iteration\.\d+$/.test(oe.dataset.editorPath??""));if(A.length===0){N(null);return}let L=1/0,F=1/0,Y=-1/0,V=-1/0;for(const oe of A){const G=oe.getBoundingClientRect();L=Math.min(L,G.left),F=Math.min(F,G.top),Y=Math.max(Y,G.right),V=Math.max(V,G.bottom)}const X=Y-L,Z=V-F,ie=document.createElement("div");ie.style.position="relative",ie.style.width=`${X}px`,ie.style.height=`${Z}px`;for(const oe of A){const G=oe.getBoundingClientRect(),ee=oe.cloneNode(!0);ee.style.position="absolute",ee.style.left=`${G.left-L}px`,ee.style.top=`${G.top-F}px`,ee.style.width=`${G.width}px`,ee.style.height=`${G.height}px`,ee.style.margin="0",ie.appendChild(ee)}N({node:ie,width:X,height:Z})},[E,t]);const[B,M]=u.useState([]),O=u.useRef(null),z=u.useRef(w.buildSlotPredicates);if(z.current=w.buildSlotPredicates,u.useEffect(()=>{if(!E||!D||!t){O.current=null,M(F=>F.length===0?F:[]);return}if(O.current===E)return;O.current=E;const{acceptsContainer:P,allowsNestSlot:A,includeContainer:L}=z.current(D);M(RI({frameEl:t,draggedPath:E,acceptsContainer:P,allowsNestSlot:A,includeContainer:L,normalizeContainerPath:F=>sA(F)}))},[E,D,t]),!t)return null;const H=w.activeDropZone?`slot:${w.activeDropZone.containerPath}:${w.activeDropZone.index}`:null;return i.jsxs(TI,{sensors:k,collisionDetection:B2,onDragStart:w.onDragStart,onDragMove:w.onDragMove,onDragEnd:w.onDragEnd,onDragCancel:w.onDragCancel,children:[x.map(P=>i.jsx(pA,{path:P.path,name:P.name,box:P.box,dimmed:S&&w.activeDragPath!==P.path,isIterationGroup:P.isIterationGroup,onSelect:c,onRequestInlineEdit:f},P.path)),S&&B.map(P=>i.jsx(uA,{slot:P,active:P.id===H},P.id)),En.createPortal(i.jsx(YI,{dropAnimation:null,zIndex:Xp,children:D?I?i.jsx(cA,{name:D,node:I.node,width:I.width,height:I.height}):i.jsx("div",{className:"g7le-dnd-drag-ghost","data-testid":"g7le-dnd-drag-ghost",style:{padding:"4px 10px",background:"rgba(79,70,229,0.95)",color:"#fff",fontSize:12,fontWeight:600,borderRadius:4,pointerEvents:"none",whiteSpace:"nowrap"},children:`<${D}>`}):null}),document.body),h&&En.createPortal(i.jsxs("div",{"data-testid":"g7le-branch-boundary-hint",role:"status",style:{position:"absolute",left:"50%",top:12,transform:"translateX(-50%)",background:"rgba(245,158,11,0.97)",color:"#fff",fontSize:13,fontWeight:600,padding:"8px 16px",borderRadius:8,boxShadow:"0 4px 14px rgba(0,0,0,0.2)",pointerEvents:"none",whiteSpace:"nowrap",zIndex:Xp},children:["⚠️ ",m("layout_editor.overlay.branch_boundary_denied")]}),t)]})}function cA(e){const{node:t,width:n,height:o}=e,r=u.useRef(null);return u.useEffect(()=>{const s=r.current;if(s)return s.replaceChildren(),s.appendChild(t.cloneNode(!0)),()=>{s.replaceChildren()}},[t]),i.jsx("div",{ref:r,className:"g7le-dnd-drag-ghost","data-testid":"g7le-dnd-drag-ghost",style:{width:n,height:o,opacity:.7,pointerEvents:"none",boxShadow:"0 6px 18px rgba(0,0,0,0.25)",borderRadius:4,overflow:"hidden",cursor:"grabbing"}})}function uA(e){const{slot:t,active:n}=e,{setNodeRef:o}=OI({id:t.id}),r=t.orientation!=="area";return i.jsx("div",{ref:o,"data-testid":`g7le-dnd-slot-${t.id}`,"data-dnd-slot-id":t.id,style:{position:"absolute",left:t.box.left,top:t.box.top,width:t.box.width,height:t.box.height,pointerEvents:"auto",zIndex:o2,boxSizing:"border-box",...r?{background:n?"rgba(79,70,229,0.15)":"transparent",...n?t.orientation==="vertical"?{borderLeft:"2px solid #4f46e5"}:{borderTop:"2px solid #4f46e5"}:{}}:{border:n?"2px dashed #4f46e5":"1px dashed transparent",background:n?"rgba(79,70,229,0.08)":"transparent",borderRadius:4}}})}function Of(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[^a-zA-Z0-9_\-.]/g,t=>`\\${t}`)}function pA(e){const{path:t,box:n,dimmed:o,isIterationGroup:r,onSelect:s,onRequestInlineEdit:a}=e,{attributes:l,listeners:d,setNodeRef:c,isDragging:p}=NI({id:t}),f=(t.match(/\.children\./g)||[]).length,b=r2(f);return i.jsx("div",{ref:c,"data-testid":`g7le-dnd-handle-${t}`,"data-dnd-handle-path":t,"data-dnd-iteration-group":r?"true":void 0,...d,...l,onClick:g=>{if(g.stopPropagation(),!r&&typeof document<"u"&&typeof document.elementsFromPoint=="function"){const m=document.elementsFromPoint(g.clientX,g.clientY);for(const h of m){const y=h.closest?.("[data-editor-path]")?.dataset?.editorPath;if(typeof y=="string"&&(y===t||y.startsWith(`${t}.`))){s(y);return}}}s(t)},onDoubleClick:g=>{g.stopPropagation(),g.preventDefault(),a?.(t)},style:{position:"absolute",left:n.left,top:n.top,width:n.width,height:n.height,cursor:"grab",pointerEvents:"auto",background:p?"rgba(79,70,229,0.06)":"transparent",...r?{border:"1px dashed rgba(79,70,229,0.5)",borderRadius:4}:{},opacity:o?.6:1,zIndex:b,touchAction:"none"}})}function fA(e,t,n,o){if(t==="route")return[];if(t==="modal"||t==="iteration_item")return o&&o.length>0?[o]:[];const r=[],s=(a,l)=>{a.forEach((d,c)=>{const p=[...l,c];if(!ud(d,t,n)){r.push(p);return}const b=Array.isArray(d.children)?d.children:[];b.length>0&&s(b,p)})};return s(e,[]),r}function gA(e){return at(e)}function bi(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function hA({frameEl:e,components:t,editMode:n,currentExtensionId:o,editableRootPath:r}){const[s,a]=u.useState(null),[l]=u.useState(()=>`g7le-dim-mask-${Math.floor(Math.random()*1e9)}`);if(u.useEffect(()=>{if(!e){a(null);return}let g=0;const m=()=>{const _=fA(t,n,o,r);if(_.length===0){a(null);return}const w=e.getBoundingClientRect(),k={left:0,top:0,width:w.width,height:w.height},x=[];for(const $ of _){const C=gA($),S=e.querySelector(`[data-editor-path="${bi(C)}"]`);let D=null;if(S){const E=S.getBoundingClientRect();E.width>0&&E.height>0&&(D={left:E.left,top:E.top,width:E.width,height:E.height})}if(!D){const E=Array.from(e.querySelectorAll(`[data-editor-path^="${bi(C)}.iteration."], [data-editor-path^="${bi(C)}.sortable."], [data-editor-path^="${bi(C)}.children."]`));let I=1/0,N=1/0,T=-1/0,B=-1/0;for(const M of E){const O=M.getBoundingClientRect();O.width<=0||O.height<=0||(I=Math.min(I,O.left),N=Math.min(N,O.top),T=Math.max(T,O.right),B=Math.max(B,O.bottom))}if(T>I&&B>N&&(D={left:I,top:N,width:T-I,height:B-N}),D&&E.length>0){const M=E[0].closest('[role="dialog"]');if(M&&e.contains(M)){const O=M.getBoundingClientRect();O.width>0&&O.height>0&&(D={left:O.left,top:O.top,width:O.width,height:O.height})}}}D&&x.push({left:D.left-w.left,top:D.top-w.top,width:D.width,height:D.height})}if(x.length===0){a(null);return}a({frame:k,holes:x})},h=()=>{g&&cancelAnimationFrame(g),g=requestAnimationFrame(m)};h();const v=typeof ResizeObserver<"u"?new ResizeObserver(h):null;v?.observe(e);const y=typeof MutationObserver<"u"?new MutationObserver(h):null;return y?.observe(e,{childList:!0,subtree:!0,attributes:!0}),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h),()=>{g&&cancelAnimationFrame(g),v?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h)}},[e,t,n,o,r?.join(".")??""]),!s||s.holes.length===0)return null;const{frame:d,holes:c}=s,p=n==="modal"||n==="iteration_item";let f=[];if(p){let g=1/0,m=1/0,h=-1/0,v=-1/0;for(const $ of c)g=Math.min(g,$.left),m=Math.min(m,$.top),h=Math.max(h,$.left+$.width),v=Math.max(v,$.top+$.height);const y=($,C,S)=>Math.max(C,Math.min(S,$)),_=y(g,0,d.width),w=y(m,0,d.height),k=y(h,0,d.width),x=y(v,0,d.height);f=[{left:0,top:0,width:d.width,height:w},{left:0,top:x,width:d.width,height:d.height-x},{left:0,top:w,width:_,height:x-w},{left:k,top:w,width:d.width-k,height:x-w}].filter($=>$.width>0&&$.height>0)}const b=g=>{g.preventDefault(),g.stopPropagation()};return i.jsxs(i.Fragment,{children:[f.map((g,m)=>i.jsx("div",{className:"g7le-source-lock-block","data-testid":"g7le-source-lock-block",onClickCapture:b,onPointerDownCapture:b,onMouseDownCapture:b,onDragStartCapture:b,style:{position:"absolute",left:g.left,top:g.top,width:g.width,height:g.height,zIndex:Yp,pointerEvents:"auto",cursor:"not-allowed",background:"transparent"}},m)),i.jsxs("svg",{className:"g7le-source-lock-dim","data-testid":"g7le-source-lock-dim",width:d.width,height:d.height,style:{position:"absolute",left:0,top:0,width:d.width,height:d.height,zIndex:Yp,pointerEvents:"none"},children:[i.jsx("defs",{children:i.jsxs("mask",{id:l,children:[i.jsx("rect",{x:0,y:0,width:d.width,height:d.height,fill:"white"}),c.map((g,m)=>i.jsx("rect",{"data-testid":"g7le-source-lock-dim-hole",x:g.left,y:g.top,width:g.width,height:g.height,rx:4,fill:"black"},m))]})}),i.jsx("rect",{"data-testid":"g7le-source-lock-dim-box",x:0,y:0,width:d.width,height:d.height,fill:"rgba(15, 23, 42, 0.45)",mask:`url(#${l})`})]})]})}function Bf(e){const t={type:e.type??"basic",name:e.name},n={};if(e.props)for(const[o,r]of Object.entries(e.props))o!=="children"&&r?.default!==void 0&&(n[o]=r.default);return Object.keys(n).length>0&&(t.props=n),t}function yA(e){if(!e?.components)return[];const t=[];for(const[n,o]of Object.entries(e.components))if(Array.isArray(o))for(const r of o)t.push({...r,type:r.type??n});return t}function bA(e,t,n,o,r){const s=yA(e);let a=null;if(n&&t?.containers){const l=t.containers[n];l&&Array.isArray(l.accepts)?a=new Set(l.accepts):a=new Set}else!n&&t?.draggable&&(a=new Set(t.draggable));return s.filter(l=>{if(a&&!a.has(l.name))return!1;if(o){const d=o.toLowerCase(),c=r(l).toLowerCase(),p=l.name.toLowerCase();if(!c.includes(d)&&!p.includes(d)&&!`<${p}>`.includes(d)&&!(l.description??"").toLowerCase().includes(d))return!1}return!0})}function mA(e,t){const n={key:"all",label:"layout_editor.palette.category.all",entries:e,isI18nKey:!0};if(t?.groups&&t.groups.length>0){const a=new Map(e.map(p=>[p.name,p])),l=new Set,d=[];for(const p of t.groups){const f=[];for(const b of p.components??[]){const g=a.get(b);g&&(f.push(g),l.add(b))}f.length!==0&&d.push({key:p.kind??p.label,label:p.label,entries:f,isI18nKey:p.label.startsWith("$t:")||/^[a-z_.]+$/i.test(p.label)})}const c=e.filter(p=>!l.has(p.name));return c.length>0&&d.push({key:"other",label:"layout_editor.palette.category.other",entries:c,isI18nKey:!0}),[n,...d]}const o=new Map;for(const a of e){const l=(a.type??"basic").toLowerCase(),d=o.get(l)??[];d.push(a),o.set(l,d)}const r=["basic","composite","layout"],s=[];for(const a of r){const l=o.get(a);l&&l.length>0&&(s.push({key:a,label:`layout_editor.palette.category.fallback.${a}`,entries:l,isI18nKey:!0}),o.delete(a))}for(const[a,l]of o.entries())s.push({key:a,label:a,entries:l,isI18nKey:!1});return[n,...s]}function Wf(e){const{manifest:t,nesting:n,componentPalette:o,targetParentPath:r,targetContainerName:s,onInsert:a,insertionIndex:l,onClose:d,editorTemplateId:c,editorLocale:p}=e,{t:f,translationEngine:b}=et(),g=u.useMemo(()=>{if(!c||!b)return f;const I=p??null;return N=>{const T={templateId:c,locale:I??"ko"},B=b.translate(N,T);return B!==N?B:f(N)}},[c,p,b,f]),[m,h]=u.useState(""),[v,y]=u.useState("all"),_=o?.entries??null,w=u.useMemo(()=>I=>{const N=_?.[I.name];return N?.label?mi(N.label,g):I.description??I.name},[_,g]),k=u.useMemo(()=>bA(t,n,s,m,w),[t,n,s,m,w]),x=u.useMemo(()=>mA(k,o??null),[k,o]),$=x.find(I=>I.key===v)??x[0]??null,C=!n||!n.draggable&&!n.containers,S=k.length===0,D=$?.entries??[],E=I=>{const N=_?.[I.name],T=!!N?.defaultNode&&typeof N.defaultNode=="object";if(N?.requiresDefaultNode&&!T)return;const B=T?JSON.parse(JSON.stringify(N.defaultNode)):Bf(I),M=r??[];a(B,M,l),pn({source:"palette",draggedComponentName:I.name,targetContainerName:s,targetContainerPath:M.length===0?null:M.join("/"),decision:"allowed",insertionIndex:l,result:"completed",timestamp:Date.now()}),d()};return i.jsxs("div",{className:"g7le-palette","data-testid":"g7le-palette",style:wA,children:[i.jsxs("div",{style:kA,children:[i.jsx("strong",{style:{fontSize:16},children:f("layout_editor.palette.title")}),i.jsx("button",{type:"button",onClick:d,"aria-label":"close","data-testid":"g7le-palette-close",style:SA,children:"×"})]}),i.jsxs("div",{style:CA,children:[i.jsx("aside",{style:$A,"data-testid":"g7le-palette-sidebar",children:i.jsx("nav",{children:i.jsx("ul",{style:EA,children:x.map(I=>{const N=$?.key===I.key,T=I.isI18nKey?mi(I.label,g):I.label;return i.jsx("li",{children:i.jsxs("button",{type:"button","data-testid":`g7le-palette-category-${I.key}`,"data-active":N?"true":"false",onClick:()=>y(I.key),style:{...IA,background:N?"#eff6ff":"transparent",color:N?"#1d4ed8":"#334155",fontWeight:N?600:500},children:[i.jsx("span",{children:T}),i.jsx("span",{style:zA,children:I.entries.length})]})},I.key)})})})}),i.jsxs("main",{style:AA,children:[i.jsx("input",{type:"text",placeholder:f("layout_editor.palette.search_placeholder"),value:m,onChange:I=>h(I.target.value),"data-testid":"g7le-palette-search",style:TA}),i.jsx("div",{style:DA,children:C?i.jsx("div",{style:jf,"data-testid":"g7le-palette-spec-missing",children:f("layout_editor.palette.spec_missing")}):S||D.length===0?i.jsx("div",{style:jf,"data-testid":"g7le-palette-empty",children:f("layout_editor.palette.empty")}):i.jsx("div",{"data-testid":`g7le-palette-group-${$?.key??"all"}`,style:{marginBottom:16},children:i.jsx("div",{style:NA,children:D.map(I=>i.jsx(vA,{entry:I,entrySpec:_?.[I.name]??null,onClick:E,t:f,entryT:g},I.name))})})})]})]})]})}function vA(e){const{entry:t,entrySpec:n,onClick:o,t:r,entryT:s}=e,a=n?.label?mi(n.label,s):t.description??t.name,l=(t.type??"").toLowerCase(),d=l==="basic"||l==="composite"||l==="layout",c=!!n?.defaultNode&&typeof n.defaultNode=="object",p=!!n?.requiresDefaultNode&&!c,f=!c,b=p?r("layout_editor.palette.requires_default_node_missing"):n?.label?mi(n.label,s):t.name;return i.jsxs("button",{type:"button",onClick:()=>o(t),disabled:p,"aria-disabled":p||void 0,"data-testid":`g7le-palette-item-${t.name}`,"data-component-type":l||void 0,"data-blocked":p?"true":void 0,"data-default-node-missing":f?"true":void 0,title:b,style:p?LA:MA,children:[i.jsx("div",{style:OA,"aria-hidden":"true",children:xA(t)}),i.jsx("div",{style:BA,children:a}),i.jsx("div",{"data-testid":`g7le-palette-item-${t.name}-tag`,style:WA,children:`<${t.name}>`}),d&&i.jsx("div",{"data-testid":`g7le-palette-item-${t.name}-badge`,style:_A(l),children:l}),f&&i.jsx("div",{"data-testid":`g7le-palette-item-${t.name}-default-missing-badge`,style:PA,children:r("layout_editor.palette.default_node_missing_badge")})]})}function mi(e,t){return e.startsWith("$t:")?t(e.slice(3)):t(e)}function _A(e){const n={basic:{bg:"#dbeafe",fg:"#1e40af"},composite:{bg:"#dcfce7",fg:"#14532d"},layout:{bg:"#fef3c7",fg:"#854d0e"}}[e]??{bg:"#e2e8f0",fg:"#334155"};return{fontSize:9,fontWeight:600,color:n.fg,background:n.bg,padding:"1px 6px",borderRadius:999,textTransform:"uppercase",letterSpacing:.4,lineHeight:1.6}}function xA(e){const t=e.name;return{Button:"🔘",A:"🔗",Img:"🖼",Icon:"✨",Hr:"➖",P:"📄",Span:"T",H1:"H₁",H2:"H₂",H3:"H₃",H4:"H₄",Ul:"☰",Li:"•",Nav:"🧭",Div:"▢",Container:"▢",Flex:"⇆",Grid:"▦",SectionLayout:"▤",ThreeColumnLayout:"⫼",Form:"📝",Input:"⎕",Textarea:"▭",Select:"⏷",Checkbox:"☑",PasswordInput:"🔒",Label:"🏷",DataGrid:"▦",Pagination:"↔",SearchBar:"🔍",ProductCard:"🛍",ImageGallery:"🖼",Avatar:"👤",UserInfo:"👥",HtmlContent:"⟨/⟩",HtmlEditor:"✏",RichTextEditor:"✏",TabNavigation:"◰",QuantitySelector:"#",ProductImageViewer:"🖼",FileUploader:"📎",AvatarUploader:"📷",SocialLoginButtons:"🌐",PostReactions:"❤"}[t]??"◻"}const wA={display:"flex",flexDirection:"column",width:"100%",height:"100%",minHeight:0,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif'},kA={display:"flex",justifyContent:"space-between",alignItems:"center",padding:"14px 20px",borderBottom:"1px solid #e2e8f0",flexShrink:0},SA={background:"transparent",border:"none",fontSize:24,cursor:"pointer",lineHeight:1,color:"#64748b",padding:"0 4px"},CA={display:"flex",flex:1,minHeight:0},$A={width:180,flexShrink:0,borderRight:"1px solid #e2e8f0",padding:"14px 8px",background:"#f8fafc",overflowY:"auto"},EA={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:4},IA={display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",textAlign:"left",padding:"8px 12px",border:"none",borderRadius:6,fontSize:13,cursor:"pointer",transition:"background-color 120ms"},AA={flex:1,display:"flex",flexDirection:"column",minHeight:0,padding:"14px 20px"},TA={width:"100%",padding:"8px 10px",border:"1px solid #cbd5e1",borderRadius:6,marginBottom:12,fontSize:13,flexShrink:0,boxSizing:"border-box"},DA={flex:1,overflowY:"auto",minHeight:0},zA={fontSize:11,color:"#94a3b8",marginLeft:8,fontWeight:500},NA={display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(96px, 1fr))",gap:10},MA={display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:6,padding:"14px 6px",background:"#fff",border:"1px solid #e2e8f0",borderRadius:8,cursor:"pointer",fontSize:12,minHeight:84,transition:"border-color 120ms, box-shadow 120ms"},LA={display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:6,padding:"14px 6px",background:"#f8fafc",border:"1px dashed #cbd5e1",borderRadius:8,cursor:"not-allowed",fontSize:12,minHeight:84,color:"#94a3b8",opacity:.65},PA={fontSize:9,fontWeight:600,color:"#92400e",background:"#fef3c7",padding:"1px 6px",borderRadius:999,textTransform:"none",letterSpacing:0,lineHeight:1.6},OA={fontSize:22,lineHeight:1,color:"#475569"},BA={fontSize:12,fontWeight:500,color:"#0f172a",textAlign:"center",wordBreak:"break-word"},WA={fontFamily:'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',fontSize:10,color:"#64748b",textAlign:"center",wordBreak:"break-all"},jf={padding:24,color:"#64748b",fontSize:13,textAlign:"center"};function jA(e){const t=[],n=r=>{if(Array.isArray(r))for(const s of r)s&&typeof s=="object"&&t.push(s)};n(e.children);const o=e.responsive;if(o&&typeof o=="object")for(const r of Object.values(o))r&&typeof r=="object"&&n(r.children);return t}function Hf(e){const t=[],n=o=>{const r="isolatedState"in o&&o.isolatedState!=null,s=o.isolatedScopeId;(r||typeof s=="string"&&s.length>0)&&t.push({scopeId:typeof s=="string"?s:void 0,initialState:o.isolatedState&&typeof o.isolatedState=="object"?o.isolatedState:void 0});for(const a of jA(o))n(a)};if(Array.isArray(e))for(const o of e)o&&typeof o=="object"&&n(o);return t}const HA=["scroll","selector","wizard","slider"];function FA(e,t){const n=new Set;for(const o of e)o.scopeId&&n.add(o.scopeId);for(const o of t){n.add(o);for(const r of HA)n.add(`${o}-${r}`)}return Array.from(n)}function Ff(e){return typeof e=="string"&&(br(e)||ts(e))}function Kf(e,t,n=o=>o){const[o,r]=u.useState(!1),[s,a]=u.useState(null),l=n(e),d=Ff(l)&&!o,c=u.useCallback(()=>{a(Ff(l)?l:null),r(!0)},[l]),p=u.useCallback(()=>{s!==null&&l!==s&&t(s),r(!1),a(null)},[s,l,t]);return{bound:d,replacing:o,original:s,beginReplace:c,restore:p}}const KA={display:"flex",flexDirection:"column",gap:4,padding:"8px 10px",border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc"},VA={fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:11,color:"#0f172a",wordBreak:"break-all"},Vf={alignSelf:"flex-start",background:"none",border:"none",padding:0,fontSize:11,color:"#2563eb",cursor:"pointer",textDecoration:"underline"};function Uf({expression:e,t,onReplace:n,testIdPrefix:o}){return i.jsxs("div",{style:KA,children:[i.jsx("code",{"data-testid":`${o}-expression`,style:VA,children:e}),i.jsx("span",{style:{fontSize:11,color:"#64748b"},children:t("layout_editor.control.bound_value.notice")}),i.jsx("button",{type:"button","data-testid":`${o}-expression-replace`,onClick:n,style:Vf,children:t("layout_editor.control.bound_value.replace")})]})}function qf({t:e,onRestore:t,testIdPrefix:n}){return i.jsx("button",{type:"button","data-testid":`${n}-expression-restore`,onClick:t,style:Vf,children:e("layout_editor.control.bound_value.restore")})}function UA(e,t,n){const o=t.label;return typeof o=="string"?o.startsWith("$t:")?n(o.slice(3)):o:e}const qA=new Set(["image","core-id","i18n-text","text"]);function vi({controlKey:e,control:t,node:n,t:o,onPatch:r,candidates:s,bindingCandidates:a,scope:l=jt}){const d=zn(t.widget),c=UA(e,t,o),p=u.useMemo(()=>Lo(n,t,l),[n,t,l]),f=t.widget==="i18n-text"&&t.apply?.type==="propValue",b=t.widget==="text"&&t.apply?.type==="propValue",g=p.darkReadonly===!0||l.colorScheme==="dark"&&t.apply!==void 0&&!Rs(t.apply),m=t.apply,h=l.colorScheme==="dark"&&!g&&m?.type==="classToken"&&typeof m.tokenTemplate=="string"&&m.tokenTemplate.includes("{value}"),v=p.scopedValue===void 0&&p.baseFallback!==void 0,y=u.useCallback(k=>{if(g)return;const x=yn(n,t,k,l);r(x)},[n,t,r,l,g]),_=Kf(p.value,y),w=!qA.has(t.widget??"");return i.jsxs("div",{className:"g7le-control-row","data-testid":`g7le-control-${e}`,style:GA,children:[i.jsxs("span",{className:"g7le-control-label",style:YA,children:[c,p.conflict&&i.jsx("span",{"data-testid":`g7le-control-conflict-${e}`,title:o("layout_editor.property_modal.value_conflict"),style:XA,children:"!"})]}),i.jsx("div",{className:"g7le-control-widget",style:{flex:1,minWidth:0,opacity:v?.45:1},"data-placeholder":v?"true":void 0,children:f?i.jsx(_t,{value:typeof p.value=="string"?p.value:"",onChange:k=>y(k),t:o,testidPrefix:`g7le-prop-i18n-${e}`,candidates:a,enableExpressionTree:!0,expressionTreeCollapsible:!0}):b?i.jsx(Ke,{value:typeof p.value=="string"?p.value:"",onChange:k=>y(k===""?void 0:k),t:o,testidPrefix:`g7le-prop-value-${e}`,candidates:a}):g?i.jsx("span",{"data-testid":`g7le-control-dark-readonly-${e}`,style:ZA,children:o("layout_editor.property_modal.dark_code_only")}):w&&_.bound?i.jsx(Uf,{expression:String(p.value),t:o,onReplace:_.beginReplace,testIdPrefix:`g7le-control-${e}`}):d?i.jsxs(i.Fragment,{children:[i.jsx(d,{control:t,value:p.value,onChange:y,t:o,candidates:s,bindingCandidates:a,freeValueDisabled:h}),w&&_.replacing&&_.original!==null&&i.jsx(qf,{t:o,onRestore:_.restore,testIdPrefix:`g7le-control-${e}`})]}):i.jsx("span",{"data-testid":`g7le-control-unsupported-${e}`,style:JA,children:o("layout_editor.property_modal.unsupported_widget")})})]})}const GA={display:"flex",alignItems:"center",gap:12,padding:"6px 0",minHeight:32,minWidth:0},YA={fontSize:12,color:"#475569",minWidth:88,display:"inline-flex",alignItems:"center",gap:4},XA={display:"inline-flex",width:14,height:14,borderRadius:7,background:"#f59e0b",color:"#fff",fontSize:10,alignItems:"center",justifyContent:"center",fontWeight:700},JA={fontSize:11,color:"#94a3b8",fontStyle:"italic"},ZA={fontSize:11,color:"#94a3b8",fontStyle:"italic"};function _i(e,t,n){return typeof e=="string"?e.startsWith("$t:")?n(e.slice(3)):e:t}function QA(e,t){const n=e.props??{};return t.key in n?n[t.key]:t.default}function RA({spec:e,node:t,t:n,onPatchProp:o}){const r=e.groups??[];return i.jsx("div",{className:"g7le-composite-settings","data-testid":"g7le-composite-settings",style:t6,children:r.map((s,a)=>i.jsxs("div",{className:"g7le-settings-group",style:n6,children:[i.jsx("div",{style:o6,children:_i(s.label,n("layout_editor.property_modal.settings_group",{index:a+1}),n)}),(s.fields??[]).map(l=>i.jsxs("div",{className:"g7le-settings-field","data-testid":`g7le-setting-${l.key}`,style:r6,children:[i.jsx("span",{style:i6,children:_i(l.label,l.key,n)}),i.jsx("div",{style:{flex:1},children:e6(l,t,n,o)})]},l.key))]},a))})}function e6(e,t,n,o){const r=QA(t,e);switch(e.type){case"number":return i.jsx("input",{type:"number","data-testid":`g7le-setting-input-${e.key}`,value:typeof r=="number"?r:"",min:e.min,max:e.max,onChange:s=>o(e.key,s.target.value===""?void 0:Number(s.target.value)),style:za});case"text":return i.jsx("input",{type:"text","data-testid":`g7le-setting-input-${e.key}`,value:typeof r=="string"?r:"",onChange:s=>o(e.key,s.target.value===""?void 0:s.target.value),style:za});case"toggle":return i.jsx("input",{type:"checkbox","data-testid":`g7le-setting-input-${e.key}`,checked:r===!0,onChange:s=>o(e.key,s.target.checked)});case"checkbox-group":{const s=Array.isArray(r)?r:[];return i.jsx("div",{style:s6,"data-testid":`g7le-setting-input-${e.key}`,children:(e.options??[]).map(a=>{const l=s.includes(a.value);return i.jsxs("label",{style:a6,children:[i.jsx("input",{type:"checkbox",checked:l,onChange:d=>{const c=d.target.checked?[...s,a.value]:s.filter(p=>p!==a.value);o(e.key,c)}}),_i(a.label,String(a.value),n)]},String(a.value))})})}case"select":case"board-select":case"datasource-select":default:return i.jsxs("select",{"data-testid":`g7le-setting-input-${e.key}`,value:r==null?"":String(r),onChange:s=>{const a=s.target.value;if(a===""){o(e.key,void 0);return}const l=(e.options??[]).find(d=>String(d.value)===a);o(e.key,l?l.value:a)},style:za,children:[i.jsx("option",{value:"",children:"—"}),(e.options??[]).map(s=>i.jsx("option",{value:String(s.value),children:_i(s.label,String(s.value),n)},String(s.value)))]})}}const t6={display:"flex",flexDirection:"column",gap:16},n6={display:"flex",flexDirection:"column",gap:6},o6={fontSize:12,fontWeight:700,color:"#0f172a",borderBottom:"1px solid #e2e8f0",paddingBottom:4},r6={display:"flex",alignItems:"center",gap:12,minHeight:30},i6={fontSize:12,color:"#475569",minWidth:96},za={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",boxSizing:"border-box"},s6={display:"flex",flexWrap:"wrap",gap:10},a6={display:"inline-flex",alignItems:"center",gap:4,fontSize:12,color:"#0f172a"},l6=["data_binding","isolatedScopeId","parentFormContextProp","skipBindingKeys","isolatedState","component_layout","sortable","itemTemplate"],d6=/\{\{|\$switch|\$get|\|\s*(date|number|truncate|currency|relative)\b/;function xi(e,t=0){return t>6?!1:typeof e=="string"?d6.test(e):Array.isArray(e)?e.some(n=>xi(n,t+1)):e&&typeof e=="object"?Object.values(e).some(n=>xi(n,t+1)):!1}function c6(e){if(rd(e))return!1;const t=Jl(e);return t.length===0?!1:t.some(n=>n.isComplex)}function Gf(e){const t=[],n=e.props??{};for(const o of l6)o in e&&e[o]!==void 0?t.push({key:o,kind:"developer_prop"}):o in n&&n[o]!==void 0&&t.push({key:`props.${o}`,kind:"developer_prop"});typeof e.text=="string"?c6(e.text)&&t.push({key:"text",kind:"complex_expression"}):xi(e.text)&&t.push({key:"text",kind:"complex_expression"});for(const[o,r]of Object.entries(n))o==="style"||o==="className"||xi(r)&&t.push({key:`props.${o}`,kind:"complex_expression"});return t}function u6(e){return Gf(e).length>0}const p6=new Set(["permissions","blur_until_loaded","comment"]);function f6({node:e,advanced:t,t:n,onPatch:o,permissionCandidates:r}){const s=u.useMemo(()=>Gf(e),[e]),a=(l,d)=>{const c={...e};d===void 0?delete c[l]:c[l]=d,o(c)};return i.jsxs("div",{className:"g7le-advanced-props","data-testid":"g7le-advanced-props",style:g6,children:[t.map(l=>{if(!p6.has(l))return i.jsxs("div",{"data-testid":`g7le-advanced-deferred-${l}`,style:y6,children:[n("layout_editor.property_modal.advanced_deferred"),":",l]},l);if(l==="permissions")return i.jsxs("div",{className:"g7le-advanced-group","data-testid":"g7le-advanced-permissions",style:Na,children:[i.jsx("div",{style:Ma,children:n("layout_editor.property_modal.advanced.permissions")}),i.jsx(ks,{control:{widget:"tag-input"},value:e.permissions,onChange:d=>a("permissions",d),t:n,candidates:r})]},l);if(l==="blur_until_loaded"){const d=e.blur_until_loaded===!0||e.blur_until_loaded!=null&&e.blur_until_loaded!==!1;return i.jsxs("div",{className:"g7le-advanced-group","data-testid":"g7le-advanced-blur",style:Na,children:[i.jsx("div",{style:Ma,children:n("layout_editor.property_modal.advanced.blur_until_loaded")}),i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12},children:[i.jsx("input",{type:"checkbox","data-testid":"g7le-advanced-blur-toggle",checked:!!d,onChange:c=>a("blur_until_loaded",c.target.checked?!0:void 0)}),n("layout_editor.property_modal.advanced.blur_hint")]})]},l)}return i.jsxs("div",{className:"g7le-advanced-group","data-testid":"g7le-advanced-comment",style:Na,children:[i.jsx("div",{style:Ma,children:n("layout_editor.property_modal.advanced.comment")}),i.jsx("input",{type:"text","data-testid":"g7le-advanced-comment-input",value:typeof e.comment=="string"?e.comment:"",onChange:d=>a("comment",d.target.value===""?void 0:d.target.value),style:h6})]},l)}),s.length>0&&i.jsxs("div",{className:"g7le-advanced-preserved","data-testid":"g7le-advanced-preserved",style:b6,children:[i.jsx("div",{style:m6,children:n("layout_editor.property_modal.advanced_preserved_title",{count:s.length})}),i.jsx("ul",{style:v6,children:s.map(l=>i.jsxs("li",{"data-testid":`g7le-advanced-preserved-${l.key}`,style:_6,children:[i.jsx("code",{style:{fontSize:11},children:l.key}),i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:l.kind==="developer_prop"?n("layout_editor.property_modal.advanced_kind_developer"):n("layout_editor.property_modal.advanced_kind_expression")})]},l.key))})]})]})}const g6={display:"flex",flexDirection:"column",gap:14},Na={display:"flex",flexDirection:"column",gap:6},Ma={fontSize:12,fontWeight:700,color:"#0f172a"},h6={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",boxSizing:"border-box"},y6={fontSize:11,color:"#94a3b8",fontStyle:"italic"},b6={borderTop:"1px dashed #cbd5e1",paddingTop:10,marginTop:4},m6={fontSize:11,color:"#b45309",marginBottom:6},v6={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:4},_6={display:"flex",justifyContent:"space-between",gap:8,padding:"3px 0"},x6={onClick:"click",onHover:"mouseenter",onChange:"change",onSubmit:"submit",onMount:"mount",onUnmount:"unmount",onFocus:"focus",onBlur:"blur"};function La(e){return x6[e]??e.replace(/^on/,"").toLowerCase()}function Yf(e){const t=e.actions;if(Array.isArray(t))return t.filter(r=>!!r&&typeof r=="object");const n=e.props??{};if(Array.isArray(n.actions))return n.actions.filter(r=>!!r&&typeof r=="object");const o=n.events;if(o&&typeof o=="object"){const r=[];for(const[s,a]of Object.entries(o)){if(!Array.isArray(a))continue;const l=La(s);for(const d of a)d&&typeof d=="object"&&r.push("type"in d?d:{type:l,...d})}return r}return[]}function w6(e,t){const n=La(t);return Yf(e).filter(o=>o.type===n||t==="onClick"&&o.type===void 0)}function k6(e,t,n){const o=La(t),r=Yf(e).filter(d=>!(d.type===o||t==="onClick"&&d.type===void 0)),s=n.map(d=>"type"in d?d:{type:o,...d}),a={...e};if(a.props&&typeof a.props=="object"){const d={...a.props};let c=!1;"actions"in d&&(delete d.actions,c=!0),"events"in d&&(delete d.events,c=!0),c&&(a.props=d)}const l=[...r,...s];return l.length===0?delete a.actions:a.actions=l,a}function S6({node:e,spec:t,capability:n,t:o,onPatchNode:r,pageCandidates:s,dataSourceCandidates:a,stateKeyCandidates:l,bindingCandidates:d}){const c=t?.actionRecipes,p=u.useMemo(()=>({pageCandidates:s,dataSourceCandidates:a,stateKeyCandidates:l,bindingCandidates:d}),[s,a,l,d]),f=Array.isArray(n?.events)?n.events:[];return f.length===0?i.jsx("div",{"data-testid":"g7le-action-no-events",style:Xf,children:o("layout_editor.action.no_events")}):!c||Object.keys(c).length===0?i.jsx("div",{"data-testid":"g7le-action-no-recipes",style:Xf,children:o("layout_editor.action.no_recipes")}):i.jsx("div",{className:"g7le-action-editor","data-testid":"g7le-action-editor",style:{display:"flex",flexDirection:"column",gap:14},children:f.map(b=>i.jsxs("div",{className:"g7le-action-event-slot","data-testid":`g7le-action-event-${b}`,children:[i.jsx("div",{style:C6,children:o(`layout_editor.action.event.${b}`)}),i.jsx(Yt,{actions:w6(e,b),onChange:g=>r(k6(e,b,g)),t:o,recipes:c,candidatePools:p,actionChipCandidates:t?.actionChipCandidates??null,addContext:"component",showSourceBadge:!0,testIdPrefix:`g7le-action-slot-${b}`})]},b))})}const Xf={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},C6={fontSize:12,fontWeight:700,color:"#475569",marginBottom:6};function Pa(e,t,n){if(!t)return n;const o=e(t);return!o||o===t||o.startsWith("$t:")?n:o}function $6(e,t){return Pa(t,e.labelKey,e.path||e.sourceId)}function E6({node:e,spec:t,candidates:n,t:o,onPatchNode:r}){const a=(e.props??{})[t.propKey],l=typeof a=="string"?a:void 0,d=u.useMemo(()=>Vt(a),[a]),c=l!==void 0&&l!==""&&d===null,[p,f]=u.useState(!1),[b,g]=u.useState(""),m=Pa(o,t.label,t.propKey),h=o(t.shape==="array"?"layout_editor.binding.shape_array":t.shape==="object"?"layout_editor.binding.shape_object":"layout_editor.binding.shape_scalar"),v=u.useMemo(()=>Ji(n,t.shape).map(x=>({...x,resolvedLabel:$6(x,o)})),[n,t.shape,o]),y=u.useMemo(()=>Zi(v,b),[v,b]),_=k=>{const x={...e.props??{}};k===void 0?delete x[t.propKey]:x[t.propKey]=k,r({...e,props:x})},w=k=>{_(In(k.sourceId,k.path,t.shape)),f(!1),g("")};return i.jsxs("div",{"data-testid":`g7le-binding-row-${t.propKey}`,style:D6,children:[i.jsxs("div",{style:z6,children:[i.jsx("span",{style:{fontWeight:600,fontSize:12},children:m}),i.jsx("span",{style:N6,children:h}),t.required&&i.jsx("span",{"data-testid":`g7le-binding-required-${t.propKey}`,style:M6,children:o("layout_editor.binding.required")})]}),c?i.jsxs("div",{"data-testid":`g7le-binding-complex-${t.propKey}`,style:B6,children:[o("layout_editor.binding.complex"),i.jsx("code",{style:Jf,children:l})]}):d?i.jsxs("div",{style:L6,children:[i.jsx("code",{"data-testid":`g7le-binding-expr-${t.propKey}`,style:Jf,children:l}),i.jsx("button",{type:"button","data-testid":`g7le-binding-clear-${t.propKey}`,onClick:()=>_(void 0),style:O6,children:o("layout_editor.binding.clear")})]}):i.jsx("div",{"data-testid":`g7le-binding-empty-${t.propKey}`,style:P6,children:o("layout_editor.binding.not_connected")}),d&&(t.shape==="array"||t.shape==="object")&&t.itemFields&&t.itemFields.length>0&&i.jsxs("div",{style:W6,children:[o("layout_editor.binding.item_fields"),": ",t.itemFields.join(", ")]}),!c&&i.jsxs("div",{style:{marginTop:4},children:[i.jsxs("button",{type:"button","data-testid":`g7le-binding-search-toggle-${t.propKey}`,onClick:()=>f(k=>!k),style:j6,children:["🔍 ",o("layout_editor.binding.search")]}),p&&i.jsxs("div",{"data-testid":`g7le-binding-picker-${t.propKey}`,style:H6,children:[i.jsx("input",{type:"text",autoFocus:!0,"data-testid":`g7le-binding-search-input-${t.propKey}`,value:b,placeholder:o("layout_editor.binding.search_placeholder"),onChange:k=>g(k.target.value),style:F6}),i.jsx("div",{style:K6,children:y.length===0?i.jsx("div",{style:V6,children:o("layout_editor.binding.no_results")}):y.map(k=>i.jsxs("button",{type:"button","data-testid":`g7le-binding-candidate-${k.expression}`,onClick:()=>w(k),style:U6,children:[i.jsxs("span",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[i.jsx("span",{style:{fontSize:12},children:k.resolvedLabel}),i.jsxs("span",{style:q6,children:[Pa(o,k.groupLabelKey,k.sourceId)," · ",k.path||k.sourceId]})]}),i.jsx("span",{style:G6,children:k.preview})]},k.expression))})]})]})]})}function I6({node:e,dataProps:t,candidates:n,t:o,onPatchNode:r}){return!Array.isArray(t)||t.length===0?null:i.jsxs("div",{"data-testid":"g7le-data-binding-section",style:A6,children:[i.jsxs("div",{style:T6,children:["🔗 ",o("layout_editor.binding.section_title")]}),t.map(s=>i.jsx(E6,{node:e,spec:s,candidates:n,t:o,onPatchNode:r},s.propKey)),i.jsx("div",{style:Y6})]})}const A6={display:"flex",flexDirection:"column",marginBottom:8},T6={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:6},D6={display:"flex",flexDirection:"column",gap:4,padding:"8px 0"},z6={display:"flex",alignItems:"center",gap:6},N6={fontSize:10,padding:"1px 6px",borderRadius:4,background:"#e0e7ff",color:"#3730a3"},M6={fontSize:10,padding:"1px 6px",borderRadius:4,background:"#fef3c7",color:"#92400e"},L6={display:"flex",alignItems:"center",gap:6},P6={fontSize:11,color:"#94a3b8"},Jf={fontSize:11,fontFamily:"monospace",background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},O6={fontSize:11,border:"1px solid #e2e8f0",borderRadius:4,background:"#fff",color:"#dc2626",padding:"2px 8px",cursor:"pointer"},B6={display:"flex",flexDirection:"column",gap:2,fontSize:11,color:"#64748b"},W6={fontSize:10,color:"#94a3b8"},j6={fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#334155",padding:"4px 10px",cursor:"pointer",textAlign:"left",width:"100%"},H6={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6},F6={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},K6={marginTop:4,maxHeight:200,overflowY:"auto",display:"flex",flexDirection:"column",gap:2},V6={fontSize:11,color:"#94a3b8",padding:"8px 0",textAlign:"center"},U6={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:"none",background:"transparent",cursor:"pointer",padding:"6px 8px",borderRadius:4,textAlign:"left"},q6={fontSize:10,color:"#94a3b8"},G6={fontSize:10,color:"#64748b",fontFamily:"monospace",whiteSpace:"nowrap"},Y6={borderTop:"1px solid #e2e8f0",marginTop:4};function X6({node:e,candidates:t,t:n,onPatchNode:o,templateIdentifier:r}){const s=typeof e.text=="string"?e.text:"",{state:a}=Qe(),l=r??a.templateIdentifier,d=a.selectedRoute?.layoutName??null,c=a.locale,[p,f]=u.useState(!1),b=/^\s*\$t:custom\.[A-Za-z0-9._-]+\s*$/.test(s),m=rd(s)&&(vt(s)?.key.startsWith("custom.")??!1)||b,h=u.useMemo(()=>m?vt(s):null,[m,s]),v=u.useMemo(()=>m?[]:Jl(s),[m,s]),y=D=>{o({...e,text:D})},_=()=>{if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:l,locale:c}}))}catch{}},w=(D,E)=>{const I=In(E.sourceId,E.path,"scalar");y(qb(s,D,I))},k=D=>{const E=vt(s);y(xo(s,D));const I=E?.key;l&&I&&Jd(l,I,D).then(_)},x=D=>{const E=n(D);return E&&E!==D&&!E.startsWith("$t:")?E:""},$=D=>D.replace(/\$t:[a-zA-Z0-9._-]+/g,E=>x(E.slice(3))).replace(/\s+/g," ").trim(),C=D=>{p||(f(!0),hs(l,d,c,s,s.length,D.sourceId,D.path,"scalar",$,E=>n(E)).then(E=>{E.kind==="ok"&&(y(E.text),_())}).finally(()=>f(!1)))},S=D=>{p||!h&&!b||(f(!0),Ir(l,c,s,Number.MAX_SAFE_INTEGER,D.sourceId,D.path,"scalar").then(E=>{E.kind==="ok"&&(y(E.text),_())}).finally(()=>f(!1)))};if(m){const D=h?.params??[];return i.jsxs("div",{"data-testid":"g7le-inline-binding-section",style:Zf,children:[i.jsxs("div",{style:Qf,children:["🔗 ",n("layout_editor.inline_binding.section_title")]}),D.length===0?i.jsx("div",{"data-testid":"g7le-inline-binding-none",style:tg,children:n("layout_editor.inline_binding.none")}):D.map(E=>i.jsx("div",{"data-testid":`g7le-inline-binding-param-${E.name}`,style:Rf,children:E.parsed===null?i.jsxs("div",{"data-testid":`g7le-inline-binding-param-complex-${E.name}`,style:Z6,children:[n("layout_editor.inline_binding.complex"),i.jsx("code",{style:Oa,children:E.expression})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:eg,children:[i.jsx("code",{"data-testid":`g7le-inline-binding-param-expr-${E.name}`,style:Oa,children:E.expression}),i.jsx("button",{type:"button","data-testid":`g7le-inline-binding-param-clear-${E.name}`,onClick:()=>k(E.name),style:J6,children:n("layout_editor.inline_binding.clear")})]}),i.jsx($t,{candidates:t,t:n,onSelect:I=>w(E.name,I),testIdSuffix:`param-${E.name}`})]})},E.name)),i.jsxs("div",{"data-testid":"g7le-inline-binding-param-append",style:ng,children:[i.jsx("div",{style:Ba,children:n("layout_editor.inline_binding.append_hint")}),i.jsx($t,{candidates:t,t:n,onSelect:S,testIdSuffix:"param-append"})]}),i.jsx("div",{"data-testid":"g7le-inline-binding-param-hint",style:Ba,children:n("layout_editor.inline_binding.param_hint")}),i.jsx("div",{style:og})]})}return i.jsxs("div",{"data-testid":"g7le-inline-binding-section",style:Zf,children:[i.jsxs("div",{style:Qf,children:["🔗 ",n("layout_editor.inline_binding.section_title")]}),v.length===0?i.jsx("div",{"data-testid":"g7le-inline-binding-none",style:tg,children:n("layout_editor.inline_binding.none")}):v.map(D=>i.jsx("div",{"data-testid":`g7le-inline-binding-row-${D.bindingIndex}`,style:Rf,children:i.jsx("div",{style:eg,children:i.jsx("code",{"data-testid":`g7le-inline-binding-expr-${D.bindingIndex}`,style:Oa,children:D.expression})})},D.bindingIndex)),i.jsxs("div",{"data-testid":"g7le-inline-binding-append",style:ng,children:[i.jsx("div",{style:Ba,children:n("layout_editor.inline_binding.append_hint")}),i.jsx($t,{candidates:t,t:n,onSelect:C,testIdSuffix:"append"})]}),i.jsx("div",{style:og})]})}const Zf={display:"flex",flexDirection:"column",marginBottom:8},Qf={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:6},Rf={display:"flex",flexDirection:"column",gap:4,padding:"8px 0"},eg={display:"flex",alignItems:"center",gap:6},tg={fontSize:11,color:"#94a3b8"},Oa={fontSize:11,fontFamily:"monospace",background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},J6={fontSize:11,border:"1px solid #e2e8f0",borderRadius:4,background:"#fff",color:"#dc2626",padding:"2px 8px",cursor:"pointer"},Z6={display:"flex",flexDirection:"column",gap:2,fontSize:11,color:"#64748b"},ng={display:"flex",flexDirection:"column",gap:2,padding:"8px 0 0"},Ba={fontSize:11,color:"#475569",fontWeight:600},og={borderTop:"1px solid #e2e8f0",marginTop:4};function rg(e,t,n){if(!t)return n;const o=e(t);return!o||o===t||o.startsWith("$t:")?n:o}function Q6(e,t){return rg(t,e.labelKey,e.path||e.sourceId)}function R6(e){const t=e.iteration;return t&&typeof t=="object"?t:null}function eT({node:e,candidates:t,t:n,onPatchNode:o}){const r=R6(e),s=r?.source,a=typeof s=="string"?s:void 0,l=u.useMemo(()=>Vt(s),[s]),d=a!==void 0&&a!==""&&l===null,[c,p]=u.useState(!1),[f,b]=u.useState(""),g=u.useMemo(()=>Ji(t,"array").map(k=>({...k,resolvedLabel:Q6(k,n)})),[t,n]),m=u.useMemo(()=>Zi(g,f),[g,f]);if(!r)return null;const h=typeof r.item_var=="string"?r.item_var:void 0,v=typeof r.index_var=="string"?r.index_var:void 0,y=w=>{const k={...r};w===void 0?delete k.source:k.source=w,o({...e,iteration:k})},_=w=>{y(In(w.sourceId,w.path,"array")),p(!1),b("")};return i.jsxs("div",{"data-testid":"g7le-iteration-binding-section",style:tT,children:[i.jsxs("div",{style:nT,children:["🔁 ",n("layout_editor.binding.iteration_title")]}),i.jsx("div",{style:oT,children:n("layout_editor.binding.iteration_hint")}),i.jsxs("div",{style:rT,children:[i.jsxs("div",{style:iT,children:[i.jsx("span",{style:{fontWeight:600,fontSize:12},children:n("layout_editor.binding.iteration_label")}),i.jsx("span",{style:sT,children:n("layout_editor.binding.shape_array")})]}),d?i.jsxs("div",{"data-testid":"g7le-iteration-binding-complex",style:cT,children:[n("layout_editor.binding.complex"),i.jsx("code",{style:ig,children:a})]}):l?i.jsxs("div",{style:aT,children:[i.jsx("code",{"data-testid":"g7le-iteration-binding-expr",style:ig,children:a}),i.jsx("button",{type:"button","data-testid":"g7le-iteration-binding-clear",onClick:()=>y(void 0),style:dT,children:n("layout_editor.binding.clear")})]}):i.jsx("div",{"data-testid":"g7le-iteration-binding-empty",style:lT,children:n("layout_editor.binding.not_connected")}),(h||v)&&i.jsxs("div",{"data-testid":"g7le-iteration-vars",style:uT,children:[h&&i.jsxs("span",{children:[n("layout_editor.binding.iteration_item_var"),": ",i.jsx("code",{style:sg,children:h})]}),v&&i.jsxs("span",{children:[n("layout_editor.binding.iteration_index_var"),": ",i.jsx("code",{style:sg,children:v})]})]}),!d&&i.jsxs("div",{style:{marginTop:4},children:[i.jsxs("button",{type:"button","data-testid":"g7le-iteration-binding-search-toggle",onClick:()=>p(w=>!w),style:pT,children:["🔍 ",n("layout_editor.binding.search")]}),c&&i.jsxs("div",{"data-testid":"g7le-iteration-binding-picker",style:fT,children:[i.jsx("input",{type:"text",autoFocus:!0,"data-testid":"g7le-iteration-binding-search-input",value:f,placeholder:n("layout_editor.binding.search_placeholder"),onChange:w=>b(w.target.value),style:gT}),i.jsx("div",{style:hT,children:m.length===0?i.jsx("div",{style:yT,children:n("layout_editor.binding.no_results")}):m.map(w=>i.jsxs("button",{type:"button","data-testid":`g7le-iteration-binding-candidate-${w.expression}`,onClick:()=>_(w),style:bT,children:[i.jsxs("span",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[i.jsx("span",{style:{fontSize:12},children:w.resolvedLabel}),i.jsxs("span",{style:mT,children:[rg(n,w.groupLabelKey,w.sourceId)," · ",w.path||w.sourceId]})]}),i.jsx("span",{style:vT,children:w.preview})]},w.expression))})]})]})]}),i.jsx("div",{style:_T})]})}const tT={display:"flex",flexDirection:"column",marginBottom:8},nT={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:4},oT={fontSize:10,color:"#94a3b8",marginBottom:6,lineHeight:1.4},rT={display:"flex",flexDirection:"column",gap:4,padding:"8px 0"},iT={display:"flex",alignItems:"center",gap:6},sT={fontSize:10,padding:"1px 6px",borderRadius:4,background:"#e0e7ff",color:"#3730a3"},aT={display:"flex",alignItems:"center",gap:6},lT={fontSize:11,color:"#94a3b8"},ig={fontSize:11,fontFamily:"monospace",background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},dT={fontSize:11,border:"1px solid #e2e8f0",borderRadius:4,background:"#fff",color:"#dc2626",padding:"2px 8px",cursor:"pointer"},cT={display:"flex",flexDirection:"column",gap:2,fontSize:11,color:"#64748b"},uT={display:"flex",gap:12,fontSize:10,color:"#94a3b8",marginTop:2},sg={fontSize:10,fontFamily:"monospace",background:"#f1f5f9",padding:"1px 4px",borderRadius:3,color:"#475569"},pT={fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#334155",padding:"4px 10px",cursor:"pointer",textAlign:"left",width:"100%"},fT={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6},gT={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},hT={marginTop:4,maxHeight:200,overflowY:"auto",display:"flex",flexDirection:"column",gap:2},yT={fontSize:11,color:"#94a3b8",padding:"8px 0",textAlign:"center"},bT={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:"none",background:"transparent",cursor:"pointer",padding:"6px 8px",borderRadius:4,textAlign:"left"},mT={fontSize:10,color:"#94a3b8"},vT={fontSize:10,color:"#64748b",fontFamily:"monospace",whiteSpace:"nowrap"},_T={borderTop:"1px solid #e2e8f0",marginTop:4},xT=new Set(["Span","P","H1","H2","H3","H4","H5","H6","A","Button","Li","Label"]);function wT(e,t){if(!e||e.iteration&&typeof e.iteration=="object")return!1;const n=t?.textBinding;if(n===!1)return!1;if(n===!0)return!0;const o=typeof e.name=="string"?e.name:"";return xT.has(o)?!0:typeof e.text=="string"}const mn={direction:"flexDirection",justify:"flexJustify",align:"flexAlign",wrap:"flexWrap",gap:"flexGap",enable:"flexEnable"},wi={grow:"flexItemGrow",selfAlign:"flexItemAlign",order:"flexItemOrder"};function ag(e){const t=e?.flexEditor;return t==="container"||t==="item"||t==="auto"?t:null}function kT(e){if(!e||typeof window>"u"||typeof window.getComputedStyle!="function")return!1;const t=(window.getComputedStyle(e).display??"").toLowerCase();return t==="flex"||t==="inline-flex"}function ST(e,t,n=jt){if(!e||!t)return!1;const o=Lo(e,t,n),r=t.options,s=Array.isArray(r)?t.onValue??r[0]?.value:void 0,a=l=>s!==void 0?l===s:l!==void 0&&l!==!1;return n.breakpoint!=="base"?a(o.scopedRawValue):o.matched&&a(o.value)}function CT(e,t,n=!1,o=!1,r=jt){if(e==="container")return{showContainer:!0,showEnableButton:!1,showDisableButton:!1};if(e==="item")return{showContainer:!1,showEnableButton:!1,showDisableButton:!1};if(e==="auto"){const s=r.breakpoint==="base";return!o&&!s?{showContainer:!1,showEnableButton:!1,showDisableButton:!1}:(o?n:kT(t))?{showContainer:!0,showEnableButton:!1,showDisableButton:o}:{showContainer:!1,showEnableButton:!0,showDisableButton:!1}}return{showContainer:!1,showEnableButton:!1,showDisableButton:!1}}const $T={[mn.direction]:"layout_editor.flex.direction",[mn.justify]:"layout_editor.flex.justify",[mn.align]:"layout_editor.flex.align",[mn.wrap]:"layout_editor.flex.wrap",[mn.gap]:"layout_editor.flex.gap"},ET={[wi.grow]:"layout_editor.flex.item_grow",[wi.selfAlign]:"layout_editor.flex.item_align",[wi.order]:"layout_editor.flex.item_order"};function IT({node:e,spec:t,capability:n,t:o,onPatchNode:r,liveElement:s,scope:a=jt}){const l=ag(n),d=Ct(t,mn.enable),c=ST(e,d,a),{showContainer:p,showEnableButton:f,showDisableButton:b}=CT(l,s,c,!!d,a),g=Object.values(mn).filter(x=>x!==mn.enable&&Ct(t,x)),m=Object.values(wi).filter(x=>Ct(t,x)),h=d?.options,v=d?.onValue??h?.[0]?.value??!0,y=Array.isArray(h)&&h.length>=2?h[1].value:void 0,_=()=>{if(!d)return;const x=yn(e,d,v,a);r(x)},w=()=>{if(!d)return;const x=a.breakpoint!=="base"&&y!==void 0?y:void 0,$=yn(e,d,x,a);r($)},k=(x,$,C)=>i.jsx("div",{"data-testid":C,style:{display:"flex",flexDirection:"column"},children:x.map(S=>{const D=Ct(t,S);if(!D)return null;const E=D.label?D:{...D,label:`$t:${$[S]}`};return i.jsx(vi,{controlKey:S,control:E,node:e,t:o,onPatch:r,scope:a},S)})});return i.jsxs("div",{className:"g7le-flex-editor","data-testid":"g7le-flex-editor",style:{display:"flex",flexDirection:"column",gap:12},children:[f&&i.jsx("button",{type:"button","data-testid":"g7le-flex-enable",onClick:_,style:AT,children:o("layout_editor.flex.make_flex")}),p&&g.length>0&&i.jsxs("div",{className:"g7le-flex-container-section","data-testid":"g7le-flex-container-section",children:[i.jsx("div",{style:lg,children:o("layout_editor.flex.container_title")}),k(g,$T,"g7le-flex-container-controls"),b&&i.jsx("button",{type:"button","data-testid":"g7le-flex-disable",onClick:w,style:TT,children:o("layout_editor.flex.unmake_flex")})]}),l==="item"&&m.length>0&&i.jsxs("div",{className:"g7le-flex-item-section","data-testid":"g7le-flex-item-section",children:[i.jsx("div",{style:lg,children:o("layout_editor.flex.item_title")}),k(m,ET,"g7le-flex-item-controls")]}),!p&&!f&&l!=="item"&&i.jsx("div",{"data-testid":"g7le-flex-empty",style:DT,children:o("layout_editor.flex.not_flex")})]})}const lg={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:6},AT={padding:"8px 12px",fontSize:12,border:"1px dashed #2563eb",borderRadius:6,background:"#eff6ff",color:"#2563eb",cursor:"pointer"},TT={marginTop:8,padding:"6px 10px",fontSize:12,border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",color:"#64748b",cursor:"pointer"},DT={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},dg=["desktop","tablet","mobile","portable"],Wa=1280,zT=820,NT=390,MT=1920,LT=320;function PT(e){const t=[],n=new Set,o=r=>{if(!r||typeof r!="object")return;const s=r.responsive;if(s&&typeof s=="object")for(const a of Object.keys(s)){n.has(a)||(n.add(a),t.push(a));const l=s[a]?.children;if(Array.isArray(l))for(const d of l)o(d)}if(Array.isArray(r.children))for(const a of r.children)o(a)};if(Array.isArray(e))for(const r of e)o(r);return t}function OT(e){const t=[...dg],n=new Set(dg);for(const o of PT(e))!n.has(o)&&!t.includes(o)&&t.push(o);return t}function BT(e,t){const n=e?.responsive;if(!n||typeof n!="object")return[];const o=[];for(const r of Object.keys(n)){const s=n[r];!s||!Array.isArray(s.children)||r!==t&&o.push(r)}return o}function WT(e){switch(e){case"desktop":return Wa;case"tablet":return zT;case"mobile":return NT}const t=e in Mo?Mo[e]:Pn.parseRange(e);return!t||!Number.isFinite(t.max)?Wa:Math.round(Math.max(LT,Math.min(MT,t.max)))}function cg(){const t=Kt()?.document?.raw?.components;return u.useMemo(()=>OT(t??null),[t])}const jT={desktop:"layout_editor.property_modal.scope.device_desktop",tablet:"layout_editor.property_modal.scope.device_tablet",mobile:"layout_editor.property_modal.scope.device_mobile",portable:"layout_editor.property_modal.scope.device_portable"},HT=[{key:"base",labelKey:"layout_editor.property_modal.scope.scheme_light"},{key:"dark",labelKey:"layout_editor.property_modal.scope.scheme_dark"}];function ug({scope:e,onChange:t,node:n,t:o,showColorScheme:r=!0,onClearScope:s}){const[a,l]=u.useState(!1),[d,c]=u.useState(""),[p,f]=u.useState(""),[b,g]=u.useState(null),m=cg(),h=u.useMemo(()=>{const w=["base",...m],k=new Set(w);for(const x of Object.keys(n.responsive??{}))x!=="base"&&!k.has(x)&&(k.add(x),w.push(x));return e.breakpoint!=="base"&&!k.has(e.breakpoint)&&w.push(e.breakpoint),w},[m,n.responsive,e.breakpoint]),v=w=>t({...e,colorScheme:w}),y=w=>t({...e,breakpoint:w}),_=()=>{const w=d.trim(),k=p.trim();if(w===""&&k===""){g(o("layout_editor.property_modal.scope.custom_invalid"));return}const x=`${w}-${k}`;if(!OC(x)){g(o("layout_editor.property_modal.scope.custom_invalid"));return}g(null),l(!1),c(""),f(""),y(x)};return i.jsxs("div",{className:"g7le-style-scope-tabs","data-testid":"g7le-style-scope-tabs",style:FT,children:[r&&i.jsx("div",{className:"g7le-style-scope-scheme","data-testid":"g7le-style-scope-scheme",role:"tablist","aria-label":o("layout_editor.property_modal.scope.scheme_light"),style:pg,children:HT.map(w=>{const k=e.colorScheme===w.key;return i.jsxs("button",{type:"button",role:"tab","aria-selected":k,"data-testid":`g7le-style-scheme-${w.key}`,"data-active":k?"true":"false",onClick:()=>v(w.key),style:fg(k),children:[o(w.labelKey),w.key==="dark"&&ta(n,{colorScheme:"dark",breakpoint:e.breakpoint})&&i.jsx("span",{"data-testid":"g7le-style-scheme-dark-dot",style:gg})]},w.key)})}),i.jsxs("div",{className:"g7le-style-scope-device","data-testid":"g7le-style-scope-device",role:"tablist","aria-label":o("layout_editor.property_modal.scope.device_base"),style:pg,children:[h.map(w=>{const k=e.breakpoint===w,x=w==="base"||zu(w),$=w==="base"?"layout_editor.property_modal.scope.device_base":jT[w],C=$?o($):w,S=x?`g7le-style-bp-${w}`:`g7le-style-bp-custom-${w}`;return i.jsxs("button",{type:"button",role:"tab","aria-selected":k,"data-testid":S,"data-active":k?"true":"false",onClick:()=>y(w),style:fg(k),children:[C,ta(n,{colorScheme:"base",breakpoint:w})&&i.jsx("span",{"data-testid":`${S}-dot`,style:gg})]},String(w))}),i.jsxs("button",{type:"button","data-testid":"g7le-style-bp-add-custom",onClick:()=>l(w=>!w),style:UT,children:["+ ",o("layout_editor.property_modal.scope.add_custom")]})]}),a&&i.jsxs("div",{className:"g7le-style-scope-custom-input","data-testid":"g7le-style-scope-custom-input",style:KT,children:[i.jsx("input",{type:"number","data-testid":"g7le-style-custom-min",placeholder:o("layout_editor.property_modal.scope.custom_min"),value:d,onChange:w=>c(w.target.value),style:hg}),i.jsx("span",{style:{color:"#94a3b8"},children:"—"}),i.jsx("input",{type:"number","data-testid":"g7le-style-custom-max",placeholder:o("layout_editor.property_modal.scope.custom_max"),value:p,onChange:w=>f(w.target.value),style:hg}),i.jsx("button",{type:"button","data-testid":"g7le-style-custom-confirm",onClick:_,style:qT,children:o("layout_editor.property_modal.scope.add_custom")})]}),b&&i.jsx("div",{"data-testid":"g7le-style-custom-error",style:GT,children:b}),e.breakpoint!=="base"&&!zu(e.breakpoint)&&i.jsx("div",{"data-testid":"g7le-style-custom-priority-note",style:YT,children:o("layout_editor.property_modal.scope.custom_priority_note")}),s&&ta(n,e)&&i.jsxs("button",{type:"button","data-testid":"g7le-style-scope-reset",onClick:s,style:VT,children:["↺ ",o("layout_editor.property_modal.scope.reset_to_base")]})]})}const FT={display:"flex",flexDirection:"column",gap:0,padding:"0 0 8px",borderBottom:"1px solid #e2e8f0",marginBottom:8},KT={display:"flex",gap:6,alignItems:"center",marginTop:4},pg={display:"flex",gap:2,flexWrap:"wrap",borderBottom:"1px solid #e2e8f0",margin:"0 -16px",padding:"0 12px"};function fg(e){return{display:"inline-flex",alignItems:"center",gap:4,padding:"6px 12px",fontSize:12,border:"none",borderBottom:`2px solid ${e?"#2563eb":"transparent"}`,background:"transparent",color:e?"#2563eb":"#64748b",cursor:"pointer",fontWeight:e?700:500,marginBottom:-1}}const gg={display:"inline-block",width:5,height:5,borderRadius:3,background:"#f59e0b"},VT={alignSelf:"flex-start",marginTop:2,padding:"3px 8px",fontSize:10,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},UT={padding:"6px 12px",fontSize:11,border:"none",borderBottom:"2px dashed #cbd5e1",background:"transparent",color:"#475569",cursor:"pointer",marginBottom:-1},hg={width:70,padding:"4px 6px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6},qT={padding:"4px 10px",fontSize:11,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},GT={fontSize:11,color:"#dc2626"},YT={fontSize:10,color:"#94a3b8"},yg=new Map;function Bn(e,t){yg.set(e,t)}function XT(e){return e?yg.get(e)??null:null}const ja={id:{label:"$t:layout_editor.core_props.id.label",widget:"core-id",placeholder:"$t:layout_editor.core_props.id.placeholder",apply:{type:"propValue",propKey:"id"}},dataKey:{label:"$t:layout_editor.core_props.dataKey.label",widget:"core-datakey",placeholder:"$t:layout_editor.core_props.dataKey.placeholder",apply:{type:"nodeKey",nodeKey:"dataKey"}},isolatedState:{label:"$t:layout_editor.core_props.isolatedState.label",widget:"toggle",apply:{type:"nodeKey",nodeKey:"isolatedState"}},isolatedScopeId:{label:"$t:layout_editor.core_props.isolatedScopeId.label",widget:"core-scopeid",placeholder:"$t:layout_editor.core_props.isolatedScopeId.placeholder",apply:{type:"nodeKey",nodeKey:"isolatedScopeId"}}},JT=["id"];function ZT(e){return e===!1?[]:Array.isArray(e)?e.filter(t=>t in ja&&!bg.has(t)):JT.filter(t=>!bg.has(t))}const bg=new Set(["isolatedState","isolatedScopeId"]);function mg(e){const t=e.props?.id??e.id;return typeof t=="string"&&t.length>0?`${t}-scope`:"scope"}function QT({node:e,onPatchNode:t,t:n,scopeIdCandidates:o=[],usedScopeIds:r=[]}){const s=e,a="isolatedState"in s&&s.isolatedState!=null,l=typeof s.isolatedScopeId=="string"?s.isolatedScopeId:"",[d,c]=u.useState(""),p=()=>{const h={...e};a?(delete h.isolatedState,delete h.isolatedScopeId):(h.isolatedState={},h.isolatedScopeId=mg(e)),t(h)},f=h=>{const v={...e};v.isolatedScopeId=h.trim()===""?mg(e):h,t(v)},b=h=>{const v={...e};v.isolatedState=h,t(v)},g=u.useMemo(()=>{const h=d.trim().toLowerCase();return o.filter(v=>!h||v.toLowerCase().includes(h))},[o,d]),m=l!==""&&r.includes(l);return i.jsxs("div",{className:"g7le-isolated-scope","data-testid":"g7le-isolated-scope-control",style:RT,children:[i.jsx("div",{style:e4,children:n("layout_editor.core_props.isolatedState.label")}),i.jsxs("div",{style:t4,children:[i.jsx("button",{type:"button","data-testid":"g7le-isolated-toggle",role:"switch","aria-checked":a,onClick:p,style:n4(a),children:n(a?"layout_editor.overlay.on":"layout_editor.overlay.off")}),a?null:i.jsx("span",{"data-testid":"g7le-isolated-off-hint",style:o4,children:n("layout_editor.core_props.isolatedState.off_hint")})]}),a?i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:vg,children:[i.jsx("label",{style:_g,children:n("layout_editor.core_props.isolatedScopeId.label")}),i.jsx("input",{type:"text","data-testid":"g7le-isolated-scopeid-input",value:l,placeholder:n("layout_editor.core_props.isolatedScopeId.placeholder"),onChange:h=>f(h.target.value),style:r4}),g.length>0?i.jsxs("div",{"data-testid":"g7le-isolated-scopeid-picker",style:i4,children:[i.jsx("input",{type:"text","data-testid":"g7le-isolated-scopeid-search",value:d,placeholder:n("layout_editor.core_props.isolatedScopeId.search"),onChange:h=>c(h.target.value),style:s4}),i.jsx("div",{style:a4,children:g.map(h=>i.jsx("button",{type:"button","data-testid":`g7le-isolated-scopeid-candidate-${h}`,onClick:()=>{f(h),c("")},style:l4,children:h},h))})]}):null,m?i.jsxs("p",{"data-testid":"g7le-isolated-scopeid-dup",style:d4,children:["ⓘ ",n("layout_editor.core_props.isolatedScopeId.duplicate")]}):null]}),i.jsxs("div",{style:vg,children:[i.jsx("label",{style:_g,children:n("layout_editor.core_props.isolatedState.initial_label")}),i.jsx("div",{"data-testid":"g7le-isolated-initial-value",children:i.jsx(Mn,{value:s.isolatedState??{},onChange:b,t:n,path:"isolatedState",scope:"isolated-node"})})]})]}):null]})}const RT={display:"flex",flexDirection:"column",gap:8,padding:10,border:"1px solid #e2e8f0",borderRadius:8,minWidth:0},e4={fontSize:12,fontWeight:700,color:"#0f172a"},t4={display:"flex",gap:8,alignItems:"center"},n4=e=>({padding:"4px 12px",fontSize:11,border:`1px solid ${e?"#3b82f6":"#cbd5e1"}`,borderRadius:14,background:e?"#eff6ff":"#fff",color:e?"#1d4ed8":"#64748b",cursor:"pointer"}),o4={fontSize:11,color:"#94a3b8"},vg={display:"flex",flexDirection:"column",gap:4,minWidth:0},_g={fontSize:11,color:"#64748b"},r4={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box",width:"100%"},i4={border:"1px solid #e2e8f0",borderRadius:6,padding:4,background:"#fff"},s4={width:"100%",padding:"4px 6px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,marginBottom:4,boxSizing:"border-box"},a4={display:"flex",flexDirection:"column",maxHeight:120,overflowY:"auto"},l4={textAlign:"left",padding:"4px 6px",fontSize:12,border:"none",background:"transparent",cursor:"pointer",borderRadius:4,color:"#0f172a"},d4={margin:0,fontSize:11,color:"#64748b"},c4={borderTop:"2px solid #c7d2fe",background:"#eef2ff",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8},xg={fontSize:13,fontWeight:700,color:"#3730a3",display:"flex",alignItems:"center",gap:6},u4={fontSize:11,fontWeight:600,color:"#4338ca",background:"#e0e7ff",border:"1px solid #c7d2fe",borderRadius:4,padding:"1px 6px"},Ha={fontSize:11,color:"#6366f1"},p4={alignSelf:"flex-start",fontSize:12,fontWeight:600,color:"#fff",background:"#4f46e5",border:"none",borderRadius:4,padding:"4px 10px",cursor:"pointer"},f4={opacity:.5,cursor:"not-allowed"},g4={fontSize:11,color:"#dc2626"};function h4({entry:e,t,onSave:n}){const[o,r]=u.useState(()=>e.props),[s,a]=u.useState(!0),[l,d]=u.useState(null),[c,p]=u.useState(!1),[f,b]=u.useState(!1),g=e.extensionName??e.extensionIdentifier??`#${e.extensionId}`,m=async()=>{if(!s){d(t("layout_editor.property_modal.injected_props.invalid_json"));return}d(null),p(!0),b(!1);try{await n(o),b(!0)}catch(h){d(h instanceof Error?h.message:String(h))}finally{p(!1)}};return i.jsxs("div",{"data-testid":`g7le-injected-props-entry-${e.extensionId}`,style:{display:"flex",flexDirection:"column",gap:6},children:[i.jsx("div",{style:xg,children:i.jsx("span",{style:u4,"data-testid":"g7le-injected-props-origin-badge",children:t("layout_editor.property_modal.injected_props.origin",{source:g})})}),i.jsx(Us,{value:o,shape:"object",emptyValue:{},testidPrefix:"g7le-injected-props-json",minHeight:80,invalidErrorKey:"layout_editor.property_modal.injected_props.invalid_json",shapeErrorKey:"layout_editor.property_modal.injected_props.invalid_json",t,onChange:h=>{r(h??{}),b(!1)},onValidityChange:h=>{a(h),h&&d(null),b(!1)}}),l&&i.jsx("div",{style:g4,"data-testid":"g7le-injected-props-error",children:l}),f&&i.jsx("div",{style:{...Ha,color:"#16a34a"},"data-testid":"g7le-injected-props-saved",children:t("layout_editor.property_modal.injected_props.saved")}),i.jsx("div",{style:Ha,children:t("layout_editor.property_modal.injected_props.save_target")}),i.jsx("button",{type:"button","data-testid":"g7le-injected-props-save",style:{...p4,...c||!s?f4:null},disabled:c||!s,onClick:m,children:c?t("layout_editor.property_modal.injected_props.saving"):t("layout_editor.property_modal.injected_props.save_button",{source:g})})]})}function y4({injectedProps:e,t,onSaveInjectedProps:n}){return!Array.isArray(e)||e.length===0?null:i.jsxs("div",{style:c4,"data-testid":"g7le-injected-props-section",children:[i.jsxs("div",{style:xg,children:["🧩 ",t("layout_editor.property_modal.injected_props.title")]}),i.jsx("div",{style:Ha,children:t("layout_editor.property_modal.injected_props.help")}),e.map(o=>i.jsx(h4,{entry:o,t,onSave:r=>n(o.extensionId,r)},o.extensionId))]})}function b4(e,t){const n=e?.components??{};for(const o of Object.values(n)){const r=o?.find(s=>s.name===t);if(r)return r}return null}function m4({node:e,spec:t,manifest:n,t:o,onPatchNode:r,onClose:s,onDelete:a,permissionCandidates:l,pageCandidates:d,dataSourceCandidates:c,stateKeyCandidates:p,bindingCandidates:f,liveElement:b,scope:g=jt,onScopeChange:m,templateIdentifier:h,initialTab:v,onSaveInjectedProps:y,branchLabel:_,isolatedScopeIdCandidates:w,usedScopeIds:k}){const x=e.__injectedProps,$=Array.isArray(x)&&x.length>0&&!!y,C=ve=>{m?.(ve)},S=()=>{r(VC(e,g))},D=typeof e.name=="string"?e.name:"",E=Ui(t,D),N=b4(n,D)?.settings,T=!!(N?.groups&&N.groups.length>0),B=Array.isArray(E?.propControls)?E.propControls:[],M=ZT(E?.coreProps),O=new Set(M.map(ve=>ja[ve].apply?.propKey)),z=B.filter(ve=>{const We=Ct(t,ve)?.apply?.propKey;return!(We!==void 0&&O.has(We))}),H=typeof E?.nodeEditor?.kind=="string"?E.nodeEditor.kind:void 0,P=E?.nodeEditor?.params,A=H?XT(H):null,L=!!A,F=Array.isArray(E?.dataProps)?E.dataProps:[],Y=F.length>0,V=!!(e.iteration&&typeof e.iteration=="object"),X=wT(e,E),Z=M.length>0||z.length>0||L||Y||X||V,ie=Array.isArray(E?.styleControls)?E.styleControls:[],oe=Array.isArray(E?.advanced)?E.advanced:[],ee=(Array.isArray(E?.events)?E.events:[]).length>0,fe=ag(E),K=ie.length>0||fe!==null,ye=!(E?.visibilityCondition===!1)&&(Z||K||ee||T||oe.length>0),Se=u.useMemo(()=>{const ve=[];return T&&ve.push("settings"),Z&&ve.push("props"),K&&ve.push("style"),ee&&ve.push("action"),ye&&ve.push("visibility"),ve.push("translation"),oe.length>0&&ve.push("advanced"),ve},[T,Z,K,ee,ye,oe.length]),De=z.length>0||L||Y||V,[Ie,Ve]=u.useState(v&&Se.includes(v)?v:T?"settings":De?"props":K?"style":Z?"props":Se[0]??"style"),ze=u6(e),Be=!Z&&!K&&!T&&!ee&&!ye&&oe.length===0,Xe=E?.label?E.label.startsWith("$t:")?o(E.label.slice(3)):E.label:D||o("layout_editor.property_modal.element"),Ne=(ve,qe)=>{const We={...e.props??{}};qe===void 0?delete We[ve]:We[ve]=qe,r({...e,props:We})},Je={settings:o("layout_editor.property_modal.tab.settings"),props:o("layout_editor.property_modal.tab.props"),style:o("layout_editor.property_modal.tab.style"),action:o("layout_editor.property_modal.tab.action"),visibility:o("layout_editor.property_modal.tab.visibility"),translation:o("layout_editor.property_modal.tab.translation"),advanced:o("layout_editor.property_modal.tab.advanced")};return i.jsxs("div",{className:"g7le-property-modal","data-testid":"g7le-property-modal",style:v4,children:[i.jsxs("div",{"data-modal-drag-handle":!0,"data-testid":"g7le-property-modal-header",style:_4,children:[i.jsx("span",{"data-testid":"g7le-property-modal-title",style:{fontSize:14,fontWeight:700},children:T&&Ie==="settings"?o("layout_editor.property_modal.settings_title",{name:Xe}):o("layout_editor.property_modal.title",{name:Xe})}),i.jsx("button",{type:"button","data-testid":"g7le-property-modal-close","aria-label":"close",onClick:s,style:x4,children:"✕"})]}),ze&&i.jsx("div",{"data-testid":"g7le-property-modal-advanced-badge",style:w4,children:o("layout_editor.property_modal.advanced_badge")}),_&&i.jsx("div",{"data-testid":"g7le-property-modal-branch-badge",style:k4,children:o("layout_editor.property_modal.branch_badge",{device:_})}),i.jsx("div",{style:S4,role:"tablist",children:Se.map(ve=>i.jsx("button",{type:"button",role:"tab","aria-selected":Ie===ve,"data-testid":`g7le-property-tab-${ve}`,"data-active":Ie===ve?"true":"false",onClick:()=>Ve(ve),style:{...C4,color:Ie===ve?"#2563eb":"#64748b",borderBottomColor:Ie===ve?"#2563eb":"transparent"},children:Je[ve]},ve))}),i.jsxs("div",{style:$4,"data-testid":"g7le-property-modal-body",children:[Be&&!$&&i.jsx("div",{"data-testid":"g7le-property-modal-no-editable",style:kg,children:o("layout_editor.property_modal.no_editable_props")}),$&&i.jsx(y4,{injectedProps:x,t:o,onSaveInjectedProps:y}),Ie==="settings"&&N&&i.jsx(RA,{spec:N,node:e,t:o,onPatchProp:Ne}),Ie==="props"&&i.jsxs("div",{"data-testid":"g7le-property-props-tab",style:{display:"flex",flexDirection:"column"},children:[V&&i.jsx(eT,{node:e,candidates:f??[],t:o,onPatchNode:r}),Y&&i.jsx(I6,{node:e,dataProps:F,candidates:f??[],t:o,onPatchNode:r}),X&&i.jsx(X6,{node:e,candidates:f??[],t:o,onPatchNode:r,templateIdentifier:h}),L&&A&&i.jsx(A,{node:e,params:P,spec:t,manifest:n,t:o,onPatchNode:r,templateIdentifier:h,candidates:f}),M.map(ve=>i.jsx(vi,{controlKey:`core-${ve}`,control:ja[ve],node:e,t:o,onPatch:r,scope:jt,bindingCandidates:f},`core-${ve}`)),z.map(ve=>{const qe=Ct(t,ve);return qe?i.jsx(vi,{controlKey:ve,control:qe,node:e,t:o,onPatch:r,scope:jt,bindingCandidates:f},ve):null}),i.jsx(QT,{node:e,onPatchNode:r,t:o,scopeIdCandidates:w,usedScopeIds:k})]}),Ie==="style"&&i.jsxs("div",{"data-testid":"g7le-property-style-tab",style:{display:"flex",flexDirection:"column"},children:[i.jsx("div",{style:wg,children:i.jsx(ug,{scope:g,onChange:C,node:e,t:o,onClearScope:S})}),fe!==null&&i.jsx(IT,{node:e,spec:t,capability:E,t:o,onPatchNode:r,liveElement:b,scope:g}),ie.map(ve=>{const qe=Ct(t,ve);return qe?i.jsx(vi,{controlKey:ve,control:qe,node:e,t:o,onPatch:r,scope:g},ve):null})]}),Ie==="action"&&i.jsx(S6,{node:e,spec:t,capability:E,t:o,onPatchNode:r,pageCandidates:d,dataSourceCandidates:c,stateKeyCandidates:p,bindingCandidates:f}),Ie==="visibility"&&i.jsxs("div",{"data-testid":"g7le-property-visibility-tab",style:{display:"flex",flexDirection:"column"},children:[i.jsx("div",{style:wg,children:i.jsx(ug,{scope:g,onChange:C,node:e,t:o,showColorScheme:!1})}),i.jsx(Ou,{node:e,spec:t,t:o,onPatchNode:r,dataSourceCandidates:c,stateKeyCandidates:p,scope:g})]}),Ie==="translation"&&(h?i.jsx(Rd,{customKey:Qd(e),templateIdentifier:h,t:o,paramLabels:Wv(e),onRemoveParam:ve=>{const qe=typeof e.text=="string"?e.text:"";r({...e,text:xo(qe,ve)});const We=Qd(e);h&&We&&Ar(h,We,ve)}}):i.jsx("div",{"data-testid":"g7le-property-translation-deferred",style:kg,children:o("layout_editor.translation.not_a_key")})),Ie==="advanced"&&i.jsx(f6,{node:e,advanced:oe,t:o,onPatch:r,permissionCandidates:l})]}),i.jsxs("div",{style:E4,children:[i.jsx("span",{"data-testid":"g7le-property-modal-node-id",style:{fontSize:11,color:"#94a3b8"},children:typeof e.id=="string"||typeof e.id=="number"?`ID: ${e.id}`:""}),i.jsxs("div",{style:{display:"flex",gap:8},children:[i.jsx("button",{type:"button","data-testid":"g7le-property-modal-delete",onClick:a,style:I4,children:o("layout_editor.property_modal.delete_element")}),i.jsx("button",{type:"button","data-testid":"g7le-property-modal-done",onClick:s,style:A4,children:o("layout_editor.property_modal.close")})]})]})]})}const v4={display:"flex",flexDirection:"column",width:420,maxWidth:"92vw"},_4={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #e2e8f0",cursor:"move",userSelect:"none"},x4={border:"none",background:"transparent",fontSize:14,cursor:"pointer",color:"#64748b"},w4={margin:"8px 16px 0",padding:"6px 10px",fontSize:11,background:"#fef3c7",color:"#92400e",borderRadius:6},k4={margin:"8px 16px 0",padding:"6px 10px",fontSize:11,background:"#dbeafe",color:"#1e40af",borderRadius:6},S4={display:"flex",gap:2,padding:"0 12px",borderBottom:"1px solid #e2e8f0",overflowX:"auto"},C4={padding:"8px 10px",fontSize:12,border:"none",borderBottom:"2px solid transparent",background:"transparent",cursor:"pointer",whiteSpace:"nowrap"},$4={padding:16,overflowY:"auto",maxHeight:"60vh"},wg={position:"sticky",top:-16,zIndex:2,background:"#fff",margin:"-16px -16px 0",padding:"6px 16px 0"},kg={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},E4={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderTop:"1px solid #e2e8f0"},I4={padding:"6px 12px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},A4={padding:"6px 12px",fontSize:12,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},Fa="g7le:component-target-picked",Ka="g7le:component-target-pick-request";let T4=1;function D4({value:e,onChange:t,t:n,control:o}){const r=vo(),s=e==null?"":String(e),a=o?.allowManualInput!==!1,l=u.useCallback(()=>{if(typeof window>"u")return;const d=`pick-${T4++}`,p=r.stack[r.stack.length-1]?.id;p&&r.minimize(p,n("layout_editor.target_picker.minimized_hint"));const f=b=>{const g=b.detail;g?.requestId===d&&(window.removeEventListener(Fa,f),p&&r.restore(p),!g.cancelled&&typeof g.id=="string"&&t(g.id))};window.addEventListener(Fa,f),window.dispatchEvent(new CustomEvent(Ka,{detail:{requestId:d}}))},[r,t,n]);return i.jsx("div",{className:"g7le-component-target-picker","data-testid":"g7le-component-target-picker",children:i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[a?i.jsx("input",{type:"text",className:"g7le-widget g7le-widget--text","data-testid":"g7le-component-target-input",value:s,placeholder:n("layout_editor.target_picker.id_placeholder"),onChange:d=>t(d.target.value===""?void 0:d.target.value),style:{flex:1,minWidth:0,padding:"6px 8px",border:"1px solid #cbd5e1",borderRadius:6,fontSize:13}}):i.jsx("span",{"data-testid":"g7le-component-target-value",style:{flex:1,minWidth:0},children:s||n("layout_editor.target_picker.none")}),i.jsxs("button",{type:"button","data-testid":"g7le-component-target-pick",onClick:l,style:{display:"flex",alignItems:"center",gap:4,padding:"6px 10px",background:"#1e293b",color:"#fff",border:"none",borderRadius:6,cursor:"pointer",fontSize:13,whiteSpace:"nowrap"},children:[i.jsx("span",{"aria-hidden":"true",children:"🎯"}),n("layout_editor.target_picker.select_area")]})]})})}async function z4(e,t,n,o,r=fetch){const s=`/api/admin/templates/${encodeURIComponent(e)}/layout-extensions/${t}`;let a;try{a=await r(s,{headers:Me(),credentials:"same-origin"})}catch(y){return{kind:"error",message:y instanceof Error?y.message:String(y)}}if(a.status===404)return{kind:"not_found"};if(!a.ok)return{kind:"error",message:`HTTP ${a.status}`};const l=await a.json().catch(()=>null),d=(l&&(l.data||l))??{};let c={};const p=d.content;if(typeof p=="string")try{c=JSON.parse(p)}catch{return{kind:"error",message:"invalid extension content"}}else p&&typeof p=="object"&&(c=p);const f=typeof d.lock_version=="number"?d.lock_version:0,b=Array.isArray(c.injections)?[...c.injections]:[],g=b.findIndex(y=>y&&y.position==="inject_props"&&y.target_id===n);if(g<0)return{kind:"injection_not_found"};b[g]={...b[g],props:o};const m={...c,injections:b};let h;try{h=await r(s,{method:"PUT",headers:Me({"Content-Type":"application/json"}),credentials:"same-origin",body:JSON.stringify({content:m,expected_lock_version:f})})}catch(y){return{kind:"error",message:y instanceof Error?y.message:String(y)}}const v=await h.json().catch(()=>null);return h.ok?{kind:"success",newLockVersion:typeof v?.data?.lock_version=="number"?v.data.lock_version:f+1}:h.status===409?{kind:"conflict",currentVersion:v?.current_version??-1,yourVersion:v?.your_version??f}:{kind:"error",message:v?.message??`HTTP ${h.status}`}}const Sg=new Map;function Va(e,t){Sg.set(e,t)}function N4(e){return e?Sg.get(e)??null:null}const Cg="g7le.clipboard";function $g(){try{return typeof window>"u"||!window.sessionStorage?null:window.sessionStorage}catch{return null}}function M4(e){const t=JSON.parse(JSON.stringify(e)),n=o=>{for(const r of Object.keys(o))r.startsWith("__")&&delete o[r];Array.isArray(o.children)&&o.children.forEach(n)};return n(t),t}function Eg(e,t=0){const n=$g();if(!n)return!1;try{const o={node:M4(e),copiedAt:t};return n.setItem(Cg,JSON.stringify(o)),!0}catch{return!1}}function L4(){const e=$g();if(!e)return null;try{const t=e.getItem(Cg);if(!t)return null;const n=JSON.parse(t);return!n||typeof n.node!="object"||n.node===null?null:JSON.parse(JSON.stringify(n.node))}catch{return null}}const tr={nw:{width:-1,height:-1},n:{width:0,height:-1},ne:{width:1,height:-1},e:{width:1,height:0},se:{width:1,height:1},s:{width:0,height:1},sw:{width:-1,height:1},w:{width:-1,height:0}};function Ua(e){if(typeof e=="number")return e;if(typeof e=="string"){const t=e.match(/^(-?\d+(?:\.\d+)?)px$/);if(t)return Number(t[1])}return null}function P4(e,t){const n=Array.isArray(e.options)?e.options:[],o=Array.isArray(e.scale)?e.scale:[],r=n.length>0?n.map(l=>l.value):o;if(r.length===0)return;let s=r[0],a=1/0;return r.forEach((l,d)=>{const c=Ua(l)??d*40,p=Math.abs(c-t);p{if(!t)return;const m=tr[b];if(m.width!==0&&!n||m.height!==0&&!o)return;const h=t.props?.style??{},v=s?.()??null,y=Ua(h.width)??(v?Math.round(v.width):0),_=Ua(h.height)??(v?Math.round(v.height):0);p.current={handle:b,startX:g.clientX,startY:g.clientY,startW:y,startH:_,node:t};const w=m.width!==0&&m.height!==0?"both":m.width!==0?"width":"height";d?.(w);let k=null;const x=C=>{const S=p.current;if(!S)return;const D=r||1,E=(C.clientX-S.startX)/D*tr[S.handle].width,I=(C.clientY-S.startY)/D*tr[S.handle].height;let N=S.node;if(tr[S.handle].width!==0&&n){const T=Ig(n,S.startW+E);N=yn(N,n,T)}if(tr[S.handle].height!==0&&o){const T=Ig(o,S.startH+I);N=yn(N,o,T)}k=N,a(N,w)},$=()=>{p.current=null,d?.(null),window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",$),k&&l?.(k,w)};window.addEventListener("pointermove",x),window.addEventListener("pointerup",$)},[t,n,o,r,a,l,d]);return{enabledAxes:c,onHandlePointerDown:f}}const Ag=320,Tg=1920,W4=1024;function qa(e){return Number.isFinite(e)?Math.round(Math.max(Ag,Math.min(Tg,e))):W4}function Ga(e={}){const{state:t,dispatch:n}=Qe(),{previewDevice:o,previewZoom:r,previewCustomWidth:s,previewColorScheme:a}=t,l=o==="custom"?qa(s):WT(o),d=u.useMemo(()=>{const g=e.availableWidth??l,m=l*r;return r>=1||m<=g?r:Math.min(r,g/l)},[l,r,e.availableWidth]),c=u.useCallback(g=>{n({type:"SET_PREVIEW_DEVICE",device:g})},[n]),p=u.useCallback(g=>{const m=Math.max(.5,Math.min(1,g));n({type:"SET_PREVIEW_ZOOM",zoom:m})},[n]),f=u.useCallback(g=>{n({type:"SET_PREVIEW_CUSTOM_WIDTH",width:qa(g)})},[n]),b=u.useCallback(g=>{n({type:"SET_PREVIEW_COLOR_SCHEME",scheme:g})},[n]);return{device:o,deviceWidth:l,zoom:r,scale:d,customWidth:qa(s),setDevice:c,setZoom:p,setCustomWidth:f,colorScheme:a,setColorScheme:b}}const ki="g7le-dnd-handle-";function j4(e){if(typeof e!="string"||!e.startsWith(ki))return null;const t=e.slice(ki.length);return t.length>0?t:null}function H4(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\\]]/g,"\\$&")}function F4(e,t,n,o){const r=o?.handleFallback??!1;if(e instanceof HTMLElement){const s=e.closest("[data-editor-path]");if(s)return s;const a=e.closest('[data-testid^="g7le-"]');if(a&&!(a.getAttribute("data-testid")??"").startsWith(ki))return null;if(r){const l=e.closest(`[data-testid^="${ki}"]`);if(l&&t){const d=j4(l.getAttribute("data-testid"));if(d){const c=t.querySelector(`[data-editor-path="${H4(d)}"]`);if(c)return c}}}}if(r&&n&&typeof document<"u"&&typeof document.elementsFromPoint=="function")for(const s of document.elementsFromPoint(n.x,n.y)){const a=s.closest?.("[data-editor-path]");if(a)return a}return null}function K4(e,t,n){if(typeof e=="string"&&e.trim().length>0)return{color:e};const o=typeof n?.color=="string"&&n.color.length>0,r=typeof t=="string"&&t.trim().length>0;return o||r?{}:{color:"#0f172a"}}const V4="#ffffff",U4="#0f172a";function q4(e){const t=e.trim(),n=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);if(n)return[Number(n[1]),Number(n[2]),Number(n[3])];const o=t.replace(/^#/,"");return/^[0-9a-f]{3}$/i.test(o)?[parseInt(o[0]+o[0],16),parseInt(o[1]+o[1],16),parseInt(o[2]+o[2],16)]:/^[0-9a-f]{6}$/i.test(o)?[parseInt(o.slice(0,2),16),parseInt(o.slice(2,4),16),parseInt(o.slice(4,6),16)]:null}function G4(e){if(!e||/transparent/i.test(e))return!1;const t=e.trim().match(/^oklch\(\s*([\d.]+)(%?)/i);if(t)return(t[2]==="%"?Number(t[1])/100:Number(t[1]))>=.62;const n=q4(e);if(!n)return!1;const[o,r,s]=n;return .299*o+.587*r+.114*s>=180}function Y4(e,t,n){const o=typeof n?.color=="string"?n.color:null;return G4(e??o??t)?U4:V4}function X4({box:e,initialValue:t,isCustomKey:n,t:o,onCommit:r,onCancel:s,mirrorClassName:a,mirrorStyle:l,nodeEffectiveColor:d,onOpenTranslations:c}){const p=u.useRef(null),f=u.useRef(!1),[b,g]=u.useState(t.trim().length>0),[m,h]=u.useState(null);u.useEffect(()=>{const k=p.current;if(k){k.textContent=t,k.focus();try{const x=window.document.createRange();x.selectNodeContents(k);const $=window.getSelection();$?.removeAllRanges(),$?.addRange(x)}catch{}f.current=!1}},[t]),u.useEffect(()=>{const k=p.current;if(!k||typeof window.getComputedStyle!="function"){h(null);return}try{h(window.getComputedStyle(k).color||null)}catch{h(null)}},[a,l]);const v=()=>(p.current?.textContent??"").trim(),y=()=>{f.current||(f.current=!0,r(v()))},_=()=>{f.current||(f.current=!0,s())},w=k=>{k.key==="Enter"&&!k.shiftKey?(k.preventDefault(),y()):k.key==="Escape"&&(k.preventDefault(),_())};return i.jsxs("div",{className:"g7le-inline-text-editor","data-testid":"g7le-inline-text-editor","data-custom-key":n?"true":"false",style:{position:"absolute",left:e.left,top:e.top,minWidth:Math.max(e.width,60),minHeight:e.height,pointerEvents:"auto",zIndex:1e4},children:[i.jsx("div",{ref:p,role:"textbox","aria-label":o("layout_editor.inline_edit.aria_label"),"aria-multiline":"false","data-testid":"g7le-inline-text-editable",className:a,contentEditable:!0,suppressContentEditableWarning:!0,spellCheck:!1,onInput:()=>g(v().length>0),onKeyDown:w,onBlur:y,style:{outline:"2px solid #2563eb",outlineOffset:1,borderRadius:3,background:Y4(d,m,l),padding:"2px 4px",minHeight:e.height,whiteSpace:"pre-wrap",wordBreak:"break-word",boxShadow:"0 2px 8px rgba(37, 99, 235, 0.25)",...l??{},...K4(d,a,l)}}),i.jsxs("div",{className:"g7le-inline-text-editor__hint","data-testid":"g7le-inline-text-editor-hint",style:{marginTop:2,display:"inline-flex",alignItems:"center",gap:4,whiteSpace:"nowrap"},children:[c?i.jsxs("button",{type:"button","data-testid":"g7le-inline-text-editor-open-translations",onMouseDown:k=>k.preventDefault(),onClick:k=>{k.preventDefault(),k.stopPropagation(),c()},title:o("layout_editor.inline_edit.open_translations"),style:{padding:"2px 8px",fontSize:11,background:n?"#eff6ff":"#f0fdf4",color:n?"#1d4ed8":"#15803d",border:`1px solid ${n?"#bfdbfe":"#bbf7d0"}`,borderRadius:4,display:"inline-flex",alignItems:"center",gap:4,cursor:"pointer",whiteSpace:"nowrap"},children:[i.jsx("span",{"aria-hidden":"true",children:"🌐"}),i.jsx("span",{children:o(n?"layout_editor.inline_edit.existing_key_hint":"layout_editor.inline_edit.new_key_hint")}),i.jsxs("span",{"aria-hidden":"true",style:{opacity:.7},children:["· ",o("layout_editor.inline_edit.open_translations")," ›"]})]}):i.jsx("span",{style:{padding:"2px 6px",fontSize:11,background:n?"#eff6ff":"#f0fdf4",color:n?"#1d4ed8":"#15803d",border:`1px solid ${n?"#bfdbfe":"#bbf7d0"}`,borderRadius:4,display:"inline-flex",alignItems:"center",gap:4,whiteSpace:"nowrap"},children:n?i.jsxs(i.Fragment,{children:["⌐ ",o("layout_editor.inline_edit.existing_key_hint")]}):i.jsxs(i.Fragment,{children:["✎ ",o("layout_editor.inline_edit.new_key_hint")]})}),!b&&i.jsx("span",{"data-testid":"g7le-inline-text-editor-empty-warn",style:{color:"#b91c1c",marginLeft:4},children:o("layout_editor.inline_edit.empty_warning")})]})]})}function J4({box:e,node:t,customKey:n,initialChipValue:o,chipParamLabels:r,onKeyify:s,templateIdentifier:a,locale:l,t:d,candidates:c,onInsertBinding:p,onRemoveBinding:f,onCommit:b,onCancel:g}){const[m,h]=u.useState(null),v=u.useRef(""),[y,_]=u.useState(!1),w=u.useRef(!1),k=u.useRef(null),x=Kt(),$=u.useRef(()=>{}),[C,S]=u.useState(null),[D,E]=u.useState(!1),I=u.useRef(n??null);u.useEffect(()=>{n&&I.current!==n&&(I.current=n)},[n]);const N=u.useMemo(()=>{if(!n&&r)return r;const P={},A=vt(typeof t.text=="string"?t.text:"");for(const L of A?.params??[])P[L.name]=Ut(L.expression);return P},[t.text,n,r]);u.useEffect(()=>{let P=!1;if(!n){const A=o??"";return v.current=A,h(A),()=>{P=!0}}return(async()=>{const A=It(n,l);if(A!==void 0){v.current=A,h(A);return}const L=await fn(a,n);if(P)return;const F=L?.values?.[l]??"";v.current=F,h(F)})(),()=>{P=!0}},[a,n,l,o]);const T=async()=>{if(w.current)return;w.current=!0;const P=m??"";if(P===v.current){b();return}_(!0);let A=I.current;if(!A){if(!s){_(!1),w.current=!1;return}if(A=await s(P),_(!1),!A){w.current=!1;return}I.current=A,b();return}const L=await Eo(a,A,l,P);if(_(!1),L.kind==="error"){w.current=!1;return}x?.markDirty?.(),b()},B=()=>{w.current||(w.current=!0,g())},M=P=>{S(P)},O=async P=>{if(!(C===null||!p||D)){E(!0);try{const A=I.current;A&&m!==null&&m!==v.current&&(await Eo(a,A,l,m),v.current=m);const L=await p(C,P);L!==null&&(h(L),v.current=L,x?.markDirty?.())}finally{E(!1),S(null)}}},z=async P=>{if(!(!f||D)){E(!0);try{const A=I.current;A&&m!==null&&m!==v.current&&(await Eo(a,A,l,m),v.current=m);const L=await f(P);L!==null&&(h(L),v.current=L,x?.markDirty?.())}finally{E(!1)}}},H=P=>{P.key==="Enter"&&!P.shiftKey?(P.preventDefault(),T()):P.key==="Escape"&&(P.preventDefault(),B())};return $.current=()=>{T()},u.useEffect(()=>{const P=L=>{const F=k.current;if(!F)return;const Y=L.target;if(Y&&F.contains(Y))return;const V=Y;V&&V.closest&&V.closest('[data-testid="g7le-inline-toolbar"], .g7le-inline-toolbar')||$.current()},A=k.current?.ownerDocument??document;return A.addEventListener("pointerdown",P,!0),()=>A.removeEventListener("pointerdown",P,!0)},[]),i.jsxs("div",{ref:k,className:"g7le-inline-param-chip-editor","data-testid":"g7le-inline-param-chip-editor",onKeyDown:H,style:{position:"absolute",left:e.left,top:e.top,minWidth:Math.max(e.width,120),pointerEvents:"auto",zIndex:1e4,background:"#fff",border:"2px solid #2563eb",borderRadius:4,boxShadow:"0 2px 8px rgba(37,99,235,0.25)",padding:4},children:[m===null?i.jsx("div",{"data-testid":"g7le-inline-param-chip-loading",style:{fontSize:12,color:"#94a3b8",padding:4},children:d("layout_editor.translation.loading")}):i.jsx(Sr,{value:m,onChange:h,t:d,paramLabels:N,testIdSuffix:"inline",onRequestInsert:p?M:void 0,onRemoveChip:f?P=>void z(P):void 0}),C!==null&&p&&i.jsx("div",{"data-testid":"g7le-inline-param-chip-insert-picker",style:{marginTop:4},children:i.jsx($t,{candidates:c??[],t:d,onSelect:P=>void O(P),testIdSuffix:"inline-insert",defaultOpen:!0,floating:!1})}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4},children:[i.jsx("button",{type:"button","data-testid":"g7le-inline-param-chip-save",disabled:y,onMouseDown:P=>P.preventDefault(),onClick:()=>void T(),style:{fontSize:11,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",padding:"4px 12px",cursor:"pointer"},children:d(y?"layout_editor.translation.saving":"layout_editor.translation.save")}),i.jsx("span",{style:{fontSize:10,color:"#94a3b8"},children:d("layout_editor.translation.placeholder_locked")})]})]})}const Z4=["fontWeight","fontBold","fontStyle","fontItalic","textDecoration","textUnderline","textAlign","fontSize","textColor"],Q4={fontWeight:"B",fontBold:"B",fontStyle:"I",fontItalic:"I",textDecoration:"U",textUnderline:"U",textAlign:"≡",fontSize:"T",textColor:"A"},R4=[["fontWeight","fontBold"],["fontItalic","fontStyle"],["textUnderline","textDecoration"]];function Dg({node:e,spec:t,t:n,onApplyControl:o,box:r,scope:s=jt}){const a=typeof e.name=="string"?e.name:"",l=Ui(t,a),d=Array.isArray(l?.styleControls)?l.styleControls:[];let c=Z4.filter(p=>d.includes(p)&&Ct(t,p)!==null);for(const p of R4){const f=p.filter(b=>c.includes(b));if(f.length>1){const b=f[0];c=c.filter(g=>!p.includes(g)||g===b)}}return c.length===0?null:i.jsx("div",{className:"g7le-inline-toolbar","data-testid":"g7le-inline-toolbar",role:"toolbar","aria-label":n("layout_editor.inline_edit.toolbar_label"),style:{position:"absolute",left:r.left,top:r.top-40,display:"inline-flex",gap:2,padding:4,background:"#0f172a",borderRadius:8,boxShadow:"0 4px 12px rgba(15, 23, 42, 0.35)",pointerEvents:"auto",zIndex:10001},children:c.map(p=>i.jsx(tD,{controlKey:p,node:e,spec:t,t:n,scope:s,onApplyControl:o},p))})}const eD={fontWeight:"bold",fontBold:"bold",fontStyle:"italic",fontItalic:"italic",textDecoration:"underline",textUnderline:"underline"};function zg(e,t){const n=r=>(r.split(/[-\s]/).pop()??r)===t||r===t;return e.find(r=>{const s=typeof r.value=="string"?r.value:"",a=Array.isArray(r.apply?.tokens)?r.apply.tokens:[];return n(s)||a.some(n)})?.value}function tD({controlKey:e,node:t,spec:n,t:o,scope:r,onApplyControl:s}){const[a,l]=u.useState(!1),d=Ct(n,e);if(!d)return null;const c=d.options,p=Array.isArray(c),f=Lo(t,d,r),b=eD[e],g=b&&Array.isArray(c)?zg(c,b):void 0,m=!b,h=g!==void 0?f.value===g:p&&f.matched&&f.value!==void 0&&f.value!=="",v=o(`layout_editor.inline_edit.format.${e}`),y=x=>typeof x.label=="string"?x.label.startsWith("$t:")?o(x.label.slice(3)):x.label:String(x.value??""),_=()=>{s(e,x=>{const $=Lo(x,d,r),C=Array.isArray(c)?zg(c,b):void 0,S=C!==void 0&&$.value===C?void 0:C;return yn(x,d,S,r)})},w=x=>{s(e,$=>{const S=Lo($,d,r).value===x?void 0:x;return yn($,d,S,r)}),l(!1)},k=x=>{if(x.preventDefault(),x.stopPropagation(),!m&&Array.isArray(c)){_();return}l($=>!$)};return i.jsxs("div",{style:{position:"relative",display:"inline-flex"},children:[i.jsxs("button",{type:"button","data-testid":`g7le-inline-format-${e}`,"data-active":h?"true":"false","aria-label":v,"aria-pressed":p?h:void 0,title:v,onMouseDown:x=>x.preventDefault(),onClick:k,style:{display:"inline-flex",alignItems:"center",gap:5,height:28,padding:"0 9px",fontSize:12,border:"none",borderRadius:5,cursor:"pointer",background:h?"#2563eb":"transparent",color:"#ffffff",whiteSpace:"nowrap"},children:[i.jsx("span",{"aria-hidden":"true",style:{fontWeight:e==="fontWeight"||e==="fontBold"?700:600,fontStyle:e==="fontStyle"||e==="fontItalic"?"italic":"normal",textDecoration:e==="textDecoration"||e==="textUnderline"?"underline":"none"},children:Q4[e]}),i.jsx("span",{children:v}),m&&i.jsx("span",{"aria-hidden":"true",style:{fontSize:9,opacity:.8},children:"▾"})]}),m&&a&&i.jsx("div",{"data-testid":`g7le-inline-popover-${e}`,role:"listbox",onMouseDown:x=>x.preventDefault(),style:{position:"absolute",top:32,left:0,minWidth:140,maxHeight:240,overflowY:"auto",background:"#0f172a",border:"1px solid #334155",borderRadius:8,boxShadow:"0 8px 24px rgba(15,23,42,0.45)",padding:4,zIndex:10002},children:Array.isArray(c)&&c.length>0?c.map((x,$)=>{const C=f.value===x.value;return i.jsxs("button",{type:"button",role:"option","aria-selected":C,"data-testid":`g7le-inline-option-${e}-${String(x.value??$)}`,onMouseDown:S=>S.preventDefault(),onClick:S=>{S.preventDefault(),S.stopPropagation(),w(x.value)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",fontSize:12,textAlign:"left",border:"none",borderRadius:5,cursor:"pointer",background:C?"#2563eb":"transparent",color:"#ffffff"},children:[typeof x.swatch=="string"&&i.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:3,background:x.swatch,border:"1px solid rgba(255,255,255,0.3)"}}),i.jsx("span",{children:y(x)}),C&&i.jsx("span",{"aria-hidden":"true",style:{marginLeft:"auto"},children:"✓"})]},String(x.value??$))}):i.jsx(nD,{testid:`g7le-inline-freeinput-${e}`,placeholder:o(`layout_editor.inline_edit.prompt.${e}`),initial:typeof f.value=="string"?f.value:"",onSubmit:x=>{s(e,$=>yn($,d,x,r)),l(!1)}})})]})}function nD({testid:e,placeholder:t,initial:n,onSubmit:o}){const[r,s]=u.useState(n);return i.jsx("input",{type:"text","data-testid":e,value:r,placeholder:t,autoFocus:!0,onMouseDown:a=>a.stopPropagation(),onChange:a=>s(a.currentTarget.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),o(r.trim()))},style:{width:130,padding:"6px 8px",fontSize:12,border:"1px solid #334155",borderRadius:5,background:"#1e293b",color:"#ffffff"}})}function oD(e){const{frameEl:t,manifest:n,nesting:o,componentPalette:r,spec:s=null,permissionCandidates:a,resolveRouteMatch:l,onNavigateToDestination:d,onSessionAddedPathsChange:c,onEditProps:p}=e,{state:f,dispatch:b}=Qe(),{t:g}=et(),m=Ga(),h=u.useCallback((W,J)=>{const R=window.G7Core;if(R&&typeof R.t=="function"){const le=R.t(W,J);if(le&&le!==W&&!le.startsWith("$t:"))return le}return g(W,J)},[g]),v=Kt(),y=Z7(50),_=vo(),w=u.useRef([]),k=u.useMemo(()=>v?.document?.raw?.components??[],[v?.document?.raw?.components]),x=u.useMemo(()=>k.length===0?null:{children:k},[k]),$=u.useMemo(()=>{if(f.editMode!=="extension")return;const W=/^__extension__\/(\d+)/.exec(f.selectedRoute?.path??"");return W?Number(W[1]):void 0},[f.editMode,f.selectedRoute?.path]),C=u.useMemo(()=>{if(f.editMode==="iteration_item"){const W=v?.document?.iterationContext?.sourceIndexPath;return Array.isArray(W)&&W.length>0?W:null}if(f.editMode==="modal"){const W=v?.document?.modalContext?.editIndexPath;return Array.isArray(W)&&W.length>0?W:null}return null},[f.editMode,v?.document?.iterationContext?.sourceIndexPath,v?.document?.modalContext?.editIndexPath]),S=F7({rootNode:x,editMode:f.editMode,currentExtensionId:$,editableRootPath:C,pathParser:Re,resolveRouteMatch:l}),[D,E]=u.useState(null),[I,N]=u.useState(null),[T,B]=u.useState(null),M=u.useRef(null);M.current=T;const[O,z]=u.useState(null),H=u.useRef(null),P=u.useRef(null);P.current=S.selectedPath;const A=dm(),[L,F]=u.useState(null),Y=u.useCallback(W=>{if(!t)return;const J=Re(W);if(!J)return;const R={children:Ne.current.components},le=Pe(R,J),me=Jt(le,f.editMode,$,Dn(R,J));if(!Zt(me))return;const xe=A.classify(le);if(!xe.editable){Et({op:"inline_edit_blocked_binding",sourceState:xe.sourceState,componentPath:at(J),timestamp:Date.now()});return}const Te=ho(t,W);if(!Te)return;const we=le?.props??{},_e=Mg(t,W);F({path:J,domPath:W,box:Te,initialValue:xe.displayValue,isCustomKey:xe.sourceState==="custom_key",isParamKey:xe.isParamKey===!0,customKey:xe.customKey,chipValue:xe.chipValue,chipParamLabels:xe.chipParamLabels,mirrorClassName:typeof we.className=="string"?we.className:void 0,mirrorStyle:we.style??void 0,nodeEffectiveColor:_e}),Et({op:"inline_edit_enter",sourceState:xe.sourceState,componentPath:at(J),timestamp:Date.now()})},[t,A,f.editMode,$]),V=u.useCallback(()=>{if(!t){E(null),N(null);return}N(ho(t,S.selectedPath)),E(ho(t,S.hoverPath))},[t,S.selectedPath,S.hoverPath,k]);u.useEffect(()=>{if(V(),typeof window<"u"&&typeof window.requestAnimationFrame=="function"){const W=window.requestAnimationFrame(()=>V());return()=>window.cancelAnimationFrame(W)}},[V]),u.useEffect(()=>{if(t)return Wp(V,t)},[t,V]);const X=u.useCallback((W,J)=>{if(typeof window>"u")return;window.dispatchEvent(new CustomEvent(Fa,{detail:J===null?{requestId:W,cancelled:!0}:{requestId:W,id:J}})),B(null),z(null);const R=H.current;R?S.handleSelect("",{dataset:{editorPath:R}}):S.clearSelection(),H.current=null},[S]);u.useEffect(()=>{if(typeof window>"u")return;const W=J=>{const R=J.detail;if(typeof R?.requestId!="string")return;const le=M.current;le&&le!==R.requestId&&X(le,null),H.current=P.current,B(R.requestId)};return window.addEventListener(Ka,W),()=>window.removeEventListener(Ka,W)},[X]),u.useEffect(()=>{if(!T)return;const W=J=>{J.key==="Escape"&&(J.preventDefault(),X(T,null))};return window.addEventListener("keydown",W,!0),()=>window.removeEventListener("keydown",W,!0)},[T,X]),u.useEffect(()=>{if(!t)return;const W=f.editMode==="iteration_item"||f.editMode==="modal",J=(_e,Ee)=>F4(_e,t,Ee?{x:Ee.clientX,y:Ee.clientY}:void 0,{handleFallback:W}),R=_e=>{const Ee=_e.dataset.editorPath??"",He=Ee?Re(Ee):null,Nt={children:Ne.current.components},gt=He?Pe(Nt,He):null,Mt=gt&&typeof gt.props?.id=="string"?gt.props.id:typeof gt?.id=="string"?gt.id:"";return Mt.startsWith("auto_")?"":Mt},le=_e=>{const Ee=J(_e.target,_e);if(!Ee)return;const He=M.current;if(He){_e.preventDefault(),_e.stopPropagation();const Nt=R(Ee);Nt&&X(He,Nt);return}_e.preventDefault(),_e.stopPropagation(),S.handleSelect(Ee.dataset.editorId??"",{currentTarget:Ee,dataset:Ee.dataset})},me=_e=>{const Ee=J(_e.target,_e);if(M.current){if(!Ee){z(null);return}const He=ho(t,Ee.dataset.editorPath??null);if(!He){z(null);return}z({box:He,hasId:R(Ee)!==""});return}if(!Ee){S.handleHover(null,{});return}S.handleHover(Ee.dataset.editorId??"",{currentTarget:Ee,dataset:Ee.dataset})},xe=()=>{if(M.current){z(null);return}S.handleHover(null,{})},Te=_e=>{const Ee=J(_e.target,_e);if(!Ee)return;const He=Ee.dataset.editorPath??"";He&&(_e.preventDefault(),_e.stopPropagation(),Y(He))},we=t.parentElement??t;return we.addEventListener("click",le,!0),we.addEventListener("mousemove",me,!0),we.addEventListener("mouseleave",xe,!0),we.addEventListener("dblclick",Te,!0),()=>{we.removeEventListener("click",le,!0),we.removeEventListener("mousemove",me,!0),we.removeEventListener("mouseleave",xe,!0),we.removeEventListener("dblclick",Te,!0)}},[t,S,Y,f.editMode,X]);const Z=u.useMemo(()=>{const W=S.selectedPath;if(!W)return null;const J=W.match(/^(.*)\.children\.\d+$/);return J?J[1]:null},[S.selectedPath]),ie=u.useCallback(()=>{Z&&S.handleSelect("",{dataset:{editorPath:Z}})},[Z,S]),oe=u.useMemo(()=>!t||!S.selectedPath?null:t.querySelector(`[data-editor-path="${dn(S.selectedPath)}"]`),[t,S.selectedPath]),G=u.useMemo(()=>S.selectedPath?Re(S.selectedPath):null,[S.selectedPath]),ee=u.useMemo(()=>{if(!G)return null;const W=G.find(tt);if(!W)return null;const{i18nKey:J,raw:R}=jC(W.responsive);return J?g(J):g("layout_editor.overlay.branch_custom",{range:R})},[G,g]),fe=u.useMemo(()=>S.selectedPath?S.selectedIsIteration&&S.selectedIterationSourcePath?S.selectedIterationSourcePath:S.selectedPath:null,[S.selectedPath,S.selectedIsIteration,S.selectedIterationSourcePath]),K=u.useMemo(()=>fe?Re(fe):null,[fe]),te=u.useMemo(()=>!t||!fe?null:t.querySelector(`[data-editor-path="${dn(fe)}"]`),[t,fe]),ye=u.useMemo(()=>{if(te?.parentElement)return te.parentElement;if(!t||!fe)return null;const W=fe.match(/^(.*)\.children\.\d+$/);return W?t.querySelector(`[data-editor-path="${dn(W[1])}"]`):null},[te,t,fe]),Se=u.useMemo(()=>{const W=S.selectedNode;return W&&(typeof W.name=="string"?W.name:typeof W.type=="string"?W.type:"")||null},[S.selectedNode]),De=u.useMemo(()=>{if(S.selectedLockKind!=="extension")return null;const W=S.selectedNode?.__source;if(!W||W.kind!=="extension")return null;const J=W.extensionName?.trim(),R=W.extensionIdentifier?.trim();return J&&R?`${J} (${R})`:J||R||W.extensionSourceType||null},[S.selectedLockKind,S.selectedNode]),Ie=Y7({parentEl:ye,selectedPath:K,selectedEl:te}),Ve=u.useMemo(()=>!t||!fe||fe===S.selectedPath?I:ho(t,fe),[t,fe,I,S.selectedPath,k]),ze=u.useRef(null),Be=u.useCallback(()=>{const W=ze.current;W&&(_.close(W),ze.current=null)},[_]),Xe=u.useRef(()=>{}),Ne=u.useRef({manifest:n,nesting:o,componentPalette:r,components:k});Ne.current={manifest:n,nesting:o,componentPalette:r,components:k};const Je=u.useCallback(W=>{const J=W.insertion?.parentPath??[],R=W.insertion?.index??0,le=Ne.current,me=Ng(le.components,J);Be();const xe=_.open({ariaLabel:h("layout_editor.palette.title"),width:880,maxHeightRatio:.82,content:u.createElement(Wf,{manifest:le.manifest,nesting:le.nesting,componentPalette:le.componentPalette??null,targetParentPath:J,targetContainerName:me,onInsert:(Te,we,_e)=>{Xe.current(Te,we,_e)},insertionIndex:R,onClose:()=>Be(),editorTemplateId:f.templateIdentifier,editorLocale:f.locale}),onClose:()=>{ze.current=null}});ze.current=xe},[_,Be]),ve=u.useMemo(()=>{if(!f.isPaletteOpen)return null;if(!G)return{parentPath:[],index:k.length};if(S.selectedLockKind!=="none"){const le=K;return!le||le.length===0?{parentPath:[],index:k.length}:{parentPath:le.slice(0,-1),index:(le[le.length-1]??0)+1}}const J=S.selectedNode,R=Array.isArray(J?.children)?J.children.length:0;return JI(J?.name,R,G,o,k.length)},[f.isPaletteOpen,G,K,S.selectedLockKind,S.selectedNode,k.length,o]),qe=u.useCallback(()=>{b({type:"SET_PALETTE_OPEN",open:!1})},[b]),We=u.useRef(null);u.useEffect(()=>{if(!f.isPaletteOpen){const me=We.current;me&&(_.close(me),We.current=null);return}if(!ve||We.current)return;const W=ve,J=Ne.current,R=Ng(J.components,W.parentPath),le=_.open({ariaLabel:h("layout_editor.palette.title"),width:880,maxHeightRatio:.82,content:u.createElement(Wf,{manifest:J.manifest,nesting:J.nesting,componentPalette:J.componentPalette??null,targetParentPath:W.parentPath,targetContainerName:R,onInsert:(me,xe,Te)=>{Xe.current(me,xe,Te),qe()},insertionIndex:W.index,onClose:()=>qe(),editorTemplateId:f.templateIdentifier,editorLocale:f.locale}),onClose:()=>{We.current=null,b({type:"SET_PALETTE_OPEN",open:!1})}});We.current=le},[f.isPaletteOpen,ve,_,qe,b]);const ce=u.useRef({layoutName:null,pushed:!1});u.useEffect(()=>{const W=v?.document?.layoutName??null;if(!W){ce.current={layoutName:null,pushed:!1};return}ce.current.layoutName!==W&&(y.clear(),y.push({actionKind:"inline_text_edit",label:"baseline",snapshot:k}),ce.current={layoutName:W,pushed:!0})},[v?.document?.layoutName,k,y]);const q=u.useRef(0);u.useEffect(()=>{const W=v?.saveSuccessCounter??0;W!==q.current&&(q.current=W,W!==0&&(y.clear(),y.push({actionKind:"inline_text_edit",label:"save_baseline",snapshot:k}),w.current=[],c?.([])))},[v?.saveSuccessCounter,k,y,c]);const se=u.useRef(0);u.useEffect(()=>{const W=v?.reloadCounter??0;W!==se.current&&(se.current=W,W!==0&&(ce.current={layoutName:null,pushed:!1},w.current=[],c?.([])))},[v?.reloadCounter,c]);const ae=u.useCallback((W,J,R)=>{if(!v)return;let le=[];v.patchLayout(we=>{const _e={children:we},Ee=Ya(_e,J),He=R<0?Array.isArray(Ee?.children)?Ee.children.length:0:R,gt=is(_e,J,He,W).children??[];return le=gt,gt}),y.push({actionKind:"insert",label:`insert ${W.name??W.type??""}`,snapshot:le});const me=Ya({children:le},J),xe=R<0?Array.isArray(me?.children)?me.children.length-1:0:R,Te=at([...J,xe]);if(w.current=[...w.current,Te],c?.(w.current),t){const we=`[data-editor-path="${dn(Te)}"]`,_e=()=>{const Ee=t.querySelector(we);Ee&&typeof Ee.scrollIntoView=="function"&&Ee.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})};typeof window<"u"&&typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(()=>window.requestAnimationFrame(_e)):setTimeout(_e,32)}},[v,y,c,t]);Xe.current=ae;const be=u.useCallback(()=>{if(!v||!S.selectedNode||!G||!Zt(S.selectedLockKind))return;const W=as(S.selectedNode);let J=[];v.patchLayout(R=>{const le={children:R},me=G.slice(0,-1),xe=G[G.length-1]??0,we=is(le,me,xe+1,W).children??[];return J=we,we}),y.push({actionKind:"insert",label:"duplicate",snapshot:J})},[v,S.selectedNode,S.selectedLockKind,G,y]),Ce=u.useCallback(()=>{if(!v||!G||!Zt(S.selectedLockKind))return;let W=[];v.patchLayout(J=>{const me=ss({children:J},G).children??[];return W=me,me}),y.push({actionKind:"remove",label:"remove",snapshot:W}),S.clearSelection()},[v,G,y,S]),$e=u.useMemo(()=>{if(!S.selectedNode||!G||G.some(tt))return null;const W=S.selectedNode;if(!Array.isArray(W.children))return null;const J=WC(f.previewDevice,W,f.previewCustomWidth);return{mode:J.mode,key:J.key,sourceKey:J.sourceKey}},[S.selectedNode,G,f.previewDevice,f.previewCustomWidth]),U=u.useCallback(()=>{if(!v||!G||$e?.mode!=="separate")return;const W=$e.key,J=$e.sourceKey;let R=[];v.patchLayout(le=>(R=Rb({children:le},G,W,J).children??[],R)),y.push({actionKind:"insert",label:"separate_branch",snapshot:R})},[v,G,$e,y]),ue=u.useCallback(()=>{if(!v||!G||$e?.mode!=="merge")return;const W=$e.key;let J=[];v.patchLayout(R=>(J=em({children:R},G,W).children??[],J)),y.push({actionKind:"remove",label:"merge_branch",snapshot:J})},[v,G,$e,y]),ge=u.useCallback(W=>{switch(W){case"mobile":return g("layout_editor.context_menu.device_mobile");case"portable":return g("layout_editor.context_menu.device_portable");case"tablet":return g("layout_editor.context_menu.device_tablet");case"desktop":return g("layout_editor.context_menu.device_desktop");default:return g("layout_editor.context_menu.device_custom",{range:W})}},[g]),ke=u.useMemo(()=>{if(!$e)return null;const W=ge($e.key);return{separate:g("layout_editor.context_menu.separate_branch_device",{device:W}),merge:g("layout_editor.context_menu.merge_branch_device",{device:W})}},[$e,g,ge]),he=u.useMemo(()=>{if(!S.selectedNode||!G)return[];if(G.some(tt))return[];const W=Qr(f.previewDevice,S.selectedNode,f.previewCustomWidth);return BT(S.selectedNode,W).map(J=>({key:J,label:ge(J)}))},[S.selectedNode,G,f.previewDevice,f.previewCustomWidth,ge]),j=u.useCallback(W=>{if(W==="desktop"||W==="tablet"||W==="mobile"||W==="portable"){m.setDevice(W);return}m.setDevice(W)},[m]),ne=u.useCallback(()=>{S.selectedNode&&Eg(S.selectedNode)},[S.selectedNode]),pe=u.useCallback(()=>{S.selectedNode&&Zt(S.selectedLockKind)&&(Eg(S.selectedNode),Ce())},[S.selectedNode,S.selectedLockKind,Ce]),Q=u.useCallback(()=>{if(!v)return;const W=L4();if(!W)return;const J=as(W);if(G&&G.length>0){const R=G.slice(0,-1),le=(G[G.length-1]??0)+1;ae(J,R,le)}else ae(J,[],k.length)},[v,G,ae,k.length]),de=u.useCallback((W,J)=>{y.push({actionKind:"move",label:J,snapshot:W})},[y]),Ae=u.useCallback(()=>{if(S.selectedNavAffordance==="route_in_tree"&&S.selectedNavTargetPath){if(d){d(S.selectedNavTargetPath);return}b({type:"SELECT_ROUTE",route:{path:S.selectedNavTargetPath,layoutName:null}})}},[S.selectedNavAffordance,S.selectedNavTargetPath,d,b]),dt=u.useCallback(()=>{const W=Zb(S.selectedBaseLayout,f.selectedRoute?.layoutName);W&&b({type:"ENTER_BASE_EDIT",layoutName:W})},[S.selectedBaseLayout,f.selectedRoute?.layoutName,b]),pt=u.useCallback(()=>{const W=S.selectedNode?.__source?.extensionId;W!=null&&b({type:"ENTER_EXTENSION_EDIT",extensionId:String(W)})},[S.selectedNode,b]),ot=u.useCallback(()=>{const W=S.selectedIterationSourcePath;W&&b({type:"ENTER_ITERATION_ITEM_EDIT",sourcePath:W})},[S.selectedIterationSourcePath,b]),Le=u.useRef(null),je=u.useRef(null),Ze=u.useRef(null),Tt=u.useRef({colorScheme:"base",breakpoint:"base"}),Dt=Le.current!==null?_.stack.some(W=>W.id===Le.current):!1,zt=u.useMemo(()=>Hd(f.routeTree,h),[f.routeTree,h]),kn=u.useMemo(()=>Fd(v?.document?.raw),[v?.document?.raw]),Sn=u.useMemo(()=>Kd(s),[s?.states]),en=u.useMemo(()=>{const W=v?.document?.raw,J=Hf(W?.components),R=W?.initIsolated,le=R&&typeof R=="object"&&!Array.isArray(R)?Object.keys(R):[];return FA(J,le)},[v?.document?.raw]),Kn=u.useMemo(()=>{const W=v?.document?.raw;return Hf(W?.components).map(J=>J.scopeId).filter(J=>typeof J=="string"&&J.length>0)},[v?.document?.raw]),cn=jd({raw:v?.document?.raw,spec:s}),Pi=u.useCallback((W,J)=>{if(!v)return;const R={children:Ne.current.components},le=Pe(R,W);if(!le)return;Tt.current={colorScheme:f.previewColorScheme==="dark"?"dark":"base",breakpoint:Qr(f.previewDevice,le,f.previewCustomWidth)};const me=t?.getBoundingClientRect(),xe=I&&me?{left:me.left+I.left,top:me.top+I.top,width:I.width,height:I.height}:void 0,Te=oe,we=W.find(tt),_e=we?ge(we.responsive):null,Ee=W.filter(Cn=>typeof Cn=="number"),He=Mb({children:Ne.current.components},Ee,Lb(cn)),Nt=He.length>0?[...Yi({iterationVars:He}),...cn]:cn,gt=(Cn,QM)=>u.createElement(m4,{key:`pem-${at(je.current??[])}`,node:Cn,spec:s,manifest:Ne.current.manifest,t:h,permissionCandidates:a,pageCandidates:zt,dataSourceCandidates:kn,stateKeyCandidates:Sn,bindingCandidates:Nt,liveElement:Te,templateIdentifier:f.templateIdentifier,initialTab:QM,branchLabel:_e,isolatedScopeIdCandidates:en,usedScopeIds:Kn,onSaveInjectedProps:async(mt,$n)=>{const Oi=typeof Cn.id=="string"?Cn.id:"",Vn=await z4(f.templateIdentifier,mt,Oi,$n);if(st({op:"save",layoutName:`extension:${mt}`,editMode:f.editMode,saveTarget:"layout_extension",endpoint:`/api/admin/templates/${f.templateIdentifier}/layout-extensions/${mt}`,isDirty:!0,timestamp:Date.now()}),Vn.kind!=="success")throw new Error(Vn.kind==="conflict"?h("layout_editor.save.conflict"):Vn.kind==="injection_not_found"?"injection not found":Vn.kind==="not_found"?"extension not found":Vn.message??"save failed")},scope:Tt.current,onScopeChange:mt=>{Tt.current=mt;const $n=Le.current;$n&&_.open({id:$n,ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:xe,content:gt(Cn),onClose:()=>{Le.current=null,je.current=null}})},onPatchNode:mt=>{let $n=[];v.patchLayout(Vn=>($n=Bt({children:Vn},W,()=>mt).children??[],$n)),y.push({actionKind:"inline_text_edit",label:"edit_props",snapshot:$n}),pr({source:"style_control",componentPath:at(W),componentName:typeof mt.name=="string"?mt.name:null,patchKey:null,timestamp:Date.now()});const Oi=Le.current;Oi&&_.open({id:Oi,ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:xe,content:gt(mt),onClose:()=>{Le.current=null,je.current=null}})},onDelete:()=>{const mt=Le.current;mt&&_.close(mt),Ce()},onClose:()=>{const mt=Le.current;mt&&_.close(mt)}});je.current=W;const Mt=_.open({ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:xe,content:gt(le,J),onClose:()=>{Le.current=null,je.current=null,Ze.current=null}});Le.current=Mt,Ze.current=Cn=>{_.open({id:Mt,ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:xe,content:gt(Cn),onClose:()=>{Le.current=null,je.current=null,Ze.current=null}})}},[v,s,h,a,zt,kn,Sn,cn,oe,y,_,Ce,t,I,f.previewColorScheme,f.previewDevice,f.previewCustomWidth,ge]);u.useEffect(()=>{const W=Ze.current,J=je.current;if(!W||!J)return;const R={children:Ne.current.components},le=Pe(R,J);le?W(le):Le.current&&_.close(Le.current)},[k]);const LM=()=>{if(!Dt)return null;const J={position:"absolute",background:"rgba(15, 23, 42, 0.45)",pointerEvents:"auto",zIndex:t2},R=we=>{we.preventDefault(),we.stopPropagation()};if(!I)return i.jsx("div",{"data-testid":"g7le-edit-lock-full",onClick:R,onMouseMove:R,style:{...J,inset:0}});const{left:le,top:me,width:xe,height:Te}=I;return i.jsxs("div",{"data-testid":"g7le-edit-lock",style:{position:"absolute",inset:0,pointerEvents:"none"},children:[i.jsx("div",{"data-testid":"g7le-edit-lock-top",onClick:R,onMouseMove:R,style:{...J,left:0,top:0,right:0,height:Math.max(0,me)}}),i.jsx("div",{"data-testid":"g7le-edit-lock-bottom",onClick:R,onMouseMove:R,style:{...J,left:0,top:me+Te,right:0,bottom:0}}),i.jsx("div",{"data-testid":"g7le-edit-lock-left",onClick:R,onMouseMove:R,style:{...J,left:0,top:me,width:Math.max(0,le),height:Te}}),i.jsx("div",{"data-testid":"g7le-edit-lock-right",onClick:R,onMouseMove:R,style:{...J,left:le+xe,top:me,right:0,height:Te}})]})},$l=u.useCallback(()=>{if(G&&Np(S.selectedLockKind)){if(p&&S.selectedPath){p(S.selectedPath);return}Pi(G)}},[G,S.selectedPath,S.selectedLockKind,p,Pi]),{scale:El}=m,Il=typeof S.selectedNode?.name=="string"?S.selectedNode.name:"",ly=s?.componentCapabilities?.[Il]??null,dy=Array.isArray(ly?.styleControls)?ly.styleControls:[],PM=dy.includes("width")?Ct(s,"width"):null,OM=dy.includes("height")?Ct(s,"height"):null,BM=u.useCallback((W,J)=>{if(!v||!G)return;let R=[];v.patchLayout(le=>(R=Bt({children:le},G,()=>W).children??[],R)),pr({source:"resize",componentPath:at(G),componentName:Il||null,patchKey:J==="height"?"height":"width",resizeAxis:J,timestamp:Date.now()})},[v,G,Il]),WM=u.useCallback((W,J)=>{if(!v||!G)return;let R=[];v.patchLayout(le=>(R=Bt({children:le},G,()=>W).children??[],R)),y.push({actionKind:"inline_text_edit",label:`resize ${J}`,snapshot:R})},[v,G,y]),jM=u.useCallback(()=>{if(!oe)return null;const W=oe.getBoundingClientRect(),J=El||1;return{width:W.width/J,height:W.height/J}},[oe,El]),ur=B4({node:S.selectedNode,widthControl:PM,heightControl:OM,scale:El,measureStartSize:jM,onResize:BM,onResizeEnd:WM}),HM=u.useCallback((W,J)=>{ur.onHandlePointerDown(W,J)},[ur]),Al=u.useCallback(()=>{const W=y.undo();!W||!v||v.setLayoutComponents(W.snapshot)},[y,v]),Tl=u.useCallback(()=>{const W=y.redo();!W||!v||v.setLayoutComponents(W.snapshot)},[y,v]);R7({onUndo:Al,onRedo:Tl});const FM=u.useMemo(()=>({copy:ne,cut:pe,paste:Q,delete:Ce,openProps:$l,selectParent:Z?ie:void 0,deselect:S.clearSelection}),[ne,pe,Q,Ce,$l,Z,ie,S.clearSelection]);gp({handlers:FM,hasSelection:!!S.selectedPath}),u.useEffect(()=>(window.__g7LayoutEditorHasSelection=!!S.selectedPath,()=>{try{delete window.__g7LayoutEditorHasSelection}catch{}}),[S.selectedPath]),u.useEffect(()=>(window.__g7LayoutEditorHistory={undo:Al,redo:Tl,canUndo:y.canUndo,canRedo:y.canRedo},()=>{try{delete window.__g7LayoutEditorHistory}catch{}}),[Al,Tl,y.canUndo,y.canRedo]);const KM=u.useCallback(W=>{const J=L;F(null),J&&(async()=>{if((await A.commit(J.path,W)).kind==="created"&&v){const le=v.document?.raw?.components??[];y.push({actionKind:"inline_text_edit",label:"inline_create_key",snapshot:le})}})()},[L,A,v,y]),cy=u.useCallback(()=>{const W=L;F(null),A.trackCancel(W?.path??null)},[L,A]),VM=u.useCallback(()=>{F(null)},[]),UM=u.useCallback(async W=>{const J=L;if(!J)return null;const R=await A.keyifyChipValue(J.path,W);if(R.kind!=="created"||!R.translationKey)return null;const le=v?.document?.raw?.components??[];return y.push({actionKind:"inline_text_edit",label:"inline_keyify_chip",snapshot:le}),R.translationKey},[L,A,v,y]),qM=u.useCallback(()=>{const W=L;W&&(F(null),S.handleSelect("",{dataset:{editorPath:W.domPath}}),Pi(W.path,"translation"))},[L,S,Pi]),wt=u.useMemo(()=>{if(!L)return null;const W=v?.document?.raw?.components??k;return Pe({children:W},L.path)},[L,v?.document,k]),GM=u.useCallback(async(W,J)=>{const R=L;if(!v||!R)return null;const le=typeof wt?.text=="string"?wt.text:"";let me;if(R.isParamKey)me=await Ir(f.templateIdentifier,f.locale,le,W,J.sourceId,J.path,"scalar");else{const He=Nt=>Nt.replace(/\$t:[a-zA-Z0-9._-]+/g,gt=>{const Mt=h(gt.slice(3));return Mt&&Mt!==gt.slice(3)&&!Mt.startsWith("$t:")?Mt:""}).replace(/\s+/g," ").trim();me=await hs(f.templateIdentifier,f.selectedRoute?.layoutName??null,f.locale,le,W,J.sourceId,J.path,"scalar",He,h)}if(me.kind==="error")return null;const xe=R.path;let Te=[];v.patchLayout(He=>(Te=Bt({children:He},xe,Mt=>({...Mt,text:me.text})).children??[],Te)),y.push({actionKind:"inline_text_edit",label:"inline_insert_binding",snapshot:Te});const we=me.kind==="ok"&&"key"in me?me.key:void 0;!R.isParamKey&&we&&F(He=>He&&He.path===xe?{...He,isParamKey:!0,customKey:we,chipValue:void 0,chipParamLabels:void 0}:He);try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:f.templateIdentifier,locale:f.locale}}))}catch{}const _e=vt(me.text),Ee=R.customKey??_e?.key??"";return Ee?It(Ee,f.locale)??null:null},[v,L,wt,f.templateIdentifier,f.locale,f.selectedRoute,y,h]),YM=u.useCallback(async W=>{const J=L;if(!v||!J)return null;const R=typeof wt?.text=="string"?wt.text:"",le=vt(R),me=J.customKey??le?.key??null,xe=xo(R,W),Te=J.path;let we=[];return v.patchLayout(_e=>(we=Bt({children:_e},Te,Nt=>({...Nt,text:xe})).children??[],we)),y.push({actionKind:"inline_text_edit",label:"inline_remove_binding",snapshot:we}),me&&await Ar(f.templateIdentifier,me,W,f.locale),me?It(me,f.locale)??null:null},[v,L,wt,f.templateIdentifier,f.locale,y]),[Dl,uy]=u.useState({}),XM=["fontSize","color","fontStyle","textDecoration","textAlign","letterSpacing","lineHeight","fontFamily"];u.useEffect(()=>{if(!L||!t||typeof MutationObserver>"u"){uy({});return}const W=`[data-editor-path="${dn(L.domPath)}"]`,J=()=>{const me=t.querySelector(W);if(!me)return;const xe={};for(const we of XM){const _e=me.style.getPropertyValue(we.replace(/([A-Z])/g,"-$1").toLowerCase());_e&&(xe[we]=_e)}const Te=Mg(t,L.domPath)??void 0;uy({className:me.className,style:xe,effectiveColor:Te})};J();const R=t.querySelector(W);if(!R)return;const le=new MutationObserver(J);return le.observe(R,{attributes:!0,attributeFilter:["class","style"]}),le.observe(t,{childList:!0,subtree:!0}),()=>le.disconnect()},[L?.path?at(L.path):null,t]);const py=u.useCallback((W,J)=>{if(!v||!L)return;const R=L.path;let le=[],me=null;v.patchLayout(xe=>(le=Bt({children:xe},R,_e=>{const Ee=J(_e);return me=typeof Ee.name=="string"?Ee.name:null,Ee}).children??[],le)),y.push({actionKind:"inline_text_edit",label:`inline_format ${W}`,snapshot:le}),pr({source:"style_control",componentPath:at(R),componentName:me,patchKey:W,timestamp:Date.now()})},[v,L,y]),ft=u.useMemo(()=>{const W=S.selectedPath;if(!W||!x)return null;const J=[];let R=W;for(;R;){J.push(R);const le=R.match(/^(.*)\.children\.\d+$/);R=le?le[1]:null}for(const le of J){const me=Re(le);if(!me)continue;const xe=Pe(x,me),Te=typeof xe?.name=="string"?xe.name:null;if(!Te)continue;const we=Ui(s,Te),_e=we?.canvasOverlay?.kind;if(typeof _e!="string"||!_e||!xe)continue;const Ee=we.canvasOverlay.params&&typeof we.canvasOverlay.params=="object"?we.canvasOverlay.params:void 0,He=le===W?null:W.slice(le.length+1);return{kind:_e,params:Ee,tablePath:le,tableNode:xe,selectedCellRel:He}}return null},[S.selectedPath,x,s]),mo=ft?N4(ft.kind):null,fy=u.useMemo(()=>!mo||!t||!ft?null:ho(t,ft.tablePath),[mo,t,ft,I,k]),JM=u.useMemo(()=>{if(!mo||!t||!ft)return[];const W=ft.tablePath,J=dn(W),R=[];return t.querySelectorAll(`[data-editor-path^="${J}.children."]`).forEach(xe=>{const Te=xe.dataset.editorPath??"";if(!Te.startsWith(W+"."))return;const we=Te.slice(W.length+1),_e=co(xe,t);_e&&R.push({path:we,top:_e.top,left:_e.left,width:_e.width,height:_e.height})}),t.querySelectorAll(`[data-editor-item-path^="${J}."]`).forEach(xe=>{const Te=xe.dataset.editorItemPath??"";if(!Te.startsWith(W+"."))return;const we=Te.slice(W.length+1),_e=co(xe,t);_e&&R.push({path:we,top:_e.top,left:_e.left,width:_e.width,height:_e.height})}),R},[mo,t,ft,I,k]),ZM=u.useCallback(W=>{const J=ft?Re(ft.tablePath):null;if(!v||!J)return;let R=[];v.patchLayout(le=>(R=Bt({children:le},J,()=>W).children??[],R)),y.push({actionKind:"inline_text_edit",label:"inplace_edit",snapshot:R}),pr({source:"style_control",componentPath:ft?.tablePath??"",componentName:typeof W.name=="string"?W.name:null,patchKey:"canvas_inplace",timestamp:Date.now()})},[v,G,y]);return t?i.jsxs("div",{className:"g7le-editor-canvas-overlay","data-testid":"g7le-editor-canvas-overlay",style:{position:"absolute",inset:0,pointerEvents:"none"},children:[!T&&LM(),T&&i.jsxs("div",{"data-testid":"g7le-canvas-pick-banner",style:{position:"absolute",top:8,left:"50%",transform:"translateX(-50%)",zIndex:9999,display:"flex",alignItems:"center",gap:12,padding:"8px 14px",background:"#1e293b",color:"#fff",borderRadius:8,fontSize:13,boxShadow:"0 4px 12px rgba(0,0,0,0.25)",pointerEvents:"auto"},children:[i.jsxs("span",{children:["🎯 ",h("layout_editor.target_picker.canvas_pick_hint")]}),i.jsx("button",{type:"button","data-testid":"g7le-canvas-pick-cancel",onClick:()=>X(T,null),style:{border:"1px solid #475569",borderRadius:6,background:"transparent",color:"#cbd5e1",cursor:"pointer",fontSize:12,padding:"3px 10px"},children:h("layout_editor.target_picker.cancel")})]}),f.editMode!=="route"&&i.jsx(hA,{frameEl:t,components:k,editMode:f.editMode,currentExtensionId:$,editableRootPath:C}),L&&((L.isParamKey&&L.customKey||L.chipValue)&&wt?i.jsxs(i.Fragment,{children:[wt&&i.jsx(Dg,{node:wt,spec:s,t:h,onApplyControl:py,box:L.box,scope:{colorScheme:f.previewColorScheme==="dark"?"dark":"base",breakpoint:Qr(f.previewDevice,wt,f.previewCustomWidth)}}),i.jsx(J4,{box:L.box,node:wt,customKey:L.customKey??null,initialChipValue:L.chipValue,chipParamLabels:L.chipParamLabels,onKeyify:UM,templateIdentifier:f.templateIdentifier,locale:f.locale,t:h,candidates:cn,onInsertBinding:GM,onRemoveBinding:YM,onCommit:VM,onCancel:cy})]}):i.jsxs(i.Fragment,{children:[wt&&i.jsx(Dg,{node:wt,spec:s,t:h,onApplyControl:py,box:L.box,scope:{colorScheme:f.previewColorScheme==="dark"?"dark":"base",breakpoint:wt?Qr(f.previewDevice,wt,f.previewCustomWidth):"base"}}),i.jsx(X4,{box:L.box,initialValue:L.initialValue,isCustomKey:L.isCustomKey,t:h,onCommit:KM,onCancel:cy,mirrorClassName:Dl.className,mirrorStyle:Dl.style,nodeEffectiveColor:Dl.effectiveColor??L.nodeEffectiveColor,onOpenTranslations:qM})]})),!T&&i.jsx(a2,{hoverBox:D,selectedBox:I,lockKind:S.selectedLockKind,navAffordance:S.selectedNavAffordance,onEditProps:$l,onDuplicate:be,onDelete:Ce,onSeparateBranch:$e?.mode==="separate"?U:void 0,separateBranchLabel:ke?.separate,onMergeBranch:$e?.mode==="merge"?ue:void 0,mergeBranchLabel:ke?.merge,definedDeviceBranches:he,onJumpToDevice:he.length>0?j:void 0,onLinkEditDestination:Ae,onEditBase:dt,onEditExtension:pt,extensionLabel:De,baseLayoutLabel:S.selectedBaseLayout,dataSourceLabel:S.selectedDataSourceId,branchLabel:ee,onEditIteration:S.selectedIsIteration&&f.editMode!=="iteration_item"?ot:void 0,resizeEnabledAxes:ur.enabledAxes,onResizeHandlePointerDown:ur.enabledAxes.width||ur.enabledAxes.height?HM:void 0,selectedName:Se,onSelectParent:Z?ie:void 0}),T&&O&&i.jsx("div",{"data-testid":"g7le-canvas-pick-hover","data-pick-has-id":O.hasId?"true":"false",style:{position:"absolute",left:O.box.left,top:O.box.top,width:O.box.width,height:O.box.height,pointerEvents:"none",zIndex:9998,boxSizing:"border-box",border:O.hasId?"2px solid #2563eb":"2px dashed #94a3b8",background:O.hasId?"rgba(37,99,235,0.10)":"repeating-linear-gradient(45deg, rgba(148,163,184,0.18) 0, rgba(148,163,184,0.18) 6px, transparent 6px, transparent 12px)",cursor:O.hasId?"pointer":"not-allowed"},children:!O.hasId&&i.jsx("span",{"data-testid":"g7le-canvas-pick-hover-hint",style:{position:"absolute",top:0,left:0,transform:"translateY(-100%)",background:"#475569",color:"#fff",fontSize:11,lineHeight:1.4,padding:"2px 6px",borderRadius:4,whiteSpace:"nowrap"},children:h("layout_editor.target_picker.needs_id")})}),!T&&i.jsx(f2,{selectedBox:Ve,points:Ie.points,onAddRequest:Je}),mo&&ft&&fy&&S.selectedLockKind==="none"&&i.jsx(mo,{node:ft.tableNode,params:ft.params,nodeBox:fy,cellBoxes:JM,selectedCellPath:ft.selectedCellRel??void 0,colorScheme:f.previewColorScheme==="dark"?"dark":"light",t:h,onPatchNode:ZM,onInsertChild:ae,onRemoveChild:W=>{const J=Re(W);if(!v||!J)return;let R=[];v.patchLayout(le=>(R=ss({children:le},J).children??[],R)),y.push({actionKind:"remove",label:"inplace_remove",snapshot:R})},onRequestInlineEdit:W=>{ft&&Y(`${ft.tablePath}.${W}`)}}),v&&i.jsx(dA,{frameEl:t,nesting:o,editMode:f.editMode,currentExtensionId:$,editableRootPath:C,components:k,patchLayout:v.patchLayout,pushHistory:de,selectedPath:S.selectedPath,onSelectPath:W=>S.handleSelect("",{dataset:{editorPath:W}}),onMovePath:W=>S.handleSelect("",{dataset:{editorPath:W}}),onRequestInlineEdit:Y})]}):null}function Ng(e,t){if(t.length===0)return null;const o=Ya({children:e},t);return o&&typeof o.name=="string"?o.name:null}function Ya(e,t){return Pe(e,t)}function dn(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[^a-zA-Z0-9_\-.]/g,t=>`\\${t}`)}function Mg(e,t){if(!t)return null;const n=e.querySelector(`[data-editor-path="${dn(t)}"]`);if(!n||typeof window.getComputedStyle!="function")return null;let o=n;const r=n.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);let s=r.nextNode();for(;s;){if((s.textContent??"").trim().length>0){const a=s.parentElement;if(a&&n.contains(a)){o=a;break}}s=r.nextNode()}try{return window.getComputedStyle(o).color||null}catch{return null}}function ho(e,t){if(!t)return null;const n=e.querySelector(`[data-editor-path="${dn(t)}"]`);if(n){const c=co(n,e);return c&&uo(c,e)?c:null}const o=e.querySelectorAll(`[data-editor-path^="${dn(t)}.iteration."]`);let r=1/0,s=1/0,a=-1/0,l=-1/0,d=!1;return o.forEach(c=>{const p=c.dataset.editorPath??"";if(!new RegExp("\\.iteration\\.\\d+$").test(p))return;const f=co(c,e);f&&uo(f,e)&&(d=!0,r=Math.min(r,f.left),s=Math.min(s,f.top),a=Math.max(a,f.left+f.width),l=Math.max(l,f.top+f.height))}),d?{left:r,top:s,width:a-r,height:l-s,scale:1}:null}function rD({isEditMode:e,editorSpec:t,sampleOverride:n}){const o=t?.sampleData;return u.useMemo(()=>sv({spec:o,overrideSpec:n,onMatch:r=>{hy(r)}}),[e,o,n])}const iD=Lt().ComponentRegistry;function sD(e){return e.replace(/[\t\n\r]/g,"").replace(/\\/g,"/").replace(/^([a-z][a-z0-9+.\-]*:)?\/{2,}/i,"$1//")}function aD(e,t){try{const n=typeof window<"u"&&window.location?.protocol||"https:",o=t||(typeof window<"u"?window.location?.origin:void 0)||"https://localhost",r=e.startsWith("//")?`${n}${e}`:e,s=new URL(r,o);return s.protocol!=="http:"&&s.protocol!=="https:"?null:s.hostname.toLowerCase()}catch{return null}}function Xa(){const e=typeof window<"u"?window.G7Config?.trustedScriptHosts:void 0;return Array.isArray(e)?e.map(t=>String(t).toLowerCase()):[]}function Lg(e,t){if(typeof e!="string")return!1;const n=e.trim();if(n==="")return!1;const o=sD(n),r=o.startsWith("//"),s=/^[a-z][a-z0-9+.-]*:/i.test(o);if(!r&&!s&&o.startsWith("/"))return!0;const a=aD(o),l=t??Xa();return a!==null&&l.map(d=>String(d).toLowerCase()).includes(a)}function lD(e){return e.split(/[-_]/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}async function dD(e){const t=typeof window<"u"?window.localStorage?.getItem("auth_token"):null,n={Accept:"application/json"};t&&(n.Authorization=`Bearer ${t}`);const o=await fetch(`/api/admin/templates/${encodeURIComponent(e)}/editor-assets`,{headers:n,credentials:"same-origin"});if(!o.ok){const s=await o.json().catch(()=>null);throw ei(o.status,s,"assets")}const r=await o.json();return r.data||r}async function cD(e){try{if(typeof fetch!="function")return 0;const t=await fetch(nn(`/api/templates/${encodeURIComponent(e)}/config`,"json"),{credentials:"same-origin",headers:{Accept:"application/json"}});if(!t.ok)return 0;const n=await t.json().catch(()=>null),o=n?.data?.cache_version??n?.cache_version;return typeof o=="number"&&o>0?o:0}catch{return 0}}function uD(e){return new Promise((t,n)=>{if(typeof document>"u"){n(new Error("document undefined"));return}if(!Lg(e,Xa())){n(new Error(`Blocked untrusted script src (same-origin path or declared trusted host required): ${e}`));return}if(document.querySelector(`script[data-g7le-asset="${e}"]`)){t();return}const r=document.createElement("script");r.src=e,r.async=!1,r.setAttribute("data-g7le-asset",e),r.addEventListener("load",()=>t()),r.addEventListener("error",()=>n(new Error(`script load failed: ${e}`))),document.head.appendChild(r)})}async function pD(e){if(typeof document>"u")return;const t=`[data-g7le-asset="${e}"]`;if(document.querySelector(`link${t}, style${t}`))return;if(e.includes("/api/admin/"))try{const r=typeof window<"u"?window.localStorage?.getItem("auth_token"):null,s={Accept:"text/css"};r&&(s.Authorization=`Bearer ${r}`);const a=await fetch(e,{headers:s,credentials:"same-origin"});if(a.ok){const l=await a.text(),d=document.createElement("style");d.textContent=l,d.setAttribute("data-g7le-asset",e),document.head.appendChild(d);return}}catch{}const o=document.createElement("link");o.rel="stylesheet",o.href=e,o.setAttribute("data-g7le-asset",e),document.head.appendChild(o)}function fD(e,t,n="user"){const[o,r]=u.useState({componentRegistry:null,translationEngine:null,isReady:!1,error:null});return u.useEffect(()=>{let s=!1;return(async()=>{r(a=>({...a,isReady:!1,error:null}));try{const a=await dD(e);if(s)return;for(const b of a.css??[])if(await pD(b),s)return;const l=lD(e);if(!(typeof window<"u"&&typeof window[l]=="object")){for(const b of a.js??[])if(await uD(b),s)return}const c=iD.createIsolatedInstance();if(await c.loadComponents(e,n),s)return;const p=await cD(e);if(s)return;const f=new Pt({defaultLocale:t});if(p>0&&f.setCacheVersion(p),await f.loadTranslations(e,t),s)return;md(f,e);try{const b=Pt.getInstance();p>b.getCacheVersion()&&b.setCacheVersion(p),await b.loadTranslations(e,t),md(b,e)}catch{}if(s)return;r({componentRegistry:c,translationEngine:f,isReady:!0,error:null})}catch(a){if(s)return;const l=Ep(a)?a:lo(a,"assets");r({componentRegistry:null,translationEngine:null,isReady:!1,error:l})}})(),()=>{s=!0}},[e,t,n]),o}const Pg=Lt().AuthManager;function gD(e){switch(e){case"unauthorized":return{icon:"🔒",tone:"blue",titleKey:"layout_editor.access_error.unauthorized.title",messageKey:"layout_editor.access_error.unauthorized.message",showRequiredPermissions:!0};case"forbidden":return{icon:"⛔",tone:"rose",titleKey:"layout_editor.access_error.forbidden.title",messageKey:"layout_editor.access_error.forbidden.message",showRequiredPermissions:!0};case"not_found":return{icon:"🗂️",tone:"slate",titleKey:"layout_editor.access_error.not_found.title",messageKey:"layout_editor.access_error.not_found.message",showRequiredPermissions:!1};case"server_error":return{icon:"🛠️",tone:"amber",titleKey:"layout_editor.access_error.server_error.title",messageKey:"layout_editor.access_error.server_error.message",showRequiredPermissions:!1};case"network":return{icon:"📡",tone:"amber",titleKey:"layout_editor.access_error.network.title",messageKey:"layout_editor.access_error.network.message",showRequiredPermissions:!1};default:return{icon:"⚠️",tone:"slate",titleKey:"layout_editor.access_error.unknown.title",messageKey:"layout_editor.access_error.unknown.message",showRequiredPermissions:!1}}}const hD={blue:{bg:"#eff6ff",border:"#bfdbfe",iconBg:"#dbeafe"},rose:{bg:"#fff1f2",border:"#fecdd3",iconBg:"#ffe4e6"},amber:{bg:"#fffbeb",border:"#fde68a",iconBg:"#fef3c7"},slate:{bg:"#f8fafc",border:"#e2e8f0",iconBg:"#f1f5f9"}};function yD({error:e}){return u.useEffect(()=>{if(e.kind!=="unauthorized"||typeof window>"u")return;const t=Pg.getInstance(),n=`${window.location.pathname}${window.location.search}`,o=t.getLoginRedirectUrl("admin",n,"session_expired"),r=window.setTimeout(()=>{window.location.href=o},600);return()=>window.clearTimeout(r)},[e.kind]),null}function Ja({error:e}){const{t}=et(),n=gD(e.kind),o=hD[n.tone],r=()=>{typeof window<"u"&&(window.location.href="/admin")},s=()=>{typeof window<"u"&&window.location.reload()},a=()=>{if(typeof window>"u")return;const l=Pg.getInstance(),d=`${window.location.pathname}${window.location.search}`;window.location.href=l.getLoginRedirectUrl("admin",d)};return i.jsxs("div",{className:"g7le-access-error","data-testid":"g7le-access-error","data-error-kind":e.kind,style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"#f1f5f9"},children:[i.jsx(yD,{error:e}),i.jsxs("div",{style:{maxWidth:480,width:"100%",background:o.bg,border:`1px solid ${o.border}`,borderRadius:12,padding:"28px 32px",boxShadow:"0 2px 8px rgba(15, 23, 42, 0.05)",textAlign:"center"},children:[i.jsx("div",{style:{width:64,height:64,margin:"0 auto 16px",borderRadius:"50%",background:o.iconBg,display:"flex",alignItems:"center",justifyContent:"center",fontSize:32,lineHeight:1},"aria-hidden":"true",children:n.icon}),i.jsx("h2",{"data-testid":"g7le-access-error-title",style:{margin:"0 0 8px",fontSize:18,fontWeight:700,color:"#0f172a"},children:t(n.titleKey)}),i.jsx("p",{"data-testid":"g7le-access-error-message",style:{margin:"0 0 16px",fontSize:13,lineHeight:1.6,color:"#475569"},children:t(n.messageKey)}),n.showRequiredPermissions&&e.requiredPermissions&&i.jsxs("div",{"data-testid":"g7le-access-error-permissions",style:{display:"inline-flex",flexWrap:"wrap",gap:6,justifyContent:"center",padding:"8px 12px",marginBottom:16,background:"rgba(15, 23, 42, 0.04)",borderRadius:8,fontSize:12,color:"#475569"},children:[i.jsx("span",{style:{fontWeight:600},children:t("layout_editor.access_error.required_permission_label")}),e.requiredPermissions.split(/[,\s]+/).filter(Boolean).map(l=>i.jsx("code",{style:{padding:"2px 6px",background:"#fff",border:"1px solid #e2e8f0",borderRadius:4,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:11,color:"#1e293b"},children:l},l))]}),e.message&&i.jsxs("details",{"data-testid":"g7le-access-error-detail",style:{marginBottom:16,fontSize:11,color:"#94a3b8"},children:[i.jsx("summary",{style:{cursor:"pointer"},children:t("layout_editor.access_error.detail_summary")}),i.jsxs("pre",{style:{marginTop:8,padding:8,background:"#fff",border:"1px solid #e2e8f0",borderRadius:6,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",textAlign:"left",fontSize:11,color:"#475569"},children:[e.status>0?`HTTP ${e.status} `:"",e.message]})]}),i.jsxs("div",{style:{display:"flex",justifyContent:"center",gap:8,flexWrap:"wrap"},children:[e.kind==="unauthorized"&&i.jsx("button",{type:"button","data-testid":"g7le-access-error-action-signin",onClick:a,style:Za,children:t("layout_editor.access_error.action.sign_in")}),e.kind==="forbidden"&&i.jsx("button",{type:"button","data-testid":"g7le-access-error-action-home",onClick:r,style:Za,children:t("layout_editor.access_error.action.go_home")}),(e.kind==="not_found"||e.kind==="server_error"||e.kind==="network"||e.kind==="unknown")&&i.jsx("button",{type:"button","data-testid":"g7le-access-error-action-retry",onClick:s,style:Za,children:t("layout_editor.access_error.action.retry")}),e.kind!=="unauthorized"&&i.jsx("button",{type:"button","data-testid":"g7le-access-error-action-home-secondary",onClick:r,style:bD,children:t("layout_editor.access_error.action.go_admin_home")})]})]})]})}const Za={padding:"8px 16px",background:"#2563eb",color:"#fff",border:"1px solid #1d4ed8",borderRadius:6,fontSize:13,fontWeight:600,cursor:"pointer"},bD={padding:"8px 16px",background:"#fff",color:"#475569",border:"1px solid #cbd5e1",borderRadius:6,fontSize:13,fontWeight:500,cursor:"pointer"};function mD(e){const t=window;if(typeof t>"u")return{getSnapshot:()=>({globalState:{},localState:{}}),restore:()=>{}};const n=t.G7Core||{},o={templateApp:t.__templateApp,g7CoreState:n.state,g7CoreDispatch:n.dispatch,g7CoreData:n.data,g7CoreModal:n.modal,g7CoreToast:n.toast};let r={...e.initialGlobalState??{}};r._local||(r._local={});const s=[],a=()=>{const c={globalState:{...r},localState:{...r._local??{}}};for(const p of s)try{p(r)}catch{}e.onChange?.(c)},l={},d={getGlobalState:()=>r,setGlobalState:(c,p)=>{typeof c=="function"?r=c(r):r={...r,...c},a()},onGlobalStateChange:c=>(s.push(c),()=>{const p=s.indexOf(c);p>=0&&s.splice(p,1)}),get globalState(){return r},getActionDispatcher:()=>e.actionDispatcher,getDataSource:c=>l[c]??null,setDataSource:(c,p)=>{l[c]=p},refetchDataSource:async c=>null,updateDataSourceItem:(c,p,f)=>l[c]??null,getLocale:()=>e.locale,changeLocale:c=>{},getRouter:()=>({navigate:()=>{},replace:()=>{},push:()=>{}}),updateQueryParams:()=>{}};return t.__templateApp=d,n&&typeof n.dispatch=="function"&&(n.dispatch=(c,p)=>{try{return e.actionDispatcher.executeAction(c,p??{})}catch{return}}),n&&typeof n.modal=="object"&&n.modal!==null&&(n.modal={...n.modal,open:()=>{},close:()=>{},closeAll:()=>{}}),n&&typeof n.toast=="object"&&n.toast!==null&&(n.toast={...n.toast,push:()=>{},dismiss:()=>{}}),{getSnapshot:()=>({globalState:{...r},localState:{...r._local??{}}}),restore:()=>{t.__templateApp===d&&(t.__templateApp=o.templateApp),t.G7Core&&(o.g7CoreState!==void 0&&(t.G7Core.state=o.g7CoreState),o.g7CoreDispatch!==void 0&&(t.G7Core.dispatch=o.g7CoreDispatch),o.g7CoreData!==void 0&&(t.G7Core.data=o.g7CoreData),o.g7CoreModal!==void 0&&(t.G7Core.modal=o.g7CoreModal),o.g7CoreToast!==void 0&&(t.G7Core.toast=o.g7CoreToast)),s.length=0}}}const vD=new Set(["id","userId","postId","orderId","productId","categoryId","commentId","noticeId","inquiryId","addressId","wishlistId","notificationId","roleId","menuId"]);function _D(e){if(!e)return{};const t={},n=/:([a-zA-Z_][a-zA-Z0-9_]*)/g;let o;for(;(o=n.exec(e))!==null;){const r=o[1];t[r]=xD(r)}return t}function xD(e){return vD.has(e)||/Id$|_id$/.test(e)?"1":"sample"}const wD=_o("LayoutEditor");function nr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Si(e){if(Array.isArray(e))return e.map(t=>Si(t));if(nr(e)){const t={};for(const[n,o]of Object.entries(e))t[n]=Si(o);return t}return e}function Og(e,t="",n=new Set){for(const[o,r]of Object.entries(e)){const s=t?`${t}.${o}`:o;nr(r)?Og(r,s,n):n.add(s)}return n}function Bg(e,t,n,o,r,s=""){for(const[a,l]of Object.entries(t)){const d=s?`${s}.${a}`:a;if(n.has(d)){r(`[LayoutEditor] sampleGlobal key conflict: extension '${o}' override of core key '${d}' ignored`);continue}const c=e[a];nr(l)&&nr(c)?Bg(c,l,n,o,r,d):e[a]=Si(l)}}function Qa(e){const t=e.warn??(r=>wD.warn(r)),n=Si(e.coreSeed??{});e.isGuestOnly&&"currentUser"in n&&delete n.currentUser;const o=Og(n);for(const r of e.sources)nr(r.sampleGlobal)&&Bg(n,r.sampleGlobal,o,r.id,t);return e.isGuestOnly&&"currentUser"in n&&delete n.currentUser,n}function kD(e){const t={};if(!e||typeof e!="object"||Array.isArray(e))return t;for(const[n,o]of Object.entries(e))n.startsWith("$")&&(t[n]=o);return t}function SD(e){const t={};if(!e||typeof e!="object"||Array.isArray(e))return t;for(const[n,o]of Object.entries(e))n.startsWith("$")||(t[n]=o);return t}function CD(e){if(typeof e!="string")return null;const t=/^\s*\{\{\s*([\s\S]*?)\s*\}\}\s*$/.exec(e);if(!t)return null;let n=t[1];const o=n.indexOf("??");return o>=0&&(n=n.slice(0,o)),n=n.replace(/\?\./g,".").replace(/\s+/g,""),n===""||!/^[A-Za-z_$][A-Za-z0-9_$]*(\.[A-Za-z_$][A-Za-z0-9_$]*)*$/.test(n)?null:n.split(".")}function $D(e,t){const n=CD(t);if(!n||n.length===0)return e;let o=e;for(let a=0;ao.map(r=>{if(!r||typeof r!="object")return r;const s=r;let a=s;if(typeof s.slot=="string"&&!t.has(s.slot)){const{slot:l,...d}=s;a={...d,__editorSlotName:l}}if(Array.isArray(a.children)){const l=n(a.children);l!==a.children&&(a={...a,children:l})}return a});return n(e)}function St(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Qt(e){if(Array.isArray(e))return e.map(t=>Qt(t));if(St(e)){const t={};for(const[n,o]of Object.entries(e))t[n]=Qt(o);return t}return e}function Ci(e,t){for(const[n,o]of Object.entries(t)){const r=e[n];St(o)&&St(r)?Ci(r,o):e[n]=Qt(o)}}function AD(e){const t=[];let n="";for(let o=0;o0&&(t.push(n),n="");const s=e[o+1];if(s==="'"||s==='"'){const l=e.indexOf(`${s}]`,o+2);if(l!==-1){t.push(e.slice(o+2,l)),o=l+1;continue}}const a=e.indexOf("]",o+1);if(a!==-1){t.push(e.slice(o+1,a)),o=a;continue}n+=r}else r==="."?n.length>0&&(t.push(n),n=""):n+=r}return n.length>0&&t.push(n),t.filter(o=>o.length>0)}function Ra(e,t,n){const o=AD(t);if(o.length===0)return;let r=e;for(let s=0;s0?t:void 0}const tl="g7le:editor-t-ready",Hg="data-g7le-vh-expanded";function DD(e,t){if(!e||!t)return;const n=t;e.querySelectorAll("*").forEach(r=>{const s=window.getComputedStyle(r),a=parseFloat(s.height),l=Number.isFinite(a)&&Math.abs(a-n)<=2,d=parseFloat(s.minHeight),c=Number.isFinite(d)&&Math.abs(d-n)<=2,p=s.overflowY==="auto"||s.overflowY==="scroll"||s.overflowY==="hidden"||s.overflow==="auto"||s.overflow==="scroll"||s.overflow==="hidden";l&&p?(r.style.setProperty("height","auto","important"),c&&r.style.setProperty("min-height","0","important"),r.style.setProperty("overflow","visible","important"),r.setAttribute(Hg,"1")):(s.overflowY==="auto"||s.overflowY==="scroll")&&r.scrollHeight>r.clientHeight+4&&r.clientHeight>120&&(r.style.setProperty("overflow","visible","important"),r.style.setProperty("height","auto","important"),r.setAttribute(Hg,"1"))})}const zD=[];function ND(e={}){const{manifest:t=null,nesting:n=null,componentPalette:o=null,spec:r=null,permissionCandidates:s,sampleGlobalSources:a=zD,resolveRouteMatch:l,onNavigateToDestination:d,onSessionAddedPathsChange:c}=e,{state:p}=Qe(),f=Kt(),b=Bp(),{document:g,isLoading:m,error:h}=f??b,v=u.useRef(null),[y,_]=u.useState(null),{deviceWidth:w,scale:k,colorScheme:x}=Ga(),$=u.useMemo(()=>p.activeStateId?p.availableStates.find(ce=>ce.id===p.activeStateId)??null:null,[p.activeStateId,p.availableStates]),C=u.useMemo(()=>jg($),[$]),S=rD({isEditMode:!0,editorSpec:r??void 0,sampleOverride:C}),{t:D}=et(),{componentRegistry:E,translationEngine:I,isReady:N,error:T}=fD(p.templateIdentifier,p.locale),B=u.useRef(null);B.current===null&&(B.current=new Ed);const M=u.useRef(null);if(M.current===null){M.current=new z7({navigate:()=>{}}),M.current.setPreviewMode(!0);try{const q=window.__templateApp?.getActionDispatcher?.();if(q&&typeof q.getRegisteredHandlers=="function"){const se=q.getRegisteredHandlers();for(const ae of se){if(!ae.includes("."))continue;const be=typeof q.getHandler=="function"?q.getHandler(ae):void 0;typeof be=="function"&&M.current.registerHandler(ae,be,{category:"plugin",source:"preview-canvas-cloned-from-host"})}}}catch{}}u.useEffect(()=>{if(!N)return;const ce=M.current;if(ce)try{const q=window.G7Core?.getActionDispatcher?.();if(!q||typeof q.getRegisteredHandlers!="function")return;const se=q.getRegisteredHandlers();for(const ae of se){if(!ae.includes(".")||typeof ce.getHandler=="function"&&ce.getHandler(ae))continue;const be=typeof q.getHandler=="function"?q.getHandler(ae):void 0;typeof be=="function"&&ce.registerHandler(ae,be,{category:"plugin",source:"preview-canvas-iife-reclone"})}}catch{}},[N]);const O=u.useMemo(()=>new N7({sampleProvider:S,actionDispatcher:M.current}),[S]),z=u.useMemo(()=>g?.raw?.meta?.guest_only===!0,[g]),H=u.useMemo(()=>Qa({sources:a,isGuestOnly:z}),[a,z]),P=u.useMemo(()=>{const ce=MD(el($),I,{templateId:p.templateIdentifier,locale:p.locale}),q=H._local,{global:se,local:ae}=TD({globalBaseline:H,localBaseline:q??{},patch:$?.initialState??null,formErrors:ce});return{...se,_local:ae}},[H,$,I,p.templateIdentifier,p.locale]),A=u.useMemo(()=>!$||!(!!$.initialState?.local||!!el($))?null:{...P._local??{},_forceLocalInit:$.id,_merge:"deep"},[$,P]),L=ce=>typeof ce=="object"&&ce!==null&&!Array.isArray(ce),F=u.useMemo(()=>L($?.initialState?.query)?$.initialState.query:null,[$]),Y=u.useMemo(()=>L($?.initialState?.route)?$.initialState.route:null,[$]),[V,X]=u.useState(()=>Qa({sources:[],isGuestOnly:!1})),Z=u.useRef(null);u.useEffect(()=>{const ce={...P},q=mD({actionDispatcher:M.current,locale:p.locale,initialGlobalState:ce,onChange:ae=>{X(ae.globalState)}});Z.current=q;const se=window.__templateApp;return se?.setGlobalState&&M.current.setGlobalStateUpdater((ae,be)=>{se.setGlobalState(ae,be)}),X(ce),Ml({kind:"applyPatch",activeStateId:p.activeStateId,routePath:p.selectedRoute?.path??null,hasInitialPatch:!!$?.initialState,hasFormErrors:!!el($),hasSampleOverride:!!jg($)}),()=>{q.restore(),Z.current=null}},[p.locale,P]),u.useEffect(()=>{if(!I)return;const ce=window.G7Core;if(!ce||typeof ce.t!="function")return;const q=ce.t,se=p.templateIdentifier,ae=p.locale;return ce.t=(be,Ce)=>{try{const $e=Ce?"|"+Object.entries(Ce).map(([ue,ge])=>`${ue}=${ge}`).join("|"):void 0,U=I.translate(be,{templateId:se,locale:ae},$e);if(U!==be&&!U.startsWith("$t:"))return U}catch{}return q(be,Ce)},typeof window<"u"&&window.dispatchEvent(new CustomEvent(tl)),()=>{window.G7Core?.t&&window.G7Core.t!==q&&(window.G7Core.t=q)}},[I,p.templateIdentifier,p.locale]);const ie=u.useMemo(()=>{const ce=g?.raw?.components??[];return p.editMode!=="base"?ce:ID(ce)},[g,p.editMode]),oe=g?.raw?.__editability,G=g?.raw?.__extensionId,ee=u.useMemo(()=>p.editMode!=="extension"||oe!=="ok"?[]:typeof G!="number"?[]:LD(ie,G),[p.editMode,oe,G,ie]),[fe,K]=u.useState(null),[te,ye]=u.useState(!1),Se=g?.layoutName??null,De=u.useMemo(()=>{const ce=g?.raw?.scripts??[];return Array.isArray(ce)?ce.map(q=>q&&typeof q.src=="string"?q.src:"").join("|"):""},[g]);u.useEffect(()=>{ye(!1)},[Se,De]),u.useEffect(()=>{let ce=!1;const q=g?.raw?.scripts??[];if(!Array.isArray(q)||q.length===0){ye(!0);return}const se=[];for(const ae of q){if(!ae?.src||typeof ae.src!="string")continue;if(!Lg(ae.src,Xa())){console.warn(`[PreviewCanvas] Blocked untrusted script src (same-origin path or declared trusted host required): ${ae.src}`);continue}const be=ae.id?`script#${CSS.escape(ae.id)}, script[data-g7le-canvas-script="${ae.src}"]`:`script[data-g7le-canvas-script="${ae.src}"], script[src="${ae.src}"]`,Ce=window.document.querySelector(be);if(Ce){const $e=Ce.hasAttribute("data-g7le-canvas-script");if(Ce.hasAttribute("data-g7le-script-loaded")||!$e)continue;se.push(new Promise(ue=>{if(Ce.hasAttribute("data-g7le-script-loaded")){ue();return}Ce.addEventListener("load",()=>ue()),Ce.addEventListener("error",()=>ue())}));continue}se.push(new Promise($e=>{const U=window.document.createElement("script");U.src=ae.src,U.async=!1,ae.id&&(U.id=ae.id),U.setAttribute("data-g7le-canvas-script",ae.src);const ue=()=>{U.setAttribute("data-g7le-script-loaded","1"),$e()};U.addEventListener("load",ue),U.addEventListener("error",ue),window.document.head.appendChild(U)}))}if(se.length===0){ye(!0);return}return Promise.all(se).then(()=>{ce||requestAnimationFrame(()=>{requestAnimationFrame(()=>{ce||ye(!0)})})}),()=>{ce=!0}},[g]);const Ie=u.useMemo(()=>g?.raw?.data_sources??[],[g]),Ve=u.useMemo(()=>g?.raw?.computed??{},[g]),[ze,Be]=u.useState({}),Xe=u.useMemo(()=>{if(p.editMode!=="iteration_item")return ze;const ce=g?.iterationContext;if(!ce)return ze;const q=g?.raw?.components??[],se=Pe({children:q},ce.sourceIndexPath),ae=se&&se.iteration&&typeof se.iteration.source=="string"?se.iteration.source:null;return ae?$D(ze,ae):ze},[p.editMode,ze,g]),[Ne,Je]=u.useState(0);u.useEffect(()=>{if(typeof window>"u")return;const ce=()=>Je(q=>q+1);return window.addEventListener(kt,ce),()=>window.removeEventListener(kt,ce)},[]);const ve=u.useMemo(()=>_D(p.selectedRoute?.path??null),[p.selectedRoute?.path]);if(u.useEffect(()=>{let ce=!1;return(async()=>{if(Ie.length===0){ce||Be({});return}try{const q=await O.fetchDataSources(Ie,ve,new URLSearchParams,void 0,void 0);ce||Be(q)}catch{ce||Be({})}})(),()=>{ce=!0}},[Ie,O,ve]),u.useEffect(()=>{const ce=y;if(!ce||typeof window>"u")return;let q=0,se=0,ae=0;const be=()=>DD(ce,window.innerHeight);q=window.requestAnimationFrame(()=>{se=window.requestAnimationFrame(be)});let Ce=null;return typeof MutationObserver<"u"&&(Ce=new MutationObserver(()=>{ae||(ae=window.requestAnimationFrame(()=>{ae=0,be()}))}),Ce.observe(ce,{childList:!0,subtree:!0})),()=>{window.cancelAnimationFrame(q),window.cancelAnimationFrame(se),ae&&window.cancelAnimationFrame(ae),Ce&&Ce.disconnect()}},[y,ie,te,w,ze]),u.useEffect(()=>{const ce=y;if(!ce||typeof window>"u"||p.editMode!=="extension"||oe!=="ok"||ee.length===0){K(null);return}let q=0,se=0;const ae=ue=>{if(!ue)return!1;const ge=ue.getBoundingClientRect();return ge.width>0&&ge.height>0},be=ue=>{const ge=ce.querySelector(`[data-editor-path="${ue}"]`);if(ae(ge))return!0;const ke=ce.querySelectorAll(`[data-editor-path^="${ue}.children."]`);for(const he of Array.from(ke))if(ae(he))return!0;return!1},Ce=()=>{K(ee.some(be))};q=window.requestAnimationFrame(()=>{se=window.requestAnimationFrame(Ce)});let $e=null,U=0;return typeof MutationObserver<"u"&&($e=new MutationObserver(()=>{U||(U=window.requestAnimationFrame(()=>{U=0,Ce()}))}),$e.observe(ce,{childList:!0,subtree:!0})),()=>{window.cancelAnimationFrame(q),window.cancelAnimationFrame(se),U&&window.cancelAnimationFrame(U),$e&&$e.disconnect()}},[y,p.editMode,oe,ee,te,ze]),u.useEffect(()=>{if(typeof window>"u"||p.editMode!=="base")return;const ce=window.document,q="g7le-base-slot-style";if(ce.getElementById(q))return;const se=ce.createElement("style");se.id=q;const ae=D("layout_editor.preview.slot_area_label");return se.textContent=`.g7le-preview-frame [data-editor-slot]{position:relative;min-height:96px;outline:2px dashed #94a3b8;outline-offset:-2px;}.g7le-preview-frame [data-editor-slot]::after{content:'${ae.replace(/'/g,"\\'")} · ' attr(data-editor-slot);position:absolute;top:8px;left:50%;transform:translateX(-50%);font-size:12px;line-height:1;color:#64748b;background:rgba(241,245,249,0.92);border:1px solid #cbd5e1;border-radius:9999px;padding:4px 12px;pointer-events:none;white-space:nowrap;}`,ce.head.appendChild(se),()=>{ce.getElementById(q)?.remove()}},[p.editMode,D]),!(p.editMode==="extension"||p.editMode==="iteration_item")&&(p.selectedRoute?.layoutName===null||p.selectedRoute===null))return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--empty","data-testid":"g7le-preview-empty",style:or,children:D("layout_editor.preview.empty")});if(m)return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--loading","data-testid":"g7le-preview-loading",style:or,children:D("layout_editor.preview.loading")});if(h)return i.jsx(Ja,{error:h});if(T)return i.jsx(Ja,{error:T});if(!N||E===null||I===null)return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--assets-loading","data-testid":"g7le-preview-assets-loading",style:or,children:D("layout_editor.preview.assets_loading")});if(ie.length===0)return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--empty-layout","data-testid":"g7le-preview-empty-layout",style:or,children:D("layout_editor.preview.empty_layout")});const We=p.editMode==="extension"?oe==="no-injection"?"no-injection":oe==="ok"&&ee.length>0&&fe!==!0?"gated-no-state":null:null;return te?i.jsx("div",{className:"g7le-preview-canvas","data-testid":"g7le-preview-canvas",style:{overflow:"visible",background:"#f1f5f9",padding:24,display:"flex",justifyContent:"center",alignItems:"flex-start",minHeight:"calc(100vh - var(--g7le-header-h, 0px))",boxSizing:"border-box"},children:i.jsxs("div",{className:"g7le-preview-frame-wrapper","data-testid":"g7le-preview-frame-wrapper",style:{position:"relative",width:w,transform:`scale(${k})`,transformOrigin:"top center"},children:[i.jsx("div",{className:x==="dark"?"g7le-preview-frame g7le-preview-dark":"g7le-preview-frame","data-testid":"g7le-preview-frame","data-color-scheme":x,ref:ce=>{v.current=ce,_(ce)},style:{width:w,background:"#fff",border:"1px solid #cbd5e1",boxShadow:"0 1px 3px rgba(0,0,0,0.05)",minHeight:400,position:"relative",transform:"translateZ(0)",overflow:"hidden"},children:i.jsx(D7,{overrideWidth:w,children:ie.map((ce,q)=>i.jsx(T7,{componentDef:ce,dataContext:{...Xe,...kD(V),_global:SD(V),_computedDefinitions:Ve,...A?{_localInit:A,_local:{...ze._local??{},...V._local??{}}}:{},route:PD({...ze.route??{},...ve,path:p.selectedRoute?.path??""},Y),query:{...ze.query??{},...F??{}}},translationContext:{templateId:p.templateIdentifier,locale:p.locale},registry:E,bindingEngine:B.current,translationEngine:Pt.getInstance(),actionDispatcher:M.current,isEditMode:!0,isRootRenderer:q===0,componentPath:`${q}`,onComponentSelect:(se,ae)=>{},onComponentHover:(se,ae)=>{}},`${ce.id??`preview-${q}`}:t${Ne}${p.editMode==="extension"?`:s${te?1:0}`:""}`))})}),i.jsx("div",{className:"g7le-overlay-layer","data-testid":"g7le-overlay-layer",style:{position:"absolute",left:0,top:0,width:w,height:y?y.getBoundingClientRect().height/(k||1):"100%",overflow:"visible",pointerEvents:"none"},children:i.jsx(oD,{frameEl:y,manifest:t,nesting:n,componentPalette:o,spec:r,permissionCandidates:s,resolveRouteMatch:l,onNavigateToDestination:d,onSessionAddedPathsChange:c})}),We!==null&&i.jsx("div",{className:"g7le-preview-canvas--extension-fallback","data-testid":"g7le-preview-extension-fallback","data-fallback-reason":We,style:{position:"absolute",left:0,top:0,right:0,bottom:0,minHeight:y?y.getBoundingClientRect().height/(k||1):400,background:"#f1f5f9",display:"flex",alignItems:"flex-start",justifyContent:"center",padding:24,boxSizing:"border-box",pointerEvents:"auto",zIndex:50},children:i.jsxs("div",{className:"g7le-extension-fallback-card",style:{maxWidth:440,textAlign:"center",position:"sticky",top:"calc(40vh - var(--g7le-header-h, 0px))"},children:[i.jsx("p",{className:"g7le-extension-fallback-title",style:{fontWeight:600,marginBottom:8,color:"#0f172a"},children:D(We==="no-injection"?"layout_editor.preview.extension_no_injection_title":"layout_editor.preview.extension_gated_title")}),i.jsx("p",{className:"g7le-extension-fallback-desc",style:{color:"#475569",lineHeight:1.6},children:We==="no-injection"?D("layout_editor.preview.extension_no_injection_desc"):p.availableStates.length>1?D("layout_editor.preview.extension_gated_desc_with_states"):D("layout_editor.preview.extension_gated_desc")})]})})]})}):i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--scripts-loading","data-testid":"g7le-preview-scripts-loading",style:or,children:D("layout_editor.preview.loading")})}function MD(e,t,n){if(!e)return;if(!t)return e;const o=s=>{if(typeof s=="string"&&s.startsWith("$t:"))try{const a=s.slice(3),l=a.indexOf("|");if(l===-1)return t.translate(a,n);const d=a.slice(0,l),c=a.slice(l);return t.translate(d,n,c)}catch{return s}return Array.isArray(s)?s.map(o):s},r={};for(const[s,a]of Object.entries(e))r[s]=o(a);return r}function LD(e,t){const n=[],o=(r,s)=>{Array.isArray(r)&&r.forEach((a,l)=>{if(!a||typeof a!="object")return;const d=s?`${s}.children.${l}`:`${l}`,c=a.__source;if(c?.kind==="extension"&&c.extensionId===t){n.push(d);return}Array.isArray(a.children)&&o(a.children,d)})};return o(e,""),n}function PD(e,t){if(!t)return e;const n={...e};for(const[o,r]of Object.entries(t))r===null?delete n[o]:n[o]=r;return n}const or={flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"#f1f5f9",color:"#64748b",fontSize:13},OD={desktop:"layout_editor.device.desktop",tablet:"layout_editor.device.tablet",mobile:"layout_editor.device.mobile",portable:"layout_editor.device.portable"};function BD(){const{device:e,zoom:t,customWidth:n,setDevice:o,setZoom:r,setCustomWidth:s,colorScheme:a,setColorScheme:l}=Ga(),{t:d}=et(),c=cg();return i.jsxs("div",{className:"g7le-device-toolbar","data-testid":"g7le-device-toolbar",style:{display:"inline-flex",alignItems:"center",gap:8,padding:"4px 8px",background:"#fff",border:"1px solid #cbd5e1",borderRadius:6},children:[i.jsxs("div",{role:"group","aria-label":d("layout_editor.device.group_label"),children:[c.map(p=>{const f=e===p,b=OD[p],g=b?d(b):p;return i.jsx("button",{type:"button","data-testid":`g7le-device-${p}`,"aria-pressed":f,onClick:()=>o(p),style:{padding:"2px 8px",marginRight:2,fontSize:12,cursor:"pointer",background:f?"#0f172a":"#f8fafc",color:f?"#fff":"#0f172a",border:"1px solid #cbd5e1",borderRadius:4},children:g},p)}),(()=>{const p=e==="custom";return i.jsx("button",{type:"button","data-testid":"g7le-device-custom","aria-pressed":p,onClick:()=>o("custom"),style:{padding:"2px 8px",marginRight:2,fontSize:12,cursor:"pointer",background:p?"#0f172a":"#f8fafc",color:p?"#fff":"#0f172a",border:"1px solid #cbd5e1",borderRadius:4},children:d("layout_editor.device.custom")})})()]}),e==="custom"&&i.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[i.jsx("label",{htmlFor:"g7le-custom-width-input",style:{fontSize:11,color:"#475569"},children:d("layout_editor.device.custom_width_label")}),i.jsx("input",{id:"g7le-custom-width-input",type:"number",min:Ag,max:Tg,step:10,value:n,"data-testid":"g7le-custom-width-input","aria-label":d("layout_editor.device.custom_width_label"),onChange:p=>{const f=parseInt(p.currentTarget.value,10);Number.isFinite(f)&&s(f)},style:{width:72,padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:4}}),i.jsx("span",{style:{fontSize:11,color:"#475569"},children:"px"})]}),i.jsx("div",{role:"group","aria-label":d("layout_editor.toolbar.color_scheme_group"),style:{display:"inline-flex",gap:2},children:["light","dark"].map(p=>{const f=a===p;return i.jsx("button",{type:"button","data-testid":`g7le-toolbar-scheme-${p}`,"aria-pressed":f,onClick:()=>l(p),style:{padding:"2px 8px",fontSize:12,cursor:"pointer",background:f?"#0f172a":"#f8fafc",color:f?"#fff":"#0f172a",border:"1px solid #cbd5e1",borderRadius:4},children:d(p==="light"?"layout_editor.toolbar.color_scheme_light":"layout_editor.toolbar.color_scheme_dark")},p)})}),i.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[i.jsx("span",{style:{fontSize:11,color:"#475569"},children:d("layout_editor.zoom.label")}),i.jsx("input",{type:"range",min:.5,max:1,step:.05,value:t,"data-testid":"g7le-zoom-slider","aria-label":d("layout_editor.zoom.aria_label"),onChange:p=>r(parseFloat(p.currentTarget.value)),style:{width:100}}),i.jsxs("span",{style:{fontSize:11,color:"#475569",minWidth:36,textAlign:"right"},children:[Math.round(t*100),"%"]})]}),i.jsx(fm,{})]})}function WD(){const{t:e}=et(),{state:t,dispatch:n}=Qe(),{availableStates:o,activeStateId:r}=t,[,s]=u.useState(0);u.useEffect(()=>{if(typeof window>"u")return;const p=()=>s(b=>b+1),f=window.requestAnimationFrame(p);return window.addEventListener(tl,p),()=>{window.cancelAnimationFrame(f),window.removeEventListener(tl,p)}},[]);const a=u.useCallback((p,f)=>{if(!p)return f;if(!p.startsWith("$t:"))return p;const b=p.slice(3),g=window.G7Core;if(g&&typeof g.t=="function"){const h=g.t(b);if(h&&h!==b&&!h.startsWith("$t:"))return h}const m=e(b);return m&&m!==b?m:f},[e]);if(!Array.isArray(o)||o.length<=1)return null;const l=p=>{const f=p.target.value;n({type:"SET_ACTIVE_STATE",activeStateId:f}),Ml({kind:"change",activeStateId:f,routePath:t.selectedRoute?.path??null,availableCount:o.length})},d=o.find(p=>p.id===r)??o[0],c=d?.description?a(d.description,""):"";return i.jsxs("div",{className:"g7le-state-switcher","data-testid":"g7le-state-switcher","data-active-state":r??"",style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 8px",background:"#fff",border:"1px solid #cbd5e1",borderRadius:6},children:[i.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#475569",whiteSpace:"nowrap"},children:e("layout_editor.toolbar.state")}),i.jsx("select",{"data-testid":"g7le-state-switcher-select","aria-label":e("layout_editor.toolbar.state"),value:r??o[0].id,onChange:l,style:{fontSize:12,padding:"2px 6px",border:"1px solid #cbd5e1",borderRadius:4,background:"#fff",color:"#0f172a",cursor:"pointer",outline:"none"},children:o.map(p=>i.jsx("option",{value:p.id,children:a(p.label,p.id)},p.id))}),c&&i.jsx("span",{"data-testid":"g7le-state-switcher-description",style:{fontSize:11,color:"#94a3b8",whiteSpace:"nowrap"},children:c})]})}function jD(e,t,n){if(e==="extension"){if(typeof n=="string"&&n.length>0){const o=nl(n,"__base__/");return o?{kind:"base",match:o}:{kind:"route",match:n}}return null}if(!t)return null;switch(e){case"route":return{kind:"route",match:t};case"base":{const o=nl(t,"__base__/");return o?{kind:"base",match:o}:null}case"modal":{const o=nl(t,"__modal__/");return o?{kind:"modal",match:o}:null}default:return null}}function HD(e,t){if(!t||!Array.isArray(e)||e.length===0)return[];const n=[];for(const o of e)if(KD(o.scope,t))for(const r of o.items??[])r&&typeof r.id=="string"&&r.id.length>0&&n.push(r);return n}function FD(e){if(e.length===0)return null;const t=e.find(n=>n.default===!0);return t?t.id:e[0].id}function KD(e,t){if(!e||e.kind!==t.kind)return!1;const n=e.match;return typeof n!="string"||n.length===0?!1:t.kind==="route"?VD(t.match,n):n===t.match}function VD(e,t){if(t===e)return!0;if(!t.includes("*"))return!1;const n=t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\/\*\\\?/g,"(?:/[^/]+)?").replace(/\*/g,"[^/]+");return new RegExp(`^${n}$`).test(e)}function nl(e,t){return e.startsWith(t)?e.slice(t.length):""}const UD="__conngroup__/modals/",qD="__conngroup__/extensions/";function GD(e){return e.meta?.editor_label?{label:e.meta.editor_label,labelSource:"editor_label"}:e.meta?.title?{label:e.meta.title,labelSource:"title"}:{label:e.path,labelSource:"path"}}function YD(e){switch(e.source.kind){case"template":return"template";case"module":return`module:${e.source.identifier??""}`;case"plugin":return`plugin:${e.source.identifier??""}`;case"core":return null;default:return null}}function XD(e,t){if(e.meta?.parent&&t.has(e.meta.parent))return e.meta.parent;const n=e.path.split("/").filter(Boolean);for(let o=n.length-1;o>=1;o--){const r="/"+n.slice(0,o).join("/");if(r!==e.path&&t.has(r))return r}return null}function JD(e){const t=new Map;for(const n of e)n.layout&&t.set(n.layout,(t.get(n.layout)??0)+1);return t}function ZD(e){const t=new Map;for(const n of e){if(!n.hostLayout)continue;const o=t.get(n.hostLayout)??[];o.push(n),t.set(n.hostLayout,o)}return t}function QD(e){const t=new Map;for(const n of e)for(const o of n.extensions)for(const r of o.hostLayouts??[]){if(!r)continue;const s=t.get(r)??[];s.push({extension:o,group:n}),t.set(r,s)}return t}function RD(e,t){return{path:`__modal__/${e.hostLayout}/${e.modalId}`,layoutName:e.hostLayout,label:e.label??e.modalId,labelSource:e.label?"editor_label":"path",source:{kind:"core",identifier:null},kind:"modal",modalId:e.modalId,modalHostLayout:e.hostLayout,connectedHostRoutePath:t,children:[]}}function e8(e,t){const{extension:n,group:o}=e,r=o.sourceType==="plugin"?"🔌":"🧩";return{path:`__extension__/${n.id}`,layoutName:null,label:`${r} ${o.sourceLabel} · ${n.targetName}`,labelSource:"path",source:{kind:o.sourceType,identifier:o.sourceIdentifier},kind:"extension",extensionId:String(n.id),extensionType:n.extensionType,extensionPriority:n.priority,extensionTargetName:n.targetName,isModified:n.isModified,isInactive:!n.isActive,connectedHostRoutePath:t,children:[]}}function Fg(e,t,n){if(e.kind!=="route"&&e.kind!=="base"||!e.layoutName)return;const o=[],r=t.get(e.layoutName)??[];r.length>0&&o.push({path:`${UD}${e.path}`,layoutName:null,label:`$t:layout_editor.chrome.route_tree.connected.modals|count=${r.length}`,labelSource:"editor_label",source:{kind:"core",identifier:null},kind:"route",children:r.map(a=>RD(a,e.path))});const s=n.get(e.layoutName)??[];s.length>0&&o.push({path:`${qD}${e.path}`,layoutName:null,label:`$t:layout_editor.chrome.route_tree.connected.extensions|count=${s.length}`,labelSource:"editor_label",source:{kind:"core",identifier:null},kind:"route",children:s.map(a=>e8(a,e.path))}),o.length>0&&(e.children=[...o,...e.children??[]])}function t8(e){const t=[],n=new Set(e.routes.map(o=>o.path));for(const o of e.routes){const r=YD(o);if(!r)continue;const{label:s,labelSource:a}=GD(o),l=XD(o,n),d={path:o.path,layoutName:o.layout??null,label:s,labelSource:a,icon:o.meta?.icon??null,source:o.source,isRedirect:!!o.redirect,isHidden:!!o.meta?.hidden,kind:"route",children:[]};t.push({node:d,parentKey:l,groupKey:r})}return t}function n8(e,t){if(e==="template")return"$t:layout_editor.chrome.route_tree.group.template";if(e.startsWith("module:")){const n=e.slice(7);return`$t:layout_editor.chrome.route_tree.group.module|name=${t.moduleDisplayNames[n]??n}`}if(e.startsWith("plugin:")){const n=e.slice(7);return`$t:layout_editor.chrome.route_tree.group.plugin|name=${t.pluginDisplayNames[n]??n}`}return e}function o8(e,t){JD(e.routes);const n=ZD(e.modals),o=QD(e.extensionGroups??[]),r=new Map;for(const d of t)r.has(d.groupKey)||r.set(d.groupKey,[]),r.get(d.groupKey).push(d);const s=Array.from(r.keys()).sort((d,c)=>{const p=g=>g==="template"?1:g.startsWith("module:")?2:g.startsWith("plugin:")?3:4,f=p(d),b=p(c);return f!==b?f-b:d.localeCompare(c)}),a=[];if(e.baseLayouts.length>0){const d=e.baseLayouts.map(c=>({path:`__base__/${c.layoutName}`,layoutName:c.layoutName,label:c.label??c.layoutName,labelSource:c.label?"editor_label":"path",source:{kind:"core",identifier:null},kind:"base",children:[]}));for(const c of d)Fg(c,n,o);a.push({path:"__group__/base",layoutName:null,label:"$t:layout_editor.chrome.route_tree.group.base",labelSource:"editor_label",source:{kind:"core",identifier:null},kind:"route",children:d})}for(const d of s){const c=r.get(d),p=new Map;for(const b of c)p.set(b.node.path,b);const f=[];for(const b of c)if(b.parentKey&&p.has(b.parentKey)){const g=p.get(b.parentKey);g.node.children=g.node.children??[],g.node.children.push(b.node)}else f.push(b.node);for(const b of c)Fg(b.node,n,o);a.push({path:`__group__/${d}`,layoutName:null,label:n8(d,e),labelSource:"editor_label",source:{kind:"core",identifier:null},kind:"route",children:f})}if(e.modals.length>0){const d=e.modals.map(c=>({path:`__modal__/${c.hostLayout}/${c.modalId}`,layoutName:c.hostLayout,label:c.label??c.modalId,labelSource:c.label?"editor_label":"path",source:{kind:"core",identifier:null},kind:"modal",modalId:c.modalId,modalHostLayout:c.hostLayout,children:[]}));a.push({path:"__group__/modal",layoutName:null,label:"$t:layout_editor.chrome.route_tree.group.modal",labelSource:"editor_label",source:{kind:"core",identifier:null},kind:"route",children:d})}const l=e.extensionGroups??[];if(l.length>0){const d=l.map(c=>{const p=c.sourceType==="plugin"?"🔌":"🧩",f=c.extensions.map(b=>({path:`__extension__/${b.id}`,layoutName:null,label:`${c.sourceLabel} · ${b.targetName}`,labelSource:"path",source:{kind:c.sourceType,identifier:c.sourceIdentifier},kind:"extension",extensionId:String(b.id),extensionType:b.extensionType,extensionPriority:b.priority,extensionTargetName:b.targetName,isModified:b.isModified,isInactive:!b.isActive,children:[]}));return{path:`__extgroup__/${c.sourceType}/${c.sourceIdentifier}`,layoutName:null,label:`${p} ${c.sourceLabel}`,labelSource:"path",source:{kind:c.sourceType,identifier:c.sourceIdentifier},kind:"route",children:f}});a.push({path:"__group__/extension",layoutName:null,label:"$t:layout_editor.chrome.route_tree.group.extension",labelSource:"editor_label",source:{kind:"core",identifier:null},kind:"route",children:d})}return a}function r8(e){const t=t8(e);return o8(e,t)}const Wn=_o("useEditorRoutes");function i8(e,t){if(typeof e=="string")return e.length>0?e:null;if(e&&typeof e=="object"){const n=e[t];if(typeof n=="string"&&n.length>0)return n;if(typeof e.en=="string"&&e.en.length>0)return e.en;for(const o of Object.values(e))if(typeof o=="string"&&o.length>0)return o}return null}function Kg(e,t){const n={};if(typeof window>"u")return n;const r=window.G7Config?.[e];if(!Array.isArray(r))return n;for(const s of r)s&&typeof s.identifier=="string"&&(n[s.identifier]=i8(s.display_name,t)??s.identifier);return n}function s8(e){const t=new Ed,n=typeof window<"u"?window.G7Config:void 0,o={_global:{settings:n?.settings??{},plugins:n?.plugins??{},modules:n?.modules??{},appConfig:n?.appConfig??{}}};return e.map(r=>{const s={...r};if(typeof s.path=="string"&&s.path.includes("{{")){const a=s.path;let l=t.resolveBindings(s.path,o);l=l.replace(/\/\/+/g,"/")||"/",l.includes("{{")&&(Wn.warn("편집기 route path 표현식 평가 실패 — fallback 적용",{originalPath:a}),l=a.replace(/\{\{[^}]+\}\}/g,"").replace(/\/\/+/g,"/")||"/"),s.path=l}if(typeof s.redirect=="string"&&s.redirect.includes("{{")){const a=s.redirect;let l=t.resolveBindings(a,o);l=l.replace(/\/\/+/g,"/")||"/",l.includes("{{")&&(Wn.warn("편집기 route redirect 표현식 평가 실패 — fallback 적용",{originalRedirect:a}),l=a.replace(/\{\{[^}]+\}\}/g,"").replace(/\/\/+/g,"/")||"/"),s.redirect=l}return s})}function a8(e){const{dispatch:t}=Qe(),{translationEngine:n,translationContext:o}=et(),{templateIdentifier:r,cacheVersion:s}=e;u.useEffect(()=>{let a=!1;const l=s??(typeof window<"u"?window.G7Config?.cache_version:void 0)??"",d=l!==""?`?v=${encodeURIComponent(String(l))}`:"",c=nn(`/api/admin/templates/${encodeURIComponent(r)}/editor/routes`,"json",null,d.replace(/^[?&]+/,"")),p=o?.locale??"ko",f=n&&r!==o?.templateId?n.loadTranslations(r,p).then(()=>{Wn.log("편집 대상 lang 로드 완료",{targetTemplate:r,locale:p})}).catch(h=>{Wn.warn("편집 대상 lang 로드 실패 — 라우트 라벨 fallback 사용",h)}):Promise.resolve(),b=(()=>{if(typeof fetch!="function")return Promise.reject(lo(new Error("fetch unavailable"),"routes"));try{const h=fetch(c,{credentials:"same-origin",headers:Me()});return!h||typeof h.then!="function"?Promise.reject(lo(new Error("fetch returned non-Promise (test stub?)"),"routes")):h.then(async v=>{if(!v.ok){const y=await v.json().catch(()=>null);throw ei(v.status,y,"routes")}return v.json()})}catch(h){return Promise.reject(h)}})(),g=`/api/admin/templates/${encodeURIComponent(r)}/layout-extensions${d}`,m=(()=>{if(typeof fetch!="function")return Promise.resolve(null);try{const h=fetch(g,{credentials:"same-origin",headers:Me()});return!h||typeof h.then!="function"?Promise.resolve(null):h.then(async v=>v.ok?await v.json():null).catch(()=>null)}catch{return Promise.resolve(null)}})();return Promise.all([b,f,m]).then(([h,,v])=>{if(a)return;if(!h||!h.success||!Array.isArray(h.data?.routes)){Wn.warn("routes 응답 형식이 비정상 — empty tree 로 둠",h),t({type:"SET_ROUTES_ERROR",error:{kind:"unknown",status:200,message:"routes 응답 형식이 비정상입니다.",source:"routes"}});return}const y=s8(h.data.routes),_=Kg("activeModules",p),w=Kg("activePlugins",p),k=(h.data.base_layouts??[]).map(I=>({layoutName:I.layout_name,label:I.label??void 0})),x=(h.data.modals??[]).map(I=>({modalId:I.modal_id,hostLayout:I.host_layout,label:I.label??void 0})),$=(v?.success&&Array.isArray(v.data)?v.data:[]).map(I=>({sourceIdentifier:I.source_identifier,sourceType:I.source_type,sourceLabel:I.source_label,extensions:(I.extensions??[]).map(N=>({id:N.id,extensionType:N.extension_type,targetName:N.target_name,priority:N.priority,isActive:N.is_active,isModified:N.is_modified,hostLayouts:Array.isArray(N.host_layouts)?N.host_layouts:[],currentVersion:typeof N.current_version=="number"?N.current_version:void 0}))})),C=r8({routes:y,modals:x,baseLayouts:k,extensionGroups:$,moduleDisplayNames:_,pluginDisplayNames:w});t({type:"SET_ROUTE_TREE",tree:C});const S=h.data.layout_versions,D={};if(S&&typeof S=="object"&&!Array.isArray(S))for(const[I,N]of Object.entries(S))typeof N=="number"&&Number.isFinite(N)&&(D[I]=N);t({type:"SET_LAYOUT_VERSIONS",versions:D});const E={};for(const I of $)for(const N of I.extensions){const T=N.currentVersion;typeof T=="number"&&Number.isFinite(T)&&(E[String(N.id)]=T)}t({type:"SET_EXTENSION_VERSIONS",versions:E}),Wn.log("routes 로드 완료",{count:y.length,groups:C.length})}).catch(h=>{if(a)return;Wn.error("routes 로드 실패",h);const v=Ep(h)?h:lo(h,"routes");t({type:"SET_ROUTES_ERROR",error:v})}),()=>{a=!0}},[r,s,t,n,o?.locale,o?.templateId])}function Vg(e,t,n,o=[]){const r=t?Ug(o,t):null,s=r!==null?{path:r.path,layoutName:r.layoutName}:void 0;if(e.startsWith("__base__/")){const a=e.slice(9);if(a)return n({type:"ENTER_BASE_EDIT",layoutName:a,returnRoute:s}),!0}else if(e.startsWith("__modal__/")){const a=e.slice(10);return a&&!a.includes("/")&&t?(n({type:"ENTER_MODAL_EDIT",modalId:a,hostLayout:t,returnRoute:s}),!0):!1}else if(e.startsWith("__extension__/")){const a=e.slice(14);if(a&&!a.includes("/"))return n({type:"ENTER_EXTENSION_EDIT",extensionId:a,returnRoute:s}),!0}else if(e.startsWith("__iteration__/")){const a=e.slice(14);return a&&t?(n({type:"ENTER_ITERATION_ITEM_EDIT",sourcePath:a,hostLayout:t,returnRoute:s}),!0):!1}return!1}function Ug(e,t){for(const n of e){if(n.kind==="route"&&n.layoutName===t)return n;if(n.children&&n.children.length>0){const o=Ug(n.children,t);if(o)return o}}return null}function ol(e,t){for(const n of e){if(n.kind==="route"&&n.path===t)return n;if(n.children&&n.children.length>0){const o=ol(n.children,t);if(o)return o}}return null}function l8(e){const{state:t,dispatch:n}=Qe(),o=u.useRef(!1),r=u.useRef(t.editMode);r.current=t.editMode,u.useEffect(()=>{if(o.current||t.routeTree.length===0||typeof window>"u")return;const a=vp(window.location.search);if(a){const c=mp(window.location.search),p=Vg(a,c,n,t.routeTree);if(o.current=!0,p)return}const l=bp(window.location.search);if(!l){o.current=!0;return}const d=ol(t.routeTree,l);d&&n({type:"SELECT_ROUTE",route:{path:d.path,layoutName:d.layoutName}}),o.current=!0},[t.routeTree,n]),u.useEffect(()=>{if(typeof window>"u")return;const a=()=>{const l=vp(window.location.search);if(l){const p=mp(window.location.search);if(Vg(l,p,n,t.routeTree))return}if(r.current!=="route")switch(r.current){case"base":n({type:"EXIT_BASE_EDIT"});return;case"modal":n({type:"EXIT_MODAL_EDIT"});return;case"extension":n({type:"EXIT_EXTENSION_EDIT"});return;case"iteration_item":n({type:"EXIT_ITERATION_ITEM_EDIT"});return}const d=bp(window.location.search);if(!d){n({type:"SELECT_ROUTE",route:null});return}const c=ol(t.routeTree,d);c&&n({type:"SELECT_ROUTE",route:{path:c.path,layoutName:c.layoutName}})};return window.addEventListener("popstate",a),()=>{window.removeEventListener("popstate",a)}},[t.routeTree,n]);const s=u.useRef("route");u.useEffect(()=>{if(typeof window>"u"||!window.history?.replaceState||t.routeTree.length===0)return;const a=ia(e,t.selectedRoute?.path??null,t.selectedRoute?.layoutName??null),l=`${window.location.pathname}${window.location.search}`,d=s.current;if(s.current=t.editMode,l===a)return;d==="route"&&t.editMode!=="route"&&window.history.pushState?window.history.pushState(window.history.state,"",a):window.history.replaceState(window.history.state,"",a)},[t.selectedRoute,t.editMode,t.routeTree,e])}function d8(){u.useEffect(()=>{if(typeof document>"u")return;const e=document.documentElement;let t=e.classList.contains("dark");const n=()=>{e.classList.contains("dark")&&(t=!0,e.classList.remove("dark"))};n();let o=null;return typeof MutationObserver<"u"&&(o=new MutationObserver(n),o.observe(e,{attributes:!0,attributeFilter:["class"]})),()=>{o?.disconnect(),t&&e.classList.add("dark")}},[])}function c8(){u.useEffect(()=>{if(typeof document>"u"||!document.body)return;const e=document.body,t=()=>{e.style.overflow==="hidden"&&(e.style.overflow=""),e.style.overflowY==="hidden"&&(e.style.overflowY="")};t();let n=null;return typeof MutationObserver<"u"&&(n=new MutationObserver(t),n.observe(e,{attributes:!0,attributeFilter:["style"]})),()=>{n?.disconnect()}},[])}function u8(e){if(typeof e!="string")return null;const t="__extension__/";if(!e.startsWith(t))return null;const n=e.slice(t.length);return n===""||n.includes("/")?null:n}function p8(e){if(Array.isArray(e.components))return e.components;if(Array.isArray(e.injections)){const t=[];return e.injections.forEach((n,o)=>{if(n&&Array.isArray(n.components))for(const r of n.components)t.push({...r,__injectionIndex:o})}),t}return[]}function f8(e,t){if(Array.isArray(e.components)){const n=t.map(o=>rl(o));return{...e,components:n}}if(Array.isArray(e.injections)){const n=e.injections.map(o=>({...o}));n.forEach(o=>{Array.isArray(o.components)&&(o.components=[])});for(const o of t){const r=o.__injectionIndex,s=typeof r=="number"&&r>=0&&rrl(n))),t}function qg(e,t){const n=[],o=r=>{if(Array.isArray(r))for(const s of r){if(!s||typeof s!="object")continue;const a=s.__source;if(a?.kind==="extension"&&a.extensionId===t){n.push(s);continue}Array.isArray(s.children)&&o(s.children)}};return o(e),n}function Gg(e,t){const o=qg(e,t)[0]?.__source;return o&&o.kind==="extension"&&o.extensionId===t?o:{kind:"extension",extensionId:t}}function il(e,t){for(const n of e){const o=n?.__source;if(o?.kind==="extension"&&o.extensionId===t||Array.isArray(n.children)&&il(n.children,t))return!0}return!1}function g8(){const{state:e}=Qe(),t=e.templateIdentifier,n=e.editMode==="extension"?u8(e.selectedRoute?.path):null,o=e.editMode==="extension"&&typeof e.selectedRoute?.layoutName=="string"?e.selectedRoute.layoutName:null,[r,s]=u.useState(null),[a,l]=u.useState(!1),[d,c]=u.useState(null),[p,f]=u.useState(!1),[b,g]=u.useState(0),[m,h]=u.useState(null),v=u.useRef({}),y=u.useRef({kind:"extension",extensionId:0}),_=u.useRef(null);u.useEffect(()=>{_.current=r},[r]),u.useEffect(()=>{h(null)},[n]);const w=u.useCallback(async I=>{const N=window.G7Config?.cache_version??0,T=nn(`/api/layouts/${encodeURIComponent(t)}/${I}`,"json",`${N}.${Op()}`,"with_source_meta=1"),B=fr(),M={Accept:"application/json"};B&&(M.Authorization=`Bearer ${B}`);const O=await fetch(T,{headers:M,credentials:"same-origin"});if(!O.ok)return null;const z=await O.json().catch(()=>null);return(z&&(z.data||z))??{}},[t]),k=u.useCallback(async()=>{if(!n){s(null),c(null),f(!1);return}l(!0),c(null);try{const I=window.G7Config?.cache_version??0,N=`/api/admin/templates/${encodeURIComponent(t)}/layout-extensions/${encodeURIComponent(n)}?v=${I}`,T=await fetch(N,{headers:Me(),credentials:"same-origin"}),B=await T.json().catch(()=>null);if(!T.ok){c(ei(T.status,B,"layout")),s(null),f(!1);return}const M=(B&&(B.data||B))??{};let O={};const z=M.content;if(typeof z=="string")try{O=JSON.parse(z)}catch{O={}}else z&&typeof z=="object"&&(O=z);const H=M.extension_type==="overlay"?"overlay":"extension_point",P=typeof M.lock_version=="number"?M.lock_version:0,A=Array.isArray(M?.host_layouts)?M.host_layouts.filter(oe=>typeof oe=="string"):[],L=o??(A.length===1?A[0]:m&&A.includes(m)?m:null),F=Number(n);v.current=O;let V=p8(O),X={},Z="pending";const ie={kind:"extension",extensionId:F};if(y.current=ie,L){const oe=await w(L);if(oe){X=oe;const G=Array.isArray(oe.components)?oe.components:[],ee=Gg(G,F);if(y.current=ee,il(G,F))V=G,Z="ok";else{const K=(Array.isArray(oe.modals)?oe.modals:[]).filter(te=>te&&typeof te=="object"&&il([te],F));if(K.length>0){const te=K.map(ye=>({...ye,props:{...ye.props??{},isOpen:!0}}));V=[...G,...te],y.current=Gg(K,F),Z="ok"}else V=G,Z="no-injection"}}}s({extensionId:F,content:O,extensionType:H,components:V,lockVersion:P,hostLayouts:A,hostLayoutName:L,hostRaw:X,editability:Z}),f(!1),st({op:"load",layoutName:`extension:${n}`,editMode:"extension",statusCode:T.status,timestamp:Date.now()})}catch(I){c(lo(I,"layout")),s(null),f(!1)}finally{l(!1)}},[t,n,m,o,w]);u.useEffect(()=>{k()},[k]);const x=u.useCallback(I=>{h(I)},[]),$=u.useCallback(I=>{s(N=>N&&{...N,components:I}),f(!0),st({op:"patch",layoutName:`extension:${_.current?.extensionId??""}`,editMode:"extension",isDirty:!0,timestamp:Date.now()})},[]),C=u.useCallback(I=>{s(N=>N&&{...N,components:I(N.components)}),f(!0)},[]),S=u.useCallback(async()=>{const I=_.current;if(!I)return{kind:"guard_no_document"};const N=`/api/admin/templates/${encodeURIComponent(t)}/layout-extensions/${I.extensionId}`,T=qg(I.components,I.extensionId),B=T.length>0?T:I.components,M=f8(v.current,B);st({op:"save",layoutName:`extension:${I.extensionId}`,editMode:"extension",saveTarget:"layout_extension",endpoint:N,isDirty:p,timestamp:Date.now()});let O;try{O=await fetch(N,{method:"PUT",headers:Me({"Content-Type":"application/json"}),credentials:"same-origin",body:JSON.stringify({content:M,expected_lock_version:I.lockVersion})})}catch(H){return{kind:"network_error",message:H instanceof Error?H.message:"network error"}}const z=await O.json().catch(()=>null);if(st({op:"save_response",layoutName:`extension:${I.extensionId}`,editMode:"extension",endpoint:N,statusCode:O.status,conflict:O.status===409?{currentVersion:z?.errors?.current_version??z?.current_version,yourVersion:z?.errors?.your_version??z?.your_version}:void 0,timestamp:Date.now()}),O.ok){const H=z?.data??{},P=typeof H.lock_version=="number"?H.lock_version:I.lockVersion+1;s(L=>L&&{...L,lockVersion:P}),f(!1),g(L=>L+1);const A=typeof H.current_version=="number"?H.current_version:void 0;return{kind:"success",newLockVersion:P,newContentVersion:A,savedExtensionId:String(I.extensionId)}}return O.status===409?{kind:"concurrent_modification",currentVersion:z?.current_version??-1,yourVersion:z?.your_version??I.lockVersion}:O.status===422?{kind:"validation_failed",status:422,errors:z?.errors??null}:{kind:"network_error",message:z?.message??`HTTP ${O.status}`}},[t,p]),D=u.useCallback(async()=>{ca(),await k()},[k]),E=!!r&&r.hostLayouts.length>1&&r.hostLayoutName===null;return{document:r,isLoading:a,error:d,isDirty:p,saveSuccessCounter:b,setLayoutComponents:$,patchLayout:C,save:S,reload:D,needsHostPicker:E,selectHost:x}}const Yg=new Set;function h8(e,t,n){const r=e&&Object.keys(e).length>0?e:t,s=Array.isArray(r.data_sources)?r.data_sources:[],a=Array.isArray(t.data_sources)?t.data_sources:[],l=new Set,d=[];for(const c of[...s,...a]){const p=c&&typeof c=="object"?c.id:void 0,f=typeof p=="string"?p:`__anon_${d.length}`;l.has(f)||(l.add(f),d.push(c))}return{...r,components:n,...d.length>0?{data_sources:d}:{},lock_version:void 0}}function y8(e){return{document:e.document?{layoutName:`extension:${e.document.extensionId}`,raw:{...h8(e.document.hostRaw,e.document.content,e.document.components),__editability:e.document.editability,__extensionId:e.document.extensionId},lockVersion:e.document.lockVersion}:null,isLoading:e.isLoading,error:e.error,isDirty:e.isDirty,saveSuccessCounter:e.saveSuccessCounter,reload:e.reload,patchLayout:e.patchLayout,setLayoutComponents:e.setLayoutComponents,patchDocumentRaw:()=>{},dirtyKeys:Yg,dirtyLayoutNames:Yg,invalidateCurrentCache:()=>{},reloadCounter:0,save:()=>e.save(),markDirty:()=>{}}}function b8({hostLayouts:e,extensionLabel:t,onSelect:n}){const{t:o}=et();return i.jsx("div",{className:"g7le-host-picker__backdrop","data-testid":"g7le-host-picker",role:"dialog","aria-modal":"true","aria-label":o("layout_editor.host_picker.title"),style:{position:"fixed",inset:0,zIndex:9500,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(15, 23, 42, 0.55)"},children:i.jsxs("div",{className:"g7le-host-picker__panel",style:{width:"min(520px, 92vw)",maxHeight:"80vh",overflow:"auto",background:"#ffffff",color:"#0f172a",borderRadius:12,boxShadow:"0 20px 48px rgba(15, 23, 42, 0.28)",padding:"20px 22px"},children:[i.jsx("h2",{className:"g7le-host-picker__title",style:{margin:"0 0 6px",fontSize:16,fontWeight:700},children:o("layout_editor.host_picker.title")}),i.jsx("p",{className:"g7le-host-picker__desc",style:{margin:"0 0 16px",fontSize:13,color:"#475569",lineHeight:1.6},children:t?o("layout_editor.host_picker.description_with_label",{label:t}):o("layout_editor.host_picker.description")}),i.jsx("ul",{className:"g7le-host-picker__list",style:{listStyle:"none",margin:0,padding:0,display:"grid",gap:8},children:e.map(r=>i.jsx("li",{children:i.jsxs("button",{type:"button",className:"g7le-host-picker__item","data-testid":"g7le-host-picker-item","data-host":r,onClick:()=>n(r),style:{width:"100%",textAlign:"left",padding:"12px 14px",border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc",cursor:"pointer",fontSize:13,fontWeight:600,color:"#0f172a",display:"flex",alignItems:"center",gap:8},children:[i.jsx("span",{"aria-hidden":!0,style:{fontSize:14},children:"🖼"}),i.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:r}),i.jsx("span",{"aria-hidden":!0,style:{color:"#94a3b8"},children:"→"})]})},r))})]})})}function m8(e,t){const[n,o]=u.useState(!1),[r,s]=u.useState(null),a=u.useCallback(async l=>{if(!t||!l)return{kind:"no_document"};o(!0),s(null);try{const d=ko(l),c=`/api/admin/templates/${encodeURIComponent(e)}/layouts/${t}/preview`,p=await fetch(c,{method:"POST",credentials:"same-origin",headers:Me({"Content-Type":"application/json"}),body:JSON.stringify({content:JSON.stringify(d)})}),f=await p.json().catch(()=>null);if(!p.ok){const h=f?.message??`HTTP ${p.status}`;return s(h),{kind:"network_error",message:h}}const b=f?.data,g=typeof b?.token=="string"?b.token:"",m=typeof b?.preview_url=="string"&&b.preview_url?b.preview_url:g?`/preview/${g}`:"";return m?(window.G7Core?.dispatch?.({handler:"openWindow",params:{path:m}}),{kind:"success",previewUrl:m,token:g}):(s("invalid preview response"),{kind:"network_error",message:"invalid preview response"})}catch(d){const c=d instanceof Error?d.message:"network error";return s(c),{kind:"network_error",message:c}}finally{o(!1)}},[e,t]);return{isCreating:n,error:r,createPreview:a}}const re="layout_editor.action_recipe",vn={setState:{label:`$t:${re}.set_state.label`,params:[{key:"target",label:`$t:${re}.set_state.param_target`,widget:"select",options:[{value:"local"},{value:"global"}]},{key:"state",label:`$t:${re}.set_state.param_state`,widget:"state-key-value"},{key:"merge",label:`$t:${re}.set_state.param_merge`,widget:"toggle"}],build:{handler:"setState",params:{target:"{{target}}",merge:"{{merge}}","...":"{{state}}"}}},loadFromLocalStorage:{label:`$t:${re}.load_local.label`,params:[{key:"key",label:`$t:${re}.load_local.param_key`,widget:"text",required:!0},{key:"stateKey",label:`$t:${re}.load_local.param_state_key`,widget:"state-key-picker"},{key:"defaultValue",label:`$t:${re}.load_local.param_default`,widget:"text"}],build:{handler:"loadFromLocalStorage",params:{key:"{{key}}",stateKey:"{{stateKey}}",defaultValue:"{{defaultValue}}"}}},saveToLocalStorage:{label:`$t:${re}.save_local.label`,params:[{key:"key",label:`$t:${re}.save_local.param_key`,widget:"text",required:!0},{key:"value",label:`$t:${re}.save_local.param_value`,widget:"data-chip"}],build:{handler:"saveToLocalStorage",params:{key:"{{key}}",value:"{{value}}"}}},navigate:{label:`$t:${re}.navigate.label`,params:[{key:"path",label:`$t:${re}.navigate.param_path`,widget:"page-picker",required:!0},{key:"query",label:`$t:${re}.navigate.param_query`,widget:"key-value"},{key:"mergeQuery",label:`$t:${re}.navigate.param_merge_query`,widget:"toggle"},{key:"scroll",label:`$t:${re}.navigate.param_scroll`,widget:"select",options:[{value:"top"},{value:"preserve"},{value:"none"}]},{key:"replace",label:`$t:${re}.navigate.param_replace`,widget:"toggle"},{key:"transition_overlay_target",label:`$t:${re}.navigate.param_overlay_target`,widget:"component-target-picker",dependsOn:{param:"replace",equals:!0}}],build:{handler:"navigate",params:{path:"{{path}}",query:"{{query}}",mergeQuery:"{{mergeQuery}}",scroll:"{{scroll}}",replace:"{{replace}}",transition_overlay_target:"{{transition_overlay_target}}"}}},openWindow:{label:`$t:${re}.open_window.label`,params:[{key:"target",label:`$t:${re}.open_window.param_target`,widget:"page-picker",required:!0},{key:"windowTarget",label:`$t:${re}.open_window.param_window_target`,widget:"select",options:[{value:"_blank"},{value:"_self"}]}],build:{handler:"openWindow",target:"{{target}}",params:{windowTarget:"{{windowTarget}}"}}},navigateBack:{label:`$t:${re}.navigate_back.label`,params:[],build:{handler:"navigateBack"}},navigateForward:{label:`$t:${re}.navigate_forward.label`,params:[],build:{handler:"navigateForward"}},replaceUrl:{label:`$t:${re}.replace_url.label`,params:[{key:"path",label:`$t:${re}.replace_url.param_path`,widget:"page-picker"},{key:"query",label:`$t:${re}.replace_url.param_query`,widget:"key-value"}],build:{handler:"replaceUrl",params:{path:"{{path}}",query:"{{query}}"}}},toast:{label:`$t:${re}.toast.label`,params:[{key:"message",label:`$t:${re}.toast.param_message`,widget:"i18n-text",required:!0},{key:"type",label:`$t:${re}.toast.param_type`,widget:"select",options:[{value:"info"},{value:"success"},{value:"warning"},{value:"error"}]},{key:"duration",label:`$t:${re}.toast.param_duration`,widget:"number"},{key:"icon",label:`$t:${re}.toast.param_icon`,widget:"text"}],build:{handler:"toast",params:{message:"{{message}}",type:"{{type}}",duration:"{{duration}}",icon:"{{icon}}"}}},openModal:{label:`$t:${re}.open_modal.label`,params:[{key:"target",label:`$t:${re}.open_modal.param_target`,widget:"modal-picker",required:!0}],build:{handler:"openModal",target:"{{target}}"}},closeModal:{label:`$t:${re}.close_modal.label`,params:[],build:{handler:"closeModal"}},showAlert:{label:`$t:${re}.show_alert.label`,params:[{key:"target",label:`$t:${re}.show_alert.param_message`,widget:"i18n-text",required:!0}],build:{handler:"showAlert",target:"{{target}}"}},setError:{label:`$t:${re}.set_error.label`,params:[{key:"target",label:`$t:${re}.set_error.param_message`,widget:"i18n-text"},{key:"stateTarget",label:`$t:${re}.set_error.param_state_target`,widget:"select",options:[{value:"local"},{value:"global"}]}],build:{handler:"setError",target:"{{target}}",params:{stateTarget:"{{stateTarget}}"}}},refetchDataSource:{label:`$t:${re}.refetch.label`,params:[{key:"dataSourceId",label:`$t:${re}.refetch.param_data_source`,widget:"datasource-picker",required:!0},{key:"sync",label:`$t:${re}.refetch.param_sync`,widget:"toggle"}],build:{handler:"refetchDataSource",params:{dataSourceId:"{{dataSourceId}}",sync:"{{sync}}"}}},appendDataSource:{label:`$t:${re}.append_data.label`,params:[{key:"dataSourceId",label:`$t:${re}.append_data.param_data_source`,widget:"datasource-picker",required:!0},{key:"dataPath",label:`$t:${re}.append_data.param_data_path`,widget:"text"},{key:"newData",label:`$t:${re}.append_data.param_new_data`,widget:"data-chip"}],build:{handler:"appendDataSource",params:{dataSourceId:"{{dataSourceId}}",dataPath:"{{dataPath}}",newData:"{{newData}}"}}},updateDataSource:{label:`$t:${re}.update_data.label`,params:[{key:"dataSourceId",label:`$t:${re}.update_data.param_data_source`,widget:"datasource-picker",required:!0},{key:"data",label:`$t:${re}.update_data.param_data`,widget:"data-chip"},{key:"merge",label:`$t:${re}.update_data.param_merge`,widget:"toggle"}],build:{handler:"updateDataSource",params:{dataSourceId:"{{dataSourceId}}",data:"{{data}}",merge:"{{merge}}"}}},scrollIntoView:{label:`$t:${re}.scroll.label`,params:[{key:"selector",label:`$t:${re}.scroll.param_selector`,widget:"text",required:!0},{key:"behavior",label:`$t:${re}.scroll.param_behavior`,widget:"select",options:[{value:"smooth"},{value:"auto"}]},{key:"block",label:`$t:${re}.scroll.param_block`,widget:"select",options:[{value:"start"},{value:"center"},{value:"end"},{value:"nearest"}]}],build:{handler:"scrollIntoView",params:{selector:"{{selector}}",behavior:"{{behavior}}",block:"{{block}}"}}},login:{label:`$t:${re}.login.label`,params:[{key:"body",label:`$t:${re}.login.param_body`,widget:"key-value"}],build:{handler:"login",params:{body:"{{body}}"}}},loginTwoFactor:{label:`$t:${re}.login_two_factor.label`,params:[{key:"body",label:`$t:${re}.login_two_factor.param_body`,widget:"key-value"}],build:{handler:"loginTwoFactor",params:{body:"{{body}}"}}},loginTwoFactorResend:{label:`$t:${re}.login_two_factor_resend.label`,params:[{key:"body",label:`$t:${re}.login_two_factor_resend.param_body`,widget:"key-value"}],build:{handler:"loginTwoFactorResend",params:{body:"{{body}}"}}},logout:{label:`$t:${re}.logout.label`,params:[{key:"target",label:`$t:${re}.logout.param_target`,widget:"text"}],build:{handler:"logout",target:"{{target}}"}},setLocale:{label:`$t:${re}.set_locale.label`,params:[{key:"target",label:`$t:${re}.set_locale.param_target`,widget:"locale-picker",required:!0}],build:{handler:"setLocale",target:"{{target}}"}},emitEvent:{label:`$t:${re}.emit_event.label`,params:[{key:"event",label:`$t:${re}.emit_event.param_event`,widget:"text",required:!0},{key:"data",label:`$t:${re}.emit_event.param_data`,widget:"data-chip"}],build:{handler:"emitEvent",params:{event:"{{event}}",data:"{{data}}"}}},apiCall:{label:`$t:${re}.api_call.label`,params:[{key:"target",label:`$t:${re}.api_call.param_target`,widget:"page-picker",required:!0},{key:"method",label:`$t:${re}.api_call.param_method`,widget:"select",options:[{value:"GET"},{value:"POST"},{value:"PUT"},{value:"PATCH"},{value:"DELETE"}]},{key:"body",label:`$t:${re}.api_call.param_body`,widget:"key-value"},{key:"query",label:`$t:${re}.api_call.param_query`,widget:"key-value"},{key:"identity_target_email",label:`$t:${re}.api_call.param_identity_target_email`,widget:"data-chip"},{key:"identity_target_phone",label:`$t:${re}.api_call.param_identity_target_phone`,widget:"data-chip"},{key:"onSuccess",label:`$t:${re}.api_call.param_on_success`,widget:"action-list"},{key:"onError",label:`$t:${re}.api_call.param_on_error`,widget:"action-list"}],build:{handler:"apiCall",target:"{{target}}",identity_target:{email:"{{identity_target_email}}",phone:"{{identity_target_phone}}"},onSuccess:"{{onSuccess}}",onError:"{{onError}}",params:{method:"{{method}}",body:"{{body}}",query:"{{query}}"}}},conditions:{label:`$t:${re}.conditions.label`,params:[{key:"branches",label:`$t:${re}.conditions.param_branches`,widget:"branch-list"}],build:{handler:"conditions",conditions:"{{branches}}"}},sequence:{label:`$t:${re}.sequence.label`,params:[{key:"actions",label:`$t:${re}.sequence.param_actions`,widget:"action-list"}],build:{handler:"sequence",params:{actions:"{{actions}}"}}},parallel:{label:`$t:${re}.parallel.label`,params:[{key:"actions",label:`$t:${re}.parallel.param_actions`,widget:"action-list"}],build:{handler:"parallel",params:{actions:"{{actions}}"}}},switch:{label:`$t:${re}.switch.label`,params:[{key:"value",label:`$t:${re}.switch.param_value`,widget:"data-chip"},{key:"cases",label:`$t:${re}.switch.param_cases`,widget:"action-list",advanced:!0}],build:{handler:"switch",params:{value:"{{value}}",cases:"{{cases}}"}}},suppress:{label:`$t:${re}.suppress.label`,params:[],build:{handler:"suppress"}}};function v8(){return{actionRecipes:vn,initActionRecipes:vn,errorRecipes:{navigate:vn.navigate,openModal:vn.openModal,toast:vn.toast,setState:vn.setState,sequence:vn.sequence,parallel:vn.parallel,showErrorPage:{label:`$t:${re}.show_error_page.label`,params:[{key:"target",label:`$t:${re}.show_error_page.param_target`,widget:"select",options:[{value:"content"},{value:"full"}]}],build:{handler:"showErrorPage",params:{target:"{{target}}"}}}}}}function sl(e,t){return typeof e.label=="string"?e.label.startsWith("$t:")?t(e.label.slice(3)):e.label:String(e.value)}function $i(e){return Array.isArray(e.options)?e.options:[]}function _8({control:e,value:t,onChange:n,t:o}){const r=$i(e);return i.jsx("div",{className:"g7le-widget g7le-widget--segmented","data-testid":"g7le-widget-segmented",style:N8,children:r.map(s=>{const a=s.value===t;return i.jsx("button",{type:"button","data-testid":`g7le-segment-${String(s.value)}`,"data-active":a?"true":"false",onClick:()=>n(a?void 0:s.value),style:{...O8,background:a?"#2563eb":"#fff",color:a?"#fff":"#0f172a",borderColor:a?"#2563eb":"#cbd5e1"},children:sl(s,o)},String(s.value))})})}function x8({control:e,value:t,onChange:n,t:o}){const r=Array.isArray(e.scale)?e.scale:[],s=r.findIndex(l=>l===t),a=t!=null;return i.jsxs("div",{className:"g7le-widget g7le-widget--slider","data-testid":"g7le-widget-slider",style:eh,children:[i.jsxs("label",{style:al,children:[i.jsx("input",{type:"checkbox","data-testid":"g7le-slider-enabled",checked:a,onChange:l=>{l.target.checked?n(r.length>0?r[Math.max(0,s===-1?0:s)]:void 0):n(void 0)}}),i.jsx("span",{style:{fontSize:12,color:"#64748b"},children:o("layout_editor.control.use")})]}),i.jsx("input",{type:"range","data-testid":"g7le-slider-range",min:0,max:Math.max(0,r.length-1),step:1,disabled:!a||r.length===0,value:s===-1?0:s,onChange:l=>{const d=Number(l.target.value);n(r[d])},style:{flex:1}}),i.jsx("span",{"data-testid":"g7le-slider-value",style:{fontSize:12,color:"#0f172a",minWidth:48,textAlign:"right"},children:a?String(t):o("layout_editor.control.default")})]})}function w8({control:e,value:t,onChange:n,t:o}){const r=$i(e);return i.jsxs("select",{className:"g7le-widget g7le-widget--select","data-testid":"g7le-widget-select",value:t==null?"":String(t),onChange:s=>{const a=s.target.value;if(a===""){n(void 0);return}const l=r.find(d=>String(d.value)===a);n(l?l.value:a)},style:B8,children:[i.jsx("option",{value:"",children:o("layout_editor.control.default")}),r.map(s=>i.jsx("option",{value:String(s.value),children:sl(s,o)},String(s.value)))]})}function k8({control:e,value:t,onChange:n}){const o=$i(e),r=o[1]?.value??!0,s=o[0]?.value??void 0,a=t===r;return i.jsx("button",{type:"button",className:"g7le-widget g7le-widget--toggle","data-testid":"g7le-widget-toggle",role:"switch","aria-checked":a,onClick:()=>n(a?s:r),style:{...W8,background:a?"#2563eb":"#cbd5e1"},children:i.jsx("span",{style:{...j8,transform:a?"translateX(18px)":"translateX(0)"}})})}function S8({control:e,value:t,onChange:n,t:o,freeValueDisabled:r}){const s=$i(e),a=t==null?"":String(t),[l,d]=u.useState(a);u.useEffect(()=>{d(a)},[a]);const c=p=>{const f=p.trim();if(f===""){n(void 0);return}n(f)};return i.jsxs("div",{className:"g7le-widget g7le-widget--dimension","data-testid":"g7le-widget-dimension",style:Jg,children:[r?i.jsx("div",{"data-testid":"g7le-dimension-free-disabled",style:L8,children:o("layout_editor.property_modal.dark_preset_only")}):i.jsxs("div",{style:Zg,children:[i.jsx("input",{type:"text","data-testid":"g7le-dimension-input",value:l,placeholder:o("layout_editor.control.dimension.placeholder"),onChange:p=>d(p.target.value),onBlur:p=>c(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),c(p.target.value))},style:Qg}),i.jsx("button",{type:"button","data-testid":"g7le-dimension-clear",title:o("layout_editor.control.default"),onClick:()=>{d(""),n(void 0)},style:Rg,children:o("layout_editor.control.default")})]}),s.length>0&&i.jsx("div",{style:M8,"data-testid":"g7le-dimension-chips",children:s.map(p=>{const f=String(p.value),b=f===a;return i.jsx("button",{type:"button","data-testid":`g7le-dimension-chip-${f}`,"data-active":b?"true":"false",onClick:()=>{d(f),n(f)},style:{...P8,background:b?"#2563eb":"#fff",color:b?"#fff":"#0f172a",borderColor:b?"#2563eb":"#cbd5e1"},children:sl(p,o)},f)})})]})}function C8({control:e,value:t,onChange:n,t:o}){const r=e,s=t==null?"":String(t),[a,l]=u.useState(s);u.useEffect(()=>{l(s)},[s]);const d=c=>{const p=c.trim();if(p===""){n(void 0);return}const f=Number(p);Number.isFinite(f)&&n(f)};return i.jsx("div",{className:"g7le-widget g7le-widget--number","data-testid":"g7le-widget-number",style:Jg,children:i.jsxs("div",{style:Zg,children:[i.jsx("input",{type:"text",inputMode:"numeric","data-testid":"g7le-number-input",value:a,placeholder:o("layout_editor.control.number.placeholder"),min:typeof r.min=="number"?r.min:void 0,max:typeof r.max=="number"?r.max:void 0,step:typeof r.step=="number"?r.step:void 0,onChange:c=>l(c.target.value),onBlur:c=>d(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),d(c.target.value))},style:Qg}),i.jsx("button",{type:"button","data-testid":"g7le-number-clear",title:o("layout_editor.control.default"),onClick:()=>{l(""),n(void 0)},style:Rg,children:o("layout_editor.control.default")})]})})}function $8(e){return[{key:"t",infix:`${e}t-`,labelKey:"layout_editor.control.spacing.top"},{key:"r",infix:`${e}r-`,labelKey:"layout_editor.control.spacing.right"},{key:"b",infix:`${e}b-`,labelKey:"layout_editor.control.spacing.bottom"},{key:"l",infix:`${e}l-`,labelKey:"layout_editor.control.spacing.left"}]}function E8(e,t,n,o){const r={all:-1,sides:{}};if(typeof e!="string"||e.trim()==="")return r;const s=e.split(/\s+/).filter(a=>a.length>0);for(const a of s){const l=n.find(d=>a.startsWith(d.infix));if(l){r.sides[l.key]=o.indexOf(a.slice(l.infix.length));continue}if(a.startsWith(`${t}x-`)){const d=o.indexOf(a.slice(`${t}x-`.length));r.sides.l=d,r.sides.r=d;continue}if(a.startsWith(`${t}y-`)){const d=o.indexOf(a.slice(`${t}y-`.length));r.sides.t=d,r.sides.b=d;continue}a.startsWith(`${t}-`)&&(r.all=o.indexOf(a.slice(`${t}-`.length)))}return r}function I8({control:e,value:t,onChange:n,t:o}){const r=typeof e.spacingPrefix=="string"?e.spacingPrefix:"p",s=(Array.isArray(e.scale)?e.scale:[]).map(y=>String(y)),a=$8(r),l=E8(t,r,a,s),d=Object.values(l.sides).some(y=>y>=0),c=l.all>=0||d,[p,f]=u.useState(d);u.useEffect(()=>{d&&f(!0)},[d]);const b=Math.min(4,Math.max(0,s.length-1)),g=y=>{const _=[];for(const w of a){const k=y[w.key];k!==void 0&&k>=0&&_.push(`${w.infix}${s[k]}`)}n(_.length>0?_.join(" "):void 0)},m=y=>{n(y>=0?`${r}-${s[Math.max(0,Math.min(y,s.length-1))]}`:void 0)},h=()=>({...l.sides}),v=(y,_,w,k,x)=>{const $=w>=0;return i.jsxs("div",{style:z8,"data-testid":y,children:[i.jsxs("label",{style:{...al,minWidth:64},children:[i.jsx("input",{type:"checkbox","data-testid":`${y}-enabled`,checked:$,onChange:C=>x(C.target.checked)}),i.jsx("span",{style:{fontSize:12,color:"#0f172a"},children:o(_)})]}),i.jsx("input",{type:"range","data-testid":`${y}-range`,min:0,max:Math.max(0,s.length-1),step:1,disabled:!$||s.length===0,value:w<0?0:w,onChange:C=>k(Number(C.target.value)),style:{flex:1}}),i.jsx("span",{"data-testid":`${y}-value`,style:{fontSize:12,color:$?"#0f172a":"#94a3b8",minWidth:28,textAlign:"right"},children:$?s[w]:"–"})]},y)};return i.jsxs("div",{className:"g7le-widget g7le-widget--spacing","data-testid":"g7le-widget-spacing",style:A8,children:[i.jsxs("div",{style:T8,children:[i.jsxs("div",{style:D8,"data-testid":"g7le-spacing-mode",children:[i.jsx("button",{type:"button","data-testid":"g7le-spacing-mode-all","data-active":p?"false":"true",onClick:()=>{f(!1),d&&n(void 0)},style:{...Xg,background:p?"#fff":"#2563eb",color:p?"#0f172a":"#fff",borderColor:p?"#cbd5e1":"#2563eb"},children:o("layout_editor.control.spacing.mode_all")}),i.jsx("button",{type:"button","data-testid":"g7le-spacing-mode-sides","data-active":p?"true":"false",onClick:()=>{if(f(!0),l.all>=0){const y={};for(const _ of a)y[_.key]=l.all;g(y)}},style:{...Xg,background:p?"#2563eb":"#fff",color:p?"#fff":"#0f172a",borderColor:p?"#2563eb":"#cbd5e1"},children:o("layout_editor.control.spacing.mode_sides")})]}),i.jsx("span",{"data-testid":"g7le-spacing-value",style:{fontSize:11,color:"#64748b",minWidth:80,textAlign:"right"},children:c?String(t):o("layout_editor.control.default")})]}),p?i.jsx("div",{"data-testid":"g7le-spacing-sides",style:{display:"flex",flexDirection:"column",gap:4},children:a.map(y=>v(`g7le-spacing-side-${y.key}`,y.labelKey,l.sides[y.key]??-1,_=>{const w=h();w[y.key]=_,g(w)},_=>{const w=h();_?w[y.key]=l.sides[y.key]>=0?l.sides[y.key]:b:delete w[y.key],g(w)}))}):i.jsxs("div",{style:eh,children:[i.jsxs("label",{style:{...al,minWidth:64},children:[i.jsx("input",{type:"checkbox","data-testid":"g7le-spacing-all-enabled",checked:l.all>=0,onChange:y=>m(y.target.checked?b:-1)}),i.jsx("span",{style:{fontSize:12,color:"#64748b"},children:o("layout_editor.control.spacing.all")})]}),i.jsx("input",{type:"range","data-testid":"g7le-spacing-all-range",min:0,max:Math.max(0,s.length-1),step:1,disabled:l.all<0||s.length===0,value:l.all<0?0:l.all,onChange:y=>m(Number(y.target.value)),style:{flex:1}}),i.jsx("span",{"data-testid":"g7le-spacing-all-value",style:{fontSize:12,color:l.all>=0?"#0f172a":"#94a3b8",minWidth:28,textAlign:"right"},children:l.all>=0?s[l.all]:"–"})]})]})}const A8={display:"flex",flexDirection:"column",gap:6,width:"100%"},T8={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},D8={display:"inline-flex",gap:0,border:"1px solid #cbd5e1",borderRadius:6,overflow:"hidden"},Xg={padding:"3px 10px",fontSize:11,border:"none",borderRight:"1px solid #e2e8f0",cursor:"pointer"},z8={display:"flex",alignItems:"center",gap:8,width:"100%"},N8={display:"inline-flex",gap:0,border:"1px solid #cbd5e1",borderRadius:6,overflow:"hidden"},Jg={display:"flex",flexDirection:"column",gap:6,width:"100%"},Zg={display:"flex",gap:6,alignItems:"center"},Qg={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:80},Rg={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer",whiteSpace:"nowrap"},M8={display:"flex",flexWrap:"wrap",gap:4},L8={fontSize:11,color:"#94a3b8",fontStyle:"italic",padding:"2px 0"},P8={padding:"3px 9px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:999,background:"#fff",cursor:"pointer"},O8={padding:"4px 10px",fontSize:12,border:"none",borderRight:"1px solid #e2e8f0",cursor:"pointer"},eh={display:"flex",alignItems:"center",gap:8,width:"100%"},al={display:"inline-flex",alignItems:"center",gap:4},B8={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",minWidth:120},W8={position:"relative",width:38,height:20,borderRadius:10,border:"none",cursor:"pointer",padding:2,display:"inline-flex",alignItems:"center",transition:"background 120ms ease"},j8={display:"block",width:16,height:16,borderRadius:8,background:"#fff",transition:"transform 120ms ease"},H8=["#0f172a","#334155","#64748b","#94a3b8","#e2e8f0","#ffffff","#dc2626","#ea580c","#d97706","#16a34a","#0891b2","#2563eb","#7c3aed","#db2777"],th=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function F8(e){return Array.isArray(e.options)?e.options.filter(t=>typeof t.value=="string").map(t=>({value:t.value,swatch:typeof t.swatch=="string"?t.swatch:void 0,label:typeof t.label=="string"?t.label:void 0})):[]}function K8({control:e,value:t,onChange:n,t:o,freeValueDisabled:r}){const s=F8(e),a=s.length>0,l=typeof t=="string"&&s.some(g=>g.value===t)?t:"",d=typeof t=="string"&&th.test(t)?t:"",[c,p]=u.useState(d);u.useEffect(()=>{p(d)},[d]);const f=g=>{const m=g.trim();if(m===""){n(void 0);return}const h=m.startsWith("#")?m:`#${m}`;th.test(h)&&n(h)},b=H8;return i.jsxs("div",{className:"g7le-widget g7le-widget--color","data-testid":"g7le-widget-color",style:V8,children:[r?i.jsx("div",{"data-testid":"g7le-color-free-disabled",style:J8,children:o("layout_editor.property_modal.dark_preset_only")}):i.jsxs("div",{style:U8,children:[i.jsxs("label",{style:q8,children:[i.jsx("span",{"data-testid":"g7le-color-swatch",style:{...G8,background:d||"transparent",backgroundImage:d?void 0:"linear-gradient(45deg,#e2e8f0 25%,transparent 25%,transparent 75%,#e2e8f0 75%),linear-gradient(45deg,#e2e8f0 25%,#fff 25%,#fff 75%,#e2e8f0 75%)",backgroundSize:"8px 8px",backgroundPosition:"0 0, 4px 4px"}}),i.jsx("input",{type:"color","data-testid":"g7le-color-native",value:d||"#000000",onChange:g=>n(g.target.value),style:{width:0,height:0,opacity:0,position:"absolute"}})]}),i.jsx("input",{type:"text","data-testid":"g7le-color-hex",value:c,placeholder:o("layout_editor.control.color_hex_placeholder"),onChange:g=>p(g.target.value),onBlur:g=>f(g.target.value),onKeyDown:g=>{g.key==="Enter"&&f(g.target.value)},style:Y8}),i.jsx("button",{type:"button","data-testid":"g7le-color-clear",onClick:()=>n(void 0),style:X8,children:o("layout_editor.control.default")})]}),a?i.jsx("div",{style:nh,"data-testid":"g7le-color-token-presets",children:s.map(g=>{const m=l===g.value,h=g.label?g.label.startsWith("$t:")?o(g.label.slice(3)):g.label:g.value;return i.jsx("button",{type:"button","aria-label":h,title:h,"data-testid":`g7le-color-token-${g.value}`,"data-active":m?"true":"false",onClick:()=>n(m?void 0:g.value),style:{...oh,background:g.swatch||"#e2e8f0",outline:m?"2px solid #2563eb":"none"}},g.value)})}):!r&&i.jsx("div",{style:nh,"data-testid":"g7le-color-presets",children:b.map(g=>i.jsx("button",{type:"button","aria-label":g,"data-testid":`g7le-color-preset-${g}`,onClick:()=>n(g),style:{...oh,background:g,outline:d.toLowerCase()===g.toLowerCase()?"2px solid #2563eb":"none"}},g))})]})}const V8={display:"flex",flexDirection:"column",gap:8},U8={display:"flex",alignItems:"center",gap:6},q8={position:"relative",display:"inline-flex",cursor:"pointer"},G8={width:24,height:24,borderRadius:4,border:"1px solid #cbd5e1",display:"inline-block"},Y8={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,fontFamily:"monospace"},X8={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",cursor:"pointer",color:"#64748b"},nh={display:"grid",gridTemplateColumns:"repeat(7, 1fr)",gap:4},oh={width:"100%",height:18,borderRadius:4,border:"1px solid #cbd5e1",cursor:"pointer",padding:0},J8={fontSize:11,color:"#94a3b8",fontStyle:"italic",padding:"2px 0"},rr=[{value:"fill",labelKey:"layout_editor.control.background_image.mode_fill",size:"cover",repeat:"no-repeat"},{value:"fit",labelKey:"layout_editor.control.background_image.mode_fit",size:"contain",repeat:"no-repeat"},{value:"tile",labelKey:"layout_editor.control.background_image.mode_tile",size:"auto",repeat:"repeat"}];function rh(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function ih(e){return rr.find(n=>n.size===e.size&&n.repeat===e.repeat)?.value??"fill"}function Z8(e){if(!e)return!1;const t=[],n=e.apply;n&&typeof n=="object"&&t.push(n);for(const o of e.options??[])o&&typeof o=="object"&&o.apply&&typeof o.apply=="object"&&t.push(o.apply);return t.length===0?!1:t.every(o=>o.type==="propValue"||o.type==="cssVar"||o.type==="styleProp"&&!Array.isArray(o.props))}function Q8({control:e,value:t,onChange:n,t:o}){const r=rh(t),s=Z8(e),a=Kf(t,I=>n({url:I}),I=>rh(I).url),l=a.bound,{state:d}=Qe(),c=vo(),[p,f]=u.useState(!1),[b,g]=u.useState(null),[m,h]=u.useState(r.url??""),[v,y]=u.useState([]),_=u.useRef(null),w=d.templateIdentifier,k=d.selectedRoute?.layoutName??"";u.useEffect(()=>{h(r.url??"")},[r.url]);const x=u.useCallback(async()=>{if(!w||!k){y([]);return}const I=await Wl(w,k);I.ok&&y(I.data)},[w,k]);u.useEffect(()=>{x()},[x]);const $=I=>{if(!I){n(void 0);return}if(s){n({url:I});return}const N=rr.find(T=>T.value===ih(r))??rr[0];n({url:I,size:r.size??N.size,repeat:r.repeat??N.repeat,position:r.position??"center"})},C=I=>{const N=rr.find(T=>T.value===I);!N||!r.url||n({url:r.url,size:N.size,repeat:N.repeat,position:r.position??"center"})},S=async I=>{const N=I.target.files?.[0];if(!N)return;f(!0),g(null);const T=await jl(w,k,N);T.ok?($(T.data.url),x()):g(o("layout_editor.control.background_image.upload_failed")),f(!1),_.current&&(_.current.value="")},D=async I=>{(await Hl(I.id)).ok&&y(T=>T.filter(B=>B.id!==I.id))},E=()=>{const I=c.open({ariaLabel:o("layout_editor.attachment_manager.title"),width:720,maxHeightRatio:.82,content:u.createElement(Fl,{templateIdentifier:w,layoutName:k,t:o,onSelect:N=>{$(N),c.close(I)},onChanged:()=>{x()},onClose:()=>c.close(I)})})};return i.jsxs("div",{className:"g7le-widget g7le-widget--image","data-testid":"g7le-widget-image",style:R8,children:[l?i.jsx(Uf,{expression:r.url??"",t:o,onReplace:a.beginReplace,testIdPrefix:"g7le-image"}):r.url&&i.jsx("div",{"data-testid":"g7le-image-preview",style:{...ez,backgroundImage:`url(${r.url})`,backgroundSize:s?"contain":r.size??"cover",backgroundRepeat:s?"no-repeat":r.repeat??"no-repeat",backgroundPosition:s?"center":r.position??"center"}}),i.jsxs("div",{style:tz,children:[i.jsxs("label",{style:{...nz,...l?Ei:null},children:[p?"…":o("layout_editor.control.background_image.upload"),i.jsx("input",{ref:_,type:"file",accept:"image/*","data-testid":"g7le-image-file",onChange:S,disabled:p||l,style:{display:"none"}})]}),i.jsx("button",{type:"button","data-testid":"g7le-image-clear",disabled:l,onClick:()=>n(void 0),style:{...oz,...l?Ei:null},children:o("layout_editor.control.background_image.clear")})]}),i.jsx("input",{type:"text","data-testid":"g7le-image-url",placeholder:"https://… / URL",value:m,readOnly:l,onChange:I=>h(I.target.value),onBlur:I=>{l||$(I.target.value.trim()||void 0)},style:rz}),a.replacing&&a.original!==null&&i.jsx(qf,{t:o,onRestore:a.restore,testIdPrefix:"g7le-image"}),!s&&i.jsx("div",{style:iz,"data-testid":"g7le-image-modes",children:rr.map(I=>{const N=ih(r)===I.value;return i.jsx("button",{type:"button","data-testid":`g7le-image-mode-${I.value}`,"data-active":N?"true":"false",disabled:!r.url||l,onClick:()=>C(I.value),style:{...sz,background:N&&r.url?"#2563eb":"#fff",color:N&&r.url?"#fff":"#0f172a"},children:o(I.labelKey)},I.value)})}),i.jsxs("div",{style:az,"data-testid":"g7le-image-gallery",children:[i.jsxs("div",{style:lz,children:[i.jsx("span",{style:{fontSize:11,color:"#64748b"},children:o("layout_editor.attachment_manager.recent")}),i.jsxs("button",{type:"button","data-testid":"g7le-image-manage",disabled:l,onClick:E,style:{...dz,...l?Ei:null},children:["🖼 ",o("layout_editor.attachment_manager.manage_link")]})]}),v.length>0?i.jsx("div",{style:cz,"data-testid":"g7le-image-thumbs",children:v.slice(0,8).map(I=>i.jsxs("div",{style:uz,"data-testid":`g7le-image-thumb-${I.id}`,children:[i.jsx("button",{type:"button",title:I.original_name,disabled:l,onClick:()=>$(I.url),style:{...pz,backgroundImage:`url(${I.url})`,...l?Ei:null},"data-testid":`g7le-image-thumb-use-${I.id}`}),i.jsx("button",{type:"button",title:o("layout_editor.attachment_manager.delete"),onClick:()=>D(I),style:fz,"data-testid":`g7le-image-thumb-del-${I.id}`,children:"✕"})]},I.id))}):i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:o("layout_editor.attachment_manager.empty")})]}),b&&i.jsx("span",{"data-testid":"g7le-image-error",style:{fontSize:11,color:"#dc2626"},children:b})]})}const R8={display:"flex",flexDirection:"column",gap:6},ez={width:"100%",height:80,borderRadius:6,border:"1px solid #cbd5e1"},tz={display:"flex",gap:6},nz={padding:"5px 10px",fontSize:12,border:"1px solid #2563eb",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",display:"inline-flex",alignItems:"center"},oz={padding:"5px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},rz={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},Ei={opacity:.45,cursor:"not-allowed"},iz={display:"inline-flex",border:"1px solid #cbd5e1",borderRadius:6,overflow:"hidden"},sz={padding:"4px 10px",fontSize:12,border:"none",borderRight:"1px solid #e2e8f0",cursor:"pointer"},az={display:"flex",flexDirection:"column",gap:4,border:"1px solid #e2e8f0",borderRadius:6,padding:6,marginTop:2},lz={display:"flex",alignItems:"center",justifyContent:"space-between"},dz={fontSize:11,color:"#2563eb",background:"transparent",border:"none",cursor:"pointer",padding:0},cz={display:"flex",gap:6,flexWrap:"wrap"},uz={position:"relative",width:44,height:44},pz={width:44,height:44,borderRadius:6,border:"1px solid #cbd5e1",backgroundSize:"cover",backgroundPosition:"center",cursor:"pointer",padding:0},fz={position:"absolute",top:-6,right:-6,width:16,height:16,borderRadius:"50%",border:"none",background:"#dc2626",color:"#fff",fontSize:9,lineHeight:"16px",cursor:"pointer",padding:0};function gz(e){return Array.isArray(e)&&e.every(t=>t!==null&&typeof t=="object"&&!Array.isArray(t))}function hz(e){return typeof e=="string"&&/\{\{.*\}\}/.test(e)}function yz({value:e,onChange:t,t:n,bindingCandidates:o}){if(hz(e))return i.jsx("div",{className:"g7le-widget g7le-widget--options-list","data-testid":"g7le-widget-options-list-bound",style:Sz,children:n("layout_editor.list_editor.bound_degraded")});const r=gz(e)?e:[],s=b=>{t(b.length===0?void 0:b)},a=(b,g)=>{const m=r.map((h,v)=>v===b?{...h,...g}:h);s(m)},l=b=>{s(r.filter((g,m)=>m!==b))},d=(b,g)=>{const m=b+g;if(m<0||m>=r.length)return;const h=[...r];[h[b],h[m]]=[h[m],h[b]],s(h)},c=()=>{s([...r,{value:"",label:""}])},p=b=>typeof b.label=="string"?b.label:b.label==null?"":String(b.label),f=b=>b.value===void 0||b.value===null?"":String(b.value);return i.jsxs("div",{className:"g7le-widget g7le-widget--options-list","data-testid":"g7le-widget-options-list",style:bz,children:[r.length===0&&i.jsx("div",{"data-testid":"g7le-options-empty",style:kz,children:n("layout_editor.list_editor.empty")}),r.map((b,g)=>i.jsxs("div",{"data-testid":`g7le-options-row-${g}`,style:mz,children:[i.jsxs("div",{style:sh,children:[i.jsx("span",{style:ah,children:n("layout_editor.list_editor.option_value")}),i.jsx("input",{type:"text","data-testid":`g7le-options-value-${g}`,value:f(b),placeholder:n("layout_editor.list_editor.option_value"),onChange:m=>a(g,{value:m.target.value}),style:_z})]}),i.jsxs("div",{style:sh,children:[i.jsx("span",{style:ah,children:n("layout_editor.list_editor.option_label")}),i.jsx("div",{"data-testid":`g7le-options-label-${g}`,style:{flex:1,minWidth:0},children:i.jsx(_t,{value:p(b),onChange:m=>a(g,{label:m??""}),t:n,placeholder:n("layout_editor.list_editor.option_label"),testidPrefix:`g7le-options-label-i18n-${g}`,candidates:o,enableExpressionTree:!0,expressionTreeCollapsible:!0})})]}),i.jsxs("div",{style:vz,children:[i.jsx("button",{type:"button","data-testid":`g7le-options-up-${g}`,title:n("layout_editor.list_editor.move_up"),disabled:g===0,onClick:()=>d(g,-1),style:lh,children:"↑"}),i.jsx("button",{type:"button","data-testid":`g7le-options-down-${g}`,title:n("layout_editor.list_editor.move_down"),disabled:g===r.length-1,onClick:()=>d(g,1),style:lh,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-options-remove-${g}`,title:n("layout_editor.list_editor.remove"),onClick:()=>l(g),style:xz,children:"✕"})]})]},g)),i.jsx("button",{type:"button","data-testid":"g7le-options-add",onClick:c,style:wz,children:n("layout_editor.list_editor.add")})]})}const bz={display:"flex",flexDirection:"column",gap:8,width:"100%"},mz={display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0,paddingBottom:6,borderBottom:"1px solid #f1f5f9"},sh={display:"flex",gap:6,alignItems:"center",width:"100%",minWidth:0},ah={flexShrink:0,width:36,fontSize:11,color:"#94a3b8",textAlign:"right"},vz={display:"flex",gap:4,alignItems:"center",justifyContent:"flex-end"},_z={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},lh={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},xz={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},wz={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},kz={fontSize:11,color:"#94a3b8",fontStyle:"italic"},Sz={fontSize:11,color:"#b45309",fontStyle:"italic",padding:"4px 2px"},dh=/[^A-Za-z0-9\-_:.]/g;function Cz(e){return typeof e=="string"&&br(e)}function ch(e){return br(e)?An(e).map(t=>t.kind==="binding"?t.raw:t.raw.replace(dh,"")).join(""):e.replace(dh,"")}const $z={width:"100%",padding:"6px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:4,fontFamily:"monospace"},Ez={marginTop:4,fontSize:11,color:"#94a3b8"},Iz={display:"flex",gap:6,alignItems:"center"},Az={flexShrink:0,padding:"5px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:4,background:"#f8fafc",cursor:"pointer",whiteSpace:"nowrap"};function Tz({value:e,onChange:t,t:n,bindingCandidates:o}){const r=e==null?"":String(e),s=Cz(e),a=!!o&&o.length>0,[l,d]=u.useState(!1),c=p=>{const f=ch(p);t(f===""?void 0:f)};return s||l?i.jsxs("div",{"data-testid":"g7le-core-id-chip",children:[i.jsx(Ss,{value:r,onChange:c,t:n,candidates:o,onDone:()=>d(!1),testidPrefix:"g7le-core-id-chip-input"}),i.jsx("div",{style:Ez,children:n("layout_editor.core_props.id.binding_hint")})]}):i.jsx("div",{children:i.jsxs("div",{style:Iz,children:[i.jsx("input",{type:"text",className:"g7le-widget g7le-widget--core-id","data-testid":"g7le-widget-core-id",value:r,onChange:p=>{const f=ch(p.target.value);t(f===""?void 0:f)},spellCheck:!1,autoComplete:"off",style:$z}),a&&i.jsxs("button",{type:"button","data-testid":"g7le-core-id-add-data",onClick:()=>d(!0),style:Az,title:n("layout_editor.core_props.id.add_data"),children:["🔗 ",n("layout_editor.core_props.id.add_data")]})]})})}const Dz=/[^A-Za-z0-9.\-_]/g;function zz(e){return typeof e=="string"&&/\{\{[\s\S]*?\}\}/.test(e)}function Nz(e){return e.replace(Dz,"")}const uh={width:"100%",padding:"6px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:4,fontFamily:"monospace",boxSizing:"border-box"},Mz={...uh,background:"#f1f5f9",color:"#64748b",cursor:"not-allowed"},ph={marginTop:4,fontSize:11,color:"#94a3b8"};function Lz({value:e,onChange:t,t:n}){const o=e==null?"":String(e);return zz(e)?i.jsxs("div",{"data-testid":"g7le-core-datakey-bound",children:[i.jsx("input",{type:"text",className:"g7le-widget g7le-widget--core-datakey-bound","data-testid":"g7le-widget-core-datakey",value:o,readOnly:!0,disabled:!0,style:Mz}),i.jsx("div",{style:ph,children:n("layout_editor.core_props.dataKey.bound_degraded")})]}):i.jsxs("div",{children:[i.jsx("input",{type:"text",className:"g7le-widget g7le-widget--core-datakey","data-testid":"g7le-widget-core-datakey",value:o,placeholder:n("layout_editor.core_props.dataKey.placeholder"),onChange:s=>{const a=Nz(s.target.value);t(a===""?void 0:a)},spellCheck:!1,autoComplete:"off",style:uh}),i.jsx("div",{style:ph,children:n("layout_editor.core_props.dataKey.hint")})]})}let fh=!1;function Pz(){fh||(Ge("segmented",_8),Ge("slider",x8),Ge("select",w8),Ge("dimension",S8),Ge("number",C8),Ge("spacing",I8),Ge("toggle",k8),Ge("color",K8),Ge("image",Q8),Ge("tag-input",ks),Ge("page-picker",R0),Ge("datasource-picker",qc),Ge("binding-picker",qc),Ge("binding-list",nk),Ge("state-key-picker",Ms),Ge("modal-picker",ek),Ge("i18n-text",tk),Ge("text",ok),Ge("options-list",yz),Ge("core-id",Tz),Ge("core-datakey",Lz),Ge("component-target-picker",D4),fh=!0)}function ir(e){return Array.isArray(e.children)?e.children:[]}function sr(e){if(typeof e.text=="string")return[];let t=null;const n=(o,r)=>{const s=ir(o);for(let a=0;ad===o?ar(l,r,n):l);return{...e,children:a}}function gh(e,t){const n=r=>typeof r.props?.[t]=="string";if(n(e))return[];const o=(r,s)=>{const a=ir(r);for(let l=0;lc===r?hh(d,s,n,o):d);return{...e,children:l}}function Oz(e){return Array.isArray(e.children)?e.children:[]}function Bz(e){const t=e?.itemFields;if(!Array.isArray(t))return[{kind:"text"}];const n=[];for(const o of t){if(!o||typeof o!="object")continue;const r=o;r.kind==="text"?n.push({kind:"text",label:typeof r.label=="string"?r.label:void 0}):r.kind==="prop"&&typeof r.prop=="string"&&r.prop.length>0&&n.push({kind:"prop",prop:r.prop,label:typeof r.label=="string"?r.label:void 0})}return n.length>0?n:[{kind:"text"}]}function ll(e,t){if(!(typeof e!="string"||e.length===0))return e.startsWith("$t:")?t(e.slice(3)):e}function yh({node:e,params:t,spec:n,manifest:o,t:r,onPatchNode:s,templateIdentifier:a,candidates:l}){const d=typeof t?.childComponent=="string"?t.childComponent:null,c=t?.childTemplate&&typeof t.childTemplate=="object"?t.childTemplate:null,p=Bz(t),f=ll(typeof t?.childLabel=="string"?t.childLabel:void 0,r)??d??"",b=Oz(e),g=u.useCallback(x=>{s({...e,children:x})},[e,s]),m=u.useCallback(()=>{if(c)return JSON.parse(JSON.stringify(c));if(!d)return null;const x=n?.componentPalette?.entries?.[d];if(x?.defaultNode&&typeof x.defaultNode=="object")return JSON.parse(JSON.stringify(x.defaultNode));const $=o?.components??{};let C=null;for(const S of Object.values($))if(Array.isArray(S)){const D=S.find(E=>E.name===d);if(D){C=D;break}}return C?Bf(C):{type:"basic",name:d}},[c,d,n,o]),h=u.useCallback(()=>{const x=m();if(x){if(x.text==="")x.text=r("layout_editor.list_editor.new_item");else{const $=sr(x);if($!==null&&$.length>0){const C=Ii(x,$);if(C&&C.text===""){const S=ar(x,$,r("layout_editor.list_editor.new_item"));g([...b,S]);return}}}g([...b,x])}},[m,g,b,r]),v=u.useCallback(x=>{g(b.filter(($,C)=>C!==x))},[g,b]),y=u.useCallback((x,$)=>{const C=x+$;if(C<0||C>=b.length)return;const S=[...b];[S[x],S[C]]=[S[C],S[x]],g(S)},[g,b]),_=u.useCallback((x,$)=>{if(typeof $!="string"||$.length===0)return;const C=b[x];if(!C)return;const S=sr(C);if(S===null)return;const D=b.map((E,I)=>I===x?ar(E,S,$):E);g(D)},[b,g]),w=u.useCallback((x,$,C)=>{if(typeof C!="string"||C.length===0)return;const S=b[x];if(!S)return;const D=gh(S,$);if(D===null)return;const E=b.map((I,N)=>N===x?hh(I,D,$,C):I);g(E)},[b,g]);if(!d&&!c)return i.jsx("div",{className:"g7le-node-editor g7le-node-editor--children","data-testid":"g7le-children-editor-misconfigured",style:vh,children:r("layout_editor.list_editor.no_child_component")});const k=p.length>1||p.some(x=>x.label);return i.jsxs("div",{className:"g7le-node-editor g7le-node-editor--children","data-testid":"g7le-children-editor",style:Wz,children:[i.jsx("div",{style:jz,children:r("layout_editor.list_editor.items_title")}),b.length===0&&i.jsx("div",{"data-testid":"g7le-children-empty",style:vh,children:r("layout_editor.list_editor.empty")}),b.map((x,$)=>{const C=[];for(const D of p)if(D.kind==="text"){const E=sr(x),I=E!==null?Ii(x,E):null;I&&typeof I.text=="string"&&C.push({key:"text",caption:ll(D.label,r)??(k?r("layout_editor.list_editor.item_label"):void 0),value:I.text,onChange:N=>_($,N),testid:`g7le-children-i18n-${$}`})}else if(D.kind==="prop"&&D.prop){const E=gh(x,D.prop);if(E!==null){const N=Ii(x,E)?.props?.[D.prop];C.push({key:`prop-${D.prop}`,caption:ll(D.label,r)??D.prop,value:typeof N=="string"?N:"",onChange:T=>w($,D.prop,T),testid:`g7le-children-prop-${D.prop}-${$}`})}}const S=typeof x?.name=="string"?x.name:r("layout_editor.list_editor.item");return i.jsxs("div",{"data-testid":`g7le-children-row-${$}`,style:Hz,children:[C.length>0?C.map(D=>i.jsx("div",{style:bh,children:i.jsxs("div",{"data-testid":D.key==="text"?`g7le-children-text-${$}`:`g7le-children-field-${D.key}-${$}`,style:Fz,children:[D.caption!==void 0&&i.jsx("div",{"data-testid":`g7le-children-caption-${D.key}-${$}`,style:Kz,children:D.caption}),i.jsx(_t,{value:D.value,onChange:D.onChange,t:r,placeholder:r("layout_editor.list_editor.item_text"),testidPrefix:D.testid,candidates:l,enableExpressionTree:!0,expressionTreeCollapsible:!0})]})},D.key)):i.jsx("div",{style:bh,children:i.jsx("span",{"data-testid":`g7le-children-label-${$}`,style:Uz,children:S})}),i.jsxs("div",{style:Vz,children:[i.jsx("button",{type:"button","data-testid":`g7le-children-up-${$}`,title:r("layout_editor.list_editor.move_up"),disabled:$===0,onClick:()=>y($,-1),style:mh,children:"↑"}),i.jsx("button",{type:"button","data-testid":`g7le-children-down-${$}`,title:r("layout_editor.list_editor.move_down"),disabled:$===b.length-1,onClick:()=>y($,1),style:mh,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-children-remove-${$}`,title:r("layout_editor.list_editor.remove"),onClick:()=>v($),style:qz,children:"✕"})]})]},$)}),i.jsx("button",{type:"button","data-testid":"g7le-children-add",onClick:h,style:Gz,children:r("layout_editor.list_editor.add_child",{component:f})})]})}const Wz={display:"flex",flexDirection:"column",gap:6,width:"100%",marginBottom:12},jz={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:2},Hz={display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0,paddingBottom:6,borderBottom:"1px solid #f1f5f9"},bh={display:"flex",gap:4,alignItems:"flex-start",width:"100%",minWidth:0},Fz={flex:1,minWidth:0},Kz={fontSize:11,color:"#64748b",marginBottom:2},Vz={display:"flex",gap:4,alignItems:"center",justifyContent:"flex-end"},Uz={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,color:"#475569",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},mh={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},qz={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},Gz={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},vh={fontSize:11,color:"#94a3b8",fontStyle:"italic"},yo={rowContainer:"Tbody",row:"Tr",cell:"Td",headerCell:"Th",colSpanProp:"colSpan",rowSpanProp:"rowSpan"};function yt(e){return{rowContainer:e?.rowContainer??yo.rowContainer,row:e?.row??yo.row,cell:e?.cell??yo.cell,headerCell:e?.headerCell??yo.headerCell,colSpanProp:e?.colSpanProp??yo.colSpanProp,rowSpanProp:e?.rowSpanProp??yo.rowSpanProp}}function jn(e){return e?Array.isArray(e.children)?e.children:[]:[]}function _h(e,t){const n=e.props?.[t],o=typeof n=="number"?n:typeof n=="string"?parseInt(n,10):NaN;return Number.isFinite(o)&&o>=1?Math.floor(o):1}function Oe(e,t){const n=yt(t),o=[],r=jn(e),s=[];r.forEach((f,b)=>{(jn(f).some(h=>h.name===n.row)||f.name===n.rowContainer||f.name==="Thead"||f.name==="Tfoot")&&s.push({container:f,containerIndex:b,isHeader:f.name==="Thead"})}),s.length===0&&r.some(f=>f.name===n.row)&&s.push({container:e,containerIndex:-1,isHeader:!1});const a=[],l=[];let d=0,c=0;const p=f=>{for(;a.length<=f;)a.push([]);return a[f]};s.forEach((f,b)=>{jn(f.container).filter(m=>m.name===n.row).forEach((m,h)=>{const v=[],y=p(d);let _=0;jn(m).filter(k=>k.name===n.cell||k.name===n.headerCell).forEach((k,x)=>{for(;y[_];)_++;const $=_h(k,n.colSpanProp),C=_h(k,n.rowSpanProp),S={cell:k,sectionIndex:b,rowIndexInSection:h,cellIndexInRow:x,gridRow:d,gridCol:_,colSpan:$,rowSpan:C,isHeader:k.name===n.headerCell};v.push(S);for(let D=0;D=0?(a.push(s.containerIndex),l=jn(e)[s.containerIndex]??e):l=e;let d=-1,c=-1,p=null;const f=jn(l);for(let m=0;m=r.gridRow&&t=r.gridCol&&nr){s=!0;break}if(s)break}s||t.add(r)}const n=Array.from(t).sort((r,s)=>r-s),o=[];for(let r=0;re.rows.find(l=>(l.cells[0]?.gridRow??-1)===a)?.sectionIndex??e.rows[a]?.sectionIndex??0,o=new Set([0,t]);for(let a=1;aa){l=!0;break}if(l)break}l||o.add(a)}const r=Array.from(o).sort((a,l)=>a-l),s=[];for(let a=0;at>=a.start&&t=o.length?{ok:!1,reason:"boundary"}:o[r].sectionIndex!==o[s].sectionIndex?{ok:!1,reason:"section"}:{ok:!0}}function Ti(e,t,n){const o=xh(e),r=o.findIndex(a=>t>=a.start&&t=o.length?{ok:!1,reason:"boundary"}:{ok:!0}}function Ye(e){return e?Array.isArray(e.children)?e.children:[]:[]}function _n(e,t,n){const o={...e.props??{}};n<=1?delete o[t]:o[t]=n;const r={...e,props:o};return Object.keys(o).length===0&&delete r.props,r}function Di(e,t,n=!1){const o={type:"basic",name:n?e.headerCell:e.cell},r=t?.props?.className;return typeof r=="string"&&r&&(o.props={className:r}),o.text="",o}function lr(e,t){return e.name===t.cell||e.name===t.headerCell}function nt(e,t,n,o){const r=t.sections[n];if(!r)return e;if(r.containerIndex===-1)return o(e);const s=Ye(e).map((a,l)=>l===r.containerIndex?o(a):a);return{...e,children:s}}function bt(e,t,n,o){let r=-1;const s=Ye(e).map(a=>a.name===t&&(r++,r===n)?o(a):a);return{...e,children:s}}function zi(e,t,n){let o=-1;const r=Ye(e);for(let s=0;s0?nt(e,r,r.sections.length-1,_=>({..._,children:[...Ye(_),y]})):{...e,children:[...Ye(e),y]}}const s=Math.max(-1,Math.min(n,r.rows.length-1)),a=s<0?r.rows[0]:r.rows[s],l=a.cells[0]?.gridRow??s,d=s<0?0:l+1,c=a.sectionIndex,p=s<0?0:a.rowIndexInSection+1,f=[],b=[];let g=0;for(;g0?Ue(r,d-1,g):null;y&&y.gridRow+y.rowSpan>d&&y.rowSpan>1?(b.push(y),g+=y.colSpan):(f.push(Di(o)),g+=1)}let m=e;for(const y of b)m=nt(m,r,y.sectionIndex,_=>bt(_,o.row,y.rowIndexInSection,w=>({...w,children:Ye(w).map((k,x)=>x===y.cellIndexInRow?_n(k,o.rowSpanProp,y.rowSpan+1):k)})));const h={type:"basic",name:o.row,children:f},v=Oe(m,t);return m=nt(m,v,c,y=>{const _=Ye(y);let w=0,k=_.length;for(let x=0;x<_.length;x++)if(_[x].name===o.row){if(w===p){k=x;break}w++}return{...y,children:[..._.slice(0,k),h,..._.slice(k)]}}),m}function kh(e,t,n){const o=yt(t),r=Oe(e,t);if(n<0||n>=r.rows.length||r.rows.length<=1)return e;const s=r.rows[n],a=s.cells[0]?.gridRow??n;let l=e;const d=new Set;for(let p=0;pbt(b,o.row,f.rowIndexInSection,g=>({...g,children:Ye(g).map((m,h)=>h===f.cellIndexInRow?_n(m,o.rowSpanProp,f.rowSpan-1):m)})))),p+=f?f.colSpan:1}const c=Oe(l,t);return l=nt(l,c,s.sectionIndex,p=>{let f=-1;const b=Ye(p).filter(g=>g.name===o.row?(f++,f!==s.rowIndexInSection):!0);return{...p,children:b}}),l}function Sh(e,t,n,o){const r=yt(t),s=Oe(e,t);if(!Ai(s,n,o).ok)return e;const a=wh(s),l=a.findIndex(h=>n>=h.start&&ns.rows.filter(v=>{const y=v.cells[0]?.gridRow??-1;return v.sectionIndex===f&&y>=h.start&&yv.rowIndexInSection),g=b(c),m=b(p);return g.length===0||m.length===0?e:nt(e,s,f,h=>{const v=[...Ye(h)],y=[];v.forEach((M,O)=>{M.name===r.row&&y.push(O)});const _=g.map(M=>y[M]).filter(M=>M!==void 0),w=m.map(M=>y[M]).filter(M=>M!==void 0);if(_.length===0||w.length===0)return h;const k=_.map(M=>v[M]),x=w.map(M=>v[M]),$=Math.min(..._)n>=m.start&&nk.gridCol>=f.start&&k.gridColk.gridCol>=b.start&&k.gridColk.cellIndexInRow),_=v.map(k=>k.cellIndexInRow),w=Oe(g,t);g=nt(g,w,m.sectionIndex,k=>bt(k,r.row,m.rowIndexInSection,x=>{const $=[...Ye(x)],C=y.map(M=>zi(x,r,M)).filter(M=>M>=0),S=_.map(M=>zi(x,r,M)).filter(M=>M>=0);if(C.length===0||S.length===0)return x;const D=C.map(M=>$[M]),E=S.map(M=>$[M]),I=Math.min(...C,...S),N=Math.max(...C,...S),T=[...E,...D],B=[...$.slice(0,I),...T,...$.slice(N+1)];return{...x,children:B}}))}return g}function $h(e,t,n){const o=yt(t),r=Oe(e,t);if(r.rows.length===0||r.colCount===0)return cl(e,t,-1);const s=Math.max(0,Math.min(n+1,r.colCount));let a=e;const l=new Set;for(const d of r.rows){const c=d.cells[0]?.gridRow??0,p=s>0?Ue(r,c,s-1):null,f=s1){if(!l.has(p.cell)){l.add(p.cell);const h=Oe(a,t);a=nt(a,h,p.sectionIndex,v=>bt(v,o.row,p.rowIndexInSection,y=>({...y,children:Ye(y).map((_,w)=>w===p.cellIndexInRow?_n(_,o.colSpanProp,p.colSpan+1):_)})))}continue}if(p&&p.gridRow0&&d.cells.every(h=>h.isHeader),m=Oe(a,t);a=nt(a,m,d.sectionIndex,h=>bt(h,o.row,d.rowIndexInSection,v=>{const y=[...Ye(v)];let _;if(b<0)_=y.findIndex(w=>lr(w,o)),_<0&&(_=y.length);else{const w=zi(v,o,b);_=w<0?y.length:w+1}return y.splice(_,0,Di(o,void 0,g)),{...v,children:y}}))}return a}function Eh(e,t,n){const o=yt(t),r=Oe(e,t);if(n<0||n>=r.colCount||r.colCount<=1)return e;let s=e;const a=new Set;for(const l of r.rows){const d=l.cells[0]?.gridRow??0,c=Ue(r,d,n);if(!(!c||a.has(c.cell)||c.gridRow1){const p=Oe(s,t);s=nt(s,p,c.sectionIndex,f=>bt(f,o.row,c.rowIndexInSection,b=>({...b,children:Ye(b).map((g,m)=>m===c.cellIndexInRow?_n(g,o.colSpanProp,c.colSpan-1):g)})))}else{const p=Oe(s,t);s=nt(s,p,c.sectionIndex,f=>bt(f,o.row,c.rowIndexInSection,b=>{let g=-1;const m=Ye(b).filter(h=>lr(h,o)?(g++,g!==c.cellIndexInRow):!0);return{...b,children:m}}))}}return s}function ul(e,t,n,o,r,s){const a=yt(t),l=Oe(e,t),d=Math.min(n,r),c=Math.max(n,r),p=Math.min(o,s),f=Math.max(o,s);if(d===c&&p===f)return{table:e,ok:!1,reason:"single"};if(!l.valid)return{table:e,ok:!1,reason:"invalid-grid"};const b=new Set;for(let y=d;y<=c;y++)for(let _=p;_<=f;_++){const w=Ue(l,y,_);if(!w)return{table:e,ok:!1,reason:"hole"};if(w.gridRowc||w.gridCol+w.colSpan-1>f)return{table:e,ok:!1,reason:"not-rectangular"};b.add(w)}const g=Ue(l,d,p),m=Array.from(b).filter(y=>y!==g);let h=nt(e,l,g.sectionIndex,y=>bt(y,a.row,g.rowIndexInSection,_=>({..._,children:Ye(_).map((w,k)=>{if(k!==g.cellIndexInRow)return w;let x=_n(w,a.colSpanProp,f-p+1);return x=_n(x,a.rowSpanProp,c-d+1),x})})));const v=new Map;for(const y of m){const _=`${y.sectionIndex}:${y.rowIndexInSection}`,w=v.get(_)??[];w.push(y),v.set(_,w)}for(const[y,_]of v){const w=parseInt(y.split(":")[0],10),k=_[0].rowIndexInSection,x=new Set(_.map(C=>C.cellIndexInRow)),$=Oe(h,t);h=nt(h,$,w,C=>bt(C,a.row,k,S=>{let D=-1;const E=Ye(S).filter(I=>lr(I,a)?(D++,!x.has(D)):!0);return{...S,children:E}}))}return{table:h,ok:!0}}function Ih(e,t,n,o){const r=yt(t),s=Oe(e,t),a=Ue(s,n,o);if(!a||a.colSpan<=1&&a.rowSpan<=1)return e;const l=a.gridRow,d=a.gridCol,c=a.gridRow+a.rowSpan-1,p=a.gridCol+a.colSpan-1,f=a.isHeader,b=typeof a.cell.props?.className=="string"?a.cell.props.className:void 0;let g=nt(e,s,a.sectionIndex,m=>bt(m,r.row,a.rowIndexInSection,h=>({...h,children:Ye(h).map((v,y)=>{if(y!==a.cellIndexInRow)return v;let _=_n(v,r.colSpanProp,1);return _=_n(_,r.rowSpanProp,1),_})})));for(let m=l;m<=c;m++)for(let h=d;h<=p;h++){if(m===l&&h===d)continue;const v=Oe(g,t),y=v.rows.find(k=>k.cells.some(x=>x.gridRow===m))??v.rows[m];if(!y)continue;let _=-1;for(const k of y.cells)k.gridRow===m&&k.gridColbt(k,r.row,y.rowIndexInSection,x=>{const $=[...Ye(x)];let C;if(_<0)C=$.findIndex(S=>lr(S,r)),C<0&&(C=$.length);else{const S=zi(x,r,_);C=S<0?$.length:S+1}return $.splice(C,0,Di(r,w,f)),{...x,children:$}}))}return g}function Ni(e,t,n,o,r){const s=yt(t),a=Oe(e,t),l=Ue(a,n,o);return l?nt(e,a,l.sectionIndex,d=>bt(d,s.row,l.rowIndexInSection,c=>({...c,children:Ye(c).map((p,f)=>{if(f!==l.cellIndexInRow)return p;const b={...p.props??{}};r.trim()===""?delete b.className:b.className=r;const g={...p,props:b};return Object.keys(b).length===0&&delete g.props,g})}))):e}function Rt(e,t,n,o,r,s){const a=yt(t),l=Oe(e,t),d=Ue(l,n,o);return d?nt(e,l,d.sectionIndex,c=>bt(c,a.row,d.rowIndexInSection,p=>({...p,children:Ye(p).map((f,b)=>{if(b!==d.cellIndexInRow)return f;const g={...f.props??{}},m={...g.style??{}};!s||s.trim()===""?delete m[r]:m[r]=s,Object.keys(m).length===0?delete g.style:g.style=m;const h={...f,props:g};return Object.keys(g).length===0&&delete h.props,h})}))):e}function bo(e,t,n,o,r,s,a){const l=yt(t),d=Oe(e,t),c=Ue(d,n,o);if(!c)return e;const p=a==="dark";return nt(e,d,c.sectionIndex,f=>bt(f,l.row,c.rowIndexInSection,b=>({...b,children:Ye(b).map((g,m)=>{if(m!==c.cellIndexInRow)return g;const h={...g.props??{}},v=typeof h.className=="string"?h.className:"",y=MC(v,s,r,p);y===""?delete h.className:h.className=y;const _={...g,props:h};return Object.keys(h).length===0&&delete _.props,_})})))}function Ah(e,t,n,o,r){const s=yt(t),a=Oe(e,t),l=Ue(a,n,o);return l?nt(e,a,l.sectionIndex,d=>bt(d,s.row,l.rowIndexInSection,c=>({...c,children:Ye(c).map((p,f)=>f===l.cellIndexInRow?{...p,text:r}:p)}))):e}function Th(e,t,n,o,r){const s=yt(t),a=Oe(e,t),l=Ue(a,n,o);return l?nt(e,a,l.sectionIndex,d=>bt(d,s.row,l.rowIndexInSection,c=>({...c,children:Ye(c).map((p,f)=>f===l.cellIndexInRow?r:p)}))):e}const Dh=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function Yz(e){return e.split(/\s+/).filter(Boolean)}function zh(e,t){for(const n of t)if(e===n||/^-?\d+$/.test(e.slice(n.length+1))&&e.startsWith(n+"-"))return!0;return!1}function Nh({className:e,catalog:t,t:n,onChange:o,colorScheme:r="light",onPresetToken:s,colorStyle:a,onColorStyle:l,disabled:d}){const c=t?.sides??[],p=t?.widths??[],f=t?.colors??[],b=r==="dark",g=u.useMemo(()=>c.map(E=>E.prefix),[c]),m=u.useMemo(()=>new Set(f.map(E=>E.token)),[f]),h=u.useMemo(()=>Yz(e),[e]),v=u.useMemo(()=>Zr(e,b),[e,b]),y=u.useMemo(()=>v.find(E=>m.has(E))??null,[v,m]),_=u.useMemo(()=>{const E=new Set;for(const I of c)h.some(T=>T===I.prefix||T.startsWith(I.prefix+"-")&&/^-?\d+$/.test(T.slice(I.prefix.length+1)))&&E.add(I.value);return E},[h,c]),w=u.useMemo(()=>{const E=h.find(N=>zh(N,g));if(!E)return"none";const I=p.filter(N=>N.value!=="none");for(const N of c){if(E===N.prefix)return I.find(T=>(T.suffix??"")==="")?.value??"thin";if(E.startsWith(N.prefix+"-")){const T=E.slice(N.prefix.length),B=I.find(M=>(M.suffix??"")===T);if(B)return B.value}}return"thin"},[h,g,c,p]);if(!t||c.length===0||p.length===0)return null;function k(E){return E.filter(I=>!zh(I,g))}function x(E,I){const N=k(h),T=p.find(O=>O.value===I);if(!T||I==="none"||E.size===0)return N.join(" ").trim();const B=T.suffix??"",M=[...N];for(const O of c)E.has(O.value)&&M.push(B?`${O.prefix}${B}`:O.prefix);return M.join(" ").trim()}const $=E=>{const I=new Set(_);I.has(E)?I.delete(E):(E==="all"?I.clear():I.delete("all"),I.add(E));const N=w==="none"?p.find(T=>T.value!=="none")?.value??"thin":w;o(x(I,N))},C=E=>{const I=_.size===0?new Set(["all"]):_;o(x(I,E))},S=E=>{s?.(E)},D=(E,I)=>E&&E.startsWith("$t:")?n(E.slice(3)):E||I;return i.jsxs("div",{className:"g7le-cell-border","data-testid":"g7le-cell-border",style:Xz,children:[i.jsx("div",{style:Jz,children:i.jsx("span",{style:Zz,children:n("layout_editor.table_editor.cell_border")})}),i.jsx("div",{style:pl,"data-testid":"g7le-cell-border-widths",children:p.map(E=>i.jsx("button",{type:"button",disabled:d,"data-testid":`g7le-cell-border-width-${E.value}`,"aria-pressed":w===E.value,onClick:()=>C(E.value),style:w===E.value?Mh:fl,children:D(E.label,E.value)},E.value))}),w!=="none"&&i.jsx("div",{style:pl,"data-testid":"g7le-cell-border-sides",children:c.map(E=>i.jsx("button",{type:"button",disabled:d,"data-testid":`g7le-cell-border-side-${E.value}`,"aria-pressed":_.has(E.value),onClick:()=>$(E.value),style:_.has(E.value)?Mh:fl,children:D(E.label,E.value)},E.value))}),w!=="none"&&(f.length>0||l)&&i.jsx(i.Fragment,{children:i.jsxs("div",{style:pl,"data-testid":"g7le-cell-border-colors",children:[f.map(E=>{const I=y===E.token;return i.jsx("button",{type:"button",disabled:d,title:D(E.label,E.value),"data-testid":`g7le-cell-border-color-${E.value}`,"aria-pressed":I,onClick:()=>S(E.token),style:{...Lh,background:E.swatch??"#fff",outline:I?"2px solid #2563eb":"1px solid #cbd5e1"}},E.value)}),l&&(()=>{const E=!!a&&f.some(N=>N.swatch&&N.swatch.toLowerCase()===a.toLowerCase()),I=!b&&!!a&&!E;return i.jsx("label",{title:n(b?"layout_editor.table_editor.dark_free_color_hint":"layout_editor.table_inplace.custom_color"),"data-testid":"g7le-cell-border-color-custom",style:{...Lh,position:"relative",overflow:"hidden",display:"inline-flex",alignItems:"center",justifyContent:"center",background:I&&Dh.test(a)?a:"conic-gradient(red, yellow, lime, aqua, blue, magenta, red)",outline:I?"2px solid #2563eb":"1px solid #cbd5e1",opacity:b?.4:1,cursor:b?"not-allowed":"pointer"},children:i.jsx("input",{type:"color",disabled:d||b,"data-testid":"g7le-cell-border-color-picker",value:a&&Dh.test(a)?a:"#000000",onChange:N=>l(N.target.value),style:{position:"absolute",width:0,height:0,opacity:0}})})})()]})})]})}const Xz={display:"flex",flexDirection:"column",gap:6},Jz={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},Zz={fontSize:12,fontWeight:600,color:"#475569"},pl={display:"flex",gap:4,flexWrap:"wrap",alignItems:"center"},fl={padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},Mh={...fl,border:"1px solid #2563eb",background:"#eff6ff",color:"#1d4ed8",fontWeight:600},Lh={width:22,height:22,borderRadius:5,padding:0,cursor:"pointer",boxSizing:"border-box"},Ph=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function Oh({colorStyle:e,className:t,catalog:n,t:o,colorScheme:r="light",onPresetToken:s,onCustomColor:a,onClear:l,disabled:d}){const c=n?.colors??[],p=r==="dark",f=e??"",b=Zr(t??"",p),g=c.find(_=>_.token&&b.includes(_.token))?.token??null,m=(_,w)=>_&&_.startsWith("$t:")?o(_.slice(3)):_||w,h=!g&&(p||f.trim()===""),v=!!f&&c.some(_=>_.swatch&&_.swatch.toLowerCase()===f.toLowerCase()),y=!p&&!!f&&!v;return i.jsxs("div",{className:"g7le-cell-fill","data-testid":"g7le-cell-fill",style:Qz,children:[i.jsx("div",{style:Rz,children:i.jsx("span",{style:eN,children:o("layout_editor.table_editor.cell_fill")})}),i.jsxs("div",{style:tN,"data-testid":"g7le-cell-fill-colors",children:[i.jsx("button",{type:"button",disabled:d,title:o("layout_editor.table_editor.cell_fill_none"),"data-testid":"g7le-cell-fill-none","aria-pressed":h,onClick:()=>l?.(),style:{...gl,background:"repeating-conic-gradient(#e2e8f0 0% 25%, #ffffff 0% 50%) 50% / 10px 10px",outline:h?"2px solid #2563eb":"1px solid #cbd5e1"}}),c.map(_=>{const w=!!_.token&&g===_.token,k=!p&&!!_.swatch&&f.toLowerCase()===(_.swatch??"").toLowerCase(),x=w||k,$=d||p&&!_.token;return i.jsx("button",{type:"button",disabled:$,title:m(_.label,_.value),"data-testid":`g7le-cell-fill-color-${_.value}`,"aria-pressed":x,onClick:()=>{_.token&&s?s(_.token):!p&&_.swatch&&a&&a(_.swatch)},style:{...gl,background:_.swatch??"#fff",outline:x?"2px solid #2563eb":"1px solid #cbd5e1",opacity:$?.4:1,cursor:$?"not-allowed":"pointer"}},_.value)}),a&&i.jsx("label",{title:o(p?"layout_editor.table_editor.dark_free_color_hint":"layout_editor.table_editor.cell_fill_custom"),"data-testid":"g7le-cell-fill-custom",style:{...gl,position:"relative",overflow:"hidden",display:"inline-flex",alignItems:"center",justifyContent:"center",background:y&&Ph.test(f)?f:"conic-gradient(red, yellow, lime, aqua, blue, magenta, red)",outline:y?"2px solid #2563eb":"1px solid #cbd5e1",opacity:p?.4:1,cursor:p?"not-allowed":"pointer"},children:i.jsx("input",{type:"color",disabled:d||p,"data-testid":"g7le-cell-fill-color-picker",value:f&&Ph.test(f)?f:"#ffffff",onChange:_=>a(_.target.value),style:{position:"absolute",width:0,height:0,opacity:0}})})]})]})}const Qz={display:"flex",flexDirection:"column",gap:6},Rz={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},eN={fontSize:12,fontWeight:600,color:"#475569"},tN={display:"flex",gap:4,flexWrap:"wrap",alignItems:"center"},gl={width:22,height:22,borderRadius:5,padding:0,cursor:"pointer",boxSizing:"border-box"};function nN(e){const t=/^(\d+)px$/.exec(e.trim());return t?parseInt(t[1],10):null}function Bh({paddingStyle:e,catalog:t,t:n,onChange:o,disabled:r}){const s=t?.steps??[],a=e??"",l=nN(a),d=(h,v)=>h&&h.startsWith("$t:")?n(h.slice(3)):h||v,c=s.some(h=>(h.px??0)===(l??-1)),p=l!==null&&!c?String(l):"",[f,b]=u.useState(p);u.useEffect(()=>{b(p)},[e]);const g=h=>{o(h&&h>0?`${h}px`:""),b("")},m=h=>{const v=parseInt(h,10);Number.isFinite(v)&&v>=0&&o(v>0?`${v}px`:"")};return i.jsxs("div",{className:"g7le-cell-padding","data-testid":"g7le-cell-padding",style:oN,children:[i.jsx("div",{style:rN,children:n("layout_editor.table_editor.cell_padding")}),i.jsxs("div",{style:iN,"data-testid":"g7le-cell-padding-steps",children:[s.map(h=>{const v=(h.px??0)===(l??-1)||!h.px&&a.trim()==="";return i.jsx("button",{type:"button",disabled:r,"data-testid":`g7le-cell-padding-step-${h.value}`,"aria-pressed":v,onClick:()=>g(h.px),style:v?sN:Wh,children:d(h.label,h.value)},h.value)}),i.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3},children:[i.jsx("input",{type:"number",min:0,disabled:r,"data-testid":"g7le-cell-padding-free",value:f,placeholder:n("layout_editor.table_editor.cell_padding_custom"),onChange:h=>b(h.target.value),onBlur:()=>f.trim()!==""&&m(f),onKeyDown:h=>{h.key==="Enter"&&f.trim()!==""&&m(f)},style:aN}),i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:"px"})]})]})]})}const oN={display:"flex",flexDirection:"column",gap:6},rN={fontSize:12,fontWeight:600,color:"#475569"},iN={display:"flex",gap:4,flexWrap:"wrap",alignItems:"center"},Wh={padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},sN={...Wh,border:"1px solid #2563eb",background:"#eff6ff",color:"#1d4ed8",fontWeight:600},aN={width:48,padding:"3px 5px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"};function jh({colorScheme:e,onChange:t,t:n,disabled:o}){const r=e==="dark";return i.jsxs("div",{className:"g7le-color-scheme-tabs","data-testid":"g7le-color-scheme-tabs",style:lN,children:[i.jsxs("div",{style:dN,children:[i.jsx("span",{style:cN,children:n("layout_editor.table_editor.cell_color")}),i.jsxs("div",{style:uN,children:[i.jsx("button",{type:"button",disabled:o,"data-testid":"g7le-color-scheme-light","aria-pressed":!r,onClick:()=>t("light"),style:r?hl:Hh,children:n("layout_editor.property_modal.scope.scheme_light")}),i.jsx("button",{type:"button",disabled:o,"data-testid":"g7le-color-scheme-dark","aria-pressed":r,onClick:()=>t("dark"),style:r?Hh:hl,children:n("layout_editor.property_modal.scope.scheme_dark")})]})]}),r&&i.jsx("div",{style:pN,"data-testid":"g7le-color-scheme-dark-hint",children:n("layout_editor.table_editor.dark_free_color_hint")})]})}const lN={display:"flex",flexDirection:"column",gap:3},dN={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},cN={fontSize:12,fontWeight:700,color:"#0f172a"},uN={display:"flex",gap:2},hl={padding:"2px 9px",fontSize:11,border:"none",borderBottom:"2px solid transparent",background:"transparent",color:"#94a3b8",cursor:"pointer"},Hh={...hl,color:"#1d4ed8",borderBottom:"2px solid #2563eb",fontWeight:600},pN={fontSize:10,color:"#94a3b8",fontStyle:"italic"},yl="dark:";function Fh(e){return typeof e=="string"?e.split(/\s+/).filter(Boolean):[]}function Kh(e,t){return t==="dark"?e.filter(n=>n.startsWith(yl)).map(n=>n.slice(yl.length)):e.filter(n=>!n.startsWith(yl))}const fN={none:0,thin:1,medium:2,thick:4},Vh={top:{w:"borderTopWidth",s:"borderTopStyle",c:"borderTopColor"},bottom:{w:"borderBottomWidth",s:"borderBottomStyle",c:"borderBottomColor"},left:{w:"borderLeftWidth",s:"borderLeftStyle",c:"borderLeftColor"},right:{w:"borderRightWidth",s:"borderRightStyle",c:"borderRightColor"}},Uh=["top","bottom","left","right"];function gN(e,t,n="light"){if(!e||!t)return{};const o=t.sides??[],r=t.widths??[],s=t.colors??[],a=Fh(e.props?.className);if(a.length===0&&!e.props?.style)return{};const l=[...r].filter(y=>y.value!=="none").sort((y,_)=>(_.suffix??"").length-(y.suffix??"").length),d={};for(const y of o)for(const _ of l){const w=_.suffix?`${y.prefix}${_.suffix}`:y.prefix;if(a.includes(w)){d[y.value]=_.value;break}}const c=e.props?.style??{},p=Kh(a,n),f=s.find(y=>p.includes(y.token))?.swatch??"",g=(n==="light"&&typeof c.borderColor=="string"?c.borderColor:"")||f||"#94a3b8",m=y=>{const _=Vh[y]?.c,w=_?c[_]:void 0;return typeof w=="string"&&w?w:g},h={},v=(y,_)=>{const w=Vh[y];if(!w)return;const k=fN[_]??1;h[w.w]=`${k}px`,h[w.s]=k>0?"solid":"none",k>0&&(h[w.c]=m(y))};if(d.all)for(const y of Uh)v(y,d.all);for(const y of Uh)d[y]&&v(y,d[y]);return h}function hN(e,t,n="light"){if(!e?.props)return{};const o=e.props.style??{},r={},s=Fh(e.props.className),a=t?.colors?.find(c=>c.token&&Kh(s,n).includes(c.token))?.swatch??"",d=(n==="light"&&typeof o.backgroundColor=="string"?o.backgroundColor:"")||a;return d&&(r.backgroundColor=d),typeof o.padding=="string"&&o.padding&&(r.padding=o.padding),r}const yN=/^\s*\$t:(custom\.[a-zA-Z0-9._-]+)\s*$/,bN=/^\s*\$t:([a-zA-Z0-9._-]+)\s*$/,mN=/\{\{.*?\}\}/;function qh(e,t,n){const o=e?.text;if(typeof o!="string")return{display:"",editable:!1,isKey:!1};const r=vt(o);if(r&&r.key.startsWith("custom.")){let a="";try{const l=Pt.getInstance().translate(r.key,{templateId:t,locale:n});a=l&&l!==r.key?l:""}catch{a=""}return{display:a,editable:!0,isKey:!0}}if(mN.test(o))return{display:o,editable:!1,isKey:!1};const s=bN.exec(o);if(s){const a=s[1];let l="";try{const d=Pt.getInstance().translate(a,{templateId:t,locale:n});l=d&&d!==a?d:""}catch{l=""}return{display:l,editable:!0,isKey:!0}}return{display:o,editable:!0,isKey:!1}}function bl(e){const t=sr(e);return t===null?{node:null,path:null}:{node:Ii(e,t),path:t}}function vN(e){if(!e||typeof e.text!="string")return null;const t=yN.exec(e.text);if(t)return t[1];const n=vt(e.text);return n&&n.key.startsWith("custom.")?n.key:null}function _N({node:e,params:t,t:n,onPatchNode:o,templateIdentifier:r,candidates:s}){const{state:a}=Qe(),l=a.selectedRoute?.layoutName??null,d=a.locale,c=r??a.templateIdentifier,p=u.useMemo(()=>t&&typeof t=="object"?t:null,[t]);u.useMemo(()=>yt(p),[p]);const f=u.useMemo(()=>Oe(e,p),[e,p]),b=u.useMemo(()=>{const U=p?.cellBorder;return U&&typeof U=="object"?U:null},[p]),g=u.useMemo(()=>{const U=p?.cellBackground;return U&&typeof U=="object"?U:null},[p]),m=u.useMemo(()=>{const U=p?.cellPadding;return U&&typeof U=="object"?U:null},[p]),[h,v]=u.useState(null),[y,_]=u.useState(null),[w,k]=u.useState({}),[x,$]=u.useState(!1),[C,S]=u.useState(null),[D,E]=u.useState(null),[I,N]=u.useState("light"),T=u.useCallback(U=>o(U),[o]),B=u.useMemo(()=>h?Ue(f,h.r,h.c):null,[f,h]),M=D!==null?D:h?.c??null,O=C!==null?C:h?.r??null,z=u.useMemo(()=>{const U=(b?.sides??[]).find(ke=>ke.value==="all")??(b?.sides??[])[0],ue=(b?.widths??[]).find(ke=>ke.value!=="none");if(!U||!ue)return[];const ge=ue.suffix??"";return[ge?`${U.prefix}${ge}`:U.prefix]},[b]),H=u.useCallback((U,ue,ge)=>{if(z.length===0)return U;const ke=(b?.sides??[]).map(Q=>Q.prefix),he=Ue(Oe(U,p),ue,ge),ne=(typeof he?.cell?.props?.className=="string"?he.cell.props.className:"").split(/\s+/).filter(Boolean);return ne.some(Q=>ke.some(de=>Q===de||Q.startsWith(de+"-")&&/^-?\d+$/.test(Q.slice(de.length+1))))?U:Ni(U,p,ue,ge,[...ne,...z].join(" ").trim())},[z,b,p]),P=u.useCallback(U=>{if(!h)return;const ue=Math.min(h.r,y?.r??h.r),ge=Math.max(h.r,y?.r??h.r),ke=Math.min(h.c,y?.c??h.c),he=Math.max(h.c,y?.c??h.c),j=new Set,ne=[];for(let Q=ue;Q<=ge;Q++)for(let de=ke;de<=he;de++)j.add(`${Q}:${de}`),ne.push({r:Q,c:de});let pe=e;for(const Q of ne){if(pe=H(pe,Q.r,Q.c),pe=Rt(pe,p,Q.r,Q.c,"borderColor",U),Q.r>0&&!j.has(`${Q.r-1}:${Q.c}`)){const de=Ue(Oe(pe,p),Q.r-1,Q.c);de&&(pe=Rt(pe,p,de.gridRow,de.gridCol,"borderBottomColor",U))}if(Q.c>0&&!j.has(`${Q.r}:${Q.c-1}`)){const de=Ue(Oe(pe,p),Q.r,Q.c-1);de&&(pe=Rt(pe,p,de.gridRow,de.gridCol,"borderRightColor",U))}}T(pe)},[h,y,e,p,T,H]),A=u.useCallback(U=>P(U),[P]),L=u.useMemo(()=>(b?.colors??[]).map(U=>U.token).filter(Boolean),[b]),F=u.useCallback(U=>{if(!h||L.length===0)return;const ue=Math.min(h.r,y?.r??h.r),ge=Math.max(h.r,y?.r??h.r),ke=Math.min(h.c,y?.c??h.c),he=Math.max(h.c,y?.c??h.c);let j=e;for(let ne=ue;ne<=ge;ne++)for(let pe=ke;pe<=he;pe++)j=H(j,ne,pe),j=bo(j,p,ne,pe,U,L,I);T(j)},[h,y,e,p,T,H,L,I]),Y=u.useMemo(()=>{if(I==="dark")return"";const U=B?.cell.props?.style;return typeof U?.borderColor=="string"?U.borderColor:""},[B,I]),V=u.useCallback((U,ue)=>{if(!h)return;const ge=Math.min(h.r,y?.r??h.r),ke=Math.max(h.r,y?.r??h.r),he=Math.min(h.c,y?.c??h.c),j=Math.max(h.c,y?.c??h.c);let ne=e;for(let pe=ge;pe<=ke;pe++)for(let Q=he;Q<=j;Q++)ne=Rt(ne,p,pe,Q,U,ue);T(ne)},[h,y,e,p,T]),X=u.useMemo(()=>(g?.colors??[]).map(U=>U.token).filter(U=>!!U),[g]),Z=u.useCallback(()=>h?{r0:Math.min(h.r,y?.r??h.r),r1:Math.max(h.r,y?.r??h.r),c0:Math.min(h.c,y?.c??h.c),c1:Math.max(h.c,y?.c??h.c)}:null,[h,y]),ie=u.useCallback(U=>{const ue=Z();if(!ue||X.length===0)return;let ge=e;for(let ke=ue.r0;ke<=ue.r1;ke++)for(let he=ue.c0;he<=ue.c1;he++)ge=bo(ge,p,ke,he,U,X,I);T(ge)},[Z,e,p,T,X,I]),oe=u.useCallback(U=>V("backgroundColor",U),[V]),G=u.useCallback(()=>{const U=Z();if(!U)return;let ue=e;for(let ge=U.r0;ge<=U.r1;ge++)for(let ke=U.c0;ke<=U.c1;ke++)ue=bo(ue,p,ge,ke,void 0,X,I),I==="light"&&(ue=Rt(ue,p,ge,ke,"backgroundColor",void 0));T(ue)},[Z,e,p,T,X,I]),ee=u.useCallback(U=>V("padding",U),[V]),fe=u.useMemo(()=>{if(I==="dark")return"";const U=B?.cell.props?.style;return typeof U?.backgroundColor=="string"?U.backgroundColor:""},[B,I]),K=u.useMemo(()=>typeof B?.cell.props?.className=="string"?B.cell.props.className:"",[B]),te=u.useMemo(()=>{const U=B?.cell.props?.style;return typeof U?.padding=="string"?U.padding:""},[B]),ye=u.useCallback(U=>U==="section"?n("layout_editor.table_editor.move_blocked_section"):"",[n]),Se=u.useCallback((U,ue)=>Ai(f,U,ue),[f]),De=u.useCallback((U,ue)=>Ti(f,U,ue),[f]),Ie=u.useCallback(U=>T(cl(e,p,U)),[e,p,T]),Ve=u.useCallback(U=>{T(kh(e,p,U)),v(null),_(null)},[e,p,T]),ze=u.useCallback((U,ue)=>T(Sh(e,p,U,ue)),[e,p,T]),Be=u.useCallback(U=>T($h(e,p,U)),[e,p,T]),Xe=u.useCallback(U=>{T(Eh(e,p,U)),v(null),_(null)},[e,p,T]),Ne=u.useCallback((U,ue)=>T(Ch(e,p,U,ue)),[e,p,T]),Je=u.useCallback(()=>{if(!h||!y)return;const U=ul(e,p,h.r,h.c,y.r,y.c);U.ok&&(T(U.table),v({r:Math.min(h.r,y.r),c:Math.min(h.c,y.c)}),_(null))},[e,p,h,y,T]),ve=u.useCallback(()=>{h&&(T(Ih(e,p,h.r,h.c)),_(null))},[e,p,h,T]),qe=u.useCallback(U=>{if(!h)return;const ue=Math.min(h.r,y?.r??h.r),ge=Math.max(h.r,y?.r??h.r),ke=Math.min(h.c,y?.c??h.c),he=Math.max(h.c,y?.c??h.c);let j=e;for(let ne=ue;ne<=ge;ne++)for(let pe=ke;pe<=he;pe++)j=Ni(j,p,ne,pe,U);T(j)},[e,p,h,y,T]),We=u.useCallback(async(U,ue)=>{const ge=`${U}:${ue}`,ke=w[ge];if(ke===void 0)return;const he=Ue(f,U,ue);if(!he)return;const{node:j,path:ne}=bl(he.cell);if(ne===null)return;const pe=qh(j,c,d);if(pe.editable){if(ke===pe.display){k(Q=>{const de={...Q};return delete de[ge],de});return}$(!0);try{const Q=vN(j);if(Q)await wr(c,Q,d,ke),await on(c,d);else{const de=await Yn(c,l,d,ke);if(de.kind==="ok"&&de.resource){const Ae=`$t:${de.resource.translation_key}`;if(ne.length===0)T(Ah(e,p,U,ue,Ae));else{const dt=ar(he.cell,ne,Ae);T(Th(e,p,U,ue,dt))}await on(c,d)}}}finally{$(!1),k(Q=>{const de={...Q};return delete de[ge],de})}}},[w,f,c,d,l,e,p,T]),ce=u.useMemo(()=>{if(!B)return null;const{node:U,path:ue}=bl(B.cell);return ue===null?null:{value:typeof U?.text=="string"?U.text:"",editable:!0}},[B]),q=u.useCallback(U=>{if(typeof U!="string"||U.length===0||!h)return;const ue=Ue(f,h.r,h.c);if(!ue)return;const ge=sr(ue.cell);if(ge!==null)if(ge.length===0)T(Ah(e,p,h.r,h.c,U));else{const ke=ar(ue.cell,ge,U);T(Th(e,p,h.r,h.c,ke))}},[h,f,e,p,T]),se=u.useCallback((U,ue,ge)=>{ge?_({r:U,c:ue}):(v({r:U,c:ue}),_(null))},[]),ae=u.useMemo(()=>Array.from({length:f.colCount},(U,ue)=>ue),[f.colCount]),be=!!(h&&y&&(h.r!==y.r||h.c!==y.c)),Ce=!!(B&&(B.colSpan>1||B.rowSpan>1)),$e=B&&typeof B.cell.props?.className=="string"?B.cell.props.className:"";return i.jsxs("div",{className:"g7le-node-editor g7le-node-editor--table","data-testid":"g7le-table-editor",style:xN,children:[i.jsx("div",{style:wN,children:n("layout_editor.table_editor.title")}),i.jsx("div",{style:{overflowX:"auto"},children:i.jsxs("table",{"data-testid":"g7le-table-editor-grid",style:kN,children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{style:SN}),ae.map(U=>{const ue=De(U,-1),ge=De(U,1),ke=M===U;return i.jsx("th",{style:CN,"data-testid":`g7le-table-colgutter-${U}`,onMouseEnter:()=>E(U),onMouseLeave:()=>E(he=>he===U?null:he),children:i.jsxs("div",{style:{...EN,visibility:ke?"visible":"hidden"},children:[i.jsx("button",{type:"button",title:ue.ok?n("layout_editor.table_editor.move_col_left"):ye(ue.reason)||n("layout_editor.table_editor.move_col_left"),disabled:!ue.ok||x,onClick:()=>Ne(U,-1),"data-testid":`g7le-table-col-left-${U}`,style:ue.ok?xn:Mi,children:"←"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.add_col"),disabled:x,onClick:()=>Be(U),"data-testid":`g7le-table-col-add-${U}`,style:xn,children:"+"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.remove_col"),disabled:f.colCount<=1||x,onClick:()=>Xe(U),"data-testid":`g7le-table-col-remove-${U}`,style:Gh,children:"✕"}),i.jsx("button",{type:"button",title:ge.ok?n("layout_editor.table_editor.move_col_right"):ye(ge.reason)||n("layout_editor.table_editor.move_col_right"),disabled:!ge.ok||x,onClick:()=>Ne(U,1),"data-testid":`g7le-table-col-right-${U}`,style:ge.ok?xn:Mi,children:"→"})]})},U)})]})}),i.jsx("tbody",{children:f.rows.map((U,ue)=>{const ge=U.cells[0]?.gridRow??ue,ke=O===ge;return i.jsxs("tr",{"data-testid":`g7le-table-row-${ge}`,onMouseEnter:()=>S(ge),onMouseLeave:()=>S(he=>he===ge?null:he),children:[i.jsx("td",{style:$N,"data-testid":`g7le-table-rowgutter-${ge}`,children:(()=>{const he=Se(ge,-1),j=Se(ge,1);return i.jsxs("div",{style:{...IN,visibility:ke?"visible":"hidden"},children:[i.jsx("button",{type:"button",title:he.ok?n("layout_editor.table_editor.move_row_up"):ye(he.reason)||n("layout_editor.table_editor.move_row_up"),disabled:!he.ok||x,onClick:()=>ze(ge,-1),"data-testid":`g7le-table-row-up-${ge}`,style:he.ok?xn:Mi,children:"↑"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.add_row"),disabled:x,onClick:()=>Ie(ge),"data-testid":`g7le-table-row-add-${ge}`,style:xn,children:"+"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.remove_row"),disabled:f.rows.length<=1||x,onClick:()=>Ve(ge),"data-testid":`g7le-table-row-remove-${ge}`,style:Gh,children:"✕"}),i.jsx("button",{type:"button",title:j.ok?n("layout_editor.table_editor.move_row_down"):ye(j.reason)||n("layout_editor.table_editor.move_row_down"),disabled:!j.ok||x,onClick:()=>ze(ge,1),"data-testid":`g7le-table-row-down-${ge}`,style:j.ok?xn:Mi,children:"↓"})]})})()}),U.cells.map(he=>{const j=`${he.gridRow}:${he.gridCol}`,{node:ne,path:pe}=bl(he.cell),Q=qh(ne,c,d),de=pe!==null&&Q.editable,Ae=pe===null,dt=w[j],pt=dt!==void 0?dt:Q.display,ot=h&&h.r===he.gridRow&&h.c===he.gridCol,Le=h&&y&&he.gridRow>=Math.min(h.r,y.r)&&he.gridRow<=Math.max(h.r,y.r)&&he.gridCol>=Math.min(h.c,y.c)&&he.gridCol<=Math.max(h.c,y.c);return i.jsx("td",{colSpan:he.colSpan,rowSpan:he.rowSpan,"data-testid":`g7le-table-cell-${he.gridRow}-${he.gridCol}`,onClick:je=>se(he.gridRow,he.gridCol,je.shiftKey),style:{...AN,...gN(he.cell,b,I),...hN(he.cell,g,I),...he.isHeader?TN:{},...ot?DN:{},...Le&&!ot?zN:{}},children:de?i.jsx("input",{type:"text","data-testid":`g7le-table-cell-input-${he.gridRow}-${he.gridCol}`,value:pt,placeholder:n("layout_editor.table_editor.cell_text"),disabled:x,onMouseDown:je=>{je.shiftKey&&je.preventDefault(),se(he.gridRow,he.gridCol,je.shiftKey)},onClick:je=>je.stopPropagation(),onChange:je=>k(Ze=>({...Ze,[j]:je.target.value})),onBlur:()=>void We(he.gridRow,he.gridCol),style:NN}):Ae?i.jsx("span",{"data-testid":`g7le-table-cell-struct-${he.gridRow}-${he.gridCol}`,style:Yh,children:n("layout_editor.table_editor.structural_cell")}):i.jsx("span",{style:Yh,children:Q.display})},j)})]},ue)})})]})}),i.jsxs("button",{type:"button","data-testid":"g7le-table-add-row-bottom",onClick:()=>Ie(f.rows.length-1),disabled:x,style:MN,children:["+ ",n("layout_editor.table_editor.add_row")]}),i.jsxs("div",{style:LN,"data-testid":"g7le-table-cell-tools",children:[i.jsx("button",{type:"button","data-testid":"g7le-table-merge",onClick:Je,disabled:!be||x,style:Xh,children:n("layout_editor.table_editor.merge_cells")}),i.jsx("button",{type:"button","data-testid":"g7le-table-unmerge",onClick:ve,disabled:!Ce||x,style:Xh,children:n("layout_editor.table_editor.unmerge_cells")})]}),B&&ce&&i.jsxs("div",{style:ON,"data-testid":"g7le-table-cell-i18n-section",children:[i.jsx("div",{style:BN,children:n("layout_editor.table_editor.cell_i18n_label")}),i.jsx(_t,{value:ce.value,onChange:q,t:n,placeholder:n("layout_editor.table_editor.cell_text"),testidPrefix:"g7le-table-cell-i18n",candidates:s,enableExpressionTree:!0,expressionTreeCollapsible:!0})]}),B&&i.jsxs("div",{style:PN,"data-testid":"g7le-table-cell-color-section",children:[i.jsx(jh,{colorScheme:I,onChange:N,t:n,disabled:x}),b&&i.jsx("div",{style:ml,"data-testid":"g7le-table-cell-border-row",children:i.jsx(Nh,{className:$e,catalog:b,t:n,onChange:qe,colorScheme:I,onPresetToken:F,colorStyle:Y,onColorStyle:A,disabled:x})}),i.jsx("div",{style:ml,"data-testid":"g7le-table-cell-fill-row",children:i.jsx(Oh,{colorStyle:fe,className:K,catalog:g,t:n,colorScheme:I,onPresetToken:ie,onCustomColor:oe,onClear:G,disabled:x})})]}),B&&i.jsx("div",{style:ml,"data-testid":"g7le-table-cell-padding-row",children:i.jsx(Bh,{paddingStyle:te,catalog:m,t:n,onChange:ee,disabled:x})}),B&&!b&&i.jsxs("label",{style:WN,"data-testid":"g7le-table-cell-border-row",children:[i.jsx("span",{style:jN,children:n("layout_editor.table_editor.cell_border")}),i.jsx("input",{type:"text","data-testid":"g7le-table-cell-border-input",value:$e,placeholder:n("layout_editor.table_editor.cell_class_placeholder"),onChange:U=>qe(U.target.value),disabled:x,style:HN})]}),!f.valid&&i.jsx("div",{"data-testid":"g7le-table-grid-warning",style:FN,children:n("layout_editor.table_editor.grid_invalid")}),i.jsx("div",{style:KN,children:n("layout_editor.table_editor.select_hint")})]})}const xN={display:"flex",flexDirection:"column",gap:8,width:"100%",marginBottom:12},wN={fontSize:12,fontWeight:700,color:"#0f172a"},kN={borderCollapse:"collapse",width:"auto"},SN={width:28,background:"transparent",border:"none"},CN={padding:2,border:"none",background:"transparent"},$N={padding:2,border:"none",background:"transparent",verticalAlign:"middle"},EN={display:"flex",gap:2,justifyContent:"center"},IN={display:"grid",gridTemplateColumns:"repeat(2, 16px)",gap:2,justifyContent:"center"},xn={width:16,height:16,lineHeight:"14px",padding:0,fontSize:10,border:"1px solid #cbd5e1",borderRadius:4,background:"#fff",color:"#475569",cursor:"pointer"},Gh={...xn,border:"1px solid #fecaca",color:"#dc2626"},Mi={...xn,cursor:"not-allowed",opacity:.4,color:"#94a3b8",borderColor:"#e2e8f0"},AN={border:"1px solid #cbd5e1",padding:0,width:64,minWidth:64,maxWidth:120,height:24,background:"#fff",cursor:"pointer"},TN={background:"#f1f5f9",fontWeight:600},DN={outline:"2px solid #2563eb",outlineOffset:-2},zN={background:"#dbeafe"},NN={width:"100%",boxSizing:"border-box",padding:"2px 5px",fontSize:11,height:22,lineHeight:"18px",border:"none",background:"transparent",outline:"none"},Yh={display:"block",padding:"2px 5px",fontSize:10,color:"#64748b",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:110},MN={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},LN={display:"flex",gap:6},Xh={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},PN={display:"flex",flexDirection:"column",gap:8,borderTop:"1px solid #f1f5f9",paddingTop:8},ON={display:"flex",flexDirection:"column",gap:6,borderTop:"1px solid #f1f5f9",paddingTop:8},BN={fontSize:12,fontWeight:700,color:"#0f172a"},ml={display:"flex",flexDirection:"column",gap:6},WN={display:"flex",alignItems:"center",gap:6},jN={fontSize:12,color:"#475569",minWidth:60},HN={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},FN={fontSize:11,color:"#b45309",background:"#fffbeb",border:"1px solid #fde68a",borderRadius:6,padding:"4px 6px"},KN={fontSize:11,color:"#94a3b8"},VN=/\{\{.*?\}\}/;function UN(e,t,n){const r=(e.props??{})[t];return Array.isArray(r)?r:r===void 0&&n?JSON.parse(JSON.stringify(n)):[]}function qN(e){return typeof e=="string"&&VN.test(e)}function vl(e,t,n){return e?e.startsWith("$t:")?t(e.slice(3)):e:n}function GN(e,t,n){return typeof e=="object"&&e!==null?e[t.key]:n?e:void 0}function YN(e,t,n,o){if(typeof e=="object"&&e!==null){const r={...e};return o===void 0?delete r[t.key]:r[t.key]=o,r}return n?o:{[t.key]:o}}function Jh({node:e,params:t,t:n,onPatchNode:o,templateIdentifier:r,candidates:s}){const a=typeof t?.arrayProp=="string"?t.arrayProp:null,l=Array.isArray(t?.fields)?t.fields:[],d=vl(typeof t?.itemLabel=="string"?t.itemLabel:void 0,n,n("layout_editor.array_editor.item")),c=t?.newItem,p=c&&typeof c=="object"?c:null,f=typeof c=="string"||typeof c=="number"?c:null,b=(l.find($=>$.primary)??l[0])?.key,g=(e.props??{})[a??""],m=Array.isArray(t?.defaultItems)?t.defaultItems:null,h=a?UN(e,a,m):[],v=u.useCallback($=>{if(!a)return;const C={...e.props??{}};C[a]=$,o({...e,props:C})},[a,e,o]),y=u.useCallback(()=>{if(p)return JSON.parse(JSON.stringify(p));if(f!==null)return f;const $={};for(const C of l)(C.widget??"text")==="boolean"?$[C.key]=!1:$[C.key]="";return $},[p,f,l]),_=u.useCallback(()=>{v([...h,y()])},[v,h,y]),w=u.useCallback($=>{v(h.filter((C,S)=>S!==$))},[v,h]),k=u.useCallback(($,C)=>{const S=$+C;if(S<0||S>=h.length)return;const D=[...h];[D[$],D[S]]=[D[S],D[$]],v(D)},[v,h]),x=u.useCallback(($,C,S)=>{const D=C.key===b,E=h.map((I,N)=>N===$?YN(I,C,D,S):I);v(E)},[h,v,b]);return a?qN(g)||g!==void 0&&!Array.isArray(g)?i.jsx("div",{className:"g7le-node-editor g7le-node-editor--array","data-testid":"g7le-array-editor-bound",style:oM,children:n("layout_editor.array_editor.bound_degraded")}):i.jsxs("div",{className:"g7le-node-editor g7le-node-editor--array","data-testid":"g7le-array-editor",style:XN,children:[i.jsx("div",{style:JN,children:n("layout_editor.array_editor.items_title")}),h.length===0&&i.jsx("div",{"data-testid":"g7le-array-empty",style:Qh,children:n("layout_editor.array_editor.empty")}),h.map(($,C)=>i.jsxs("div",{"data-testid":`g7le-array-row-${C}`,style:ZN,children:[i.jsxs("div",{style:QN,children:[i.jsxs("span",{style:RN,children:["#",C+1]}),i.jsx("div",{style:{flex:1}}),i.jsx("button",{type:"button","data-testid":`g7le-array-up-${C}`,title:n("layout_editor.array_editor.move_up"),disabled:C===0,onClick:()=>k(C,-1),style:Zh,children:"↑"}),i.jsx("button",{type:"button","data-testid":`g7le-array-down-${C}`,title:n("layout_editor.array_editor.move_down"),disabled:C===h.length-1,onClick:()=>k(C,1),style:Zh,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-array-remove-${C}`,title:n("layout_editor.array_editor.remove"),onClick:()=>w(C),style:tM,children:"✕"})]}),l.map(S=>{const D=S.widget??"text",E=S.key===b,I=vl(S.label,n,S.key),N=GN($,S,E),T=`g7le-array-field-${C}-${S.key}`;if(D==="boolean")return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsx("input",{type:"checkbox","data-testid":T,checked:N===!0,onChange:M=>x(C,S,M.target.checked)})]},S.key);if(D==="select"){const M=Array.isArray(S.options)?S.options:[];return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsxs("select",{"data-testid":T,value:N==null?"":String(N),onChange:O=>x(C,S,O.target.value===""?void 0:O.target.value),style:dr,children:[i.jsx("option",{value:"",children:"—"}),M.map((O,z)=>i.jsx("option",{value:String(O.value),children:vl(O.label,n,String(O.value))},z))]})]},S.key)}if(D==="i18n-text"){const M=typeof N=="string"?N:N==null?"":String(N);return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsx("div",{"data-testid":T,style:{flex:1,minWidth:0},children:i.jsx(_t,{value:M,onChange:O=>x(C,S,O===""?void 0:O),t:n,placeholder:I,testidPrefix:`${T}-i18n`,candidates:s,enableExpressionTree:!0,expressionTreeCollapsible:!0})})]},S.key)}if(D==="number"){const M=N==null?"":String(N);return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsx("input",{type:"number","data-testid":T,value:M,onChange:O=>{const z=O.target.value;x(C,S,z===""?void 0:Number(z))},style:dr})]},S.key)}if(D==="color"){const M=typeof N=="string"?N:"",O=/^#[0-9a-fA-F]{6}$/.test(M)?M:"#000000";return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsx("input",{type:"color","data-testid":`${T}-swatch`,value:O,onChange:z=>x(C,S,z.target.value),style:eM}),i.jsx("input",{type:"text","data-testid":T,value:M,placeholder:"#7C3AED",onChange:z=>x(C,S,z.target.value===""?void 0:z.target.value),style:dr})]},S.key)}if(D==="number-list"){const M=Array.isArray(N)?N.join(", "):"";return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsx("input",{type:"text","data-testid":T,value:M,placeholder:n("layout_editor.array_editor.number_list_placeholder"),onChange:O=>{const z=O.target.value.split(",").map(H=>H.trim()).filter(H=>H!=="").map(H=>Number(H)).filter(H=>!Number.isNaN(H));x(C,S,z)},style:dr})]},S.key)}const B=N==null?"":String(N);return i.jsxs("label",{style:Hn,children:[i.jsx("span",{style:Fn,children:I}),i.jsx("input",{type:"text","data-testid":T,value:B,placeholder:D==="icon"?n("layout_editor.array_editor.icon_placeholder"):I,onChange:M=>x(C,S,M.target.value===""?void 0:M.target.value),style:dr})]},S.key)})]},C)),i.jsx("button",{type:"button","data-testid":"g7le-array-add",onClick:_,style:nM,children:n("layout_editor.array_editor.add",{item:d})})]}):i.jsx("div",{className:"g7le-node-editor g7le-node-editor--array","data-testid":"g7le-array-editor-misconfigured",style:Qh,children:n("layout_editor.array_editor.no_array_prop")})}const XN={display:"flex",flexDirection:"column",gap:8,width:"100%",marginBottom:12},JN={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:2},ZN={display:"flex",flexDirection:"column",gap:4,padding:8,border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc"},QN={display:"flex",gap:4,alignItems:"center"},RN={fontSize:11,fontWeight:700,color:"#64748b"},Hn={display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},Fn={fontSize:11,color:"#475569",minWidth:64,flexShrink:0},dr={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},eM={width:32,height:28,padding:0,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",cursor:"pointer",flexShrink:0},Zh={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},tM={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},nM={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},Qh={fontSize:11,color:"#94a3b8",fontStyle:"italic"},oM={fontSize:11,color:"#b45309",fontStyle:"italic",padding:"4px 2px"};function rM(e,t){return e?e.startsWith("$t:")?t(e.slice(3)):e:null}function iM(e){const{params:t,t:n}=e,o=Array.isArray(t?.groups)?t.groups:[];return o.length===0?i.jsx("div",{className:"g7le-node-editor g7le-node-editor--array-group","data-testid":"g7le-array-group-misconfigured",style:dM,children:n("layout_editor.array_editor.no_array_prop")}):i.jsx("div",{className:"g7le-node-editor g7le-node-editor--array-group","data-testid":"g7le-array-group-editor",style:sM,children:o.map((r,s)=>{const a=rM(r.title,n),{title:l,...d}=r;return i.jsxs("div",{"data-testid":`g7le-array-group-${r.arrayProp??s}`,style:aM,children:[a&&i.jsx("div",{style:lM,children:a}),i.jsx(Jh,{...e,params:d})]},r.arrayProp??s)})})}const sM={display:"flex",flexDirection:"column",gap:16,width:"100%",marginBottom:12},aM={display:"flex",flexDirection:"column",gap:4},lM={fontSize:12,fontWeight:700,color:"#1e293b",borderBottom:"1px solid #e2e8f0",paddingBottom:4},dM={fontSize:11,color:"#94a3b8",fontStyle:"italic"},cM=/\{\{.*?\}\}/;function uM(e){return typeof e=="string"&&cM.test(e)}function pM(e,t,n){return e?e.startsWith("$t:")?t(e.slice(3)):e:n}function fM(e){const{node:t,params:n,t:o,onPatchNode:r}=e,s=typeof n?.arrayProp=="string"?n.arrayProp:null,a=typeof n?.idField=="string"?n.idField:"id",l=typeof n?.cellChildrenProp=="string"?n.cellChildrenProp:"cellChildren",d=typeof n?.cellChildComponent=="string"?n.cellChildComponent:"Div",c=pM(typeof n?.itemLabel=="string"?n.itemLabel:void 0,o,o("layout_editor.array_editor.item")),[p,f]=u.useState(null),b=s?(t.props??{})[s]:void 0,g=Array.isArray(b)?b:[],m=u.useCallback($=>{if(!s)return;const C={...t.props??{}};C[s]=$,r({...t,props:C})},[s,t,r]),h=u.useCallback(()=>{const $=n?.newItem;return $&&typeof $=="object"?JSON.parse(JSON.stringify($)):{[a]:"",[l]:[]}},[n,a,l]),v=u.useCallback(()=>{m([...g,h()])},[m,g,h]),y=u.useCallback($=>{m(g.filter((C,S)=>S!==$)),f(null)},[m,g]),_=u.useCallback(($,C)=>{const S=$+C;if(S<0||S>=g.length)return;const D=[...g];[D[$],D[S]]=[D[S],D[$]],m(D)},[m,g]),w=u.useCallback(($,C)=>{const S=g.map((D,E)=>E===$?{...D,[a]:C}:D);m(S)},[g,m,a]),k=u.useCallback($=>({type:"composite",name:"CardGridCell",children:Array.isArray($[l])?$[l]:[]}),[l]),x=u.useCallback($=>C=>{const S=Array.isArray(C.children)?C.children:[],D=g.map((E,I)=>I===$?{...E,[l]:S}:E);m(D)},[g,m,l]);return s?uM(b)||b!==void 0&&!Array.isArray(b)?i.jsx("div",{className:"g7le-node-editor g7le-node-editor--cell-tree","data-testid":"g7le-cell-tree-bound",style:SM,children:o("layout_editor.array_editor.bound_degraded")}):i.jsxs("div",{className:"g7le-node-editor g7le-node-editor--cell-tree","data-testid":"g7le-cell-tree-editor",style:gM,children:[i.jsx("div",{style:hM,children:o("layout_editor.cell_tree_editor.columns_title")}),g.length===0&&i.jsx("div",{"data-testid":"g7le-cell-tree-empty",style:ey,children:o("layout_editor.array_editor.empty")}),g.map(($,C)=>{const S=typeof $[a]=="string"?$[a]:"",D=p===C;return i.jsxs("div",{"data-testid":`g7le-cell-tree-row-${C}`,style:yM,children:[i.jsxs("div",{style:bM,children:[i.jsxs("span",{style:mM,children:["#",C+1]}),i.jsx("input",{type:"text","data-testid":`g7le-cell-tree-id-${C}`,value:S,placeholder:o("layout_editor.cell_tree_editor.id_placeholder"),onChange:E=>w(C,E.target.value),style:vM}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-up-${C}`,title:o("layout_editor.array_editor.move_up"),disabled:C===0,onClick:()=>_(C,-1),style:Rh,children:"↑"}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-down-${C}`,title:o("layout_editor.array_editor.move_down"),disabled:C===g.length-1,onClick:()=>_(C,1),style:Rh,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-remove-${C}`,title:o("layout_editor.array_editor.remove"),onClick:()=>y(C),style:_M,children:"✕"})]}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-toggle-${C}`,onClick:()=>f(D?null:C),style:xM,children:o(D?"layout_editor.cell_tree_editor.collapse_cells":"layout_editor.cell_tree_editor.expand_cells")}),D&&i.jsx("div",{"data-testid":`g7le-cell-tree-cells-${C}`,style:wM,children:i.jsx(yh,{...e,node:k($),params:{childComponent:d},onPatchNode:x(C)})})]},C)}),i.jsx("button",{type:"button","data-testid":"g7le-cell-tree-add",onClick:v,style:kM,children:o("layout_editor.cell_tree_editor.add_column",{item:c})})]}):i.jsx("div",{className:"g7le-node-editor g7le-node-editor--cell-tree","data-testid":"g7le-cell-tree-misconfigured",style:ey,children:o("layout_editor.array_editor.no_array_prop")})}const gM={display:"flex",flexDirection:"column",gap:8,width:"100%",marginBottom:12},hM={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:2},yM={display:"flex",flexDirection:"column",gap:6,padding:8,border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc"},bM={display:"flex",gap:4,alignItems:"center"},mM={fontSize:11,fontWeight:700,color:"#64748b",flexShrink:0},vM={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},Rh={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},_M={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},xM={padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",alignSelf:"flex-start"},wM={paddingLeft:8,borderLeft:"2px solid #e2e8f0"},kM={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},ey={fontSize:11,color:"#94a3b8",fontStyle:"italic"},SM={fontSize:11,color:"#b45309",fontStyle:"italic",padding:"4px 2px"};function CM(e,t,n){const o=Oe(e,t);if(!n||n.length===0)return{measured:[],grid:o};const r=[];for(const s of o.rows)for(const a of s.cells){const d=dl(e,a,t).map(p=>`children.${p}`).join("."),c=n.find(p=>p.path===d||p.path.endsWith("."+d));c&&r.push({ref:a,box:{top:c.top,left:c.left,width:c.width,height:c.height}})}return{measured:r,grid:o}}const _l=26,xl=50,wl=6,ty=44,ny=18,oy="g7le-table-inplace-empty-cell-style";function $M(){if(typeof document>"u"||document.getElementById(oy))return;const e=document.createElement("style");e.id=oy,e.textContent=".g7le-preview-frame td[data-editor-name],.g7le-preview-frame th[data-editor-name]{min-width:56px;height:38px;}.g7le-preview-frame table[data-editor-name]{min-width:120px;}",document.head.appendChild(e)}function EM({node:e,params:t,nodeBox:n,cellBoxes:o,selectedCellPath:r,colorScheme:s,t:a,onPatchNode:l,onRequestInlineEdit:d}){const c=u.useMemo(()=>t&&typeof t=="object"?t:null,[t]),{measured:p,grid:f}=u.useMemo(()=>CM(e,c,o),[e,c,o]),[b,g]=u.useState(null),[m,h]=u.useState(null),v=u.useMemo(()=>{if(!r)return null;for(const j of f.rows)for(const ne of j.cells){const pe=dl(e,ne,c).map(Q=>`children.${Q}`).join(".");if(r===pe||r.startsWith(pe+"."))return{r:ne.gridRow,c:ne.gridCol}}return null},[r,f,e,c]),y=u.useMemo(()=>b&&Ue(f,b.r,b.c)?b:v,[b,v,f]),[_,w]=u.useState(!1),[k,x]=u.useState(s==="dark"?"dark":"light"),[$,C]=u.useState(null),[S,D]=u.useState(null),E=u.useRef(null),I=u.useCallback(()=>{E.current!==null&&(clearTimeout(E.current),E.current=null)},[]),N=u.useCallback(()=>{I(),E.current=setTimeout(()=>{C(null),D(null),E.current=null},240)},[I]);u.useEffect(()=>()=>I(),[I]),u.useEffect(()=>{$M()},[]);const T=u.useCallback(j=>l(j),[l]),B=u.useMemo(()=>y?Ue(f,y.r,y.c):null,[f,y]),M=u.useMemo(()=>B&&typeof B.cell.props?.className=="string"?B.cell.props.className:"",[B]),O=u.useCallback(j=>T(cl(e,c,j)),[e,c,T]),z=u.useCallback(j=>T(kh(e,c,j)),[e,c,T]),H=u.useCallback((j,ne)=>T(Sh(e,c,j,ne)),[e,c,T]),P=u.useCallback(j=>T($h(e,c,j)),[e,c,T]),A=u.useCallback(j=>T(Eh(e,c,j)),[e,c,T]),L=u.useCallback((j,ne)=>T(Ch(e,c,j,ne)),[e,c,T]),F=u.useCallback(j=>{if(!B)return;const ne=B.gridRow,pe=B.gridCol,Q=j==="down"?ne+B.rowSpan:ne+B.rowSpan-1,de=j==="right"?pe+B.colSpan:pe+B.colSpan-1;if(Q>=f.rows.length||de>=f.colCount)return;const Ae=ul(e,c,ne,pe,Q,de);Ae.ok&&T(Ae.table)},[B,f,e,c,T]),Y=!!(B&&B.gridCol+B.colSpan!y||!m||!Ue(f,m.r,m.c)?null:{r0:Math.min(y.r,m.r),c0:Math.min(y.c,m.c),r1:Math.max(y.r,m.r),c1:Math.max(y.c,m.c)},[y,m,f]),Z=u.useMemo(()=>{if(!X)return[];const j=new Set,ne=[];for(const pe of f.rows)for(const Q of pe.cells)if(Q.gridRow>=X.r0&&Q.gridRow<=X.r1&&Q.gridCol>=X.c0&&Q.gridCol<=X.c1){const de=`${Q.gridRow}:${Q.gridCol}`;j.has(de)||(j.add(de),ne.push({r:Q.gridRow,c:Q.gridCol}))}return ne},[X,f]),ie=Z.length>1,oe=u.useCallback(()=>{if(!X)return;const j=ul(e,c,X.r0,X.c0,X.r1,X.c1);j.ok&&(T(j.table),h(null))},[X,e,c,T]),G=u.useCallback(()=>{y&&T(Ih(e,c,y.r,y.c))},[e,c,y,T]),ee=u.useMemo(()=>{const j=c?.cellBorder;return j&&typeof j=="object"?j:null},[c]),fe=u.useMemo(()=>{const j=c?.cellBackground;return j&&typeof j=="object"?j:null},[c]),K=u.useMemo(()=>{const j=c?.cellPadding;return j&&typeof j=="object"?j:null},[c]),te=u.useMemo(()=>{if(_){const j=new Set,ne=[];for(const pe of f.rows)for(const Q of pe.cells){const de=`${Q.gridRow}:${Q.gridCol}`;j.has(de)||(j.add(de),ne.push({r:Q.gridRow,c:Q.gridCol}))}return ne}return ie?Z:y?[{r:y.r,c:y.c}]:[]},[_,ie,Z,y,f]),ye=u.useCallback(j=>{if(te.length===0)return;let ne=e;for(const pe of te){const Q=(ee?.colors??[]).map(Ae=>Ae.token),de=j.split(/\s+/).filter(Ae=>Ae&&!Q.includes(Ae)).join(" ");ne=Ni(ne,c,pe.r,pe.c,de)}T(ne)},[e,c,te,ee,T]),Se=u.useMemo(()=>{const j=(ee?.sides??[]).find(Q=>Q.value==="all")??(ee?.sides??[])[0],ne=(ee?.widths??[]).find(Q=>Q.value!=="none");if(!j||!ne)return[];const pe=ne.suffix??"";return[pe?`${j.prefix}${pe}`:j.prefix]},[ee]),De=u.useCallback((j,ne,pe)=>{if(Se.length===0)return j;const Q=(ee?.sides??[]).map(Le=>Le.prefix),de=Ue(Oe(j,c),ne,pe),dt=(typeof de?.cell?.props?.className=="string"?de.cell.props.className:"").split(/\s+/).filter(Boolean);if(dt.some(Le=>Q.some(je=>Le===je||Le.startsWith(je+"-")&&/^-?\d+$/.test(Le.slice(je.length+1)))))return j;const ot=[...dt,...Se].join(" ").trim();return Ni(j,c,ne,pe,ot)},[Se,ee,c]),Ie=u.useCallback((j,ne)=>{if(j.length===0)return;const pe=new Set(j.map(de=>`${de.r}:${de.c}`));let Q=e;for(const de of j){if(Q=De(Q,de.r,de.c),Q=Rt(Q,c,de.r,de.c,"borderColor",ne),de.r>0&&!pe.has(`${de.r-1}:${de.c}`)){const Ae=Ue(Oe(Q,c),de.r-1,de.c);Ae&&(Q=Rt(Q,c,Ae.gridRow,Ae.gridCol,"borderBottomColor",ne))}if(de.c>0&&!pe.has(`${de.r}:${de.c-1}`)){const Ae=Ue(Oe(Q,c),de.r,de.c-1);Ae&&(Q=Rt(Q,c,Ae.gridRow,Ae.gridCol,"borderRightColor",ne))}}T(Q)},[e,c,T,De]),Ve=u.useMemo(()=>(ee?.colors??[]).map(j=>j.token).filter(Boolean),[ee]),ze=u.useCallback(j=>{if(te.length===0||Ve.length===0)return;let ne=e;for(const pe of te)ne=De(ne,pe.r,pe.c),ne=bo(ne,c,pe.r,pe.c,j,Ve,k);T(ne)},[te,e,c,T,De,Ve,k]),Be=u.useCallback(j=>Ie(te,j),[Ie,te]),Xe=u.useMemo(()=>{if(k==="dark")return"";const j=B?.cell.props?.style;return typeof j?.borderColor=="string"?j.borderColor:""},[B,k]),Ne=u.useCallback((j,ne)=>{if(te.length===0)return;let pe=e;for(const Q of te)pe=Rt(pe,c,Q.r,Q.c,j,ne);T(pe)},[te,e,c,T]),Je=u.useMemo(()=>(fe?.colors??[]).map(j=>j.token).filter(j=>!!j),[fe]),ve=u.useCallback(j=>{if(te.length===0||Je.length===0)return;let ne=e;for(const pe of te)ne=bo(ne,c,pe.r,pe.c,j,Je,k);T(ne)},[te,e,c,T,Je,k]),qe=u.useCallback(j=>Ne("backgroundColor",j),[Ne]),We=u.useCallback(()=>{if(te.length===0)return;let j=e;for(const ne of te)j=bo(j,c,ne.r,ne.c,void 0,Je,k),k==="light"&&(j=Rt(j,c,ne.r,ne.c,"backgroundColor",void 0));T(j)},[te,e,c,T,Je,k]),ce=u.useCallback(j=>Ne("padding",j),[Ne]),q=u.useMemo(()=>{if(k==="dark")return"";const j=B?.cell.props?.style;return typeof j?.backgroundColor=="string"?j.backgroundColor:""},[B,k]),se=u.useMemo(()=>typeof B?.cell.props?.className=="string"?B.cell.props.className:"",[B]),ae=u.useMemo(()=>{const j=B?.cell.props?.style;return typeof j?.padding=="string"?j.padding:""},[B]),be=u.useCallback(j=>{const ne=j.currentTarget,pe=ne.style.pointerEvents;ne.style.pointerEvents="none";const Q=document.elementFromPoint(j.clientX,j.clientY);ne.style.pointerEvents=pe;const de=Q?.closest?.("[data-dnd-handle-path]");de&&de.dispatchEvent(new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:j.clientX,clientY:j.clientY,pointerId:j.pointerId,pointerType:j.pointerType,button:j.button,isPrimary:!0}))},[]),Ce=u.useMemo(()=>{const j=new Map;for(const ne of p)j.has(ne.ref.gridCol)||j.set(ne.ref.gridCol,ne.box);return j},[p]),$e=u.useMemo(()=>{const j=new Map;for(const ne of p)j.has(ne.ref.gridRow)||j.set(ne.ref.gridRow,ne.box);return j},[p]);if(p.length===0)return null;const U=!!(B&&(B.colSpan>1||B.rowSpan>1)),ue=S!==null?S:y?.c??null,ge=$!==null?$:y?.r??null,ke=n.top-_l-wl-ty,he=n.left-xl-wl-ty;return i.jsxs("div",{className:"g7le-table-inplace","data-testid":"g7le-table-inplace",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:n2},children:[p.map(j=>{const ne=y&&y.r===j.ref.gridRow&&y.c===j.ref.gridCol,pe=X&&j.ref.gridRow>=X.r0&&j.ref.gridRow<=X.r1&&j.ref.gridCol>=X.c0&&j.ref.gridCol<=X.c1;return i.jsx("div",{"data-testid":`g7le-inplace-cell-${j.ref.gridRow}-${j.ref.gridCol}`,role:"button",tabIndex:-1,"aria-label":a("layout_editor.table_inplace.select_cell"),onMouseEnter:()=>{I(),C(j.ref.gridRow),D(j.ref.gridCol)},onMouseLeave:()=>{N()},onPointerDown:Q=>be(Q),onClick:Q=>{if(Q.stopPropagation(),Q.shiftKey&&(b||y))h({r:j.ref.gridRow,c:j.ref.gridCol});else{g({r:j.ref.gridRow,c:j.ref.gridCol}),h(null);const de=dl(e,j.ref,c).map(Ae=>`children.${Ae}`).join(".");d?.(de)}},style:{position:"absolute",top:j.box.top,left:j.box.left,width:j.box.width,height:j.box.height,minWidth:ny,minHeight:ny,boxSizing:"border-box",pointerEvents:"auto",cursor:"pointer",outline:ne?"2px solid #2563eb":"none",outlineOffset:-2,background:pe&&!ne?"rgba(37,99,235,0.14)":"transparent"}},`cell-${j.ref.gridRow}-${j.ref.gridCol}`)}),i.jsx("div",{"data-testid":"g7le-inplace-col-rail",onMouseEnter:I,onMouseLeave:N,style:{position:"absolute",top:ke,left:n.left,width:n.width,height:_l,pointerEvents:"none"},children:ue!==null&&Ce.has(ue)&&(()=>{const j=ue,ne=Ce.get(j),pe=Ti(f,j,-1),Q=Ti(f,j,1),de=ne.left-n.left;return i.jsxs("div",{"data-testid":`g7le-inplace-colgutter-${j}`,onMouseEnter:()=>{I(),D(j)},onMouseLeave:N,style:{position:"absolute",top:0,left:de,width:ne.width,minWidth:96,height:_l,display:"flex",gap:3,justifyContent:"center",alignItems:"center",pointerEvents:"auto"},children:[i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.move_col_left"),disabled:!pe.ok,onClick:()=>L(j,-1),"data-testid":`g7le-inplace-col-left-${j}`,style:pe.ok?wn:Li,children:"←"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.add_col"),onClick:()=>P(j),"data-testid":`g7le-inplace-col-add-${j}`,style:wn,children:"+"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.remove_col"),disabled:f.colCount<=1,onClick:()=>A(j),"data-testid":`g7le-inplace-col-remove-${j}`,style:ry,children:"✕"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.move_col_right"),disabled:!Q.ok,onClick:()=>L(j,1),"data-testid":`g7le-inplace-col-right-${j}`,style:Q.ok?wn:Li,children:"→"})]},`colgut-${j}`)})()}),i.jsx("div",{"data-testid":"g7le-inplace-row-rail",style:{position:"absolute",top:n.top,left:he,width:xl,height:n.height,pointerEvents:"none"},children:ge!==null&&$e.has(ge)&&(()=>{const j=ge,ne=$e.get(j),pe=Ai(f,j,-1),Q=Ai(f,j,1),de=ne.top-n.top;return i.jsxs("div",{"data-testid":`g7le-inplace-rowgutter-${j}`,onMouseEnter:()=>{I(),C(j)},onMouseLeave:N,style:{position:"absolute",top:de,left:0,width:xl,height:ne.height,minHeight:48,display:"grid",gridTemplateColumns:"repeat(2, 22px)",gridAutoRows:"22px",gap:3,justifyContent:"center",alignContent:"center",pointerEvents:"auto"},children:[i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.move_row_up"),disabled:!pe.ok,onClick:()=>H(j,-1),"data-testid":`g7le-inplace-row-up-${j}`,style:pe.ok?wn:Li,children:"↑"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.add_row"),onClick:()=>O(j),"data-testid":`g7le-inplace-row-add-${j}`,style:wn,children:"+"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.remove_row"),disabled:f.rows.length<=1,onClick:()=>z(j),"data-testid":`g7le-inplace-row-remove-${j}`,style:ry,children:"✕"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.move_row_down"),disabled:!Q.ok,onClick:()=>H(j,1),"data-testid":`g7le-inplace-row-down-${j}`,style:Q.ok?wn:Li,children:"↓"})]},`rowgut-${j}`)})()}),i.jsxs("div",{"data-testid":"g7le-inplace-corner-add",style:{position:"absolute",top:n.top+n.height+wl,left:n.left,display:"flex",flexDirection:"column",gap:6,pointerEvents:"auto",minWidth:200,maxWidth:Math.max(240,n.width),background:"#fff",border:"1px solid #e2e8f0",borderRadius:8,padding:8,boxShadow:"0 2px 8px rgba(0,0,0,0.12)"},children:[i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[i.jsxs("button",{type:"button","data-testid":"g7le-inplace-add-row-bottom",onClick:()=>O(f.rows.length-1),style:iy,children:["+ ",a("layout_editor.table_inplace.add_row")]}),i.jsxs("button",{type:"button","data-testid":"g7le-inplace-add-col-right",onClick:()=>P(f.colCount-1),style:iy,children:["+ ",a("layout_editor.table_inplace.add_col")]})]}),!y&&i.jsx("div",{"data-testid":"g7le-inplace-select-hint",style:{fontSize:11,color:"#94a3b8",borderTop:"1px solid #f1f5f9",paddingTop:6},children:a("layout_editor.table_inplace.select_cell_hint")}),y&&i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,borderTop:"1px solid #f1f5f9",paddingTop:6},children:[ie&&i.jsx("div",{"data-testid":"g7le-inplace-range-count",style:{fontSize:11,color:"#2563eb"},children:a("layout_editor.table_inplace.range_selected",{count:Z.length})}),i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[ie?i.jsx("button",{type:"button","data-testid":"g7le-inplace-merge-range",onClick:oe,style:cr,children:a("layout_editor.table_inplace.merge_range")}):i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button","data-testid":"g7le-inplace-merge-right",disabled:!Y,onClick:()=>F("right"),style:Y?cr:kl,children:a("layout_editor.table_inplace.merge_right")}),i.jsx("button",{type:"button","data-testid":"g7le-inplace-merge-down",disabled:!V,onClick:()=>F("down"),style:V?cr:kl,children:a("layout_editor.table_inplace.merge_down")})]}),i.jsx("button",{type:"button","data-testid":"g7le-inplace-unmerge",disabled:!U,onClick:G,style:U?cr:kl,children:a("layout_editor.table_inplace.unmerge")})]}),i.jsxs("div",{"data-testid":"g7le-inplace-cell-color",style:{borderTop:"1px solid #f1f5f9",paddingTop:6,display:"flex",flexDirection:"column",gap:6},children:[i.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"#475569",cursor:"pointer"},children:[i.jsx("input",{type:"checkbox","data-testid":"g7le-inplace-border-all-toggle",checked:_,onChange:j=>w(j.target.checked)}),a("layout_editor.table_inplace.border_apply_all")]}),i.jsx(jh,{colorScheme:k,onChange:x,t:a}),ee&&i.jsx("div",{"data-testid":"g7le-inplace-cell-border",children:i.jsx(Nh,{className:_?"":M,catalog:ee,t:a,onChange:ye,colorScheme:k,onPresetToken:ze,colorStyle:_?"":Xe,onColorStyle:Be})}),i.jsx("div",{"data-testid":"g7le-inplace-cell-fill",children:i.jsx(Oh,{colorStyle:_?"":q,className:_?"":se,catalog:fe,t:a,colorScheme:k,onPresetToken:ve,onCustomColor:qe,onClear:We})})]}),i.jsx("div",{"data-testid":"g7le-inplace-cell-padding",style:{borderTop:"1px solid #f1f5f9",paddingTop:6},children:i.jsx(Bh,{paddingStyle:_?"":ae,catalog:K,t:a,onChange:ce})})]})]})]})}const wn={width:22,height:22,lineHeight:"20px",padding:0,fontSize:13,border:"1px solid #cbd5e1",borderRadius:5,background:"#fff",color:"#475569",cursor:"pointer",boxShadow:"0 1px 3px rgba(0,0,0,0.18)"},ry={...wn,border:"1px solid #fecaca",color:"#dc2626"},Li={...wn,cursor:"not-allowed",opacity:.4,color:"#94a3b8",borderColor:"#e2e8f0"},cr={padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.12)"},kl={...cr,cursor:"not-allowed",opacity:.4},iy={padding:"3px 8px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"};let sy=!1;function IM(){sy||(Bn("children",yh),Bn("table",_N),Bn("array",Jh),Bn("array-group",iM),Bn("array-cell-tree",fM),Va("table",EM),sy=!0)}function AM(){if(typeof window>"u")return;const e=window.G7Core;if(!e)return;const t=e.layoutEditor,n=Array.isArray(t?.__queue)?t.__queue:[],o=Array.isArray(t?.__readyCallbacks)?t.__readyCallbacks:[];e.layoutEditor={registerWidget:Ge,registerNodeEditor:Bn,registerCanvasOverlay:Va,onReady:r=>{typeof r=="function"&&r()}};for(const r of n){const[s,...a]=r;try{s==="widget"?Ge(a[0],a[1]):s==="nodeEditor"?Bn(a[0],a[1]):s==="canvasOverlay"&&Va(a[0],a[1])}catch{}}for(const r of o)try{r()}catch{}}const TM=1280;Pz(),IM(),AM();async function DM(e){if(typeof fetch!="function")return[];try{const t=await fetch(nn(`/api/admin/templates/${encodeURIComponent(e)}/editor/permission-candidates`,"json"),{credentials:"same-origin",headers:Me()});if(!t.ok)return[];const o=(await t.json().catch(()=>null))?.data?.permissions;if(!Array.isArray(o))return[];const r=[];for(const s of o)if(s&&typeof s=="object"){const a=s.key,l=s.name;typeof a=="string"&&a.length>0&&r.push({value:a,label:typeof l=="string"&&l?l:a})}return r}catch{return[]}}function zM({templateIdentifier:e}){a8({templateIdentifier:e}),l8(e);const{state:t,dispatch:n}=Qe(),{t:o}=et(),r=vo(),s=Bp(),a=g8(),l=t.selectedRoute?.layoutName??null,d=m8(e,l),c=t.editMode==="extension",p=u.useMemo(()=>c?y8(a):s,[c,a,s]),[f,b]=u.useState(null),[g,m]=u.useState(null),[h,v]=u.useState([]),[y,_]=u.useState("user"),[w,k]=u.useState(null),[x,$]=u.useState(null),[C,S]=u.useState([]);u.useEffect(()=>{let q=!1;return(async()=>{try{const se=await fetch(nn(`/api/templates/${encodeURIComponent(e)}/components`,"json"),{credentials:"same-origin",headers:{Accept:"application/json"}});if(!se.ok)return;const ae=await se.json().catch(()=>null);!q&&ae&&typeof ae=="object"&&b(ae)}catch{}})(),()=>{q=!0}},[e]),u.useEffect(()=>{let q=!1;return(async()=>{const{spec:se,sampleGlobalSources:ae}=await Sb({templateIdentifier:e,coreSeed:v8()});q||(m(se),v(ae),MM(e,se,ae))})(),()=>{q=!0}},[e]),u.useEffect(()=>{let q=!1;return(async()=>{if(typeof fetch=="function")try{const se=await fetch(`/api/admin/templates/${encodeURIComponent(e)}`,{credentials:"same-origin",headers:Me()});if(!se.ok)return;const be=(await se.json().catch(()=>null))?.data,Ce=be?.type;q||((Ce==="admin"||Ce==="user")&&_(Ce),typeof be?.name=="string"&&be.name&&k(be.name),typeof be?.version=="string"&&be.version&&$(be.version))}catch{}})(),()=>{q=!0}},[e]),u.useEffect(()=>{let q=!1;return(async()=>{if(typeof fetch=="function")try{const se=await fetch("/api/admin/templates/?per_page=100&page=1",{credentials:"same-origin",headers:Me()});if(!se.ok)return;const be=(await se.json().catch(()=>null))?.data?.data;if(!q&&Array.isArray(be)){const Ce=[];for(const $e of be){if(!$e||typeof $e!="object")continue;const U=$e.identifier;if(typeof U!="string"||!U||$e.is_pending===!0)continue;const ge=$e.type==="admin"?"admin":"user",ke=$e.name,he=$e.version;Ce.push({identifier:U,name:typeof ke=="string"?ke:U,version:typeof he=="string"?he:"",type:ge})}S(Ce)}}catch{}})(),()=>{q=!0}},[e]);const D=g?.nesting??null,E=t.selectedRoute?.path??null,I=t.editMode,N=t.selectedRoute?.layoutName??(c?a.document?.hostLayoutName??null:null),T=t.routeTree,B=u.useMemo(()=>{if(I!=="extension"||!N)return null;const q=Cl(T,N);return q||`__base__/${N}`},[I,N,T]),M=c&&t.returnRoute===null&&!!N;u.useEffect(()=>{if(!M||!N)return;const q=Cl(T,N);q&&n({type:"SET_RETURN_ROUTE",route:{path:q,layoutName:N}})},[M,N,T,n]),u.useEffect(()=>{const q=jD(I,E,B),se=HD(g?.states?.groups,q);n({type:"SET_AVAILABLE_STATES",states:se,activeStateId:FD(se)})},[g,I,E,B,n]);const[O,z]=u.useState([]);u.useEffect(()=>{let q=!1;return(async()=>{const se=await DM(e);q||z(se)})(),()=>{q=!0}},[e]),d8(),c8();const H=u.useCallback(q=>{const se=t.routeTree,ae=q.split("?")[0]?.split("#")[0]??q;return NM(se,ae)?"route_in_tree":"route_not_in_tree"},[t.routeTree]),P=u.useCallback(q=>{const se=q.split("?")[0]?.split("#")[0]??q,ae=Sl(t.routeTree,se);ae&&(p.isDirty&&!(!(typeof window<"u")||window.confirm(o("layout_editor.chrome.dirty_guard.message")))||n({type:"SELECT_ROUTE",route:{path:ae.path,layoutName:ae.layoutName}}))},[t.routeTree,p.isDirty,n]),A=u.useRef([]),L=u.useCallback(q=>{A.current=q},[]),[F,Y]=u.useState(null),V=u.useCallback(()=>Y(null),[]),X=u.useRef(null),Z=u.useRef(null);u.useEffect(()=>{const q=Z.current,se=X.current;if(!q||!se||typeof ResizeObserver>"u")return;const ae=()=>{se.style.setProperty("--g7le-header-h",`${Math.round(q.getBoundingClientRect().height)}px`)};ae();const be=new ResizeObserver(ae);return be.observe(q),()=>be.disconnect()},[]);const ie=u.useCallback(()=>{p.reload()},[p]),oe=u.useCallback(()=>{p.isDirty&&!(!(typeof window<"u")||window.confirm(o("layout_editor.chrome.dirty_guard.message")))||window.G7Core?.dispatch?.({handler:"openWindow",params:{path:`/admin/templates/${y}`,target:"_self"}})},[p.isDirty,o,y]),G=u.useCallback(q=>{if(!q||q===e||p.isDirty&&!(typeof window<"u"?window.confirm(o("layout_editor.chrome.dirty_guard.message")):!0))return;const se=ia(q);window.G7Core?.dispatch?.({handler:"openWindow",params:{path:se,target:"_self"}})},[e,p.isDirty,o]),ee=u.useCallback(()=>{const q=r.open({ariaLabel:o("layout_editor.custom_assets.title"),width:860,maxHeightRatio:.86,content:u.createElement(BE,{templateIdentifier:e,t:o,onClose:()=>r.close(q)})})},[r,e,o]),fe=typeof window<"u"&&(!!window.G7Config?.customAssetsDisabled||new URLSearchParams(window.location.search).get("custom")==="off"),K=u.useCallback(()=>{if(typeof window>"u"||p.isDirty&&!window.confirm(o("layout_editor.chrome.dirty_guard.message")))return;const q=new URL(window.location.href);if(fe){if(q.searchParams.delete("custom"),q.toString()===window.location.href){window.location.reload();return}}else q.searchParams.set("custom","off");window.G7Core?.dispatch?.({handler:"openWindow",params:{path:`${q.pathname}${q.search}${q.hash}`,target:"_self"}})},[p.isDirty,fe,o]),te=u.useCallback(()=>{const q=w7(e,t.selectedRoute?.path??null);window.G7Core?.dispatch?.({handler:"openWindow",params:{path:q}})},[e,t.selectedRoute]),ye=u.useCallback(()=>{const q=t.selectedRoute?.layoutName??"";if(!q)return;const se=r.open({ariaLabel:o("layout_editor.attachment_manager.title"),width:720,maxHeightRatio:.82,content:u.createElement(Fl,{templateIdentifier:e,layoutName:q,t:o,onClose:()=>r.close(se)})})},[r,e,t.selectedRoute,o]),Se=u.useCallback(()=>{const q=t.selectedRoute?.layoutName??"";if(!q)return;const se=ub(s.document?.raw??{}),ae=r.open({ariaLabel:o("layout_editor.translation_manager.title"),width:720,maxHeightRatio:.82,content:u.createElement(Nm,{templateIdentifier:e,layoutName:q,t:o,referencedKeys:se,onClose:()=>r.close(ae)})})},[r,e,t.selectedRoute,o,s.document]),De=u.useCallback((q,se)=>{const ae=window.G7Core;if(ae&&typeof ae.t=="function"){const be=ae.t(q,se);if(be&&be!==q&&!be.startsWith("$t:"))return be}return o(q,se)},[o]),Ie=u.useCallback(()=>{if(!t.selectedRoute||t.editMode==="extension"||t.editMode==="iteration_item")return;const q=r.open({ariaLabel:o("layout_editor.page_settings.title",{name:t.selectedRoute.path??""}),width:1080,maxHeightRatio:.88,closeOnEscape:!1,content:u.createElement(M$,{templateIdentifier:e,spec:g,t:o,resolveLabel:De,permissionCandidates:O,onClose:()=>r.close(q)})})},[r,t.selectedRoute,t.editMode,o,De,e,g,O]),Ve=u.useCallback(async()=>{const q=await d.createPreview(s.document?.raw??null);if(q.kind!=="success"){const se=q.kind==="network_error"?q.message:o("layout_editor.preview_action.no_document");typeof window<"u"&&window.alert(se)}},[d,s.document,o]),ze=u.useCallback(()=>{const q=t.selectedRoute?.layoutName??"",se=t.selectedRoute?.path??"",ae=t.editMode==="extension"&&se.startsWith("__extension__/")?se.slice(14):null,be=ae?{kind:"extension",extensionId:ae}:q?{kind:"layout",layoutName:q}:null;if(!be)return;const Ce=r.open({ariaLabel:o("layout_editor.version_history.title"),width:640,maxHeightRatio:.82,content:u.createElement(mE,{templateIdentifier:e,target:be,t:o,onRestored:async $e=>{typeof $e=="number"&&(be.kind==="extension"?n({type:"SET_EXTENSION_VERSION",extensionId:be.extensionId,version:$e}):n({type:"SET_LAYOUT_VERSION",layoutName:be.layoutName,version:$e})),await p.reload()},onClose:()=>r.close(Ce)})})},[r,e,t.selectedRoute,t.editMode,o,p,n]),Be=p.dirtyKeys.size>0||p.isDirty;u.useEffect(()=>{if(!Be)return;const q=se=>{se.preventDefault(),se.returnValue=""};return window.addEventListener("beforeunload",q),()=>window.removeEventListener("beforeunload",q)},[Be]);const Xe=u.useCallback(()=>{!p.isDirty||!(!(typeof window<"u")||window.confirm(o("layout_editor.chrome.reset_guard.message")))||p.reload()},[p,o]),Ne=u.useCallback(async()=>{const q=await p.save({sessionAddedPaths:A.current});Y(q),q.kind==="success"&&typeof q.newContentVersion=="number"&&(q.savedExtensionId?n({type:"SET_EXTENSION_VERSION",extensionId:q.savedExtensionId,version:q.newContentVersion}):q.savedLayoutName&&n({type:"SET_LAYOUT_VERSION",layoutName:q.savedLayoutName,version:q.newContentVersion}))},[p,n]),Je=u.useCallback(()=>{const q=r.open({ariaLabel:o("layout_editor.shortcuts.title"),width:560,maxHeightRatio:.85,content:u.createElement(GE,{t:o,onClose:()=>r.close(q)})})},[r,o]),ve=u.useMemo(()=>({save:()=>{Ne()},exit:oe,editCode:te,reset:Xe,translations:Se,addElement:()=>{t.selectedRoute&&n({type:"TOGGLE_PALETTE"})},help:Je,preview:()=>{t.selectedRoute?.layoutName&&Ve()}}),[Ne,oe,te,Xe,Se,t.selectedRoute,n,Je,Ve]),[qe,We]=u.useState(!1);u.useEffect(()=>{const q=window.setInterval(()=>{We(!!window.__g7LayoutEditorHasSelection)},200);return()=>window.clearInterval(q)},[]),gp({handlers:ve,hasSelection:qe});const ce=p;return t.routesError?i.jsx("div",{className:"g7le-chrome g7le-chrome--routes-error","data-testid":"g7le-chrome-routes-error",style:{position:"fixed",inset:0,display:"flex",background:"#f8fafc",color:"#0f172a",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif',fontSize:13,lineHeight:1.5,zIndex:9e3},children:i.jsx(Ja,{error:t.routesError})}):i.jsx("div",{className:"g7le-chrome","data-testid":"g7le-chrome",ref:X,style:{position:"static",minHeight:"100vh",minWidth:TM,background:"#f8fafc",color:"#0f172a",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif',fontSize:13,lineHeight:1.5,zIndex:9e3},children:i.jsxs(Ny,{value:ce,children:[c&&a.needsHostPicker&&a.document&&i.jsx(b8,{hostLayouts:a.document.hostLayouts,extensionLabel:null,onSelect:a.selectHost}),i.jsxs("div",{className:"g7le-chrome__header","data-testid":"g7le-chrome-header",ref:Z,style:{position:"sticky",top:0,zIndex:20,background:"#f8fafc"},children:[i.jsx(Hy,{onSave:()=>{Ne()},isDirty:p.isDirty,onExit:oe,onEditCode:te,onManageImages:ye,onManageTranslations:Se,onPageSettings:Ie,onReset:Xe,onShowShortcuts:Je,onPreview:Ve,onShowVersions:ze,templateName:w,templateVersion:x,templateList:C,onSwitchTemplate:G,onToggleCustomAssets:K,customAssetsDisabled:fe,onManageCustomAssets:ee}),i.jsx(d7,{result:F,onDismiss:V,onLoadLatest:ie}),i.jsxs("div",{className:"g7le-chrome__device-toolbar","data-testid":"g7le-chrome-device-toolbar",style:{display:"flex",justifyContent:"center",padding:"6px 12px",background:"#f1f5f9",borderBottom:"1px solid #e2e8f0"},children:[i.jsx(BD,{}),i.jsx(WD,{})]})]}),i.jsxs("div",{className:"g7le-chrome__body",style:{display:"grid",gridTemplateColumns:"auto 1fr",alignItems:"stretch"},children:[i.jsx(A7,{}),i.jsx(ND,{manifest:f,nesting:D,componentPalette:g?.componentPalette??null,spec:g,permissionCandidates:O,sampleGlobalSources:h,resolveRouteMatch:H,onNavigateToDestination:P,onSessionAddedPathsChange:L})]}),i.jsx(Py,{})]})})}function Sl(e,t){for(const n of e){if(n.kind==="route"&&n.path===t)return n;if(n.children&&n.children.length>0){const o=Sl(n.children,t);if(o)return o}}return null}function NM(e,t){return Sl(e,t)!==null}function Cl(e,t){for(const n of e){if(n.kind==="route"&&n.layoutName===t&&typeof n.path=="string")return n.path;if(n.children&&n.children.length>0){const o=Cl(n.children,t);if(o)return o}}return null}function MM(e,t,n){const o=[];Qa({sources:n,isGuestOnly:!1,warn:s=>{const a=/extension '([^']+)' override of core key '([^']+)'/.exec(s);a&&o.push(`${a[1]}:${a[2]}`)}});const r=t?.sampleData?.byDataSourceId?Object.keys(t.sampleData.byDataSourceId).length:0;wy({templateIdentifier:e,mergedSources:[...n.map(s=>({kind:s.kind,id:s.id}))],blockCounts:{controls:t?.controls?Object.keys(t.controls).length:0,componentCapabilities:t?.componentCapabilities?Object.keys(t.componentCapabilities).length:0,actionRecipes:t?.actionRecipes?Object.keys(t.actionRecipes).length:0,conditionRecipes:t?.conditionRecipes?Object.keys(t.conditionRecipes).length:0,paletteGroups:t?.componentPalette?.groups?.length??0,stateGroups:t?.states?.groups?.length??0,sampleDataIds:r},sampleGlobalSourceCount:n.length,sampleGlobalConflicts:o,timestamp:Date.now()})}function ay({templateIdentifier:e,initialLocale:t}){return u.useEffect(()=>()=>{gy(),yy(),my(),vy(),_y(),xy(),ky(),Sy(),Cy()},[]),i.jsx(zy,{templateIdentifier:e,initialLocale:t,children:i.jsx(Ly,{children:i.jsx(zM,{templateIdentifier:e})})})}if(typeof window<"u"){const e=window.G7Core||(window.G7Core={});if(e.__LayoutEditorChrome=ay,typeof e.__onChromeReady=="function")try{e.__onChromeReady()}catch{}}un.LayoutEditorChrome=ay,Object.defineProperty(un,Symbol.toStringTag,{value:"Module"})})(this.G7LayoutEditor=this.G7LayoutEditor||{},ReactJSXRuntime,React,ReactDOM);