2단계 인증은 7.0.6 에서 서버측이 갖춰졌지만 인증번호를 입력할 화면이 어느 버전에도
없었다. 그래서 그 설정을 켠 사이트는 관리자를 포함한 전원이 로그인할 수 없었다.
원인은 `POST /api/auth/login` 이 조건에 따라 **다른 형태의 200** 을 돌려준다는 것이다.
평소에는 `{token, user}` 지만 2단계 인증이 켜져 있으면 `{two_factor_required,
challenge_id, ...}` 를 돌려준다. 프론트는 앞의 형태만 선언하고 `response.data.user.language`
를 바로 읽었으므로 그 자리에서 TypeError 가 났고, 영문 원문이 로그인 화면에 그대로 노출됐다.
서버는 정상 응답했으므로 서버 로그에는 아무 흔적도 남지 않는다.
이어서 `setToken(undefined)` 가 `localStorage` 에 문자열 `"undefined"` 를 남겼다.
이 값은 truthy 라 이후 모든 요청이 `Bearer undefined` 로 나가 401 이 되고, 사용자에게는
「세션이 만료되었습니다」로 보인다. 관리자 로그인은 한발 더 나가 `null->isAdmin` 으로
500 이 되어, 설정을 되돌릴 수단까지 함께 사라졌다.
## 구현
- 로그인 응답을 판별 유니온(`LoginResult`)으로 표현하고, 형태를 판별한 뒤에 읽는다.
`ApiClient.setToken` 은 비어 있지 않은 문자열만 저장한다.
- 사용자·관리자 로그인 화면에 인증번호 입력 단계를 추가했다. 같은 카드 안에서 넘어가며
「인증번호 다시 받기」와 「처음부터」를 제공한다. 관리자 판정은 코드 확인에 성공한 뒤에
수행하고, 거부할 때는 그 직전에 발급된 토큰을 회수한다.
- 재발송(`login/two-factor/resend`)은 기존 challenge 를 취소하고 새로 발행한다. 유효한
코드를 여러 개 살려 두면 대입 시도의 표적이 넓어진다.
- 인증번호를 보내지 못하면 401 이 아니라 503 으로 답한다. 자격 증명은 올바른데 401 로
뭉개면 사용자는 비밀번호를 의심하며 같은 시도를 반복하고, 운영자는 메일 설정이 깨진
사실을 알 방법이 없다.
- 공개 본인인증 경로(`identity/verify`·`cancel`)가 로그인 목적의 challenge 를 소진하지
못하도록 403 게이트를 세웠다. 소진되면 그 challenge 로 영영 로그인할 수 없다.
- 로그인 시도 제한 429 응답이 다국어 문구를 싣도록 했다(종전에는 프레임워크 기본 영문).
- 다국어 파라미터에서 파이프 표현식이 평가되지 않아 「유효시간 까지」처럼 값이 빠지던
문제를 함께 고쳤다. 같은 결함이 문의 목록 화면에도 있었다.
## 이번 점검에서 함께 고친 것
- 계정 잠금(423)·발송 실패(503) 응답이 사용자·관리자 컨트롤러에 동일하게 복제돼 있었고
그 주석 자신은 "단일 지점에서 만든다" 고 적혀 있었다. 페이로드에 필드가 하나 추가되면
한쪽만 따라가 같은 실패를 두 화면이 다르게 안내하게 된다 — 트레이트로 통합했다.
- 테스트가 개발자 자신의 사이트 설정을 읽고 있었다. 2단계 인증을 켜 둔 환경에서는 로그인
성공을 전제한 테스트가 503 으로 깨지는데 실패 메시지가 원인을 가리키지도 않는다.
같은 결함군을 위해 이미 존재하던 단일 지점에 그 축을 추가했다.
## 버전
코어 7.0.11 · sirsoft-basic 1.1.4 · sirsoft-admin_basic 1.0.9 ·
번들 일본어팩 3종 · 템플릿 엔진 engine-v1.65.0.
14 lines
792 KiB
JavaScript
14 lines
792 KiB
JavaScript
var OM=Object.defineProperty;var BM=(dn,i,u)=>i in dn?OM(dn,i,{enumerable:!0,configurable:!0,writable:!0,value:u}):dn[i]=u;var Ni=(dn,i,u)=>BM(dn,typeof i!="symbol"?i+"":i,u);(function(dn,i,u,Cn){"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 Mi=Lt();Mi.TranslationProvider;const tt=Mi.useTranslation;Mi.TranslationReactContext;function rt(){return typeof window>"u"?null:window.__g7Devtools??null}function Il(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 Zh(){const e=rt();if(e?.clearEditorStateData)try{e.clearEditorStateData()}catch{}}function Qh(e){const t=rt();if(t?.trackEditorSampleMatch)try{t.trackEditorSampleMatch(e)}catch{}}function Rh(){const e=rt();if(e?.clearEditorSampleData)try{e.clearEditorSampleData()}catch{}}function ey(e){const t=rt();if(t?.trackEditorHistoryEntry)try{t.trackEditorHistoryEntry(e)}catch{}}function ty(){const e=rt();if(e?.clearEditorHistoryData)try{e.clearEditorHistoryData()}catch{}}function Al(e){const t=rt();if(t?.trackEditorSelection)try{t.trackEditorSelection(e)}catch{}}function ny(){const e=rt();if(e?.clearEditorSelectionData)try{e.clearEditorSelectionData()}catch{}}function dr(e){const t=rt();if(t?.trackEditorPropertyPatch)try{t.trackEditorPropertyPatch(e)}catch{}}function $n(e){const t=rt();if(t?.trackEditorDnd)try{t.trackEditorDnd(e)}catch{}}function oy(){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 ry(){const e=rt();if(e?.clearEditorDocumentData)try{e.clearEditorDocumentData()}catch{}}function iy(e){const t=rt();if(t?.trackEditorSpecMerge)try{t.trackEditorSpecMerge(e)}catch{}}function sy(){const e=rt();if(e?.clearEditorSpecMergeData)try{e.clearEditorSpecMergeData()}catch{}}function Li(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)>>>0;return t}function Et(e){const t=rt();if(t?.trackEditorI18n)try{t.trackEditorI18n(e)}catch{}}function ay(){const e=rt();if(e?.clearEditorI18nData)try{e.clearEditorI18nData()}catch{}}function Tl(e){const t=rt();if(t?.trackPageState)try{t.trackPageState(e)}catch{}}function ly(){const e=rt();if(e?.clearPageStateData)try{e.clearPageStateData()}catch{}}const Dl="g7le.routeTree.collapsed";function dy(){if(typeof window>"u")return!1;try{return window.localStorage?.getItem(Dl)==="1"}catch{return!1}}function cy(e){if(!(typeof window>"u"))try{window.localStorage?.setItem(Dl,e?"1":"0")}catch{}}function uy(e,t){return{templateIdentifier:e,routeTree:[],routesError:null,selectedRoute:null,isRouteTreeCollapsed:dy(),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 py(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 fy(e,t){const n=py(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 zl=u.createContext(null);function gy(e,t){const n=fy(e,t);return Il(n,t.type),n}function hy({templateIdentifier:e,initialLocale:t,children:n}){const[o,r]=u.useReducer(gy,void 0,()=>{const a=uy(e,t);return Il(a,void 0),a});u.useEffect(()=>{cy(o.isRouteTreeCollapsed)},[o.isRouteTreeCollapsed]);const s=u.useMemo(()=>({state:o,dispatch:r}),[o]);return u.createElement(zl.Provider,{value:s},n)}function Qe(){const e=u.useContext(zl);if(!e)throw new Error("useLayoutEditor must be used within LayoutEditorProvider");return e}const Nl=u.createContext(null);function yy({value:e,children:t}){return u.createElement(Nl.Provider,{value:e},t)}function Ft(){return u.useContext(Nl)}const Pi=u.createContext(null);let by=1;function my({children:e,t}){const[n,o]=u.useState([]),r=u.useRef([]),[s,a]=u.useState({}),l=u.useCallback(y=>{const _=y.id??`editor-modal-${by++}`,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(S=>S.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(Pi.Provider,{value:v},e,u.createElement(_y,{minimized:s,onRestore:b,t,key:"__min_bar"}))}function bo(){const e=u.useContext(Pi);if(!e)throw new Error("useEditorModal must be used within EditorModalProvider");return e}function vy(){const e=u.useContext(Pi);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 _y({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 xy(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 Ml="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 - (${Ml}) * 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(),_=xy(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 S=T=>{const E=p.current;if(!E)return;const A=window.innerWidth,N=window.innerHeight,D=w?.offsetWidth??0,B=w?.offsetHeight??0;let M=E.baseLeft+(T.clientX-E.startX),O=E.baseTop+(T.clientY-E.startY);M=Math.min(Math.max(0,M),Math.max(0,A-D)),O=Math.min(Math.max(0,O),Math.max(0,N-B)),d({left:M,top:O})},C=()=>{p.current=null,window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",C)};window.addEventListener("pointermove",S),window.addEventListener("pointerup",C)},[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:Ml,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 ky({templateIdentifier:e,templateName:t,templateVersion:n,templateList:o,onSwitch:r}){const{t:s}=tt(),[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 Sy(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:S}=tt(),{state:C,dispatch:T}=Qe(),[E,A]=u.useState(null);u.useEffect(()=>{const K=()=>{const Z=window.__g7LayoutEditorHistory;A(Z?{undo:Z.undo,redo:Z.redo,canUndo:!!Z.canUndo,canRedo:!!Z.canRedo}:null)};K();const X=window.setInterval(K,250);return()=>window.clearInterval(X)},[]);const N=()=>{T({type:"TOGGLE_ROUTE_TREE"})},D=()=>C.editMode==="base"?S("layout_editor.chrome.toolbar.mode_badge.base"):C.editMode==="modal"?S("layout_editor.chrome.toolbar.mode_badge.modal"):C.editMode==="extension"?S("layout_editor.chrome.toolbar.mode_badge.extension"):C.editMode==="iteration_item"?S("layout_editor.chrome.toolbar.mode_badge.iteration_item"):null,B=()=>{C.editMode==="base"?T({type:"EXIT_BASE_EDIT"}):C.editMode==="modal"?T({type:"EXIT_MODAL_EDIT"}):C.editMode==="extension"?T({type:"EXIT_EXTENSION_EDIT"}):C.editMode==="iteration_item"&&T({type:"EXIT_ITERATION_ITEM_EDIT"})},M=D(),O=C.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},I={...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":S("layout_editor.chrome.toolbar.toggle_route_tree"),title:S("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(ky,{templateIdentifier:C.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":C.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":S("layout_editor.chrome.toolbar.undo"),title:S("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":S("layout_editor.chrome.toolbar.redo"),title:S("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":C.isPaletteOpen?"true":"false",disabled:!C.selectedRoute,onClick:()=>T({type:"TOGGLE_PALETTE"}),"aria-pressed":C.isPaletteOpen,baseStyle:z,hoverStyle:L,style:C.isPaletteOpen?{backgroundColor:"#eff6ff",color:"#1d4ed8",borderColor:"#93c5fd"}:void 0,children:["+ ",S("layout_editor.chrome.toolbar.add_element")]}),i.jsx(ht,{"data-testid":"g7le-toolbar-preview","data-previewing":x?"true":"false",disabled:!p||!C.selectedRoute?.layoutName||x,onClick:()=>{const K=p?.();K&&typeof K.then=="function"&&($(!0),K.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"}}),S("layout_editor.chrome.toolbar.previewing")]}):i.jsxs(i.Fragment,{children:["👁 ",S("layout_editor.chrome.toolbar.preview")]})}),i.jsxs(ht,{"data-testid":"g7le-toolbar-versions",disabled:!f||!(C.selectedRoute?.layoutName||C.selectedRoute?.path?.startsWith("__extension__/")),onClick:()=>f?.(),"aria-label":S("layout_editor.chrome.toolbar.version_history"),title:S("layout_editor.chrome.toolbar.version_history"),baseStyle:z,hoverStyle:L,children:["🕘 ",S("layout_editor.chrome.toolbar.version_history")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-edit-code",disabled:!r,onClick:()=>r?.(),baseStyle:z,hoverStyle:L,children:["⟨/⟩ ",S("layout_editor.chrome.toolbar.edit_code")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-images",disabled:!s||!C.selectedRoute,onClick:()=>s?.(),baseStyle:z,hoverStyle:L,children:["🖼 ",S("layout_editor.chrome.toolbar.images")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-translations",disabled:!a||!C.selectedRoute,onClick:()=>a?.(),baseStyle:z,hoverStyle:L,children:["🌐 ",S("layout_editor.chrome.toolbar.translations")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-custom-assets",disabled:!_,onClick:()=>_?.(),title:S("layout_editor.chrome.toolbar.custom_assets_hint"),baseStyle:z,hoverStyle:L,children:["🎨 ",S("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:S(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?"👁":"🚫"," ",S(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||!C.selectedRoute||C.editMode==="extension"||C.editMode==="iteration_item",onClick:()=>l?.(),baseStyle:z,hoverStyle:L,children:["⚙ ",S("layout_editor.chrome.toolbar.page_settings")]}),i.jsxs(ht,{"data-testid":"g7le-toolbar-reset",disabled:!d||!n,onClick:()=>d?.(),"aria-label":S("layout_editor.chrome.toolbar.reset"),title:S("layout_editor.chrome.toolbar.reset"),baseStyle:z,hoverStyle:L,style:{opacity:n?1:.4},children:["↺ ",S("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 K=t?.();K&&typeof K.then=="function"&&(k(!0),K.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"}}),S("layout_editor.chrome.toolbar.saving")]}):i.jsxs(i.Fragment,{children:["💾 ",S("layout_editor.chrome.toolbar.save")]})}),i.jsx(ht,{"data-testid":"g7le-toolbar-shortcuts",disabled:!c,onClick:()=>c?.(),"aria-label":S("layout_editor.shortcuts.title"),title:S("layout_editor.shortcuts.title"),baseStyle:z,hoverStyle:L,children:"⌨"}),i.jsxs(ht,{"data-testid":"g7le-toolbar-exit",disabled:!o,onClick:()=>o?.(),baseStyle:I,hoverStyle:Y,children:["✕ ",S("layout_editor.chrome.toolbar.exit")]})]}),O&&i.jsxs(ht,{"data-testid":"g7le-toolbar-exit-alt-mode",onClick:B,baseStyle:I,hoverStyle:Y,children:["← ",C.editMode==="base"&&S("layout_editor.chrome.toolbar.exit_base_edit"),C.editMode==="modal"&&S("layout_editor.chrome.toolbar.exit_modal_edit"),C.editMode==="extension"&&S("layout_editor.chrome.toolbar.exit_extension_edit"),C.editMode==="iteration_item"&&S("layout_editor.chrome.toolbar.exit_iteration_item_edit")]})]})}function cr(){if(typeof window>"u")return null;try{return window.localStorage?.getItem("auth_token")??null}catch{return null}}function Ne(e){const t={Accept:"application/json",...e??{}},n=cr();return n&&(t.Authorization=`Bearer ${n}`),t}function Oi(e){return encodeURIComponent(e)}async function Ll(e,t){const n=`/api/admin/templates/${Oi(e)}/layout-attachments?layout_name=${encodeURIComponent(t)}`;try{const o=await fetch(n,{method:"GET",headers:Ne(),credentials:"same-origin"}),r=await o.json().catch(()=>null);return!o.ok||!r?.success?{ok:!1,status:o.status,message:Bi(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 Pl(e,t,n){const o=`/api/admin/templates/${Oi(e)}/layout-attachments`,r=new FormData;r.append("file",n),r.append("layout_name",t);try{const s=await fetch(o,{method:"POST",headers:Ne(),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:Bi(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 Ol(e){const t=`/api/admin/templates/layout-attachments/${Oi(String(e))}`;try{const n=await fetch(t,{method:"DELETE",headers:Ne(),credentials:"same-origin"}),o=await n.json().catch(()=>null);return!n.ok||o&&o.success===!1?{ok:!1,status:n.status,message:Bi(o,n.status)}:{ok:!0,data:!0}}catch(n){return{ok:!1,status:0,message:n instanceof Error?n.message:"network error"}}}function Bi(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 Cy(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function $y(e){if(!e)return"";const t=e.match(/^(\d{4})-(\d{2})-(\d{2})/);return t?`${t[2]}-${t[3]}`:""}function Bl({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 Ll(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 Pl(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 Ol(_.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:Ey,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:Iy,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:Ay,"data-testid":"g7le-attachment-manager-close",children:"✕"})]}),i.jsx("div",{style:Ty,children:i.jsxs("label",{style:Dy,"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:zy,"data-testid":"g7le-attachment-manager-error",children:b}),i.jsx("div",{style:Ny,children:d==="loading"?i.jsx("div",{style:Wl,"data-testid":"g7le-attachment-manager-loading",children:n("layout_editor.attachment_manager.loading")}):a.length===0&&d!=="error"?i.jsx("div",{style:Wl,"data-testid":"g7le-attachment-manager-empty",children:n("layout_editor.attachment_manager.empty")}):i.jsx("div",{style:My,"data-testid":"g7le-attachment-grid",children:a.map(_=>i.jsxs("div",{style:Ly,"data-testid":`g7le-attachment-card-${_.id}`,children:[i.jsx("div",{style:{...Py,backgroundImage:`url(${_.url})`}}),i.jsx("div",{style:Oy,title:_.original_name,children:_.original_name}),i.jsxs("div",{style:By,children:[Cy(_.size),_.created_at?` · ${$y(_.created_at)}`:""]}),i.jsxs("div",{style:Wy,children:[o&&i.jsx("button",{type:"button",onClick:()=>o(_.url),style:jy,"data-testid":`g7le-attachment-use-${_.id}`,children:n("layout_editor.attachment_manager.use_as_bg")}),i.jsx("button",{type:"button",onClick:()=>y(_),style:Hy,"data-testid":`g7le-attachment-delete-${_.id}`,children:"🗑"})]})]},_.id))})}),i.jsx("div",{style:Fy,children:i.jsx("button",{type:"button",onClick:s,style:Ky,"data-testid":"g7le-attachment-manager-footer-close",children:n("layout_editor.attachment_manager.close")})})]})}const Ey={display:"flex",flexDirection:"column",minHeight:0,flex:1},Iy={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #e2e8f0"},Ay={border:"none",background:"transparent",fontSize:16,color:"#94a3b8",cursor:"pointer"},Ty={padding:"10px 16px",borderBottom:"1px solid #f1f5f9",display:"flex",gap:8},Dy={padding:"6px 12px",fontSize:13,border:"1px solid #2563eb",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",display:"inline-flex",alignItems:"center"},zy={padding:"8px 16px",fontSize:12,color:"#b91c1c",background:"#fef2f2"},Ny={padding:16,overflow:"auto",flex:1,minHeight:120},Wl={fontSize:13,color:"#94a3b8",textAlign:"center",padding:"32px 0"},My={display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(140px, 1fr))",gap:12},Ly={display:"flex",flexDirection:"column",gap:4,border:"1px solid #e2e8f0",borderRadius:8,padding:8},Py={width:"100%",height:88,borderRadius:6,border:"1px solid #cbd5e1",backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f8fafc"},Oy={fontSize:12,fontWeight:600,color:"#0f172a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},By={fontSize:11,color:"#64748b"},Wy={display:"flex",gap:6,marginTop:2},jy={flex:1,padding:"4px 6px",fontSize:11,border:"1px solid #2563eb",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},Hy={padding:"4px 8px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},Fy={padding:"10px 16px",borderTop:"1px solid #e2e8f0",display:"flex",justifyContent:"flex-end"},Ky={padding:"6px 14px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"};function ur(e){return encodeURIComponent(e)}async function Vy(e,t,n){const o=new URLSearchParams;t&&o.set("layout_name",t);const r=o.toString(),s=`/api/admin/templates/${ur(e)}/custom-translations`+(r?`?${r}`:"");try{const a=await fetch(s,{method:"GET",headers:Ne(),credentials:"same-origin"}),l=await a.json().catch(()=>null);return!a.ok||!l?.success?{ok:!1,status:a.status,message:pr(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 Uy(e,t,n,o){const r=`/api/admin/templates/${ur(e)}/custom-translations/${t}`;try{const s=await fetch(r,{method:"PUT",headers:Ne({"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:pr(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 qy(e,t){const n=`/api/admin/templates/${ur(e)}/custom-translations/${t}`;try{const o=await fetch(n,{method:"DELETE",headers:Ne(),credentials:"same-origin"}),r=await o.json().catch(()=>null);return!o.ok||r&&r.success===!1?{ok:!1,status:o.status,message:pr(r,o.status)}:{ok:!0,data:!0}}catch(o){return{ok:!1,status:0,message:o instanceof Error?o.message:"network error"}}}async function Gy(e,t){const n=`/api/admin/templates/${ur(e)}/custom-translations`;try{const o=await fetch(n,{method:"DELETE",headers:Ne({"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:pr(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 jl=/\$t:(custom\.[A-Za-z0-9_\-]+\.\d+)/g;function Yy(e){const t=new Set,n=o=>{if(typeof o=="string"){if(o.includes("$t:custom.")){let r;for(jl.lastIndex=0;(r=jl.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 pr(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,mo=Lt().createLogger,Wi=mo("EditorSpecLoader"),Xy=["controls","componentCapabilities","actionRecipes","conditionRecipes","pageSettings","initActionRecipes","errorRecipes","computedRecipes","loadingComponents"],Jy=["actionRecipes","initActionRecipes","errorRecipes","computedRecipes","loadingComponents"];function Hl(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 Zy(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&&Wi.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 Wi.warn("fetchOneSpec: fetch failed",s,a),null}}function Qy(e){return Jy.includes(e)}function Ry(e,t){return e==null||typeof e!="object"?e:{...e,__source:t}}function eb(e,t,n,o){const r=t[n];if(!r||typeof r!="object")return;const s=e[n]??{};if(o&&Qy(n)){const a={};for(const[l,d]of Object.entries(r))a[l]=Ry(d,o);e[n]={...s,...a};return}e[n]={...s,...r}}function tb(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 nb(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 ob(e,t){if(!t.states)return;const n=e.states??{},o=[...n.groups??[],...t.states.groups??[]];n.groups=o,e.states=n}function rb(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 ib(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 sb(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 Fl(e,t,n){for(const o of Xy)eb(e,t,o,n);tb(e,t),nb(e,t),ob(e,t),rb(e,t),ib(e,t),sb(e,t),t.version&&(e.version=t.version)}async function ab(e){const t=e.apiBaseUrl??"/api",n=e.fetcher??(typeof fetch<"u"?fetch:void 0);if(!n)return Wi.warn("loadEditorSpecBundle: fetch unavailable, returning null spec"),{spec:null,sampleGlobalSources:[]};const o=e.activeModuleIdentifiers??Hl("activeModules"),r=e.activePluginIdentifiers??Hl("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=>Zy(p.kind,p.id,t,n)));let l=null;const d=[],c={};if(e.coreSeed&&(l={},Fl(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={}),Fl(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 ji(e,t){return e?.componentCapabilities?.[t]??null}function Ct(e,t){return e?.controls?.[t]??null}function lb(e){return e?.initActionRecipes??{}}function db(e){return e?.computedRecipes??{}}function cb(e){return e?.errorRecipes??{}}function ub(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 pb(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 Hi(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function fb(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 gb(e){const t=e.find(n=>Hi(n));if(Hi(t))return Object.keys(t).slice(0,8)}function hb(e){return Object.keys(e).slice(0,8)}function yb(e){const t=Object.entries(e);return t.length===0?!1:t.some(([,n])=>n===null||typeof n!="object")}function Fi(e,t,n,o,r){if(Array.isArray(e)){r(t,"array",`[${e.length}]`,gb(e));return}if(Hi(e)){if(t&&yb(e)){const s=hb(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;Fi(a,l,n+1,o,r)}return}r(t,"scalar",fb(e))}function bb(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(Kl(d))||[];o.push({name:l.item_var,kind:"item",itemFields:c})}}return o}function Kl(e){return e.replace(/^\{\{|\}\}$/g,"").trim()}function mb(e){const t=new Map;for(const n of e)n.shape==="array"&&n.itemFields&&n.itemFields.length>0&&t.set(Kl(n.expression),n.itemFields);return t}function Ki(e){const t=e.maxDepth??4,n=[];for(const o of e.dataSources??[])!o||typeof o.id!="string"||o.id.length===0||Fi(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"||Fi(o.tree,"",0,t,(r,s,a,l)=>{if(!r)return;const d=pb(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 vb=["$localized"];function _b(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(!vb.includes(o))return{fn:null,inner:t};const r=t.slice(n+1,-1);let s=0,a=null;for(let l=0;l<r.length;l++){const d=r[l];if(a){if(d==="\\"){l++;continue}d===a&&(a=null);continue}if(d==="'"||d==='"'||d==="`"){a=d;continue}if(d==="("||d==="[")s++;else if(d===")"||d==="]"){if(s--,s<0)return{fn:null,inner:t}}else if(s===0&&d===",")return{fn:null,inner:t}}return s!==0?{fn:null,inner:t}:{fn:o,inner:r.trim()}}const xb=["_global","_local","route","query","_computed"];function Vi(e){let t=e.trim();for(;t.startsWith("(")&&t.endsWith(")");){let n=0,o=!0;for(let r=0;r<t.length;r++)if(t[r]==="(")n++;else if(t[r]===")"&&(n--,n===0&&r<t.length-1)){o=!1;break}if(!o)break;t=t.slice(1,-1).trim()}return t}function Kt(e){if(typeof e!="string")return null;const t=e.trim(),n=/^\{\{\s*([^{}]+?)\s*\}\}$/.exec(t);if(!n)return null;let o=Vi(n[1].trim()),r;{let g=0;for(let m=0;m<o.length-1;m++){const h=o[m];if(h==="("||h==="[")g++;else if(h===")"||h==="]")g--;else if(g===0&&h==="?"&&o[m+1]==="?"){r=o.slice(m+2).trim(),o=o.slice(0,m).trim();break}}}o=Vi(o);const s=_b(o),a=s.fn??void 0;a&&(o=Vi(s.inner));const l=o.includes("?."),d=o.replace(/\?\./g,".");if(!/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\[\d+\])*$/.test(d)||r!==void 0&&!/^(\[\s*\]|\{\s*\}|''|""|`+`|-?\d+(\.\d+)?|true|false|null)$/.test(r))return null;const c=d.indexOf("."),p=c===-1?d:d.slice(0,c),f=c===-1?"":d.slice(c+1);return{...xb.includes(p)?{source:p,sourceId:p,path:f}:{source:"data_source",sourceId:p,path:f},optional:l,fallback:r,localeFn:a}}function En(e,t,n,o){const r=t?t.split(".").filter(Boolean):[];return`{{${[e,...r].join("?.")} ?? ${n==="array"?"[]":n==="object"?"{}":"''"}}}`}function Ui(e,t){return e.filter(n=>n.shape===t)}function qi(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 Vl(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 Gi=/\{\{(?:[^}]|\}(?!\}))*\}\}/g;function In(e){const t=[];if(typeof e!="string"||e.length===0)return t;let n=0,o=0;const r=new RegExp(Gi.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:Kt(s[0]),bindingIndex:o++}),n=l}return n<e.length&&t.push({kind:"literal",raw:e.slice(n),start:n,end:e.length}),t}function fr(e){return In(e).filter(t=>t.kind==="binding")}function Yi(e){return typeof e!="string"?!1:new RegExp(Gi.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 Ul(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 Xi(e,t){const n=typeof e=="string"?e:"";return An(n).includes(t)?n:n.length===0?`{${t}}`:/\s$/.test(n)?`${n}{${t}}`:`${n} {${t}}`}function ql(e){return fr(e).map(t=>({bindingIndex:t.bindingIndex??0,expression:t.raw,parsed:t.parsed??null,isComplex:(t.parsed??null)===null}))}function gr(e){return typeof e!="string"?"":e.replace(new RegExp(Gi.source,"g")," ").replace(/\s+/g," ").trim()}const kb=/\$t:([a-zA-Z0-9._-]+)/g,Gl="custom.";function Ji(e,t){return typeof e!="string"||e.length===0?typeof e=="string"?e:"":t?In(e).map(n=>n.kind!=="literal"?n.raw:n.raw.replace(kb,(o,r)=>{if(r.startsWith(Gl))return o;const s=t(r);return s&&s!==r?s:o})).join(""):e}const Kn="(?:(?!\\|[a-zA-Z0-9_]+=).)*",Sb=new RegExp(`^\\s*\\$t:([a-zA-Z0-9._-]+)((?:\\|[a-zA-Z0-9_]+=${Kn})*)`),Cb=new RegExp(`\\|([a-zA-Z0-9_]+)=(${Kn})`,"g");function Vt(e){if(typeof e!="string")return"";const t=Kt(e);if(t)return t.path||t.sourceId;const n=e.trim().replace(/^\{\{\s*/,"").replace(/\s*\}\}$/,"");let o=-1;for(let l=0;l<n.length;l++)if(n[l]==="|"&&n[l+1]!=="|"&&n[l-1]!=="|"){o=l;break}if(o>0){const l=n.slice(0,o).trim(),d=Kt(`{{${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 Yl=/\$(?:core|module|plugin)_settings:[a-zA-Z0-9._:-]+/g;function Xl(e){return typeof e=="string"&&new RegExp(Yl.source).test(e)}function $b(e){return typeof e!="string"?"":e.replace(/^\$(?:core|module|plugin)_settings:/,"").split(/[.:]/).filter(Boolean).pop()||e}function Jl(e){const t=[];for(const n of In(e)){if(n.kind==="binding"){t.push({kind:"chip",label:Vt(n.raw)});continue}let o=0;const r=n.raw,s=new RegExp(Yl.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:$b(a[0])}),o=a.index+a[0].length;o<r.length&&t.push({kind:"text",label:r.slice(o)})}return t}function Eb(e){return typeof e!="string"?!1:/\{\{/.test(e)?!0:Xl(e)}function Zi(e,t){const n={chipValue:"",bindings:[],paramLabels:{},keyifiable:!1};if(typeof e!="string"||e.length===0)return n;const o=[],r={},s=g=>{const m=`p${o.length}`;return o.push(g),r[m]=Vt(g),`{${m}}`};let a=e,l="";const d=Sb.exec(e);if(d&&!d[1].startsWith(Gl)){const g=d[1],m=d[2]??"",h=e.slice(d[0].length),v=new Map,y=new RegExp(Cb.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=Ji(a,t),p=In(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 Zl(e,t){return t.bindings.length?e+t.bindings.map((n,o)=>`|p${o}=${n}`).join(""):e}function Ql(e,t){const n=fr(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 Rl(e){if(typeof e!="string")return"";const t=In(e);let n=0;return t.map(o=>o.kind==="binding"?`{p${n++}}`:o.raw).join("")}const ed=new RegExp(`^\\s*\\$t:([a-zA-Z0-9._-]+)((?:\\|[a-zA-Z0-9_]+=${Kn})+)\\s*$`),Ib=new RegExp(`\\|([a-zA-Z0-9_]+)=(${Kn})`,"g");function vt(e){if(typeof e!="string")return null;const t=ed.exec(e);if(!t)return null;const n=t[1],o=t[2],r=[],s=new RegExp(Ib.source,"g");let a;for(;(a=s.exec(o))!==null;){const l=a[1],d=a[2];r.push({name:l,expression:d,parsed:Kt(d)})}return{key:n,params:r}}function td(e){return typeof e=="string"&&ed.test(e)}function An(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 Ab(e,t,n){if(typeof e!="string")return e;const o=new RegExp(`(\\|${t}=)${Kn}`);return o.test(e)?e.replace(o,`$1${n}`):e}function vo(e,t){if(typeof e!="string")return e;const n=new RegExp(`\\|${t}=${Kn}`);return e.replace(n,"")}function nd(e,t){return typeof e!="string"?e:e.replace(new RegExp(`\\s*\\{\\{?${t}\\}?\\}\\s*`,"g")," ").replace(/\s+/g," ").trim()}function Tb(e,t){const n=s=>fr(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 od(e){return e.__source?.kind==="base"}function rd(e){return e.__source?.kind==="partial"}function Db(e){return e.__source?.kind==="route"}function hr(e,t){return e.__source?.kind!=="extension"?!1:t==null?!0:e.__source.extensionId!==t}function id(e){return e.type==="extension_point"}function Qi(e=[]){for(const t of e)if(t.iteration&&t.iteration.source!==void 0)return!0;return!1}function zb(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:sd(e)}function sd(e){if(typeof e.text=="string"&&ad(e.text)&&!Nb(e.text))return!0;if(e.props&&typeof e.props=="object"){for(const t of Object.values(e.props))if(typeof t=="string"&&ad(t))return!0}return!1}function ad(e){return/\{\{[\s\S]*?\}\}/.test(e)}function Nb(e){const t=vt(e);return t!==null&&t.key.startsWith("custom.")}function Mb(e,t){return e??t??null}function Ri(e,t,n){if(id(e))return!0;switch(t){case"route":return od(e)||rd(e)||hr(e);case"base":return hr(e);case"modal":return hr(e);case"extension":return hr(e,n)?!0:od(e)||Db(e)||rd(e);default:return!1}}function et(e){return typeof e=="object"&&e!==null&&typeof e.responsive=="string"}function yr(e,t){return et(e)?et(t)&&e.responsive===t.responsive:!et(t)&&e===t}function at(e){const t=[];let n=!1;for(const o of e){if(et(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 Qt(e){return Array.isArray(e.children)?e.children:[]}function br(e,t){const n=e.responsive?.[t];return n&&Array.isArray(n.children)?n.children:[]}function Be(e,t){if(!e)return null;if(t.length===0)return e;let n=e,o=Qt(e);for(const r of t){if(et(r)){o=br(n,r.responsive);continue}if(r<0||r>=o.length||(n=o[r],!n))return null;o=Qt(n)}return n}function Lb(e,t,n){if(!e||t.length===0)return t;let o=e,r=Qt(e),s;for(let a=0;a<t.length;a++){const l=t[a];if(et(l)){r=br(o,l.responsive);continue}const d=r[l]??null;if(!d)return t;const c=d.__source?.kind,p=d.__source?.extensionId,f=c==="extension"&&n!=null&&p===n;if(c==="extension"&&s!=="extension"&&!f)return t.slice(0,a+1);s=c,o=d,r=Qt(d)}return t}function ld(e,t){if(t.length===0)return null;const n=t[t.length-1];if(et(n))return null;const o=n,r=t.length>=2?t[t.length-2]:void 0;if(r!==void 0&&et(r)){const a=Be(e,t.slice(0,-2));return a?{owner:a,children:br(a,r.responsive),branchKey:r.responsive,index:o}:null}const s=Be(e,t.slice(0,-1));return s?{owner:s,children:Qt(s),index:o}:null}function es(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 Rt(e){const t={...e};t.props&&typeof t.props=="object"&&(t.props={...t.props});const n=Qt(e);if(n.length>0&&(t.children=n.map(Rt)),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(Rt)),a.props&&typeof a.props=="object"&&(a.props={...a.props}),o[r]=a}t.responsive=o}return t}function ts(e,t,n,o){const r=Rt(e),s=t.length>0?t[t.length-1]:void 0;if(s!==void 0&&et(s)){const p=Be(r,t.slice(0,-1));if(!p)return r;const f=br(p,s.responsive),b=Math.max(0,Math.min(n,f.length)),g=[...f];return g.splice(b,0,o),es({owner:p,branchKey:s.responsive},g),r}const a=Be(r,t);if(!a)return r;const l=Qt(a),d=Math.max(0,Math.min(n,l.length)),c=[...l];return c.splice(d,0,o),a.children=c,r}function ns(e,t){if(t.length===0)return e;const n=Rt(e),o=ld(n,t);if(!o||o.index<0||o.index>=o.children.length)return n;const r=[...o.children];return r.splice(o.index,1),es(o,r),n}function Pb(e,t,n,o){if(t.length===0||!n||et(t[t.length-1]))return e;const r=Rt(e),s=Be(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:Qt(s)).map(Rt),p={...s.responsive??{}};return p[n]={...p[n]??{},children:c},s.responsive=p,r}function Ob(e,t,n){if(t.length===0||!n||et(t[t.length-1]))return e;const o=Rt(e),r=Be(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 Bb(e,t,n,o){if(t.length===0)return e;const r=Be(e,t);if(!r||Wb(t,n))return e;const s=Rt(r),a=ns(e,t),l=dd(n,t);let d=o;const c=t.slice(0,-1);if(cd(c,n)){const p=t[t.length-1];(typeof p=="number"?p:0)<o&&(d=Math.max(0,o-1))}return ts(a,l,d,s)}function dd(e,t){if(t.length===0)return e;const n=t.length-1;if(e.length<=n)return e;for(let s=0;s<n;s++)if(!yr(e[s],t[s]))return e;const o=t[n],r=e[n];if(et(o)||et(r))return e;if(r>o){const s=[...e];return s[n]=r-1,s}return e}function cd(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!yr(e[n],t[n]))return!1;return!0}function Wb(e,t){if(t.length<e.length)return!1;for(let n=0;n<e.length;n++)if(!yr(t[n],e[n]))return!1;return t.length>e.length||cd(e,t)}function os(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}_${jb()}`}const n=Qt(e);return n.length>0&&(t.children=n.map(os)),t}function Ot(e,t,n){if(t.length===0)return n(e);const o=Rt(e),r=Be(o,t);if(!r)return o;const s=n(r),a=ld(o,t);if(!a||a.index<0||a.index>=a.children.length)return o;const l=[...a.children];return l[a.index]=s,es(a,l),o}function jb(){return Math.floor(Math.random()*2821109907456).toString(36).padStart(8,"0")}function Vn(e){if(!Array.isArray(e)||e.length===0)return[];const t=[];for(const n of e){const o=Hb(n);o.length>0&&t.push(...o)}return t}function Hb(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 Vn(s)}const r={...e};return delete r.__source,delete r._fromBase,delete r.__injectedProps,Array.isArray(r.children)&&(r.children=Vn(r.children)),[r]}function _o(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=Vn(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)?Vn(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)?Vn(g):g;l.slots=f}}else l.components=a,delete l.slots;return delete l.lock_version,delete l.__editor,l}const ud="extension",Un="extensionless";function Fb(){const e=globalThis?.G7Config;if(globalThis?.__g7AssetUrlMode===Un)return Un;const n=e?.assetUrlMode;return n===Un||n===ud?n:e?.settings?.general?.asset_url_mode===Un?Un:ud}function Kb(){return Fb()===Un}function en(e,t,n,o){const r=e.replace(/\/+$/,""),s=t.replace(/^\.+/,""),a=Kb()?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 pd=/^\s*\$t:([a-zA-Z0-9._-]+)\s*$/,mr="custom.",Vb=/\{\{.*?\}\}/;function Ub(e){return!!(!e||e.iteration&&typeof e.iteration=="object")}function fd(e,t){const n=e?.text,o=typeof n=="string"?n:"";if(Ub(e)||typeof n!="string")return{sourceState:"plain_text",editable:!1,customKey:null,displayValue:o};const r=vt(o);if(r&&r.key.startsWith(mr)){const a=t?t(r.key):r.key;return{sourceState:"custom_key",editable:!0,customKey:r.key,displayValue:a,isParamKey:!0}}const s=pd.exec(o);if(s){const a=s[1];if(a.startsWith(mr)){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(Vb.test(o)){const a=gr(o),l=pd.exec(a);if(l&&l[1].startsWith(mr)){const f=l[1],b=t?t(f):f;return{sourceState:"custom_key",editable:!0,customKey:f,displayValue:b}}const d=Ji(o,t),c=gr(d),p=/\$t:[a-zA-Z0-9._-]+/.test(c);if(c.length>0){const f=Zi(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 qb(){const{state:e}=Qe(),t=Ft(),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=>fd(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=Be(g,p),h=fd(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};xo(n,o,h.customKey,f);const S=await vr(n,h.customKey,o,f);return S.kind==="error"?{kind:"error",message:S.message}:(await tn(n,o),Et({op:"inline_edit_update_value",sourceState:"custom_key",componentPath:at(p),translationKey:h.customKey,toLocale:o,valueLength:f.length,valueHash:Li(f),timestamp:Date.now()}),{kind:"updated",translationKey:h.customKey})}const v=typeof m?.text=="string"?m.text:"",y=h.sourceState==="plain_with_binding",_=Ji(v,s),w=y?Rl(_):f,k=S=>y?Ql(S,v):S;t.patchLayout(S=>Ot({children:S},p,E=>({...E,text:f})).children??[]);const x=await qn(n,r,o,w);if(x.kind==="error"||!x.resource)return{kind:"error",message:x.message};const $=x.resource.translation_key;return xo(n,o,$,w),t.patchLayout(S=>Ot({children:S},p,E=>({...E,text:k(`$t:${$}`)})).children??[]),await tn(n,o),Et({op:"inline_edit_create_key",sourceState:h.sourceState,componentPath:at(p),translationKey:$,toLocale:o,valueLength:f.length,valueHash:Li(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=Be(g,p),h=typeof m?.text=="string"?m.text:"",v=vt(h);if(v&&v.key.startsWith(mr))return _r(n,v.key,o,f),xo(n,o,v.key,f),t.markDirty?.(),{kind:"updated",translationKey:v.key};const y=Zi(h,s),_=gr(f.replace(/\{\{?p\d+\}?\}/g," ")).replace(/\s+/g," ").trim(),w=await qn(n,r,o,_);if(w.kind==="error"||!w.resource)return{kind:"error",message:w.message};const k=w.resource.translation_key,x=An(f),$=w.resource.values??{},S={[o]:f};for(const C of Object.keys($)){if(C===o)continue;let T=$[C]??"";for(const E of x)T=Xi(T,E);S[C]=T}return wo(n,k,S),xo(n,o,k,f),t.patchLayout(C=>Ot({children:C},p,A=>({...A,text:Zl(`$t:${k}`,y)})).children??[]),t.markDirty?.(),await tn(n,o),xo(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:Li(f),timestamp:Date.now()}),{kind:"created",translationKey:k}},[t,n,o,r]);return{classify:a,commit:d,trackCancel:l,keyifyChipValue:c}}async function qn(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:Ne({"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 vr(e,t,n,o){const r=await cn(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:Ne({"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 cn(e,t){const n=`/api/admin/templates/${encodeURIComponent(e)}/custom-translations`;try{const o=await fetch(n,{method:"GET",credentials:"same-origin",headers:Ne()});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 xo(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 tn(e,t){if(typeof window>"u")return;const n=t??window.__g7EditorContentLocale;if(n){try{const o=Pt.getInstance();try{const r=await fetch(en(`/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 nn=new Map;function _r(e,t,n,o){const r=nn.get(t)??{};r[n]=o,nn.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 wo(e,t,n){for(const[o,r]of Object.entries(n))_r(e,t,o,r)}function It(e,t){return nn.get(e)?.[t]}function Gb(e){const t=nn.get(e);return t?{...t}:void 0}function Yb(){return nn.size>0}function gd(e,t){for(const[n,o]of nn.entries())for(const[r,s]of Object.entries(o))try{e.setTranslationValue(t,r,n,s)}catch{}}async function Xb(e){if(nn.size===0)return{ok:0,failed:[]};const t=Array.from(nn.entries());let n=0;const o=[];for(const[r,s]of t)try{const a=await cn(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:Ne({"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)||nn.delete(r);try{await tn(e)}catch{}return{ok:n,failed:o}}function Gn(e,t){const n=`layout_editor.locale.${e}`,o=t(n);return o&&o!==n?o:e.toUpperCase()}function hd(){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 Jb({locales:e}={}){const{t}=tt(),{state:n,dispatch:o}=Qe();u.useEffect(()=>{window.__g7EditorContentLocale=n.locale},[n.locale]);const r=e??hd(),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"),": ",Gn(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:Gn(l,t)},l)})})]})}const Zb=/\{\{?(p\d+)\}?\}/g;function Qb(e){const t=[];if(typeof e!="string"||e.length===0)return t;const n=new RegExp(Zb.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<e.length&&t.push({kind:"text",raw:e.slice(o),start:o,end:e.length}),t}function Rb(e){const t=Qb(e),n=[];let o="",r=!1;const s=a=>{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 em(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 xr({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(()=>Rb(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("")},S=()=>{l||t($())},C=u.useRef(null),T=u.useRef(!1),E=(O,z)=>{if(!l){O.preventDefault(),O.stopPropagation(),C.current={param:z,pointerId:O.pointerId},T.current=!1,g(z);try{O.currentTarget.setPointerCapture(O.pointerId)}catch{}}},A=O=>{const z=C.current;if(!z||O.pointerId!==z.pointerId)return;T.current=!0;const H=B(O.clientX,O.clientY);H&&(h({slotIdx:H.slotIdx,offset:H.offset}),y(nm(f.current,H.slotIdx,H.offset)))},N=(O,z)=>{if(O.stopPropagation(),T.current){T.current=!1;return}s?.(z)},D=O=>{const z=C.current;if(!z||O.pointerId!==z.pointerId)return;try{O.currentTarget.releasePointerCapture(O.pointerId)}catch{}C.current=null,T.current&&typeof setTimeout=="function"&&setTimeout(()=>{T.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=em(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]")),I=H.ownerDocument,L=I.elementFromPoint(O,z);let F=L?.closest('[data-seg="text"]');if(F)return{slotIdx:P.indexOf(F),offset:tm(I,F,O,z)};const Y=L?.closest('[data-seg="chip"]');if(Y){const X=P.indexOf(Y),Z=Y.getBoundingClientRect();if(O<Z.left+Z.width/2&&X-1>=0){const ae=P[X-1];return{slotIdx:X-1,offset:(ae.textContent??"").length}}if(X+1<P.length)return{slotIdx:X+1,offset:0}}const K=P.map((X,Z)=>({s:X,i:Z})).filter(X=>X.s.dataset.seg==="text").pop();return K?{slotIdx:K.i,offset:(K.s.textContent??"").length}:null},M=()=>{l||!r||r(yd(f.current,e.length))};return u.useEffect(()=>{if(c)return c.current=()=>yd(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:om,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:A,onPointerUp:D,title:n("layout_editor.translation.placeholder_locked"),style:{...am,...b===O.paramName?lm:null,touchAction:"none"},children:[i.jsx("span",{"aria-hidden":"true",style:dm,children:"⠿"}),i.jsx("span",{"aria-hidden":"true",style:{marginRight:3},children:"🔗"}),i.jsx("span",{style:cm,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:um,children:"✕"})]},`chip-${O.paramName}`):i.jsx("span",{ref:H=>{k.current[z]=H},"data-seg":"text",contentEditable:!l,suppressContentEditableWarning:!0,onInput:S,"data-testid":`g7le-chip-text-${a}-${z}`,style:{...rm,...b?im:null,...m?.slotIdx===z?sm: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:pm,children:["+ ",n("layout_editor.inline_binding.insert_data")]}),i.jsx("span",{style:fm,children:n("layout_editor.translation.placeholder_locked")})]})]})}function tm(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 nm(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 yd(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 om={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},rm={outline:"none",minWidth:8,minHeight:"1.2em",whiteSpace:"pre-wrap",color:"#0f172a",display:"inline-block"},im={boxShadow:"inset 0 -2px 0 #93c5fd",background:"#eff6ff",borderRadius:2},sm={background:"#dbeafe",boxShadow:"inset 0 -2px 0 #2563eb"},am={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"},lm={opacity:.5,borderStyle:"solid",cursor:"grabbing"},dm={color:"#2563eb",opacity:.7,fontSize:11,marginRight:1,cursor:"grab"},cm={textDecoration:"none"},um={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"},pm={fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#334155",padding:"3px 10px",cursor:"pointer"},fm={fontSize:10,color:"#94a3b8"};function bd(e){e&&(e.style.height="auto",e.style.height=`${Math.max(e.scrollHeight,28)}px`)}function gm(e){bd(e)}function hm(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 ym({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 Vy(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(()=>hm(s),[s]),S=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,I=H.updated_at?Date.parse(H.updated_at):0;return I!==P?I-P:H.id-z.id}),[s,f]),C=u.useMemo(()=>s.filter(z=>z.status==="orphaned"),[s]),T=u.useCallback(z=>{const H={...z.values??{}};for(const P of Object.keys(H)){const I=It(z.translation_key,P);I!==void 0&&(H[P]=I)}return H},[]),E=u.useCallback(z=>h[z.id]??T(z),[h,T]),A=u.useCallback((z,H,P)=>{v(I=>{const L=I[z]??s.find(F=>F.id===z)?.values??{};return{...I,[z]:{...L,[H]:P}}})},[s]),N=u.useCallback(async z=>{_(z.id),k(I=>({...I,[z.id]:""}));const H=E(z),P=await Uy(e,z.id,H,z.lock_version);if(P.ok)a(I=>I.map(L=>L.id===z.id?P.data:L)),v(I=>{const L={...I};return delete L[z.id],L});else{const I=P.status===409?n("layout_editor.translation_manager.conflict"):P.message;k(L=>({...L,[z.id]:I}))}_(null)},[e,E,n]),D=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(!D(1))return;const H=await qy(e,z.id);H.ok?(a(P=>P.filter(I=>I.id!==z.id)),m(P=>{const I=new Set(P);return I.delete(z.id),I})):p(H.message)},[e,D]),M=u.useCallback(async z=>{if(z.length===0||!D(z.length))return;const H=await Gy(e,z);if(H.ok){const P=new Set(z);a(I=>I.filter(L=>!P.has(L.id))),m(new Set)}else p(H.message)},[e,D]),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:bm,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:mm,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:vm,"data-testid":"g7le-translation-manager-close",children:"✕"})]}),i.jsxs("div",{style:_m,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?xm:md,"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:vd,"data-testid":"g7le-translation-bulk-delete",children:["🗑 ",n("layout_editor.translation_manager.delete_selected",{count:g.size})]}),C.length>0&&i.jsxs("button",{type:"button",onClick:()=>void M(C.map(z=>z.id)),style:vd,"data-testid":"g7le-translation-purge-orphaned",children:["🧹 ",n("layout_editor.translation_manager.purge_orphaned",{count:C.length})]})]}),c&&i.jsx("div",{style:wm,"data-testid":"g7le-translation-manager-error",children:c}),i.jsx("div",{style:km,children:l==="loading"?i.jsx("div",{style:_d,"data-testid":"g7le-translation-manager-loading",children:n("layout_editor.translation_manager.loading")}):S.length===0&&l!=="error"?i.jsx("div",{style:_d,"data-testid":"g7le-translation-manager-empty",children:n("layout_editor.translation_manager.empty")}):i.jsx("div",{"data-testid":"g7le-translation-list",style:Sm,children:S.map(z=>{const H=E(z),P=z.status==="orphaned",I=o?o.has(z.translation_key):null;return i.jsxs("div",{style:Cm,"data-testid":`g7le-translation-row-${z.id}`,children:[i.jsxs("div",{style:$m,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:Em,children:z.translation_key}),P&&i.jsx("span",{style:Im,"data-testid":`g7le-translation-badge-orphaned-${z.id}`,children:n("layout_editor.translation_manager.badge_orphaned")}),I===!0&&i.jsx("span",{style:Am,"data-testid":`g7le-translation-badge-live-inuse-${z.id}`,children:n("layout_editor.translation_manager.badge_live_in_use")}),I===!1&&i.jsx("span",{style:Tm,"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:Om,"data-testid":`g7le-translation-delete-${z.id}`,children:"🗑"})]}),i.jsxs("div",{style:Dm,children:[$.map(L=>{const F=H[L]??"",Y=An(F).length>0;return i.jsxs("div",{style:zm,"data-testid":`g7le-translation-field-${z.id}-${L}`,children:[i.jsxs("label",{style:Nm,title:L,children:[Gn(L,n),i.jsxs("span",{style:Mm,children:["(",L,")"]})]}),Y?i.jsx("div",{style:{flex:1},"data-testid":`g7le-translation-chip-${z.id}-${L}`,children:i.jsx(xr,{value:F,onChange:K=>A(z.id,L,K),t:n,testIdSuffix:`${z.id}-${L}`})}):i.jsx("textarea",{value:F,rows:1,ref:gm,onChange:K=>{A(z.id,L,K.currentTarget.value),bd(K.currentTarget)},style:Lm,"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:Pm,"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:Bm,children:i.jsx("button",{type:"button",onClick:r,style:Wm,"data-testid":"g7le-translation-manager-footer-close",children:n("layout_editor.translation_manager.close")})})]})}const bm={display:"flex",flexDirection:"column",minHeight:0,flex:1},mm={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #e2e8f0"},vm={border:"none",background:"transparent",fontSize:16,color:"#94a3b8",cursor:"pointer"},_m={padding:"10px 16px",borderBottom:"1px solid #f1f5f9",display:"flex",gap:8,alignItems:"center"},md={padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},xm={...md,borderColor:"#2563eb",background:"#eff6ff",color:"#1d4ed8",fontWeight:600},vd={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"},km={padding:16,overflow:"auto",flex:1,minHeight:120,display:"flex",flexDirection:"column",gap:12},_d={fontSize:13,color:"#94a3b8",textAlign:"center",padding:"32px 0"},Sm={display:"flex",flexDirection:"column",gap:20},Cm={border:"1px solid #e2e8f0",borderRadius:8,padding:10,display:"flex",flexDirection:"column",gap:6},$m={display:"flex",alignItems:"center",gap:8},Em={fontSize:11,background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a"},Im={fontSize:10,color:"#b45309",background:"#fef3c7",padding:"1px 6px",borderRadius:4,fontWeight:600},Am={fontSize:10,color:"#15803d",background:"#dcfce7",padding:"1px 6px",borderRadius:4,fontWeight:600},Tm={fontSize:10,color:"#9f1239",background:"#ffe4e6",padding:"1px 6px",borderRadius:4,fontWeight:600},Dm={display:"flex",flexDirection:"column",gap:6},zm={display:"flex",alignItems:"flex-start",gap:8},Nm={fontSize:12,color:"#475569",minWidth:88,fontWeight:600,paddingTop:4,display:"flex",flexDirection:"column",lineHeight:1.2},Mm={fontSize:10,color:"#94a3b8",fontWeight:400},Lm={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"},Pm={padding:"5px 12px",fontSize:12,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},Om={padding:"4px 8px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},Bm={padding:"10px 16px",borderTop:"1px solid #e2e8f0",display:"flex",justifyContent:"flex-end"},Wm={padding:"6px 14px",fontSize:13,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"};function jm(){const e=Ft(),{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:qn(o,r,c,p),[o,r]),d=u.useCallback(async(c,p,f)=>o?vr(o,c,p,f):null,[o]);return{raw:n,getValue:s,patch:a,createI18nKey:l,updateI18nKeyValue:d}}function Hm(e){const t=e.__source;return t&&(t.kind==="module"||t.kind==="plugin")&&t.identifier?`${t.kind}:${t.identifier}`:"template"}function xd(e,t){if(!t)return null;const n=Hm(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(Fm(r,s))return{value:a,match:{dataSourceId:e.id,resolvedBy:"spec_byEndpoint"}}}return null}function rs(e,t){const n=xd(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 Fm(e,t){const n=t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${n}$`).test(e)}function Km(e={}){const{spec:t,overrideSpec:n,onMatch:o}=e;return{has(r){return!0},resolve(r){const s=n?xd(r,n):null,{value:a,match:l}=s??rs(r,t);if(o)try{o(l)}catch{}return a}}}const wd=Lt(),kd=wd.DataBindingEngine,Sd=wd.dataBindingEngine;mo("PipeRegistry");function Vm(e){let t=null,n=0;for(let o=0;o<e.length;o++){const r=e[o],s=o>0?e[o-1]:"",a=o<e.length-1?e[o+1]:"";if(s!=="\\"){if((r==='"'||r==="'")&&!t){t=r;continue}if(r===t){t=null;continue}if(!t){if(r==="("||r==="["||r==="{"){n++;continue}if(r===")"||r==="]"||r==="}"){n--;continue}if(r==="|"&&a!=="|"&&s!=="|"&&n===0)return!0}}}return!1}const Um=new Set(["comment"]);function Cd(e){if(!e||typeof e!="object")return[];const t=[];for(const[n,o]of Object.entries(e)){if(Um.has(n)||!o||typeof o!="object")continue;const r=o;typeof r.expr!="string"||r.expr.length===0||t.push({id:n,label:typeof r.label=="string"?r.label:void 0,params:Array.isArray(r.params)?r.params:[],expr:r.expr,group:typeof r.group=="string"?r.group:void 0,source:r.__source})}return t}function qm(e,t){let n=e.replace(/\{(\w+)\*\}(\s*\?\?\s*)?/g,(o,r,s)=>{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 wr(e){const t=e.trim(),n=/^\{\{([\s\S]*)\}\}$/.exec(t);return n?n[1].trim():t}function $d(e){const t=e.trim();return/^\{\{[\s\S]*\}\}$/.test(t)?t:`{{ ${t} }}`}function Ed(e,t){const n={};for(const[r,s]of Object.entries(t))n[r]=typeof s=="string"?wr(s):s;const o=qm(e.expr,n);return $d(o)}function Gm(e,t){if(typeof e!="string")return null;const n=Id(wr(e));for(const o of t){const r=Ym(n,o.expr,o.params);if(r)return{recipeId:o.id,params:r}}return null}function Id(e){return e.replace(/\s+/g," ").trim()}function Ad(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ym(e,t,n){const o=[],r=new Set;let s="";const a=/\{(\w+)(\*?)\}(\s*\?\?\s*)?/g;let l=0,d;const c=Id(t);for(;(d=a.exec(c))!==null;){const g=c.slice(l,d.index);s+=Ad(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+=Ad(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 Xm(e){const t=`x.${e.field}`,n=Jm(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 Jm(e){const t=e.trim();return t==="true"||t==="false"||t!==""&&!Number.isNaN(Number(t))||/^['"].*['"]$/.test(t)||/[.([{]/.test(t)?t:`'${t.replace(/'/g,"\\'")}'`}function is(e){return!e||e.length===0?"true":e.map(Xm).join(" && ")}function Zm(e){const n=`(${(e.source??"").trim()||"[]"} ?? [])`;let o;switch(e.op){case"count":o=`${n}.filter(x => ${is(e.conditions)}).length`;break;case"sum":{const r=(e.sumField??"").trim()||"value";o=`${n}.filter(x => ${is(e.conditions)}).reduce((s, x) => s + (x.${r} ?? 0), 0)`;break}case"filter":o=`${n}.filter(x => ${is(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 $d(o)}function Qm(e){if(typeof e!="string")return null;const t=wr(e).trim();let n=/^\((.+?)\s*\?\?\s*\[\]\)\.filter\(x => (.+)\)\.length$/.exec(t);return n?{key:"",op:"count",source:n[1].trim(),conditions:ss(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:ss(n[2]),sumField:n[3]}:(n=/^\((.+?)\s*\?\?\s*\[\]\)\.filter\(x => (.+)\)$/.exec(t),n?{key:"",op:"filter",source:n[1].trim(),conditions:ss(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 ss(e){const t=e.trim();if(t==="true")return[];const n=[];for(const o of Rm(t)){const r=ev(o.trim());r&&n.push(r)}return n}function Rm(e){const t=[];let n=0,o=0;for(let r=0;r<e.length;r++){const s=e[r];s==="("||s==="["||s==="{"?n++:s===")"||s==="]"||s==="}"?n--:n===0&&s==="&"&&e[r+1]==="&"&&(t.push(e.slice(o,r)),r++,o=r+1)}return t.push(e.slice(o)),t}function ev(e){let t=/^\(x\.(\w+(?:\.\w+)*) \?\? \[\]\)\.includes\((.+)\)$/.exec(e);if(t)return{field:t[1],cmp:"includes",value:Td(t[2])};if(t=/^x\.(\w+(?:\.\w+)*)\s*(===|!==|>=|<=|>|<)\s*(.+)$/.exec(e),t){const n={"===":"=","!==":"!=",">":">","<":"<",">=":">=","<=":"<="};return{field:t[1],cmp:n[t[2]]??"=",value:Td(t[3])}}return null}function Td(e){const t=e.trim(),n=/^'(.*)'$/.exec(t)||/^"(.*)"$/.exec(t);return n?n[1]:t}function Dd(e,t){const n=Gm(e,t);if(n)return{kind:"preset",recipeId:n.recipeId,params:n.params};const o=Qm(e);return o?{kind:"custom",model:o}:{kind:"advanced"}}function tv(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 zd(e,t){if(typeof e!="string"||e.trim()==="")return{ok:!1,reason:"empty"};const n=wr(e);try{const o=Vm(n)?Sd.evaluatePipeExpression(n,t??{},{skipCache:!0}):Sd.evaluateExpression(n,t??{},{skipCache:!0});return{ok:!0,value:o,type:tv(o)}}catch(o){return{ok:!1,reason:o instanceof Error?o.message:String(o)}}}function Nd(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}=rs(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 Md(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 Ld(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=zd(s,n);o[r]=a.ok?a.value:s}return o}function nv(e,t){const n=Nd(e,t),o=Md(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]=Ld(s.tree,o):r[s.scope]=s.tree;return r}function Pd(e){const{raw:t,spec:n,evaluateComputed:o}=e;return u.useMemo(()=>{const r=Nd(t,n),s=Md(t,n);if(o){const a=s.findIndex(l=>l.scope==="_computed");if(a>=0){const l=Ld(s[a].tree,s);s[a]={scope:"_computed",tree:l}}}return Ki({dataSources:r,states:s,spec:n??void 0})},[t,n,o])}function ov(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}=rs(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=Ki({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 Od(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 Bd(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 as(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 ls(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 rv(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:as(a,t),source:ls(a,n)}))}return r}function Wd(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 iv(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:sv(s,a,t)}))}return o}function sv(e,t,n){const r=e?.meta?.editor_label;if(typeof r=="string"&&r.length>0)return jd(r,n);const s=e?.title;return typeof s=="string"&&s.length>0?jd(s,n):t}function jd(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 Hd=mo("ActionRecipeEngine"),av={api:"apiCall",nav:"navigate",showToast:"toast",setLocalState:"setState"},lv=new Set(["comment"]);function ko(e){if(!e||typeof e!="object")return[];const t=[];for(const[n,o]of Object.entries(e)){if(lv.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 on(e){const t=/^\{\{\s*([\w.]+)\s*\}\}$/.exec(e);return t?t[1]:null}const kr="...";function dv(e,t){return e.replace(/\{\{\s*([\w.]+)\s*\}\}/g,(n,o)=>{const r=t[o];return r==null?"":String(r)})}function ds(e,t){if(typeof e=="string"){const n=on(e);return n!==null?n in t?t[n]:void 0:e.includes("{{")?dv(e,t):e}if(Array.isArray(e))return e.map(n=>ds(n,t)).filter(n=>n!==void 0);if(e&&typeof e=="object"){const n={};for(const[o,r]of Object.entries(e)){if(o===kr&&typeof r=="string"){const d=on(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=ds(r,t);if(s===void 0||Array.isArray(s)&&s.length===0&&(o==="onSuccess"||o==="onError"))continue;const a=on(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 cv(e){const t=e.handler;if(typeof t!="string")return e;const n=av[t];if(n)return Hd.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&&Hd.warn(`action recipe build placed "${r}" inside params for handler "${t}" — should be top-level (core handler rules)`)}return e}function Sr(e,t){const n=ds(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&&Fd(e.build,n,o)}return cv(n)}function Fd(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=on(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;Fd(a,r[s],n)}}}function uv(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&&!pv(s.build,e))continue;const l=fv(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 pv(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"&&on(a)!==null);return s.length===0?!1:s.every(([a])=>a in r)}function fv(e,t){const n={},o=(r,s)=>{if(typeof r=="string"){const a=on(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[kr],d=typeof l=="string"?on(l):null,c=new Set(Object.keys(r).filter(p=>p!==kr));for(const[p,f]of Object.entries(r))if(p!==kr){if(typeof f=="string"&&on(f)!==null){const b=on(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 Yn(e,t){const n=typeof e?.handler=="string"?e.handler:"",o=uv(e,t);return o?{kind:"preset",recipeId:o.recipeId,values:o.values,handler:n}:{kind:"advanced",handler:n}}function Kd(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=gv(d);if(c!==""&&(s.push(c),s.length>=2))break}return s.length===0?r:`${r} (${s.join(", ")})`}function gv(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):Array.isArray(e)?`[${e.length}]`:e&&typeof e=="object"?"{…}":""}function Vd(e,t){const n={...e};return typeof t=="string"&&t.trim().length>0?n.if=t.trim():delete n.if,n}function cs(e){const t=e?.if;return typeof t=="string"&&t.trim().length>0?t:null}const hv=/^\s*\$t:(custom\.[a-zA-Z0-9._-]+)\s*$/,yv=/^\s*\$t:([a-zA-Z0-9._-]+)\s*$/,bv=/\{\{.*?\}\}/;function Ud(e,t){const n=typeof e=="string"?e:"",o=hv.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(bv.test(n))return{customKey:null,binding:!0,paramKey:!1,displayValue:n};const s=yv.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 mv(){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=>Ud(l,r),[r]),a=u.useCallback(async(l,d)=>{const c=Ud(l,r);if(c.binding)return{kind:"blocked"};if(c.customKey){if(d===c.displayValue)return{kind:"noop",customKey:c.customKey};const b=await vr(t,c.customKey,n,d);return b.kind==="error"?{kind:"error",message:b.message}:(await tn(t,n),{kind:"updated",customKey:c.customKey})}const p=await qn(t,o,n,d);if(p.kind==="error"||!p.resource)return{kind:"error",message:p.message};const f=p.resource.translation_key;return await tn(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 us(e,t,n,o,r,s,a,l,d,c){const p=c?Zi(o,c):null,f=!!(p&&p.keyifiable),b=d?d(o):o,g=f?p.chipValue:Rl(b),h=`p${f?p.bindings.length:fr(b).length}`,v=Math.max(0,Math.min(r,g.length)),y=Ul(g,v,h),_=gr(y).replace(/\{\{?p\d+\}?\}/g," ").replace(/\s+/g," ").trim(),w=_.length>0?_:y,k=await qn(e,t,n,w);if(k.kind==="error"||!k.resource)return{kind:"error",message:k.message};const x=k.resource.translation_key,$=An(y),S=k.resource.values??{},C={[n]:y};for(const N of Object.keys(S)){if(N===n)continue;let D=S[N]??"";for(const B of $)D=Xi(D,B);C[N]=D}wo(e,x,C);const T=En(s,a,l);return{kind:"ok",text:`${f?Zl(`$t:${x}`,p):Ql(`$t:${x}`,b)}|${h}=${T}`,key:x}}async function Cr(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=En(r,s,a),p=`${n.trim()}|${d}=${c}`,f=await cn(e,l.key),b=Gb(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?Ul(v,o,d):Xi(v,d)}return wo(e,l.key,m),{kind:"ok",text:p,paramName:d}}async function So(e,t,n,o){return _r(e,t,n,o),{kind:"ok"}}async function vv(e,t,n){const o=await cn(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)}wo(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 qd(e,t,n){return vv(e,t,o=>nd(o,n))}function Gd(e,t){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:e,locale:t}}))}catch{}}async function $r(e,t,n,o){const r=await qd(e,t,n);return Gd(e,o),r}const _v=/^\s*\$t:(custom\.[a-zA-Z0-9._-]+)\s*$/;function xv(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 Yd(e){const t=e.text;if(typeof t!="string")return null;const n=_v.exec(t);if(n)return n[1];const o=vt(t);return o&&o.key.startsWith("custom.")?o.key:null}function ps(e){const t={},n=vt(typeof e=="string"?e:"");for(const o of n?.params??[])t[o.name]=Vt(o.expression);return t}function wv(e){return ps(typeof e.text=="string"?e.text:"")}function Xd({customKey:e,templateIdentifier:t,t:n,paramLabels:o,locales:r,onRemoveParam:s}){const a=r??hd(),l=Ft(),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 A=await cn(t,e);if(E)return;if(!A){p({status:"error",values:{}});return}const N={...A.values??{}};for(const D of Object.keys(N)){const B=It(e,D);B!==void 0&&(N[D]=B)}for(const D of a){const B=It(e,D);B!==void 0&&(N[D]=B)}y.current={...N},p({status:"loaded",id:A.id,lockVersion:A.lock_version,values:N})})(),()=>{E=!0}},[e,t]),u.useEffect(()=>{if(typeof window>"u"||!e)return;const E=A=>{const N=A.detail;N?.templateIdentifier&&N.templateIdentifier!==t||p(D=>{if(D.status!=="loaded")return D;let B=!1;const M={...D.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},{...D,values:M}):D})};return window.addEventListener(kt,E),()=>window.removeEventListener(kt,E)},[e,t]);const _=u.useCallback((E,A)=>{p(N=>{const D=N.values[E]??"",B={...N,values:{...N.values,[E]:A}};return e&&xv(D,A)&&(_r(t,e,E,A),y.current={...y.current,[E]:A},l?.markDirty?.(),Gd(t,E)),B})},[e,t,l]),w=u.useCallback(E=>{p(A=>{const N={};for(const[D,B]of Object.entries(A.values))N[D]=nd(B,E);return y.current={...N},{...A,values:N}}),s?.(E)},[s]),k=u.useMemo(()=>[...Object.values(c.values),...Object.values(y.current)].some(A=>An(A).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 S=u.useCallback(async()=>{if(m(!1),c.status!=="loaded"||c.id===void 0)return;const E=y.current;for(const[N,D]of Object.entries(c.values)){const B=E[N]??"";if(k){const M=An(B);if(M.length===0)continue;const O=An(D);if(!(M.length===O.length&&M.every((H,P)=>H===O[P]))){v(n("layout_editor.translation.placeholder_mismatch"));return}continue}if(Yi(B)&&!Tb(B,D)){v(n("layout_editor.translation.token_mismatch"));return}}if(b(!0),v(null),k){wo(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 A=`/api/admin/templates/${encodeURIComponent(t)}/custom-translations/${c.id}`;try{const N=await fetch(A,{method:"PUT",credentials:"same-origin",headers:Ne({"Content-Type":"application/json"}),body:JSON.stringify({values:c.values,expected_lock_version:c.lockVersion??0})}),D=await N.json().catch(()=>null);if(N.status===409){v(n("layout_editor.translation.conflict"));return}if(!N.ok){v(D?.message??n("layout_editor.translation.save_failed"));return}const B=typeof D?.data?.lock_version=="number"?D.data.lock_version:(c.lockVersion??0)+1;p(M=>({...M,lockVersion:B})),y.current={...c.values},await tn(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:fs,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:fs,children:n("layout_editor.translation.loading")});if(c.status==="error")return i.jsx("div",{"data-testid":"g7le-translation-error",style:fs,children:n("layout_editor.translation.load_failed")});const C=new Set([...a,...Object.keys(c.values)]),T=Array.from(C);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:kv,children:[n("layout_editor.translation.key_label"),": ",i.jsx("code",{style:Sv,children:e})]}),T.map(E=>{const A=c.values[E]??"",N=A.trim().length===0;return i.jsxs("div",{className:"g7le-translation-row","data-testid":`g7le-translation-row-${E}`,style:Cv,children:[i.jsxs("label",{htmlFor:`g7le-translation-input-${E}`,style:{fontSize:12,color:"#475569",minWidth:72,display:"inline-flex",alignItems:"center",gap:4},children:[Gn(E,n),N&&i.jsx("span",{"data-testid":`g7le-translation-missing-${E}`,style:$v,children:n("layout_editor.translation.needs_translation")})]}),k?i.jsx("div",{style:{flex:1},"data-testid":`g7le-translation-chip-${E}`,children:i.jsx(xr,{value:A,onChange:D=>_(E,D),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:A,placeholder:N?n("layout_editor.translation.needs_translation"):"",onChange:D=>_(E,D.currentTarget.value),onBlur:S,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:S,style:Ev,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 fs={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},kv={fontSize:12,color:"#475569"},Sv={fontSize:11,background:"#f1f5f9",padding:"1px 4px",borderRadius:3,color:"#0f172a"},Cv={display:"flex",alignItems:"center",gap:8},$v={fontSize:10,color:"#b45309",background:"#fef3c7",padding:"0 4px",borderRadius:3},Ev={padding:"6px 12px",fontSize:12,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"};function Xn({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 S=_-v.bottom-l,C=v.top-l;let T,E;const A=r==="bottom",N=S>=Math.min(x,160),D=C>=Math.min(x,160);A&&N||A&&!D?(T=v.bottom+4,E=S):!A&&D||D?(T=v.top-4-Math.min(x,C),E=C):S>=C?(T=v.bottom+4,E=S):(T=l,E=C),f({left:$,top:T,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={...Iv,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 Iv={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 Jd(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(()=>Ui(e,"scalar").map(h=>({...h,resolvedLabel:Jd(t,h.labelKey,h.path||h.sourceId)})),[e,t]),b=u.useMemo(()=>qi(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:zv}),i.jsx("div",{style:Nv,children:b.length===0?i.jsx("div",{style:Mv,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:Lv,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:Pv,children:[Jd(t,m.groupLabelKey,m.sourceId)," · ",m.path||m.sourceId]})]}),i.jsx("span",{style:Ov,children:m.preview})]},m.expression))})]});return i.jsxs("div",{style:s?Dv:{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:Av,children:"🔍"}),s?i.jsx(Xn,{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:Tv,children:g})]})}const Av={fontSize:13,lineHeight:1,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#334155",padding:"4px 8px",cursor:"pointer",textAlign:"center",whiteSpace:"nowrap"},Tv={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6},Dv={display:"inline-block"},zv={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},Nv={marginTop:4,maxHeight:200,overflowY:"auto",display:"flex",flexDirection:"column",gap:2},Mv={fontSize:11,color:"#94a3b8",padding:"8px 0",textAlign:"center"},Lv={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:"none",background:"transparent",cursor:"pointer",padding:"6px 8px",borderRadius:4,textAlign:"left"},Pv={fontSize:10,color:"#94a3b8"},Ov={fontSize:10,color:"#64748b",fontFamily:"monospace",whiteSpace:"nowrap"},Bv=["$localized"];function Jn(e){const t=e.trim();if(!t.startsWith("{{")||!t.endsWith("}}")||t.length<4)return null;let n=0;for(let o=0;o<t.length;o++){if(t[o]==="{"&&t[o+1]==="{"){n++,o++;continue}if(t[o]==="}"&&t[o+1]==="}"&&(n--,o++,n===0))return o===t.length-1?t.slice(2,-2).trim():null}return null}function Zd(e){if(typeof e!="string"||e.trim()===""||Jn(e)!==null)return!1;const t=e.match(/\{\{(?:[^}]|\}(?!\}))*\}\}/g);return!t||t.length===0?!1:t.some(n=>un(n).decomposed)}function Co(e,t,n,o){switch(e.kind){case"leaf":Qd(e.text,t,n,o);return;case"conditional":Co(e.then,t,n,o),o.push({kind:"ellipsis",text:"⋯"});return;case"fallback":Co(e.primary,t,n,o);return;case"concat":e.parts.forEach(r=>Co(r,t,n,o));return;case"raw":default:o.push({kind:"text",text:e.source});return}}function Qd(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 gs(e,t,n){const o=[];if(typeof e!="string"||e==="")return o;if(Jn(e)===null&&/\{\{/.test(e)){for(const a of e.split(/(\{\{(?:[^}]|\}(?!\}))*\}\})/g))if(!(a===void 0||a===""))if(/^\{\{[\s\S]*\}\}$/.test(a)){const l=un(a);Co(l.node,t,n,o)}else Qd(a,t,n,o);return o}const s=un(e);return Co(s.node,t,n,o),o}function Wv(e){if(typeof e!="string"||e.trim()==="")return"empty";const t=e.trim();if(Jn(t)===null)return"simple";const n=un(e);return n.node.kind==="leaf"?"simple":n.decomposed?"expression":"raw"}function un(e){const t=typeof e=="string"?e:"",n=t.trim();if(n==="")return{node:{kind:"leaf",text:t},decomposed:!1,original:t};const o=Jn(n);if(o===null)return{node:{kind:"leaf",text:t},decomposed:!1,original:t};let r;try{r=Yv(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==="??"&&jv(r.primary)&&Hv(r.fallback))return{node:{kind:"leaf",text:t},decomposed:!1,original:t};const s=Zn(r,!0);return Rv(o,s)?{node:r,decomposed:!0,original:t}:{node:{kind:"raw",source:o},decomposed:!1,original:t}}function Zn(e,t=!1){const n=ec(e);return t?n:e.kind==="leaf"?e.text:`{{${n}}}`}function $o(e){return Zn({kind:"conditional",condition:{kind:"simple",left:"",op:"truthy",right:""},then:{kind:"leaf",text:typeof e=="string"?e:""},else:{kind:"leaf",text:""}},!1)}function hs(e){return Zn({kind:"fallback",op:"??",primary:{kind:"leaf",text:typeof e=="string"?e:""},fallback:{kind:"leaf",text:""}},!1)}function Eo(e){switch(e.kind){case"leaf":return e.text;case"conditional":return Eo(e.then);case"fallback":return Eo(e.primary);case"concat":return e.parts.map(Eo).join("");case"raw":default:return e.kind==="raw"?`{{${e.source}}}`:""}}function WM(e){return e}function Er(e){if(typeof e!="string"||e.trim()==="")return"";if(Jn(e)===null&&/\{\{/.test(e)){for(const n of e.split(/(\{\{(?:[^}]|\}(?!\}))*\}\})/g))if(!(n===void 0||n===""))return/^\{\{[\s\S]*\}\}$/.test(n)?Eo(un(n).node):n;return""}return Eo(un(e).node)}function jv(e){if(e.kind!=="leaf")return!1;const t=/^\{\{([\s\S]*)\}\}$/.exec(e.text.trim());return t?Qn(t[1].trim()):!1}function Hv(e){if(e.kind!=="leaf")return!1;const t=e.text.trim();return!(/\{\{/.test(t)||t.startsWith("$t:"))}function Ir(e){return`'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function Fv(e){const t=[];let n=0,o=0;const r=e.length;for(;o<r;){if(e[o]==="{"&&e[o+1]==="{"){o>n&&t.push(Ir(e.slice(n,o)));let s=o+2;for(;s<r&&!(e[s]==="}"&&e[s+1]==="}");)s++;if(s>=r)break;const a=e.slice(o+2,s).trim();t.push(a),o=s+2,n=o;continue}o++}return n<r&&t.push(Ir(e.slice(n))),t.length===0?Ir(e):t.join(" + ")}function Kv(e){const t=e.trim(),n=/^\{\{([\s\S]*)\}\}$/.exec(t);return n?n[1].trim():!t.startsWith("$t:")&&/\{\{/.test(t)?Fv(e):Ir(e)}const Rd="false";function Vv(e){if(e.kind==="raw")return e.source;if(e.left.trim()==="")return Rd;if(e.op==="truthy")return e.left;if(e.op==="falsy")return`!${Uv(e.left)?`(${e.left})`:e.left}`;const t=e.right.trim()===""?"''":e.right;return`${e.left} ${e.op} ${t}`}function Uv(e){return/[\s()?:|&+]/.test(e.trim())&&!/^[A-Za-z_$][\w$.?[\]]*$/.test(e.trim())}function ec(e){switch(e.kind){case"leaf":return Kv(e.text);case"raw":return e.source;case"concat":return e.parts.map(t=>Io(t,"concat")).join(" + ");case"fallback":return`${Io(e.primary,"fallback")} ${e.op} ${Io(e.fallback,"fallback")}`;case"conditional":return`${Vv(e.condition)} ? ${Io(e.then,"conditional")} : ${Io(e.else,"conditional")}`;default:return""}}function Io(e,t){const n=ec(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 qv=["===","!==","??","||","&&","==","!=",">=","<="];function tc(e){const t=[];let n=0;const o=e.length;for(;n<o;){const r=e[n];if(/\s/.test(r)){n++;continue}if(r==="'"||r==='"'||r==="`"){const a=r;let l=n+1,d=a;for(;l<o;){if(e[l]==="\\"){d+=e[l]+(e[l+1]??""),l+=2;continue}if(e[l]==="{"&&e[l+1]==="{"){let c=l+2;for(;c<o&&!(e[c]==="}"&&e[c+1]==="}");)c++;if(c>=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<o;){if(e[a]==="}"&&e[a+1]==="}"){a+=2;break}a++}if(e[a-1]!=="}"||e[a-2]!=="}")throw new Error("unterminated-binding");t.push({kind:"binding",value:e.slice(n,a),start:n,end:a}),n=a;continue}if(r==="$"&&e.startsWith("$t:",n)){let a=n+3;for(;a<o&&/[a-zA-Z0-9._-]/.test(e[a]);)a++;t.push({kind:"tkey",value:e.slice(n,a),start:n,end:a}),n=a;continue}let s="";for(const a of qv)if(e.startsWith(a,n)){s=a;break}if(s){t.push({kind:"op",value:s,start:n,end:n+s.length}),n+=s.length;continue}if(r==="?"){t.push({kind:"op",value:"?",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:"op",value:"+",start:n,end:n+1}),n++;continue}if(r===">"||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<o&&/[0-9.]/.test(e[a]);)a++;t.push({kind:"number",value:e.slice(n,a),start:n,end:a}),n=a;continue}if(/[A-Za-z_$]/.test(r)){let a=n;for(;a<o&&/[A-Za-z0-9_$]/.test(e[a]);)a++;t.push({kind:"ident",value:e.slice(n,a),start:n,end:a}),n=a;continue}t.push({kind:"other",value:r,start:n,end:n+1}),n++}return t}class Gv{constructor(t){Ni(this,"toks");Ni(this,"pos",0);Ni(this,"src");this.src=t,this.toks=tc(t)}parse(){const t=this.parseTernary();if(this.pos<this.toks.length)throw new Error("trailing-tokens");return t}peek(){return this.toks[this.pos]}next(){return this.toks[this.pos++]}parseTernary(){const t=this.pos,n=this.findTopLevelQuestion(t);if(n===-1)return this.parseFallback();const o=this.sliceSource(t,n);this.pos=n+1;const r=this.parseTernary(),s=this.next();if(!s||s.kind!=="op"||s.value!==":")throw new Error("expected-colon");const a=this.parseTernary();return{kind:"conditional",condition:Jv(o.trim()),then:r,else:a}}findTopLevelQuestion(t){let n=0;for(let o=t;o<this.toks.length;o++){const r=this.toks[o];if(r.kind==="lparen"||r.kind==="lbracket")n++;else if(r.kind==="rparen"||r.kind==="rbracket"){if(n===0)return-1;n--}else if(n===0&&r.kind==="op"&&r.value==="?"){if(this.toks[o+1]?.kind==="dot")continue;return o}else if(n===0&&r.kind==="op"&&r.value===":")return-1}return-1}sliceSource(t,n){if(t>=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:oc(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"&&Bv.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 Yv(e){return new Gv(e).parse()}const Xv=["===","!==","==","!=",">=","<=",">","<"];function Jv(e,t){const n=e.trim();if(n==="")return{kind:"raw",source:n};if(n===Rd)return{kind:"simple",left:"",op:"truthy",right:""};if(n.startsWith("!")){const s=n.slice(1).trim(),a=nc(s);return Qn(a)?{kind:"simple",left:a,op:"falsy",right:""}:{kind:"raw",source:n}}const o=Zv(n);if(o){const{left:s,op:a,right:l}=o,d=s.trim(),c=l.trim();return Qn(d)&&(c==="''"||c==='""')?{kind:"simple",left:d,op:a,right:""}:Qn(d)&&Qv(c)?{kind:"simple",left:d,op:a,right:c}:{kind:"raw",source:n}}const r=nc(n);return Qn(r)?{kind:"simple",left:r,op:"truthy",right:""}:{kind:"raw",source:n}}function Zv(e){let t=0,n=null;for(let o=0;o<e.length;o++){const r=e[o];if(n){if(r==="\\"){o++;continue}r===n&&(n=null);continue}if(r==="'"||r==='"'||r==="`"){n=r;continue}if(r==="("||r==="["){t++;continue}if(r===")"||r==="]"){t--;continue}if(t===0){if(r==="&"&&e[o+1]==="&"||r==="|"&&e[o+1]==="|"||r==="?"&&e[o+1]==="?")return null;for(const s of Xv)if(e.startsWith(s,o))return{left:e.slice(0,o),op:s,right:e.slice(o+s.length)}}}return null}function nc(e){let t=e.trim();for(;t.startsWith("(")&&t.endsWith(")");){let n=0,o=!0;for(let r=0;r<t.length;r++)if(t[r]==="(")n++;else if(t[r]===")"&&(n--,n===0&&r<t.length-1)){o=!1;break}if(!o)break;t=t.slice(1,-1).trim()}return t}function Qn(e){const t=e.trim();if(t==="")return!1;let n=0;const o=t.length;if(!/[A-Za-z_$]/.test(t[0]))return!1;for(n++;n<o&&/[\w$]/.test(t[n]);)n++;for(;n<o;){if(t[n]==="?"&&t[n+1]==="."){if(n+=2,n>=o||!/[A-Za-z_$]/.test(t[n]))return!1;for(n++;n<o&&/[\w$]/.test(t[n]);)n++;continue}if(t[n]==="."){if(n++,n>=o||!/[A-Za-z_$]/.test(t[n]))return!1;for(n++;n<o&&/[\w$]/.test(t[n]);)n++;continue}if(t[n]==="["){const r=t.indexOf("]",n);if(r===-1)return!1;const s=t.slice(n+1,r).trim();if(!/^\d+$/.test(s)&&!/^'[^']*'$/.test(s)&&!/^"[^"]*"$/.test(s))return!1;n=r+1;continue}return!1}return!0}function Qv(e){const t=e.trim();return/^'[^']*'$/.test(t)||/^"[^"]*"$/.test(t)||/^-?\d+(\.\d+)?$/.test(t)||/^(true|false|null|undefined)$/.test(t)?!0:Qn(t)}function oc(e){const t=e.trim();return t.length>=2&&(t[0]==="'"||t[0]==='"'||t[0]==="`")?t.slice(1,-1).replace(/\\(['"`\\])/g,"$1"):t}function Rv(e,t){try{return Ar(e)===Ar(t)}catch{return!1}}function Ar(e){const t=Jn(e);return t!==null?Ar(t):tc(e).map(o=>{if(o.kind==="string")return`S:${oc(o.value)}`;if(o.kind==="binding"){const r=/^\{\{([\s\S]*)\}\}$/.exec(o.value);return`B:${r?Ar(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 Rn({active:e,testid:t}){return i.jsx("div",{"data-testid":t,"data-active":e?"true":"false","aria-hidden":"true",style:e?t_:e_})}const e_={height:0,margin:0,transition:"height 80ms"},t_={height:3,margin:"1px 0",borderRadius:2,background:"#2563eb",boxShadow:"0 0 0 1px #93c5fd"};function ys(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 n_={text:"",expression:"{{false ? '' : ''}}",fallback:"{{'' ?? ''}}",data:""};function rc(e,t){const n=In(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 bs({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=rc(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=rc(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:n_[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]),_=ys({length:c.length,onMove:y});return i.jsxs("div",{"data-testid":r,style:i_,children:[i.jsx("div",{style:s_,children:n("layout_editor.value_tree.segmented_hint")}),c.map((w,k)=>i.jsxs(u.Fragment,{children:[i.jsx(Rn,{active:_.isDropTarget(k),testid:`${r}-dropline-${k}`}),i.jsx(r_,{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(Rn,{active:_.isDropTarget(c.length),testid:`${r}-dropline-end`}),i.jsxs("div",{style:p_,"data-testid":`${r}-add-row`,children:[i.jsxs("button",{type:"button","data-testid":`${r}-add-text`,onClick:()=>v("text"),style:Tr,children:["+ ",n("layout_editor.value_tree.segment.text")]}),i.jsxs("button",{type:"button","data-testid":`${r}-add-expression`,onClick:()=>v("expression"),style:Tr,children:["+ ",n("layout_editor.value_tree.segment.expression")]}),i.jsxs("button",{type:"button","data-testid":`${r}-add-fallback`,onClick:()=>v("fallback"),style:Tr,children:["+ ",n("layout_editor.value_tree.segment.fallback")]}),i.jsxs("button",{type:"button","data-testid":`${r}-add-data`,onClick:()=>v("data"),style:Tr,children:["+ ",n("layout_editor.value_tree.segment.data")]})]}),i.jsxs("div",{style:h_,children:[i.jsxs("button",{type:"button","data-testid":`${r}-source-toggle`,"aria-expanded":f,onClick:()=>b(w=>!w),style:y_,children:["</>"," ",n("layout_editor.value_tree.show_source")," ",f?"▴":"▾"]}),f&&i.jsx("code",{"data-testid":`${r}-source-code`,style:b_,children:c.map(w=>w.value).join("")})]})]})}function o_({t:e,candidates:t,onPick:n,testidPrefix:o}){return!t||t.length===0?i.jsx("div",{"data-testid":`${o}-data-empty`,style:g_,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:f_,children:e("layout_editor.value_tree.segment.data_pick_hint")}),i.jsx($t,{candidates:t,t:e,onSelect:r=>{n(En(r.sourceId,r.path,"scalar"))},testIdSuffix:`${o}-data`,defaultOpen:!0,floating:!0})]})}function r_({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?{...ic,opacity:.5}:ic,onDragOver:m=>{m.preventDefault();const h=m.currentTarget.getBoundingClientRect();f(m.clientY<h.top+h.height/2?"before":"after")},onDrop:m=>{m.preventDefault(),b()},children:[i.jsxs("div",{style:a_,children:[i.jsx("span",{"data-testid":`${r}-drag-${t}`,style:c_,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:l_,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:u_,children:"✕"})]}),i.jsx("div",{style:d_,children:e.kind==="data"&&e.value.trim()===""?i.jsx(o_,{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 i_={display:"flex",flexDirection:"column",gap:6,width:"100%",minWidth:0},s_={fontSize:11,color:"#64748b"},ic={display:"flex",flexDirection:"column",gap:4,padding:"6px 8px",border:"1px solid #e2e8f0",borderLeft:"3px solid #6366f1",borderRadius:6,background:"#f8fafc",minWidth:0},a_={display:"flex",alignItems:"center",gap:6,minWidth:0},l_={fontSize:10,fontWeight:600,color:"#6366f1",flex:1,minWidth:0},d_={minWidth:0},c_={color:"#94a3b8",cursor:"grab",fontSize:14,userSelect:"none"},u_={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12,padding:2,flexShrink:0},p_={display:"flex",flexWrap:"wrap",gap:6,marginTop:2},f_={fontSize:11,color:"#64748b",marginBottom:2},g_={fontSize:11,color:"#94a3b8",padding:"4px 0"},Tr={padding:"4px 10px",fontSize:11,border:"1px dashed #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},h_={display:"flex",flexDirection:"column",gap:4,marginTop:2},y_={alignSelf:"flex-start",padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",fontFamily:"monospace"},b_={fontSize:11,background:"#0f172a",color:"#e2e8f0",padding:"6px 8px",borderRadius:4,wordBreak:"break-all",fontFamily:"monospace"},m_=[{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 sc({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(eo,{node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:l});return p?a?i.jsxs("div",{"data-testid":r,style:lc,children:[f,i.jsxs("div",{style:B_,children:[i.jsxs("button",{type:"button","data-testid":`${r}-source-toggle`,"aria-expanded":d,onClick:()=>c(b=>!b),style:W_,children:["</>"," ",n("layout_editor.value_tree.show_source")," ",d?"▴":"▾"]}),d&&i.jsx("code",{"data-testid":`${r}-source-code`,style:j_,children:Zn(e,!1)})]})]}):i.jsx("div",{"data-testid":r,style:lc,children:f}):f}function eo({node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a}){switch(e.kind){case"leaf":return i.jsx(bs,{value:e.text,onChange:l=>t({kind:"leaf",text:l}),t:n,candidates:o,testidPrefix:`${r}-leaf`,renderLeafInput:a});case"conditional":return i.jsx(v_,{node:e,onChange:t,t:n,candidates:o,testidPrefix:r,depth:s,renderLeafInput:a});case"fallback":return i.jsx(__,{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:H_,children:[i.jsx("code",{style:uc,children:e.source??""}),i.jsxs("span",{style:pc,children:["🔒 ",n("layout_editor.value_tree.raw_code_only")]})]})}}function v_({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:ms(s),children:[i.jsx(k_,{condition:e.condition,onChange:l,t:n,candidates:o,testidPrefix:r}),i.jsx(Dr,{label:n("layout_editor.value_tree.cond.when_true"),testid:`${r}-then`,children:i.jsx(eo,{node:e.then,onChange:d,t:n,candidates:o,testidPrefix:`${r}-then`,depth:s+1,renderLeafInput:a})}),i.jsx(Dr,{label:n("layout_editor.value_tree.cond.when_false"),testid:`${r}-else`,children:i.jsx(eo,{node:e.else,onChange:c,t:n,candidates:o,testidPrefix:`${r}-else`,depth:s+1,renderLeafInput:a})})]})}function __({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:ms(s),children:[i.jsx(Dr,{label:n("layout_editor.value_tree.fallback.primary"),testid:`${r}-primary`,children:i.jsx(eo,{node:e.primary,onChange:l,t:n,candidates:o,testidPrefix:`${r}-primary`,depth:s+1,renderLeafInput:a})}),i.jsx(Dr,{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(eo,{node:e.fallback,onChange:d,t:n,candidates:o,testidPrefix:`${r}-fallbackb`,depth:s+1,renderLeafInput:a})})]})}const x_={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,x_[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=ys({length:e.parts.length,onMove:f});return i.jsxs("div",{"data-testid":`${r}-concat`,style:ms(s),children:[i.jsx("div",{style:z_,children:n("layout_editor.value_tree.concat.hint")}),e.parts.map((g,m)=>i.jsxs(u.Fragment,{children:[i.jsx(Rn,{active:b.isDropTarget(m),testid:`${r}-part-dropline-${m}`}),i.jsxs("div",{"data-testid":`${r}-part-card-${m}`,style:b.dragIndex===m?{...cc,opacity:.5}:cc,onDragOver:h=>{h.preventDefault();const v=h.currentTarget.getBoundingClientRect();b.onDragOverItem(m,h.clientY<v.top+v.height/2?"before":"after")},onDrop:h=>{h.preventDefault(),b.onDrop()},children:[i.jsxs("div",{style:N_,children:[i.jsx("span",{"data-testid":`${r}-part-handle-${m}`,style:P_,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:M_,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:O_,children:"✕"})]}),i.jsx("div",{style:{minWidth:0},children:i.jsx(eo,{node:g,onChange:h=>l(m,h),t:n,candidates:o,testidPrefix:`${r}-part-${m}`,depth:s+1,renderLeafInput:a})})]})]},m)),i.jsx(Rn,{active:b.isDropTarget(e.parts.length),testid:`${r}-part-dropline-end`}),i.jsxs("div",{style:L_,"data-testid":`${r}-part-add-row`,children:[i.jsxs("button",{type:"button","data-testid":`${r}-part-add-text`,onClick:()=>p("text"),style:zr,children:["+ ",n("layout_editor.value_tree.segment.text")]}),i.jsxs("button",{type:"button","data-testid":`${r}-part-add-expression`,onClick:()=>p("expression"),style:zr,children:["+ ",n("layout_editor.value_tree.segment.expression")]}),i.jsxs("button",{type:"button","data-testid":`${r}-part-add-fallback`,onClick:()=>p("fallback"),style:zr,children:["+ ",n("layout_editor.value_tree.segment.fallback")]}),i.jsxs("button",{type:"button","data-testid":`${r}-part-add-data`,onClick:()=>p("data"),style:zr,children:["+ ",n("layout_editor.value_tree.segment.data")]})]})]})}function k_({condition:e,onChange:t,t:n,candidates:o,testidPrefix:r}){if(e.kind==="raw")return i.jsxs("div",{"data-testid":`${r}-cond-raw`,style:I_,children:[i.jsx("span",{style:dc,children:n("layout_editor.value_tree.cond.label")}),i.jsx("code",{style:uc,children:e.source}),i.jsxs("span",{style:pc,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:E_,children:[i.jsx("span",{style:dc,children:n("layout_editor.value_tree.cond.label")}),i.jsx(ac,{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:D_,children:m_.map(l=>i.jsx("option",{value:l.value,children:n(l.labelKey)},l.value))}),a&&i.jsx(ac,{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 ac({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=En(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:A_,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:T_}),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 Dr({label:e,testid:t,children:n}){return i.jsxs("div",{"data-testid":t,style:S_,children:[i.jsx("span",{style:C_,children:e}),i.jsx("div",{style:$_,children:n})]})}const lc={display:"flex",flexDirection:"column",gap:6,width:"100%",minWidth:0},ms=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}),S_={display:"flex",flexDirection:"column",gap:3,minWidth:0},C_={fontSize:11,fontWeight:600,color:"#475569"},$_={paddingLeft:8,minWidth:0},E_={display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",minWidth:0},I_={display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",minWidth:0},dc={fontSize:11,fontWeight:600,color:"#0f172a",whiteSpace:"nowrap"},A_={display:"inline-flex",alignItems:"flex-start",gap:2,flex:"1 1 80px",minWidth:60},T_={flex:"1 1 80px",minWidth:60,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},D_={padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff"},z_={fontSize:11,color:"#94a3b8"},cc={display:"flex",flexDirection:"column",gap:4,padding:"6px 8px",border:"1px solid #e2e8f0",borderLeft:"3px solid #6366f1",borderRadius:6,background:"#fff",minWidth:0},N_={display:"flex",alignItems:"center",gap:6,minWidth:0},M_={fontSize:10,fontWeight:600,color:"#6366f1",flex:1,minWidth:0},L_={display:"flex",flexWrap:"wrap",gap:6,marginTop:2},P_={color:"#94a3b8",cursor:"grab",fontSize:14,userSelect:"none"},O_={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12,padding:2,flexShrink:0},zr={padding:"4px 10px",fontSize:11,border:"1px dashed #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},B_={display:"flex",flexDirection:"column",gap:4,marginTop:2},W_={alignSelf:"flex-start",padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",fontFamily:"monospace"},j_={fontSize:11,background:"#0f172a",color:"#e2e8f0",padding:"6px 8px",borderRadius:4,wordBreak:"break-all",fontFamily:"monospace"},H_={display:"flex",flexDirection:"column",gap:2,minWidth:0},uc={fontSize:11,background:"#f1f5f9",padding:"3px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all",fontFamily:"monospace"},pc={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}=mv(),[h,v]=u.useState(null),[y,_]=u.useState(!1),[w,k]=u.useState(!1),[x,$]=u.useState(!1),[S,C]=u.useState(!1),[T,E]=u.useState(!1),[,A]=u.useState(0);u.useEffect(()=>{if(typeof window>"u")return;const z=H=>{const P=H.detail;P?.templateIdentifier&&P.templateIdentifier!==f||A(I=>I+1)};return window.addEventListener(kt,z),()=>window.removeEventListener(kt,z)},[f]);const N=g(e);u.useEffect(()=>{v(null),E(!1)},[p,e]);const D=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(vo(e,z)),N.customKey&&$r(f,N.customKey,z,p))},[e,t,N.customKey,f,p]);if(N.binding){if(l&&typeof e=="string"){const z=Zd(e),H=un(e),P=!z&&Kt(e)!==null,I=(z||H.decomposed)&&!P;if(I&&d&&!x)return i.jsx(V_,{value:e,t:n,translate:m,onEdit:()=>$(!0),testidPrefix:`${r}-preview`});const F=I&&(d||z)?i.jsx(bs,{value:e,onChange:Y=>t(Y),t:n,candidates:a,testidPrefix:`${r}-seg`}):H.decomposed?i.jsx(sc,{node:H.node,onChange:Y=>t(Zn(Y,!1)),t:n,candidates:a,testidPrefix:`${r}-tree`,showSourceToggle:c}):null;if(F){if(!d)return F;const Y=Er(e),K=Y?gs(Y,X=>{const Z=m(X);return Z&&Z!==X&&!Z.startsWith("$t:")?Z:""},X=>Vt(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:()=>C(!0),style:Z_,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:hc,title:n("layout_editor.value_tree.collapse"),"aria-label":n("layout_editor.value_tree.collapse"),children:["▴ ",n("layout_editor.value_tree.collapse")]})]}),S&&i.jsxs("div",{"data-testid":`${r}-to-plain-confirm`,style:Q_,children:[i.jsx("p",{style:R_,children:n("layout_editor.value_tree.to_plain_lead")}),i.jsx("div",{style:ex,children:K.length===0?i.jsx("span",{style:{color:"#94a3b8"},children:n("layout_editor.prop_i18n.placeholder")}):K.map((X,Z)=>X.kind==="chip"?i.jsxs("span",{style:fc,children:["🔗 ",X.text]},Z):i.jsx("span",{style:X.kind==="ellipsis"?gc:void 0,children:X.text},Z))}),i.jsxs("p",{style:tx,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:()=>C(!1),style:hc,children:n("layout_editor.value_tree.to_plain_cancel")}),i.jsx("button",{type:"button","data-testid":`${r}-to-plain-confirm-ok`,onClick:()=>{C(!1),$(!1),t(Er(e)||void 0)},style:nx,children:n("layout_editor.value_tree.to_plain_ok")})]})]}),F]})}}return l&&typeof e=="string"&&a&&a.length>0&&Kt(e)!==null?i.jsx(U_,{value:e,onChange:t,t:n,candidates:a,testidPrefix:`${r}-data`}):i.jsxs("div",{"data-testid":`${r}-binding`,style:lx,children:[i.jsx("code",{style:dx,children:typeof e=="string"?e:""}),i.jsxs("span",{style:cx,children:["🔗 ",n("layout_editor.prop_i18n.bound_code_only")]})]})}if(!T&&typeof e=="string"&&Xl(e)){const z=Jl(e);return i.jsxs("div",{"data-testid":`${r}-settings-ref`,style:ix,children:[i.jsx("div",{"data-testid":`${r}-settings-ref-chips`,style:sx,children:z.map((H,P)=>H.kind==="chip"?i.jsxs("span",{style:ax,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:yc,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")} (${Gn(p,n)})`,"aria-label":`${n("layout_editor.prop_i18n.edit_languages")} (${Gn(p,n)})`,"aria-expanded":w,onClick:()=>k(z=>!z),style:yc,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:ox,children:N.paramKey&&N.customKey?i.jsx(F_,{customKey:N.customKey,value:typeof e=="string"?e:"",onChange:t,t:n,candidates:a,testidPrefix:r,showExprButton:l&&d,onToExpression:()=>{$(!0),t($o(typeof e=="string"?e:""))},langToggle:O}):i.jsxs(i.Fragment,{children:[i.jsx("input",{type:"text","data-testid":`${r}-preview`,value:D,placeholder:o??n("layout_editor.prop_i18n.placeholder"),onChange:z=>v(z.target.value),onBlur:()=>{B(),T&&E(!1)},disabled:y,style:rx}),a&&a.length>0&&i.jsx(K_,{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($o(typeof e=="string"?e:""))},title:n("layout_editor.value_tree.to_expression"),"aria-label":n("layout_editor.value_tree.to_expression"),style:Ao,children:"ƒx"}),O]})}),w&&(N.customKey?i.jsx(Xd,{customKey:N.customKey,templateIdentifier:f,t:n,paramLabels:ps(e),locales:s,onRemoveParam:M},N.customKey):i.jsx("div",{"data-testid":`${r}-expand-hint`,style:ux,children:n("layout_editor.prop_i18n.create_first")}))]})}function F_({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=Ft(),[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),S=ps(t),C=u.useCallback(async()=>{const D=It(e,f);if(D!==void 0){h.current=D,m(D);return}const M=(await cn(p,e))?.values?.[f]??"";h.current=M,m(M)},[e,p,f]);u.useEffect(()=>{let D=!1;return(async()=>{const B=It(e,f);if(B!==void 0){D||(h.current=B,m(B));return}const M=await cn(p,e);if(D)return;const O=M?.values?.[f]??"";h.current=O,m(O)})(),()=>{D=!0}},[e,p,f]),u.useEffect(()=>{if(typeof window>"u")return;const D=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,D),()=>window.removeEventListener(kt,D)},[e,p,f,g]);const T=u.useCallback(D=>{m(D),So(p,e,f,D).then(()=>{b?.markDirty?.()})},[p,e,f,b]),E=u.useCallback(D=>{n(vo(t,D)),$r(p,e,D,f).then(()=>{C(),b?.markDirty?.()})},[t,n,p,e,f,C,b]),A=u.useCallback(async D=>{if(!(w===null||x)){$(!0);try{g!==null&&g!==h.current&&(await So(p,e,f,g),h.current=g);const B=await Cr(p,f,t,w,D.sourceId,D.path,"scalar");B.kind==="ok"&&(n(B.text),await C(),b?.markDirty?.())}finally{$(!1),k(null)}}},[w,x,g,t,p,e,f,n,C,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(xr,{value:g,onChange:T,t:o,paramLabels:S,testIdSuffix:`${s}-field`,onRequestInsert:N?D=>k(D):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:Ao,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:Ao,children:"ƒx"}),d,N&&i.jsx(Xn,{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:D=>void A(D),testIdSuffix:`${s}-field-insert`,defaultOpen:!0,floating:!1})})})]})}function K_({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=Ft(),[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 Cr(l,c,e,Number.MAX_SAFE_INTEGER,w.sourceId,w.path,"scalar");k.kind==="ok"&&(n(k.text),p?.markDirty?.())}else{const k=await us(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:Ao,children:"+"}),i.jsx(Xn,{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 V_({value:e,t,translate:n,onEdit:o,testidPrefix:r}){const s=gs(e,a=>{const l=n(a);return l&&l!==a&&!l.startsWith("$t:")?l:""},a=>Vt(a));return i.jsxs("div",{"data-testid":r,style:Y_,children:[i.jsx("div",{"data-testid":`${r}-text`,style:X_,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:fc,children:["🔗 ",a.text]},l):i.jsx("span",{style:a.kind==="ellipsis"?gc:void 0,children:a.text},l))}),i.jsxs("button",{type:"button","data-testid":`${r}-edit`,onClick:o,style:J_,title:t("layout_editor.value_tree.edit"),"aria-label":t("layout_editor.value_tree.edit"),children:["✎ ",t("layout_editor.value_tree.edit")]})]})}function U_({value:e,onChange:t,t:n,candidates:o,testidPrefix:r}){const[s,a]=u.useState(!1),l=u.useRef(null),d=Vt(e);return i.jsxs("div",{"data-testid":r,style:{display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0},children:[i.jsxs("div",{style:q_,children:[i.jsxs("span",{"data-testid":`${r}-chip`,style:G_,children:["🔗 ",d]}),i.jsx("button",{ref:l,type:"button","data-testid":`${r}-change`,onClick:()=>a(c=>!c),style:Ao,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(Xn,{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 q_={display:"flex",alignItems:"center",gap:6,width:"100%",minWidth:0,flexWrap:"wrap"},G_={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"3px 8px",borderRadius:12,wordBreak:"break-all"},Y_={display:"flex",alignItems:"center",gap:8,width:"100%",minWidth:0},X_={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"},fc={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"1px 6px",borderRadius:10,whiteSpace:"nowrap"},gc={color:"#94a3b8"},J_={padding:"4px 10px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",whiteSpace:"nowrap",flexShrink:0},hc={padding:"3px 10px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},Z_={padding:"3px 10px",fontSize:11,border:"1px solid #fca5a5",borderRadius:6,background:"#fef2f2",color:"#b91c1c",cursor:"pointer",whiteSpace:"nowrap"},Q_={display:"flex",flexDirection:"column",gap:6,padding:10,border:"1px solid #fca5a5",borderRadius:8,background:"#fffbeb"},R_={margin:0,fontSize:12,color:"#334155"},ex={padding:"5px 8px",fontSize:12,color:"#0f172a",background:"#fff",border:"1px solid #e2e8f0",borderRadius:6,wordBreak:"break-all"},tx={margin:0,fontSize:11,color:"#b45309"},nx={padding:"3px 12px",fontSize:11,border:"1px solid #dc2626",borderRadius:6,background:"#dc2626",color:"#fff",cursor:"pointer",whiteSpace:"nowrap"},ox={display:"flex",gap:4,alignItems:"center",width:"100%",minWidth:0},rx={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%"},yc={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},Ao={padding:"4px 8px",fontSize:13,lineHeight:1,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},ix={display:"flex",alignItems:"center",gap:6,width:"100%",minWidth:0,flexWrap:"wrap"},sx={flex:1,minWidth:0,display:"flex",flexWrap:"wrap",alignItems:"center",gap:4,fontSize:12,color:"#334155"},ax={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"2px 8px",borderRadius:12,whiteSpace:"nowrap"},lx={display:"flex",flexDirection:"column",gap:2,width:"100%"},dx={fontSize:11,background:"#f1f5f9",padding:"3px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},cx={fontSize:10,color:"#64748b"},ux={fontSize:11,color:"#94a3b8",padding:"6px 8px",border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc"};function vs({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:px,children:[i.jsxs("div",{style:fx,children:[r.map(g=>i.jsxs("span",{"data-testid":`g7le-tag-chip-${g}`,style:gx,children:[i.jsx("span",{style:hx,children:d(g)}),c(g)&&i.jsx("code",{"data-testid":`g7le-tag-chip-id-${g}`,style:yx,children:g}),i.jsx("button",{type:"button","aria-label":`remove ${g}`,"data-testid":`g7le-tag-remove-${g}`,onClick:()=>p(g),style:bx,children:"✕"})]},g)),i.jsx("button",{type:"button","data-testid":"g7le-tag-add",onClick:()=>l(g=>!g),disabled:b.length===0,style:mx,children:o("layout_editor.control.tag_add")})]}),a&&b.length>0&&i.jsx("div",{"data-testid":"g7le-tag-candidates",style:vx,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:_x,children:[i.jsx("span",{style:xx,children:g.label}),m&&i.jsx("code",{"data-testid":`g7le-tag-candidate-id-${g.value}`,style:wx,children:g.value})]},g.value)})})]})}const px={display:"flex",flexDirection:"column",gap:6},fx={display:"flex",flexWrap:"wrap",gap:4,alignItems:"center"},gx={display:"inline-flex",alignItems:"center",gap:4,padding:"2px 6px",fontSize:12,background:"#e0e7ff",color:"#1d4ed8",borderRadius:12},hx={fontSize:12},yx={fontSize:10,color:"#4f46e5",background:"#c7d2fe",borderRadius:4,padding:"0 4px",fontFamily:"monospace"},bx={border:"none",background:"transparent",color:"#1d4ed8",cursor:"pointer",fontSize:10,padding:0,lineHeight:1},mx={padding:"2px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:12,background:"#fff",cursor:"pointer",color:"#475569"},vx={display:"flex",flexDirection:"column",maxHeight:180,overflowY:"auto",border:"1px solid #cbd5e1",borderRadius:6,background:"#fff"},_x={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"},xx={fontSize:12,color:"#0f172a"},wx={fontSize:10,color:"#64748b",fontFamily:"monospace"},bc=new Map;function Ze(e,t){bc.set(e,t)}function Tn(e){return e?bc.get(e)??null:null}function Nr(e,t){const o=e("meta",{})?.[t];return typeof o=="string"?o:""}function kx({getValue:e,patch:t,t:n,fieldT:o,spec:r,permissionCandidates:s,bindingCandidates:a}){const l=o??n,d=Nr(e,"title"),c=Nr(e,"description"),p=Nr(e,"icon"),f=Nr(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=Tn("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:Cx,children:[i.jsx(To,{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(To,{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(To,{label:n("layout_editor.page_settings.meta.icon"),children:h?i.jsx(Sx,{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:Ax})}),i.jsx(To,{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(To,{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(vs,{control:{widget:"tag-input"},value:b,onChange:m,t:n,candidates:s})})})]})}function To({label:e,hint:t,children:n}){return i.jsxs("div",{className:"g7le-meta-field",style:$x,children:[i.jsx("label",{style:Ex,children:e}),n,t?i.jsxs("p",{style:Ix,children:["ⓘ ",t]}):null]})}function Sx({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 Cx={display:"flex",flexDirection:"column",gap:16,minWidth:0},$x={display:"flex",flexDirection:"column",gap:6,minWidth:0},Ex={fontSize:13,fontWeight:600,color:"#0f172a"},Ix={margin:0,fontSize:11,color:"#94a3b8"},Ax={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%"};function Mr({checked:e,onChange:t,label:n,testid:o,ariaLabel:r,disabled:s=!1}){return i.jsxs("label",{style:{...Mx,...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:Lx(e,s),children:i.jsx("span",{style:Px(e)})}),n!=null?i.jsx("span",{style:Ox(s),children:n}):null]})}function Lr({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 Tx({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:Dx,children:[s,l?i.jsxs("button",{type:"button","data-testid":a?`${a}-revert`:void 0,onClick:n,title:r??o,"aria-label":o,style:Nx,children:["↩ ",o]}):d?i.jsx("span",{"data-testid":a?`${a}-source`:void 0,title:r,style:zx,children:t}):null]})}const Dx={position:"relative",minWidth:0,width:"100%"},zx={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"},Nx={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"},Mx={display:"inline-flex",alignItems:"center",gap:8,cursor:"pointer"},Lx=(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"}),Px=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"}),Ox=e=>({fontSize:13,fontWeight:600,color:e?"#94a3b8":"#0f172a"}),Bx=/\$(?:core|module|plugin)_settings:[a-zA-Z0-9._:-]+/;function Wx(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 jx(e))s.kind==="text"?o(s.raw):r(s.raw,s.label,s.removable);return n||o(""),t}function jx(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;){if(e[o]==="{"&&e[o+1]==="{"){let a=o+2;for(;a<n&&!(e[a]==="}"&&e[a+1]==="}");)a++;if(a>=n){o++;continue}s(o);const l=e.slice(o,a+2);t.push({kind:"chip",raw:l,label:Vt(l),removable:!0}),o=a+2,r=o;continue}if(e[o]==="$"){const a=Bx.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 Hx(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 Fx(e,t,n){const o=Math.max(0,Math.min(t,e.length));return e.slice(0,o)+n+e.slice(o)}function Kx(e,t){const n=e.indexOf(t);return n<0?e:e.slice(0,n)+e.slice(n+t.length)}function _s({value:e,onChange:t,t:n,candidates:o,onDone:r,testidPrefix:s="g7le-binding-chip-text",disabled:a=!1}){const l=u.useMemo(()=>Wx(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([]),S=u.useRef(!1);u.useLayoutEffect(()=>{const P=S.current;S.current=!1,!(!P&&x.current===k)&&(x.current=k,l.forEach((I,L)=>{if(I.kind!=="text")return;const F=$.current[L];F&&F.textContent!==(I.text??"")&&(F.textContent=I.text??"")}))},[k,l,e]);const C=u.useCallback(()=>{const P=d.current;if(!P)return e;const I=[];for(const L of Array.from(P.querySelectorAll("[data-seg]")))L.dataset.seg==="chip"?I.push(L.dataset.raw??""):I.push(L.textContent??"");return I.join("")},[e]),T=u.useCallback(()=>{a||t(C())},[a,t,C]),E=u.useRef(null),A=u.useRef(!1),N=(P,I)=>{if(!a){P.preventDefault(),P.stopPropagation(),E.current={raw:I,pointerId:P.pointerId},A.current=!1,f(I);try{P.currentTarget.setPointerCapture(P.pointerId)}catch{}}},D=P=>{const I=E.current;if(!I||P.pointerId!==I.pointerId)return;A.current=!0;const L=O(P.clientX,P.clientY);L&&(g({slotIdx:L.slotIdx,offset:L.offset}),h(Ux(d.current,L.slotIdx,L.offset)))},B=(P,I)=>{if(P.stopPropagation(),A.current){A.current=!1;return}S.current=!0,t(Kx(e,I))},M=P=>{const I=E.current;if(!I||P.pointerId!==I.pointerId)return;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}E.current=null,A.current&&typeof setTimeout=="function"&&setTimeout(()=>{A.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 K=Array.from(F.querySelectorAll("[data-seg]")).map(Z=>Z.dataset.seg==="chip"?{kind:"chip",raw:Z.dataset.raw??""}:{kind:"text",text:Z.textContent??""}),X=Hx(K,I.raw,L.slotIdx,L.offset);X!==e&&(S.current=!0,t(X))},O=(P,I)=>{const L=d.current;if(!L)return null;const F=Array.from(L.querySelectorAll("[data-seg]")),Y=L.ownerDocument,K=Y.elementFromPoint(P,I),X=K?.closest('[data-seg="text"]');if(X)return{slotIdx:F.indexOf(X),offset:Vx(Y,X,P,I)};const Z=K?.closest('[data-seg="chip"]');if(Z){const oe=F.indexOf(Z),G=Z.getBoundingClientRect();if(P<G.left+G.width/2&&oe-1>=0){const ee=F[oe-1];return{slotIdx:oe-1,offset:(ee.textContent??"").length}}if(oe+1<F.length)return{slotIdx:oe+1,offset:0}}const ae=F.map((oe,G)=>({s:oe,i:G})).filter(oe=>oe.s.dataset.seg==="text").pop();return ae?{slotIdx:ae.i,offset:(ae.s.textContent??"").length}:null},z=()=>{a||!c||(_.current=qx(d.current,e.length),y(P=>!P))},H=P=>{const I=P.path?P.path.split(".").filter(Boolean):[],L=[P.sourceId,...I].join("?.");S.current=!0,t(Fx(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:Gx,children:[l.map((P,I)=>P.kind==="chip"?i.jsxs("span",{"data-seg":"chip","data-raw":P.raw,"data-testid":`${s}-chip-${I}`,contentEditable:!1,onPointerDown:L=>N(L,P.raw??""),onPointerMove:D,onPointerUp:M,title:P.removable?n("layout_editor.value_tree.change_data"):n("layout_editor.prop_i18n.bound_code_only"),style:{...Zx,...p===P.raw?Qx:null,touchAction:"none"},children:[i.jsx("span",{"aria-hidden":"true",style:Rx,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-${I}`,"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:ew,children:"✕"})]},`chip-${P.raw}-${I}`):i.jsx("span",{ref:L=>{$.current[I]=L},"data-seg":"text",contentEditable:!a,suppressContentEditableWarning:!0,onInput:T,"data-testid":`${s}-text-${I}`,style:{...Yx,...p?Xx:null,...b?.slotIdx===I?Jx:null}},`text-slot-${I}`)),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:mc,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:mc,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(Xn,{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:tw,children:n("layout_editor.translation.placeholder_locked")})]})]})}function Vx(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 Ux(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 qx(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 Gx={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"},Yx={outline:"none",minWidth:8,minHeight:"1.2em",whiteSpace:"pre-wrap",color:"#0f172a",display:"inline-block",wordBreak:"break-all"},Xx={boxShadow:"inset 0 -2px 0 #93c5fd",background:"#eff6ff",borderRadius:2},Jx={background:"#dbeafe",boxShadow:"inset 0 -2px 0 #2563eb"},Zx={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"},Qx={opacity:.5,borderStyle:"solid",cursor:"grabbing"},Rx={color:"#2563eb",opacity:.7,fontSize:11,marginRight:1,cursor:"grab"},ew={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"},mc={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},tw={fontSize:10,color:"#94a3b8"},nw=Jl;function xs(e){return Eb(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(S=>i.jsx(Ke,{value:S.value,onChange:C=>S.onChange(C),t:S.t,candidates:S.candidates,testidPrefix:S.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:S=>t(S.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(S=>{const C=d?`${d} ${S.expression}`:S.expression;t(C)},[d,t]);if(!l||a)return i.jsxs("div",{"data-testid":s,style:pn,children:[y(),!a&&c&&i.jsx($t,{candidates:o,t:n,onSelect:_,testIdSuffix:`${s}-pick`})]});const w=Wv(d),k=Zd(d),x=Kt(d),$=S=>{const C=Er(d),T=C?gs(C,()=>"",E=>Vt(E)):[];return i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{display:"flex",justifyContent:"flex-start"},children:i.jsxs("button",{type:"button","data-testid":`${S}-to-plain`,onClick:()=>h(!0),style:sw,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":`${S}-to-plain-confirm`,style:aw,children:[i.jsx("p",{style:lw,children:n("layout_editor.value_tree.to_plain_lead")}),i.jsx("div",{style:dw,children:T.length===0?i.jsx("span",{style:{color:"#94a3b8"},children:n("layout_editor.page_settings.seo.value_placeholder")}):T.map((E,A)=>E.kind==="chip"?i.jsxs("span",{style:ws,children:["🔗 ",E.text]},A):i.jsx("span",{style:E.kind==="ellipsis"?{color:"#94a3b8"}:void 0,children:E.text},A))}),i.jsxs("p",{style:cw,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":`${S}-to-plain-confirm-cancel`,onClick:()=>h(!1),style:Ut,children:n("layout_editor.value_tree.to_plain_cancel")}),i.jsx("button",{type:"button","data-testid":`${S}-to-plain-confirm-ok`,onClick:()=>{h(!1),t(Er(d)||"")},style:uw,children:n("layout_editor.value_tree.to_plain_ok")})]})]})]})};if(!p&&(w==="expression"||k)){if(k)return i.jsxs("div",{"data-testid":s,style:pn,children:[!a&&$(`${s}-seg`),i.jsx(bs,{value:d,onChange:C=>t(C),t:n,candidates:o,testidPrefix:`${s}-seg`,renderLeafInput:v})]});const S=un(d);return i.jsxs("div",{"data-testid":s,style:pn,children:[!a&&$(`${s}-tree`),i.jsx(sc,{node:S.node,onChange:C=>t(Zn(C,!1)),t:n,candidates:o,testidPrefix:`${s}-tree`,renderLeafInput:v})]})}if(x&&!p&&!b)return i.jsx(ow,{value:d,onChange:t,t:n,candidates:o,testidPrefix:s,onEditRaw:()=>g(!0)});if(!p&&!b&&xs(d)){const S=nw(d);return i.jsx("div",{"data-testid":s,style:pn,children:i.jsxs("div",{style:vc,children:[i.jsx("div",{"data-testid":`${s}-chips`,style:rw,children:S.map((C,T)=>C.kind==="chip"?i.jsxs("span",{style:ws,children:["🔗 ",C.label]},T):i.jsx("span",{children:C.label},T))}),i.jsxs("button",{type:"button","data-testid":`${s}-edit-raw`,onClick:()=>g(!0),style:Ut,title:n("layout_editor.value_tree.edit"),"aria-label":n("layout_editor.value_tree.edit"),children:["✎ ",n("layout_editor.value_tree.edit")]})]})})}return b&&xs(d)?i.jsxs("div",{"data-testid":s,style:pn,children:[i.jsx(_s,{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($o(d)),style:Ut,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(hs(d)),style:Ut,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:ks,children:["ⓘ ",n("layout_editor.value_tree.raw_expression_hint")]})]}):!p&&xs(d)?i.jsxs("div",{"data-testid":s,style:pn,children:[i.jsx(_s,{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($o(d)),style:Ut,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(hs(d)),style:Ut,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:ks,children:["ⓘ ",n("layout_editor.value_tree.raw_expression_hint")]})]}):i.jsxs("div",{"data-testid":s,style:pn,children:[y(),i.jsxs("div",{style:iw,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($o(d)),style:Ut,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(hs(d)),style:Ut,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:ks,children:["ⓘ ",n("layout_editor.value_tree.raw_expression_hint")]})]})}function ow({value:e,onChange:t,t:n,candidates:o,testidPrefix:r,onEditRaw:s}){const[a,l]=u.useState(!1),d=u.useRef(null),c=Vt(e),p=!!o&&o.length>0,f=Kt(e)?.localeFn;return i.jsxs("div",{"data-testid":r,style:pn,children:[i.jsxs("div",{style:vc,children:[i.jsxs("span",{"data-testid":`${r}-chip`,style:ws,children:["🔗 ",c]}),p&&i.jsx("button",{ref:d,type:"button","data-testid":`${r}-change`,onClick:()=>l(b=>!b),style:Ut,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:Ut,title:n("layout_editor.value_tree.edit"),"aria-label":n("layout_editor.value_tree.edit"),children:"✎"})]}),p&&i.jsx(Xn,{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 pn={display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0},vc={display:"flex",alignItems:"center",gap:6,width:"100%",minWidth:0,flexWrap:"wrap"},rw={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"},ws={fontSize:11,background:"#eef2ff",color:"#4338ca",padding:"2px 8px",borderRadius:12,whiteSpace:"nowrap"},Ut={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},iw={display:"flex",flexWrap:"wrap",alignItems:"center",gap:6},ks={margin:"2px 0 0",fontSize:11,color:"#94a3b8",lineHeight:1.4},sw={padding:"3px 10px",fontSize:11,border:"1px solid #fca5a5",borderRadius:6,background:"#fef2f2",color:"#b91c1c",cursor:"pointer",whiteSpace:"nowrap"},aw={display:"flex",flexDirection:"column",gap:6,padding:10,border:"1px solid #fca5a5",borderRadius:8,background:"#fffbeb"},lw={margin:0,fontSize:12,color:"#334155"},dw={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"},cw={margin:0,fontSize:11,color:"#b45309"},uw={padding:"3px 12px",fontSize:11,border:"1px solid #dc2626",borderRadius:6,background:"#dc2626",color:"#fff",cursor:"pointer",whiteSpace:"nowrap"};let _c=0;function Pr({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:_c++,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:_c++,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 pw=["website","article","product","profile"],fw=["summary","summary_large_image","app","player"];function gw(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 xc(e){const t={};for(const n of e??[])t[n.key]=n;return t}function wc(e,t){return!!e&&t&&typeof e.sourceExpr=="string"&&e.sourceExpr!==""&&!e.overriddenByLayout&&!e.lockedByFilter}function kc({label:e,sourceExpr:t,onReplace:n,t:o,testid:r}){return i.jsxs("div",{"data-testid":r,style:Sw,children:[i.jsxs("span",{"data-testid":`${r}-chip`,style:Cw,title:t,children:["🔗 ",e||t]}),i.jsx("span",{"data-testid":`${r}-badge`,style:$w,children:o("layout_editor.page_settings.seo.auto_chip_source")}),i.jsx("button",{type:"button","data-testid":`${r}-replace`,onClick:n,style:Ew,children:o("layout_editor.page_settings.seo.auto_chip_replace")})]})}function hw({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=xc(r),h=xc(s),v=u.useCallback((T,E)=>{const A={...p};E===void 0||E===""||E===null?delete A[T]:A[T]=E,n(A)},[p,n]),y=u.useCallback((T,E)=>{const A={...f};E===void 0||E===""||E===null?delete A[T]:A[T]=E,o(A)},[f,o]),_=(T,E,A)=>!A||!a||!A.lockedByFilter?null:i.jsx("div",{style:{display:"flex",gap:6,alignItems:"center",marginTop:2},children:i.jsxs("span",{"data-testid":`${T}-locked-${E}`,style:xw,children:["🔒 ",d("layout_editor.page_settings.seo.og_locked")]})}),w=T=>{if(!T||!a||T.lockedByFilter||T.overriddenByLayout)return;const E=gw(T.source);return E?d(E):void 0},k=(T,E)=>T&&a?T.overriddenByLayout===!0:E!=="",x=(T,E,A,N,D,B)=>{const M=B[E],O=!!M?.lockedByFilter,z=typeof N[E]=="string"?N[E]:"";return i.jsxs("div",{"data-testid":`${T}-${E}`,style:Dn,children:[i.jsx("label",{style:to,children:d(A)}),O?i.jsx("div",{"data-testid":`${T}-locked-value-${E}`,style:_w,children:String(M?.effectiveValue??"")}):wc(M,a)?i.jsx(kc,{label:M.label??"",sourceExpr:M.sourceExpr,onReplace:()=>D(E,M.sourceExpr),t:d,testid:`${T}-${E}-auto`}):i.jsx(_t,{value:z,onChange:H=>D(E,H??""),t:d,candidates:l,placeholder:a&&M?.effectiveValue!=null?String(M.effectiveValue):void 0,testidPrefix:`${T}-${E}-field`,enableExpressionTree:!0,expressionTreeCollapsible:!0}),_(T,E,M)]})},$=(T,E,A,N,D,B)=>{const M=B[E],O=!!M?.lockedByFilter,z=typeof N[E]=="string"?N[E]:"";return i.jsxs("div",{"data-testid":`${T}-${E}`,style:Dn,children:[i.jsx("label",{style:to,children:d(A)}),wc(M,a)?i.jsx(kc,{label:M.label??"",sourceExpr:M.sourceExpr,onReplace:()=>D(E,M.sourceExpr),t:d,testid:`${T}-${E}-auto`}):i.jsx(Ke,{value:z,onChange:H=>D(E,H),t:d,candidates:l,readOnly:O,placeholder:a&&M?.effectiveValue!=null?String(M.effectiveValue):void 0,testidPrefix:`${T}-${E}-field`}),_(T,E,M)]})},S=(T,E,A,N,D,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":`${T}-${E}`,style:Dn,children:[i.jsx("label",{style:to,children:d(A)}),i.jsx(Tx,{filled:H,sourceLabel:w(M),onRevert:O?void 0:()=>D(E,void 0),revertLabel:d("layout_editor.page_settings.seo.revert_default"),testid:`${T}-${E}-overlay`,children:i.jsx("div",{"data-testid":`${T}-${E}-input`,style:{minWidth:0},children:i.jsx(Ke,{value:P,onChange:I=>D(E,I),t:d,candidates:l,readOnly:O,placeholder:a&&M?.effectiveValue!=null?String(M.effectiveValue):void 0,testidPrefix:`${T}-${E}-chip`})})}),_(T,E,M)]})},C=(T,E,A,N,D,B,M)=>{const O=M[E],z=typeof D[E]=="string"?D[E]:"",H=k(O,z),P=w(O),I=H?z:"";return i.jsxs("div",{"data-testid":`${T}-${E}`,style:Dn,children:[i.jsxs("div",{style:bw,children:[i.jsx("label",{style:to,children:d(A)}),P?i.jsxs("span",{"data-testid":`${T}-${E}-source-inline`,style:mw,children:["· ",P]}):null]}),i.jsxs("select",{"data-testid":`${T}-${E}-select`,value:I,onChange:L=>B(E,L.target.value),style:vw,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))]}),_(T,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:Sc,children:[i.jsx("div",{style:Cc,children:d("layout_editor.page_settings.seo.og_section")}),i.jsxs("p",{"data-testid":`${c}-intro`,style:yw,children:["ⓘ ",d("layout_editor.page_settings.seo.og_intro")]}),C(c,"type","layout_editor.page_settings.seo.og_type",pw,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:Dn,children:[i.jsxs("button",{type:"button","data-testid":`${c}-image-adv-toggle`,"aria-expanded":b,onClick:()=>g(T=>!T),style:ww,children:[b?"▾":"▸"," ",d("layout_editor.page_settings.seo.og_image_adv")]}),b?i.jsxs("div",{"data-testid":`${c}-image-adv`,style:kw,children:[S(c,"image_height","layout_editor.page_settings.seo.og_image_height",p,v,m),S(c,"image_type","layout_editor.page_settings.seo.og_image_type",p,v,m),S(c,"image_secure_url","layout_editor.page_settings.seo.og_image_secure_url",p,v,m)]}):null]}),S(c,"site_name","layout_editor.page_settings.seo.og_site_name",p,v,m),S(c,"locale","layout_editor.page_settings.seo.og_locale",p,v,m),i.jsxs("div",{"data-testid":`${c}-extra`,style:Dn,children:[i.jsx("label",{style:to,children:d("layout_editor.page_settings.seo.og_extra")}),i.jsx(Pr,{value:Array.isArray(p.extra)?p.extra:[],onChange:T=>v("extra",T.length>0?T:void 0),keyField:"property",t:d,candidates:l,testidPrefix:`${c}-extra-editor`})]})]}),i.jsxs("div",{"data-testid":`${c}-tw-section`,style:Sc,children:[i.jsx("div",{style:Cc,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")}),C("g7le-seo-tw","card","layout_editor.page_settings.seo.tw_card",fw,f,y,h),S("g7le-seo-tw","site","layout_editor.page_settings.seo.tw_site",f,y,h),S("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:Dn,children:[i.jsx("label",{style:to,children:d("layout_editor.page_settings.seo.tw_extra")}),i.jsx(Pr,{value:Array.isArray(f.extra)?f.extra:[],onChange:T=>y("extra",T.length>0?T:void 0),keyField:"name",t:d,candidates:l,testidPrefix:"g7le-seo-tw-extra-editor"})]})]})]})}const Sc={border:"1px solid #e2e8f0",borderRadius:8,padding:12,display:"flex",flexDirection:"column",gap:10},Cc={fontSize:13,fontWeight:600,color:"#0f172a"},yw={margin:0,fontSize:11,color:"#64748b",background:"#f8fafc",borderRadius:6,padding:"6px 8px"},Dn={display:"flex",flexDirection:"column",gap:4},to={fontSize:12,color:"#475569"},bw={display:"flex",alignItems:"center",gap:6},mw={fontSize:11,color:"#94a3b8"},vw={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",minWidth:0,boxSizing:"border-box"},_w={padding:"5px 8px",fontSize:12,border:"1px solid #e2e8f0",borderRadius:6,background:"#f1f5f9",color:"#64748b"},xw={fontSize:11,color:"#7c3aed"},ww={alignSelf:"flex-start",padding:"2px 0",fontSize:12,fontWeight:600,color:"#475569",background:"transparent",border:"none",cursor:"pointer"},kw={display:"flex",flexDirection:"column",gap:8,paddingLeft:14,marginTop:4,minWidth:0},Sw={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",minWidth:0},Cw={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"},$w={fontSize:11,color:"#94a3b8"},Ew={padding:"2px 8px",fontSize:11,color:"#475569",background:"#fff",border:"1px solid #cbd5e1",borderRadius:6,cursor:"pointer"},Iw=["WebPage","WebSite","ItemList","BreadcrumbList","Organization","Person","CollectionPage","AboutPage","ContactPage","SearchAction"];function Or(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 $c(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;l<s.length-1;l++){const d=s[l];(typeof a[d]!="object"||a[d]===null||Array.isArray(a[d]))&&(a[d]={}),a=a[d]}a[s[s.length-1]]=r}return n}let Ss=0;function Aw({value:e,onChange:t,autoBlock:n,autoMeta:o,lockedByFilter:r=!1,filteredBlock:s,pageType:a,candidates:l,t:d,testidPrefix:c="g7le-seo-sd"}){const p=!!e&&typeof e=="object",[f,b]=u.useState(p),g=p&&typeof e["@type"]=="string"?e["@type"]:"WebPage",[m,h]=u.useState(g),[v,y]=u.useState(()=>p?Or(e).map(D=>({id:Ss++,...D})):[]),_=u.useCallback((D,B)=>{h(D),y(B),t($c(D,B.map(M=>({key:M.key,value:M.value}))))},[t]),w=u.useCallback(()=>{const D=n,B=typeof D["@type"]=="string"?D["@type"]:m,M=Or(D).map(O=>({id:Ss++,key:O.key,value:o?.[O.key]?.expr??O.value}));return{type:B,rows:M}},[n,o,m]),k=u.useCallback(D=>{if(b(D),D){if(v.length===0&&n&&typeof n=="object"){const B=w();_(B.type,B.rows);return}t($c(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 D=w();_(D.type,D.rows)},[n,w,_]),$=u.useCallback(()=>{_(m,[...v,{id:Ss++,key:"",value:""}])},[m,v,_]),S=u.useCallback(D=>{_(m,v.filter(B=>B.id!==D))},[m,v,_]),C=u.useCallback((D,B)=>{_(m,v.map(M=>M.id===D?{...M,key:B}:M))},[m,v,_]),T=u.useCallback((D,B)=>{_(m,v.map(M=>M.id===D?{...M,value:B}:M))},[m,v,_]),E=u.useMemo(()=>n?Or(n):[],[n]),A=u.useMemo(()=>s?Or(s):[],[s]),N=v.some(D=>D.key.trim()!==""&&D.value.trim()==="");if(r){const D=s&&typeof s["@type"]=="string"?s["@type"]:"";return i.jsxs("div",{"data-testid":c,style:Ec,children:[i.jsxs("div",{style:Ic,children:[i.jsx("span",{style:Tw,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:Dw,children:d("layout_editor.page_settings.seo.sd_filter_locked")})]}),i.jsxs("div",{"data-testid":`${c}-locked`,style:zw,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:[D?i.jsxs("div",{style:{fontSize:12,fontWeight:600,marginBottom:4},children:["@type: ",D]}):null,A.map(B=>i.jsxs("div",{"data-testid":`${c}-filtered-row-${B.key}`,style:Ac,children:[i.jsx("code",{style:Tc,children:B.key}),i.jsx("span",{style:Dc,children:B.value})]},B.key))]})]})]})}return i.jsxs("div",{"data-testid":c,style:Ec,children:[i.jsx("div",{style:Ic,children:i.jsx(Mr,{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:Nw,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(D=>{const B=o?.[D.key];return i.jsxs("div",{"data-testid":`${c}-auto-row-${D.key}`,style:Ac,children:[i.jsx("code",{style:Tc,children:D.key}),B?i.jsxs("span",{"data-testid":`${c}-auto-chip-${D.key}`,style:Mw,title:B.expr,children:["🔗 ",B.label||B.expr]}):i.jsx("span",{style:Dc,children:D.value})]},D.key)})]}),i.jsxs("p",{"data-testid":`${c}-replace-warn`,style:Lw,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:Pw,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:D=>_(D.target.value,v),style:Ow}),i.jsx("datalist",{id:`${c}-type-options`,children:Iw.map(D=>i.jsx("option",{value:D},D))})]}),i.jsx("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:6},children:v.map(D=>i.jsxs("div",{"data-testid":`${c}-prop-${D.id}`,style:Bw,children:[i.jsx("input",{type:"text","data-testid":`${c}-prop-key-${D.id}`,value:D.key,placeholder:d("layout_editor.page_settings.seo.sd_prop_key"),onChange:B=>C(D.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:D.value,onChange:B=>T(D.id,B),t:d,candidates:l,placeholder:d("layout_editor.page_settings.seo.sd_prop_value"),testidPrefix:`${c}-prop-value-${D.id}`})}),i.jsx("button",{type:"button","data-testid":`${c}-prop-remove-${D.id}`,onClick:()=>S(D.id),title:d("layout_editor.page_settings.seo.remove"),"aria-label":d("layout_editor.page_settings.seo.remove"),style:Ww,children:"✕"})]},D.id))}),i.jsxs("div",{style:{marginTop:8,display:"flex",gap:8},children:[i.jsxs("button",{type:"button","data-testid":`${c}-add`,onClick:$,style:zc,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:zc,children:["↩ ",d("layout_editor.page_settings.seo.sd_seed_from_module")]}):null]}),i.jsxs("p",{"data-testid":`${c}-empty-note`,style:jw,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 Ec={display:"flex",flexDirection:"column"},Ic={display:"flex",alignItems:"center",gap:8},Tw={fontSize:14},Dw={fontSize:11,padding:"2px 6px",borderRadius:4,background:"#f1f5f9",color:"#64748b"},zw={marginTop:8,border:"1px solid #fcd34d",borderRadius:8,padding:10,background:"#fffbeb"},Nw={border:"1px solid #e2e8f0",borderRadius:8,padding:10,background:"#f8fafc"},Ac={display:"flex",gap:8,alignItems:"center",padding:"2px 0"},Tc={fontSize:11,color:"#475569",background:"#fff",padding:"2px 6px",borderRadius:4,minWidth:120},Dc={fontSize:11,color:"#0f172a",fontFamily:"monospace",wordBreak:"break-all"},Mw={display:"inline-flex",alignItems:"center",padding:"2px 8px",fontSize:11,color:"#1d4ed8",background:"#eff6ff",border:"1px solid #bfdbfe",borderRadius:6},Lw={margin:"6px 0 0",fontSize:12,color:"#64748b"},Pw={margin:"0 0 8px",fontSize:12,color:"#b45309",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,padding:"6px 8px"},Ow={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",minWidth:0},Bw={display:"flex",gap:6,alignItems:"flex-start",border:"1px solid #e2e8f0",borderRadius:8,padding:8},Ww={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},zc={padding:"5px 10px",fontSize:12,border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},jw={margin:"8px 0 0",fontSize:11,color:"#94a3b8"},Nc=new Set(["core_setting","setting","query","route"]);function Hw({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=>Nc.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)Nc.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 S={...l};$===void 0?delete S[x]:S[x]=$,t(S)},[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:Fw,children:["⚠ ",s("layout_editor.page_settings.seo.vars_precondition")]}),c.length>0&&i.jsxs("div",{"data-testid":`${a}-auto-group`,style:Cs,children:[i.jsx("div",{style:$s,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:Kw,children:[i.jsx("span",{style:Vw,children:"🔒"}),i.jsx("code",{style:Es,children:x.name}),i.jsxs("span",{style:Uw,children:["〔",s("layout_editor.page_settings.seo.vars_auto"),"·",x.source,"〕"]}),x.owner?.name?i.jsx("span",{style:qw,children:x.owner.name}):null]},x.name))]}),p.length>0&&i.jsxs("div",{"data-testid":`${a}-data-group`,style:Cs,children:[i.jsx("div",{style:$s,children:s("layout_editor.page_settings.seo.vars_data_group")}),p.map(x=>{const $=l[x.name]??"",S=$.trim()==="";return i.jsxs("div",{"data-testid":`g7le-seo-var-data-${x.name}`,style:Mc,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[i.jsx("code",{style:Es,children:x.name}),x.required?i.jsx("span",{"data-testid":`g7le-seo-var-required-${x.name}`,style:Gw,children:"*"}):null]}),i.jsx(Ke,{value:$,onChange:C=>m(x.name,C??""),t:s,candidates:r,testidPrefix:`g7le-seo-var-data-field-${x.name}`}),x.required&&S?i.jsxs("p",{"data-testid":`g7le-seo-var-empty-warn-${x.name}`,style:Is,children:["⚠ ",s("layout_editor.page_settings.seo.vars_required_empty")]}):null]},x.name)})]}),i.jsxs("div",{"data-testid":`${a}-custom-group`,style:Cs,children:[i.jsx("div",{style:$s,children:s("layout_editor.page_settings.seo.vars_custom_group")}),g.map(x=>i.jsxs("div",{"data-testid":`g7le-seo-var-custom-${x}`,style:Mc,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[i.jsx("code",{style:Es,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:Yw,children:["+ ",s("layout_editor.page_settings.seo.vars_add")]})]}),y?i.jsxs("p",{"data-testid":"g7le-seo-var-add-reserved-warn",style:Is,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:Is,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 Fw={fontSize:12,color:"#b45309",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,padding:"6px 8px"},Cs={border:"1px solid #e2e8f0",borderRadius:8,padding:10,display:"flex",flexDirection:"column",gap:6},$s={fontSize:12,fontWeight:600,color:"#475569"},Kw={display:"flex",alignItems:"center",gap:6,padding:"2px 0"},Mc={display:"flex",flexDirection:"column",border:"1px solid #f1f5f9",borderRadius:6,padding:8},Vw={fontSize:13},Es={fontSize:12,color:"#0f172a",background:"#f1f5f9",padding:"2px 6px",borderRadius:4},Uw={fontSize:11,color:"#64748b"},qw={fontSize:11,color:"#94a3b8"},Gw={color:"#dc2626",fontWeight:700},Is={margin:"4px 0 0",fontSize:11,color:"#b45309"},Yw={padding:"5px 10px",fontSize:12,border:"1px dashed #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"};function Xw({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 T=c??(typeof fetch<"u"?fetch:void 0);if(!T)return;const{templateIdentifier:E,layout:A,url:N,locale:D,seedContext:B,routeParams:M}=k.current;v(!0),_(null);try{const O=`/api/admin/templates/${encodeURIComponent(E)}/editor/seo-bot-preview`,z=await T(O,{method:"POST",credentials:"same-origin",headers:Ne({"Content-Type":"application/json"}),body:JSON.stringify({layout:A,url:N,locale:D,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]),S=g?.html??null,C=g?.enabled??!0;return i.jsxs("div",{"data-testid":p,style:Jw,children:[i.jsxs("div",{style:Zw,children:[i.jsxs("button",{type:"button","data-testid":`${p}-toggle`,onClick:()=>b(T=>!T),"aria-expanded":f,style:Qw,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:Rw,children:["⟳ ",l("layout_editor.page_settings.seo.bot_preview_refresh")]}):null]}),f&&i.jsxs("div",{style:{marginTop:8},children:[g&&!C?i.jsxs("p",{"data-testid":`${p}-disabled`,style:e0,children:["ⓘ ",l("layout_editor.page_settings.seo.bot_preview_disabled")]}):i.jsx("div",{"data-testid":`${p}-body`,style:t0,children:h&&!S?i.jsx("p",{style:As,children:l("layout_editor.translation.loading")}):y?i.jsx("p",{"data-testid":`${p}-error`,style:{...As,color:"#dc2626"},children:y}):S==null?i.jsx("p",{style:As,children:l("layout_editor.page_settings.seo.bot_preview_empty")}):i.jsx("pre",{"data-testid":`${p}-code`,style:n0,children:S})}),i.jsxs("p",{"data-testid":`${p}-sample-note`,style:o0,children:["ⓘ ",l("layout_editor.page_settings.seo.bot_preview_sample_note")]})]})]})}const Jw={borderTop:"1px solid #e2e8f0",paddingTop:10,marginTop:12},Zw={display:"flex",alignItems:"center",gap:8},Qw={background:"none",border:"none",cursor:"pointer",fontSize:13,fontWeight:600,color:"#0f172a",padding:0},Rw={marginLeft:"auto",padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},e0={margin:0,fontSize:12,color:"#64748b",background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,padding:"8px 10px"},t0={border:"1px solid #e2e8f0",borderRadius:8,background:"#0b1020",padding:0,minHeight:80,overflow:"hidden"},n0={margin:0,padding:12,fontSize:11,lineHeight:1.5,color:"#d1fae5",fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto"},As={margin:0,padding:12,fontSize:12,color:"#94a3b8"},o0={margin:"8px 0 0",fontSize:11,color:"#94a3b8"};function Lc({option:e,testIdPrefix:t}){const{id:n,friendly:o,source:r}=e;return i.jsxs("span",{style:r0,children:[i.jsx("span",{"data-testid":t?`${t}-title`:void 0,style:i0,children:o??n}),o?i.jsx("span",{"data-testid":t?`${t}-id`:void 0,style:s0,children:n}):null,r?i.jsx("span",{"data-testid":t?`${t}-source`:void 0,style:a0,children:r}):null]})}const r0={display:"inline-flex",alignItems:"baseline",gap:4,flexWrap:"wrap",minWidth:0},i0={fontSize:12,color:"#0f172a"},s0={fontSize:10,color:"#94a3b8",fontFamily:"ui-monospace, monospace"},a0={fontSize:9,fontWeight:600,color:"#7c3aed",background:"#f5f3ff",border:"1px solid #ddd6fe",borderRadius:4,padding:"0 5px",whiteSpace:"nowrap"},l0=["always","hourly","daily","weekly","monthly","yearly","never"];function d0({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((V,te)=>{const be={...e("meta",{})},Ee={...be.seo??{}};te==null||te===""?delete Ee[V]:Ee[V]=te,be.seo=Ee,t("meta",be)},[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&&_!=="",[$,S]=u.useState(null),[C,T]=u.useState(null),E=u.useCallback(async(V,te)=>{if(p)return p(V,te);if(typeof fetch>"u")return null;const be=new URLSearchParams;V&&be.set("page_type",V),Array.isArray(te)&&te.length>0&&be.set("extensions",JSON.stringify(te.map(Ue=>({type:Ue.type,id:Ue.id}))));const Ee=be.toString()?`?${be.toString()}`:"",De=await fetch(en(`/api/admin/templates/${encodeURIComponent(o)}/editor/seo-candidates`,"json",null,Ee.replace(/^[?&]+/,"")),{credentials:"same-origin",headers:Ne()}),Se=await De.json().catch(()=>null);return De.ok?Se?.data??null:null},[p,o]),A=u.useMemo(()=>{const be=(e("__editor",{})??{}).original?.meta?.seo;return be&&typeof be=="object"?be:void 0},[e]),N=u.useRef(A);N.current=A;const D=u.useCallback(async V=>{if(f)return f(V);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:Ne({"Content-Type":"application/json"}),body:JSON.stringify({seo:V,own_seo:N.current??null,seed_context:c??{},route_params:{}})}),be=await te.json().catch(()=>null);return te.ok?be?.data??null:null},[f,o,c]),B=u.useMemo(()=>JSON.stringify(w),[w]),M=u.useRef(h);M.current=h,u.useEffect(()=>{let V=!1;return(async()=>{const te=await E(_,w);V||S(te)})(),()=>{V=!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 V=!1;const te=()=>{(async()=>{const Ee=await D(M.current);V||T(Ee)})()};if(!z.current)return z.current=!0,te(),()=>{V=!0};const be=setTimeout(te,180);return()=>{V=!0,clearTimeout(be)}},[_,B,O]);const H=$?.page_types??[],P=$?.toggle_settings??[],I=$?.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(V=>{w.some(te=>te.type===V.type&&te.id===V.id)||v("extensions",[...w,{type:V.type,id:V.id}])},[w,v]),K=u.useCallback(V=>{const te=w.filter(be=>!(be.type===V.type&&be.id===V.id));v("extensions",te.length>0?te:void 0)},[w,v]),[X,Z]=u.useState(!1),[ae,oe]=u.useState(""),G=u.useMemo(()=>{const V=ae.trim().toLowerCase();return V?P.filter(te=>`${te.ref} ${te.label??""}`.toLowerCase().includes(V)):P},[P,ae]),ee=typeof h.toggle_setting=="string"?h.toggle_setting:"",ge=u.useCallback(V=>{const be=k.includes(V)?k.filter(Ee=>Ee!==V):[...k,V];v("data_sources",be.length>0?be:void 0)},[k,v]);return i.jsxs("div",{"data-testid":g,style:{display:"flex",flexDirection:"column",gap:14},children:[i.jsxs("div",{style:Bt,children:[i.jsx(Mr,{checked:y,onChange:V=>v("enabled",V),testid:`${g}-enabled`,label:n("layout_editor.page_settings.seo.enabled")}),y?null:i.jsxs("p",{"data-testid":`${g}-disabled-note`,style:no,children:["ⓘ ",n("layout_editor.page_settings.seo.disabled_note")]})]}),i.jsx(Lr,{disabled:!y,testid:`${g}-body`,style:{display:"flex",flexDirection:"column",gap:14},children:i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.page_type")}),H.length>0?i.jsxs("select",{"data-testid":`${g}-page-type`,value:_,onChange:V=>v("page_type",V.target.value),style:Br,children:[i.jsx("option",{value:"",children:n("layout_editor.page_settings.seo.page_type_none")}),H.map(V=>i.jsxs("option",{value:V.value,children:[V.label??V.value,V.owner?.name?` (${V.owner.name})`:""]},V.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:V=>v("page_type",V.target.value),style:Br}),i.jsxs("p",{"data-testid":`${g}-page-type-free-note`,style:no,children:["ⓘ ",n("layout_editor.page_settings.seo.page_type_free_note")]})]})]}),i.jsxs("div",{style:Bt,children:[i.jsxs("label",{style:qt,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(V=>i.jsxs("span",{"data-testid":`${g}-extension-${V.type}-${V.id}`,style:Pc,children:[V.name??`${V.type}:${V.id}`,i.jsx("button",{type:"button","data-testid":`${g}-extension-remove-${V.type}-${V.id}`,onClick:()=>K(V),style:Oc,children:"✕"})]},`${V.type}:${V.id}`)),i.jsxs("button",{type:"button","data-testid":`${g}-extension-add`,onClick:()=>Z(V=>!V),style:p0,children:["+ ",n("layout_editor.page_settings.seo.add_extension")]})]}),X&&i.jsx("div",{"data-testid":`${g}-extension-picker`,style:Bc,children:s.length===0?i.jsx("p",{style:no,children:n("layout_editor.page_settings.seo.no_extension_candidate")}):s.map(V=>i.jsx("button",{type:"button","data-testid":`${g}-extension-option-${V.type}-${V.id}`,onClick:()=>{Y(V),Z(!1)},style:Wc,children:V.name??`${V.type}:${V.id}`},`${V.type}:${V.id}`))})]}),!x&&i.jsxs("div",{"data-testid":`${g}-defaults-precondition`,style:u0,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:Bt,children:[i.jsx("label",{style:qt,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:Pc,children:ee}),i.jsx("button",{type:"button","data-testid":`${g}-toggle-setting-clear`,onClick:()=>v("toggle_setting",void 0),style:Oc,children:"✕"})]}):null,i.jsx("input",{type:"text","data-testid":`${g}-toggle-setting-search`,value:ae,placeholder:n("layout_editor.page_settings.seo.toggle_setting_search"),onChange:V=>oe(V.target.value),style:Br}),ae.trim()!==""&&i.jsx("div",{"data-testid":`${g}-toggle-setting-results`,style:Bc,children:G.length===0?i.jsx("p",{style:no,children:n("layout_editor.inline_binding.no_results")}):G.map(V=>i.jsx("button",{type:"button","data-testid":`${g}-toggle-setting-option-${V.ref}`,onClick:()=>{v("toggle_setting",V.ref),oe("")},style:Wc,children:V.label??V.ref},V.ref))})]})]}),i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.data_sources")}),i.jsx("p",{style:no,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:no,children:n("layout_editor.page_settings.seo.data_sources_empty")}):a.map(V=>{const te=k.includes(V.id);return i.jsxs("label",{"data-testid":`${g}-data-source-${V.id}`,style:c0(te),children:[i.jsx("input",{type:"checkbox","data-testid":`${g}-data-source-check-${V.id}`,checked:te,onChange:()=>ge(V.id)}),i.jsx(Lc,{option:V,testIdPrefix:`${g}-data-source-${V.id}`})]},V.id)})})]}),i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,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:V=>v("priority",Number(V.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:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.changefreq")}),i.jsxs("select",{"data-testid":`${g}-changefreq`,value:typeof h.changefreq=="string"?h.changefreq:"",onChange:V=>v("changefreq",V.target.value),style:Br,children:[i.jsx("option",{value:"",children:n("layout_editor.page_settings.seo.use_default")}),l0.map(V=>i.jsx("option",{value:V,children:V},V))]})]}),i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.title")}),i.jsx(_t,{value:typeof h.title=="string"?h.title:"",onChange:V=>v("title",V??""),t:n,candidates:r,testidPrefix:`${g}-title`,enableExpressionTree:!0,expressionTreeCollapsible:!0})]}),i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.description")}),i.jsx(_t,{value:typeof h.description=="string"?h.description:"",onChange:V=>v("description",V??""),t:n,candidates:r,testidPrefix:`${g}-description`,enableExpressionTree:!0,expressionTreeCollapsible:!0})]}),i.jsx(hw,{og:h.og,twitter:h.twitter,onChangeOg:V=>v("og",Object.keys(V).length>0?V:void 0),onChangeTwitter:V=>v("twitter",Object.keys(V).length>0?V:void 0),ogPreview:C?.og,twitterPreview:C?.twitter,defaultsAvailable:C?.defaultsAvailable??!1,candidates:r,t:n}),i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.structured_data")}),i.jsx(Aw,{value:h.structured_data,onChange:V=>v("structured_data",V??void 0),autoBlock:C?.structured?.autoBlock,autoMeta:C?.structured?.autoMeta,lockedByFilter:C?.structured?.lockedByFilter,filteredBlock:C?.structured?.filteredBlock,pageType:_,candidates:r,t:n})]}),i.jsxs("div",{style:Bt,children:[i.jsx("label",{style:qt,children:n("layout_editor.page_settings.seo.vars")}),i.jsx(Hw,{vars:h.vars,onChange:V=>v("vars",Object.keys(V).length>0?V:void 0),varCandidates:I,gatingMet:x,candidates:r,t:n})]}),i.jsx(Xw,{templateIdentifier:o,layout:F,url:l,locale:d,seedContext:c,settingsSignature:L,t:n,fetchImpl:b})]})})]})}const Bt={display:"flex",flexDirection:"column",gap:4},qt={fontSize:12,fontWeight:600,color:"#334155"},Br={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",minWidth:0,boxSizing:"border-box"},no={margin:"4px 0 0",fontSize:11,color:"#94a3b8"},c0=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}),u0={fontSize:12,color:"#b45309",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,padding:"8px 10px"},Pc={display:"inline-flex",alignItems:"center",gap:4,fontSize:11,padding:"3px 8px",borderRadius:999,background:"#eef2ff",color:"#3730a3"},Oc={border:"none",background:"transparent",cursor:"pointer",color:"#6366f1",fontSize:11,padding:0},p0={fontSize:11,padding:"3px 10px",borderRadius:999,border:"1px dashed #cbd5e1",background:"#f8fafc",color:"#475569",cursor:"pointer"},Bc={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6,display:"flex",flexDirection:"column",gap:2},Wc={textAlign:"left",border:"none",background:"transparent",cursor:"pointer",padding:"5px 8px",borderRadius:4,fontSize:12,color:"#0f172a"},f0={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"},g0={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"},h0={init:["state","data","notify","nav","locale","etc","flow","error","extension"],component:["nav","notify","data","state","locale","etc","flow","error","extension"]};function y0(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 b0(e,t){return!e||e.kind==="core"?t("layout_editor.action.source_core"):e.id??t(`layout_editor.action.source_${e.kind}`)}function jc(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function m0({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(()=>ko(e),[e]),p=u.useMemo(()=>{const f=h0[o],b=new Map;for(const m of c){const h=y0(e,m.id),y=h!=null&&h.kind!=="core"?"extension":f0[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})=>jc(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:I0,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:v0,children:[t("layout_editor.action.add_action")," ▾"]}),s?i.jsxs("div",{"data-testid":`${r}-list`,style:_0,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:x0}),p.map(({groupKey:f,items:b})=>i.jsxs("div",{"data-testid":`${r}-group-${f}`,children:[i.jsxs("div",{style:w0,children:["━━ ",t(g0[f]??f)," ━━"]}),b.map(({recipe:g,source:m})=>i.jsxs("button",{type:"button","data-testid":`g7le-init-action-spec-${g.id}`,onClick:()=>{n(Sr(g,{})),a(!1),d("")},style:k0,children:[i.jsx("span",{style:S0,children:jc(g.label,t,g.id)}),i.jsxs("span",{"data-testid":`g7le-init-action-spec-source-${g.id}`,style:C0,children:["〔",b0(m,t),"〕"]}),i.jsx("code",{style:$0,children:g.build.handler})]},g.id))]},f)),p.length===0?i.jsx("div",{"data-testid":`${r}-no-match`,style:E0,children:t("layout_editor.action.add_no_match")}):null]}):null]})}const v0={padding:"6px 12px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},_0={marginTop:6,border:"1px solid #cbd5e1",borderRadius:8,background:"#fff",maxHeight:320,overflowY:"auto",padding:8},x0={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"},k0={display:"flex",alignItems:"center",gap:6,width:"100%",textAlign:"left",padding:"6px 8px",fontSize:12,border:"none",background:"transparent",cursor:"pointer",borderRadius:6},S0={flex:1,minWidth:0,color:"#0f172a"},C0={fontSize:10,color:"#64748b",whiteSpace:"nowrap"},$0={fontSize:10,color:"#cbd5e1",fontFamily:"monospace",whiteSpace:"nowrap"},E0={fontSize:12,color:"#94a3b8",padding:"8px 4px"},I0={fontSize:12,color:"#94a3b8",padding:"8px 0"};function A0(e,t){return t.startsWith("$t:")?e(t.slice(3)):t}function T0({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?Kd(t,n,p=>A0(o,p)):typeof e.handler=="string"?e.handler:o("layout_editor.action.advanced_action");return i.jsxs("div",{className:a,"data-testid":a,style:D0,children:[r?i.jsxs("span",{"data-testid":`${a}-missing`,style:N0,children:["⚠ ",o("layout_editor.action.summary_missing_required")]}):i.jsx("span",{"data-testid":`${a}-summary`,style:z0,children:c}),s?i.jsx("button",{type:"button","data-testid":`${a}-code-toggle`,onClick:()=>d(p=>!p),style:M0,"aria-expanded":l,"aria-label":o("layout_editor.action.view_code"),children:"</>"}):null,s&&l?i.jsx("pre",{"data-testid":`${a}-code`,style:L0,children:JSON.stringify(e,null,2)}):null]})}const D0={display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,minWidth:0},z0={flex:1,minWidth:0,fontSize:12,color:"#475569"},N0={flex:1,minWidth:0,fontSize:12,color:"#b45309"},M0={border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",fontSize:11,padding:"2px 6px",whiteSpace:"nowrap"},L0={flexBasis:"100%",margin:"6px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:11,overflow:"auto"},Hc="__g7le_custom__";function Wr({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:Uc,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===Hc){f(!0);return}t(g===""?void 0:g)},style:{...Kc,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:Hc,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:qc,children:"✎"})]}):i.jsxs("div",{style:Uc,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:qc,children:"≡"})]})}function P0({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Wr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.page_placeholder"),testid:"g7le-widget-page-picker",t:o,bindingCandidates:r})}function Fc({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Wr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.datasource_placeholder"),testid:"g7le-widget-datasource-picker",t:o,bindingCandidates:r})}function Ts({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Wr,{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 O0({value:e,onChange:t,candidates:n,t:o,bindingCandidates:r}){return i.jsx(Wr,{value:e,onChange:t,candidates:n,placeholder:o("layout_editor.recipe.modal_placeholder"),testid:"g7le-widget-modal-picker",t:o,bindingCandidates:r})}function B0({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 W0({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:Vc}),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:{...Kc,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 j0({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:Vc})}const Kc={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",minWidth:140,width:"100%"},Vc={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:100,width:"100%"},Uc={display:"flex",gap:4,alignItems:"flex-start",width:"100%"},qc={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"};function H0(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 Gc(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 Ds(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function F0(e,t,n){return t.includes(n)?"self":e.includes(n)?"inherited":"self"}function K0(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 Yc=[{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 zn({value:e,onChange:t,t:n,path:o,scope:r,depth:s=0,renderStringLeaf:a}){const l=H0(e),d=c=>{t(Gc(c))};return i.jsxs("div",{className:"g7le-initstate-value",style:{paddingLeft:s>0?12:0,minWidth:0},children:[i.jsxs("div",{style:U0,children:[i.jsx("select",{"data-testid":`g7le-initstate-type-${o}`,value:l,onChange:c=>d(c.target.value),style:Xc,children:Yc.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:Jc}):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:Jc}):l==="boolean"?i.jsx(Mr,{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:q0,children:"null"}):null]}),l==="list"?i.jsxs("div",{style:Zc,children:[e.map((c,p)=>i.jsxs("div",{style:G0,children:[i.jsxs("span",{style:Y0,children:["[",p,"]"]}),i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(zn,{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:Qc,children:"✕"})]},p)),i.jsxs("button",{type:"button","data-testid":`g7le-initstate-item-add-${o}`,onClick:()=>t([...e,""]),style:Rc,children:["+ ",n("layout_editor.initstate.add_item")]})]}):null,l==="object"?i.jsx(V0,{value:e,onChange:t,t:n,path:o,scope:r,depth:s+1,renderStringLeaf:a}):null]})}function V0({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(!Ds(h)){b(n("layout_editor.initstate.name_invalid"));return}if(h in e){b(n("layout_editor.initstate.name_duplicate"));return}t({...e,[h]:Gc(c)}),d(""),b(null)};return i.jsxs("div",{style:Zc,children:[g.map(([h,v])=>i.jsxs("div",{style:X0,children:[i.jsx("code",{style:J0,children:h}),i.jsx("div",{style:{flex:1,minWidth:0},children:i.jsx(zn,{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:Qc,children:"✕"})]},h)),i.jsxs("div",{style:Z0,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:{...Q0,...f?R0: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:Xc,children:Yc.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:Rc,children:["+ ",n("layout_editor.initstate.add_subkey")]})]}),f?i.jsx("p",{"data-testid":`g7le-initstate-subkey-error-${o}`,style:ek,children:f}):null]})}const U0={display:"flex",gap:6,alignItems:"center",minWidth:0},Xc={padding:"4px 6px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,color:"#64748b"},Jc={flex:1,minWidth:0,padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},q0={fontSize:12,color:"#94a3b8",fontFamily:"monospace"},Zc={display:"flex",flexDirection:"column",gap:6,marginTop:6,paddingLeft:8,borderLeft:"2px solid #e2e8f0"},G0={display:"flex",gap:6,alignItems:"flex-start",minWidth:0},Y0={fontSize:11,color:"#94a3b8",minWidth:28,paddingTop:4},X0={display:"flex",gap:6,alignItems:"flex-start",minWidth:0},J0={fontSize:11,color:"#475569",fontFamily:"monospace",minWidth:72,paddingTop:4},Qc={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12},Rc={alignSelf:"flex-start",padding:"2px 8px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},Z0={display:"flex",gap:6,alignItems:"center"},Q0={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6},R0={border:"1px solid #dc2626"},ek={margin:"2px 0 0",fontSize:11,color:"#dc2626"},tk=new Set(["text","data-chip","number"]),nk=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 ok(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function rk(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 ik({param:e,value:t,t:n,pools:o,onChange:r,testIdPrefix:s,renderActionList:a,siblingValues:l}){const d=ok(e.label,n,e.key);if(e.advanced)return i.jsxs("div",{"data-testid":`${s}-locked-${e.key}`,style:hk,children:[i.jsx("span",{style:yk,children:d}),i.jsxs("span",{style:bk,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:oo,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:oo,children:d}),i.jsx(sk,{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:oo,children:d}),i.jsx(uk,{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:oo,children:d}),i.jsx(pk,{value:t,onChange:r,t:n,candidates:o.bindingCandidates,stateKeyCandidates:o.stateKeyCandidates,param:e,siblingTarget:l?.target,testIdPrefix:`${s}-skv-${e.key}`})]});if(tk.has(e.widget??"")||!nk.has(e.widget??""))return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:tu,children:[i.jsx("span",{style:oo,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=Tn(e.widget);return i.jsxs("div",{"data-testid":`${s}-param-${e.key}`,style:tu,children:[i.jsx("span",{style:oo,children:d}),i.jsx("div",{style:{flex:1,minWidth:0},children:p?i.jsx(p,{control:{...e},value:t,onChange:r,t:n,candidates:rk(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 sk({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:ak,children:[i.jsxs("div",{style:lk,children:[i.jsxs("span",{style:dk,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:zs,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:zs,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:zs,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:eu,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:eu,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:ck,children:["+ ",n("layout_editor.action_recipe.conditions.add_branch")]})]})}const ak={border:"1px solid #e2e8f0",borderRadius:6,padding:8,display:"flex",flexDirection:"column",gap:6,background:"#f8fafc"},lk={display:"flex",justifyContent:"space-between",alignItems:"center"},dk={fontSize:12,fontWeight:700,color:"#475569"},eu={fontSize:11,color:"#64748b"},zs={border:"1px solid #cbd5e1",background:"#fff",borderRadius:4,width:22,height:22,cursor:"pointer",fontSize:12,lineHeight:"1",color:"#475569"},ck={border:"1px dashed #94a3b8",background:"#fff",borderRadius:6,padding:"6px 10px",cursor:"pointer",fontSize:12,color:"#475569",alignSelf:"flex-start"};function uk({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(Pr,{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 pk({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(zn,{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(Ts,{control:{...s},value:y,onChange:w=>{const k=w==null?"":String(w);if(k===""||k===y||d.some(([$])=>$===k))return;const x={};for(const[$,S]of d)x[$===y?k:$]=S;t(x)},t:n,candidates:r})}),i.jsx("div",{style:{minWidth:0},children:i.jsx(zn,{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(Ts,{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 Ns({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=Sr(t,f),g=cs(e);s(g?Vd(b,g):b)};return i.jsx(i.Fragment,{children:t.params.filter(c=>fk(c,n)).map(c=>i.jsx(ik,{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 fk(e,t){const n=e.dependsOn;return!n||typeof n!="object"||typeof n.param!="string"?!0:t[n.param]===n.equals}function gk({raw:e,t,onChange:n,testIdPrefix:o,candidates:r}){const[s,a]=u.useState(!1);return i.jsxs("div",{"data-testid":`${o}-if`,style:mk,children:[i.jsxs("button",{type:"button",onClick:()=>a(l=>!l),style:vk,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:cs(e)??"",onChange:l=>n(Vd(e,l)),t,candidates:r,placeholder:t("layout_editor.init_actions.if_placeholder"),testidPrefix:`${o}-if-chip`})}):null]})}const tu={display:"flex",alignItems:"center",gap:8,minWidth:0},oo={fontSize:11,color:"#64748b",minWidth:80},hk={display:"flex",alignItems:"center",gap:8,padding:"4px 0"},yk={fontSize:11,color:"#64748b",minWidth:80},bk={fontSize:11,color:"#92400e"},mk={display:"flex",flexDirection:"column",gap:4},vk={textAlign:"left",border:"none",background:"transparent",color:"#475569",cursor:"pointer",fontSize:11,padding:0};function _k(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 xk(e,t,n){const o=Yn(e,t);if(o.kind==="preset"){const r=t.find(s=>s.id===o.recipeId);return Kd(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 Gt({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(()=>ko(o),[o]),y=u.useMemo(()=>{if(r==null||r==="init")return c;const B=Vl(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]),S=ys({length:e.length,onMove:$,canDrag:f,canDropAt:b}),C=u.useCallback(B=>{t(e.filter((M,O)=>O!==B))},[e,t]),T=u.useCallback((B,M)=>{const O=e.slice();O[B]=M,t(O)},[e,t]),E=u.useCallback(B=>{t([...e,B])},[e,t]),A=u.useCallback((B,M)=>{const O=Yn(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:Ck,children:[i.jsx(Ns,{raw:B,recipe:z,values:H,t:n,pools:y??{},onChange:M,testIdPrefix:`${h}-edit`,renderActionList:(P,I,L,F)=>{const Y=F==="onSuccess"?"response":F==="onError"?"error":void 0;return i.jsx(Gt,{actions:P,onChange:I,t:n,recipes:o,chipContext:Y,actionChipCandidates:Y?s:void 0,candidatePools:Y?c:y,addContext:a,showSourceBadge:p,testIdPrefix:L})}}),i.jsx(gk,{raw:B,t:n,onChange:M,testIdPrefix:`${h}-edit`,candidates:y?.bindingCandidates})]})},[v,n,y,c,s,h,o,a,p]),N=d??(o?A:void 0),D=m?null:l?l(E):o?i.jsx(m0,{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=Yn(B,v),z=O.kind==="preset"?O.recipeId:null,H=z?v.find(Y=>Y.id===z)??null:null,P=H===null,I=g?.(M)??!1,L=cs(B)!==null,F=N?N(B,Y=>T(M,Y)):null;return i.jsxs(u.Fragment,{children:[I?null:i.jsx("li",{"aria-hidden":"true",style:{listStyle:"none",margin:0,padding:0},children:i.jsx(Rn,{active:S.isDropTarget(M),testid:`${h}-dropline-${M}`})}),i.jsxs("li",{"data-testid":`${h}-item-${M}`,"data-drag-source":S.dragIndex===M?"true":void 0,style:{border:"1px solid #e2e8f0",borderRadius:8,padding:"8px 10px",...S.dragIndex===M?{opacity:.5}:{}},onDragOver:S.dragging&&!I?Y=>{Y.preventDefault();const K=Y.currentTarget.getBoundingClientRect();S.onDragOverItem(M,Y.clientY<K.top+K.height/2?"before":"after")}:void 0,onDrop:S.dragging&&!I?Y=>{Y.preventDefault(),S.onDrop()}:void 0,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[I?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:()=>S.onDragStart(M),onDragEnd:S.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:xk(B,v,n)}),p?i.jsxs("span",{"data-testid":`${h}-source-${M}`,style:wk,children:["〔",_k(o,z,n),"〕"]}):null,L?i.jsxs("span",{"data-testid":`${h}-cond-badge-${M}`,style:kk,children:["〔",n("layout_editor.init_actions.cond_badge"),"〕"]}):null,P?i.jsxs("span",{"data-testid":`${h}-advanced-${M}`,style:Sk,children:["[",n("layout_editor.action.advanced"),"]"]}):null,!I&&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?$k:nu,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?Ek:Ms,children:"</>"}),I?null:i.jsx("button",{type:"button","data-testid":`${h}-remove-${M}`,onClick:()=>C(M),"aria-label":n("layout_editor.action_list.remove"),title:n("layout_editor.action_list.remove"),style:Ik,children:"✕"})]}),H?i.jsx(T0,{action:B,recipe:H,values:O.kind==="preset"?O.values:{},t:n,showCodeButton:!1,testIdPrefix:`${h}-preview-${M}`}):null,k===M&&!I&&F?i.jsx("div",{"data-testid":`${h}-edit-body-${M}`,children:F}):null,d&&k!==M?d(B,Y=>T(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(Rn,{active:S.isDropTarget(e.length),testid:`${h}-dropline-end`})})]}),D?i.jsx("div",{style:{marginTop:8},children:D}):null]})}const wk={fontSize:10,color:"#64748b",whiteSpace:"nowrap"},kk={fontSize:10,color:"#7c3aed",whiteSpace:"nowrap"},Sk={fontSize:10,color:"#92400e",whiteSpace:"nowrap"},Ck={display:"flex",flexDirection:"column",gap:6,paddingTop:6,borderTop:"1px dashed #e2e8f0",marginTop:6},nu={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},$k={...nu,background:"#eff6ff",borderColor:"#bfdbfe",color:"#2563eb"},Ms={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"},Ek={...Ms,background:"#0f172a",borderColor:"#0f172a",color:"#e2e8f0"},Ik={...Ms,color:"#dc2626",borderColor:"#fecaca",fontFamily:"inherit"};function ou(e){const t=e.__source;return t&&typeof t=="object"?t:null}function Ak({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=>ou(h)?.kind==="base"),[e]),f=u.useMemo(()=>e.filter(h=>ou(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:Tk,children:[i.jsx("p",{style:Dk,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:ru,children:[i.jsx("div",{style:iu,children:o("layout_editor.init_actions.group_base")}),i.jsx(Gt,{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:zk,children:["ⓘ ",o("layout_editor.init_actions.base_readonly_hint")]})]}),i.jsxs("div",{"data-testid":"g7le-init-action-group-self",style:ru,children:[i.jsx("div",{style:iu,children:o("layout_editor.init_actions.group_self")}),f.length===0?i.jsx("p",{style:su,children:o("layout_editor.init_actions.empty_self")}):null,i.jsx(Gt,{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:Nk,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:su,children:o("layout_editor.init_actions.empty")}):null,i.jsx(Gt,{actions:e,onChange:t,t:o,recipes:n,candidatePools:c,addContext:"init",showSourceBadge:!0,testIdPrefix:"g7le-init-action"})]})]})}const Tk={display:"flex",flexDirection:"column",gap:12,minWidth:0},Dk={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},ru={border:"1px solid #e2e8f0",borderRadius:10,padding:10,display:"flex",flexDirection:"column",gap:8},iu={fontSize:12,fontWeight:700,color:"#475569"},zk={margin:0,fontSize:11,color:"#64748b"},su={margin:0,fontSize:12,color:"#94a3b8"},Nk={margin:0,fontSize:11,color:"#64748b"};function Mk(e){return e==="spinner"?new Set(["spinner","page"]):new Set(["skeleton"])}function au(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function lu({candidates:e,value:t,onSelect:n,styleKind:o,t:r,testIdPrefix:s="g7le-loading-component-picker"}){const a=bo(),l=()=>{const d=a.open({ariaLabel:r("layout_editor.overlay.loading_picker.select"),width:520,maxHeightRatio:.7,content:i.jsx(Lk,{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:Pk,children:[i.jsx("span",{"data-testid":`${s}-current`,style:Ok,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:Bk,children:["🔍 ",r("layout_editor.overlay.loading_picker.select")]})]})})}function Lk({candidates:e,value:t,styleKind:n,t:o,testIdPrefix:r,onPick:s,onClose:a}){const[l,d]=u.useState(""),c=Mk(n),p=u.useMemo(()=>{const f=l.trim().toLowerCase();return e.filter(b=>c.has(b.role)).filter(b=>f?au(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:Wk,children:[i.jsxs("div",{style:jk,children:[i.jsxs("span",{style:Hk,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:Fk,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:Kk,autoFocus:!0}),p.length===0?i.jsx("p",{"data-testid":`${r}-empty`,style:Jk,children:o("layout_editor.overlay.loading_picker.empty")}):i.jsx("ul",{style:Vk,children:p.map(f=>i.jsx("li",{children:i.jsxs("button",{type:"button","data-testid":`${r}-item-${f.name}`,onClick:()=>s(f.name),style:{...Uk,...t===f.name?qk:{}},children:[i.jsx("span",{style:Gk,children:au(f.label,o,f.name)}),i.jsx("code",{style:Yk,children:f.name}),i.jsx("span",{style:Xk,children:f.role})]})},f.name))})]})}const Pk={display:"flex",alignItems:"center",gap:6,minWidth:0},Ok={flex:1,minWidth:0,fontSize:12,color:"#0f172a",fontFamily:"monospace"},Bk={padding:"4px 10px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer",whiteSpace:"nowrap"},Wk={display:"flex",flexDirection:"column",minHeight:0,padding:16,boxSizing:"border-box",fontFamily:"system-ui, -apple-system, sans-serif"},jk={display:"flex",alignItems:"center",gap:8,paddingBottom:8,borderBottom:"1px solid #e2e8f0",marginBottom:10},Hk={flex:1,fontSize:14,fontWeight:700,color:"#0f172a",minWidth:0},Fk={border:"none",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:15,lineHeight:1,padding:4},Kk={width:"100%",padding:"6px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,marginBottom:8,boxSizing:"border-box"},Vk={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:2,overflowY:"auto",minHeight:0},Uk={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},qk={border:"1px solid #3b82f6",background:"#eff6ff"},Gk={flex:1,minWidth:0,color:"#0f172a"},Yk={fontSize:10,color:"#94a3b8",fontFamily:"monospace"},Xk={fontSize:10,color:"#64748b",background:"#f1f5f9",borderRadius:4,padding:"0 4px"},Jk={margin:0,fontSize:12,color:"#94a3b8",padding:"8px 4px"};function du(e){return e===!0?{enabled:!0}:e===!1||e===void 0?{}:e}const Zk=["opaque","blur","fade","skeleton","spinner"];function Qk({value:e,patch:t,t:n,baseValue:o,ownValue:r,loadingComponents:s=[],progressiveDataSources:a=[],bindingCandidates:l}){const d=du(e),c=d.enabled??!1,p=!!o&&Object.keys(o).length>0,f=Tn("component-target-picker"),[b,g]=u.useState((d.wait_for??[]).length>0),m=u.useCallback(k=>{const x={...du(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:Rk,children:[p?i.jsxs("p",{"data-testid":"g7le-overlay-inherit-banner",style:e1,children:["ⓘ ",n("layout_editor.overlay.inherit_banner")]}):null,i.jsxs("div",{style:Hr,children:[i.jsx(Ls,{label:n("layout_editor.overlay.enabled_label"),inherited:v("enabled"),hasInheritance:p,onOverride:()=>y("enabled"),testidKey:"enabled",t:n}),i.jsx(Lr,{disabled:v("enabled"),children:i.jsx(Mr,{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:Fr,children:["ⓘ ",n("layout_editor.overlay.enabled_hint")]})]}),i.jsx(Lr,{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:Hr,children:[i.jsx(Ls,{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:Ps,children:[i.jsx(jr,{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(jr,{active:w==="region",onClick:()=>m(k=>{k.target=k.target??""}),testid:"g7le-overlay-scope-region",children:n("layout_editor.overlay.scope_region")})]}),i.jsx(Lr,{disabled:w!=="region",testid:"g7le-overlay-region-box",style:r1,children:i.jsxs(i.Fragment,{children:[i.jsx(Nn,{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:a1})})}),i.jsx(Nn,{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:Fr,children:["ⓘ ",n("layout_editor.overlay.fallback_hint")]})]})})]}),i.jsxs("div",{style:Hr,children:[i.jsx(Ls,{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:Ps,children:Zk.map(k=>i.jsx(jr,{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:cu,children:[i.jsx(Nn,{label:n("layout_editor.overlay.skeleton_component"),children:i.jsx(lu,{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(Nn,{label:n("layout_editor.overlay.skeleton_animation"),children:i.jsx("div",{"data-testid":"g7le-overlay-skeleton-anim",style:Ps,children:["wave","pulse","none"].map(k=>i.jsx(jr,{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(Nn,{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:l1})})]}):null,d.style==="spinner"?i.jsxs("div",{style:cu,children:[i.jsx(Nn,{label:n("layout_editor.overlay.spinner_component"),children:i.jsx(lu,{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(Nn,{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:Hr,children:[i.jsxs("button",{type:"button","data-testid":"g7le-overlay-waitfor-toggle","aria-expanded":b,onClick:()=>g(k=>!k),style:u1,children:[b?"▾":"▸"," ",n("layout_editor.overlay.waitfor_label")]}),b?i.jsxs("div",{"data-testid":"g7le-overlay-waitfor-body",style:p1,children:[i.jsxs("p",{"data-testid":"g7le-overlay-waitfor-hint",style:Fr,children:["ⓘ ",n("layout_editor.overlay.waitfor_hint")]}),a.length===0?i.jsx("p",{"data-testid":"g7le-overlay-waitfor-empty",style:Fr,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:d1(x),children:[i.jsx("input",{type:"checkbox",checked:x,onChange:()=>m($=>{const S=new Set($.wait_for??[]);S.has(k.id)?S.delete(k.id):S.add(k.id);const C=Array.from(S);C.length===0?delete $.wait_for:$.wait_for=C})}),i.jsx(Lc,{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:c1,children:["⟲ ",n("layout_editor.overlay.reset_inherit")]}):null]})})]})}function jr({active:e,onClick:t,children:n,testid:o}){return i.jsx("button",{type:"button","data-testid":o,"aria-pressed":e,onClick:t,style:{...n1,...e?o1:{}},children:n})}function Ls({label:e,inherited:t,hasInheritance:n,onOverride:o,testidKey:r,t:s}){return i.jsxs("div",{style:f1,children:[i.jsx("label",{style:t1,children:e}),n?t?i.jsxs(i.Fragment,{children:[i.jsxs("span",{"data-testid":`g7le-overlay-inherited-${r}`,style:g1,children:["〔",s("layout_editor.overlay.inherited_badge"),"〕"]}),i.jsx("button",{type:"button","data-testid":`g7le-overlay-override-${r}`,onClick:o,style:y1,children:s("layout_editor.overlay.override_field")})]}):i.jsxs("span",{"data-testid":`g7le-overlay-overridden-${r}`,style:h1,children:["〔",s("layout_editor.overlay.overridden_badge"),"〕"]}):null]})}function Nn({label:e,children:t}){return i.jsxs("div",{style:i1,children:[i.jsx("span",{style:s1,children:e}),i.jsx("div",{style:{flex:1,minWidth:0},children:t})]})}const Rk={display:"flex",flexDirection:"column",gap:16,minWidth:0},e1={margin:0,fontSize:12,color:"#1d4ed8",background:"#eff6ff",padding:"8px 10px",borderRadius:6},Hr={display:"flex",flexDirection:"column",gap:6,minWidth:0},t1={fontSize:13,fontWeight:600,color:"#0f172a"},Fr={margin:0,fontSize:11,color:"#94a3b8"},Ps={display:"flex",gap:4,flexWrap:"wrap"},n1={padding:"4px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},o1={border:"1px solid #3b82f6",background:"#eff6ff",color:"#1d4ed8"},r1={display:"flex",flexDirection:"column",gap:8,padding:8,border:"1px dashed #e2e8f0",borderRadius:8},cu={display:"flex",flexDirection:"column",gap:8,padding:8,border:"1px dashed #e2e8f0",borderRadius:8},i1={display:"flex",alignItems:"center",gap:8,minWidth:0},s1={fontSize:11,color:"#64748b",minWidth:90},a1={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},l1={width:80,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},d1=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"}),c1={alignSelf:"flex-start",padding:"6px 12px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},u1={alignSelf:"flex-start",padding:"4px 0",fontSize:13,fontWeight:600,color:"#0f172a",background:"transparent",border:"none",cursor:"pointer"},p1={display:"flex",flexDirection:"column",gap:6,paddingLeft:14,minWidth:0},f1={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",minWidth:0},g1={fontSize:11,color:"#64748b",background:"#f1f5f9",borderRadius:4,padding:"1px 6px"},h1={fontSize:11,color:"#0369a1",background:"#e0f2fe",borderRadius:4,padding:"1px 6px"},y1={padding:"2px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},b1="g7le:computed-effect-preview",m1={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 v1(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 uu({expr:e,computedKey:t,sampleContext:n,t:o,isEffect:r=!1,testIdPrefix:s="g7le-computed-preview"}){const a=zd(e,n),l=()=>{typeof window>"u"||!t||window.dispatchEvent(new CustomEvent(b1,{detail:{key:t}}))};return a.ok?i.jsxs("div",{className:s,"data-testid":s,style:_1,children:[i.jsx("span",{style:x1,children:o("layout_editor.computed.preview_label")}),i.jsx("span",{"data-testid":`${s}-value`,style:w1,children:v1(a.value,a.type,o)}),i.jsxs("span",{"data-testid":`${s}-type`,style:k1,children:["(",o(m1[a.type]),")"]}),r&&a.type==="boolean"?i.jsxs("button",{type:"button","data-testid":`${s}-effect`,onClick:l,style:S1,children:["▷ ",o("layout_editor.computed.effect_preview")]}):null]}):i.jsxs("div",{"data-testid":`${s}-error`,style:C1,children:["⚠ ",o("layout_editor.computed.preview_error")]})}const _1={display:"flex",alignItems:"center",flexWrap:"wrap",gap:6,minWidth:0},x1={fontSize:11,color:"#94a3b8"},w1={fontSize:12,color:"#0f172a",fontFamily:"monospace",wordBreak:"break-all"},k1={fontSize:10,color:"#64748b"},S1={padding:"2px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},C1={fontSize:12,color:"#b45309"},$1=[{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"}],E1=["=","!=",">","<",">=","<=","includes"],I1=new Set(["count","sum","filter"]);function pu({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=Tn("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:A1,children:[i.jsx(Os,{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:ro})})}),i.jsxs(Os,{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:ro,children:$1.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:ro}),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:ro,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:ro}),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,I1.has(e.op)?i.jsxs("div",{style:N1,children:[l.map((g,m)=>i.jsxs("div",{"data-testid":`g7le-computed-custom-cond-${m}`,style:M1,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:L1,children:E1.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:P1,children:"✕"})]},m)),i.jsxs("button",{type:"button","data-testid":"g7le-computed-custom-cond-add",onClick:p,style:O1,children:["+ ",n("layout_editor.computed.cond_add")]})]}):null]}),i.jsxs(Os,{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:{...ro,...c?z1:{}}}),c?i.jsxs("p",{"data-testid":"g7le-computed-custom-key-dup",style:B1,children:["⚠ ",n("layout_editor.computed.key_duplicate")]}):null]})]})}function Os({label:e,children:t}){return i.jsxs("div",{style:T1,children:[i.jsx("div",{style:D1,children:e}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:t})]})}function Bs(e){return Zm(e)}const A1={display:"flex",flexDirection:"column",gap:12,padding:10,border:"1px solid #cbd5e1",borderRadius:8,background:"#fff"},T1={display:"flex",flexDirection:"column",gap:4,minWidth:0},D1={fontSize:12,fontWeight:600,color:"#475569"},ro={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:0,width:"100%",boxSizing:"border-box"},z1={border:"1px solid #ef4444"},N1={display:"flex",flexDirection:"column",gap:6,marginTop:4},M1={display:"flex",gap:4,alignItems:"center",minWidth:0},L1={padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},P1={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12},O1={alignSelf:"flex-start",padding:"2px 8px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},B1={margin:0,fontSize:11,color:"#b45309"};function Ws(e,t,n){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function W1(e){if(e&&typeof e=="object"){const t=e.__source;if(t&&typeof t=="object")return t}return null}function j1({computed:e,onChange:t,recipes:n,t:o,sampleContext:r,dataSourceCandidates:s,bindingCandidates:a,computedSource:l={},effectKeys:d=[],onRevert:c}){const p=u.useMemo(()=>Cd(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,$,S)=>{const C={...e};x&&x!==$&&delete C[x],C[$]=S,t(C)},[e,t]),w=u.useCallback(x=>{const $=Ed(x,{});let S=x.id,C=1;for(;S in e;)S=`${x.id}${++C}`;t({...e,[S]:$}),b(!1)},[e,t]),k=u.useCallback(()=>{!g||!g.key||(t({...e,[g.key]:Bs(g)}),m(null),b(!1))},[g,e,t]);return i.jsxs("div",{className:"g7le-computed-form","data-testid":"g7le-computed-form",style:V1,children:[i.jsx("p",{style:U1,children:o("layout_editor.page_settings.computed.heading")}),h.length>0?h.map(x=>i.jsx(H1,{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:($,S)=>_(x,$,S),onRemove:()=>y(x),onRevert:c?()=>c(x):void 0},x)):i.jsx("p",{"data-testid":"g7le-computed-empty",style:gS,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:sS,children:["+ ",o("layout_editor.computed.add")," ▾"]}),f?i.jsxs("div",{"data-testid":"g7le-computed-add-list",style:aS,children:[["common","more"].map(x=>{const $=p.filter(S=>(S.group??"more")===x);return $.length===0?null:i.jsxs("div",{children:[i.jsxs("div",{style:lS,children:["━━ ",o(`layout_editor.computed.group_${x}`)," ━━"]}),$.map(S=>{const C=W1(n?.[S.id]);return i.jsxs("button",{type:"button","data-testid":`g7le-computed-preset-${S.id}`,onClick:()=>w(S),style:dS,children:[i.jsx("span",{style:cS,children:Ws(S.label,o,S.id)}),C&&C.kind!=="core"?i.jsxs("span",{"data-testid":`g7le-computed-preset-source-${S.id}`,style:uS,children:["〔",C.id??C.kind,"〕"]}):null]},S.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:pS,children:["⚙ ",o("layout_editor.computed.custom_open")," ▾"]}),g?i.jsxs("div",{style:{marginTop:6},children:[i.jsx(pu,{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(uu,{expr:Bs(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:fS,children:o("layout_editor.computed.custom_add")})]}):null]})]}):null]})]})}function H1({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(()=>Dd(t,n),[t,n]),k=d==="base",x=d==="route-override",$=w.kind==="advanced",S=w.kind==="preset"?n.find(E=>E.id===w.recipeId)??null:null,C=S?Ws(S.label,r,e):e,T=(E,A)=>{if(w.kind!=="preset"||!S)return;const N={...w.params,[E]:A};f(Ed(S,N))};return i.jsxs("div",{"data-testid":`g7le-computed-item-${e}`,style:q1,children:[i.jsxs("div",{style:G1,children:[i.jsx("span",{style:Y1,children:C}),i.jsx("code",{style:X1,children:e}),k?i.jsxs("span",{"data-testid":`g7le-computed-source-${e}`,style:J1,children:["〔",r("layout_editor.computed.source_base"),"〕"]}):null,x?i.jsxs("span",{"data-testid":`g7le-computed-overridden-${e}`,style:Z1,children:["〔",r("layout_editor.computed.source_overridden"),"〕"]}):null,$?i.jsxs("span",{"data-testid":"g7le-computed-advanced",style:Q1,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:js,"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:js,children:r("layout_editor.init_actions.edit")}),i.jsx("button",{type:"button","data-testid":`g7le-computed-remove-${e}`,onClick:g,style:js,"aria-label":r("layout_editor.init_actions.remove"),children:"✕"})]}),y?i.jsx("pre",{"data-testid":`g7le-computed-code-block-${e}`,style:hS,children:t}):null,i.jsx("div",{"data-testid":`g7le-computed-preview-${e}`,children:i.jsx(uu,{expr:t,computedKey:e,sampleContext:s,t:r,isEffect:c,testIdPrefix:`g7le-computed-preview-${e}-eval`})}),x&&m?i.jsxs("div",{style:R1,children:[i.jsxs("span",{style:eS,children:["ⓘ ",r("layout_editor.computed.overridden_hint")]}),i.jsx("button",{type:"button","data-testid":`g7le-computed-revert-${e}`,onClick:m,style:tS,children:r("layout_editor.computed.revert")})]}):null,h&&!$?i.jsxs("div",{style:nS,children:[k?i.jsxs("p",{"data-testid":`g7le-computed-override-notice-${e}`,style:oS,children:["⚠ ",r("layout_editor.computed.override_notice")]}):null,w.kind==="preset"&&S?i.jsx(i.Fragment,{children:S.params.map(E=>i.jsx(K1,{param:E,value:w.params[E.key]??"",t:r,dataSourceCandidates:a,bindingCandidates:l,onChange:A=>T(E.key,A)},E.key))}):w.kind==="custom"?i.jsx(pu,{model:{...w.model,key:e},onChange:E=>b(E.key,Bs(E)),t:r,dataSourceCandidates:a,bindingCandidates:l,existingKeys:p.filter(E=>E!==e)}):null]}):null]})}const F1=new Set(["datasource-picker","binding-picker","select","toggle","state-key-picker","page-picker"]);function K1({param:e,value:t,t:n,dataSourceCandidates:o,bindingCandidates:r,onChange:s}){const a=Ws(e.label,n,e.key),l=e.widget??"",c=F1.has(l)?Tn(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:rS,children:[i.jsx("span",{style:iS,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 V1={display:"flex",flexDirection:"column",gap:12,minWidth:0},U1={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},q1={border:"1px solid #e2e8f0",borderRadius:8,padding:"8px 10px",display:"flex",flexDirection:"column",gap:6,background:"#f8fafc"},G1={display:"flex",alignItems:"center",gap:6},Y1={fontSize:13,fontWeight:600,color:"#0f172a"},X1={fontSize:10,color:"#64748b",fontFamily:"monospace"},J1={fontSize:10,color:"#0891b2",whiteSpace:"nowrap"},Z1={fontSize:10,color:"#7c3aed",whiteSpace:"nowrap"},Q1={fontSize:10,color:"#92400e",whiteSpace:"nowrap"},R1={display:"flex",alignItems:"center",gap:8,marginTop:4,minWidth:0},eS={fontSize:11,color:"#7c3aed",flex:1,minWidth:0},tS={border:"1px solid #c4b5fd",borderRadius:6,background:"#f5f3ff",color:"#6d28d9",cursor:"pointer",fontSize:11,padding:"2px 8px",whiteSpace:"nowrap"},js={border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",fontSize:11,padding:"2px 6px"},nS={display:"flex",flexDirection:"column",gap:6,paddingTop:6,borderTop:"1px dashed #e2e8f0"},oS={margin:0,fontSize:11,color:"#b45309",background:"#fef3c7",padding:"6px 8px",borderRadius:6},rS={display:"flex",alignItems:"center",gap:8,minWidth:0},iS={fontSize:11,color:"#64748b",minWidth:90},sS={padding:"6px 12px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},aS={marginTop:6,border:"1px solid #cbd5e1",borderRadius:8,background:"#fff",padding:8,maxHeight:380,overflowY:"auto"},lS={fontSize:11,fontWeight:700,color:"#94a3b8",padding:"6px 4px 2px"},dS={display:"flex",alignItems:"center",gap:6,width:"100%",textAlign:"left",padding:"6px 8px",fontSize:12,border:"none",background:"transparent",cursor:"pointer",borderRadius:6},cS={flex:1,minWidth:0,color:"#0f172a"},uS={fontSize:10,color:"#64748b",whiteSpace:"nowrap"},pS={padding:"6px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},fS={marginTop:6,padding:"6px 12px",fontSize:12,border:"1px solid #3b82f6",borderRadius:6,background:"#3b82f6",color:"#fff",cursor:"pointer"},gS={margin:0,fontSize:12,color:"#94a3b8"},hS={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 yS(e,t){return t==="any"?!0:e===null||typeof e!="object"?!1:t==="object"?!Array.isArray(e):!0}function Hs({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(()=>Kr(e)),[v,y]=u.useState(null),_=u.useRef(!1),w=u.useRef(e);u.useEffect(()=>{if(!_.current&&!Object.is(e,w.current)){if(Kr(e)===Kr(w.current)){w.current=e;return}h(Kr(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(!yS($,r)){y(o(c??"layout_editor.json_block.invalid")),n?.(!1);return}const S=g?.($)??null;if(S){y(S),n?.(!1);return}y(null),w.current=$,n?.(!0),t($)};return i.jsxs("div",{className:"g7le-json-block",style:bS,children:[i.jsx("textarea",{id:b,"data-testid":d,style:{...mS,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:vS,children:v}):null]})}function Kr(e){if(e===void 0)return"";try{return JSON.stringify(e,null,2)??""}catch{return""}}const bS={display:"flex",flexDirection:"column",gap:4,minWidth:0},mS={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"},vS={fontSize:11,color:"#dc2626"},_S=[{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"}],Fs={local:"initLocal",global:"initGlobal",isolated:"initIsolated"};function xS({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(()=>K0({initLocal:e?.initLocal,state:s}),[e,s]),d=f=>{if(f==="local")return a;const b=e?.[Fs[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?.[Fs[f]]??{})},p=u.useCallback((f,b)=>{const g=Fs[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:kS,children:[i.jsx("p",{style:SS,children:o("layout_editor.page_settings.initstate.heading")}),l?i.jsxs("p",{"data-testid":"g7le-initstate-legacy-state",style:CS,children:["ⓘ ",o("layout_editor.initstate.legacy_state")]}):null,i.jsx(Ks,{scope:"local",label:o("layout_editor.initstate.section_local"),value:d("local"),ownKeys:c("local"),patchSection:p,t:o}),i.jsx(Ks,{scope:"global",label:o("layout_editor.initstate.section_global"),value:d("global"),ownKeys:c("global"),patchSection:p,t:o}),i.jsx(Ks,{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:KS,children:["ⓘ ",o("layout_editor.initstate.isolated_dynamic_hint")]})]})}function Ks({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(!Ds(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:$S,children:[i.jsxs("div",{style:ES,children:[i.jsx("div",{style:IS,children:t}),i.jsx("button",{type:"button","data-testid":`g7le-initstate-${e}-mode-toggle`,onClick:()=>h(x=>!x),style:TS,children:a(m?"layout_editor.json_block.mode_block":"layout_editor.json_block.mode_code")})]}),n?i.jsxs("p",{style:AS,children:["ⓘ ",n]}):null,m?i.jsx(Hs,{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(S=>!Ds(S));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:FS,children:a("layout_editor.initstate.no_values")}):v.map(x=>{const S=F0(y,r,x)==="inherited",C=e==="isolated"&&l[x];return i.jsx(wS,{scope:e,itemKey:x,value:o[x],inherited:S,isOrphan:!!C,onChangeValue:T=>_(x,T),onRemove:()=>w(x),t:a},x)}),i.jsxs("div",{style:PS,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:{...OS,...b?BS: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:jS,children:_S.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:HS,children:["+ ",a("layout_editor.initstate.add_value")]})]}),b?i.jsx("p",{"data-testid":`g7le-initstate-${e}-add-error`,style:WS,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:DS,children:[i.jsxs("div",{style:zS,children:[o?i.jsx("span",{"data-testid":`g7le-initstate-inherited-${t}`,style:NS,children:"🔗"}):null,i.jsx("code",{style:MS,children:t}),i.jsx("span",{style:{flex:1}}),i.jsx("button",{type:"button","data-testid":`g7le-initstate-code-${t}`,onClick:()=>c(f=>!f),style:Vs,"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:Vs,children:l("layout_editor.initstate.revert")}):i.jsx("button",{type:"button","data-testid":`g7le-initstate-remove-${t}`,onClick:a,style:Vs,"aria-label":l("layout_editor.init_actions.remove"),children:"✕"})]}),d?i.jsx("pre",{"data-testid":`g7le-initstate-code-block-${t}`,style:VS,children:p}):null,i.jsx(zn,{value:n,onChange:s,t:l,path:t,scope:e}),r?i.jsxs("p",{"data-testid":`g7le-initstate-isolated-orphan-${t}`,style:LS,children:["⚠ ",l("layout_editor.initstate.isolated_orphan")]}):null]})}const kS={display:"flex",flexDirection:"column",gap:14,minWidth:0},SS={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},CS={margin:0,fontSize:11,color:"#1d4ed8",background:"#eff6ff",padding:"6px 8px",borderRadius:6},$S={display:"flex",flexDirection:"column",gap:8,padding:10,border:"1px solid #e2e8f0",borderRadius:10,minWidth:0},ES={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},IS={fontSize:12,fontWeight:700,color:"#475569"},AS={margin:0,fontSize:11,color:"#94a3b8"},TS={padding:"2px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},DS={display:"flex",flexDirection:"column",gap:4,padding:"6px 8px",border:"1px solid #f1f5f9",borderRadius:6,minWidth:0},zS={display:"flex",alignItems:"center",gap:6},NS={fontSize:12},MS={fontSize:12,color:"#0f172a",fontFamily:"monospace"},Vs={border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",fontSize:11,padding:"2px 6px"},LS={margin:0,fontSize:11,color:"#b45309",background:"#fef3c7",padding:"4px 6px",borderRadius:6},PS={display:"flex",gap:6,alignItems:"center"},OS={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},BS={border:"1px solid #dc2626"},WS={margin:0,fontSize:11,color:"#dc2626"},jS={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#0f172a"},HS={padding:"2px 10px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},FS={margin:0,fontSize:12,color:"#94a3b8"},KS={margin:0,fontSize:11,color:"#94a3b8"},VS={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"},US={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 Us({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(US[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 qS(e){return[...e.filter(n=>n!=="maintenance"),"default"]}function GS({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(()=>ko(a),[a]),b=u.useMemo(()=>qS(o),[o]),g=f.length>0,m=u.useMemo(()=>Vl("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:fu,children:[i.jsx("p",{style:gu,children:n("layout_editor.page_settings.error.heading")}),i.jsxs("p",{style:XS,children:["ⓘ ",n("layout_editor.error.intro")]}),i.jsx(Us,{value:e,onChange:t,t:n,codes:b,mode:"badge",sourceOf:v,testIdPrefix:"g7le-error-rows",renderActionList:(y,_,w)=>i.jsx(YS,{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:fu,children:[i.jsx("p",{style:gu,children:n("layout_editor.page_settings.error.heading")}),i.jsxs("p",{"data-testid":"g7le-error-degrade",style:JS,children:["ⓘ ",n("layout_editor.error.degrade")]}),i.jsx(Us,{value:e,onChange:t,t:n,codes:b,mode:"badge",sourceOf:v,testIdPrefix:"g7le-error-rows"})]})}function YS({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?Yn(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(Sr(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:ZS,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:{...QS,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?RS:hu,children:"</>"}):null]}),m?i.jsx("div",{"data-testid":`g7le-error-actions-${e}`,children:i.jsx(Gt,{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(Ns,{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:eC,children:JSON.stringify(t,null,2)}):null]})}const fu={display:"flex",flexDirection:"column",gap:12,minWidth:0},gu={margin:0,fontSize:13,fontWeight:700,color:"#0f172a"},XS={margin:0,fontSize:11,color:"#94a3b8"},JS={margin:0,fontSize:12,color:"#b45309",background:"#fef3c7",padding:"8px 10px",borderRadius:6},ZS={display:"flex",flexDirection:"column",gap:6,minWidth:0},QS={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},hu={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"},RS={...hu,background:"#0f172a",borderColor:"#0f172a",color:"#e2e8f0"},eC={margin:"4px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:12,overflow:"auto",fontFamily:"ui-monospace, monospace"};function Vr(e){const t=e.trim(),n=/^\{\{([\s\S]*)\}\}$/.exec(t);return n?n[1].trim():t}function tC(e){let t=e;for(;t.length>=2&&t[0]==="("&&t[t.length-1]===")";){let n=0,o=!0;for(let r=0;r<t.length;r++)if(t[r]==="(")n++;else if(t[r]===")"&&(n--,n===0&&r<t.length-1)){o=!1;break}if(!o)break;t=t.slice(1,-1)}return t}function Ur(e){let t=e.replace(/\s+/g,"");for(t=t.replace(/\?\./g,".");t.startsWith("!!");)t=t.slice(2);return t=tC(t),t}function nC(e){if(!e||typeof e!="object")return[];const t=e.operators;if(Array.isArray(t))return t.filter(o=>!!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:Vr(o.expr),aliases:yu(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:Vr(s.expr),aliases:yu(s.aliases)})}return n}function yu(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(typeof n!="string")continue;const o=Vr(n);o.trim().length>0&&t.push(o)}return t}function oC(e){const t=e.params.length*1e3;return Ur(e.expr).replace(/\{\w+\}/g,"").length-t}function rC(e){return e.map((t,n)=>({op:t,idx:n,score:oC(t)})).sort((t,n)=>n.score-t.score||t.idx-n.idx).map(t=>t.op)}function iC(e,t){return e.replace(/\{(\w+)\}/g,(n,o)=>{const r=t[o];return r===void 0?n:r})}function sC(e,t){const n=t.find(o=>o.value===e.operator);return n?iC(n.expr,e.params??{}):null}function bu(e,t,n){const o=e.map(a=>sC(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 mu(e,t){const n=Ur(e);for(const o of rC(t)){if(o.params.length===0){for(const r of[o.expr,...o.aliases])if(Ur(r)===n)return{operator:o.value,params:{}};continue}for(const r of[o.expr,...o.aliases]){const s=aC(o,r,n);if(s)return s}}return null}function aC(e,t,n){const o=t.trim(),r=[];let s="",a=0;for(;a<o.length;){const f=/^\{(\w+)\}/.exec(o.slice(a));if(f)r.push(f[1]),s+="(.+?)",a+=f[0].length;else{let b="";for(;a<o.length&&!/^\{(\w+)\}/.test(o.slice(a));)b+=o[a],a+=1;const g=Ur(b);for(const m of g)s+=m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}const d=new RegExp("^"+s+"$").exec(n);if(!d)return null;const c={};for(let f=0;f<r.length;f++){const b=r[f],g=d[f+1];if(b in c&&c[b]!==g)return null;c[b]=g}const p=lC(o);for(const[f,b]of Object.entries(c))if(/&&|\|\|/.test(b)||!p.has(f)&&/===|!==|==|!=|>=|<=|>|<|\?|:|\(|\)|!/.test(b))return null;return{operator:e.value,params:c}}function lC(e){const t=new Set,n=/(['"])\{(\w+)\}\1/g;let o;for(;(o=n.exec(e))!==null;)t.add(o[2]);return t}function dC(e,t){if(typeof e!="string"||e.trim()==="")return null;const n=Vr(e),o=mu(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=mu(c.trim(),t);if(!p)return null;d.push(p)}return{clauses:d,combinator:r}}const vu=Lt(),Mn=vu.responsiveManager,Do=vu.BREAKPOINT_PRESETS;function _u(e){const t=e.groupPrefixes;return{group:typeof e.group=="string"?e.group: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 xu(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 qr(e){return typeof e!="string"?[]:e.split(/\s+/).filter(t=>t.length>0)}function wu(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(!Yt(s))return!1;const a=Xs(s);return n.has(a)?!0:o.some(l=>l.length>0&&a.startsWith(l))}return Yt(s)?!1:n.has(s)?!0:o.some(a=>a.length>0&&s.startsWith(a))}}function cC(e,t,n,o,r=!1){const s=wu(t,r),a=qr(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(Iu):l,c=[...a,...d];c.length===0?delete e.className:e.className=c.join(" ")}const qs={url:"backgroundImage",size:"backgroundSize",repeat:"backgroundRepeat",position:"backgroundPosition"};function uC(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.keys(qs).some(t=>t in e)}function pC(e){return/^url\(/i.test(e.trim())?e:`url(${e})`}function ku(e){const t=/^url\(\s*(['"]?)(.*?)\1\s*\)$/i.exec(e.trim());return t?t[2]:e}function fC(e){return e.includes("backgroundImage")}function Gs(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 gC(e){const t=e.backgroundImage,n=Gs(e.backgroundSize,"size"),o=Gs(e.backgroundRepeat,"repeat"),r=Gs(e.backgroundPosition,"position");let s;if(typeof t=="string"?s=ku(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"?ku(s):s),n!==void 0&&(a.size=n),o!==void 0&&(a.repeat=o),r!==void 0&&(a.position=r),a}function hC(e,t,n){const o=(r,s)=>{s==null||s===""?delete e[r]:e[r]=s};if(Array.isArray(t.props)){if(!t.values&&uC(n)){for(const r of t.props){const s=Object.keys(qs).find(d=>qs[d]===r);let a=s?n[s]:void 0;a!==null&&typeof a=="object"&&(a=void 0);const l=r==="backgroundImage"&&typeof a=="string"&&a!==""?pC(a):a;o(r,l)}return}for(const r of t.props){const s=t.values&&r in t.values?t.values[r]:n;o(r,s)}return}typeof t.prop=="string"&&o(t.prop,t.value!==void 0?t.value:n)}function yC(e,t,n){if(typeof t.varName!="string")return;const o=t.value!==void 0?t.value:n;o==null||o===""?delete e[t.varName]:e[t.varName]=o}function bC(e,t,n){if(typeof t.propKey!="string")return;const o=t.value!==void 0?t.value:n;o==null||o===""?delete e[t.propKey]:e[t.propKey]=o}function fn(e,t,n,o=Wt){const r=_u(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,p=(d?r.apply:a)?.type==="classToken"||(r.options?.some(b=>b.apply?.type==="classToken")??!1);if(s&&!p)return e;const f=o.breakpoint!=="base"&&p?(()=>{const b=e.props??{};return typeof b.className=="string"?b.className:void 0})():void 0;return Eu(e,o,(b,g)=>{if(f!==void 0&&typeof b.className!="string"&&(b.className=f),d){const m=wu(r,s),h=qr(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)switch(a.type){case"classToken":cC(b,r,a,n,s);break;case"styleProp":hC(g,a,n);break;case"cssVar":yC(g,a,n);break;case"propValue":bC(b,a,n);break}})}function Gr(e,t){const n=qr(e);return t?n.filter(Yt).map(Xs):n.filter(o=>!Yt(o))}function mC(e,t,n,o){const r=new Set(t.filter(l=>typeof l=="string"&&l.length>0)),s=l=>o?Yt(l)?r.has(Xs(l)):!1:Yt(l)?!1:r.has(l),a=qr(e).filter(l=>!s(l));return n&&n.length>0&&a.push(o?Iu(n):n),a.join(" ").trim()}function Su(e,t,n,o){if(e.options&&e.options.some(s=>s.apply)){const s=Gr(t.className,o),a=[];for(const l of e.options)l.apply&&_C(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)&&fC(r.props)){const l=gC(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}:{value:s,matched:!0}}case"classToken":{const s=Gr(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 Cu(e){return e.style&&typeof e.style=="object"&&!Array.isArray(e.style)?e.style:{}}function zo(e,t,n=Wt){const o=_u(t),r=n.colorScheme==="dark";if(r&&!Ys(o.apply)&&!o.options?.some(m=>Ys(m.apply)))return{value:void 0,matched:!1,darkReadonly:!0};const s=CC(e,n),a=Cu(s),l=Su(o,s,a,r);if(n.breakpoint==="base")return l;const d=l.matched?l.value:void 0,c=e.props??{},p=Cu(c),f=Su(o,c,p,r),b=l.matched&&l.value!==void 0,g=b&&!vC(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 vC(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 _C(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 Wt={colorScheme:"base",breakpoint:"base"},No="dark:";function xC(e){return e==="base"?!0:Mn.parseRange(e)!==null}function $u(e){return e in Do}function Yr(e,t,n){if(e==="custom"){if(typeof n=="number"){const o=t.responsive;if(o&&typeof o=="object"){const r=Mn.getMatchingKey(o,n);if(r)return r}}return"base"}return e}function wC(e){return!!e&&typeof e=="object"&&Array.isArray(e.children)}function kC(e,t,n){let o,r,s;if(e!=="custom"&&e in Do){o=e;const l=Do[e];r=l.min,s=l.max}else if(e!=="custom"){const l=Mn.parseRange(e);if(l)o=e,r=l.min,s=l.max;else{const d=typeof n=="number"?n:Mn.getWidth();o=`${d}-${d}`,r=d,s=d}}else{const l=typeof n=="number"?n:Mn.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(!wC(a[c]))continue;const p=Mn.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;f<d&&(d=f,l=c)}}}if(l)return{mode:"separate",key:o,sourceKey:l}}return{mode:"separate",key:o}}function SC(e){switch(e){case"mobile":case"portable":return{i18nKey:"layout_editor.overlay.branch_mobile",raw:e};case"tablet":return{i18nKey:"layout_editor.overlay.branch_tablet",raw:e};case"desktop":return{i18nKey:"layout_editor.overlay.branch_desktop",raw:e};default:return{i18nKey:null,raw:e}}}function CC(e,t){return t.breakpoint==="base"?e.props??{}:e.responsive?.[t.breakpoint]?.props??{}}function Eu(e,t,n){if(t.breakpoint==="base"){const{props:c,style:p}=xu(e.props);return n(c,p),Object.keys(p).length===0&&delete c.style,{...e,props:c}}const o=t.breakpoint,r={...e.responsive??{}},s={...r[o]??{}},{props:a,style:l}=xu(s.props);n(a,l),Object.keys(l).length===0&&delete a.style,Object.keys(a).length===0?delete s.props:s.props=a,Object.keys(s).length===0?delete r[o]:r[o]=s;const d={...e};return Object.keys(r).length===0?delete d.responsive:d.responsive=r,d}function $C(e,t){if(t.breakpoint==="base")return e.if;const n=e.responsive?.[t.breakpoint];return n&&typeof n=="object"&&"if"in n?n.if:e.if}function EC(e,t,n){const o=n==null||n==="";if(t.breakpoint==="base"){const d={...e};return o?delete d.if:d.if=n,d}const r=t.breakpoint,s={...e.responsive??{}},a={...s[r]??{}};o?delete a.if:a.if=n,Object.keys(a).length===0?delete s[r]:s[r]=a;const l={...e};return Object.keys(s).length===0?delete l.responsive:l.responsive=s,l}function Ys(e){return e?.type==="classToken"}function Yt(e){return e.startsWith(No)}function Xs(e){return e.startsWith(No)?e.slice(No.length):e}function Iu(e){return e.startsWith(No)?e:`${No}${e}`}function Xr(e){return typeof e=="string"?e.split(/\s+/).filter(t=>t.length>0):[]}function IC(e,t){if(t.colorScheme==="dark")return Eu(e,t,l=>{const d=Xr(l.className).filter(c=>!Yt(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 Js(e,t){if(t.colorScheme==="dark"){const c=t.breakpoint==="base"?e.props:e.responsive?.[t.breakpoint]?.props;return Xr(c?.className).some(Yt)}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(Xr(e.props?.className).filter(c=>!Yt(c))),d=Xr(r.className).filter(c=>!Yt(c));return d.length!==l.size?!0:d.some(c=>!l.has(c))}function Au(e,t,n=""){return typeof e!="string"?n:e.startsWith("$t:")?t(e.slice(3)):e}function Tu(e,t,n){if(n.breakpoint!=="base")return EC(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 Du({node:e,spec:t,t:n,onPatchNode:o,dataSourceCandidates:r,stateKeyCandidates:s,scope:a=Wt}){const l=u.useMemo(()=>nC(t?.conditionRecipes),[t]),d=a.breakpoint!=="base"?$C(e,a):e.if??e.props?.if,c=u.useMemo(()=>dC(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:AC,children:n("layout_editor.visibility.no_recipes")});const g=(w,k)=>{o(Tu(e,bu(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:BC,children:n("layout_editor.visibility.advanced_preserved")}),i.jsx("code",{"data-testid":"g7le-condition-advanced-expr",style:Nu,children:String(d)}),i.jsx("button",{type:"button","data-testid":"g7le-condition-clear-advanced",onClick:()=>o(Tu(e,"",a)),style:WC,children:n("layout_editor.visibility.clear")})]});const _=bu(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:TC,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:DC,children:[i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[k>0&&i.jsx("span",{"data-testid":`g7le-condition-combinator-${k}`,style:NC,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:zC,children:l.map($=>i.jsx("option",{value:$.value,children:Au($.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:MC,children:"✕"})]}),x.params.map($=>{const S=Tn($.widget);return i.jsxs("div",{className:"g7le-condition-param","data-testid":`g7le-condition-param-${k}-${$.key}`,style:LC,children:[i.jsx("span",{style:PC,children:Au($.label,n,$.key)}),i.jsx("div",{style:{flex:1},children:S?i.jsx(S,{control:{...$},value:w.params[$.key],onChange:C=>m(k,{operator:w.operator,params:{...w.params,[$.key]:C===void 0?"":String(C)}}),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:zu,children:["+ ",n("layout_editor.visibility.and")]}),i.jsxs("button",{type:"button","data-testid":"g7le-condition-add-or",onClick:()=>v("or"),style:zu,children:["+ ",n("layout_editor.visibility.or")]})]}),_!==""&&i.jsxs("div",{"data-testid":"g7le-condition-preview",style:OC,children:[i.jsx("span",{style:{fontSize:11,color:"#64748b"},children:n("layout_editor.visibility.preview")}),i.jsx("code",{style:Nu,children:_})]})]})}const AC={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},TC={fontSize:12,fontWeight:600,color:"#0f172a"},DC={border:"1px solid #e2e8f0",borderRadius:8,padding:10,display:"flex",flexDirection:"column",gap:8,background:"#f8fafc"},zC={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff"},NC={fontSize:11,fontWeight:700,color:"#2563eb",background:"#dbeafe",padding:"2px 8px",borderRadius:999},MC={border:"none",background:"transparent",color:"#94a3b8",cursor:"pointer",fontSize:12},zu={padding:"5px 12px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},LC={display:"flex",alignItems:"center",gap:8},PC={fontSize:11,color:"#64748b",minWidth:64},OC={display:"flex",flexDirection:"column",gap:4,padding:10,background:"#f1f5f9",borderRadius:6},Nu={fontSize:11,color:"#0f172a",fontFamily:"monospace",wordBreak:"break-all"},BC={fontSize:11,color:"#92400e",background:"#fef3c7",padding:"6px 8px",borderRadius:6},WC={padding:"5px 12px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer",alignSelf:"flex-start"};function jC(e){return typeof e=="string"?e:e===void 0?"":JSON.stringify(e)}function HC(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 Mu(e){return!e||typeof e!="object"||Array.isArray(e)?[]:Object.entries(e).map(([t,n])=>({key:t,value:jC(n)}))}function Zs(e){const t={};for(const n of e){const o=n.key.trim();o!==""&&(t[o]=HC(n.value))}return t}function Lu(e){return!e||typeof e!="object"||Array.isArray(e)?!1:Object.values(e).some(t=>t!==null&&typeof t=="object")}function FC(e){const t={};return typeof e.if=="string"&&e.if.trim().length>0&&(t.if=e.if),t}function KC(e,t){const n={...t},o=e.if;return typeof o=="string"&&o.trim().length>0?n.if=o:delete n.if,n}const VC=["api","static","route_params","query_params","websocket"],UC=["GET","POST","PUT","PATCH","DELETE"],qC=["none","optional","required"],GC=["progressive","blocking","background"],YC=["application/json","multipart/form-data"],XC=["public","private","presence"];function JC(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 ZC(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:Mu(e.params),paramsRaw:Lu(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 QC(){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 RC(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=Zs(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 jt={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},rn={padding:"6px 12px",fontSize:13,fontWeight:500,borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#0f172a",cursor:"pointer"},Pu={...rn,background:"#2563eb",borderColor:"#2563eb",color:"#ffffff",fontWeight:600},Mo={marginTop:12,padding:10,border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc"},Lo={fontSize:12,fontWeight:700,color:"#475569",marginBottom:8},e$={margin:"0 0 6px",fontSize:11,color:"#94a3b8"},Ou={marginTop:8},Bu={alignSelf:"flex-start",padding:"2px 0",fontSize:11,border:"none",background:"none",color:"#64748b",cursor:"pointer"},Wu={margin:0,padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:11,lineHeight:1.5,overflow:"auto",fontFamily:"ui-monospace, monospace"};function t$({code:e,action:t,recipes:n,pools:o,t:r,onPatch:s}){const[a,l]=u.useState(!1),d=u.useMemo(()=>ko(n),[n]),c=Array.isArray(t)?t[0]:t,p=typeof c?.handler=="string"?c.handler:"",f=d.find(_=>_.id===p)??null,b=c?Yn(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?Sr(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:{...jt,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?n$:ju,children:"</>"}):null]}),m?i.jsx("div",{"data-testid":`g7le-ds-eh-actions-${e}`,children:i.jsx(Gt,{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(Ns,{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:o$,children:JSON.stringify(t,null,2)}):null]})}const ju={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"},n$={...ju,background:"#0f172a",borderColor:"#0f172a",color:"#e2e8f0"},o$={margin:"4px 0 0",padding:8,background:"#0f172a",color:"#e2e8f0",borderRadius:6,fontSize:12,overflow:"auto",fontFamily:"ui-monospace, monospace"};function r$({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(()=>JC(e),[e]),m=g.inherited,[h,v]=u.useState(g.own),[y,_]=u.useState(null),[w,k]=u.useState(null),[x,$]=u.useState(!1),[S,C]=u.useState(!1),[T,E]=u.useState(()=>new Set),A=u.useCallback(I=>{E(L=>{const F=new Set(L);return F.has(I)?F.delete(I):F.add(I),F})},[]),N=u.useMemo(()=>({pageCandidates:c,dataSourceCandidates:p,stateKeyCandidates:f,bindingCandidates:d}),[c,p,f,d]),D=u.useCallback(I=>{v(I),t([...m,...I],I)},[m,t]),B=u.useCallback(()=>{k(null),_(QC())},[]),M=u.useCallback((I,L)=>{k(null),_(ZC(I,L))},[]),O=u.useCallback(I=>{const L=h.filter((F,Y)=>Y!==I);D(L)},[h,D]),z=u.useCallback(()=>{_(null),k(null)},[]),H=u.useCallback(()=>{if(!y)return;const I=new Set;h.forEach((K,X)=>{X!==y.index&&typeof K.id=="string"&&I.add(K.id)}),m.forEach(K=>{typeof K.id=="string"&&I.add(K.id)});const L=y.index>=0?h[y.index]??null:null,F=RC(y,L,I,n);if("error"in F){k(F.error);return}const Y=y.index>=0?h.map((K,X)=>X===y.index?F.entry:K):[...h,F.entry];D(Y),_(null),k(null)},[y,h,m,D,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:{...rn,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:jt,value:y.id,onChange:I=>_({...y,id:I.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:I=>_({...y,label_key:I??""}),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:jt,value:y.type,onChange:I=>_({...y,type:I.target.value}),children:VC.map(I=>i.jsx("option",{value:I,children:n(`layout_editor.data_sources.ds_type.${I}`)},I))})]}),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:I=>_({...y,endpoint:I}),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:jt,value:y.method,onChange:I=>_({...y,method:I.target.value}),children:UC.map(I=>i.jsx("option",{value:I,children:I},I))})]}),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:jt,value:y.auth_mode,onChange:I=>_({...y,auth_mode:I.target.value}),children:qC.map(I=>i.jsx("option",{value:I,children:n(`layout_editor.data_sources.auth_mode.${I}`)},I))})]})]}),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:jt,value:y.loading_strategy,onChange:I=>_({...y,loading_strategy:I.target.value}),children:GC.map(I=>i.jsx("option",{value:I,children:n(`layout_editor.data_sources.loading_strategy.${I}`)},I))})]}),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:jt,value:y.contentType||"application/json",onChange:I=>_({...y,contentType:I.target.value}),children:YC.map(I=>i.jsx("option",{value:I,children:I},I))})]})]}),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:I=>_({...y,auto_fetch:I.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:I=>_({...y,refetchOnMount:I.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 I=y.paramsRawValue;I&&typeof I=="object"&&!Array.isArray(I)&&!Lu(I)&&_({...y,paramsRaw:!1,paramRows:Mu(I)})}}else{const I=Zs(y.paramRows);_({...y,paramsRaw:!0,paramsRawValue:I,paramsRawValid:!0})}},style:{...rn,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(Hs,{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:I=>_(L=>L&&{...L,paramsRawValue:I??{},paramsRawValid:!0}),onValidityChange:I=>_(L=>L&&{...L,paramsRawValid:I})}):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:e$,children:n("layout_editor.data_sources.field.params_empty")}),i.jsx(Pr,{value:y.paramRows.map(I=>({key:I.key,value:I.value})),onChange:I=>_({...y,paramRows:I.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 I=Zs(y.paramRows);return Object.keys(I).length===0?null:i.jsxs("div",{style:Ou,children:[i.jsxs("button",{type:"button","data-testid":"g7le-ds-params-preview-toggle","aria-expanded":x,onClick:()=>$(L=>!L),style:Bu,children:[x?"▴":"▾"," ",n("layout_editor.data_sources.field.params_preview")]}),x&&i.jsx("pre",{"data-testid":"g7le-ds-params-preview",style:{...Wu,marginTop:4},children:JSON.stringify(I,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(zn,{value:y.fallbackValue===void 0?{}:y.fallbackValue,onChange:I=>_({...y,fallbackValue:I}),t:n,path:"fallback",scope:"ds-fallback",renderStringLeaf:I=>i.jsx(Ke,{value:I.value,onChange:I.onChange,t:n,candidates:d,testidPrefix:I.testidPrefix})}),(()=>{const I=y.fallbackValue===void 0?{}:y.fallbackValue;return i.jsxs("div",{style:Ou,children:[i.jsxs("button",{type:"button","data-testid":"g7le-ds-fallback-preview-toggle","aria-expanded":S,onClick:()=>C(L=>!L),style:Bu,children:[S?"▴":"▾"," ",n("layout_editor.data_sources.field.fallback_preview")]}),S&&i.jsx("pre",{"data-testid":"g7le-ds-fallback-preview",style:{...Wu,marginTop:4},children:JSON.stringify(I,null,2)})]})})(),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-field-fallback-clear",onClick:()=>_({...y,fallbackEnabled:!1,fallbackValue:void 0}),style:{...rn,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:{...rn,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:Mo,children:[i.jsx("div",{style:Lo,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:jt,value:y.channel,onChange:I=>_({...y,channel:I.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:jt,value:y.event,onChange:I=>_({...y,event:I.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:jt,value:y.channel_type,onChange:I=>_({...y,channel_type:I.target.value}),children:XC.map(I=>i.jsx("option",{value:I,children:I},I))})]}),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:jt,value:y.target_source,onChange:I=>_({...y,target_source:I.target.value}),list:"g7le-ds-ws-target-list"}),i.jsx("datalist",{id:"g7le-ds-ws-target-list",children:h.filter(I=>I.id!==y.id).map(I=>typeof I.id=="string"?i.jsx("option",{value:I.id},I.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(Gt,{actions:y.onReceive,onChange:I=>_({...y,onReceive:I}),t:n,recipes:s,candidatePools:N,chipContext:"payload",actionChipCandidates:l?.actionChipCandidates??null,testIdPrefix:"g7le-ds-onreceive-list"})})]})]}),i.jsxs("div",{style:Mo,children:[i.jsx("div",{style:Lo,children:n("layout_editor.data_sources.section.on_success")}),i.jsx("div",{"data-testid":"g7le-ds-onsuccess",children:i.jsx(Gt,{actions:y.onSuccess,onChange:I=>_({...y,onSuccess:I}),t:n,recipes:s,candidatePools:N,chipContext:"response",actionChipCandidates:l?.actionChipCandidates??null,testIdPrefix:"g7le-ds-onsuccess-list"})})]}),i.jsxs("div",{style:Mo,children:[i.jsx("div",{style:Lo,children:n("layout_editor.data_sources.section.on_error")}),i.jsx("div",{"data-testid":"g7le-ds-onerror",children:i.jsx(Gt,{actions:y.onError,onChange:I=>_({...y,onError:I}),t:n,recipes:s,candidatePools:N,chipContext:"error",actionChipCandidates:l?.actionChipCandidates??null,testIdPrefix:"g7le-ds-onerror-list"})})]}),i.jsxs("div",{style:Mo,children:[i.jsx("div",{style:Lo,children:n("layout_editor.data_sources.section.error_handling")}),i.jsxs("div",{"data-testid":"g7le-ds-errorhandling",children:[i.jsx(Us,{value:y.errorHandling,onChange:I=>_({...y,errorHandling:I}),t:n,mode:"local",testIdPrefix:"g7le-ds-eh",renderActionList:(I,L,F)=>i.jsx(t$,{code:I,action:L,recipes:a,pools:N,t:n,onPatch:F})}),i.jsxs("button",{type:"button","data-testid":"g7le-ds-errorhandling-add",onClick:()=>{const I=Object.keys(y.errorHandling),L=["403","404","500","422","default"].find(F=>!I.includes(F))??"default";_({...y,errorHandling:{...y.errorHandling,[L]:{handler:"toast"}}})},style:{...rn,padding:"4px 10px",marginTop:6},children:["+ ",n("layout_editor.data_sources.add_error_code")]})]})]}),i.jsxs("div",{style:Mo,children:[i.jsx("div",{style:Lo,children:n("layout_editor.data_sources.section.load_condition")}),i.jsx("div",{"data-testid":"g7le-ds-loadcondition",children:i.jsx(Du,{node:FC({if:y.if||void 0}),spec:l??null,t:n,dataSourceCandidates:p,stateKeyCandidates:f,onPatchNode:I=>{const L=KC(I,{});_({...y,if:typeof L.if=="string"?L.if:""})}})})]})]}),!y&&i.jsxs("button",{type:"button","data-testid":"g7le-data-sources-add",onClick:B,style:{...Pu,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((I,L)=>{const F=typeof I.id=="string"?I.id:`#${L}`,Y=typeof I.endpoint=="string"?I.endpoint:"",K=typeof I.label_key=="string"?I.label_key:"",X=as(I,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=ls(I,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}),!K&&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(I,L),style:{...rn,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:{...rn,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((I,L)=>{const F=typeof I.id=="string"?I.id:`#${L}`,Y=T.has(F),K=[],X=(Z,ae)=>{const oe=I[Z];oe!=null&&K.push([ae,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:()=>A(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=as(I,b),ae=ls(I,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}),ae&&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:ae})]})})()]}),Y&&i.jsxs("div",{"data-testid":"g7le-data-sources-inherited-info",style:{padding:"0 12px 10px 32px",display:"flex",flexDirection:"column",gap:3},children:[K.length===0&&i.jsx("span",{style:{color:"#94a3b8"},children:"—"}),K.map(([Z,ae])=>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:ae})]},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:rn,children:n("layout_editor.data_sources.form.cancel")}),i.jsx("button",{type:"button","data-testid":"g7le-data-sources-form-submit",onClick:H,style:Pu,children:n("layout_editor.data_sources.form.save")})]})]})]})}function i$(e){const t=e?.globalHeaders;return Array.isArray(t)?t:[]}function s$(e){const t=e?.scripts;return Array.isArray(t)?t:[]}function a$(e){const t=i$(e.raw),n=s$(e.raw);return i.jsxs("div",{className:"g7le-data-source-tab","data-testid":"g7le-data-source-tab",style:l$,children:[i.jsx(r$,{...e}),i.jsxs("div",{style:Hu,"data-testid":"g7le-global-headers",children:[i.jsx("div",{style:Fu,children:e.t("layout_editor.data_sources.global_headers")}),t.length===0?i.jsx("p",{"data-testid":"g7le-global-header-empty",style:Gu,children:e.t("layout_editor.data_sources.global_headers_empty")}):t.map((o,r)=>i.jsxs("div",{"data-testid":`g7le-global-header-${r}`,style:Ku,children:[i.jsx("code",{style:Vu,children:o.pattern??"*"}),i.jsx("span",{style:d$,children:"→"}),i.jsx("span",{style:Uu,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:Hu,"data-testid":"g7le-scripts",children:[i.jsx("div",{style:Fu,children:e.t("layout_editor.data_sources.scripts")}),n.length===0?i.jsx("p",{"data-testid":"g7le-script-empty",style:Gu,children:e.t("layout_editor.data_sources.scripts_empty")}):n.map((o,r)=>i.jsxs("div",{"data-testid":`g7le-script-${o.id??r}`,style:Ku,children:[i.jsx("code",{style:Vu,children:o.id??`#${r}`}),i.jsx("span",{style:Uu,children:o.src??""}),o.loading?i.jsx("span",{style:c$,children:o.loading}):null]},o.id??r)),i.jsxs("p",{style:qu,children:["ⓘ ",e.t("layout_editor.data_sources.scripts_hint")]})]})]})}const l$={display:"flex",flexDirection:"column",gap:16,minWidth:0},Hu={borderTop:"1px solid #e2e8f0",paddingTop:12,display:"flex",flexDirection:"column",gap:6},Fu={fontSize:12,fontWeight:700,color:"#475569"},Ku={display:"flex",alignItems:"center",gap:8,fontSize:12,padding:"4px 8px",border:"1px solid #f1f5f9",borderRadius:6},Vu={fontSize:11,color:"#0f172a",fontFamily:"monospace"},d$={color:"#94a3b8"},Uu={flex:1,minWidth:0,color:"#475569",wordBreak:"break-all"},c$={fontSize:10,color:"#64748b",background:"#f1f5f9",borderRadius:4,padding:"0 4px"},qu={margin:0,fontSize:11,color:"#94a3b8"},Gu={margin:0,fontSize:12,color:"#94a3b8"},u$=["meta","seo","init","overlay","computed","state","error","data"],p$=["401","403","404","500","503"],f$={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 g$(e){if(typeof fetch!="function"||!e)return[];try{const t=await fetch(en(`/api/admin/templates/${encodeURIComponent(e)}/editor/seo-candidates`,"json"),{credentials:"same-origin",headers:Ne()});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 h$(e,t){let n=0;for(const o of e)Yn(o,t).kind==="advanced"&&(n+=1);return n}function y$(e,t){let n=0;for(const o of Object.keys(e))Dd(e[o],t).kind==="advanced"&&(n+=1);return n}function b$(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}=jm(),[b,g]=u.useState(a),m=d.selectedRoute?.path??"",h=u.useMemo(()=>Od(d.routeTree,o),[d.routeTree,o]),v=u.useMemo(()=>Bd(c),[c]),y=u.useMemo(()=>Wd(t),[t]),_=u.useMemo(()=>iv(c,o),[c,o]),w=Pd({raw:c,spec:t}),k=u.useMemo(()=>lb(t),[t]),x=u.useMemo(()=>db(t),[t]),$=u.useMemo(()=>cb(t),[t]),S=u.useMemo(()=>ub(t),[t]),C=u.useMemo(()=>ko(k),[k]),T=u.useMemo(()=>Cd(x),[x]),E=p("init_actions",void 0)??p("initActions",[]),A=p("computed",{}),N=p("__computedSource",{}),D=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??{},ge={};for(const[V,te]of Object.entries(G))V in ee||(ge[V]=te);return Object.keys(ge).length>0?ge:void 0},[B,O]),[H,P]=u.useState([]);u.useEffect(()=>{let G=!1;const ee=l??g$;return(async()=>{const ge=await ee(e);G||P(ge)})(),()=>{G=!0}},[e,l]);const I=(p("meta",{})??{}).seo?.page_type,L=ov({raw:c,spec:t,pageType:typeof I=="string"?I:null}),F=u.useMemo(()=>nv(c,t),[c,t]),Y=u.useMemo(()=>({meta:0,seo:0,init:h$(E,C),overlay:0,computed:y$(A,T),state:0,error:0,data:0}),[E,C,A,T]),K=u.useMemo(()=>Object.values(Y).reduce((G,ee)=>G+ee,0),[Y]),X=u.useMemo(()=>rv(c,o,n),[c,o,n]),Z=u.useCallback(G=>{const ge={...M?.computed??{}};delete ge[G];const V={...A};delete V[G],f("computed",V,Object.keys(ge).length===0?void 0:ge)},[M,A,f]),ae=b$(p,m,n),oe=()=>{switch(b){case"meta":return i.jsx(kx,{getValue:p,patch:f,t:n,fieldT:o,spec:t,permissionCandidates:r,bindingCandidates:w});case"seo":return i.jsx(d0,{getValue:p,patch:f,t:n,templateIdentifier:e,candidates:L,availableExtensions:H,dataSourceOptions:X,previewUrl:m||"/",seedContext:F});case"init":return i.jsx(Ak,{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(Qk,{value:B,ownValue:O,baseValue:z,patch:G=>f("transition_overlay",G),t:o,loadingComponents:S,progressiveDataSources:X,bindingCandidates:w});case"computed":return i.jsx(j1,{computed:A,onChange:G=>f("computed",G),recipes:x,t:o,sampleContext:F,dataSourceCandidates:v,bindingCandidates:w,computedSource:N,onRevert:Z});case"state":return i.jsx(xS,{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(GS,{value:D,onChange:G=>f("errorHandling",G),t:o,errorConfigCodes:p$,templateCodes:Object.keys(D),ownCodes:Object.keys(M?.errorHandling??{}),recipes:$,pageCandidates:h,modalCandidates:_,dataSourceCandidates:v,stateKeyCandidates:y});case"data":return i.jsx(a$,{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:v$,children:[i.jsxs("div",{style:_$,children:[i.jsx("span",{"data-testid":"g7le-page-settings-title",style:x$,children:n("layout_editor.page_settings.title",{name:ae})}),i.jsx("button",{type:"button","data-testid":"g7le-page-settings-close-x",onClick:s,"aria-label":n("layout_editor.page_settings.close"),style:w$,children:"✕"})]}),i.jsx("div",{role:"tablist",style:k$,children:u$.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?S$:Yu,children:[n(f$[G]),ee>0?i.jsxs("span",{"data-testid":`g7le-page-settings-tab-badge-${G}`,style:C$,children:["(",ee,")"]}):null]},G)})}),K>0?i.jsxs("p",{"data-testid":"g7le-page-settings-advanced-summary",style:$$,children:["⚠ ",n("layout_editor.page_settings.advanced_summary",{count:K})," ⓘ"]}):null,i.jsx("div",{"data-testid":"g7le-page-settings-panel",style:E$,children:oe()}),i.jsx("div",{style:I$,children:i.jsx("button",{type:"button","data-testid":"g7le-page-settings-close",onClick:s,style:A$,children:n("layout_editor.page_settings.close")})})]})}const v$={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"},_$={display:"flex",alignItems:"center",gap:8,paddingBottom:8,borderBottom:"1px solid #e2e8f0"},x$={flex:1,fontSize:15,fontWeight:700,color:"#0f172a",minWidth:0},w$={border:"none",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:16,lineHeight:1,padding:4},k$={display:"flex",gap:2,paddingTop:8,borderBottom:"1px solid #e2e8f0",flexWrap:"nowrap",overflowX:"auto",overflowY:"hidden",flexShrink:0,minWidth:0},Yu={border:"none",borderBottomWidth:"2px",borderBottomStyle:"solid",borderBottomColor:"transparent",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:12,padding:"6px 10px",whiteSpace:"nowrap"},S$={...Yu,color:"#2563eb",borderBottomColor:"#2563eb",fontWeight:600},C$={marginLeft:4,fontSize:10,color:"#b45309"},$$={margin:0,marginTop:8,fontSize:11,color:"#b45309",background:"#fffbeb",padding:"6px 8px",borderRadius:6},E$={flex:1,overflowY:"auto",paddingTop:12,minWidth:0,minHeight:0},I$={display:"flex",justifyContent:"flex-end",paddingTop:8,borderTop:"1px solid #e2e8f0"},A$={border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",fontSize:13,padding:"6px 16px"};function Qs(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 Xu=100,Ju=500;function T$(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(Xu),[h,v]=u.useState(!1),y=u.useCallback(async($,S)=>{if(!t){r([]),p(null),v(!1);return}S==="more"?d(!0):a(!0),p(null);try{const C=`${Qs(e,t)}?limit=${$}`,T=await fetch(C,{credentials:"same-origin",headers:Ne()}),E=await T.json().catch(()=>null);if(!T.ok){p(E?.message??`HTTP ${T.status}`),S==="reload"&&r([]);return}const A=E?.data,N=Array.isArray(A)?A:[];r(N),v(N.length>=$&&$<Ju),m($)}catch(C){p(C instanceof Error?C.message:"network error"),S==="reload"&&r([])}finally{S==="more"?d(!1):a(!1)}},[e,t]),_=u.useCallback(async()=>{await y(g,"reload")},[y,g]),w=u.useCallback(async()=>{const $=Math.min(g+Xu,Ju);if($<=g){v(!1);return}await y($,"more")},[y,g]),k=u.useCallback(async $=>{if(!t)return{kind:"not_found"};b($);try{const S=`${Qs(e,t)}/${$}/restore`,C=await fetch(S,{method:"POST",credentials:"same-origin",headers:Ne({"Content-Type":"application/json"})}),T=await C.json().catch(()=>null);if(C.status===404)return{kind:"not_found"};if(!C.ok)return{kind:"network_error",message:T?.message??`HTTP ${C.status}`};const E=typeof T?.data?.version=="number"?T.data.version:-1;return await n?.(E>=0?E:void 0),{kind:"success",newVersion:E}}catch(S){return{kind:"network_error",message:S instanceof Error?S.message:"network error"}}finally{b(null)}},[e,t,n]),x=u.useCallback(async $=>{if(!t)return{kind:"not_found"};try{const S=`${Qs(e,t)}/${$}`,C=await fetch(S,{credentials:"same-origin",headers:Ne()}),T=await C.json().catch(()=>null);if(C.status===404)return{kind:"not_found"};if(!C.ok)return{kind:"network_error",message:T?.message??`HTTP ${C.status}`};const E=T?.data;if(!E)return{kind:"not_found"};if(t.kind==="extension"&&!E.full_content){const A=E.content;if(typeof A=="string")try{const N=JSON.parse(A);N&&typeof N=="object"&&(E.full_content=N)}catch{}}return{kind:"success",detail:E}}catch(S){return{kind:"network_error",message:S instanceof Error?S.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 D$(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 z$(e,t,n){const o=[];let r=0,s=0;const a=e.length,l=t.length;for(;r<a&&s<l;)e[r]===t[s]?(o.push({kind:"context",oldIndex:r,newIndex:s,content:e[r]}),r++,s++):n[r+1][s]>=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(;r<a;)o.push({kind:"remove",oldIndex:r,content:e[r]}),r++;for(;s<l;)o.push({kind:"add",newIndex:s,content:t[s]}),s++;return o}function Zu(e){const t=e.replace(/\r\n/g,`
|
||
`).split(`
|
||
`);return t.length>0&&t[t.length-1]===""&&t.pop(),t}const Qu=4e3;function N$(e,t,n=3){const o=Zu(e),r=Zu(t);let s=0;const a=Math.min(o.length,r.length);for(;s<a&&o[s]===r[s];)s++;let l=0;const d=Math.min(o.length,r.length)-s;for(;l<d&&o[o.length-1-l]===r[r.length-1-l];)l++;const c=o.slice(s,o.length-l),p=r.slice(s,r.length-l);if(c.length>Qu||p.length>Qu)return{hunks:[],addedCount:-1,removedCount:-1,identical:!1};const f=D$(c,p),b=z$(c,p,f),g=[];let m=s,h=s,v=0,y=0;for(let k=0;k<s;k++)g.push({kind:"context",oldLine:k+1,newLine:k+1,content:o[k]});for(const k of b)k.kind==="context"?(m++,h++,g.push({kind:"context",oldLine:m,newLine:h,content:k.content})):k.kind==="remove"?(m++,y++,g.push({kind:"remove",oldLine:m,newLine:null,content:k.content})):(h++,v++,g.push({kind:"add",oldLine:null,newLine:h,content:k.content}));for(let k=0;k<l;k++){const x=o.length-l+k,$=r.length-l+k;g.push({kind:"context",oldLine:x+1,newLine:$+1,content:o[x]})}const _=v===0&&y===0;return{hunks:M$(g,n),addedCount:v,removedCount:y,identical:_}}function M$(e,t){const n=[];for(let r=0;r<e.length;r++)e[r].kind!=="context"&&n.push(r);if(n.length===0)return[];const o=[];for(const r of n){const s=Math.max(0,r-t),a=Math.min(e.length-1,r+t),l=o[o.length-1];l&&s<=l.end+1?l.end=Math.max(l.end,a):o.push({start:s,end:a})}return o.map(r=>{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 Ru(e){return JSON.stringify(Rs(e),null,2)}function Rs(e){if(Array.isArray(e))return e.map(Rs);if(e&&typeof e=="object"){const t=e,n={};for(const o of Object.keys(t).sort())n[o]=Rs(t[o]);return n}return e}const L$={display:"flex",flexDirection:"column",height:"100%",minHeight:0},P$={display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc"},O$={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"},B$={marginLeft:"auto",border:"none",background:"transparent",fontSize:16,color:"#64748b",cursor:"pointer",outline:"none"},W$={display:"flex",alignItems:"center",gap:12,padding:"8px 16px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",fontSize:12,fontWeight:600},j$={flex:1,minHeight:0,overflow:"auto",background:"#ffffff",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:12,lineHeight:1.5},ep={padding:"24px 12px",textAlign:"center",color:"#94a3b8",fontSize:13},H$={padding:"2px 12px",background:"#f1f5f9",color:"#64748b",borderTop:"1px solid #e2e8f0",borderBottom:"1px solid #e2e8f0",userSelect:"none"};function F$(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 tp={display:"inline-block",width:44,textAlign:"right",padding:"0 6px",color:"#94a3b8",userSelect:"none",borderRight:"1px solid #e2e8f0",whiteSpace:"nowrap"};function K$({oldVersion:e,newVersion:t,oldContent:n,newContent:o,t:r,onBack:s,onClose:a}){const l=u.useMemo(()=>{const c=Ru(n),p=Ru(o);return N$(c,p)},[n,o]),d=l.addedCount<0;return i.jsxs("div",{className:"g7le-version-diff","data-testid":"g7le-version-diff",style:L$,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:P$,children:[i.jsxs("button",{type:"button",onClick:s,style:O$,"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:B$,"data-testid":"g7le-version-diff-close",children:"✕"})]}),!d&&i.jsxs("div",{style:W$,"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:j$,children:d?i.jsx("div",{style:ep,"data-testid":"g7le-version-diff-too-large",children:r("layout_editor.version_history.diff_too_large")}):l.identical?i.jsx("div",{style:ep,"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:H$,"data-testid":`g7le-version-diff-hunk-header-${p}`,children:c.header}),c.lines.map((f,b)=>{const g=F$(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:{...tp,...g.gutter},"aria-hidden":"true",children:f.oldLine??""}),i.jsx("span",{style:{...tp,...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 V$={display:"flex",flexDirection:"column",height:"100%",minHeight:0},U$={display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc"},q$={marginLeft:"auto",border:"none",background:"transparent",fontSize:16,color:"#64748b",cursor:"pointer",outline:"none"},G$={flex:1,minHeight:0,overflowY:"auto",padding:12},np={padding:"24px 12px",textAlign:"center",color:"#94a3b8",fontSize:13},Y$={margin:"8px 16px 0",padding:"8px 12px",borderRadius:6,background:"#fef2f2",color:"#b91c1c",fontSize:12,border:"1px solid #fecaca"},X$={display:"flex",flexDirection:"column",gap:8},J$={display:"flex",alignItems:"center",gap:12,padding:"10px 12px",borderRadius:8,border:"1px solid #e2e8f0",background:"#ffffff"},Z$={display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:44,padding:"2px 8px",borderRadius:999,background:"#eff6ff",color:"#1d4ed8",fontSize:12,fontWeight:700},Q$={display:"inline-flex",alignItems:"center",padding:"1px 8px",borderRadius:999,background:"#0f172a",color:"#ffffff",fontSize:10,fontWeight:700,letterSpacing:.3},R$={display:"flex",alignItems:"center",gap:10,fontSize:11,fontWeight:600},eE={display:"flex",flexDirection:"column",gap:2,minWidth:0,flex:1},op={padding:"6px 12px",borderRadius:6,border:"1px solid #cbd5e1",background:"#ffffff",color:"#0f172a",fontSize:12,fontWeight:600,cursor:"pointer",outline:"none",whiteSpace:"nowrap"};function rp(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 tE(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 nE({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}=T$(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 C=>{v(null),k(C.version);try{const T=await m(C.version);if(T.kind!=="success"){v(T.kind==="not_found"?n("layout_editor.version_history.restore_not_found"):T.message);return}const E=C.version-1,A=s.some(D=>D.version===E);let N={};if(A){const D=await m(E);if(D.kind==="success")N=rp(D.detail);else if(D.kind==="network_error"){v(D.message);return}}_({oldVersion:A?E:0,newVersion:C.version,oldContent:N,newContent:rp(T.detail)})}finally{k(null)}},[m,s,n]),$=u.useCallback(async C=>{v(null);const T=n("layout_editor.version_history.restore_confirm");if(!(typeof window<"u"?window.confirm(T):!0))return;const A=await g(C);A.kind==="success"?r():A.kind==="not_found"?v(n("layout_editor.version_history.restore_not_found")):v(A.message)},[g,r,n]),S=h??d;return y?i.jsx(K$,{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:V$,children:[i.jsxs("div",{"data-modal-drag-handle":!0,style:U$,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:q$,"data-testid":"g7le-version-history-close",children:"✕"})]}),S&&i.jsx("div",{style:Y$,"data-testid":"g7le-version-history-error",children:S}),i.jsx("div",{style:G$,children:a?i.jsx("div",{style:np,"data-testid":"g7le-version-history-loading",children:n("layout_editor.version_history.loading")}):s.length===0?i.jsx("div",{style:np,"data-testid":"g7le-version-history-empty",children:n("layout_editor.version_history.empty")}):i.jsxs("div",{"data-testid":"g7le-version-history-list",style:X$,children:[s.map((C,T)=>{const E=C.changes_summary,A=E?.added_count??0,N=E?.removed_count??0,D=E?.char_diff??0,B=tE(C.created_at),M=c===C.id,O=T===0;return i.jsxs("div",{style:J$,"data-testid":`g7le-version-row-${C.id}`,children:[i.jsxs("span",{style:Z$,"data-testid":`g7le-version-badge-${C.id}`,children:["v",C.version]}),i.jsxs("div",{style:eE,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:Q$,"data-testid":`g7le-version-latest-${C.id}`,children:n("layout_editor.version_history.latest")})]}),i.jsxs("span",{style:R$,"data-testid":`g7le-version-summary-${C.id}`,children:[i.jsx("span",{style:{color:"#16a34a"},"data-testid":`g7le-version-added-${C.id}`,children:n("layout_editor.version_history.added",{count:A})}),i.jsx("span",{style:{color:"#dc2626"},"data-testid":`g7le-version-removed-${C.id}`,children:n("layout_editor.version_history.removed",{count:N})}),i.jsx("span",{style:{color:"#94a3b8",fontWeight:500},"data-testid":`g7le-version-chars-${C.id}`,children:n("layout_editor.version_history.chars",{diff:`${D>=0?"+":""}${D}`})})]}),i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},"data-testid":`g7le-version-author-${C.id}`,children:n("layout_editor.version_history.saved_by",{name:C.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(C),disabled:w!==null,style:{...op,background:"#f8fafc",opacity:w!==null?.6:1},"data-testid":`g7le-version-compare-${C.id}`,children:w===C.version?n("layout_editor.version_history.comparing"):n("layout_editor.version_history.compare")}),!O&&i.jsx("button",{type:"button",onClick:()=>void $(C.id),disabled:M||c!==null,style:{...op,opacity:M||c!==null?.6:1},"data-testid":`g7le-version-restore-${C.id}`,children:n(M?"layout_editor.version_history.restoring":"layout_editor.version_history.restore")})]})]},C.id)}),p&&i.jsx("button",{type:"button","data-testid":"g7le-version-history-load-more",style:oE,disabled:l,onClick:()=>{b()},children:n(l?"layout_editor.version_history.loading":"layout_editor.version_history.load_more")})]})})]})}const oE={width:"100%",marginTop:8,padding:"8px 12px",fontSize:12,color:"#475569",background:"#f8fafc",border:"1px solid #e2e8f0",borderRadius:6,cursor:"pointer"};function Po(e){return`/api/admin/extensions/${encodeURIComponent(e.type)}/${encodeURIComponent(e.identifier)}/custom-assets`}function Oo(e,t){const n=e?.message;return typeof n=="string"&&n!==""?n:`HTTP ${t}`}function rE(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(Po(e),{credentials:"same-origin",headers:Ne()}),y=await v.json().catch(()=>null);if(v.status===401||v.status===403){d(!0),n([]);return}if(d(!1),!v.ok){p(Oo(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=`${Po(e)}/content?path=${encodeURIComponent(v)}`,_=await fetch(y,{credentials:"same-origin",headers:Ne()}),w=await _.json().catch(()=>null);if(!_.ok)return p(Oo(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(`${Po(e)}/content`,{method:"PUT",credentials:"same-origin",headers:Ne({"Content-Type":"application/json"}),body:JSON.stringify({path:v,content:y})}),w=await _.json().catch(()=>null);return _.ok?(await f(),!0):(p(Oo(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(`${Po(e)}/upload`,{method:"POST",credentials:"same-origin",headers:Ne(),body:_}),k=await w.json().catch(()=>null);return w.ok?(await f(),!0):(p(Oo(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=`${Po(e)}?path=${encodeURIComponent(v)}`,_=await fetch(y,{method:"DELETE",credentials:"same-origin",headers:Ne()}),w=await _.json().catch(()=>null);return _.ok?(await f(),!0):(p(Oo(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 iE={display:"flex",flexDirection:"column",height:"100%",minHeight:0},sE={display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:"1px solid #e2e8f0",background:"#f8fafc",fontWeight:600,color:"#0f172a"},aE={marginLeft:"auto",border:"none",background:"transparent",fontSize:16,color:"#64748b",cursor:"pointer",outline:"none"},lE={flex:1,minHeight:0,display:"flex"},dE={width:260,flexShrink:0,borderRight:"1px solid #e2e8f0",overflowY:"auto",padding:8},cE={flex:1,minWidth:0,display:"flex",flexDirection:"column",padding:12,gap:8},ip={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"},uE={...ip,backgroundColor:"#eff6ff",borderColor:"#bfdbfe",color:"#1d4ed8",fontWeight:600},pE={margin:16,padding:16,borderRadius:8,border:"1px solid #fcd34d",background:"#fffbeb",color:"#92400e",fontSize:13,lineHeight:1.7},fE={padding:"8px 12px",borderRadius:6,border:"1px solid #fecaca",background:"#fef2f2",color:"#b91c1c",fontSize:12},gE={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"},sp={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},io={padding:"6px 12px",borderRadius:6,borderWidth:1,borderStyle:"solid",borderColor:"#cbd5e1",backgroundColor:"#ffffff",color:"#334155",fontSize:12,cursor:"pointer"},hE={...io,backgroundColor:"#2563eb",borderColor:"#2563eb",color:"#ffffff",fontWeight:600},yE={...io,borderColor:"#fca5a5",color:"#b91c1c"},bE={...io,cursor:"text",minWidth:200},mE={...io,cursor:"pointer",minWidth:220};function vE(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 _E(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:vE(s?.display_name,a)})}return n}function xE(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function wE(e){const{templateIdentifier:t,t:n,onClose:o}=e,r=u.useMemo(()=>_E(t),[t]),[s,a]=u.useState(`template:${t}`),l=u.useMemo(()=>r.find(S=>`${S.type}:${S.identifier}`===s)??r[0],[r,s]),d=rE({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 S=>{if(f(S),!S.editable){g("");return}y(!0);const C=await d.read(S.path);y(!1),g(C??"")},[d]),k=u.useCallback(async()=>{const S=p?.path??m.trim();if(!S)return;y(!0);const C=await d.save(S,b);y(!1),C&&!p&&(h(""),f({path:S,name:S.split("/").pop()??S,extension:(S.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 S=await d.remove(p.path);y(!1),S&&(f(null),g(""))},[d,p,n]),$=u.useCallback(async S=>{const C=S.target.files?.[0];C&&(y(!0),await d.upload(C),y(!1),_.current&&(_.current.value=""))},[d]);return i.jsxs("div",{className:"g7le-custom-assets",style:iE,"data-testid":"g7le-custom-assets-modal",children:[i.jsxs("div",{style:sE,children:[i.jsxs("span",{children:["🎨 ",n("layout_editor.custom_assets.title")]}),i.jsx("select",{value:s,onChange:S=>a(S.target.value),style:mE,"aria-label":n("layout_editor.custom_assets.target_label"),"data-testid":"g7le-custom-assets-target",children:r.map(S=>i.jsxs("option",{value:`${S.type}:${S.identifier}`,children:[n(`layout_editor.custom_assets.type_${S.type}`)," · ",S.label]},`${S.type}:${S.identifier}`))}),i.jsx("button",{type:"button",style:aE,onClick:o,"aria-label":n("layout_editor.custom_assets.close"),"data-testid":"g7le-custom-assets-close",children:"✕"})]}),d.forbidden?i.jsx("div",{style:pE,"data-testid":"g7le-custom-assets-forbidden",children:n("layout_editor.custom_assets.forbidden")}):i.jsxs("div",{style:lE,children:[i.jsxs("div",{style:dE,"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(S=>i.jsxs("button",{type:"button",style:p?.path===S.path?uE:ip,onClick:()=>void w(S),"data-testid":`g7le-custom-asset-row-${S.path}`,"data-loaded":S.loaded?"true":"false",children:[i.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:S.path}),i.jsx("span",{style:{color:"#94a3b8",fontSize:11},children:xE(S.size)})]},S.path))]}),i.jsxs("div",{style:cE,children:[d.error?i.jsx("div",{style:fE,"data-testid":"g7le-custom-assets-error",children:d.error}):null,i.jsxs("div",{style:sp,children:[i.jsx("input",{type:"text",value:p?p.path:m,readOnly:!!p,onChange:S=>h(S.target.value),placeholder:n("layout_editor.custom_assets.new_path_placeholder"),style:bE,"aria-label":n("layout_editor.custom_assets.path_label"),"data-testid":"g7le-custom-assets-path"}),p?i.jsx("button",{type:"button",style:io,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:S=>g(S.target.value),style:gE,spellCheck:!1,"aria-label":n("layout_editor.custom_assets.content_label"),"data-testid":"g7le-custom-assets-content"}),i.jsxs("div",{style:sp,children:[i.jsx("button",{type:"button",style:hE,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:io,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:S=>void $(S),"data-testid":"g7le-custom-assets-file-input"}),i.jsx("button",{type:"button",style:yE,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 ap=[{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 kE(e){return{key:(e.key||"").toLowerCase(),mod:e.ctrlKey||e.metaKey,shift:e.shiftKey,alt:e.altKey}}function SE(e,t){return e.key===t.key&&!!e.mod==!!t.mod&&!!e.shift==!!t.shift&&!!e.alt==!!t.alt}function CE(e){for(const t of ap)if(t.combos.some(n=>SE(n,e)))return t;return null}function $E(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(EE(e.key)),n.join(" + ")}function EE(e){return{arrowup:"↑",arrowdown:"↓",arrowleft:"←",arrowright:"→",enter:"Enter",escape:"Esc",delete:"Delete",backspace:"Backspace"," ":"Space"}[e]??(e.length===1?e.toUpperCase():e)}const IE=["clipboard","element","history","view","document"],AE={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 TE(){return typeof navigator>"u"?!1:/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent||"")}function DE({t:e,onClose:t,isMac:n}){const o=n??TE(),r=u.useMemo(()=>{const s=new Map;for(const a of ap){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:zE,children:[i.jsxs("div",{style:NE,children:[i.jsx("span",{style:ME,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:LE,children:"✕"})]}),i.jsx("div",{style:PE,children:IE.map(s=>{const a=r.get(s);return!a||a.length===0?null:i.jsxs("div",{style:OE,"data-testid":`g7le-shortcut-group-${s}`,children:[i.jsx("div",{style:BE,children:e(AE[s])}),i.jsx("table",{style:WE,children:i.jsx("tbody",{children:a.map(l=>i.jsxs("tr",{"data-testid":`g7le-shortcut-row-${l.id}`,children:[i.jsx("td",{style:jE,children:e(l.labelKey)}),i.jsx("td",{style:HE,children:l.combos.map((d,c)=>i.jsxs(u.Fragment,{children:[c>0&&i.jsx("span",{style:KE,children:e("layout_editor.shortcuts.or")}),i.jsx("kbd",{style:FE,children:$E(d,o)})]},c))})]},l.id))})})]},s)})}),i.jsx("div",{style:VE,children:e("layout_editor.shortcuts.footnote")})]})}const zE={display:"flex",flexDirection:"column",padding:20,gap:16,width:"100%",boxSizing:"border-box"},NE={display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:12,borderBottom:"1px solid #e2e8f0"},ME={fontSize:15,fontWeight:700,color:"#0f172a"},LE={width:28,height:28,border:"none",background:"transparent",color:"#64748b",cursor:"pointer",fontSize:14,borderRadius:6},PE={display:"grid",gridTemplateColumns:"1fr 1fr",columnGap:28,rowGap:18,alignItems:"start"},OE={display:"flex",flexDirection:"column",gap:6},BE={fontSize:12,fontWeight:700,color:"#2563eb"},WE={width:"100%",borderCollapse:"collapse"},jE={padding:"4px 0",fontSize:12.5,color:"#334155",textAlign:"left",whiteSpace:"nowrap",verticalAlign:"middle"},HE={padding:"4px 0",paddingLeft:12,textAlign:"right",verticalAlign:"middle"},FE={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"},KE={fontSize:11,color:"#94a3b8",margin:"0 4px"},VE={fontSize:11,color:"#94a3b8",paddingTop:12,borderTop:"1px solid #f1f5f9"};function UE(e){if(!e||!(e instanceof HTMLElement))return!1;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable)}function qE(){return typeof document>"u"?!1:!!document.querySelector(".g7le-modal-backdrop, .g7le-modal")}function lp(e){const{handlers:t,hasSelection:n,enabled:o=!0}=e;u.useEffect(()=>{if(!o||typeof window>"u")return;const r=s=>{if(UE(s.target))return;const a=kE(s),l=CE(a);if(!l||qE()||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 GE(e){const{result:t,onDismiss:n,onLoadLatest:o,onKeepMyChanges:r}=e,{t:s}=tt();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(Bo,{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(Bo,{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:dp,"data-testid":"g7le-save-banner-validation-errors",children:l.map(([d,c])=>i.jsxs("li",{children:[i.jsx("code",{style:cp,children:d}),": ",c.join(", ")]},d))})]})}return t.kind==="blocked_inactive_extension"?i.jsxs(Bo,{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:dp,"data-testid":"g7le-save-banner-blocked-paths",children:t.blockedPaths.map(a=>i.jsx("li",{children:i.jsx("code",{style:cp,children:a})},a))})]}):t.kind==="network_error"?i.jsxs(Bo,{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(Bo,{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:ZE,children:i.jsxs("div",{style:QE,children:[i.jsx("h2",{style:RE,children:s("layout_editor.save.concurrent.title")}),i.jsx("p",{style:e7,children:s("layout_editor.save.concurrent.message")}),i.jsx("div",{style:t7,children:s("layout_editor.save.concurrent.version_info",{current:String(t.currentVersion),yours:String(t.yourVersion)})}),i.jsxs("div",{style:n7,children:[i.jsx("button",{type:"button","data-testid":"g7le-save-banner-concurrent-load-latest",onClick:()=>{o?.(),n()},style:o7,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:r7,children:s("layout_editor.save.concurrent.view_my_changes")}),i.jsx("button",{type:"button","data-testid":"g7le-save-banner-concurrent-cancel",onClick:n,style:i7,children:s("layout_editor.save.concurrent.cancel")})]})]})})}function Bo(e){const{tone:t,testId:n,onDismiss:o,children:r}=e,s=YE[t];return i.jsxs("div",{role:"status","data-testid":n,style:{...XE,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:JE,children:"×"})]})}const YE={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"}},XE={display:"flex",alignItems:"flex-start",gap:12,padding:"12px 16px",border:"1px solid",borderRadius:0,fontSize:13,lineHeight:1.5},JE={background:"transparent",border:"none",fontSize:18,cursor:"pointer",lineHeight:1,color:"inherit",padding:"0 4px",flexShrink:0},dp={margin:"8px 0 0",paddingLeft:20,fontSize:12},cp={background:"rgba(0, 0, 0, 0.06)",padding:"1px 4px",borderRadius:3,fontFamily:"monospace"},ZE={position:"fixed",inset:0,background:"rgba(15, 23, 42, 0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e4},QE={background:"#fff",borderRadius:8,padding:24,width:"min(480px, 90vw)",boxShadow:"0 10px 25px rgba(0,0,0,0.15)"},RE={margin:"0 0 8px",fontSize:16,fontWeight:600,color:"#0f172a"},e7={margin:"0 0 12px",color:"#334155",fontSize:13,lineHeight:1.5},t7={marginBottom:16,padding:"8px 12px",background:"#f8fafc",borderRadius:6,fontSize:12,color:"#64748b",fontFamily:"monospace"},n7={display:"flex",gap:8,justifyContent:"flex-end"},o7={padding:"8px 14px",background:"#2563eb",color:"#fff",border:"none",borderRadius:6,fontSize:13,fontWeight:600,cursor:"pointer"},r7={padding:"8px 14px",background:"#fff",color:"#334155",border:"1px solid #cbd5e1",borderRadius:6,fontSize:13,fontWeight:500,cursor:"pointer"},i7={padding:"8px 14px",background:"transparent",color:"#64748b",border:"none",borderRadius:6,fontSize:13,cursor:"pointer"};function up(e){if(!e)return null;const n=new URLSearchParams(e).get("route");return n&&n.length>0?n:null}function ea(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 pp(e){if(!e)return null;const n=new URLSearchParams(e).get("host");return n&&n.length>0?n:null}function fp(e){if(!e)return null;const n=new URLSearchParams(e).get("edit");return n&&n.length>0&&n.startsWith("__")?n:null}function s7(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 a7="g7le-editor-route",l7=new Set;function ta(e){return e.path.startsWith("__group__/")||e.path.startsWith("__conngroup__/")}function gp(e,t){const{t:n,translationEngine:o,translationContext:r,templateIdentifier:s}=t,a=ta(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 d7(e){return e.trim().toLocaleLowerCase()}function hp(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<e.length&&o.push(e.slice(r)),o}function c7(e){if(!e.layoutName)return null;const t=`${e.layoutName}.json`;switch(e.source.kind){case"module":case"plugin":return`${e.source.identifier?`${e.source.identifier} · `:""}resources/layouts/${t}`;case"template":return`${e.source.identifier?`${e.source.identifier} · `:""}layouts/${t}`;default:return`layouts/${t}`}}function u7({node:e}){const{t}=tt(),n=[],o={display:"inline-flex",alignItems:"center",padding:"1px 6px",fontSize:10,fontWeight:600,borderRadius:4,letterSpacing:.3,textTransform:"uppercase",border:"1px solid transparent"};return e.isHidden&&n.push(i.jsx("span",{className:"g7le-route-tree__badge g7le-route-tree__badge--hidden","data-testid":"g7le-route-tree-badge-hidden",style:{...o,background:"#f1f5f9",color:"#64748b",borderColor:"#e2e8f0"},children:t("layout_editor.chrome.route_tree.badge.hidden")},"hidden")),e.isRedirect&&n.push(i.jsx("span",{className:"g7le-route-tree__badge g7le-route-tree__badge--redirect","data-testid":"g7le-route-tree-badge-redirect",style:{...o,background:"#fef3c7",color:"#92400e",borderColor:"#fde68a"},children:t("layout_editor.chrome.route_tree.badge.redirect")},"redirect")),n.length===0?null:i.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",gap:4},children:n})}function yp({node:e,depth:t,onSelect:n,selectedRoutePath:o,activeHostRoutePath:r,dirtyLayoutNames:s,query:a,forceExpand:l}){const{t:d,translationEngine:c,translationContext:p}=tt(),{state:f}=Qe(),b=ta(e),g=e.path.startsWith("__conngroup__/"),m=u.useMemo(()=>{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"?bp(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,S=e.kind==="modal"&&!!x&&e.modalId===x&&($===null||e.modalHostLayout==null||$===e.modalHostLayout),C=e.kind!=="extension"&&e.kind!=="modal"&&o===e.path||k||S||e.kind==="route"&&!b&&r===e.path,E=(e.children?.length??0)>0&&(!g||l||!v),A=!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,D=()=>{if(g){y(z=>!z);return}b||n(e)},B=gp(e,{t:d,translationEngine:c,translationContext:p,templateIdentifier:f.templateIdentifier}),M=b?null:c7(e),O={paddingLeft:12+t*14,paddingRight:12,paddingTop:4,paddingBottom:4,opacity:e.isHidden?.55:1,cursor:g?"pointer":b?"default":"pointer",background:C?"#eff6ff":"transparent",borderLeft:C?"2px solid #2563eb":"2px solid transparent",fontWeight:b||C?600:400,fontSize:b?11:13,color:b?"#64748b":C?"#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:D,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?"▾":"▸"}),A&&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:hp(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(u7,{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:hp(M,a)})]}),E&&i.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:e.children.map(z=>i.jsx(yp,{node:z,depth:t+1,onSelect:n,selectedRoutePath:o,activeHostRoutePath:r,dirtyLayoutNames:s,query:a,forceExpand:l},z.path))})]})}function p7(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 bp(e,t){if(e.connectedHostRoutePath){const n=mp(t,e.connectedHostRoutePath);if(n?.layoutName)return n.layoutName}if(e.extensionType==="overlay"&&e.extensionTargetName)return e.extensionTargetName}function mp(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=mp(n.children,t);if(o)return o}}return null}function vp(e,t,n){const o=[];for(const r of e){const s=ta(r),a=r.children&&r.children.length>0?vp(r.children,t,n):[];if(s){a.length>0&&o.push({...r,children:a});continue}const l=gp(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 f7(){const{t:e,translationEngine:t,translationContext:n}=tt(),{state:o,dispatch:r}=Qe(),a=Ft()?.dirtyLayoutNames??l7,[l,d]=u.useState(""),c=d7(l),p=u.useMemo(()=>c?vp(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=bp(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=ea(o.templateIdentifier,h.path);`${window.location.pathname}${window.location.search}`!==v&&window.history.pushState({source:a7,routePath:h.path},"",v)}},b=o.selectedRoute?.path??null,g=u.useMemo(()=>p7(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(yp,{node:h,depth:0,onSelect:f,selectedRoutePath:b,activeHostRoutePath:g,dirtyLayoutNames:a,query:c,forceExpand:!!c},h.path))})})]})}const g7=Lt().DynamicRenderer,na=Lt(),h7=na.ResponsiveProvider;na.useResponsive,na.ResponsiveContext;const y7=Lt().ActionDispatcher,_p=Lt(),b7=_p.DataSourceManager;_p.dataSourceManager;function Jr(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 so(e,t){return{kind:"network",status:0,message:e instanceof Error?e.message:String(e??"Unknown network error"),source:t}}function xp(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;o<n.length;o++){const r=n[o];if(r==="children")continue;if(r==="iteration"||r==="sortable"){o+=1;continue}if(r==="responsive"){const a=n[o+1];typeof a=="string"&&a.length>0&&(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=v7(e);return n?_7(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 v7(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 _7(e){return/\{\{[\s\S]*?\}\}/.test(e)}function x7(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 w7(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=S7(o);if(a!==null)return a}const r=[];if(typeof e.text=="string"&&r.push(...wp(e.text)),e.props&&typeof e.props=="object")for(const a of Object.values(e.props))typeof a=="string"&&r.push(...wp(a));return r.length===0?null:r.find(a=>!k7.has(a))??r[0]}const k7=new Set(["_local","_global","_computed","route","query","props","item","index","event","$event","$response","response"]);function wp(e){const t=[],n=/\{\{([\s\S]*?)\}\}/g;let o;for(;(o=n.exec(e))!==null;){const r=kp(o[1]);r!==null&&t.push(r)}return t}function S7(e){const t=e.replace(/\{\{|\}\}/g,"");return kp(t)}function kp(e){const t=/[A-Za-z_$][A-Za-z0-9_$]*/.exec(e.trim());return t?t[0]:null}function gn(e,t,n,o=[]){if(!e)return"none";if(id(e)||typeof e.slot=="string"||typeof e.__editorSlotName=="string")return"extension_point";if(t!=="route"&&Ri(e,t,n)){const s=e.__source?.kind;return s==="base"?"base":s==="partial"?"partial":s==="extension"?"extension":"base"}if(zb(e,o))return"data_bound";if(!Ri(e,t,n))return"none";const r=e.__source?.kind;return r==="base"?"base":r==="partial"?"partial":r==="extension"?"extension":"none"}function Sp(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 C7(e,t){if(t<=0)return e;const n=e.split(".");let o=0;const r=[];for(let s=0;s<n.length;s++){const a=n[s];if(a==="children"){if(o>=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 Cp(e,t,n,o){if(!e||!t)return t;const r=n(t),s=Lb(e,r,o);return s.length===r.length?t:C7(t,s.length)}function $p(e){return e==="none"||e==="data_bound"}function $7(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 Ep($,r)}const w=oa(t,_,s);if(!w)return!0;const k=ra(t,_,s),x=gn(w,n,o,k);return x==="none"||x==="data_bound"},[t,s,n,o,r]),b=u.useCallback((_,w)=>{const x=(w?.currentTarget?.dataset??w?.dataset)?.editorPath??null,$=Cp(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,$=Cp(t,x,s,o);if(!f($)){p(null);return}p($)},[t,s,o,f]),m=u.useCallback(()=>{d(null)},[]),h=u.useMemo(()=>{const _=oa(t,l,s),w=oa(t,c,s),k=_?ra(t,l,s):[];let x=gn(_,n,o,k);(n==="iteration_item"||n==="modal")&&l!==null&&_&&r&&r.length>0&&Ep(s(l),r)&&(sd(_)?x="data_bound":x==="data_bound"&&(x="none"));const{affordance:$,targetPath:S}=m7(_,a),C=x==="base"&&typeof _?.__source?.layout=="string"?_.__source.layout:null,T=x==="data_bound"&&_?w7(_,k):null,{isIteration:E,iterationSourcePath:A}=x==="data_bound"&&_?x7(_,k,l):{isIteration:!1,iterationSourcePath:null};return{selectedNode:_,hoverNode:w,selectedLockKind:x,selectedNavAffordance:$,selectedNavTargetPath:S,selectedBaseLayout:C,selectedDataSourceId:T,selectedIsIteration:E,selectedIterationSourcePath:A}},[t,l,c,n,o,r,s,a]),v=u.useRef(void 0);v.current!==l&&(v.current=l,Al({op:l===null?"clear":"select",componentPath:l,componentName:Ip(h.selectedNode),lockKind:h.selectedLockKind,navAffordance:h.selectedNavAffordance,sourceExtensionId:Sp(h.selectedNode),timestamp:Date.now()}));const y=u.useRef(void 0);return y.current!==c&&(y.current=c,c!==null&&Al({op:"hover",componentPath:c,componentName:Ip(h.hoverNode),lockKind:gn(h.hoverNode,n,o,ra(t,c,s)),navAffordance:"none",sourceExtensionId:Sp(h.hoverNode),timestamp:Date.now()})),{selectedPath:l,hoverPath:c,...h,handleSelect:b,handleHover:g,clearSelection:m}}function oa(e,t,n){if(!e||!t)return null;const o=n(t);return Be(e,o)}function Ep(e,t){if(e.length<t.length)return!1;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function ra(e,t,n){if(!e||!t)return[];const o=n(t),r=[];for(let s=0;s<o.length;s++){const a=o.slice(0,s),l=Be(e,a);l&&r.push(l)}return r}function Ip(e){return e?typeof e.name=="string"&&e.name.length>0?e.name:typeof e.type=="string"&&e.type.length>0?e.type:null:null}let Ap=0;function Tp(){return Ap}function ia(){Ap+=1}function E7(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 I7(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 Dp(){const{state:e}=Qe(),t=e.templateIdentifier,n=e.selectedRoute?.layoutName??null,o=e.editMode,r=o==="modal"?E7(e.selectedRoute?.path):null,s=o==="iteration_item"?I7(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,I)=>`${P}|${I??""}`,[]),$=u.useRef(null);u.useEffect(()=>{$.current=a},[a]);const S=u.useCallback((P,I)=>{const L=x(o,n);_.current.set(L,{raw:P,lockVersion:I}),k(F=>{if(F.has(L))return F;const Y=new Set(F);return Y.add(L),Y})},[x,o,n]),C=u.useCallback(P=>{_.current.delete(P),k(I=>{if(!I.has(P))return I;const L=new Set(I);return L.delete(P),L})},[]),T=u.useCallback(P=>{const I=`|${P??""}`,L=[];for(const F of _.current.keys())F.endsWith(I)&&L.push(F);for(const F of L)_.current.delete(F);L.length>0&&k(F=>{let Y=!1;const K=new Set(F);for(const X of L)K.delete(X)&&(Y=!0);return Y?K:F})},[]),E=u.useCallback(async()=>{if(!n){l(null),f(null),g(!1);return}const P=x(o,n),I=_.current.get(P);if(I){l({layoutName:n,raw:I.raw,lockVersion:I.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=en(`/api/layouts/${encodeURIComponent(t)}/${n}`,"json",`${L}.${Tp()}`,"with_source_meta=1"),Y=cr(),K={Accept:"application/json"};Y&&(K.Authorization=`Bearer ${Y}`);const X=await fetch(F,{headers:K,credentials:"same-origin"}),Z=await X.json().catch(()=>null);if(!X.ok){f(Jr(X.status,Z,"layout")),l(null),g(!1);return}const ae=(Z&&(Z.data||Z))??{},oe=typeof ae.lock_version=="number"?ae.lock_version:0;if(o==="modal"&&r){const ee=ae,ge=Array.isArray(ee.modals)?ee.modals:[],V=ge.findIndex(te=>te&&(te.id===r||te.modal_id===r));if(V>=0){const te=ge[V],be={...te,props:{...te.props??{},isOpen:!0}},De=[...Array.isArray(ee.components)?ee.components:[],be],Se=[De.length-1];l({layoutName:n,raw:{...ee,components:De},lockVersion:oe,modalContext:{modalId:r,modalIndex:V,hostRaw:ee,originalModalNode:te,editIndexPath:Se}}),g(!1),st({op:"load",layoutName:n,editMode:o,statusCode:X.status,timestamp:Date.now()});return}}if(o==="iteration_item"&&s){const ee=ae,ge=Re(s),V={children:ee.components??[]},te=Be(V,ge);if(te&&Array.isArray(te.children)){l({layoutName:n,raw:ee,lockVersion:oe,iterationContext:{sourcePath:s,sourceIndexPath:ge,hostRaw:ee}}),g(!1),st({op:"load",layoutName:n,editMode:o,statusCode:X.status,timestamp:Date.now()});return}}l({layoutName:n,raw:ae,lockVersion:oe}),g(!1),st({op:"load",layoutName:n,editMode:o,statusCode:X.status,timestamp:Date.now()})}catch(L){f(so(L,"layout")),l(null),g(!1)}finally{c(!1)}},[t,n,o,r,s,x]);u.useEffect(()=>{E()},[E]);const A=u.useCallback(async()=>{C(x(o,n)),ia(),y(P=>P+1),await E()},[C,x,o,n,E]),N=u.useCallback(()=>{C(x(o,n))},[C,x,o,n]),D=u.useCallback(P=>{l(I=>{if(!I)return I;const L=I.raw.components??[],F=P(L),Y={...I.raw,components:F};return S(Y,I.lockVersion),{...I,raw:Y}}),g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o,S]),B=u.useCallback(()=>{g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o]),M=u.useCallback(P=>{l(I=>{if(!I)return I;const L={...I.raw,components:P};return S(L,I.lockVersion),{...I,raw:L}}),g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o,S]),O=u.useCallback((P,I,...L)=>{const F=L.length>=1?L[0]:I;l(Y=>{if(!Y)return Y;const K={...Y.raw,[P]:I},X=Y.raw.__editor;if(X&&typeof X=="object"&&!Array.isArray(X)){const Z=X,ae=Z.original;ae&&typeof ae=="object"&&!Array.isArray(ae)&&(K.__editor={...Z,original:{...ae,[P]:F}})}return S(K,Y.lockVersion),{...Y,raw:K}}),g(!0),st({op:"patch",layoutName:n,editMode:o,isDirty:!0,timestamp:Date.now()})},[n,o,S]),z=u.useCallback(async P=>{const I=$.current;if(!I)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 ge=await P.resolveActiveExtensions(),V=A7(I.raw.components,P.sessionAddedPaths,ge);if(V.length>0)return st({op:"save_guard_result",layoutName:n,editMode:o,guardBlocked:!0,guardBlockedPaths:V,timestamp:Date.now()}),{kind:"blocked_inactive_extension",blockedPaths:V}}catch{}if(Yb())try{await Xb(t)}catch{}const L=`/api/admin/templates/${encodeURIComponent(t)}/layouts/${I.layoutName}`,F=cr(),Y={Accept:"application/json","Content-Type":"application/json"};F&&(Y.Authorization=`Bearer ${F}`);const K=!!I.modalContext,X=!!I.iterationContext,Z=K||X?"host_layout_modal_patch":"layout";st({op:"save",layoutName:I.layoutName,editMode:o,saveTarget:Z,endpoint:L,isDirty:b,timestamp:Date.now()});let ae;if(K&&I.modalContext){const{modalIndex:ge,hostRaw:V,originalModalNode:te,editIndexPath:be}=I.modalContext,Ee=Array.isArray(V.modals)?[...V.modals]:[],De=Array.isArray(I.raw.components)?I.raw.components:[],Se=be&&be.length===1?be[0]:0,Ue=De.length>Se?De[Se]:void 0,Me=Ue?Vn([Ue]):[],Oe=Me.length>0?{...Me[0]}:void 0;if(ge>=0&&ge<Ee.length&&Oe){const ze=te.props??{},Xe={...Oe.props??{}};"isOpen"in ze?Xe.isOpen=ze.isOpen:delete Xe.isOpen,Oe.props=Xe,Ee[ge]=Oe}ae={..._o(V),modals:Ee}}else if(X&&I.iterationContext){const{sourceIndexPath:ge,hostRaw:V}=I.iterationContext,te=_o(I.raw),be=Array.isArray(te.components)?te.components:[],Ee=Be({children:be},ge),De=Array.isArray(Ee?.children)?Ee.children:[],Se=_o(V),Me={children:Array.isArray(Se.components)?Se.components:[]},Ye=Ot(Me,ge,ze=>({...ze,children:De})).children??[];ae={...Se,components:Ye}}else ae=_o(I.raw);const oe=ae;let G;try{G=await fetch(L,{method:"PUT",headers:Y,credentials:"same-origin",body:JSON.stringify({content:JSON.stringify(oe),expected_lock_version:I.lockVersion})})}catch(ge){const V=ge instanceof Error?ge.message:"network error";return st({op:"save_response",layoutName:I.layoutName,editMode:o,endpoint:L,statusCode:0,timestamp:Date.now()}),{kind:"network_error",message:V}}const ee=await G.json().catch(()=>null);if(st({op:"save_response",layoutName:I.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 ge=typeof ee?.data?.lock_version=="number"?ee.data.lock_version:I.lockVersion+1;l({...I,lockVersion:ge}),g(!1),C(x(o,I.layoutName)),T(I.layoutName),ia(),h(te=>te+1);const V=typeof ee?.data?.current_version=="number"?ee.data.current_version:void 0;return{kind:"success",newLockVersion:ge,newContentVersion:V,savedLayoutName:I.layoutName}}return G.status===409?{kind:"concurrent_modification",currentVersion:ee?.current_version??-1,yourVersion:ee?.your_version??I.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,C,T,x,r,s]),H=u.useMemo(()=>{const P=new Set,I="route|";for(const L of w)if(L.startsWith(I)){const F=L.slice(I.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:A,patchLayout:D,setLayoutComponents:M,patchDocumentRaw:O,save:z,markDirty:B}}function A7(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=T7(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 T7(e,t){const n=Re(t);return n.length===0?null:Be({children:e},n)}function ao(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 lo(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 zp(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 Np=44;function Mp(e){if(!e)return"inside";const t=e.scale||1,n=e.width*t,o=e.height*t;return n<Np||o<Np?"outside":"inside"}const D7=24,Lp=6;function Pp(e){const t=D7/2,n=e.width/2,o=e.height/2,r=t+Lp,s=2*t-Math.min(n,o)+Lp,a=Math.max(r,s);return{above:{left:n-t,top:-a-t},below:{left:n-t,top:e.height+a-t},left:{left:-a-t,top:o-t},right:{left:e.width+a-t,top:o-t}}}function Op(e){if(!e||typeof window>"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 z7(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??Op(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=N7(s,o,a,l);if(p)return{points:p,flow:s}}return{points:M7(s,a,l),flow:s}},[t,n,o,r])}function N7(e,t,n,o){let r=t.parentElement;for(;r&&Bp(r)==="contents";)r=r.parentElement;if(!r)return null;const s=[];if(Wp(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}):_<l?c.push({rect:y,path:v.path}):p.push({rect:y,path:v.path})}d.sort((v,y)=>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=Qr(v.path);y&&(m.disabled=!1,m.insertion=y)}else if(d.length>0){const v=d[0],y=Zr(v.path);y&&(m.disabled=!1,m.insertion=y)}if(f>=0&&f<d.length-1){const v=d[f+1],y=Zr(v.path);y&&(h.disabled=!1,h.insertion=y)}else if(d.length>0){const v=d[d.length-1],y=Qr(v.path);y&&(h.disabled=!1,h.insertion=y)}if(c.length>0){const v=c[c.length-1],y=Qr(v.path);y&&(b.disabled=!1,b.insertion=y)}else if(s.length>0){const v=s[0],y=Zr(v.path);y&&(b.disabled=!1,b.insertion=y)}if(p.length>0){const v=p[0],y=Zr(v.path);y&&(g.disabled=!1,g.insertion=y)}else if(s.length>0){const v=s[s.length-1],y=Qr(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 Bp(e){return typeof window>"u"?"":(window.getComputedStyle(e).display??"").toLowerCase()}function Wp(e,t){const n=Array.from(e.children);for(const o of n){if(Bp(o)==="contents"){Wp(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 Zr(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 Qr(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 M7(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 L7(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;ey({op:p,actionKind:f?.actionKind,label:f?.label,stackSize:b,cursor:g,canUndo:g>0,canRedo:g>=0&&g<b-1,timestamp:Date.now()})},a=u.useCallback(p=>{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<t.current.length-1}}function P7(e){if(!e||!(e instanceof HTMLElement))return!1;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable)}function O7(e){const{onUndo:t,onRedo:n,enabled:o=!0}=e;u.useEffect(()=>{if(!o||typeof window>"u")return;const r=s=>{if(P7(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 B7=20,jp=50,W7=90,Ln=120,j7=130,Hp=80,H7=9e3,Fp=1e4;function F7(e){const t=e<0?0:e>jp?jp:e;return B7+t}function K7(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}=tt(),[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:{...V7,color:v?w:y,background:v?_:"transparent"},children:h.label},h.testid)})})}const V7={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 U7(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:S,selectedName:C,onSelectParent:T}=e,{t:E}=tt(),[A,N]=u.useState(!1),D=$p(o),B=A&&D,M=Mp(n),O=M==="outside",z=O&&n?Pp(n):null,H=z?{left:z.right.left,top:z.above.top}:{right:-30,top:-30},P={top:-28,left:0},L=O&&!!C?{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:G7,children:["📱 ",k]}):null,C&&(T?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:K=>{K.preventDefault(),K.stopPropagation(),T()},style:O?X7:Y7,children:[i.jsx("span",{"aria-hidden":!0,style:{marginRight:3,opacity:.85},children:"↑"}),C]}):i.jsx("span",{"data-testid":"g7le-overlay-type-label","data-placement":O?"outside":"inside",style:O?Vp:Kp,children:C})),D&&i.jsx("button",{type:"button","data-testid":"g7le-overlay-info-button","aria-label":"info",onClick:K=>{K.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:Ln},children:"ⓘ"}),o==="none"&&i.jsx(q7,{enabledAxes:$,onHandlePointerDown:S}),o==="base"&&h&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-edit-base",onClick:K=>{K.stopPropagation(),h()},style:{...Wo,...P},children:["🔒 ",E("layout_editor.overlay.edit_common_layout"),_?i.jsx("span",{"data-testid":"g7le-overlay-base-layout-label",style:aa,children:_}):null]}),o==="extension"&&v&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-edit-extension",onClick:K=>{K.stopPropagation(),v()},style:{...Wo,...P},children:["🔒 ",E("layout_editor.overlay.edit_extension"),y?i.jsx("span",{"data-testid":"g7le-overlay-extension-label",style:aa,children:y}):null]}),o==="data_bound"&&i.jsxs("span",{"data-testid":"g7le-overlay-data-bound-notice",style:{...Wo,...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:aa,children:w}):null]}),o==="data_bound"&&x&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-edit-iteration",onClick:K=>{K.stopPropagation(),x()},style:{...Wo,...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:K=>{K.stopPropagation(),m()},style:{...Wo,...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(K=>i.jsxs("button",{type:"button","data-testid":`g7le-overlay-jump-device-${K.key}`,title:E("layout_editor.overlay.jump_device_hint",{device:K.label}),onClick:X=>{X.stopPropagation(),g(K.key)},style:sa,children:["↗ ",E("layout_editor.overlay.jump_device",{device:K.label})]},K.key)),d&&i.jsxs("button",{type:"button","data-testid":"g7le-overlay-separate-branch",title:E("layout_editor.context_menu.separate_branch_hint"),onClick:K=>{K.stopPropagation(),d()},style:sa,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:K=>{K.stopPropagation(),p()},style:sa,children:["↩️ ",f??E("layout_editor.context_menu.merge_branch")]})]})]}),i.jsx(K7,{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 q7(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:Ln}},a.key)})})}const Wo={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:Ln},sa={background:"#fff",border:"1px solid #2563eb",color:"#2563eb",padding:"2px 6px",fontSize:11,borderRadius:4,cursor:"pointer",pointerEvents:"auto",whiteSpace:"nowrap",zIndex:Ln},aa={marginLeft:6,padding:"0 5px",borderRadius:3,background:"#eef2ff",border:"1px solid #c7d2fe",fontSize:10,fontWeight:600,color:"#3730a3"},G7={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"},Kp={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"},Vp={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"},Y7={...Kp,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:Ln},X7={...Vp,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:Ln},J7={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 Z7(e){const{selectedBox:t,points:n,onAddRequest:o}=e,{t:r}=tt();if(!t||n.length===0)return null;const s=Mp(t),l=s==="outside"?Pp(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}:J7[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:Ln},children:"+"},d.direction)})})}const Rr=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function co(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function la(e){return"nodeType"in e}function xt(e){var t,n;return e?co(e)?e:la(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function da(e){const{Document:t}=xt(e);return e instanceof t}function jo(e){return co(e)?!1:e instanceof xt(e).HTMLElement}function Up(e){return e instanceof xt(e).SVGElement}function uo(e){return e?co(e)?e.document:la(e)?da(e)?e:jo(e)||Up(e)?e.ownerDocument:document:document:document}const sn=Rr?u.useLayoutEffect:u.useEffect;function ei(e){const t=u.useRef(e);return sn(()=>{t.current=e}),u.useCallback(function(){for(var n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];return t.current==null?void 0:t.current(...o)},[])}function Q7(){const e=u.useRef(null),t=u.useCallback((o,r)=>{e.current=setInterval(o,r)},[]),n=u.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function Ho(e,t){t===void 0&&(t=[e]);const n=u.useRef(e);return sn(()=>{n.current!==e&&(n.current=e)},t),n}function Fo(e,t){const n=u.useRef();return u.useMemo(()=>{const o=e(n.current);return n.current=o,o},[...t])}function ti(e){const t=ei(e),n=u.useRef(null),o=u.useCallback(r=>{r!==n.current&&t?.(r,n.current),n.current=r},[]);return[n,o]}function ni(e){const t=u.useRef();return u.useEffect(()=>{t.current=e},[e]),t.current}let ca={};function oi(e,t){return u.useMemo(()=>{if(t)return t;const n=ca[e]==null?0:ca[e]+1;return ca[e]=n,e+"-"+n},[e,t])}function qp(e){return function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return o.reduce((s,a)=>{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 po=qp(1),ri=qp(-1);function R7(e){return"clientX"in e&&"clientY"in e}function ua(e){if(!e)return!1;const{KeyboardEvent:t}=xt(e.target);return t&&e instanceof t}function e2(e){if(!e)return!1;const{TouchEvent:t}=xt(e.target);return t&&e instanceof t}function ii(e){if(e2(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 R7(e)?{x:e.clientX,y:e.clientY}:null}const Ko=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[Ko.Translate.toString(e),Ko.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:o}=e;return t+" "+n+"ms "+o}}}),Gp="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function t2(e){return e.matches(Gp)?e:e.querySelector(Gp)}const n2={display:"none"};function o2(e){let{id:t,value:n}=e;return u.createElement("div",{id:t,style:n2},n)}function r2(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 i2(){const[e,t]=u.useState("");return{announce:u.useCallback(o=>{o!=null&&t(o)},[]),announcement:e}}const Yp=u.createContext(null);function s2(e){const t=u.useContext(Yp);u.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function a2(){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 l2={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.
|
||
`},d2={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 c2(e){let{announcements:t=d2,container:n,hiddenTextDescribedById:o,screenReaderInstructions:r=l2}=e;const{announce:s,announcement:a}=i2(),l=oi("DndLiveRegion"),[d,c]=u.useState(!1);if(u.useEffect(()=>{c(!0)},[]),s2(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(o2,{id:o,value:r.draggable}),u.createElement(r2,{id:l,announcement:a}));return n?Cn.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 si(){}function u2(e,t){return u.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function p2(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return u.useMemo(()=>[...t].filter(o=>o!=null),[...t])}const Ht=Object.freeze({x:0,y:0});function f2(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function g2(e,t){const n=ii(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 h2(e,t){let{data:{value:n}}=e,{data:{value:o}}=t;return n-o}function y2(e,t){let{data:{value:n}}=e,{data:{value:o}}=t;return o-n}function b2(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 v2(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<r&&n<s){const d=t.width*t.height,c=e.width*e.height,p=a*l,f=p/(d+c-p);return Number(f.toFixed(4))}return 0}const _2=e=>{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=v2(l,t);d>0&&r.push({id:a,data:{droppableContainer:s,value:d}})}}return r.sort(y2)};function x2(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 w2=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&&x2(o,l)){const c=b2(l).reduce((f,b)=>f+f2(o,b),0),p=Number((c/4).toFixed(4));r.push({id:a,data:{droppableContainer:s,value:p}})}}return r.sort(h2)};function k2(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function Xp(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Ht}function S2(e){return function(n){for(var o=arguments.length,r=new Array(o>1?o-1:0),s=1;s<o;s++)r[s-1]=arguments[s];return r.reduce((a,l)=>({...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 C2=S2(1);function Jp(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 $2(e,t,n){const o=Jp(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 E2={ignoreTransform:!1};function Vo(e,t){t===void 0&&(t=E2);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:c,transformOrigin:p}=xt(e).getComputedStyle(e);c&&(n=$2(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 Zp(e){return Vo(e,{ignoreTransform:!0})}function I2(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function A2(e,t){return t===void 0&&(t=xt(e).getComputedStyle(e)),t.position==="fixed"}function T2(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 pa(e,t){const n=[];function o(r){if(t!=null&&n.length>=t||!r)return n;if(da(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!jo(r)||Up(r)||n.includes(r))return n;const s=xt(e).getComputedStyle(r);return r!==e&&T2(r,s)&&n.push(r),A2(r,s)?n:o(r.parentNode)}return e?o(e):n}function Qp(e){const[t]=pa(e,1);return t??null}function fa(e){return!Rr||!e?null:co(e)?e:la(e)?da(e)||e===uo(e).scrollingElement?window:jo(e)?e:null:null}function Rp(e){return co(e)?e.scrollX:e.scrollLeft}function ef(e){return co(e)?e.scrollY:e.scrollTop}function ga(e){return{x:Rp(e),y:ef(e)}}var lt;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(lt||(lt={}));function tf(e){return!Rr||!e?!1:e===document.scrollingElement}function nf(e){const t={x:0,y:0},n=tf(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 D2={x:.2,y:.2};function z2(e,t,n,o,r){let{top:s,left:a,right:l,bottom:d}=n;o===void 0&&(o=10),r===void 0&&(r=D2);const{isTop:c,isBottom:p,isLeft:f,isRight:b}=nf(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 N2(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 of(e){return e.reduce((t,n)=>po(t,ga(n)),Ht)}function M2(e){return e.reduce((t,n)=>t+Rp(n),0)}function L2(e){return e.reduce((t,n)=>t+ef(n),0)}function rf(e,t){if(t===void 0&&(t=Vo),!e)return;const{top:n,left:o,bottom:r,right:s}=t(e);Qp(e)&&(r<=0||s<=0||n>=window.innerHeight||o>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const P2=[["x",["left","right"],M2],["y",["top","bottom"],L2]];class ha{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=pa(n),r=of(o);this.rect={...t},this.width=t.width,this.height=t.height;for(const[s,a,l]of P2)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 Uo{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 O2(e){const{EventTarget:t}=xt(e);return e instanceof t?e:uo(e)}function ya(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 sf(e){e.preventDefault()}function B2(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 af={start:[Fe.Space,Fe.Enter],cancel:[Fe.Esc],end:[Fe.Space,Fe.Enter,Fe.Tab]},W2=(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 lf{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 Uo(uo(n)),this.windowListeners=new Uo(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&&rf(o),n(Ht)}handleKeyDown(t){if(ua(t)){const{active:n,context:o,options:r}=this.props,{keyboardCodes:s=af,coordinateGetter:a=W2,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}:Ht;this.referenceCoordinates||(this.referenceCoordinates=p);const f=a(t,{active:n,context:o.current,currentCoordinates:p});if(f){const b=ri(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:$}=nf(h),S=N2(h),C={x:Math.min(v===Fe.Right?S.right-S.width/2:S.right,Math.max(v===Fe.Right?S.left:S.left+S.width/2,f.x)),y:Math.min(v===Fe.Down?S.bottom-S.height/2:S.bottom,Math.max(v===Fe.Down?S.top:S.top+S.height/2,f.y))},T=v===Fe.Right&&!_||v===Fe.Left&&!w,E=v===Fe.Down&&!k||v===Fe.Up&&!y;if(T&&C.x!==f.x){const A=h.scrollLeft+b.x,N=v===Fe.Right&&A<=x.x||v===Fe.Left&&A>=$.x;if(N&&!b.y){h.scrollTo({left:A,behavior:l});return}N?g.x=h.scrollLeft-A: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&&C.y!==f.y){const A=h.scrollTop+b.y,N=v===Fe.Down&&A<=x.y||v===Fe.Up&&A>=$.y;if(N&&!b.x){h.scrollTo({top:A,behavior:l});return}N?g.y=h.scrollTop-A: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,po(ri(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()}}lf.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:o=af,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 df(e){return!!(e&&"distance"in e)}function cf(e){return!!(e&&"delay"in e)}class ba{constructor(t,n,o){var r;o===void 0&&(o=O2(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=uo(a),this.documentListeners=new Uo(this.document),this.listeners=new Uo(o),this.windowListeners=new Uo(xt(a)),this.initialCoordinates=(r=ii(s))!=null?r:Ht,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,sf),this.windowListeners.add(At.VisibilityChange,this.handleCancel),this.windowListeners.add(At.ContextMenu,sf),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(cf(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(df(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,B2,{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=ii(t))!=null?n:Ht,c=ri(r,d);if(!o&&l){if(df(l)){if(l.tolerance!=null&&ya(c,l.tolerance))return this.handleCancel();if(ya(c,l.distance))return this.handleStart()}if(cf(l)&&ya(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 j2={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ma extends ba{constructor(t){const{event:n}=t,o=uo(n.target);super(t,j2,o)}}ma.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 H2={move:{name:"mousemove"},end:{name:"mouseup"}};var va;(function(e){e[e.RightClick=2]="RightClick"})(va||(va={}));class F2 extends ba{constructor(t){super(t,H2,uo(t.event.target))}}F2.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:o}=t;return n.button===va.RightClick?!1:(o?.({event:n}),!0)}}];const _a={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class K2 extends ba{constructor(t){super(t,_a)}static setup(){return window.addEventListener(_a.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(_a.move.name,t)};function t(){}}}K2.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 qo;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(qo||(qo={}));var ai;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(ai||(ai={}));function V2(e){let{acceleration:t,activator:n=qo.Pointer,canScroll:o,draggingRect:r,enabled:s,interval:a=5,order:l=ai.TreeOrder,pointerCoordinates:d,scrollableAncestors:c,scrollableAncestorRects:p,delta:f,threshold:b}=e;const g=q2({delta:f,disabled:!s}),[m,h]=Q7(),v=u.useRef({x:0,y:0}),y=u.useRef({x:0,y:0}),_=u.useMemo(()=>{switch(n){case qo.Pointer:return d?{top:d.y,bottom:d.y,left:d.x,right:d.x}:null;case qo.DraggableRect:return r}},[n,r,d]),w=u.useRef(null),k=u.useCallback(()=>{const $=w.current;if(!$)return;const S=v.current.x*y.current.x,C=v.current.y*y.current.y;$.scrollBy(S,C)},[]),x=u.useMemo(()=>l===ai.TreeOrder?[...c].reverse():c,[l,c]);u.useEffect(()=>{if(!s||!c.length||!_){h();return}for(const $ of x){if(o?.($)===!1)continue;const S=c.indexOf($),C=p[S];if(!C)continue;const{direction:T,speed:E}=z2($,C,_,t,b);for(const A of["x","y"])g[A][T[A]]||(E[A]=0,T[A]=0);if(E.x>0||E.y>0){h(),w.current=$,m(k,a),v.current=E,y.current=T;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 U2={x:{[lt.Backward]:!1,[lt.Forward]:!1},y:{[lt.Backward]:!1,[lt.Forward]:!1}};function q2(e){let{delta:t,disabled:n}=e;const o=ni(t);return Fo(r=>{if(n||!o||!r)return U2;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 G2(e,t){const n=t!=null?e.get(t):void 0,o=n?n.node.current:null;return Fo(r=>{var s;return t==null?null:(s=o??r)!=null?s:null},[o,t])}function Y2(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 Go;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Go||(Go={}));var xa;(function(e){e.Optimized="optimized"})(xa||(xa={}));const uf=new Map;function X2(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=Ho(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=Fo(y=>{if(f&&!n)return uf;if(!y||y===uf||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 ha(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 Go.Always:return!1;case Go.BeforeDragging:return n;default:return!n}}}function wa(e,t){return Fo(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function J2(e,t){return wa(e,t)}function Z2(e){let{callback:t,disabled:n}=e;const o=ei(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 li(e){let{callback:t,disabled:n}=e;const o=ei(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 Q2(e){return new ha(Vo(e),e)}function pf(e,t,n){t===void 0&&(t=Q2);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=Z2({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=li({callback:s});return sn(()=>{s(),e?(l?.observe(e),a?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),a?.disconnect())},[e]),o}function R2(e){const t=wa(e);return Xp(e,t)}const ff=[];function eI(e){const t=u.useRef(e),n=Fo(o=>e?o&&o!==ff&&e&&t.current&&e.parentNode===t.current.parentNode?o:pa(e):ff,[e]);return u.useEffect(()=>{t.current=e},[e]),n}function tI(e){const[t,n]=u.useState(null),o=u.useRef(e),r=u.useCallback(s=>{const a=fa(s.target);a&&n(l=>l?(l.set(a,ga(a)),new Map(l)):null)},[]);return u.useEffect(()=>{const s=o.current;if(e!==s){a(s);const l=e.map(d=>{const c=fa(d);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,ga(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=fa(d);c?.removeEventListener("scroll",r)})}},[r,e]),u.useMemo(()=>e.length?t?Array.from(t.values()).reduce((s,a)=>po(s,a),Ht):of(e):Ht,[e,t])}function gf(e,t){t===void 0&&(t=[]);const n=u.useRef(null);return u.useEffect(()=>{n.current=null},t),u.useEffect(()=>{const o=e!==Ht;o&&!n.current&&(n.current=e),!o&&n.current&&(n.current=null)},[e]),n.current?ri(e,n.current):Ht}function nI(e){u.useEffect(()=>{if(!Rr)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 oI(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 hf(e){return u.useMemo(()=>e?I2(e):null,[e])}const yf=[];function rI(e,t){t===void 0&&(t=Vo);const[n]=e,o=hf(n?xt(n):null),[r,s]=u.useState(yf);function a(){s(()=>e.length?e.map(d=>tf(d)?o:new ha(t(d),d)):yf)}const l=li({callback:a});return sn(()=>{l?.disconnect(),a(),e.forEach(d=>l?.observe(d))},[e]),r}function bf(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return jo(t)?t:e}function iI(e){let{measure:t}=e;const[n,o]=u.useState(null),r=u.useCallback(c=>{for(const{target:p}of c)if(jo(p)){o(f=>{const b=t(p);return f?{...f,width:b.width,height:b.height}:b});break}},[t]),s=li({callback:r}),a=u.useCallback(c=>{const p=bf(c);s?.disconnect(),p&&s?.observe(p),o(p?t(p):null)},[t,s]),[l,d]=ti(a);return u.useMemo(()=>({nodeRef:l,rect:n,setRef:d}),[n,l,d])}const sI=[{sensor:ma,options:{}},{sensor:lf,options:{}}],aI={current:{}},di={draggable:{measure:Zp},droppable:{measure:Zp,strategy:Go.WhileDragging,frequency:xa.Optimized},dragOverlay:{measure:Vo}};class Yo 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 lI={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Yo,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:si},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:di,measureDroppableContainers:si,windowRect:null,measuringScheduled:!1},mf={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:si,draggableNodes:new Map,over:null,measureDroppableContainers:si},Xo=u.createContext(mf),vf=u.createContext(lI);function dI(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Yo}}}function cI(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 Yo(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 Yo(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 Yo(e.droppable.containers);return s.delete(n),{...e,droppable:{...e.droppable,containers:s}}}default:return e}}function uI(e){let{disabled:t}=e;const{active:n,activatorEvent:o,draggableNodes:r}=u.useContext(Xo),s=ni(o),a=ni(n?.id);return u.useEffect(()=>{if(!t&&!o&&s&&a!=null){if(!ua(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=t2(p);if(f){f.focus();break}}})}},[o,t,r,a,s]),null}function _f(e,t){let{transform:n,...o}=t;return e!=null&&e.length?e.reduce((r,s)=>s({transform:r,...o}),n):n}function pI(e){return u.useMemo(()=>({draggable:{...di.draggable,...e?.draggable},droppable:{...di.droppable,...e?.droppable},dragOverlay:{...di.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function fI(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;sn(()=>{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=Xp(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=Qp(c);b&&b.scrollBy({top:f.y,left:f.x})}},[t,a,l,o,n])}const ci=u.createContext({...Ht,scaleX:1,scaleY:1});var hn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(hn||(hn={}));const gI=u.memo(function(t){var n,o,r,s;let{id:a,accessibility:l,autoScroll:d=!0,children:c,sensors:p=sI,collisionDetection:f=_2,measuring:b,modifiers:g,...m}=t;const h=u.useReducer(cI,void 0,dI),[v,y]=h,[_,w]=a2(),[k,x]=u.useState(hn.Uninitialized),$=k===hn.Initialized,{draggable:{active:S,nodes:C,translate:T},droppable:{containers:E}}=v,A=S!=null?C.get(S):null,N=u.useRef({initial:null,translated:null}),D=u.useMemo(()=>{var Q;return S!=null?{id:S,data:(Q=A?.data)!=null?Q:aI,rect:N}:null},[S,A]),B=u.useRef(null),[M,O]=u.useState(null),[z,H]=u.useState(null),P=Ho(m,Object.values(m)),I=oi("DndDescribedBy",a),L=u.useMemo(()=>E.getEnabled(),[E]),F=pI(b),{droppableRects:Y,measureDroppableContainers:K,measuringScheduled:X}=X2(L,{dragging:$,dependencies:[T.x,T.y],config:F.droppable}),Z=G2(C,S),ae=u.useMemo(()=>z?ii(z):null,[z]),oe=pe(),G=J2(Z,F.draggable.measure);fI({activeNode:S!=null?C.get(S):null,config:oe.layoutShiftCompensation,initialRect:G,measure:F.draggable.measure});const ee=pf(Z,F.draggable.measure,G),ge=pf(Z?Z.parentElement:null),V=u.useRef({activatorEvent:null,active:null,activeNode:Z,collisionRect:null,collisions:null,droppableRects:Y,draggableNodes:C,draggingNode:null,draggingNodeRect:null,droppableContainers:E,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),te=E.getNodeFor((n=V.current.over)==null?void 0:n.id),be=iI({measure:F.dragOverlay.measure}),Ee=(o=be.nodeRef.current)!=null?o:Z,De=$?(r=be.rect)!=null?r:ee:null,Se=!!(be.nodeRef.current&&be.rect),Ue=R2(Se?null:ee),Me=hf(Ee?xt(Ee):null),Oe=eI($?te??Z:null),Ye=rI(Oe),ze=_f(g,{transform:{x:T.x-Ue.x,y:T.y-Ue.y,scaleX:1,scaleY:1},activatorEvent:z,active:D,activeNodeRect:ee,containerNodeRect:ge,draggingNodeRect:De,over:V.current.over,overlayNodeRect:be.rect,scrollableAncestors:Oe,scrollableAncestorRects:Ye,windowRect:Me}),Xe=ae?po(ae,T):null,ve=tI(Oe),qe=gf(ve),We=gf(ve,[ee]),ce=po(ze,qe),q=De?C2(De,ze):null,ie=D&&q?f({active:D,collisionRect:q,droppableRects:Y,droppableContainers:L,pointerCoordinates:Xe}):null,se=m2(ie,"id"),[me,Ce]=u.useState(null),$e=Se?ze:po(ze,We),U=k2($e,(s=me?.rect)!=null?s:null,ee),ue=u.useRef(null),fe=u.useCallback((Q,le)=>{let{sensor:Ae,options:dt}=le;if(B.current==null)return;const pt=C.get(B.current);if(!pt)return;const ot=Q.nativeEvent,Le=new Ae({active:B.current,activeNode:pt,event:ot,options:dt,context:V,onAbort(Je){if(!C.get(Je))return;const{onDragAbort:Dt}=P.current,zt={id:Je};Dt?.(zt),_({type:"onDragAbort",event:zt})},onPending(Je,Tt,Dt,zt){if(!C.get(Je))return;const{onDragPending:wn}=P.current,Zt={id:Je,constraint:Tt,initialCoordinates:Dt,offset:zt};wn?.(Zt),_({type:"onDragPending",event:Zt})},onStart(Je){const Tt=B.current;if(Tt==null)return;const Dt=C.get(Tt);if(!Dt)return;const{onDragStart:zt}=P.current,xn={activatorEvent:ot,active:{id:Tt,data:Dt.data,rect:N}};Cn.unstable_batchedUpdates(()=>{zt?.(xn),x(hn.Initializing),y({type:it.DragStart,initialCoordinates:Je,active:Tt}),_({type:"onDragStart",event:xn}),O(ue.current),H(ot)})},onMove(Je){y({type:it.DragMove,coordinates:Je})},onEnd:je(it.DragEnd),onCancel:je(it.DragCancel)});ue.current=Le;function je(Je){return async function(){const{active:Dt,collisions:zt,over:xn,scrollAdjustedTranslate:wn}=V.current;let Zt=null;if(Dt&&wn){const{cancelDrop:Hn}=P.current;Zt={activatorEvent:ot,active:Dt,collisions:zt,delta:wn,over:xn},Je===it.DragEnd&&typeof Hn=="function"&&await Promise.resolve(Hn(Zt))&&(Je=it.DragCancel)}B.current=null,Cn.unstable_batchedUpdates(()=>{y({type:Je}),x(hn.Uninitialized),Ce(null),O(null),H(null),ue.current=null;const Hn=Je===it.DragEnd?"onDragEnd":"onDragCancel";if(Zt){const ln=P.current[Hn];ln?.(Zt),_({type:Hn,event:Zt})}})}}},[C]),xe=u.useCallback((Q,le)=>(Ae,dt)=>{const pt=Ae.nativeEvent,ot=C.get(dt);if(B.current!==null||!ot||pt.dndKit||pt.defaultPrevented)return;const Le={active:ot};Q(Ae,le.options,Le)===!0&&(pt.dndKit={capturedBy:le.sensor},B.current=dt,fe(Ae,le))},[C,fe]),he=Y2(p,xe);nI(p),sn(()=>{ee&&k===hn.Initializing&&x(hn.Initialized)},[ee,k]),u.useEffect(()=>{const{onDragMove:Q}=P.current,{active:le,activatorEvent:Ae,collisions:dt,over:pt}=V.current;if(!le||!Ae)return;const ot={active:le,activatorEvent:Ae,collisions:dt,delta:{x:ce.x,y:ce.y},over:pt};Cn.unstable_batchedUpdates(()=>{Q?.(ot),_({type:"onDragMove",event:ot})})},[ce.x,ce.y]),u.useEffect(()=>{const{active:Q,activatorEvent:le,collisions:Ae,droppableContainers:dt,scrollAdjustedTranslate:pt}=V.current;if(!Q||B.current==null||!le||!pt)return;const{onDragOver:ot}=P.current,Le=dt.get(se),je=Le&&Le.rect.current?{id:Le.id,rect:Le.rect.current,data:Le.data,disabled:Le.disabled}:null,Je={active:Q,activatorEvent:le,collisions:Ae,delta:{x:pt.x,y:pt.y},over:je};Cn.unstable_batchedUpdates(()=>{Ce(je),ot?.(Je),_({type:"onDragOver",event:Je})})},[se]),sn(()=>{V.current={activatorEvent:z,active:D,activeNode:Z,collisionRect:q,collisions:ie,droppableRects:Y,draggableNodes:C,draggingNode:Ee,draggingNodeRect:De,droppableContainers:E,over:me,scrollableAncestors:Oe,scrollAdjustedTranslate:ce},N.current={initial:De,translated:q}},[D,Z,ie,q,C,Ee,De,Y,E,me,Oe,ce]),V2({...oe,delta:T,draggingRect:q,pointerCoordinates:Xe,scrollableAncestors:Oe,scrollableAncestorRects:Ye});const j=u.useMemo(()=>({active:D,activeNode:Z,activeNodeRect:ee,activatorEvent:z,collisions:ie,containerNodeRect:ge,dragOverlay:be,draggableNodes:C,droppableContainers:E,droppableRects:Y,over:me,measureDroppableContainers:K,scrollableAncestors:Oe,scrollableAncestorRects:Ye,measuringConfiguration:F,measuringScheduled:X,windowRect:Me}),[D,Z,ee,z,ie,ge,be,C,E,Y,me,K,Oe,Ye,F,X,Me]),ne=u.useMemo(()=>({activatorEvent:z,activators:he,active:D,activeNodeRect:ee,ariaDescribedById:{draggable:I},dispatch:y,draggableNodes:C,over:me,measureDroppableContainers:K}),[z,he,D,ee,y,I,C,me,K]);return u.createElement(Yp.Provider,{value:w},u.createElement(Xo.Provider,{value:ne},u.createElement(vf.Provider,{value:j},u.createElement(ci.Provider,{value:U},c)),u.createElement(uI,{disabled:l?.restoreFocus===!1})),u.createElement(c2,{...l,hiddenTextDescribedById:I}));function pe(){const Q=M?.autoScrollEnabled===!1,le=typeof d=="object"?d.enabled===!1:d===!1,Ae=$&&!Q&&!le;return typeof d=="object"?{...d,enabled:Ae}:{enabled:Ae}}}),hI=u.createContext(null),xf="button",yI="Draggable";function bI(e){let{id:t,data:n,disabled:o=!1,attributes:r}=e;const s=oi(yI),{activators:a,activatorEvent:l,active:d,activeNodeRect:c,ariaDescribedById:p,draggableNodes:f,over:b}=u.useContext(Xo),{role:g=xf,roleDescription:m="draggable",tabIndex:h=0}=r??{},v=d?.id===t,y=u.useContext(v?ci:hI),[_,w]=ti(),[k,x]=ti(),$=oI(a,t),S=Ho(n);sn(()=>(f.set(t,{id:t,key:s,node:_,activatorNode:k,data:S}),()=>{const T=f.get(t);T&&T.key===s&&f.delete(t)}),[f,t]);const C=u.useMemo(()=>({role:g,tabIndex:h,"aria-disabled":o,"aria-pressed":v&&g===xf?!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:C,isDragging:v,listeners:o?void 0:$,node:_,over:b,setNodeRef:w,setActivatorNodeRef:x,transform:y}}function mI(){return u.useContext(vf)}const vI="Droppable",_I={timeout:25};function xI(e){let{data:t,disabled:n=!1,id:o,resizeObserverConfig:r}=e;const s=oi(vI),{active:a,dispatch:l,over:d,measureDroppableContainers:c}=u.useContext(Xo),p=u.useRef({disabled:n}),f=u.useRef(!1),b=u.useRef(null),g=u.useRef(null),{disabled:m,updateMeasurementsFor:h,timeout:v}={..._I,...r},y=Ho(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=li({callback:_,disabled:m||!a}),k=u.useCallback((C,T)=>{w&&(T&&(w.unobserve(T),f.current=!1),C&&w.observe(C))},[w]),[x,$]=ti(k),S=Ho(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:S}}),()=>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 wI(e){let{animation:t,children:n}=e;const[o,r]=u.useState(null),[s,a]=u.useState(null),l=ni(n);return!n&&!o&&l&&r(l),sn(()=>{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 kI={x:0,y:0,scaleX:1,scaleY:1};function SI(e){let{children:t}=e;return u.createElement(Xo.Provider,{value:mf},u.createElement(ci.Provider,{value:kI},t))}const CI={position:"fixed",touchAction:"none"},$I=e=>ua(e)?"transform 250ms ease":void 0,EI=u.forwardRef((e,t)=>{let{as:n,activatorEvent:o,adjustScale:r,children:s,className:a,rect:l,style:d,transform:c,transition:p=$I}=e;if(!l)return null;const f=r?c:{...c,scaleX:1,scaleY:1},b={...CI,width:l.width,height:l.height,top:l.top,left:l.left,transform:Ko.Transform.toString(f),transformOrigin:r&&o?g2(o,l):void 0,transition:typeof p=="function"?p(o):p,...d};return u.createElement(n,{className:a,style:b,ref:t},s)}),II={duration:250,easing:"ease",keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:Ko.Transform.toString(t)},{transform:Ko.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 AI(e){let{config:t,draggableNodes:n,droppableContainers:o,measuringConfiguration:r}=e;return ei((s,a)=>{if(t===null)return;const l=n.get(s);if(!l)return;const d=l.node.current;if(!d)return;const c=bf(a);if(!c)return;const{transform:p}=xt(a).getComputedStyle(a),f=Jp(p);if(!f)return;const b=typeof t=="function"?t:TI(t);return rf(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 TI(e){const{duration:t,easing:n,sideEffects:o,keyframes:r}={...II,...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 wf=0;function DI(e){return u.useMemo(()=>{if(e!=null)return wf++,wf},[e])}const zI=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(ci),S=DI(f?.id),C=_f(a,{activatorEvent:p,active:f,activeNodeRect:b,containerNodeRect:g,draggingNodeRect:v.rect,over:y,overlayNodeRect:v.rect,scrollableAncestors:w,scrollableAncestorRects:k,transform:$,windowRect:x}),T=wa(b),E=AI({config:o,draggableNodes:m,droppableContainers:h,measuringConfiguration:_}),A=T?v.setRef:void 0;return u.createElement(SI,null,u.createElement(wI,{animation:E},f&&S?u.createElement(EI,{key:S,id:f.id,ref:A,as:l,activatorEvent:p,adjustScale:t,className:d,transition:s,rect:T,style:{zIndex:c,...r},transform:C},n):null))});function Jo(e,t){return!t||!Array.isArray(t.draggable)?!1:t.draggable.includes(e)}function NI({draggedComponentName:e,targetContainerName:t,nesting:n}){if(!n||!Jo(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 kf(e,t){if(!t?.containers)return!1;const n=t.containers[e];return!!(n&&Array.isArray(n.accepts)&&n.accepts.length>0)}function MI(e,t,n,o,r){if(!n||n.length===0)return{parentPath:[],index:r};if(e&&kf(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 Sf(e,t){return e===t||e.startsWith(`${t}.`)}function Cf(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 LI(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 PI=16;function OI(e){const{frameEl:t,draggedPath:n,acceptsContainer:o,allowsNestSlot:r,includeContainer:s}=e,a=e.normalizeContainerPath??(g=>g),l=t.getBoundingClientRect(),d=LI(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=WI(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="${If(h)}"]`);if(!v&&!m||!m&&Sf(g,p))continue;const y=g;if(!m&&s&&!s(y))continue;const _=$=>{const S=c.get($);if(!S||typeof window>"u")return!1;const C=t.querySelector(`[data-editor-path="${If(S)}"]`);return C?(window.getComputedStyle(C).display??"").toLowerCase()==="contents":!1},w=d.filter($=>Cf(g,$.path)!==null).filter($=>!Sf($.path,p)).filter($=>!_($.path)).map($=>({origIndex:Cf(g,$.path),rect:BI($.rect,$.path,d)})).filter($=>$.rect.width>0||$.rect.height>0).sort(($,S)=>$.origIndex-S.origIndex),k=Op(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(S=>{b.push($f(y,S.origIndex,S.rect,l,x,"before"))});const $=w[w.length-1];b.push($f(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:Ef($,l),orientation:"area"})}else m&&b.push({id:"slot::0",kind:"gap",containerPath:"",index:0,box:Ef(l,l),orientation:"area"})}return b.filter(g=>lo(g.box,t))}function $f(e,t,n,o,r,s){const a=PI;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 BI(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 Ef(e,t){return{left:e.left-t.left,top:e.top-t.top,width:e.width,height:e.height,scale:1}}function WI(e){if(e==="")return null;const t=e.lastIndexOf(".children.");return t<0?"":e.slice(0,t)}function jI(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 If(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[^a-zA-Z0-9_\-.]/g,t=>`\\${t}`)}function ka(e){return typeof e=="string"&&e.length>0?e:null}function Sa(e,t){return t&&e.startsWith(`${t}.`)?t:e}function Af(e){if(typeof e!="string")return null;const t=jI(e);return t?{containerPath:t.containerPath,index:t.index}:null}function Ca(e,t){return t?e.startsWith(`${t}.iteration.`):!1}function $a(e,t,n){return t?n==="iteration_item"?Ca(e,t):e===t||e.startsWith(`${t}.`):!1}function HI(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=Be(x(M),O);return z?typeof z.name=="string"?z.name:typeof z.type=="string"?z.type:null:null},[x]),S=u.useCallback(M=>O=>{const z=w.current;if(O==="")return Jo(M,z.nesting);const H=Re(O),P=Be(x(z.components),H);if(!P)return!1;const I=typeof P.name=="string"?P.name:typeof P.type=="string"?P.type:"";if(!I)return!1;const L=!!z.editableRootSourcePath&&(O===z.editableRootSourcePath||O.startsWith(`${z.editableRootSourcePath}.`));if(z.editableRootSourcePath&&!L)return!1;if(!L){const F=Ea(x(z.components),H);if(gn(P,z.editMode,z.currentExtensionId,F)!=="none")return!1}return kf(I,z.nesting)?NI({draggedComponentName:M,targetContainerName:I,nesting:z.nesting}):!1},[x]),C=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(ui(z,L))return!0}const P=Be(x(O.components),z);return P?(typeof P.name=="string"?P.name:typeof P.type=="string"?P.type:"").length>0:!1},[x]),T=u.useCallback(M=>{const O=S(M),z=w.current,H=k.current,P=H?H.slice(0,-1):null,I=new Set;if(P)for(let K=P.length;K>=0;K--)I.add(pi(P.slice(0,K)));const L=pi(H??[]),F=K=>!!H&&(K===L||K.startsWith(`${L}.`)),Y=(K,X)=>{for(let Z=0;Z<K.length;Z++){const ae=[...X,Z],oe=pi(ae);!I.has(oe)&&!F(oe)&&O(oe)&&C(oe)&&I.add(oe);const G=K[Z];if(G&&Array.isArray(G.children)&&Y(G.children,ae),G&&G.responsive&&typeof G.responsive=="object")for(const ee of Object.keys(G.responsive)){const ge=G.responsive[ee];ge&&Array.isArray(ge.children)&&Y(ge.children,[...ae,{responsive:ee}])}}};return Y(z.components,[]),{acceptsContainer:O,includeContainer:K=>K===""?!0:F(K)?!1:I.has(K),allowsNestSlot:K=>{if(!O(K))return!1;if(P){const X=Re(K);if(ui(X,P))return!1}return C(K)}}},[S,C,x]),E=u.useCallback(M=>{const O=ka(M.active.id),z=w.current;if(!O)return;const H=Sa(O,z.selectedPath),P=Re(H),I=Be(x(z.components),P),L=I&&typeof I.name=="string"?I.name:I&&typeof I.type=="string"?I.type:null;m(H),v(L),_(null),k.current=I?P:null;let F="allowed";if(!L||!Jo(L,z.nesting))F="denied_no_draggable";else if(I){const Y=Ea(x(z.components),P),K=gn(I,z.editMode,z.currentExtensionId,Y);z.editableRootSourcePath&&!$a(H,z.editableRootSourcePath,z.editMode)||Qi(Y)&&!Ca(H,z.editableRootSourcePath)?F="denied_data_bound":K==="base"||K==="partial"?F="denied_base_locked":(K==="extension"||K==="extension_point")&&(F="denied_extension_locked")}$n({source:"drag",draggedComponentName:L,targetContainerName:null,targetContainerPath:null,decision:F,result:F==="allowed"?"completed":"denied",timestamp:Date.now()})},[x]),A=u.useCallback(M=>{if(!t)return;const O=ka(M.active.id);if(!O)return;const z=h;if(!z){_(null);return}const H=w.current,P=Sa(O,H.selectedPath),I=Re(P),L=Be(x(H.components),I);if(!L||!Jo(z,H.nesting)){_(null);return}const F=Ea(x(H.components),I);if(H.editableRootSourcePath&&!$a(P,H.editableRootSourcePath,H.editMode)){_(null);return}const Y=gn(L,H.editMode,H.currentExtensionId,F),K=Ca(P,H.editableRootSourcePath);if(Qi(F)&&!K||Y!=="none"&&Y!=="data_bound"&&!K){_(null);return}_(Af(M.over?.id))},[t,h,x]),N=u.useCallback(()=>{m(null),v(null),_(null),k.current=null},[]),D=u.useCallback(M=>{const O=ka(M.active.id),z=h,H=w.current,P=O?Sa(O,H.selectedPath):null;if(!t||!P||!z){N();return}const I=Af(M.over?.id),L=Re(P);if(!I){$n({source:"drag",draggedComponentName:z,targetContainerName:null,targetContainerPath:null,decision:"denied_no_accepts",result:"cancelled",timestamp:Date.now()}),N();return}const F=I.containerPath===""?[]:Re(I.containerPath),Y=I.containerPath===""?null:$(H.components,F);if(!FI(L.slice(0,-1),F)){$n({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:I.containerPath||null,decision:"denied_responsive_branch_boundary",result:"denied",timestamp:Date.now()}),f?.(),N();return}if(H.editableRootSourcePath&&!$a(I.containerPath,H.editableRootSourcePath,H.editMode)){$n({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:I.containerPath||null,decision:"denied_data_bound",result:"denied",timestamp:Date.now()}),N();return}const K=L.slice(0,-1),X=L[L.length-1]??-1;if(ui(K,F)&&(I.index===X||I.index===X+1)){$n({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:I.containerPath||null,decision:"allowed",insertionIndex:I.index,result:"cancelled",timestamp:Date.now()}),N();return}const oe=ui(K,F),G=I.index;let ee=[];l(be=>{const Se=Bb({children:be},L,F,G).children??[];return ee=Se,Se}),d(ee,`move ${z}`);const ge=dd(F,L),V=oe&&X<G?G-1:G,te=pi([...ge,V]);c?.(te),$n({source:"drag",draggedComponentName:z,targetContainerName:Y,targetContainerPath:I.containerPath||null,decision:"allowed",insertionIndex:I.index,result:"completed",timestamp:Date.now()}),N()},[t,h,S,C,$,l,d,N,c]),B=u.useCallback(()=>{N()},[N]);return{activeDragPath:g,activeDragName:h,activeDropZone:y,onDragStart:E,onDragMove:A,onDragEnd:D,onDragCancel:B,buildSlotPredicates:T}}function Ea(e,t){const n=[];let o=e,r=Array.isArray(e.children)?e.children:[];for(let s=0;s<t.length-1;s++){const a=t[s];if(et(a)){const d=o.responsive?.[a.responsive];r=d&&Array.isArray(d.children)?d.children:[];continue}const l=r[a]??null;if(!l)break;n.push(l),o=l,r=Array.isArray(l.children)?l.children:[]}return n}function ui(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!yr(e[n],t[n]))return!1;return!0}function FI(e,t){const n=e.filter(et),o=t.filter(et);if(n.length!==o.length)return!1;for(let r=0;r<n.length;r++)if(n[r].responsive!==o[r].responsive)return!1;return!0}function pi(e){return at(e)}function KI(e){const t=/^(.*?)\.iteration\.\d+(?:\.|$)/.exec(e);return t?t[1]:null}function VI(e){const t=Re(e);return at(t)}function Zo(e,t){return t?e.startsWith(`${t}.iteration.`):!1}function UI(e,t,n){return t?n==="iteration_item"?Zo(e,t):e===t||e.startsWith(`${t}.`):!1}function qI(e){if(e.length===0)return null;let t=1/0,n=1/0,o=-1/0,r=-1/0;for(const s of e)t=Math.min(t,s.left),n=Math.min(n,s.top),o=Math.max(o,s.left+s.width),r=Math.max(r,s.top+s.height);return{left:t,top:n,width:o-t,height:r-n,scale:e[0].scale}}function GI(e){const{frameEl:t,nesting:n,editMode:o,currentExtensionId:r,editableRootPath:s,components:a,patchLayout:l,pushHistory:d,onSelectPath:c,onMovePath:p,onRequestInlineEdit:f,selectedPath:b}=e,g=(o==="iteration_item"||o==="modal")&&s&&s.length>0?at(s):null,{t:m}=tt(),[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=HI({frameEl:t,nesting:n,editMode:o,currentExtensionId:r,editableRootPath:s,components:a,patchLayout:l,pushHistory:d,onMovePath:p,selectedPath:b,showBranchBoundaryHint:_}),k=p2(u2(ma,{activationConstraint:{distance:8}})),[x,$]=u.useState([]),S=u.useCallback(()=>{if(!t){$([]);return}if(w.activeDragPath!==null)return;const P={children:a},I=t.querySelectorAll("[data-editor-path]"),L=[],F=new Map;I.forEach(Y=>{const K=Y.dataset.editorPath;if(typeof K!="string"||o!=="iteration_item"&&g&&!UI(K,g,o))return;const X=KI(K);if(X!==null&&!Zo(K,g)){if(/\.iteration\.\d+$/.test(K)){const V=ao(Y,t);if(V&&lo(V,t)){const te=F.get(X)??[];te.push(V),F.set(X,te)}}return}if(Zo(K,g)&&/\.iteration\.\d+$/.test(K))return;const Z=Re(K),ae=Be(P,Z);if(!ae||ae.iteration&&ae.iteration.source!==void 0)return;const oe=typeof ae.name=="string"?ae.name:typeof ae.type=="string"?ae.type:null;if(!oe||!Jo(oe,n))return;const G=Df(P,Z);if(Qi(G)&&!Zo(K,g))return;const ee=gn(ae,o,r,G);if(ee!=="none"&&ee!=="data_bound"&&!Zo(K,g))return;const ge=ao(Y,t);ge&&lo(ge,t)&&L.push({path:K,name:oe,box:ge})});for(const[Y,K]of F){const X=Re(Y),Z=Be(P,X);if(!Z)continue;const ae=typeof Z.name=="string"?Z.name:typeof Z.type=="string"?Z.type:null;if(!ae)continue;const oe=Df(P,X),G=gn(Z,o,r,oe);if(G!=="none"&&G!=="data_bound")continue;const ee=qI(K);ee&&lo(ee,t)&&L.push({path:Y,name:ae,box:ee,isIterationGroup:!0})}$(L)},[t,a,n,o,r,g,w.activeDragPath]);u.useEffect(()=>{S()},[S]),u.useEffect(()=>{if(t)return zp(S,t)},[t,S]);const C=w.activeDragPath!==null,T=w.activeDragName,E=w.activeDragPath,[A,N]=u.useState(null),D=u.useRef(null);u.useEffect(()=>{if(!E||!t){E||(D.current=null,N(null));return}if(D.current===E)return;D.current=E;const P=t.querySelector(`[data-editor-path="${Tf(E)}"]`);if(P){const oe=P.getBoundingClientRect();N({node:P.cloneNode(!0),width:oe.width,height:oe.height});return}const I=Array.from(t.querySelectorAll(`[data-editor-path^="${Tf(E)}.iteration."]`)).filter(oe=>/\.iteration\.\d+$/.test(oe.dataset.editorPath??""));if(I.length===0){N(null);return}let L=1/0,F=1/0,Y=-1/0,K=-1/0;for(const oe of I){const G=oe.getBoundingClientRect();L=Math.min(L,G.left),F=Math.min(F,G.top),Y=Math.max(Y,G.right),K=Math.max(K,G.bottom)}const X=Y-L,Z=K-F,ae=document.createElement("div");ae.style.position="relative",ae.style.width=`${X}px`,ae.style.height=`${Z}px`;for(const oe of I){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",ae.appendChild(ee)}N({node:ae,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||!T||!t){O.current=null,M(F=>F.length===0?F:[]);return}if(O.current===E)return;O.current=E;const{acceptsContainer:P,allowsNestSlot:I,includeContainer:L}=z.current(T);M(OI({frameEl:t,draggedPath:E,acceptsContainer:P,allowsNestSlot:I,includeContainer:L,normalizeContainerPath:F=>VI(F)}))},[E,T,t]),!t)return null;const H=w.activeDropZone?`slot:${w.activeDropZone.containerPath}:${w.activeDropZone.index}`:null;return i.jsxs(gI,{sensors:k,collisionDetection:w2,onDragStart:w.onDragStart,onDragMove:w.onDragMove,onDragEnd:w.onDragEnd,onDragCancel:w.onDragCancel,children:[x.map(P=>i.jsx(JI,{path:P.path,name:P.name,box:P.box,dimmed:C&&w.activeDragPath!==P.path,isIterationGroup:P.isIterationGroup,onSelect:c,onRequestInlineEdit:f},P.path)),C&&B.map(P=>i.jsx(XI,{slot:P,active:P.id===H},P.id)),Cn.createPortal(i.jsx(zI,{dropAnimation:null,zIndex:Fp,children:T?A?i.jsx(YI,{name:T,node:A.node,width:A.width,height:A.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:`<${T}>`}):null}),document.body),h&&Cn.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:Fp},children:["⚠️ ",m("layout_editor.overlay.branch_boundary_denied")]}),t)]})}function YI(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 XI(e){const{slot:t,active:n}=e,{setNodeRef:o}=xI({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:H7,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 Tf(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[^a-zA-Z0-9_\-.]/g,t=>`\\${t}`)}function JI(e){const{path:t,box:n,dimmed:o,isIterationGroup:r,onSelect:s,onRequestInlineEdit:a}=e,{attributes:l,listeners:d,setNodeRef:c,isDragging:p}=bI({id:t}),f=(t.match(/\.children\./g)||[]).length,b=F7(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 Df(e,t){const n=[];let o=e,r=Array.isArray(e.children)?e.children:[];for(let s=0;s<t.length-1;s++){const a=t[s];if(et(a)){const d=o.responsive?.[a.responsive];r=d&&Array.isArray(d.children)?d.children:[];continue}const l=r[a]??null;if(!l)break;n.push(l),o=l,r=Array.isArray(l.children)?l.children:[]}return n}function ZI(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(!Ri(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 QI(e){return at(e)}function fi(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function RI({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 _=ZI(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 S=QI($),C=e.querySelector(`[data-editor-path="${fi(S)}"]`);let T=null;if(C){const E=C.getBoundingClientRect();E.width>0&&E.height>0&&(T={left:E.left,top:E.top,width:E.width,height:E.height})}if(!T){const E=Array.from(e.querySelectorAll(`[data-editor-path^="${fi(S)}.iteration."], [data-editor-path^="${fi(S)}.sortable."], [data-editor-path^="${fi(S)}.children."]`));let A=1/0,N=1/0,D=-1/0,B=-1/0;for(const M of E){const O=M.getBoundingClientRect();O.width<=0||O.height<=0||(A=Math.min(A,O.left),N=Math.min(N,O.top),D=Math.max(D,O.right),B=Math.max(B,O.bottom))}if(D>A&&B>N&&(T={left:A,top:N,width:D-A,height:B-N}),T&&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&&(T={left:O.left,top:O.top,width:O.width,height:O.height})}}}T&&x.push({left:T.left-w.left,top:T.top-w.top,width:T.width,height:T.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=($,S,C)=>Math.max(S,Math.min(C,$)),_=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:Hp,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:Hp,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 zf(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 eA(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 tA(e,t,n,o,r){const s=eA(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 nA(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 Nf(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}=tt(),g=u.useMemo(()=>{if(!c||!b)return f;const A=p??null;return N=>{const D={templateId:c,locale:A??"ko"},B=b.translate(N,D);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(()=>A=>{const N=_?.[A.name];return N?.label?gi(N.label,g):A.description??A.name},[_,g]),k=u.useMemo(()=>tA(t,n,s,m,w),[t,n,s,m,w]),x=u.useMemo(()=>nA(k,o??null),[k,o]),$=x.find(A=>A.key===v)??x[0]??null,S=!n||!n.draggable&&!n.containers,C=k.length===0,T=$?.entries??[],E=A=>{const N=_?.[A.name],D=!!N?.defaultNode&&typeof N.defaultNode=="object";if(N?.requiresDefaultNode&&!D)return;const B=D?JSON.parse(JSON.stringify(N.defaultNode)):zf(A),M=r??[];a(B,M,l),$n({source:"palette",draggedComponentName:A.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:sA,children:[i.jsxs("div",{style:aA,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:lA,children:"×"})]}),i.jsxs("div",{style:dA,children:[i.jsx("aside",{style:cA,"data-testid":"g7le-palette-sidebar",children:i.jsx("nav",{children:i.jsx("ul",{style:uA,children:x.map(A=>{const N=$?.key===A.key,D=A.isI18nKey?gi(A.label,g):A.label;return i.jsx("li",{children:i.jsxs("button",{type:"button","data-testid":`g7le-palette-category-${A.key}`,"data-active":N?"true":"false",onClick:()=>y(A.key),style:{...pA,background:N?"#eff6ff":"transparent",color:N?"#1d4ed8":"#334155",fontWeight:N?600:500},children:[i.jsx("span",{children:D}),i.jsx("span",{style:yA,children:A.entries.length})]})},A.key)})})})}),i.jsxs("main",{style:fA,children:[i.jsx("input",{type:"text",placeholder:f("layout_editor.palette.search_placeholder"),value:m,onChange:A=>h(A.target.value),"data-testid":"g7le-palette-search",style:gA}),i.jsx("div",{style:hA,children:S?i.jsx("div",{style:Mf,"data-testid":"g7le-palette-spec-missing",children:f("layout_editor.palette.spec_missing")}):C||T.length===0?i.jsx("div",{style:Mf,"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:bA,children:T.map(A=>i.jsx(oA,{entry:A,entrySpec:_?.[A.name]??null,onClick:E,t:f,entryT:g},A.name))})})})]})]})]})}function oA(e){const{entry:t,entrySpec:n,onClick:o,t:r,entryT:s}=e,a=n?.label?gi(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?gi(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?vA:mA,children:[i.jsx("div",{style:xA,"aria-hidden":"true",children:iA(t)}),i.jsx("div",{style:wA,children:a}),i.jsx("div",{"data-testid":`g7le-palette-item-${t.name}-tag`,style:kA,children:`<${t.name}>`}),d&&i.jsx("div",{"data-testid":`g7le-palette-item-${t.name}-badge`,style:rA(l),children:l}),f&&i.jsx("div",{"data-testid":`g7le-palette-item-${t.name}-default-missing-badge`,style:_A,children:r("layout_editor.palette.default_node_missing_badge")})]})}function gi(e,t){return e.startsWith("$t:")?t(e.slice(3)):t(e)}function rA(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 iA(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 sA={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'},aA={display:"flex",justifyContent:"space-between",alignItems:"center",padding:"14px 20px",borderBottom:"1px solid #e2e8f0",flexShrink:0},lA={background:"transparent",border:"none",fontSize:24,cursor:"pointer",lineHeight:1,color:"#64748b",padding:"0 4px"},dA={display:"flex",flex:1,minHeight:0},cA={width:180,flexShrink:0,borderRight:"1px solid #e2e8f0",padding:"14px 8px",background:"#f8fafc",overflowY:"auto"},uA={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:4},pA={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"},fA={flex:1,display:"flex",flexDirection:"column",minHeight:0,padding:"14px 20px"},gA={width:"100%",padding:"8px 10px",border:"1px solid #cbd5e1",borderRadius:6,marginBottom:12,fontSize:13,flexShrink:0,boxSizing:"border-box"},hA={flex:1,overflowY:"auto",minHeight:0},yA={fontSize:11,color:"#94a3b8",marginLeft:8,fontWeight:500},bA={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"},vA={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},_A={fontSize:9,fontWeight:600,color:"#92400e",background:"#fef3c7",padding:"1px 6px",borderRadius:999,textTransform:"none",letterSpacing:0,lineHeight:1.6},xA={fontSize:22,lineHeight:1,color:"#475569"},wA={fontSize:12,fontWeight:500,color:"#0f172a",textAlign:"center",wordBreak:"break-word"},kA={fontFamily:'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',fontSize:10,color:"#64748b",textAlign:"center",wordBreak:"break-all"},Mf={padding:24,color:"#64748b",fontSize:13,textAlign:"center"};function SA(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 Lf(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 SA(o))n(a)};if(Array.isArray(e))for(const o of e)o&&typeof o=="object"&&n(o);return t}const CA=["scroll","selector","wizard","slider"];function $A(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 CA)n.add(`${o}-${r}`)}return Array.from(n)}function EA(e,t,n){const o=t.label;return typeof o=="string"?o.startsWith("$t:")?n(o.slice(3)):o:e}function hi({controlKey:e,control:t,node:n,t:o,onPatch:r,candidates:s,bindingCandidates:a,scope:l=Wt}){const d=Tn(t.widget),c=EA(e,t,o),p=u.useMemo(()=>zo(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&&!Ys(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(_=>{if(g)return;const w=fn(n,t,_,l);r(w)},[n,t,r,l,g]);return i.jsxs("div",{className:"g7le-control-row","data-testid":`g7le-control-${e}`,style:IA,children:[i.jsxs("span",{className:"g7le-control-label",style:AA,children:[c,p.conflict&&i.jsx("span",{"data-testid":`g7le-control-conflict-${e}`,title:o("layout_editor.property_modal.value_conflict"),style:TA,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:_=>y(_),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:_=>y(_===""?void 0:_),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")}):d?i.jsx(d,{control:t,value:p.value,onChange:y,t:o,candidates:s,bindingCandidates:a,freeValueDisabled:h}):i.jsx("span",{"data-testid":`g7le-control-unsupported-${e}`,style:DA,children:o("layout_editor.property_modal.unsupported_widget")})})]})}const IA={display:"flex",alignItems:"center",gap:12,padding:"6px 0",minHeight:32,minWidth:0},AA={fontSize:12,color:"#475569",minWidth:88,display:"inline-flex",alignItems:"center",gap:4},TA={display:"inline-flex",width:14,height:14,borderRadius:7,background:"#f59e0b",color:"#fff",fontSize:10,alignItems:"center",justifyContent:"center",fontWeight:700},DA={fontSize:11,color:"#94a3b8",fontStyle:"italic"},zA={fontSize:11,color:"#94a3b8",fontStyle:"italic"};function yi(e,t,n){return typeof e=="string"?e.startsWith("$t:")?n(e.slice(3)):e:t}function NA(e,t){const n=e.props??{};return t.key in n?n[t.key]:t.default}function MA({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:PA,children:r.map((s,a)=>i.jsxs("div",{className:"g7le-settings-group",style:OA,children:[i.jsx("div",{style:BA,children:yi(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:WA,children:[i.jsx("span",{style:jA,children:yi(l.label,l.key,n)}),i.jsx("div",{style:{flex:1},children:LA(l,t,n,o)})]},l.key))]},a))})}function LA(e,t,n,o){const r=NA(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:Ia});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:Ia});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:HA,"data-testid":`g7le-setting-input-${e.key}`,children:(e.options??[]).map(a=>{const l=s.includes(a.value);return i.jsxs("label",{style:FA,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)}}),yi(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:Ia,children:[i.jsx("option",{value:"",children:"—"}),(e.options??[]).map(s=>i.jsx("option",{value:String(s.value),children:yi(s.label,String(s.value),n)},String(s.value)))]})}}const PA={display:"flex",flexDirection:"column",gap:16},OA={display:"flex",flexDirection:"column",gap:6},BA={fontSize:12,fontWeight:700,color:"#0f172a",borderBottom:"1px solid #e2e8f0",paddingBottom:4},WA={display:"flex",alignItems:"center",gap:12,minHeight:30},jA={fontSize:12,color:"#475569",minWidth:96},Ia={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",boxSizing:"border-box"},HA={display:"flex",flexWrap:"wrap",gap:10},FA={display:"inline-flex",alignItems:"center",gap:4,fontSize:12,color:"#0f172a"},KA=["data_binding","isolatedScopeId","parentFormContextProp","skipBindingKeys","isolatedState","component_layout","sortable","itemTemplate"],VA=/\{\{|\$switch|\$get|\|\s*(date|number|truncate|currency|relative)\b/;function bi(e,t=0){return t>6?!1:typeof e=="string"?VA.test(e):Array.isArray(e)?e.some(n=>bi(n,t+1)):e&&typeof e=="object"?Object.values(e).some(n=>bi(n,t+1)):!1}function UA(e){if(td(e))return!1;const t=ql(e);return t.length===0?!1:t.some(n=>n.isComplex)}function Pf(e){const t=[],n=e.props??{};for(const o of KA)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"?UA(e.text)&&t.push({key:"text",kind:"complex_expression"}):bi(e.text)&&t.push({key:"text",kind:"complex_expression"});for(const[o,r]of Object.entries(n))o==="style"||o==="className"||bi(r)&&t.push({key:`props.${o}`,kind:"complex_expression"});return t}function qA(e){return Pf(e).length>0}const GA=new Set(["permissions","blur_until_loaded","comment"]);function YA({node:e,advanced:t,t:n,onPatch:o,permissionCandidates:r}){const s=u.useMemo(()=>Pf(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:XA,children:[t.map(l=>{if(!GA.has(l))return i.jsxs("div",{"data-testid":`g7le-advanced-deferred-${l}`,style:ZA,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:Aa,children:[i.jsx("div",{style:Ta,children:n("layout_editor.property_modal.advanced.permissions")}),i.jsx(vs,{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:Aa,children:[i.jsx("div",{style:Ta,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:Aa,children:[i.jsx("div",{style:Ta,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:JA})]},l)}),s.length>0&&i.jsxs("div",{className:"g7le-advanced-preserved","data-testid":"g7le-advanced-preserved",style:QA,children:[i.jsx("div",{style:RA,children:n("layout_editor.property_modal.advanced_preserved_title",{count:s.length})}),i.jsx("ul",{style:e6,children:s.map(l=>i.jsxs("li",{"data-testid":`g7le-advanced-preserved-${l.key}`,style:t6,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 XA={display:"flex",flexDirection:"column",gap:14},Aa={display:"flex",flexDirection:"column",gap:6},Ta={fontSize:12,fontWeight:700,color:"#0f172a"},JA={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,width:"100%",boxSizing:"border-box"},ZA={fontSize:11,color:"#94a3b8",fontStyle:"italic"},QA={borderTop:"1px dashed #cbd5e1",paddingTop:10,marginTop:4},RA={fontSize:11,color:"#b45309",marginBottom:6},e6={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:4},t6={display:"flex",justifyContent:"space-between",gap:8,padding:"3px 0"},n6={onClick:"click",onHover:"mouseenter",onChange:"change",onSubmit:"submit",onMount:"mount",onUnmount:"unmount",onFocus:"focus",onBlur:"blur"};function Da(e){return n6[e]??e.replace(/^on/,"").toLowerCase()}function Of(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=Da(s);for(const d of a)d&&typeof d=="object"&&r.push("type"in d?d:{type:l,...d})}return r}return[]}function o6(e,t){const n=Da(t);return Of(e).filter(o=>o.type===n||t==="onClick"&&o.type===void 0)}function r6(e,t,n){const o=Da(t),r=Of(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 i6({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:Bf,children:o("layout_editor.action.no_events")}):!c||Object.keys(c).length===0?i.jsx("div",{"data-testid":"g7le-action-no-recipes",style:Bf,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:s6,children:o(`layout_editor.action.event.${b}`)}),i.jsx(Gt,{actions:o6(e,b),onChange:g=>r(r6(e,b,g)),t:o,recipes:c,candidatePools:p,actionChipCandidates:t?.actionChipCandidates??null,addContext:"component",showSourceBadge:!0,testIdPrefix:`g7le-action-slot-${b}`})]},b))})}const Bf={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},s6={fontSize:12,fontWeight:700,color:"#475569",marginBottom:6};function za(e,t,n){if(!t)return n;const o=e(t);return!o||o===t||o.startsWith("$t:")?n:o}function a6(e,t){return za(t,e.labelKey,e.path||e.sourceId)}function l6({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(()=>Kt(a),[a]),c=l!==void 0&&l!==""&&d===null,[p,f]=u.useState(!1),[b,g]=u.useState(""),m=za(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(()=>Ui(n,t.shape).map(x=>({...x,resolvedLabel:a6(x,o)})),[n,t.shape,o]),y=u.useMemo(()=>qi(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=>{_(En(k.sourceId,k.path,t.shape)),f(!1),g("")};return i.jsxs("div",{"data-testid":`g7le-binding-row-${t.propKey}`,style:p6,children:[i.jsxs("div",{style:f6,children:[i.jsx("span",{style:{fontWeight:600,fontSize:12},children:m}),i.jsx("span",{style:g6,children:h}),t.required&&i.jsx("span",{"data-testid":`g7le-binding-required-${t.propKey}`,style:h6,children:o("layout_editor.binding.required")})]}),c?i.jsxs("div",{"data-testid":`g7le-binding-complex-${t.propKey}`,style:v6,children:[o("layout_editor.binding.complex"),i.jsx("code",{style:Wf,children:l})]}):d?i.jsxs("div",{style:y6,children:[i.jsx("code",{"data-testid":`g7le-binding-expr-${t.propKey}`,style:Wf,children:l}),i.jsx("button",{type:"button","data-testid":`g7le-binding-clear-${t.propKey}`,onClick:()=>_(void 0),style:m6,children:o("layout_editor.binding.clear")})]}):i.jsx("div",{"data-testid":`g7le-binding-empty-${t.propKey}`,style:b6,children:o("layout_editor.binding.not_connected")}),d&&(t.shape==="array"||t.shape==="object")&&t.itemFields&&t.itemFields.length>0&&i.jsxs("div",{style:_6,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:x6,children:["🔍 ",o("layout_editor.binding.search")]}),p&&i.jsxs("div",{"data-testid":`g7le-binding-picker-${t.propKey}`,style:w6,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:k6}),i.jsx("div",{style:S6,children:y.length===0?i.jsx("div",{style:C6,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:$6,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:E6,children:[za(o,k.groupLabelKey,k.sourceId)," · ",k.path||k.sourceId]})]}),i.jsx("span",{style:I6,children:k.preview})]},k.expression))})]})]})]})}function d6({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:c6,children:[i.jsxs("div",{style:u6,children:["🔗 ",o("layout_editor.binding.section_title")]}),t.map(s=>i.jsx(l6,{node:e,spec:s,candidates:n,t:o,onPatchNode:r},s.propKey)),i.jsx("div",{style:A6})]})}const c6={display:"flex",flexDirection:"column",marginBottom:8},u6={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:6},p6={display:"flex",flexDirection:"column",gap:4,padding:"8px 0"},f6={display:"flex",alignItems:"center",gap:6},g6={fontSize:10,padding:"1px 6px",borderRadius:4,background:"#e0e7ff",color:"#3730a3"},h6={fontSize:10,padding:"1px 6px",borderRadius:4,background:"#fef3c7",color:"#92400e"},y6={display:"flex",alignItems:"center",gap:6},b6={fontSize:11,color:"#94a3b8"},Wf={fontSize:11,fontFamily:"monospace",background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},m6={fontSize:11,border:"1px solid #e2e8f0",borderRadius:4,background:"#fff",color:"#dc2626",padding:"2px 8px",cursor:"pointer"},v6={display:"flex",flexDirection:"column",gap:2,fontSize:11,color:"#64748b"},_6={fontSize:10,color:"#94a3b8"},x6={fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#334155",padding:"4px 10px",cursor:"pointer",textAlign:"left",width:"100%"},w6={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6},k6={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},S6={marginTop:4,maxHeight:200,overflowY:"auto",display:"flex",flexDirection:"column",gap:2},C6={fontSize:11,color:"#94a3b8",padding:"8px 0",textAlign:"center"},$6={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:"none",background:"transparent",cursor:"pointer",padding:"6px 8px",borderRadius:4,textAlign:"left"},E6={fontSize:10,color:"#94a3b8"},I6={fontSize:10,color:"#64748b",fontFamily:"monospace",whiteSpace:"nowrap"},A6={borderTop:"1px solid #e2e8f0",marginTop:4};function T6({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=td(s)&&(vt(s)?.key.startsWith("custom.")??!1)||b,h=u.useMemo(()=>m?vt(s):null,[m,s]),v=u.useMemo(()=>m?[]:ql(s),[m,s]),y=T=>{o({...e,text:T})},_=()=>{if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:l,locale:c}}))}catch{}},w=(T,E)=>{const A=En(E.sourceId,E.path,"scalar");y(Ab(s,T,A))},k=T=>{const E=vt(s);y(vo(s,T));const A=E?.key;l&&A&&qd(l,A,T).then(_)},x=T=>{const E=n(T);return E&&E!==T&&!E.startsWith("$t:")?E:""},$=T=>T.replace(/\$t:[a-zA-Z0-9._-]+/g,E=>x(E.slice(3))).replace(/\s+/g," ").trim(),S=T=>{p||(f(!0),us(l,d,c,s,s.length,T.sourceId,T.path,"scalar",$,E=>n(E)).then(E=>{E.kind==="ok"&&(y(E.text),_())}).finally(()=>f(!1)))},C=T=>{p||!h&&!b||(f(!0),Cr(l,c,s,Number.MAX_SAFE_INTEGER,T.sourceId,T.path,"scalar").then(E=>{E.kind==="ok"&&(y(E.text),_())}).finally(()=>f(!1)))};if(m){const T=h?.params??[];return i.jsxs("div",{"data-testid":"g7le-inline-binding-section",style:jf,children:[i.jsxs("div",{style:Hf,children:["🔗 ",n("layout_editor.inline_binding.section_title")]}),T.length===0?i.jsx("div",{"data-testid":"g7le-inline-binding-none",style:Vf,children:n("layout_editor.inline_binding.none")}):T.map(E=>i.jsx("div",{"data-testid":`g7le-inline-binding-param-${E.name}`,style:Ff,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:Na,children:E.expression})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:Kf,children:[i.jsx("code",{"data-testid":`g7le-inline-binding-param-expr-${E.name}`,style:Na,children:E.expression}),i.jsx("button",{type:"button","data-testid":`g7le-inline-binding-param-clear-${E.name}`,onClick:()=>k(E.name),style:D6,children:n("layout_editor.inline_binding.clear")})]}),i.jsx($t,{candidates:t,t:n,onSelect:A=>w(E.name,A),testIdSuffix:`param-${E.name}`})]})},E.name)),i.jsxs("div",{"data-testid":"g7le-inline-binding-param-append",style:Uf,children:[i.jsx("div",{style:Ma,children:n("layout_editor.inline_binding.append_hint")}),i.jsx($t,{candidates:t,t:n,onSelect:C,testIdSuffix:"param-append"})]}),i.jsx("div",{"data-testid":"g7le-inline-binding-param-hint",style:Ma,children:n("layout_editor.inline_binding.param_hint")}),i.jsx("div",{style:qf})]})}return i.jsxs("div",{"data-testid":"g7le-inline-binding-section",style:jf,children:[i.jsxs("div",{style:Hf,children:["🔗 ",n("layout_editor.inline_binding.section_title")]}),v.length===0?i.jsx("div",{"data-testid":"g7le-inline-binding-none",style:Vf,children:n("layout_editor.inline_binding.none")}):v.map(T=>i.jsx("div",{"data-testid":`g7le-inline-binding-row-${T.bindingIndex}`,style:Ff,children:i.jsx("div",{style:Kf,children:i.jsx("code",{"data-testid":`g7le-inline-binding-expr-${T.bindingIndex}`,style:Na,children:T.expression})})},T.bindingIndex)),i.jsxs("div",{"data-testid":"g7le-inline-binding-append",style:Uf,children:[i.jsx("div",{style:Ma,children:n("layout_editor.inline_binding.append_hint")}),i.jsx($t,{candidates:t,t:n,onSelect:S,testIdSuffix:"append"})]}),i.jsx("div",{style:qf})]})}const jf={display:"flex",flexDirection:"column",marginBottom:8},Hf={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:6},Ff={display:"flex",flexDirection:"column",gap:4,padding:"8px 0"},Kf={display:"flex",alignItems:"center",gap:6},Vf={fontSize:11,color:"#94a3b8"},Na={fontSize:11,fontFamily:"monospace",background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},D6={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"},Uf={display:"flex",flexDirection:"column",gap:2,padding:"8px 0 0"},Ma={fontSize:11,color:"#475569",fontWeight:600},qf={borderTop:"1px solid #e2e8f0",marginTop:4};function Gf(e,t,n){if(!t)return n;const o=e(t);return!o||o===t||o.startsWith("$t:")?n:o}function N6(e,t){return Gf(t,e.labelKey,e.path||e.sourceId)}function M6(e){const t=e.iteration;return t&&typeof t=="object"?t:null}function L6({node:e,candidates:t,t:n,onPatchNode:o}){const r=M6(e),s=r?.source,a=typeof s=="string"?s:void 0,l=u.useMemo(()=>Kt(s),[s]),d=a!==void 0&&a!==""&&l===null,[c,p]=u.useState(!1),[f,b]=u.useState(""),g=u.useMemo(()=>Ui(t,"array").map(k=>({...k,resolvedLabel:N6(k,n)})),[t,n]),m=u.useMemo(()=>qi(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(En(w.sourceId,w.path,"array")),p(!1),b("")};return i.jsxs("div",{"data-testid":"g7le-iteration-binding-section",style:P6,children:[i.jsxs("div",{style:O6,children:["🔁 ",n("layout_editor.binding.iteration_title")]}),i.jsx("div",{style:B6,children:n("layout_editor.binding.iteration_hint")}),i.jsxs("div",{style:W6,children:[i.jsxs("div",{style:j6,children:[i.jsx("span",{style:{fontWeight:600,fontSize:12},children:n("layout_editor.binding.iteration_label")}),i.jsx("span",{style:H6,children:n("layout_editor.binding.shape_array")})]}),d?i.jsxs("div",{"data-testid":"g7le-iteration-binding-complex",style:U6,children:[n("layout_editor.binding.complex"),i.jsx("code",{style:Yf,children:a})]}):l?i.jsxs("div",{style:F6,children:[i.jsx("code",{"data-testid":"g7le-iteration-binding-expr",style:Yf,children:a}),i.jsx("button",{type:"button","data-testid":"g7le-iteration-binding-clear",onClick:()=>y(void 0),style:V6,children:n("layout_editor.binding.clear")})]}):i.jsx("div",{"data-testid":"g7le-iteration-binding-empty",style:K6,children:n("layout_editor.binding.not_connected")}),(h||v)&&i.jsxs("div",{"data-testid":"g7le-iteration-vars",style:q6,children:[h&&i.jsxs("span",{children:[n("layout_editor.binding.iteration_item_var"),": ",i.jsx("code",{style:Xf,children:h})]}),v&&i.jsxs("span",{children:[n("layout_editor.binding.iteration_index_var"),": ",i.jsx("code",{style:Xf,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:G6,children:["🔍 ",n("layout_editor.binding.search")]}),c&&i.jsxs("div",{"data-testid":"g7le-iteration-binding-picker",style:Y6,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:X6}),i.jsx("div",{style:J6,children:m.length===0?i.jsx("div",{style:Z6,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:Q6,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:R6,children:[Gf(n,w.groupLabelKey,w.sourceId)," · ",w.path||w.sourceId]})]}),i.jsx("span",{style:eT,children:w.preview})]},w.expression))})]})]})]}),i.jsx("div",{style:tT})]})}const P6={display:"flex",flexDirection:"column",marginBottom:8},O6={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:4},B6={fontSize:10,color:"#94a3b8",marginBottom:6,lineHeight:1.4},W6={display:"flex",flexDirection:"column",gap:4,padding:"8px 0"},j6={display:"flex",alignItems:"center",gap:6},H6={fontSize:10,padding:"1px 6px",borderRadius:4,background:"#e0e7ff",color:"#3730a3"},F6={display:"flex",alignItems:"center",gap:6},K6={fontSize:11,color:"#94a3b8"},Yf={fontSize:11,fontFamily:"monospace",background:"#f1f5f9",padding:"2px 6px",borderRadius:4,color:"#0f172a",wordBreak:"break-all"},V6={fontSize:11,border:"1px solid #e2e8f0",borderRadius:4,background:"#fff",color:"#dc2626",padding:"2px 8px",cursor:"pointer"},U6={display:"flex",flexDirection:"column",gap:2,fontSize:11,color:"#64748b"},q6={display:"flex",gap:12,fontSize:10,color:"#94a3b8",marginTop:2},Xf={fontSize:10,fontFamily:"monospace",background:"#f1f5f9",padding:"1px 4px",borderRadius:3,color:"#475569"},G6={fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#334155",padding:"4px 10px",cursor:"pointer",textAlign:"left",width:"100%"},Y6={marginTop:4,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",padding:6},X6={width:"100%",padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"},J6={marginTop:4,maxHeight:200,overflowY:"auto",display:"flex",flexDirection:"column",gap:2},Z6={fontSize:11,color:"#94a3b8",padding:"8px 0",textAlign:"center"},Q6={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:"none",background:"transparent",cursor:"pointer",padding:"6px 8px",borderRadius:4,textAlign:"left"},R6={fontSize:10,color:"#94a3b8"},eT={fontSize:10,color:"#64748b",fontFamily:"monospace",whiteSpace:"nowrap"},tT={borderTop:"1px solid #e2e8f0",marginTop:4},nT=new Set(["Span","P","H1","H2","H3","H4","H5","H6","A","Button","Li","Label"]);function oT(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 nT.has(o)?!0:typeof e.text=="string"}const yn={direction:"flexDirection",justify:"flexJustify",align:"flexAlign",wrap:"flexWrap",gap:"flexGap",enable:"flexEnable"},mi={grow:"flexItemGrow",selfAlign:"flexItemAlign",order:"flexItemOrder"};function Jf(e){const t=e?.flexEditor;return t==="container"||t==="item"||t==="auto"?t:null}function rT(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 iT(e,t,n=Wt){if(!e||!t)return!1;const o=zo(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 sT(e,t,n=!1,o=!1,r=Wt){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:rT(t))?{showContainer:!0,showEnableButton:!1,showDisableButton:o}:{showContainer:!1,showEnableButton:!0,showDisableButton:!1}}return{showContainer:!1,showEnableButton:!1,showDisableButton:!1}}const aT={[yn.direction]:"layout_editor.flex.direction",[yn.justify]:"layout_editor.flex.justify",[yn.align]:"layout_editor.flex.align",[yn.wrap]:"layout_editor.flex.wrap",[yn.gap]:"layout_editor.flex.gap"},lT={[mi.grow]:"layout_editor.flex.item_grow",[mi.selfAlign]:"layout_editor.flex.item_align",[mi.order]:"layout_editor.flex.item_order"};function dT({node:e,spec:t,capability:n,t:o,onPatchNode:r,liveElement:s,scope:a=Wt}){const l=Jf(n),d=Ct(t,yn.enable),c=iT(e,d,a),{showContainer:p,showEnableButton:f,showDisableButton:b}=sT(l,s,c,!!d,a),g=Object.values(yn).filter(x=>x!==yn.enable&&Ct(t,x)),m=Object.values(mi).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=fn(e,d,v,a);r(x)},w=()=>{if(!d)return;const x=a.breakpoint!=="base"&&y!==void 0?y:void 0,$=fn(e,d,x,a);r($)},k=(x,$,S)=>i.jsx("div",{"data-testid":S,style:{display:"flex",flexDirection:"column"},children:x.map(C=>{const T=Ct(t,C);if(!T)return null;const E=T.label?T:{...T,label:`$t:${$[C]}`};return i.jsx(hi,{controlKey:C,control:E,node:e,t:o,onPatch:r,scope:a},C)})});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:cT,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:Zf,children:o("layout_editor.flex.container_title")}),k(g,aT,"g7le-flex-container-controls"),b&&i.jsx("button",{type:"button","data-testid":"g7le-flex-disable",onClick:w,style:uT,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:Zf,children:o("layout_editor.flex.item_title")}),k(m,lT,"g7le-flex-item-controls")]}),!p&&!f&&l!=="item"&&i.jsx("div",{"data-testid":"g7le-flex-empty",style:pT,children:o("layout_editor.flex.not_flex")})]})}const Zf={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:6},cT={padding:"8px 12px",fontSize:12,border:"1px dashed #2563eb",borderRadius:6,background:"#eff6ff",color:"#2563eb",cursor:"pointer"},uT={marginTop:8,padding:"6px 10px",fontSize:12,border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",color:"#64748b",cursor:"pointer"},pT={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},Qf=["desktop","tablet","mobile","portable"],La=1280,fT=820,gT=390,hT=1920,yT=320;function bT(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 mT(e){const t=[...Qf],n=new Set(Qf);for(const o of bT(e))!n.has(o)&&!t.includes(o)&&t.push(o);return t}function vT(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 _T(e){switch(e){case"desktop":return La;case"tablet":return fT;case"mobile":return gT}const t=e in Do?Do[e]:Mn.parseRange(e);return!t||!Number.isFinite(t.max)?La:Math.round(Math.max(yT,Math.min(hT,t.max)))}function Rf(){const t=Ft()?.document?.raw?.components;return u.useMemo(()=>mT(t??null),[t])}const xT={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"},wT=[{key:"base",labelKey:"layout_editor.property_modal.scope.scheme_light"},{key:"dark",labelKey:"layout_editor.property_modal.scope.scheme_dark"}];function eg({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=Rf(),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(!xC(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:kT,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:tg,children:wT.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:ng(k),children:[o(w.labelKey),w.key==="dark"&&Js(n,{colorScheme:"dark",breakpoint:e.breakpoint})&&i.jsx("span",{"data-testid":"g7le-style-scheme-dark-dot",style:og})]},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:tg,children:[h.map(w=>{const k=e.breakpoint===w,x=w==="base"||$u(w),$=w==="base"?"layout_editor.property_modal.scope.device_base":xT[w],S=$?o($):w,C=x?`g7le-style-bp-${w}`:`g7le-style-bp-custom-${w}`;return i.jsxs("button",{type:"button",role:"tab","aria-selected":k,"data-testid":C,"data-active":k?"true":"false",onClick:()=>y(w),style:ng(k),children:[S,Js(n,{colorScheme:"base",breakpoint:w})&&i.jsx("span",{"data-testid":`${C}-dot`,style:og})]},String(w))}),i.jsxs("button",{type:"button","data-testid":"g7le-style-bp-add-custom",onClick:()=>l(w=>!w),style:$T,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:ST,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:rg}),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:rg}),i.jsx("button",{type:"button","data-testid":"g7le-style-custom-confirm",onClick:_,style:ET,children:o("layout_editor.property_modal.scope.add_custom")})]}),b&&i.jsx("div",{"data-testid":"g7le-style-custom-error",style:IT,children:b}),e.breakpoint!=="base"&&!$u(e.breakpoint)&&i.jsx("div",{"data-testid":"g7le-style-custom-priority-note",style:AT,children:o("layout_editor.property_modal.scope.custom_priority_note")}),s&&Js(n,e)&&i.jsxs("button",{type:"button","data-testid":"g7le-style-scope-reset",onClick:s,style:CT,children:["↺ ",o("layout_editor.property_modal.scope.reset_to_base")]})]})}const kT={display:"flex",flexDirection:"column",gap:0,padding:"0 0 8px",borderBottom:"1px solid #e2e8f0",marginBottom:8},ST={display:"flex",gap:6,alignItems:"center",marginTop:4},tg={display:"flex",gap:2,flexWrap:"wrap",borderBottom:"1px solid #e2e8f0",margin:"0 -16px",padding:"0 12px"};function ng(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 og={display:"inline-block",width:5,height:5,borderRadius:3,background:"#f59e0b"},CT={alignSelf:"flex-start",marginTop:2,padding:"3px 8px",fontSize:10,border:"1px solid #cbd5e1",borderRadius:6,background:"#f8fafc",color:"#475569",cursor:"pointer"},$T={padding:"6px 12px",fontSize:11,border:"none",borderBottom:"2px dashed #cbd5e1",background:"transparent",color:"#475569",cursor:"pointer",marginBottom:-1},rg={width:70,padding:"4px 6px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6},ET={padding:"4px 10px",fontSize:11,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},IT={fontSize:11,color:"#dc2626"},AT={fontSize:10,color:"#94a3b8"},ig=new Map;function Pn(e,t){ig.set(e,t)}function TT(e){return e?ig.get(e)??null:null}const Pa={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"}}},DT=["id"];function zT(e){return e===!1?[]:Array.isArray(e)?e.filter(t=>t in Pa):[...DT]}function sg(e){const t=e.props?.id??e.id;return typeof t=="string"&&t.length>0?`${t}-scope`:"scope"}function NT({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=sg(e)),t(h)},f=h=>{const v={...e};v.isolatedScopeId=h.trim()===""?sg(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:MT,children:[i.jsx("div",{style:LT,children:n("layout_editor.core_props.isolatedState.label")}),i.jsxs("div",{style:PT,children:[i.jsx("button",{type:"button","data-testid":"g7le-isolated-toggle",role:"switch","aria-checked":a,onClick:p,style:OT(a),children:n(a?"layout_editor.overlay.on":"layout_editor.overlay.off")}),a?null:i.jsx("span",{"data-testid":"g7le-isolated-off-hint",style:BT,children:n("layout_editor.core_props.isolatedState.off_hint")})]}),a?i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:ag,children:[i.jsx("label",{style:lg,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:WT}),g.length>0?i.jsxs("div",{"data-testid":"g7le-isolated-scopeid-picker",style:jT,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:HT}),i.jsx("div",{style:FT,children:g.map(h=>i.jsx("button",{type:"button","data-testid":`g7le-isolated-scopeid-candidate-${h}`,onClick:()=>{f(h),c("")},style:KT,children:h},h))})]}):null,m?i.jsxs("p",{"data-testid":"g7le-isolated-scopeid-dup",style:VT,children:["ⓘ ",n("layout_editor.core_props.isolatedScopeId.duplicate")]}):null]}),i.jsxs("div",{style:ag,children:[i.jsx("label",{style:lg,children:n("layout_editor.core_props.isolatedState.initial_label")}),i.jsx("div",{"data-testid":"g7le-isolated-initial-value",children:i.jsx(zn,{value:s.isolatedState??{},onChange:b,t:n,path:"isolatedState",scope:"isolated-node"})})]})]}):null]})}const MT={display:"flex",flexDirection:"column",gap:8,padding:10,border:"1px solid #e2e8f0",borderRadius:8,minWidth:0},LT={fontSize:12,fontWeight:700,color:"#0f172a"},PT={display:"flex",gap:8,alignItems:"center"},OT=e=>({padding:"4px 12px",fontSize:11,border:`1px solid ${e?"#3b82f6":"#cbd5e1"}`,borderRadius:14,background:e?"#eff6ff":"#fff",color:e?"#1d4ed8":"#64748b",cursor:"pointer"}),BT={fontSize:11,color:"#94a3b8"},ag={display:"flex",flexDirection:"column",gap:4,minWidth:0},lg={fontSize:11,color:"#64748b"},WT={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box",width:"100%"},jT={border:"1px solid #e2e8f0",borderRadius:6,padding:4,background:"#fff"},HT={width:"100%",padding:"4px 6px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,marginBottom:4,boxSizing:"border-box"},FT={display:"flex",flexDirection:"column",maxHeight:120,overflowY:"auto"},KT={textAlign:"left",padding:"4px 6px",fontSize:12,border:"none",background:"transparent",cursor:"pointer",borderRadius:4,color:"#0f172a"},VT={margin:0,fontSize:11,color:"#64748b"},UT={borderTop:"2px solid #c7d2fe",background:"#eef2ff",padding:"10px 12px",display:"flex",flexDirection:"column",gap:8},dg={fontSize:13,fontWeight:700,color:"#3730a3",display:"flex",alignItems:"center",gap:6},qT={fontSize:11,fontWeight:600,color:"#4338ca",background:"#e0e7ff",border:"1px solid #c7d2fe",borderRadius:4,padding:"1px 6px"},Oa={fontSize:11,color:"#6366f1"},GT={alignSelf:"flex-start",fontSize:12,fontWeight:600,color:"#fff",background:"#4f46e5",border:"none",borderRadius:4,padding:"4px 10px",cursor:"pointer"},YT={opacity:.5,cursor:"not-allowed"},XT={fontSize:11,color:"#dc2626"};function JT({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:dg,children:i.jsx("span",{style:qT,"data-testid":"g7le-injected-props-origin-badge",children:t("layout_editor.property_modal.injected_props.origin",{source:g})})}),i.jsx(Hs,{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:XT,"data-testid":"g7le-injected-props-error",children:l}),f&&i.jsx("div",{style:{...Oa,color:"#16a34a"},"data-testid":"g7le-injected-props-saved",children:t("layout_editor.property_modal.injected_props.saved")}),i.jsx("div",{style:Oa,children:t("layout_editor.property_modal.injected_props.save_target")}),i.jsx("button",{type:"button","data-testid":"g7le-injected-props-save",style:{...GT,...c||!s?YT: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 ZT({injectedProps:e,t,onSaveInjectedProps:n}){return!Array.isArray(e)||e.length===0?null:i.jsxs("div",{style:UT,"data-testid":"g7le-injected-props-section",children:[i.jsxs("div",{style:dg,children:["🧩 ",t("layout_editor.property_modal.injected_props.title")]}),i.jsx("div",{style:Oa,children:t("layout_editor.property_modal.injected_props.help")}),e.map(o=>i.jsx(JT,{entry:o,t,onSave:r=>n(o.extensionId,r)},o.extensionId))]})}function QT(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 RT({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=Wt,onScopeChange:m,templateIdentifier:h,initialTab:v,onSaveInjectedProps:y,branchLabel:_,isolatedScopeIdCandidates:w,usedScopeIds:k}){const x=e.__injectedProps,$=Array.isArray(x)&&x.length>0&&!!y,S=ve=>{m?.(ve)},C=()=>{r(IC(e,g))},T=typeof e.name=="string"?e.name:"",E=ji(t,T),N=QT(n,T)?.settings,D=!!(N?.groups&&N.groups.length>0),B=Array.isArray(E?.propControls)?E.propControls:[],M=zT(E?.coreProps),O=new Set(M.map(ve=>Pa[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,I=H?TT(H):null,L=!!I,F=Array.isArray(E?.dataProps)?E.dataProps:[],Y=F.length>0,K=!!(e.iteration&&typeof e.iteration=="object"),X=oT(e,E),Z=M.length>0||z.length>0||L||Y||X||K,ae=Array.isArray(E?.styleControls)?E.styleControls:[],oe=Array.isArray(E?.advanced)?E.advanced:[],ee=(Array.isArray(E?.events)?E.events:[]).length>0,ge=Jf(E),V=ae.length>0||ge!==null,be=!(E?.visibilityCondition===!1)&&(Z||V||ee||D||oe.length>0),Ee=u.useMemo(()=>{const ve=[];return D&&ve.push("settings"),Z&&ve.push("props"),V&&ve.push("style"),ee&&ve.push("action"),be&&ve.push("visibility"),ve.push("translation"),oe.length>0&&ve.push("advanced"),ve},[D,Z,V,ee,be,oe.length]),De=z.length>0||L||Y||K,[Se,Ue]=u.useState(v&&Ee.includes(v)?v:D?"settings":De?"props":V?"style":Z?"props":Ee[0]??"style"),Me=qA(e),Oe=!Z&&!V&&!D&&!ee&&!be&&oe.length===0,Ye=E?.label?E.label.startsWith("$t:")?o(E.label.slice(3)):E.label:T||o("layout_editor.property_modal.element"),ze=(ve,qe)=>{const We={...e.props??{}};qe===void 0?delete We[ve]:We[ve]=qe,r({...e,props:We})},Xe={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:e4,children:[i.jsxs("div",{"data-modal-drag-handle":!0,"data-testid":"g7le-property-modal-header",style:t4,children:[i.jsx("span",{"data-testid":"g7le-property-modal-title",style:{fontSize:14,fontWeight:700},children:D&&Se==="settings"?o("layout_editor.property_modal.settings_title",{name:Ye}):o("layout_editor.property_modal.title",{name:Ye})}),i.jsx("button",{type:"button","data-testid":"g7le-property-modal-close","aria-label":"close",onClick:s,style:n4,children:"✕"})]}),Me&&i.jsx("div",{"data-testid":"g7le-property-modal-advanced-badge",style:o4,children:o("layout_editor.property_modal.advanced_badge")}),_&&i.jsx("div",{"data-testid":"g7le-property-modal-branch-badge",style:r4,children:o("layout_editor.property_modal.branch_badge",{device:_})}),i.jsx("div",{style:i4,role:"tablist",children:Ee.map(ve=>i.jsx("button",{type:"button",role:"tab","aria-selected":Se===ve,"data-testid":`g7le-property-tab-${ve}`,"data-active":Se===ve?"true":"false",onClick:()=>Ue(ve),style:{...s4,color:Se===ve?"#2563eb":"#64748b",borderBottomColor:Se===ve?"#2563eb":"transparent"},children:Xe[ve]},ve))}),i.jsxs("div",{style:a4,"data-testid":"g7le-property-modal-body",children:[Oe&&!$&&i.jsx("div",{"data-testid":"g7le-property-modal-no-editable",style:ug,children:o("layout_editor.property_modal.no_editable_props")}),$&&i.jsx(ZT,{injectedProps:x,t:o,onSaveInjectedProps:y}),Se==="settings"&&N&&i.jsx(MA,{spec:N,node:e,t:o,onPatchProp:ze}),Se==="props"&&i.jsxs("div",{"data-testid":"g7le-property-props-tab",style:{display:"flex",flexDirection:"column"},children:[K&&i.jsx(L6,{node:e,candidates:f??[],t:o,onPatchNode:r}),Y&&i.jsx(d6,{node:e,dataProps:F,candidates:f??[],t:o,onPatchNode:r}),X&&i.jsx(T6,{node:e,candidates:f??[],t:o,onPatchNode:r,templateIdentifier:h}),L&&I&&i.jsx(I,{node:e,params:P,spec:t,manifest:n,t:o,onPatchNode:r,templateIdentifier:h,candidates:f}),M.map(ve=>i.jsx(hi,{controlKey:`core-${ve}`,control:Pa[ve],node:e,t:o,onPatch:r,scope:Wt,bindingCandidates:f},`core-${ve}`)),z.map(ve=>{const qe=Ct(t,ve);return qe?i.jsx(hi,{controlKey:ve,control:qe,node:e,t:o,onPatch:r,scope:Wt,bindingCandidates:f},ve):null}),i.jsx(NT,{node:e,onPatchNode:r,t:o,scopeIdCandidates:w,usedScopeIds:k})]}),Se==="style"&&i.jsxs("div",{"data-testid":"g7le-property-style-tab",style:{display:"flex",flexDirection:"column"},children:[i.jsx("div",{style:cg,children:i.jsx(eg,{scope:g,onChange:S,node:e,t:o,onClearScope:C})}),ge!==null&&i.jsx(dT,{node:e,spec:t,capability:E,t:o,onPatchNode:r,liveElement:b,scope:g}),ae.map(ve=>{const qe=Ct(t,ve);return qe?i.jsx(hi,{controlKey:ve,control:qe,node:e,t:o,onPatch:r,scope:g},ve):null})]}),Se==="action"&&i.jsx(i6,{node:e,spec:t,capability:E,t:o,onPatchNode:r,pageCandidates:d,dataSourceCandidates:c,stateKeyCandidates:p,bindingCandidates:f}),Se==="visibility"&&i.jsxs("div",{"data-testid":"g7le-property-visibility-tab",style:{display:"flex",flexDirection:"column"},children:[i.jsx("div",{style:cg,children:i.jsx(eg,{scope:g,onChange:S,node:e,t:o,showColorScheme:!1})}),i.jsx(Du,{node:e,spec:t,t:o,onPatchNode:r,dataSourceCandidates:c,stateKeyCandidates:p,scope:g})]}),Se==="translation"&&(h?i.jsx(Xd,{customKey:Yd(e),templateIdentifier:h,t:o,paramLabels:wv(e),onRemoveParam:ve=>{const qe=typeof e.text=="string"?e.text:"";r({...e,text:vo(qe,ve)});const We=Yd(e);h&&We&&$r(h,We,ve)}}):i.jsx("div",{"data-testid":"g7le-property-translation-deferred",style:ug,children:o("layout_editor.translation.not_a_key")})),Se==="advanced"&&i.jsx(YA,{node:e,advanced:oe,t:o,onPatch:r,permissionCandidates:l})]}),i.jsxs("div",{style:l4,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:d4,children:o("layout_editor.property_modal.delete_element")}),i.jsx("button",{type:"button","data-testid":"g7le-property-modal-done",onClick:s,style:c4,children:o("layout_editor.property_modal.close")})]})]})]})}const e4={display:"flex",flexDirection:"column",width:420,maxWidth:"92vw"},t4={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #e2e8f0",cursor:"move",userSelect:"none"},n4={border:"none",background:"transparent",fontSize:14,cursor:"pointer",color:"#64748b"},o4={margin:"8px 16px 0",padding:"6px 10px",fontSize:11,background:"#fef3c7",color:"#92400e",borderRadius:6},r4={margin:"8px 16px 0",padding:"6px 10px",fontSize:11,background:"#dbeafe",color:"#1e40af",borderRadius:6},i4={display:"flex",gap:2,padding:"0 12px",borderBottom:"1px solid #e2e8f0",overflowX:"auto"},s4={padding:"8px 10px",fontSize:12,border:"none",borderBottom:"2px solid transparent",background:"transparent",cursor:"pointer",whiteSpace:"nowrap"},a4={padding:16,overflowY:"auto",maxHeight:"60vh"},cg={position:"sticky",top:-16,zIndex:2,background:"#fff",margin:"-16px -16px 0",padding:"6px 16px 0"},ug={fontSize:12,color:"#94a3b8",padding:"16px 0",textAlign:"center"},l4={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderTop:"1px solid #e2e8f0"},d4={padding:"6px 12px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},c4={padding:"6px 12px",fontSize:12,border:"none",borderRadius:6,background:"#2563eb",color:"#fff",cursor:"pointer"},Ba="g7le:component-target-picked",Wa="g7le:component-target-pick-request";let u4=1;function p4({value:e,onChange:t,t:n,control:o}){const r=bo(),s=e==null?"":String(e),a=o?.allowManualInput!==!1,l=u.useCallback(()=>{if(typeof window>"u")return;const d=`pick-${u4++}`,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(Ba,f),p&&r.restore(p),!g.cancelled&&typeof g.id=="string"&&t(g.id))};window.addEventListener(Ba,f),window.dispatchEvent(new CustomEvent(Wa,{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 f4(e,t,n,o,r=fetch){const s=`/api/admin/templates/${encodeURIComponent(e)}/layout-extensions/${t}`;let a;try{a=await r(s,{headers:Ne(),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:Ne({"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 pg=new Map;function ja(e,t){pg.set(e,t)}function g4(e){return e?pg.get(e)??null:null}const fg="g7le.clipboard";function gg(){try{return typeof window>"u"||!window.sessionStorage?null:window.sessionStorage}catch{return null}}function h4(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 hg(e,t=0){const n=gg();if(!n)return!1;try{const o={node:h4(e),copiedAt:t};return n.setItem(fg,JSON.stringify(o)),!0}catch{return!1}}function y4(){const e=gg();if(!e)return null;try{const t=e.getItem(fg);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 Qo={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 Ha(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 b4(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=Ha(l)??d*40,p=Math.abs(c-t);p<a&&(a=p,s=l)}),s}function m4(e,t){const n=typeof t.min=="number"?t.min:void 0,o=typeof t.max=="number"?t.max:void 0;let r=e;return n!==void 0&&(r=Math.max(n,r)),o!==void 0&&(r=Math.min(o,r)),r}function yg(e,t){const n=e.apply,o=m4(Math.max(0,Math.round(t)),e);return n?.type==="styleProp"?`${o}px`:n?.type==="classToken"&&n.tokenTemplate?`${o}px`:b4(e,o)}function v4(e){const{node:t,widthControl:n,heightControl:o,scale:r,measureStartSize:s,onResize:a,onResizeEnd:l,onResizeStateChange:d}=e,c={width:!!n,height:!!o},p=u.useRef(null),f=u.useCallback((b,g)=>{if(!t)return;const m=Qo[b];if(m.width!==0&&!n||m.height!==0&&!o)return;const h=t.props?.style??{},v=s?.()??null,y=Ha(h.width)??(v?Math.round(v.width):0),_=Ha(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=S=>{const C=p.current;if(!C)return;const T=r||1,E=(S.clientX-C.startX)/T*Qo[C.handle].width,A=(S.clientY-C.startY)/T*Qo[C.handle].height;let N=C.node;if(Qo[C.handle].width!==0&&n){const D=yg(n,C.startW+E);N=fn(N,n,D)}if(Qo[C.handle].height!==0&&o){const D=yg(o,C.startH+A);N=fn(N,o,D)}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 bg=320,mg=1920,_4=1024;function Fa(e){return Number.isFinite(e)?Math.round(Math.max(bg,Math.min(mg,e))):_4}function Ka(e={}){const{state:t,dispatch:n}=Qe(),{previewDevice:o,previewZoom:r,previewCustomWidth:s,previewColorScheme:a}=t,l=o==="custom"?Fa(s):_T(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:Fa(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:Fa(s),setDevice:c,setZoom:p,setCustomWidth:f,colorScheme:a,setColorScheme:b}}const vi="g7le-dnd-handle-";function x4(e){if(typeof e!="string"||!e.startsWith(vi))return null;const t=e.slice(vi.length);return t.length>0?t:null}function w4(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\\]]/g,"\\$&")}function k4(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(vi))return null;if(r){const l=e.closest(`[data-testid^="${vi}"]`);if(l&&t){const d=x4(l.getAttribute("data-testid"));if(d){const c=t.querySelector(`[data-editor-path="${w4(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 S4(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 C4="#ffffff",$4="#0f172a";function E4(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 I4(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=E4(e);if(!n)return!1;const[o,r,s]=n;return .299*o+.587*r+.114*s>=180}function A4(e,t,n){const o=typeof n?.color=="string"?n.color:null;return I4(e??o??t)?$4:C4}function T4({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:A4(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??{},...S4(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 D4({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=Ft(),$=u.useRef(()=>{}),[S,C]=u.useState(null),[T,E]=u.useState(!1),A=u.useRef(n??null);u.useEffect(()=>{n&&A.current!==n&&(A.current=n)},[n]);const N=u.useMemo(()=>{if(!n&&r)return r;const P={},I=vt(typeof t.text=="string"?t.text:"");for(const L of I?.params??[])P[L.name]=Vt(L.expression);return P},[t.text,n,r]);u.useEffect(()=>{let P=!1;if(!n){const I=o??"";return v.current=I,h(I),()=>{P=!0}}return(async()=>{const I=It(n,l);if(I!==void 0){v.current=I,h(I);return}const L=await cn(a,n);if(P)return;const F=L?.values?.[l]??"";v.current=F,h(F)})(),()=>{P=!0}},[a,n,l,o]);const D=async()=>{if(w.current)return;w.current=!0;const P=m??"";if(P===v.current){b();return}_(!0);let I=A.current;if(!I){if(!s){_(!1),w.current=!1;return}if(I=await s(P),_(!1),!I){w.current=!1;return}A.current=I,b();return}const L=await So(a,I,l,P);if(_(!1),L.kind==="error"){w.current=!1;return}x?.markDirty?.(),b()},B=()=>{w.current||(w.current=!0,g())},M=P=>{C(P)},O=async P=>{if(!(S===null||!p||T)){E(!0);try{const I=A.current;I&&m!==null&&m!==v.current&&(await So(a,I,l,m),v.current=m);const L=await p(S,P);L!==null&&(h(L),v.current=L,x?.markDirty?.())}finally{E(!1),C(null)}}},z=async P=>{if(!(!f||T)){E(!0);try{const I=A.current;I&&m!==null&&m!==v.current&&(await So(a,I,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(),D()):P.key==="Escape"&&(P.preventDefault(),B())};return $.current=()=>{D()},u.useEffect(()=>{const P=L=>{const F=k.current;if(!F)return;const Y=L.target;if(Y&&F.contains(Y))return;const K=Y;K&&K.closest&&K.closest('[data-testid="g7le-inline-toolbar"], .g7le-inline-toolbar')||$.current()},I=k.current?.ownerDocument??document;return I.addEventListener("pointerdown",P,!0),()=>I.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(xr,{value:m,onChange:h,t:d,paramLabels:N,testIdSuffix:"inline",onRequestInsert:p?M:void 0,onRemoveChip:f?P=>void z(P):void 0}),S!==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 D(),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"],N4={fontWeight:"B",fontBold:"B",fontStyle:"I",fontItalic:"I",textDecoration:"U",textUnderline:"U",textAlign:"≡",fontSize:"T",textColor:"A"},M4=[["fontWeight","fontBold"],["fontItalic","fontStyle"],["textUnderline","textDecoration"]];function vg({node:e,spec:t,t:n,onApplyControl:o,box:r,scope:s=Wt}){const a=typeof e.name=="string"?e.name:"",l=ji(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 M4){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(P4,{controlKey:p,node:e,spec:t,t:n,scope:s,onApplyControl:o},p))})}const L4={fontWeight:"bold",fontBold:"bold",fontStyle:"italic",fontItalic:"italic",textDecoration:"underline",textUnderline:"underline"};function _g(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 P4({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=zo(t,d,r),b=L4[e],g=b&&Array.isArray(c)?_g(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 $=zo(x,d,r),S=Array.isArray(c)?_g(c,b):void 0,C=S!==void 0&&$.value===S?void 0:S;return fn(x,d,C,r)})},w=x=>{s(e,$=>{const C=zo($,d,r).value===x?void 0:x;return fn($,d,C,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:N4[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 S=f.value===x.value;return i.jsxs("button",{type:"button",role:"option","aria-selected":S,"data-testid":`g7le-inline-option-${e}-${String(x.value??$)}`,onMouseDown:C=>C.preventDefault(),onClick:C=>{C.preventDefault(),C.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:S?"#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)}),S&&i.jsx("span",{"aria-hidden":"true",style:{marginLeft:"auto"},children:"✓"})]},String(x.value??$))}):i.jsx(O4,{testid:`g7le-inline-freeinput-${e}`,placeholder:o(`layout_editor.inline_edit.prompt.${e}`),initial:typeof f.value=="string"?f.value:"",onSubmit:x=>{s(e,$=>fn($,d,x,r)),l(!1)}})})]})}function O4({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 B4(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}=tt(),m=Ka(),h=u.useCallback((W,J)=>{const R=window.G7Core;if(R&&typeof R.t=="function"){const de=R.t(W,J);if(de&&de!==W&&!de.startsWith("$t:"))return de}return g(W,J)},[g]),v=Ft(),y=L7(50),_=bo(),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]),S=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]),C=$7({rootNode:x,editMode:f.editMode,currentExtensionId:$,editableRootPath:S,pathParser:Re,resolveRouteMatch:l}),[T,E]=u.useState(null),[A,N]=u.useState(null),[D,B]=u.useState(null),M=u.useRef(null);M.current=D;const[O,z]=u.useState(null),H=u.useRef(null),P=u.useRef(null);P.current=C.selectedPath;const I=qb(),[L,F]=u.useState(null),Y=u.useCallback(W=>{if(!t)return;const J=Re(W);if(!J)return;const R={children:ze.current.components},de=Be(R,J),ye=I.classify(de);if(!ye.editable){Et({op:"inline_edit_blocked_binding",sourceState:ye.sourceState,componentPath:at(J),timestamp:Date.now()});return}const we=fo(t,W);if(!we)return;const Te=de?.props??{},ke=wg(t,W);F({path:J,domPath:W,box:we,initialValue:ye.displayValue,isCustomKey:ye.sourceState==="custom_key",isParamKey:ye.isParamKey===!0,customKey:ye.customKey,chipValue:ye.chipValue,chipParamLabels:ye.chipParamLabels,mirrorClassName:typeof Te.className=="string"?Te.className:void 0,mirrorStyle:Te.style??void 0,nodeEffectiveColor:ke}),Et({op:"inline_edit_enter",sourceState:ye.sourceState,componentPath:at(J),timestamp:Date.now()})},[t,I]),K=u.useCallback(()=>{if(!t){E(null),N(null);return}N(fo(t,C.selectedPath)),E(fo(t,C.hoverPath))},[t,C.selectedPath,C.hoverPath,k]);u.useEffect(()=>{if(K(),typeof window<"u"&&typeof window.requestAnimationFrame=="function"){const W=window.requestAnimationFrame(()=>K());return()=>window.cancelAnimationFrame(W)}},[K]),u.useEffect(()=>{if(t)return zp(K,t)},[t,K]);const X=u.useCallback((W,J)=>{if(typeof window>"u")return;window.dispatchEvent(new CustomEvent(Ba,{detail:J===null?{requestId:W,cancelled:!0}:{requestId:W,id:J}})),B(null),z(null);const R=H.current;R?C.handleSelect("",{dataset:{editorPath:R}}):C.clearSelection(),H.current=null},[C]);u.useEffect(()=>{if(typeof window>"u")return;const W=J=>{const R=J.detail;if(typeof R?.requestId!="string")return;const de=M.current;de&&de!==R.requestId&&X(de,null),H.current=P.current,B(R.requestId)};return window.addEventListener(Wa,W),()=>window.removeEventListener(Wa,W)},[X]),u.useEffect(()=>{if(!D)return;const W=J=>{J.key==="Escape"&&(J.preventDefault(),X(D,null))};return window.addEventListener("keydown",W,!0),()=>window.removeEventListener("keydown",W,!0)},[D,X]),u.useEffect(()=>{if(!t)return;const W=f.editMode==="iteration_item"||f.editMode==="modal",J=(_e,Ie)=>k4(_e,t,Ie?{x:Ie.clientX,y:Ie.clientY}:void 0,{handleFallback:W}),R=_e=>{const Ie=_e.dataset.editorPath??"",He=Ie?Re(Ie):null,Nt={children:ze.current.components},gt=He?Be(Nt,He):null,Mt=gt&&typeof gt.props?.id=="string"?gt.props.id:typeof gt?.id=="string"?gt.id:"";return Mt.startsWith("auto_")?"":Mt},de=_e=>{const Ie=J(_e.target,_e);if(!Ie)return;const He=M.current;if(He){_e.preventDefault(),_e.stopPropagation();const Nt=R(Ie);Nt&&X(He,Nt);return}_e.preventDefault(),_e.stopPropagation(),C.handleSelect(Ie.dataset.editorId??"",{currentTarget:Ie,dataset:Ie.dataset})},ye=_e=>{const Ie=J(_e.target,_e);if(M.current){if(!Ie){z(null);return}const He=fo(t,Ie.dataset.editorPath??null);if(!He){z(null);return}z({box:He,hasId:R(Ie)!==""});return}if(!Ie){C.handleHover(null,{});return}C.handleHover(Ie.dataset.editorId??"",{currentTarget:Ie,dataset:Ie.dataset})},we=()=>{if(M.current){z(null);return}C.handleHover(null,{})},Te=_e=>{const Ie=J(_e.target,_e);if(!Ie)return;const He=Ie.dataset.editorPath??"";He&&(_e.preventDefault(),_e.stopPropagation(),Y(He))},ke=t.parentElement??t;return ke.addEventListener("click",de,!0),ke.addEventListener("mousemove",ye,!0),ke.addEventListener("mouseleave",we,!0),ke.addEventListener("dblclick",Te,!0),()=>{ke.removeEventListener("click",de,!0),ke.removeEventListener("mousemove",ye,!0),ke.removeEventListener("mouseleave",we,!0),ke.removeEventListener("dblclick",Te,!0)}},[t,C,Y,f.editMode,X]);const Z=u.useMemo(()=>{const W=C.selectedPath;if(!W)return null;const J=W.match(/^(.*)\.children\.\d+$/);return J?J[1]:null},[C.selectedPath]),ae=u.useCallback(()=>{Z&&C.handleSelect("",{dataset:{editorPath:Z}})},[Z,C]),oe=u.useMemo(()=>!t||!C.selectedPath?null:t.querySelector(`[data-editor-path="${an(C.selectedPath)}"]`),[t,C.selectedPath]),G=u.useMemo(()=>C.selectedPath?Re(C.selectedPath):null,[C.selectedPath]),ee=u.useMemo(()=>{if(!G)return null;const W=G.find(et);if(!W)return null;const{i18nKey:J,raw:R}=SC(W.responsive);return J?g(J):g("layout_editor.overlay.branch_custom",{range:R})},[G,g]),ge=u.useMemo(()=>C.selectedPath?C.selectedIsIteration&&C.selectedIterationSourcePath?C.selectedIterationSourcePath:C.selectedPath:null,[C.selectedPath,C.selectedIsIteration,C.selectedIterationSourcePath]),V=u.useMemo(()=>ge?Re(ge):null,[ge]),te=u.useMemo(()=>!t||!ge?null:t.querySelector(`[data-editor-path="${an(ge)}"]`),[t,ge]),be=u.useMemo(()=>{if(te?.parentElement)return te.parentElement;if(!t||!ge)return null;const W=ge.match(/^(.*)\.children\.\d+$/);return W?t.querySelector(`[data-editor-path="${an(W[1])}"]`):null},[te,t,ge]),Ee=u.useMemo(()=>{const W=C.selectedNode;return W&&(typeof W.name=="string"?W.name:typeof W.type=="string"?W.type:"")||null},[C.selectedNode]),De=u.useMemo(()=>{if(C.selectedLockKind!=="extension")return null;const W=C.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},[C.selectedLockKind,C.selectedNode]),Se=z7({parentEl:be,selectedPath:V,selectedEl:te}),Ue=u.useMemo(()=>!t||!ge||ge===C.selectedPath?A:fo(t,ge),[t,ge,A,C.selectedPath,k]),Me=u.useRef(null),Oe=u.useCallback(()=>{const W=Me.current;W&&(_.close(W),Me.current=null)},[_]),Ye=u.useRef(()=>{}),ze=u.useRef({manifest:n,nesting:o,componentPalette:r,components:k});ze.current={manifest:n,nesting:o,componentPalette:r,components:k};const Xe=u.useCallback(W=>{const J=W.insertion?.parentPath??[],R=W.insertion?.index??0,de=ze.current,ye=xg(de.components,J);Oe();const we=_.open({ariaLabel:h("layout_editor.palette.title"),width:880,maxHeightRatio:.82,content:u.createElement(Nf,{manifest:de.manifest,nesting:de.nesting,componentPalette:de.componentPalette??null,targetParentPath:J,targetContainerName:ye,onInsert:(Te,ke,_e)=>{Ye.current(Te,ke,_e)},insertionIndex:R,onClose:()=>Oe(),editorTemplateId:f.templateIdentifier,editorLocale:f.locale}),onClose:()=>{Me.current=null}});Me.current=we},[_,Oe]),ve=u.useMemo(()=>{if(!f.isPaletteOpen)return null;if(!G)return{parentPath:[],index:k.length};if(C.selectedLockKind!=="none"){const de=V;return!de||de.length===0?{parentPath:[],index:k.length}:{parentPath:de.slice(0,-1),index:(de[de.length-1]??0)+1}}const J=C.selectedNode,R=Array.isArray(J?.children)?J.children.length:0;return MI(J?.name,R,G,o,k.length)},[f.isPaletteOpen,G,V,C.selectedLockKind,C.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 ye=We.current;ye&&(_.close(ye),We.current=null);return}if(!ve||We.current)return;const W=ve,J=ze.current,R=xg(J.components,W.parentPath),de=_.open({ariaLabel:h("layout_editor.palette.title"),width:880,maxHeightRatio:.82,content:u.createElement(Nf,{manifest:J.manifest,nesting:J.nesting,componentPalette:J.componentPalette??null,targetParentPath:W.parentPath,targetContainerName:R,onInsert:(ye,we,Te)=>{Ye.current(ye,we,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=de},[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 ie=u.useRef(0);u.useEffect(()=>{const W=v?.reloadCounter??0;W!==ie.current&&(ie.current=W,W!==0&&(ce.current={layoutName:null,pushed:!1},w.current=[],c?.([])))},[v?.reloadCounter,c]);const se=u.useCallback((W,J,R)=>{if(!v)return;let de=[];v.patchLayout(ke=>{const _e={children:ke},Ie=Va(_e,J),He=R<0?Array.isArray(Ie?.children)?Ie.children.length:0:R,gt=ts(_e,J,He,W).children??[];return de=gt,gt}),y.push({actionKind:"insert",label:`insert ${W.name??W.type??""}`,snapshot:de});const ye=Va({children:de},J),we=R<0?Array.isArray(ye?.children)?ye.children.length-1:0:R,Te=at([...J,we]);if(w.current=[...w.current,Te],c?.(w.current),t){const ke=`[data-editor-path="${an(Te)}"]`,_e=()=>{const Ie=t.querySelector(ke);Ie&&typeof Ie.scrollIntoView=="function"&&Ie.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]);Ye.current=se;const me=u.useCallback(()=>{if(!v||!C.selectedNode||!G)return;const W=os(C.selectedNode);let J=[];v.patchLayout(R=>{const de={children:R},ye=G.slice(0,-1),we=G[G.length-1]??0,ke=ts(de,ye,we+1,W).children??[];return J=ke,ke}),y.push({actionKind:"insert",label:"duplicate",snapshot:J})},[v,C.selectedNode,G,y]),Ce=u.useCallback(()=>{if(!v||!G)return;let W=[];v.patchLayout(J=>{const ye=ns({children:J},G).children??[];return W=ye,ye}),y.push({actionKind:"remove",label:"remove",snapshot:W}),C.clearSelection()},[v,G,y,C]),$e=u.useMemo(()=>{if(!C.selectedNode||!G||G.some(et))return null;const W=C.selectedNode;if(!Array.isArray(W.children))return null;const J=kC(f.previewDevice,W,f.previewCustomWidth);return{mode:J.mode,key:J.key,sourceKey:J.sourceKey}},[C.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(de=>(R=Pb({children:de},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=Ob({children:R},G,W).children??[],J)),y.push({actionKind:"remove",label:"merge_branch",snapshot:J})},[v,G,$e,y]),fe=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]),xe=u.useMemo(()=>{if(!$e)return null;const W=fe($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,fe]),he=u.useMemo(()=>{if(!C.selectedNode||!G)return[];if(G.some(et))return[];const W=Yr(f.previewDevice,C.selectedNode,f.previewCustomWidth);return vT(C.selectedNode,W).map(J=>({key:J,label:fe(J)}))},[C.selectedNode,G,f.previewDevice,f.previewCustomWidth,fe]),j=u.useCallback(W=>{if(W==="desktop"||W==="tablet"||W==="mobile"||W==="portable"){m.setDevice(W);return}m.setDevice(W)},[m]),ne=u.useCallback(()=>{C.selectedNode&&hg(C.selectedNode)},[C.selectedNode]),pe=u.useCallback(()=>{C.selectedNode&&(hg(C.selectedNode),Ce())},[C.selectedNode,Ce]),Q=u.useCallback(()=>{if(!v)return;const W=y4();if(!W)return;const J=os(W);if(G&&G.length>0){const R=G.slice(0,-1),de=(G[G.length-1]??0)+1;se(J,R,de)}else se(J,[],k.length)},[v,G,se,k.length]),le=u.useCallback((W,J)=>{y.push({actionKind:"move",label:J,snapshot:W})},[y]),Ae=u.useCallback(()=>{if(C.selectedNavAffordance==="route_in_tree"&&C.selectedNavTargetPath){if(d){d(C.selectedNavTargetPath);return}b({type:"SELECT_ROUTE",route:{path:C.selectedNavTargetPath,layoutName:null}})}},[C.selectedNavAffordance,C.selectedNavTargetPath,d,b]),dt=u.useCallback(()=>{const W=Mb(C.selectedBaseLayout,f.selectedRoute?.layoutName);W&&b({type:"ENTER_BASE_EDIT",layoutName:W})},[C.selectedBaseLayout,f.selectedRoute?.layoutName,b]),pt=u.useCallback(()=>{const W=C.selectedNode?.__source?.extensionId;W!=null&&b({type:"ENTER_EXTENSION_EDIT",extensionId:String(W)})},[C.selectedNode,b]),ot=u.useCallback(()=>{const W=C.selectedIterationSourcePath;W&&b({type:"ENTER_ITERATION_ITEM_EDIT",sourcePath:W})},[C.selectedIterationSourcePath,b]),Le=u.useRef(null),je=u.useRef(null),Je=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(()=>Od(f.routeTree,h),[f.routeTree,h]),xn=u.useMemo(()=>Bd(v?.document?.raw),[v?.document?.raw]),wn=u.useMemo(()=>Wd(s),[s?.states]),Zt=u.useMemo(()=>{const W=v?.document?.raw,J=Lf(W?.components),R=W?.initIsolated,de=R&&typeof R=="object"&&!Array.isArray(R)?Object.keys(R):[];return $A(J,de)},[v?.document?.raw]),Hn=u.useMemo(()=>{const W=v?.document?.raw;return Lf(W?.components).map(J=>J.scopeId).filter(J=>typeof J=="string"&&J.length>0)},[v?.document?.raw]),ln=Pd({raw:v?.document?.raw,spec:s}),Di=u.useCallback((W,J)=>{if(!v)return;const R={children:ze.current.components},de=Be(R,W);if(!de)return;Tt.current={colorScheme:f.previewColorScheme==="dark"?"dark":"base",breakpoint:Yr(f.previewDevice,de,f.previewCustomWidth)};const ye=t?.getBoundingClientRect(),we=A&&ye?{left:ye.left+A.left,top:ye.top+A.top,width:A.width,height:A.height}:void 0,Te=oe,ke=W.find(et),_e=ke?fe(ke.responsive):null,Ie=W.filter(kn=>typeof kn=="number"),He=bb({children:ze.current.components},Ie,mb(ln)),Nt=He.length>0?[...Ki({iterationVars:He}),...ln]:ln,gt=(kn,PM)=>u.createElement(RT,{key:`pem-${at(je.current??[])}`,node:kn,spec:s,manifest:ze.current.manifest,t:h,permissionCandidates:a,pageCandidates:zt,dataSourceCandidates:xn,stateKeyCandidates:wn,bindingCandidates:Nt,liveElement:Te,templateIdentifier:f.templateIdentifier,initialTab:PM,branchLabel:_e,isolatedScopeIdCandidates:Zt,usedScopeIds:Hn,onSaveInjectedProps:async(mt,Sn)=>{const zi=typeof kn.id=="string"?kn.id:"",Fn=await f4(f.templateIdentifier,mt,zi,Sn);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()}),Fn.kind!=="success")throw new Error(Fn.kind==="conflict"?h("layout_editor.save.conflict"):Fn.kind==="injection_not_found"?"injection not found":Fn.kind==="not_found"?"extension not found":Fn.message??"save failed")},scope:Tt.current,onScopeChange:mt=>{Tt.current=mt;const Sn=Le.current;Sn&&_.open({id:Sn,ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:we,content:gt(kn),onClose:()=>{Le.current=null,je.current=null}})},onPatchNode:mt=>{let Sn=[];v.patchLayout(Fn=>(Sn=Ot({children:Fn},W,()=>mt).children??[],Sn)),y.push({actionKind:"inline_text_edit",label:"edit_props",snapshot:Sn}),dr({source:"style_control",componentPath:at(W),componentName:typeof mt.name=="string"?mt.name:null,patchKey:null,timestamp:Date.now()});const zi=Le.current;zi&&_.open({id:zi,ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:we,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:we,content:gt(de,J),onClose:()=>{Le.current=null,je.current=null,Je.current=null}});Le.current=Mt,Je.current=kn=>{_.open({id:Mt,ariaLabel:h("layout_editor.property_modal.title"),width:420,draggable:!0,avoidRect:we,content:gt(kn),onClose:()=>{Le.current=null,je.current=null,Je.current=null}})}},[v,s,h,a,zt,xn,wn,ln,oe,y,_,Ce,t,A,f.previewColorScheme,f.previewDevice,f.previewCustomWidth,fe]);u.useEffect(()=>{const W=Je.current,J=je.current;if(!W||!J)return;const R={children:ze.current.components},de=Be(R,J);de?W(de):Le.current&&_.close(Le.current)},[k]);const vM=()=>{if(!Dt)return null;const J={position:"absolute",background:"rgba(15, 23, 42, 0.45)",pointerEvents:"auto",zIndex:W7},R=ke=>{ke.preventDefault(),ke.stopPropagation()};if(!A)return i.jsx("div",{"data-testid":"g7le-edit-lock-full",onClick:R,onMouseMove:R,style:{...J,inset:0}});const{left:de,top:ye,width:we,height:Te}=A;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,ye)}}),i.jsx("div",{"data-testid":"g7le-edit-lock-bottom",onClick:R,onMouseMove:R,style:{...J,left:0,top:ye+Te,right:0,bottom:0}}),i.jsx("div",{"data-testid":"g7le-edit-lock-left",onClick:R,onMouseMove:R,style:{...J,left:0,top:ye,width:Math.max(0,de),height:Te}}),i.jsx("div",{"data-testid":"g7le-edit-lock-right",onClick:R,onMouseMove:R,style:{...J,left:de+we,top:ye,right:0,height:Te}})]})},wl=u.useCallback(()=>{if(G&&$p(C.selectedLockKind)){if(p&&C.selectedPath){p(C.selectedPath);return}Di(G)}},[G,C.selectedPath,C.selectedLockKind,p,Di]),{scale:kl}=m,Sl=typeof C.selectedNode?.name=="string"?C.selectedNode.name:"",Uh=s?.componentCapabilities?.[Sl]??null,qh=Array.isArray(Uh?.styleControls)?Uh.styleControls:[],_M=qh.includes("width")?Ct(s,"width"):null,xM=qh.includes("height")?Ct(s,"height"):null,wM=u.useCallback((W,J)=>{if(!v||!G)return;let R=[];v.patchLayout(de=>(R=Ot({children:de},G,()=>W).children??[],R)),dr({source:"resize",componentPath:at(G),componentName:Sl||null,patchKey:J==="height"?"height":"width",resizeAxis:J,timestamp:Date.now()})},[v,G,Sl]),kM=u.useCallback((W,J)=>{if(!v||!G)return;let R=[];v.patchLayout(de=>(R=Ot({children:de},G,()=>W).children??[],R)),y.push({actionKind:"inline_text_edit",label:`resize ${J}`,snapshot:R})},[v,G,y]),SM=u.useCallback(()=>{if(!oe)return null;const W=oe.getBoundingClientRect(),J=kl||1;return{width:W.width/J,height:W.height/J}},[oe,kl]),lr=v4({node:C.selectedNode,widthControl:_M,heightControl:xM,scale:kl,measureStartSize:SM,onResize:wM,onResizeEnd:kM}),CM=u.useCallback((W,J)=>{lr.onHandlePointerDown(W,J)},[lr]),Cl=u.useCallback(()=>{const W=y.undo();!W||!v||v.setLayoutComponents(W.snapshot)},[y,v]),$l=u.useCallback(()=>{const W=y.redo();!W||!v||v.setLayoutComponents(W.snapshot)},[y,v]);O7({onUndo:Cl,onRedo:$l});const $M=u.useMemo(()=>({copy:ne,cut:pe,paste:Q,delete:Ce,openProps:wl,selectParent:Z?ae:void 0,deselect:C.clearSelection}),[ne,pe,Q,Ce,wl,Z,ae,C.clearSelection]);lp({handlers:$M,hasSelection:!!C.selectedPath}),u.useEffect(()=>(window.__g7LayoutEditorHasSelection=!!C.selectedPath,()=>{try{delete window.__g7LayoutEditorHasSelection}catch{}}),[C.selectedPath]),u.useEffect(()=>(window.__g7LayoutEditorHistory={undo:Cl,redo:$l,canUndo:y.canUndo,canRedo:y.canRedo},()=>{try{delete window.__g7LayoutEditorHistory}catch{}}),[Cl,$l,y.canUndo,y.canRedo]);const EM=u.useCallback(W=>{const J=L;F(null),J&&(async()=>{if((await I.commit(J.path,W)).kind==="created"&&v){const de=v.document?.raw?.components??[];y.push({actionKind:"inline_text_edit",label:"inline_create_key",snapshot:de})}})()},[L,I,v,y]),Gh=u.useCallback(()=>{const W=L;F(null),I.trackCancel(W?.path??null)},[L,I]),IM=u.useCallback(()=>{F(null)},[]),AM=u.useCallback(async W=>{const J=L;if(!J)return null;const R=await I.keyifyChipValue(J.path,W);if(R.kind!=="created"||!R.translationKey)return null;const de=v?.document?.raw?.components??[];return y.push({actionKind:"inline_text_edit",label:"inline_keyify_chip",snapshot:de}),R.translationKey},[L,I,v,y]),TM=u.useCallback(()=>{const W=L;W&&(F(null),C.handleSelect("",{dataset:{editorPath:W.domPath}}),Di(W.path,"translation"))},[L,C,Di]),wt=u.useMemo(()=>{if(!L)return null;const W=v?.document?.raw?.components??k;return Be({children:W},L.path)},[L,v?.document,k]),DM=u.useCallback(async(W,J)=>{const R=L;if(!v||!R)return null;const de=typeof wt?.text=="string"?wt.text:"";let ye;if(R.isParamKey)ye=await Cr(f.templateIdentifier,f.locale,de,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();ye=await us(f.templateIdentifier,f.selectedRoute?.layoutName??null,f.locale,de,W,J.sourceId,J.path,"scalar",He,h)}if(ye.kind==="error")return null;const we=R.path;let Te=[];v.patchLayout(He=>(Te=Ot({children:He},we,Mt=>({...Mt,text:ye.text})).children??[],Te)),y.push({actionKind:"inline_text_edit",label:"inline_insert_binding",snapshot:Te});const ke=ye.kind==="ok"&&"key"in ye?ye.key:void 0;!R.isParamKey&&ke&&F(He=>He&&He.path===we?{...He,isParamKey:!0,customKey:ke,chipValue:void 0,chipParamLabels:void 0}:He);try{window.dispatchEvent(new CustomEvent(kt,{detail:{templateIdentifier:f.templateIdentifier,locale:f.locale}}))}catch{}const _e=vt(ye.text),Ie=R.customKey??_e?.key??"";return Ie?It(Ie,f.locale)??null:null},[v,L,wt,f.templateIdentifier,f.locale,f.selectedRoute,y,h]),zM=u.useCallback(async W=>{const J=L;if(!v||!J)return null;const R=typeof wt?.text=="string"?wt.text:"",de=vt(R),ye=J.customKey??de?.key??null,we=vo(R,W),Te=J.path;let ke=[];return v.patchLayout(_e=>(ke=Ot({children:_e},Te,Nt=>({...Nt,text:we})).children??[],ke)),y.push({actionKind:"inline_text_edit",label:"inline_remove_binding",snapshot:ke}),ye&&await $r(f.templateIdentifier,ye,W,f.locale),ye?It(ye,f.locale)??null:null},[v,L,wt,f.templateIdentifier,f.locale,y]),[El,Yh]=u.useState({}),NM=["fontSize","color","fontStyle","textDecoration","textAlign","letterSpacing","lineHeight","fontFamily"];u.useEffect(()=>{if(!L||!t||typeof MutationObserver>"u"){Yh({});return}const W=`[data-editor-path="${an(L.domPath)}"]`,J=()=>{const ye=t.querySelector(W);if(!ye)return;const we={};for(const ke of NM){const _e=ye.style.getPropertyValue(ke.replace(/([A-Z])/g,"-$1").toLowerCase());_e&&(we[ke]=_e)}const Te=wg(t,L.domPath)??void 0;Yh({className:ye.className,style:we,effectiveColor:Te})};J();const R=t.querySelector(W);if(!R)return;const de=new MutationObserver(J);return de.observe(R,{attributes:!0,attributeFilter:["class","style"]}),de.observe(t,{childList:!0,subtree:!0}),()=>de.disconnect()},[L?.path?at(L.path):null,t]);const Xh=u.useCallback((W,J)=>{if(!v||!L)return;const R=L.path;let de=[],ye=null;v.patchLayout(we=>(de=Ot({children:we},R,_e=>{const Ie=J(_e);return ye=typeof Ie.name=="string"?Ie.name:null,Ie}).children??[],de)),y.push({actionKind:"inline_text_edit",label:`inline_format ${W}`,snapshot:de}),dr({source:"style_control",componentPath:at(R),componentName:ye,patchKey:W,timestamp:Date.now()})},[v,L,y]),ft=u.useMemo(()=>{const W=C.selectedPath;if(!W||!x)return null;const J=[];let R=W;for(;R;){J.push(R);const de=R.match(/^(.*)\.children\.\d+$/);R=de?de[1]:null}for(const de of J){const ye=Re(de);if(!ye)continue;const we=Be(x,ye),Te=typeof we?.name=="string"?we.name:null;if(!Te)continue;const ke=ji(s,Te),_e=ke?.canvasOverlay?.kind;if(typeof _e!="string"||!_e||!we)continue;const Ie=ke.canvasOverlay.params&&typeof ke.canvasOverlay.params=="object"?ke.canvasOverlay.params:void 0,He=de===W?null:W.slice(de.length+1);return{kind:_e,params:Ie,tablePath:de,tableNode:we,selectedCellRel:He}}return null},[C.selectedPath,x,s]),yo=ft?g4(ft.kind):null,Jh=u.useMemo(()=>!yo||!t||!ft?null:fo(t,ft.tablePath),[yo,t,ft,A,k]),MM=u.useMemo(()=>{if(!yo||!t||!ft)return[];const W=ft.tablePath,J=an(W),R=[];return t.querySelectorAll(`[data-editor-path^="${J}.children."]`).forEach(we=>{const Te=we.dataset.editorPath??"";if(!Te.startsWith(W+"."))return;const ke=Te.slice(W.length+1),_e=ao(we,t);_e&&R.push({path:ke,top:_e.top,left:_e.left,width:_e.width,height:_e.height})}),t.querySelectorAll(`[data-editor-item-path^="${J}."]`).forEach(we=>{const Te=we.dataset.editorItemPath??"";if(!Te.startsWith(W+"."))return;const ke=Te.slice(W.length+1),_e=ao(we,t);_e&&R.push({path:ke,top:_e.top,left:_e.left,width:_e.width,height:_e.height})}),R},[yo,t,ft,A,k]),LM=u.useCallback(W=>{const J=ft?Re(ft.tablePath):null;if(!v||!J)return;let R=[];v.patchLayout(de=>(R=Ot({children:de},J,()=>W).children??[],R)),y.push({actionKind:"inline_text_edit",label:"inplace_edit",snapshot:R}),dr({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:[!D&&vM(),D&&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(D,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(RI,{frameEl:t,components:k,editMode:f.editMode,currentExtensionId:$,editableRootPath:S}),L&&((L.isParamKey&&L.customKey||L.chipValue)&&wt?i.jsxs(i.Fragment,{children:[wt&&i.jsx(vg,{node:wt,spec:s,t:h,onApplyControl:Xh,box:L.box,scope:{colorScheme:f.previewColorScheme==="dark"?"dark":"base",breakpoint:Yr(f.previewDevice,wt,f.previewCustomWidth)}}),i.jsx(D4,{box:L.box,node:wt,customKey:L.customKey??null,initialChipValue:L.chipValue,chipParamLabels:L.chipParamLabels,onKeyify:AM,templateIdentifier:f.templateIdentifier,locale:f.locale,t:h,candidates:ln,onInsertBinding:DM,onRemoveBinding:zM,onCommit:IM,onCancel:Gh})]}):i.jsxs(i.Fragment,{children:[wt&&i.jsx(vg,{node:wt,spec:s,t:h,onApplyControl:Xh,box:L.box,scope:{colorScheme:f.previewColorScheme==="dark"?"dark":"base",breakpoint:wt?Yr(f.previewDevice,wt,f.previewCustomWidth):"base"}}),i.jsx(T4,{box:L.box,initialValue:L.initialValue,isCustomKey:L.isCustomKey,t:h,onCommit:EM,onCancel:Gh,mirrorClassName:El.className,mirrorStyle:El.style,nodeEffectiveColor:El.effectiveColor??L.nodeEffectiveColor,onOpenTranslations:TM})]})),!D&&i.jsx(U7,{hoverBox:T,selectedBox:A,lockKind:C.selectedLockKind,navAffordance:C.selectedNavAffordance,onEditProps:wl,onDuplicate:me,onDelete:Ce,onSeparateBranch:$e?.mode==="separate"?U:void 0,separateBranchLabel:xe?.separate,onMergeBranch:$e?.mode==="merge"?ue:void 0,mergeBranchLabel:xe?.merge,definedDeviceBranches:he,onJumpToDevice:he.length>0?j:void 0,onLinkEditDestination:Ae,onEditBase:dt,onEditExtension:pt,extensionLabel:De,baseLayoutLabel:C.selectedBaseLayout,dataSourceLabel:C.selectedDataSourceId,branchLabel:ee,onEditIteration:C.selectedIsIteration&&f.editMode!=="iteration_item"?ot:void 0,resizeEnabledAxes:lr.enabledAxes,onResizeHandlePointerDown:lr.enabledAxes.width||lr.enabledAxes.height?CM:void 0,selectedName:Ee,onSelectParent:Z?ae:void 0}),D&&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")})}),!D&&i.jsx(Z7,{selectedBox:Ue,points:Se.points,onAddRequest:Xe}),yo&&ft&&Jh&&C.selectedLockKind==="none"&&i.jsx(yo,{node:ft.tableNode,params:ft.params,nodeBox:Jh,cellBoxes:MM,selectedCellPath:ft.selectedCellRel??void 0,colorScheme:f.previewColorScheme==="dark"?"dark":"light",t:h,onPatchNode:LM,onInsertChild:se,onRemoveChild:W=>{const J=Re(W);if(!v||!J)return;let R=[];v.patchLayout(de=>(R=ns({children:de},J).children??[],R)),y.push({actionKind:"remove",label:"inplace_remove",snapshot:R})},onRequestInlineEdit:W=>{ft&&Y(`${ft.tablePath}.${W}`)}}),v&&i.jsx(GI,{frameEl:t,nesting:o,editMode:f.editMode,currentExtensionId:$,editableRootPath:S,components:k,patchLayout:v.patchLayout,pushHistory:le,selectedPath:C.selectedPath,onSelectPath:W=>C.handleSelect("",{dataset:{editorPath:W}}),onMovePath:W=>C.handleSelect("",{dataset:{editorPath:W}}),onRequestInlineEdit:Y})]}):null}function xg(e,t){if(t.length===0)return null;const o=Va({children:e},t);return o&&typeof o.name=="string"?o.name:null}function Va(e,t){return Be(e,t)}function an(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/[^a-zA-Z0-9_\-.]/g,t=>`\\${t}`)}function wg(e,t){if(!t)return null;const n=e.querySelector(`[data-editor-path="${an(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 fo(e,t){if(!t)return null;const n=e.querySelector(`[data-editor-path="${an(t)}"]`);if(n){const c=ao(n,e);return c&&lo(c,e)?c:null}const o=e.querySelectorAll(`[data-editor-path^="${an(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=ao(c,e);f&&lo(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 W4({isEditMode:e,editorSpec:t,sampleOverride:n}){const o=t?.sampleData;return u.useMemo(()=>Km({spec:o,overrideSpec:n,onMatch:r=>{Qh(r)}}),[e,o,n])}const j4=Lt().ComponentRegistry;function H4(e){return e.replace(/[\t\n\r]/g,"").replace(/\\/g,"/").replace(/^([a-z][a-z0-9+.\-]*:)?\/{2,}/i,"$1//")}function F4(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 Ua(){const e=typeof window<"u"?window.G7Config?.trustedScriptHosts:void 0;return Array.isArray(e)?e.map(t=>String(t).toLowerCase()):[]}function kg(e,t){if(typeof e!="string")return!1;const n=e.trim();if(n==="")return!1;const o=H4(n),r=o.startsWith("//"),s=/^[a-z][a-z0-9+.-]*:/i.test(o);if(!r&&!s&&o.startsWith("/"))return!0;const a=F4(o),l=t??Ua();return a!==null&&l.map(d=>String(d).toLowerCase()).includes(a)}function K4(e){return e.split(/[-_]/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}async function V4(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 Jr(o.status,s,"assets")}const r=await o.json();return r.data||r}async function U4(e){try{if(typeof fetch!="function")return 0;const t=await fetch(en(`/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 q4(e){return new Promise((t,n)=>{if(typeof document>"u"){n(new Error("document undefined"));return}if(!kg(e,Ua())){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 G4(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 Y4(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 V4(e);if(s)return;for(const b of a.css??[])if(await G4(b),s)return;const l=K4(e);if(!(typeof window<"u"&&typeof window[l]=="object")){for(const b of a.js??[])if(await q4(b),s)return}const c=j4.createIsolatedInstance();if(await c.loadComponents(e,n),s)return;const p=await U4(e);if(s)return;const f=new Pt({defaultLocale:t});if(p>0&&f.setCacheVersion(p),await f.loadTranslations(e,t),s)return;gd(f,e);try{const b=Pt.getInstance();p>b.getCacheVersion()&&b.setCacheVersion(p),await b.loadTranslations(e,t),gd(b,e)}catch{}if(s)return;r({componentRegistry:c,translationEngine:f,isReady:!0,error:null})}catch(a){if(s)return;const l=xp(a)?a:so(a,"assets");r({componentRegistry:null,translationEngine:null,isReady:!1,error:l})}})(),()=>{s=!0}},[e,t,n]),o}const Sg=Lt().AuthManager;function X4(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 J4={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 Z4({error:e}){return u.useEffect(()=>{if(e.kind!=="unauthorized"||typeof window>"u")return;const t=Sg.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 qa({error:e}){const{t}=tt(),n=X4(e.kind),o=J4[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=Sg.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(Z4,{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:Ga,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:Ga,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:Ga,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:Q4,children:t("layout_editor.access_error.action.go_admin_home")})]})]})]})}const Ga={padding:"8px 16px",background:"#2563eb",color:"#fff",border:"1px solid #1d4ed8",borderRadius:6,fontSize:13,fontWeight:600,cursor:"pointer"},Q4={padding:"8px 16px",background:"#fff",color:"#475569",border:"1px solid #cbd5e1",borderRadius:6,fontSize:13,fontWeight:500,cursor:"pointer"};function R4(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 eD=new Set(["id","userId","postId","orderId","productId","categoryId","commentId","noticeId","inquiryId","addressId","wishlistId","notificationId","roleId","menuId"]);function tD(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]=nD(r)}return t}function nD(e){return eD.has(e)||/Id$|_id$/.test(e)?"1":"sample"}const oD=mo("LayoutEditor");function Ro(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function _i(e){if(Array.isArray(e))return e.map(t=>_i(t));if(Ro(e)){const t={};for(const[n,o]of Object.entries(e))t[n]=_i(o);return t}return e}function Cg(e,t="",n=new Set){for(const[o,r]of Object.entries(e)){const s=t?`${t}.${o}`:o;Ro(r)?Cg(r,s,n):n.add(s)}return n}function $g(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];Ro(l)&&Ro(c)?$g(c,l,n,o,r,d):e[a]=_i(l)}}function Ya(e){const t=e.warn??(r=>oD.warn(r)),n=_i(e.coreSeed??{});e.isGuestOnly&&"currentUser"in n&&delete n.currentUser;const o=Cg(n);for(const r of e.sources)Ro(r.sampleGlobal)&&$g(n,r.sampleGlobal,o,r.id,t);return e.isGuestOnly&&"currentUser"in n&&delete n.currentUser,n}function rD(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 iD(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){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 aD(e,t){const n=sD(t);if(!n||n.length===0)return e;let o=e;for(let a=0;a<n.length;a++){if(o==null||typeof o!="object")return e;o=o[n[a]]}if(!Array.isArray(o)||o.length<=1)return e;const r={...e};let s=r;for(let a=0;a<n.length-1;a++){const l=n[a],d=s[l];if(d==null||typeof d!="object")return e;s[l]=Array.isArray(d)?[...d]:{...d},s=s[l]}return s[n[n.length-1]]=o.slice(0,1),r}const lD="SlotContainer";function Eg(e,t=new Set){for(const n of e){if(!n||typeof n!="object")continue;const o=n;if(o.name===lD){const r=o.props?.slotId;typeof r=="string"&&t.add(r)}Array.isArray(o.children)&&Eg(o.children,t)}return t}function dD(e){const t=Eg(e),n=o=>o.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 Xt(e){if(Array.isArray(e))return e.map(t=>Xt(t));if(St(e)){const t={};for(const[n,o]of Object.entries(e))t[n]=Xt(o);return t}return e}function xi(e,t){for(const[n,o]of Object.entries(t)){const r=e[n];St(o)&&St(r)?xi(r,o):e[n]=Xt(o)}}function cD(e){const t=[];let n="";for(let o=0;o<e.length;o+=1){const r=e[o];if(r==="["){n.length>0&&(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 Xa(e,t,n){const o=cD(t);if(o.length===0)return;let r=e;for(let s=0;s<o.length-1;s+=1){const a=o[s],l=r[a];if(St(l)){const d=Xt(l);r[a]=d,r=d}else{const d={};r[a]=d,r=d}}r[o[o.length-1]]=Xt(n)}function uD(e){const t=Xt(e.globalBaseline??{}),n=Xt(e.localBaseline??{}),o=Xt(e.queryBaseline??{}),r=Xt(e.routeBaseline??{});if(e.patch&&(St(e.patch.global)&&xi(t,e.patch.global),St(e.patch.local)&&xi(n,e.patch.local),St(e.patch.query)&&xi(o,e.patch.query),St(e.patch.route)))for(const[s,a]of Object.entries(e.patch.route))a===null?delete r[s]:r[s]=Xt(a);if(St(e.formErrors))for(const[s,a]of Object.entries(e.formErrors))s.startsWith("_global.")?Xa(t,s.slice(8),a):s.startsWith("_local.")?Xa(n,s.slice(7),a):Xa(n,s,a);return{global:t,local:n,query:o,route:r}}function Ig(e){if(!e||!St(e.sampleDataOverrides))return;const t=e.sampleDataOverrides;return St(t.byDataSourceId)||St(t.byEndpointPattern)||St(t.bySource)?t:void 0}function Ja(e){if(!e||!St(e.formErrors))return;const t=e.formErrors;return Object.keys(t).length>0?t:void 0}const Za="g7le:editor-t-ready",Ag="data-g7le-vh-expanded";function pD(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(Ag,"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(Ag,"1"))})}const fD=[];function gD(e={}){const{manifest:t=null,nesting:n=null,componentPalette:o=null,spec:r=null,permissionCandidates:s,sampleGlobalSources:a=fD,resolveRouteMatch:l,onNavigateToDestination:d,onSessionAddedPathsChange:c}=e,{state:p}=Qe(),f=Ft(),b=Dp(),{document:g,isLoading:m,error:h}=f??b,v=u.useRef(null),[y,_]=u.useState(null),{deviceWidth:w,scale:k,colorScheme:x}=Ka(),$=u.useMemo(()=>p.activeStateId?p.availableStates.find(ce=>ce.id===p.activeStateId)??null:null,[p.activeStateId,p.availableStates]),S=u.useMemo(()=>Ig($),[$]),C=W4({isEditMode:!0,editorSpec:r??void 0,sampleOverride:S}),{t:T}=tt(),{componentRegistry:E,translationEngine:A,isReady:N,error:D}=Y4(p.templateIdentifier,p.locale),B=u.useRef(null);B.current===null&&(B.current=new kd);const M=u.useRef(null);if(M.current===null){M.current=new y7({navigate:()=>{}}),M.current.setPreviewMode(!0);try{const q=window.__templateApp?.getActionDispatcher?.();if(q&&typeof q.getRegisteredHandlers=="function"){const ie=q.getRegisteredHandlers();for(const se of ie){if(!se.includes("."))continue;const me=typeof q.getHandler=="function"?q.getHandler(se):void 0;typeof me=="function"&&M.current.registerHandler(se,me,{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 ie=q.getRegisteredHandlers();for(const se of ie){if(!se.includes(".")||typeof ce.getHandler=="function"&&ce.getHandler(se))continue;const me=typeof q.getHandler=="function"?q.getHandler(se):void 0;typeof me=="function"&&ce.registerHandler(se,me,{category:"plugin",source:"preview-canvas-iife-reclone"})}}catch{}},[N]);const O=u.useMemo(()=>new b7({sampleProvider:C,actionDispatcher:M.current}),[C]),z=u.useMemo(()=>g?.raw?.meta?.guest_only===!0,[g]),H=u.useMemo(()=>Ya({sources:a,isGuestOnly:z}),[a,z]),P=u.useMemo(()=>{const ce=hD(Ja($),A,{templateId:p.templateIdentifier,locale:p.locale}),q=H._local,{global:ie,local:se}=uD({globalBaseline:H,localBaseline:q??{},patch:$?.initialState??null,formErrors:ce});return{...ie,_local:se}},[H,$,A,p.templateIdentifier,p.locale]),I=u.useMemo(()=>!$||!(!!$.initialState?.local||!!Ja($))?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,[$]),[K,X]=u.useState(()=>Ya({sources:[],isGuestOnly:!1})),Z=u.useRef(null);u.useEffect(()=>{const ce={...P},q=R4({actionDispatcher:M.current,locale:p.locale,initialGlobalState:ce,onChange:se=>{X(se.globalState)}});Z.current=q;const ie=window.__templateApp;return ie?.setGlobalState&&M.current.setGlobalStateUpdater((se,me)=>{ie.setGlobalState(se,me)}),X(ce),Tl({kind:"applyPatch",activeStateId:p.activeStateId,routePath:p.selectedRoute?.path??null,hasInitialPatch:!!$?.initialState,hasFormErrors:!!Ja($),hasSampleOverride:!!Ig($)}),()=>{q.restore(),Z.current=null}},[p.locale,P]),u.useEffect(()=>{if(!A)return;const ce=window.G7Core;if(!ce||typeof ce.t!="function")return;const q=ce.t,ie=p.templateIdentifier,se=p.locale;return ce.t=(me,Ce)=>{try{const $e=Ce?"|"+Object.entries(Ce).map(([ue,fe])=>`${ue}=${fe}`).join("|"):void 0,U=A.translate(me,{templateId:ie,locale:se},$e);if(U!==me&&!U.startsWith("$t:"))return U}catch{}return q(me,Ce)},typeof window<"u"&&window.dispatchEvent(new CustomEvent(Za)),()=>{window.G7Core?.t&&window.G7Core.t!==q&&(window.G7Core.t=q)}},[A,p.templateIdentifier,p.locale]);const ae=u.useMemo(()=>{const ce=g?.raw?.components??[];return p.editMode!=="base"?ce:dD(ce)},[g,p.editMode]),oe=g?.raw?.__editability,G=g?.raw?.__extensionId,ee=u.useMemo(()=>p.editMode!=="extension"||oe!=="ok"?[]:typeof G!="number"?[]:yD(ae,G),[p.editMode,oe,G,ae]),[ge,V]=u.useState(null),[te,be]=u.useState(!1),Ee=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(()=>{be(!1)},[Ee,De]),u.useEffect(()=>{let ce=!1;const q=g?.raw?.scripts??[];if(!Array.isArray(q)||q.length===0){be(!0);return}const ie=[];for(const se of q){if(!se?.src||typeof se.src!="string")continue;if(!kg(se.src,Ua())){console.warn(`[PreviewCanvas] Blocked untrusted script src (same-origin path or declared trusted host required): ${se.src}`);continue}const me=se.id?`script#${CSS.escape(se.id)}, script[data-g7le-canvas-script="${se.src}"]`:`script[data-g7le-canvas-script="${se.src}"], script[src="${se.src}"]`,Ce=window.document.querySelector(me);if(Ce){const $e=Ce.hasAttribute("data-g7le-canvas-script");if(Ce.hasAttribute("data-g7le-script-loaded")||!$e)continue;ie.push(new Promise(ue=>{if(Ce.hasAttribute("data-g7le-script-loaded")){ue();return}Ce.addEventListener("load",()=>ue()),Ce.addEventListener("error",()=>ue())}));continue}ie.push(new Promise($e=>{const U=window.document.createElement("script");U.src=se.src,U.async=!1,se.id&&(U.id=se.id),U.setAttribute("data-g7le-canvas-script",se.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(ie.length===0){be(!0);return}return Promise.all(ie).then(()=>{ce||requestAnimationFrame(()=>{requestAnimationFrame(()=>{ce||be(!0)})})}),()=>{ce=!0}},[g]);const Se=u.useMemo(()=>g?.raw?.data_sources??[],[g]),Ue=u.useMemo(()=>g?.raw?.computed??{},[g]),[Me,Oe]=u.useState({}),Ye=u.useMemo(()=>{if(p.editMode!=="iteration_item")return Me;const ce=g?.iterationContext;if(!ce)return Me;const q=g?.raw?.components??[],ie=Be({children:q},ce.sourceIndexPath),se=ie&&ie.iteration&&typeof ie.iteration.source=="string"?ie.iteration.source:null;return se?aD(Me,se):Me},[p.editMode,Me,g]),[ze,Xe]=u.useState(0);u.useEffect(()=>{if(typeof window>"u")return;const ce=()=>Xe(q=>q+1);return window.addEventListener(kt,ce),()=>window.removeEventListener(kt,ce)},[]);const ve=u.useMemo(()=>tD(p.selectedRoute?.path??null),[p.selectedRoute?.path]);if(u.useEffect(()=>{let ce=!1;return(async()=>{if(Se.length===0){ce||Oe({});return}try{const q=await O.fetchDataSources(Se,ve,new URLSearchParams,void 0,void 0);ce||Oe(q)}catch{ce||Oe({})}})(),()=>{ce=!0}},[Se,O,ve]),u.useEffect(()=>{const ce=y;if(!ce||typeof window>"u")return;let q=0,ie=0,se=0;const me=()=>pD(ce,window.innerHeight);q=window.requestAnimationFrame(()=>{ie=window.requestAnimationFrame(me)});let Ce=null;return typeof MutationObserver<"u"&&(Ce=new MutationObserver(()=>{se||(se=window.requestAnimationFrame(()=>{se=0,me()}))}),Ce.observe(ce,{childList:!0,subtree:!0})),()=>{window.cancelAnimationFrame(q),window.cancelAnimationFrame(ie),se&&window.cancelAnimationFrame(se),Ce&&Ce.disconnect()}},[y,ae,te,w,Me]),u.useEffect(()=>{const ce=y;if(!ce||typeof window>"u"||p.editMode!=="extension"||oe!=="ok"||ee.length===0){V(null);return}let q=0,ie=0;const se=ue=>{if(!ue)return!1;const fe=ue.getBoundingClientRect();return fe.width>0&&fe.height>0},me=ue=>{const fe=ce.querySelector(`[data-editor-path="${ue}"]`);if(se(fe))return!0;const xe=ce.querySelectorAll(`[data-editor-path^="${ue}.children."]`);for(const he of Array.from(xe))if(se(he))return!0;return!1},Ce=()=>{V(ee.some(me))};q=window.requestAnimationFrame(()=>{ie=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(ie),U&&window.cancelAnimationFrame(U),$e&&$e.disconnect()}},[y,p.editMode,oe,ee,te,Me]),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 ie=ce.createElement("style");ie.id=q;const se=T("layout_editor.preview.slot_area_label");return ie.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:'${se.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(ie),()=>{ce.getElementById(q)?.remove()}},[p.editMode,T]),!(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:er,children:T("layout_editor.preview.empty")});if(m)return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--loading","data-testid":"g7le-preview-loading",style:er,children:T("layout_editor.preview.loading")});if(h)return i.jsx(qa,{error:h});if(D)return i.jsx(qa,{error:D});if(!N||E===null||A===null)return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--assets-loading","data-testid":"g7le-preview-assets-loading",style:er,children:T("layout_editor.preview.assets_loading")});if(ae.length===0)return i.jsx("div",{className:"g7le-preview-canvas g7le-preview-canvas--empty-layout","data-testid":"g7le-preview-empty-layout",style:er,children:T("layout_editor.preview.empty_layout")});const We=p.editMode==="extension"?oe==="no-injection"?"no-injection":oe==="ok"&&ee.length>0&&ge!==!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(h7,{overrideWidth:w,children:ae.map((ce,q)=>i.jsx(g7,{componentDef:ce,dataContext:{...Ye,...rD(K),_global:iD(K),_computedDefinitions:Ue,...I?{_localInit:I,_local:{...Me._local??{},...K._local??{}}}:{},route:bD({...Me.route??{},...ve,path:p.selectedRoute?.path??""},Y),query:{...Me.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:(ie,se)=>{},onComponentHover:(ie,se)=>{}},`${ce.id??`preview-${q}`}:t${ze}${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(B4,{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:T(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"?T("layout_editor.preview.extension_no_injection_desc"):p.availableStates.length>1?T("layout_editor.preview.extension_gated_desc_with_states"):T("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:er,children:T("layout_editor.preview.loading")})}function hD(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 yD(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 bD(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 er={flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"#f1f5f9",color:"#64748b",fontSize:13},mD={desktop:"layout_editor.device.desktop",tablet:"layout_editor.device.tablet",mobile:"layout_editor.device.mobile",portable:"layout_editor.device.portable"};function vD(){const{device:e,zoom:t,customWidth:n,setDevice:o,setZoom:r,setCustomWidth:s,colorScheme:a,setColorScheme:l}=Ka(),{t:d}=tt(),c=Rf();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=mD[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:bg,max:mg,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(Jb,{})]})}function _D(){const{t:e}=tt(),{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(Za,p),()=>{window.cancelAnimationFrame(f),window.removeEventListener(Za,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}),Tl({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 xD(e,t,n){if(e==="extension"){if(typeof n=="string"&&n.length>0){const o=Qa(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=Qa(t,"__base__/");return o?{kind:"base",match:o}:null}case"modal":{const o=Qa(t,"__modal__/");return o?{kind:"modal",match:o}:null}default:return null}}function wD(e,t){if(!t||!Array.isArray(e)||e.length===0)return[];const n=[];for(const o of e)if(SD(o.scope,t))for(const r of o.items??[])r&&typeof r.id=="string"&&r.id.length>0&&n.push(r);return n}function kD(e){if(e.length===0)return null;const t=e.find(n=>n.default===!0);return t?t.id:e[0].id}function SD(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"?CD(t.match,n):n===t.match}function CD(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 Qa(e,t){return e.startsWith(t)?e.slice(t.length):""}const $D="__conngroup__/modals/",ED="__conngroup__/extensions/";function ID(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 AD(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 TD(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 DD(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 ND(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 MD(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 LD(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 Tg(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:`${$D}${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=>MD(a,e.path))});const s=n.get(e.layoutName)??[];s.length>0&&o.push({path:`${ED}${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=>LD(a,e.path))}),o.length>0&&(e.children=[...o,...e.children??[]])}function PD(e){const t=[],n=new Set(e.routes.map(o=>o.path));for(const o of e.routes){const r=AD(o);if(!r)continue;const{label:s,labelSource:a}=ID(o),l=TD(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 OD(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 BD(e,t){DD(e.routes);const n=zD(e.modals),o=ND(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)Tg(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)Tg(b.node,n,o);a.push({path:`__group__/${d}`,layoutName:null,label:OD(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 WD(e){const t=PD(e);return BD(e,t)}const On=mo("useEditorRoutes");function jD(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 Dg(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]=jD(s.display_name,t)??s.identifier);return n}function HD(e){const t=new kd,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("{{")&&(On.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("{{")&&(On.warn("편집기 route redirect 표현식 평가 실패 — fallback 적용",{originalRedirect:a}),l=a.replace(/\{\{[^}]+\}\}/g,"").replace(/\/\/+/g,"/")||"/"),s.redirect=l}return s})}function FD(e){const{dispatch:t}=Qe(),{translationEngine:n,translationContext:o}=tt(),{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=en(`/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(()=>{On.log("편집 대상 lang 로드 완료",{targetTemplate:r,locale:p})}).catch(h=>{On.warn("편집 대상 lang 로드 실패 — 라우트 라벨 fallback 사용",h)}):Promise.resolve(),b=(()=>{if(typeof fetch!="function")return Promise.reject(so(new Error("fetch unavailable"),"routes"));try{const h=fetch(c,{credentials:"same-origin",headers:Ne()});return!h||typeof h.then!="function"?Promise.reject(so(new Error("fetch returned non-Promise (test stub?)"),"routes")):h.then(async v=>{if(!v.ok){const y=await v.json().catch(()=>null);throw Jr(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:Ne()});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)){On.warn("routes 응답 형식이 비정상 — empty tree 로 둠",h),t({type:"SET_ROUTES_ERROR",error:{kind:"unknown",status:200,message:"routes 응답 형식이 비정상입니다.",source:"routes"}});return}const y=HD(h.data.routes),_=Dg("activeModules",p),w=Dg("activePlugins",p),k=(h.data.base_layouts??[]).map(A=>({layoutName:A.layout_name,label:A.label??void 0})),x=(h.data.modals??[]).map(A=>({modalId:A.modal_id,hostLayout:A.host_layout,label:A.label??void 0})),$=(v?.success&&Array.isArray(v.data)?v.data:[]).map(A=>({sourceIdentifier:A.source_identifier,sourceType:A.source_type,sourceLabel:A.source_label,extensions:(A.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}))})),S=WD({routes:y,modals:x,baseLayouts:k,extensionGroups:$,moduleDisplayNames:_,pluginDisplayNames:w});t({type:"SET_ROUTE_TREE",tree:S});const C=h.data.layout_versions,T={};if(C&&typeof C=="object"&&!Array.isArray(C))for(const[A,N]of Object.entries(C))typeof N=="number"&&Number.isFinite(N)&&(T[A]=N);t({type:"SET_LAYOUT_VERSIONS",versions:T});const E={};for(const A of $)for(const N of A.extensions){const D=N.currentVersion;typeof D=="number"&&Number.isFinite(D)&&(E[String(N.id)]=D)}t({type:"SET_EXTENSION_VERSIONS",versions:E}),On.log("routes 로드 완료",{count:y.length,groups:S.length})}).catch(h=>{if(a)return;On.error("routes 로드 실패",h);const v=xp(h)?h:so(h,"routes");t({type:"SET_ROUTES_ERROR",error:v})}),()=>{a=!0}},[r,s,t,n,o?.locale,o?.templateId])}function zg(e,t,n,o=[]){const r=t?Ng(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 Ng(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=Ng(n.children,t);if(o)return o}}return null}function Ra(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=Ra(n.children,t);if(o)return o}}return null}function KD(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=fp(window.location.search);if(a){const c=pp(window.location.search),p=zg(a,c,n,t.routeTree);if(o.current=!0,p)return}const l=up(window.location.search);if(!l){o.current=!0;return}const d=Ra(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=fp(window.location.search);if(l){const p=pp(window.location.search);if(zg(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=up(window.location.search);if(!d){n({type:"SELECT_ROUTE",route:null});return}const c=Ra(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=ea(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 VD(){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 UD(){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 qD(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 GD(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 YD(e,t){if(Array.isArray(e.components)){const n=t.map(o=>el(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&&r<n.length?n[r]:null;s&&(Array.isArray(s.components)||(s.components=[]),s.components.push(el(o)))}return{...e,injections:n}}return e}function el(e){if(!e||typeof e!="object")return e;const t={...e};return delete t.__injectionIndex,delete t.__source,delete t.__injectedProps,delete t._fromBase,Array.isArray(t.children)&&(t.children=t.children.map(n=>el(n))),t}function Mg(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 Lg(e,t){const o=Mg(e,t)[0]?.__source;return o&&o.kind==="extension"&&o.extensionId===t?o:{kind:"extension",extensionId:t}}function tl(e,t){for(const n of e){const o=n?.__source;if(o?.kind==="extension"&&o.extensionId===t||Array.isArray(n.children)&&tl(n.children,t))return!0}return!1}function XD(){const{state:e}=Qe(),t=e.templateIdentifier,n=e.editMode==="extension"?qD(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 A=>{const N=window.G7Config?.cache_version??0,D=en(`/api/layouts/${encodeURIComponent(t)}/${A}`,"json",`${N}.${Tp()}`,"with_source_meta=1"),B=cr(),M={Accept:"application/json"};B&&(M.Authorization=`Bearer ${B}`);const O=await fetch(D,{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 A=window.G7Config?.cache_version??0,N=`/api/admin/templates/${encodeURIComponent(t)}/layout-extensions/${encodeURIComponent(n)}?v=${A}`,D=await fetch(N,{headers:Ne(),credentials:"same-origin"}),B=await D.json().catch(()=>null);if(!D.ok){c(Jr(D.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,I=Array.isArray(M?.host_layouts)?M.host_layouts.filter(oe=>typeof oe=="string"):[],L=o??(I.length===1?I[0]:m&&I.includes(m)?m:null),F=Number(n);v.current=O;let K=GD(O),X={},Z="pending";const ae={kind:"extension",extensionId:F};if(y.current=ae,L){const oe=await w(L);if(oe){X=oe;const G=Array.isArray(oe.components)?oe.components:[],ee=Lg(G,F);if(y.current=ee,tl(G,F))K=G,Z="ok";else{const V=(Array.isArray(oe.modals)?oe.modals:[]).filter(te=>te&&typeof te=="object"&&tl([te],F));if(V.length>0){const te=V.map(be=>({...be,props:{...be.props??{},isOpen:!0}}));K=[...G,...te],y.current=Lg(V,F),Z="ok"}else K=G,Z="no-injection"}}}s({extensionId:F,content:O,extensionType:H,components:K,lockVersion:P,hostLayouts:I,hostLayoutName:L,hostRaw:X,editability:Z}),f(!1),st({op:"load",layoutName:`extension:${n}`,editMode:"extension",statusCode:D.status,timestamp:Date.now()})}catch(A){c(so(A,"layout")),s(null),f(!1)}finally{l(!1)}},[t,n,m,o,w]);u.useEffect(()=>{k()},[k]);const x=u.useCallback(A=>{h(A)},[]),$=u.useCallback(A=>{s(N=>N&&{...N,components:A}),f(!0),st({op:"patch",layoutName:`extension:${_.current?.extensionId??""}`,editMode:"extension",isDirty:!0,timestamp:Date.now()})},[]),S=u.useCallback(A=>{s(N=>N&&{...N,components:A(N.components)}),f(!0)},[]),C=u.useCallback(async()=>{const A=_.current;if(!A)return{kind:"guard_no_document"};const N=`/api/admin/templates/${encodeURIComponent(t)}/layout-extensions/${A.extensionId}`,D=Mg(A.components,A.extensionId),B=D.length>0?D:A.components,M=YD(v.current,B);st({op:"save",layoutName:`extension:${A.extensionId}`,editMode:"extension",saveTarget:"layout_extension",endpoint:N,isDirty:p,timestamp:Date.now()});let O;try{O=await fetch(N,{method:"PUT",headers:Ne({"Content-Type":"application/json"}),credentials:"same-origin",body:JSON.stringify({content:M,expected_lock_version:A.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:${A.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:A.lockVersion+1;s(L=>L&&{...L,lockVersion:P}),f(!1),g(L=>L+1);const I=typeof H.current_version=="number"?H.current_version:void 0;return{kind:"success",newLockVersion:P,newContentVersion:I,savedExtensionId:String(A.extensionId)}}return O.status===409?{kind:"concurrent_modification",currentVersion:z?.current_version??-1,yourVersion:z?.your_version??A.lockVersion}:O.status===422?{kind:"validation_failed",status:422,errors:z?.errors??null}:{kind:"network_error",message:z?.message??`HTTP ${O.status}`}},[t,p]),T=u.useCallback(async()=>{ia(),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:S,save:C,reload:T,needsHostPicker:E,selectHost:x}}const Pg=new Set;function JD(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 ZD(e){return{document:e.document?{layoutName:`extension:${e.document.extensionId}`,raw:{...JD(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:Pg,dirtyLayoutNames:Pg,invalidateCurrentCache:()=>{},reloadCounter:0,save:()=>e.save(),markDirty:()=>{}}}function QD({hostLayouts:e,extensionLabel:t,onSelect:n}){const{t:o}=tt();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 RD(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=_o(l),c=`/api/admin/templates/${encodeURIComponent(e)}/layouts/${t}/preview`,p=await fetch(c,{method:"POST",credentials:"same-origin",headers:Ne({"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",bn={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 e8(){return{actionRecipes:bn,initActionRecipes:bn,errorRecipes:{navigate:bn.navigate,openModal:bn.openModal,toast:bn.toast,setState:bn.setState,sequence:bn.sequence,parallel:bn.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 nl(e,t){return typeof e.label=="string"?e.label.startsWith("$t:")?t(e.label.slice(3)):e.label:String(e.value)}function wi(e){return Array.isArray(e.options)?e.options:[]}function t8({control:e,value:t,onChange:n,t:o}){const r=wi(e);return i.jsx("div",{className:"g7le-widget g7le-widget--segmented","data-testid":"g7le-widget-segmented",style:f8,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:{...x8,background:a?"#2563eb":"#fff",color:a?"#fff":"#0f172a",borderColor:a?"#2563eb":"#cbd5e1"},children:nl(s,o)},String(s.value))})})}function n8({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:Bg,children:[i.jsxs("label",{style:ol,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 o8({control:e,value:t,onChange:n,t:o}){const r=wi(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:w8,children:[i.jsx("option",{value:"",children:o("layout_editor.control.default")}),r.map(s=>i.jsx("option",{value:String(s.value),children:nl(s,o)},String(s.value)))]})}function r8({control:e,value:t,onChange:n}){const o=wi(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:{...k8,background:a?"#2563eb":"#cbd5e1"},children:i.jsx("span",{style:{...S8,transform:a?"translateX(18px)":"translateX(0)"}})})}function i8({control:e,value:t,onChange:n,t:o,freeValueDisabled:r}){const s=wi(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:g8,children:[r?i.jsx("div",{"data-testid":"g7le-dimension-free-disabled",style:v8,children:o("layout_editor.property_modal.dark_preset_only")}):i.jsxs("div",{style:h8,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:y8}),i.jsx("button",{type:"button","data-testid":"g7le-dimension-clear",title:o("layout_editor.control.default"),onClick:()=>{d(""),n(void 0)},style:b8,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:{..._8,background:b?"#2563eb":"#fff",color:b?"#fff":"#0f172a",borderColor:b?"#2563eb":"#cbd5e1"},children:nl(p,o)},f)})})]})}function s8(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 a8(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 l8({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=s8(r),l=a8(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:p8,"data-testid":y,children:[i.jsxs("label",{style:{...ol,minWidth:64},children:[i.jsx("input",{type:"checkbox","data-testid":`${y}-enabled`,checked:$,onChange:S=>x(S.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:S=>k(Number(S.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:d8,children:[i.jsxs("div",{style:c8,children:[i.jsxs("div",{style:u8,"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:{...Og,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:{...Og,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:Bg,children:[i.jsxs("label",{style:{...ol,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 d8={display:"flex",flexDirection:"column",gap:6,width:"100%"},c8={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},u8={display:"inline-flex",gap:0,border:"1px solid #cbd5e1",borderRadius:6,overflow:"hidden"},Og={padding:"3px 10px",fontSize:11,border:"none",borderRight:"1px solid #e2e8f0",cursor:"pointer"},p8={display:"flex",alignItems:"center",gap:8,width:"100%"},f8={display:"inline-flex",gap:0,border:"1px solid #cbd5e1",borderRadius:6,overflow:"hidden"},g8={display:"flex",flexDirection:"column",gap:6,width:"100%"},h8={display:"flex",gap:6,alignItems:"center"},y8={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,minWidth:80},b8={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},v8={fontSize:11,color:"#94a3b8",fontStyle:"italic",padding:"2px 0"},_8={padding:"3px 9px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:999,background:"#fff",cursor:"pointer"},x8={padding:"4px 10px",fontSize:12,border:"none",borderRight:"1px solid #e2e8f0",cursor:"pointer"},Bg={display:"flex",alignItems:"center",gap:8,width:"100%"},ol={display:"inline-flex",alignItems:"center",gap:4},w8={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",minWidth:120},k8={position:"relative",width:38,height:20,borderRadius:10,border:"none",cursor:"pointer",padding:2,display:"inline-flex",alignItems:"center",transition:"background 120ms ease"},S8={display:"block",width:16,height:16,borderRadius:8,background:"#fff",transition:"transform 120ms ease"},C8=["#0f172a","#334155","#64748b","#94a3b8","#e2e8f0","#ffffff","#dc2626","#ea580c","#d97706","#16a34a","#0891b2","#2563eb","#7c3aed","#db2777"],Wg=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function $8(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 E8({control:e,value:t,onChange:n,t:o,freeValueDisabled:r}){const s=$8(e),a=s.length>0,l=typeof t=="string"&&s.some(g=>g.value===t)?t:"",d=typeof t=="string"&&Wg.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}`;Wg.test(h)&&n(h)},b=C8;return i.jsxs("div",{className:"g7le-widget g7le-widget--color","data-testid":"g7le-widget-color",style:I8,children:[r?i.jsx("div",{"data-testid":"g7le-color-free-disabled",style:M8,children:o("layout_editor.property_modal.dark_preset_only")}):i.jsxs("div",{style:A8,children:[i.jsxs("label",{style:T8,children:[i.jsx("span",{"data-testid":"g7le-color-swatch",style:{...D8,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:z8}),i.jsx("button",{type:"button","data-testid":"g7le-color-clear",onClick:()=>n(void 0),style:N8,children:o("layout_editor.control.default")})]}),a?i.jsx("div",{style:jg,"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:{...Hg,background:g.swatch||"#e2e8f0",outline:m?"2px solid #2563eb":"none"}},g.value)})}):!r&&i.jsx("div",{style:jg,"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:{...Hg,background:g,outline:d.toLowerCase()===g.toLowerCase()?"2px solid #2563eb":"none"}},g))})]})}const I8={display:"flex",flexDirection:"column",gap:8},A8={display:"flex",alignItems:"center",gap:6},T8={position:"relative",display:"inline-flex",cursor:"pointer"},D8={width:24,height:24,borderRadius:4,border:"1px solid #cbd5e1",display:"inline-block"},z8={flex:1,padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,fontFamily:"monospace"},N8={padding:"4px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",cursor:"pointer",color:"#64748b"},jg={display:"grid",gridTemplateColumns:"repeat(7, 1fr)",gap:4},Hg={width:"100%",height:18,borderRadius:4,border:"1px solid #cbd5e1",cursor:"pointer",padding:0},M8={fontSize:11,color:"#94a3b8",fontStyle:"italic",padding:"2px 0"},tr=[{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 L8(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Fg(e){return tr.find(n=>n.size===e.size&&n.repeat===e.repeat)?.value??"fill"}function P8({value:e,onChange:t,t:n}){const o=L8(e),{state:r}=Qe(),s=bo(),[a,l]=u.useState(!1),[d,c]=u.useState(null),[p,f]=u.useState(o.url??""),[b,g]=u.useState([]),m=u.useRef(null),h=r.templateIdentifier,v=r.selectedRoute?.layoutName??"";u.useEffect(()=>{f(o.url??"")},[o.url]);const y=u.useCallback(async()=>{if(!h||!v){g([]);return}const S=await Ll(h,v);S.ok&&g(S.data)},[h,v]);u.useEffect(()=>{y()},[y]);const _=S=>{if(!S){t(void 0);return}const C=tr.find(T=>T.value===Fg(o))??tr[0];t({url:S,size:o.size??C.size,repeat:o.repeat??C.repeat,position:o.position??"center"})},w=S=>{const C=tr.find(T=>T.value===S);!C||!o.url||t({url:o.url,size:C.size,repeat:C.repeat,position:o.position??"center"})},k=async S=>{const C=S.target.files?.[0];if(!C)return;l(!0),c(null);const T=await Pl(h,v,C);T.ok?(_(T.data.url),y()):c(n("layout_editor.control.background_image.upload_failed")),l(!1),m.current&&(m.current.value="")},x=async S=>{(await Ol(S.id)).ok&&g(T=>T.filter(E=>E.id!==S.id))},$=()=>{const S=s.open({ariaLabel:n("layout_editor.attachment_manager.title"),width:720,maxHeightRatio:.82,content:u.createElement(Bl,{templateIdentifier:h,layoutName:v,t:n,onSelect:C=>{_(C),s.close(S)},onChanged:()=>{y()},onClose:()=>s.close(S)})})};return i.jsxs("div",{className:"g7le-widget g7le-widget--image","data-testid":"g7le-widget-image",style:O8,children:[o.url&&i.jsx("div",{"data-testid":"g7le-image-preview",style:{...B8,backgroundImage:`url(${o.url})`,backgroundSize:o.size??"cover",backgroundRepeat:o.repeat??"no-repeat",backgroundPosition:o.position??"center"}}),i.jsxs("div",{style:W8,children:[i.jsxs("label",{style:j8,children:[a?"…":n("layout_editor.control.background_image.upload"),i.jsx("input",{ref:m,type:"file",accept:"image/*","data-testid":"g7le-image-file",onChange:k,disabled:a,style:{display:"none"}})]}),i.jsx("button",{type:"button","data-testid":"g7le-image-clear",onClick:()=>t(void 0),style:H8,children:n("layout_editor.control.background_image.clear")})]}),i.jsx("input",{type:"text","data-testid":"g7le-image-url",placeholder:"https://… / URL",value:p,onChange:S=>f(S.target.value),onBlur:S=>_(S.target.value.trim()||void 0),style:F8}),i.jsx("div",{style:K8,"data-testid":"g7le-image-modes",children:tr.map(S=>{const C=Fg(o)===S.value;return i.jsx("button",{type:"button","data-testid":`g7le-image-mode-${S.value}`,"data-active":C?"true":"false",disabled:!o.url,onClick:()=>w(S.value),style:{...V8,background:C&&o.url?"#2563eb":"#fff",color:C&&o.url?"#fff":"#0f172a"},children:n(S.labelKey)},S.value)})}),i.jsxs("div",{style:U8,"data-testid":"g7le-image-gallery",children:[i.jsxs("div",{style:q8,children:[i.jsx("span",{style:{fontSize:11,color:"#64748b"},children:n("layout_editor.attachment_manager.recent")}),i.jsxs("button",{type:"button","data-testid":"g7le-image-manage",onClick:$,style:G8,children:["🖼 ",n("layout_editor.attachment_manager.manage_link")]})]}),b.length>0?i.jsx("div",{style:Y8,"data-testid":"g7le-image-thumbs",children:b.slice(0,8).map(S=>i.jsxs("div",{style:X8,"data-testid":`g7le-image-thumb-${S.id}`,children:[i.jsx("button",{type:"button",title:S.original_name,onClick:()=>_(S.url),style:{...J8,backgroundImage:`url(${S.url})`},"data-testid":`g7le-image-thumb-use-${S.id}`}),i.jsx("button",{type:"button",title:n("layout_editor.attachment_manager.delete"),onClick:()=>x(S),style:Z8,"data-testid":`g7le-image-thumb-del-${S.id}`,children:"✕"})]},S.id))}):i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:n("layout_editor.attachment_manager.empty")})]}),d&&i.jsx("span",{"data-testid":"g7le-image-error",style:{fontSize:11,color:"#dc2626"},children:d})]})}const O8={display:"flex",flexDirection:"column",gap:6},B8={width:"100%",height:80,borderRadius:6,border:"1px solid #cbd5e1"},W8={display:"flex",gap:6},j8={padding:"5px 10px",fontSize:12,border:"1px solid #2563eb",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",display:"inline-flex",alignItems:"center"},H8={padding:"5px 10px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#64748b",cursor:"pointer"},F8={padding:"5px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},K8={display:"inline-flex",border:"1px solid #cbd5e1",borderRadius:6,overflow:"hidden"},V8={padding:"4px 10px",fontSize:12,border:"none",borderRight:"1px solid #e2e8f0",cursor:"pointer"},U8={display:"flex",flexDirection:"column",gap:4,border:"1px solid #e2e8f0",borderRadius:6,padding:6,marginTop:2},q8={display:"flex",alignItems:"center",justifyContent:"space-between"},G8={fontSize:11,color:"#2563eb",background:"transparent",border:"none",cursor:"pointer",padding:0},Y8={display:"flex",gap:6,flexWrap:"wrap"},X8={position:"relative",width:44,height:44},J8={width:44,height:44,borderRadius:6,border:"1px solid #cbd5e1",backgroundSize:"cover",backgroundPosition:"center",cursor:"pointer",padding:0},Z8={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 Q8(e){return Array.isArray(e)&&e.every(t=>t!==null&&typeof t=="object"&&!Array.isArray(t))}function R8(e){return typeof e=="string"&&/\{\{.*\}\}/.test(e)}function ez({value:e,onChange:t,t:n,bindingCandidates:o}){if(R8(e))return i.jsx("div",{className:"g7le-widget g7le-widget--options-list","data-testid":"g7le-widget-options-list-bound",style:lz,children:n("layout_editor.list_editor.bound_degraded")});const r=Q8(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:tz,children:[r.length===0&&i.jsx("div",{"data-testid":"g7le-options-empty",style:az,children:n("layout_editor.list_editor.empty")}),r.map((b,g)=>i.jsxs("div",{"data-testid":`g7le-options-row-${g}`,style:nz,children:[i.jsxs("div",{style:Kg,children:[i.jsx("span",{style:Vg,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:rz})]}),i.jsxs("div",{style:Kg,children:[i.jsx("span",{style:Vg,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:oz,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:Ug,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:Ug,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-options-remove-${g}`,title:n("layout_editor.list_editor.remove"),onClick:()=>l(g),style:iz,children:"✕"})]})]},g)),i.jsx("button",{type:"button","data-testid":"g7le-options-add",onClick:c,style:sz,children:n("layout_editor.list_editor.add")})]})}const tz={display:"flex",flexDirection:"column",gap:8,width:"100%"},nz={display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0,paddingBottom:6,borderBottom:"1px solid #f1f5f9"},Kg={display:"flex",gap:6,alignItems:"center",width:"100%",minWidth:0},Vg={flexShrink:0,width:36,fontSize:11,color:"#94a3b8",textAlign:"right"},oz={display:"flex",gap:4,alignItems:"center",justifyContent:"flex-end"},rz={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},Ug={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},iz={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},sz={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},az={fontSize:11,color:"#94a3b8",fontStyle:"italic"},lz={fontSize:11,color:"#b45309",fontStyle:"italic",padding:"4px 2px"},qg=/[^A-Za-z0-9\-_:.]/g;function dz(e){return typeof e=="string"&&Yi(e)}function Gg(e){return Yi(e)?In(e).map(t=>t.kind==="binding"?t.raw:t.raw.replace(qg,"")).join(""):e.replace(qg,"")}const cz={width:"100%",padding:"6px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:4,fontFamily:"monospace"},uz={marginTop:4,fontSize:11,color:"#94a3b8"},pz={display:"flex",gap:6,alignItems:"center"},fz={flexShrink:0,padding:"5px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:4,background:"#f8fafc",cursor:"pointer",whiteSpace:"nowrap"};function gz({value:e,onChange:t,t:n,bindingCandidates:o}){const r=e==null?"":String(e),s=dz(e),a=!!o&&o.length>0,[l,d]=u.useState(!1),c=p=>{const f=Gg(p);t(f===""?void 0:f)};return s||l?i.jsxs("div",{"data-testid":"g7le-core-id-chip",children:[i.jsx(_s,{value:r,onChange:c,t:n,candidates:o,onDone:()=>d(!1),testidPrefix:"g7le-core-id-chip-input"}),i.jsx("div",{style:uz,children:n("layout_editor.core_props.id.binding_hint")})]}):i.jsx("div",{children:i.jsxs("div",{style:pz,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=Gg(p.target.value);t(f===""?void 0:f)},spellCheck:!1,autoComplete:"off",style:cz}),a&&i.jsxs("button",{type:"button","data-testid":"g7le-core-id-add-data",onClick:()=>d(!0),style:fz,title:n("layout_editor.core_props.id.add_data"),children:["🔗 ",n("layout_editor.core_props.id.add_data")]})]})})}const hz=/[^A-Za-z0-9.\-_]/g;function yz(e){return typeof e=="string"&&/\{\{[\s\S]*?\}\}/.test(e)}function bz(e){return e.replace(hz,"")}const Yg={width:"100%",padding:"6px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:4,fontFamily:"monospace",boxSizing:"border-box"},mz={...Yg,background:"#f1f5f9",color:"#64748b",cursor:"not-allowed"},Xg={marginTop:4,fontSize:11,color:"#94a3b8"};function vz({value:e,onChange:t,t:n}){const o=e==null?"":String(e);return yz(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:Xg,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=bz(s.target.value);t(a===""?void 0:a)},spellCheck:!1,autoComplete:"off",style:Yg}),i.jsx("div",{style:Xg,children:n("layout_editor.core_props.dataKey.hint")})]})}let Jg=!1;function _z(){Jg||(Ze("segmented",t8),Ze("slider",n8),Ze("select",o8),Ze("dimension",i8),Ze("spacing",l8),Ze("toggle",r8),Ze("color",E8),Ze("image",P8),Ze("tag-input",vs),Ze("page-picker",P0),Ze("datasource-picker",Fc),Ze("binding-picker",Fc),Ze("binding-list",W0),Ze("state-key-picker",Ts),Ze("modal-picker",O0),Ze("i18n-text",B0),Ze("text",j0),Ze("options-list",ez),Ze("core-id",gz),Ze("core-datakey",vz),Ze("component-target-picker",p4),Jg=!0)}function nr(e){return Array.isArray(e.children)?e.children:[]}function or(e){if(typeof e.text=="string")return[];let t=null;const n=(o,r)=>{const s=nr(o);for(let a=0;a<s.length;a++){const l=s[a],d=[...r,a];if(typeof l.text=="string")if(l.text.trim().length<=1)t===null&&(t=d);else return d;const c=n(l,d);if(c)return c}return null};return n(e,[])??t}function ki(e,t){let n=e;for(const o of t){if(!n)return null;n=nr(n)[o]??null}return n}function rr(e,t,n){if(t.length===0)return{...e,text:n};const[o,...r]=t,a=nr(e).map((l,d)=>d===o?rr(l,r,n):l);return{...e,children:a}}function Zg(e,t){const n=r=>typeof r.props?.[t]=="string";if(n(e))return[];const o=(r,s)=>{const a=nr(r);for(let l=0;l<a.length;l++){const d=a[l],c=[...s,l];if(n(d))return c;const p=o(d,c);if(p)return p}return null};return o(e,[])}function Qg(e,t,n,o){if(t.length===0)return{...e,props:{...e.props??{},[n]:o}};const[r,...s]=t,l=nr(e).map((d,c)=>c===r?Qg(d,s,n,o):d);return{...e,children:l}}function xz(e){return Array.isArray(e.children)?e.children:[]}function wz(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 rl(e,t){if(!(typeof e!="string"||e.length===0))return e.startsWith("$t:")?t(e.slice(3)):e}function Rg({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=wz(t),f=rl(typeof t?.childLabel=="string"?t.childLabel:void 0,r)??d??"",b=xz(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 S=null;for(const C of Object.values($))if(Array.isArray(C)){const T=C.find(E=>E.name===d);if(T){S=T;break}}return S?zf(S):{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 $=or(x);if($!==null&&$.length>0){const S=ki(x,$);if(S&&S.text===""){const C=rr(x,$,r("layout_editor.list_editor.new_item"));g([...b,C]);return}}}g([...b,x])}},[m,g,b,r]),v=u.useCallback(x=>{g(b.filter(($,S)=>S!==x))},[g,b]),y=u.useCallback((x,$)=>{const S=x+$;if(S<0||S>=b.length)return;const C=[...b];[C[x],C[S]]=[C[S],C[x]],g(C)},[g,b]),_=u.useCallback((x,$)=>{if(typeof $!="string"||$.length===0)return;const S=b[x];if(!S)return;const C=or(S);if(C===null)return;const T=b.map((E,A)=>A===x?rr(E,C,$):E);g(T)},[b,g]),w=u.useCallback((x,$,S)=>{if(typeof S!="string"||S.length===0)return;const C=b[x];if(!C)return;const T=Zg(C,$);if(T===null)return;const E=b.map((A,N)=>N===x?Qg(A,T,$,S):A);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:nh,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:kz,children:[i.jsx("div",{style:Sz,children:r("layout_editor.list_editor.items_title")}),b.length===0&&i.jsx("div",{"data-testid":"g7le-children-empty",style:nh,children:r("layout_editor.list_editor.empty")}),b.map((x,$)=>{const S=[];for(const T of p)if(T.kind==="text"){const E=or(x),A=E!==null?ki(x,E):null;A&&typeof A.text=="string"&&S.push({key:"text",caption:rl(T.label,r)??(k?r("layout_editor.list_editor.item_label"):void 0),value:A.text,onChange:N=>_($,N),testid:`g7le-children-i18n-${$}`})}else if(T.kind==="prop"&&T.prop){const E=Zg(x,T.prop);if(E!==null){const N=ki(x,E)?.props?.[T.prop];S.push({key:`prop-${T.prop}`,caption:rl(T.label,r)??T.prop,value:typeof N=="string"?N:"",onChange:D=>w($,T.prop,D),testid:`g7le-children-prop-${T.prop}-${$}`})}}const C=typeof x?.name=="string"?x.name:r("layout_editor.list_editor.item");return i.jsxs("div",{"data-testid":`g7le-children-row-${$}`,style:Cz,children:[S.length>0?S.map(T=>i.jsx("div",{style:eh,children:i.jsxs("div",{"data-testid":T.key==="text"?`g7le-children-text-${$}`:`g7le-children-field-${T.key}-${$}`,style:$z,children:[T.caption!==void 0&&i.jsx("div",{"data-testid":`g7le-children-caption-${T.key}-${$}`,style:Ez,children:T.caption}),i.jsx(_t,{value:T.value,onChange:T.onChange,t:r,placeholder:r("layout_editor.list_editor.item_text"),testidPrefix:T.testid,candidates:l,enableExpressionTree:!0,expressionTreeCollapsible:!0})]})},T.key)):i.jsx("div",{style:eh,children:i.jsx("span",{"data-testid":`g7le-children-label-${$}`,style:Az,children:C})}),i.jsxs("div",{style:Iz,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:th,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:th,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-children-remove-${$}`,title:r("layout_editor.list_editor.remove"),onClick:()=>v($),style:Tz,children:"✕"})]})]},$)}),i.jsx("button",{type:"button","data-testid":"g7le-children-add",onClick:h,style:Dz,children:r("layout_editor.list_editor.add_child",{component:f})})]})}const kz={display:"flex",flexDirection:"column",gap:6,width:"100%",marginBottom:12},Sz={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:2},Cz={display:"flex",flexDirection:"column",gap:4,width:"100%",minWidth:0,paddingBottom:6,borderBottom:"1px solid #f1f5f9"},eh={display:"flex",gap:4,alignItems:"flex-start",width:"100%",minWidth:0},$z={flex:1,minWidth:0},Ez={fontSize:11,color:"#64748b",marginBottom:2},Iz={display:"flex",gap:4,alignItems:"center",justifyContent:"flex-end"},Az={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,color:"#475569",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},th={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},Tz={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},Dz={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},nh={fontSize:11,color:"#94a3b8",fontStyle:"italic"},go={rowContainer:"Tbody",row:"Tr",cell:"Td",headerCell:"Th",colSpanProp:"colSpan",rowSpanProp:"rowSpan"};function yt(e){return{rowContainer:e?.rowContainer??go.rowContainer,row:e?.row??go.row,cell:e?.cell??go.cell,headerCell:e?.headerCell??go.headerCell,colSpanProp:e?.colSpanProp??go.colSpanProp,rowSpanProp:e?.rowSpanProp??go.rowSpanProp}}function Bn(e){return e?Array.isArray(e.children)?e.children:[]:[]}function oh(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 Pe(e,t){const n=yt(t),o=[],r=Bn(e),s=[];r.forEach((f,b)=>{(Bn(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)=>{Bn(f.container).filter(m=>m.name===n.row).forEach((m,h)=>{const v=[],y=p(d);let _=0;Bn(m).filter(k=>k.name===n.cell||k.name===n.headerCell).forEach((k,x)=>{for(;y[_];)_++;const $=oh(k,n.colSpanProp),S=oh(k,n.rowSpanProp),C={cell:k,sectionIndex:b,rowIndexInSection:h,cellIndexInRow:x,gridRow:d,gridCol:_,colSpan:$,rowSpan:S,isHeader:k.name===n.headerCell};v.push(C);for(let T=0;T<S;T++){const E=p(d+T);for(let A=0;A<$;A++)E[_+A]&&o.push(`overlap at row ${d+T}, col ${_+A}`),E[_+A]=!0}_+=$}),c=Math.max(c,_),l.push({cells:v,sectionIndex:b,rowIndexInSection:h,rowNode:m}),d++})});for(let f=0;f<d;f++){const b=a[f]??[];for(let g=0;g<c;g++)b[g]||o.push(`hole at row ${f}, col ${g}`)}return{sections:s,rows:l,colCount:c,valid:o.length===0,issues:o}}function il(e,t,n){const o=yt(n),s=Pe(e,n).sections[t.sectionIndex],a=[];let l;s&&s.containerIndex>=0?(a.push(s.containerIndex),l=Bn(e)[s.containerIndex]??e):l=e;let d=-1,c=-1,p=null;const f=Bn(l);for(let m=0;m<f.length;m++)if(f[m].name===o.row&&(d++,d===t.rowIndexInSection)){c=m,p=f[m];break}if(c<0||!p)return a;a.push(c);let b=-1;const g=Bn(p);for(let m=0;m<g.length;m++){const h=g[m].name;if((h===o.cell||h===o.headerCell)&&(b++,b===t.cellIndexInRow))return a.push(m),a}return a}function Ve(e,t,n){for(const o of e.rows)for(const r of o.cells)if(t>=r.gridRow&&t<r.gridRow+r.rowSpan&&n>=r.gridCol&&n<r.gridCol+r.colSpan)return r;return null}function rh(e){if(e.colCount===0)return[];const t=new Set([0,e.colCount]);for(let r=1;r<e.colCount;r++){let s=!1;for(const a of e.rows){for(const l of a.cells)if(l.gridCol<r&&l.gridCol+l.colSpan>r){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;r<n.length-1;r++)o.push({start:n[r],end:n[r+1]});return o}function ih(e){const t=e.rows.length;if(t===0)return[];const n=a=>e.rows.find(l=>(l.cells[0]?.gridRow??-1)===a)?.sectionIndex??e.rows[a]?.sectionIndex??0,o=new Set([0,t]);for(let a=1;a<t;a++){if(n(a)!==n(a-1)){o.add(a);continue}let l=!1;for(const d of e.rows){for(const c of d.cells)if(c.gridRow<a&&c.gridRow+c.rowSpan>a){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;a<r.length-1;a++)s.push({start:r[a],end:r[a+1],sectionIndex:n(r[a])});return s}function Si(e,t,n){const o=ih(e),r=o.findIndex(a=>t>=a.start&&t<a.end);if(r<0)return{ok:!1,reason:"boundary"};const s=r+n;return s<0||s>=o.length?{ok:!1,reason:"boundary"}:o[r].sectionIndex!==o[s].sectionIndex?{ok:!1,reason:"section"}:{ok:!0}}function Ci(e,t,n){const o=rh(e),r=o.findIndex(a=>t>=a.start&&t<a.end);if(r<0)return{ok:!1,reason:"boundary"};const s=r+n;return s<0||s>=o.length?{ok:!1,reason:"boundary"}:{ok:!0}}function Ge(e){return e?Array.isArray(e.children)?e.children:[]:[]}function mn(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 $i(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 ir(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=Ge(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=Ge(e).map(a=>a.name===t&&(r++,r===n)?o(a):a);return{...e,children:s}}function Ei(e,t,n){let o=-1;const r=Ge(e);for(let s=0;s<r.length;s++)if(ir(r[s],t)&&(o++,o===n))return s;return-1}function sl(e,t,n){const o=yt(t),r=Pe(e,t);if(r.rows.length===0||r.colCount===0){const y={type:"basic",name:o.row,children:[$i(o)]};return r.sections.length>0?nt(e,r,r.sections.length-1,_=>({..._,children:[...Ge(_),y]})):{...e,children:[...Ge(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(;g<r.colCount;){const y=d>0?Ve(r,d-1,g):null;y&&y.gridRow+y.rowSpan>d&&y.rowSpan>1?(b.push(y),g+=y.colSpan):(f.push($i(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:Ge(w).map((k,x)=>x===y.cellIndexInRow?mn(k,o.rowSpanProp,y.rowSpan+1):k)})));const h={type:"basic",name:o.row,children:f},v=Pe(m,t);return m=nt(m,v,c,y=>{const _=Ge(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 sh(e,t,n){const o=yt(t),r=Pe(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;p<r.colCount;){const f=Ve(r,a,p);f&&f.gridRow<a&&!d.has(f.cell)&&(d.add(f.cell),l=nt(l,r,f.sectionIndex,b=>bt(b,o.row,f.rowIndexInSection,g=>({...g,children:Ge(g).map((m,h)=>h===f.cellIndexInRow?mn(m,o.rowSpanProp,f.rowSpan-1):m)})))),p+=f?f.colSpan:1}const c=Pe(l,t);return l=nt(l,c,s.sectionIndex,p=>{let f=-1;const b=Ge(p).filter(g=>g.name===o.row?(f++,f!==s.rowIndexInSection):!0);return{...p,children:b}}),l}function ah(e,t,n,o){const r=yt(t),s=Pe(e,t);if(!Si(s,n,o).ok)return e;const a=ih(s),l=a.findIndex(h=>n>=h.start&&n<h.end),d=l+o,c=a[l],p=a[d],f=c.sectionIndex,b=h=>s.rows.filter(v=>{const y=v.cells[0]?.gridRow??-1;return v.sectionIndex===f&&y>=h.start&&y<h.end}).map(v=>v.rowIndexInSection),g=b(c),m=b(p);return g.length===0||m.length===0?e:nt(e,s,f,h=>{const v=[...Ge(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(..._)<Math.min(...w),S=$?_:w,C=$?k:x,T=$?w:_,E=$?x:k,A=Math.min(...S),N=Math.max(...T),D=[...E,...C],B=[...v.slice(0,A),...D,...v.slice(N+1)];return{...h,children:B}})}function lh(e,t,n,o){const r=yt(t),s=Pe(e,t);if(!Ci(s,n,o).ok)return e;const a=rh(s),l=a.findIndex(m=>n>=m.start&&n<m.end),d=l+o,c=a[l],p=a[d],f=c.start<p.start?c:p,b=c.start<p.start?p:c;let g=e;for(const m of s.rows){const h=m.cells.filter(k=>k.gridCol>=f.start&&k.gridCol<f.end),v=m.cells.filter(k=>k.gridCol>=b.start&&k.gridCol<b.end);if(h.length===0||v.length===0)continue;const y=h.map(k=>k.cellIndexInRow),_=v.map(k=>k.cellIndexInRow),w=Pe(g,t);g=nt(g,w,m.sectionIndex,k=>bt(k,r.row,m.rowIndexInSection,x=>{const $=[...Ge(x)],S=y.map(M=>Ei(x,r,M)).filter(M=>M>=0),C=_.map(M=>Ei(x,r,M)).filter(M=>M>=0);if(S.length===0||C.length===0)return x;const T=S.map(M=>$[M]),E=C.map(M=>$[M]),A=Math.min(...S,...C),N=Math.max(...S,...C),D=[...E,...T],B=[...$.slice(0,A),...D,...$.slice(N+1)];return{...x,children:B}}))}return g}function dh(e,t,n){const o=yt(t),r=Pe(e,t);if(r.rows.length===0||r.colCount===0)return sl(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?Ve(r,c,s-1):null,f=s<r.colCount?Ve(r,c,s):null;if(p&&f&&p.cell===f.cell&&p.colSpan>1){if(!l.has(p.cell)){l.add(p.cell);const h=Pe(a,t);a=nt(a,h,p.sectionIndex,v=>bt(v,o.row,p.rowIndexInSection,y=>({...y,children:Ge(y).map((_,w)=>w===p.cellIndexInRow?mn(_,o.colSpanProp,p.colSpan+1):_)})))}continue}if(p&&p.gridRow<c||f&&f.gridRow<c)continue;const b=p&&p.gridRow===c?p.cellIndexInRow:-1,g=d.cells.length>0&&d.cells.every(h=>h.isHeader),m=Pe(a,t);a=nt(a,m,d.sectionIndex,h=>bt(h,o.row,d.rowIndexInSection,v=>{const y=[...Ge(v)];let _;if(b<0)_=y.findIndex(w=>ir(w,o)),_<0&&(_=y.length);else{const w=Ei(v,o,b);_=w<0?y.length:w+1}return y.splice(_,0,$i(o,void 0,g)),{...v,children:y}}))}return a}function ch(e,t,n){const o=yt(t),r=Pe(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=Ve(r,d,n);if(!(!c||a.has(c.cell)||c.gridRow<d))if(a.add(c.cell),c.colSpan>1){const p=Pe(s,t);s=nt(s,p,c.sectionIndex,f=>bt(f,o.row,c.rowIndexInSection,b=>({...b,children:Ge(b).map((g,m)=>m===c.cellIndexInRow?mn(g,o.colSpanProp,c.colSpan-1):g)})))}else{const p=Pe(s,t);s=nt(s,p,c.sectionIndex,f=>bt(f,o.row,c.rowIndexInSection,b=>{let g=-1;const m=Ge(b).filter(h=>ir(h,o)?(g++,g!==c.cellIndexInRow):!0);return{...b,children:m}}))}}return s}function al(e,t,n,o,r,s){const a=yt(t),l=Pe(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=Ve(l,y,_);if(!w)return{table:e,ok:!1,reason:"hole"};if(w.gridRow<d||w.gridCol<p||w.gridRow+w.rowSpan-1>c||w.gridCol+w.colSpan-1>f)return{table:e,ok:!1,reason:"not-rectangular"};b.add(w)}const g=Ve(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:Ge(_).map((w,k)=>{if(k!==g.cellIndexInRow)return w;let x=mn(w,a.colSpanProp,f-p+1);return x=mn(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(S=>S.cellIndexInRow)),$=Pe(h,t);h=nt(h,$,w,S=>bt(S,a.row,k,C=>{let T=-1;const E=Ge(C).filter(A=>ir(A,a)?(T++,!x.has(T)):!0);return{...C,children:E}}))}return{table:h,ok:!0}}function uh(e,t,n,o){const r=yt(t),s=Pe(e,t),a=Ve(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:Ge(h).map((v,y)=>{if(y!==a.cellIndexInRow)return v;let _=mn(v,r.colSpanProp,1);return _=mn(_,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=Pe(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.gridCol<h&&(_=Math.max(_,k.cellIndexInRow));const w=b?{props:{className:b}}:null;g=nt(g,v,y.sectionIndex,k=>bt(k,r.row,y.rowIndexInSection,x=>{const $=[...Ge(x)];let S;if(_<0)S=$.findIndex(C=>ir(C,r)),S<0&&(S=$.length);else{const C=Ei(x,r,_);S=C<0?$.length:C+1}return $.splice(S,0,$i(r,w,f)),{...x,children:$}}))}return g}function Ii(e,t,n,o,r){const s=yt(t),a=Pe(e,t),l=Ve(a,n,o);return l?nt(e,a,l.sectionIndex,d=>bt(d,s.row,l.rowIndexInSection,c=>({...c,children:Ge(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 Jt(e,t,n,o,r,s){const a=yt(t),l=Pe(e,t),d=Ve(l,n,o);return d?nt(e,l,d.sectionIndex,c=>bt(c,a.row,d.rowIndexInSection,p=>({...p,children:Ge(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 ho(e,t,n,o,r,s,a){const l=yt(t),d=Pe(e,t),c=Ve(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:Ge(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 ph(e,t,n,o,r){const s=yt(t),a=Pe(e,t),l=Ve(a,n,o);return l?nt(e,a,l.sectionIndex,d=>bt(d,s.row,l.rowIndexInSection,c=>({...c,children:Ge(c).map((p,f)=>f===l.cellIndexInRow?{...p,text:r}:p)}))):e}function fh(e,t,n,o,r){const s=yt(t),a=Pe(e,t),l=Ve(a,n,o);return l?nt(e,a,l.sectionIndex,d=>bt(d,s.row,l.rowIndexInSection,c=>({...c,children:Ge(c).map((p,f)=>f===l.cellIndexInRow?r:p)}))):e}const gh=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function zz(e){return e.split(/\s+/).filter(Boolean)}function hh(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 yh({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(()=>zz(e),[e]),v=u.useMemo(()=>Gr(e,b),[e,b]),y=u.useMemo(()=>v.find(E=>m.has(E))??null,[v,m]),_=u.useMemo(()=>{const E=new Set;for(const A of c)h.some(D=>D===A.prefix||D.startsWith(A.prefix+"-")&&/^-?\d+$/.test(D.slice(A.prefix.length+1)))&&E.add(A.value);return E},[h,c]),w=u.useMemo(()=>{const E=h.find(N=>hh(N,g));if(!E)return"none";const A=p.filter(N=>N.value!=="none");for(const N of c){if(E===N.prefix)return A.find(D=>(D.suffix??"")==="")?.value??"thin";if(E.startsWith(N.prefix+"-")){const D=E.slice(N.prefix.length),B=A.find(M=>(M.suffix??"")===D);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(A=>!hh(A,g))}function x(E,A){const N=k(h),D=p.find(O=>O.value===A);if(!D||A==="none"||E.size===0)return N.join(" ").trim();const B=D.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 A=new Set(_);A.has(E)?A.delete(E):(E==="all"?A.clear():A.delete("all"),A.add(E));const N=w==="none"?p.find(D=>D.value!=="none")?.value??"thin":w;o(x(A,N))},S=E=>{const A=_.size===0?new Set(["all"]):_;o(x(A,E))},C=E=>{s?.(E)},T=(E,A)=>E&&E.startsWith("$t:")?n(E.slice(3)):E||A;return i.jsxs("div",{className:"g7le-cell-border","data-testid":"g7le-cell-border",style:Nz,children:[i.jsx("div",{style:Mz,children:i.jsx("span",{style:Lz,children:n("layout_editor.table_editor.cell_border")})}),i.jsx("div",{style:ll,"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:()=>S(E.value),style:w===E.value?bh:dl,children:T(E.label,E.value)},E.value))}),w!=="none"&&i.jsx("div",{style:ll,"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)?bh:dl,children:T(E.label,E.value)},E.value))}),w!=="none"&&(f.length>0||l)&&i.jsx(i.Fragment,{children:i.jsxs("div",{style:ll,"data-testid":"g7le-cell-border-colors",children:[f.map(E=>{const A=y===E.token;return i.jsx("button",{type:"button",disabled:d,title:T(E.label,E.value),"data-testid":`g7le-cell-border-color-${E.value}`,"aria-pressed":A,onClick:()=>C(E.token),style:{...mh,background:E.swatch??"#fff",outline:A?"2px solid #2563eb":"1px solid #cbd5e1"}},E.value)}),l&&(()=>{const E=!!a&&f.some(N=>N.swatch&&N.swatch.toLowerCase()===a.toLowerCase()),A=!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:{...mh,position:"relative",overflow:"hidden",display:"inline-flex",alignItems:"center",justifyContent:"center",background:A&&gh.test(a)?a:"conic-gradient(red, yellow, lime, aqua, blue, magenta, red)",outline:A?"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&&gh.test(a)?a:"#000000",onChange:N=>l(N.target.value),style:{position:"absolute",width:0,height:0,opacity:0}})})})()]})})]})}const Nz={display:"flex",flexDirection:"column",gap:6},Mz={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},Lz={fontSize:12,fontWeight:600,color:"#475569"},ll={display:"flex",gap:4,flexWrap:"wrap",alignItems:"center"},dl={padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},bh={...dl,border:"1px solid #2563eb",background:"#eff6ff",color:"#1d4ed8",fontWeight:600},mh={width:22,height:22,borderRadius:5,padding:0,cursor:"pointer",boxSizing:"border-box"},vh=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function _h({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=Gr(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:Pz,children:[i.jsx("div",{style:Oz,children:i.jsx("span",{style:Bz,children:o("layout_editor.table_editor.cell_fill")})}),i.jsxs("div",{style:Wz,"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:{...cl,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:{...cl,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:{...cl,position:"relative",overflow:"hidden",display:"inline-flex",alignItems:"center",justifyContent:"center",background:y&&vh.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&&vh.test(f)?f:"#ffffff",onChange:_=>a(_.target.value),style:{position:"absolute",width:0,height:0,opacity:0}})})]})]})}const Pz={display:"flex",flexDirection:"column",gap:6},Oz={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},Bz={fontSize:12,fontWeight:600,color:"#475569"},Wz={display:"flex",gap:4,flexWrap:"wrap",alignItems:"center"},cl={width:22,height:22,borderRadius:5,padding:0,cursor:"pointer",boxSizing:"border-box"};function jz(e){const t=/^(\d+)px$/.exec(e.trim());return t?parseInt(t[1],10):null}function xh({paddingStyle:e,catalog:t,t:n,onChange:o,disabled:r}){const s=t?.steps??[],a=e??"",l=jz(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:Hz,children:[i.jsx("div",{style:Fz,children:n("layout_editor.table_editor.cell_padding")}),i.jsxs("div",{style:Kz,"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?Vz: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:Uz}),i.jsx("span",{style:{fontSize:11,color:"#94a3b8"},children:"px"})]})]})]})}const Hz={display:"flex",flexDirection:"column",gap:6},Fz={fontSize:12,fontWeight:600,color:"#475569"},Kz={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"},Vz={...wh,border:"1px solid #2563eb",background:"#eff6ff",color:"#1d4ed8",fontWeight:600},Uz={width:48,padding:"3px 5px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,boxSizing:"border-box"};function kh({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:qz,children:[i.jsxs("div",{style:Gz,children:[i.jsx("span",{style:Yz,children:n("layout_editor.table_editor.cell_color")}),i.jsxs("div",{style:Xz,children:[i.jsx("button",{type:"button",disabled:o,"data-testid":"g7le-color-scheme-light","aria-pressed":!r,onClick:()=>t("light"),style:r?ul:Sh,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?Sh:ul,children:n("layout_editor.property_modal.scope.scheme_dark")})]})]}),r&&i.jsx("div",{style:Jz,"data-testid":"g7le-color-scheme-dark-hint",children:n("layout_editor.table_editor.dark_free_color_hint")})]})}const qz={display:"flex",flexDirection:"column",gap:3},Gz={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},Yz={fontSize:12,fontWeight:700,color:"#0f172a"},Xz={display:"flex",gap:2},ul={padding:"2px 9px",fontSize:11,border:"none",borderBottom:"2px solid transparent",background:"transparent",color:"#94a3b8",cursor:"pointer"},Sh={...ul,color:"#1d4ed8",borderBottom:"2px solid #2563eb",fontWeight:600},Jz={fontSize:10,color:"#94a3b8",fontStyle:"italic"},pl="dark:";function Ch(e){return typeof e=="string"?e.split(/\s+/).filter(Boolean):[]}function $h(e,t){return t==="dark"?e.filter(n=>n.startsWith(pl)).map(n=>n.slice(pl.length)):e.filter(n=>!n.startsWith(pl))}const Zz={none:0,thin:1,medium:2,thick:4},Eh={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"}},Ih=["top","bottom","left","right"];function Qz(e,t,n="light"){if(!e||!t)return{};const o=t.sides??[],r=t.widths??[],s=t.colors??[],a=Ch(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=$h(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 _=Eh[y]?.c,w=_?c[_]:void 0;return typeof w=="string"&&w?w:g},h={},v=(y,_)=>{const w=Eh[y];if(!w)return;const k=Zz[_]??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 Ih)v(y,d.all);for(const y of Ih)d[y]&&v(y,d[y]);return h}function Rz(e,t,n="light"){if(!e?.props)return{};const o=e.props.style??{},r={},s=Ch(e.props.className),a=t?.colors?.find(c=>c.token&&$h(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 eN=/^\s*\$t:(custom\.[a-zA-Z0-9._-]+)\s*$/,tN=/^\s*\$t:([a-zA-Z0-9._-]+)\s*$/,nN=/\{\{.*?\}\}/;function Ah(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(nN.test(o))return{display:o,editable:!1,isKey:!1};const s=tN.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 fl(e){const t=or(e);return t===null?{node:null,path:null}:{node:ki(e,t),path:t}}function oN(e){if(!e||typeof e.text!="string")return null;const t=eN.exec(e.text);if(t)return t[1];const n=vt(e.text);return n&&n.key.startsWith("custom.")?n.key:null}function rN({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(()=>Pe(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),[S,C]=u.useState(null),[T,E]=u.useState(null),[A,N]=u.useState("light"),D=u.useCallback(U=>o(U),[o]),B=u.useMemo(()=>h?Ve(f,h.r,h.c):null,[f,h]),M=T!==null?T:h?.c??null,O=S!==null?S:h?.r??null,z=u.useMemo(()=>{const U=(b?.sides??[]).find(xe=>xe.value==="all")??(b?.sides??[])[0],ue=(b?.widths??[]).find(xe=>xe.value!=="none");if(!U||!ue)return[];const fe=ue.suffix??"";return[fe?`${U.prefix}${fe}`:U.prefix]},[b]),H=u.useCallback((U,ue,fe)=>{if(z.length===0)return U;const xe=(b?.sides??[]).map(Q=>Q.prefix),he=Ve(Pe(U,p),ue,fe),ne=(typeof he?.cell?.props?.className=="string"?he.cell.props.className:"").split(/\s+/).filter(Boolean);return ne.some(Q=>xe.some(le=>Q===le||Q.startsWith(le+"-")&&/^-?\d+$/.test(Q.slice(le.length+1))))?U:Ii(U,p,ue,fe,[...ne,...z].join(" ").trim())},[z,b,p]),P=u.useCallback(U=>{if(!h)return;const ue=Math.min(h.r,y?.r??h.r),fe=Math.max(h.r,y?.r??h.r),xe=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<=fe;Q++)for(let le=xe;le<=he;le++)j.add(`${Q}:${le}`),ne.push({r:Q,c:le});let pe=e;for(const Q of ne){if(pe=H(pe,Q.r,Q.c),pe=Jt(pe,p,Q.r,Q.c,"borderColor",U),Q.r>0&&!j.has(`${Q.r-1}:${Q.c}`)){const le=Ve(Pe(pe,p),Q.r-1,Q.c);le&&(pe=Jt(pe,p,le.gridRow,le.gridCol,"borderBottomColor",U))}if(Q.c>0&&!j.has(`${Q.r}:${Q.c-1}`)){const le=Ve(Pe(pe,p),Q.r,Q.c-1);le&&(pe=Jt(pe,p,le.gridRow,le.gridCol,"borderRightColor",U))}}D(pe)},[h,y,e,p,D,H]),I=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),fe=Math.max(h.r,y?.r??h.r),xe=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<=fe;ne++)for(let pe=xe;pe<=he;pe++)j=H(j,ne,pe),j=ho(j,p,ne,pe,U,L,A);D(j)},[h,y,e,p,D,H,L,A]),Y=u.useMemo(()=>{if(A==="dark")return"";const U=B?.cell.props?.style;return typeof U?.borderColor=="string"?U.borderColor:""},[B,A]),K=u.useCallback((U,ue)=>{if(!h)return;const fe=Math.min(h.r,y?.r??h.r),xe=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=fe;pe<=xe;pe++)for(let Q=he;Q<=j;Q++)ne=Jt(ne,p,pe,Q,U,ue);D(ne)},[h,y,e,p,D]),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]),ae=u.useCallback(U=>{const ue=Z();if(!ue||X.length===0)return;let fe=e;for(let xe=ue.r0;xe<=ue.r1;xe++)for(let he=ue.c0;he<=ue.c1;he++)fe=ho(fe,p,xe,he,U,X,A);D(fe)},[Z,e,p,D,X,A]),oe=u.useCallback(U=>K("backgroundColor",U),[K]),G=u.useCallback(()=>{const U=Z();if(!U)return;let ue=e;for(let fe=U.r0;fe<=U.r1;fe++)for(let xe=U.c0;xe<=U.c1;xe++)ue=ho(ue,p,fe,xe,void 0,X,A),A==="light"&&(ue=Jt(ue,p,fe,xe,"backgroundColor",void 0));D(ue)},[Z,e,p,D,X,A]),ee=u.useCallback(U=>K("padding",U),[K]),ge=u.useMemo(()=>{if(A==="dark")return"";const U=B?.cell.props?.style;return typeof U?.backgroundColor=="string"?U.backgroundColor:""},[B,A]),V=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]),be=u.useCallback(U=>U==="section"?n("layout_editor.table_editor.move_blocked_section"):"",[n]),Ee=u.useCallback((U,ue)=>Si(f,U,ue),[f]),De=u.useCallback((U,ue)=>Ci(f,U,ue),[f]),Se=u.useCallback(U=>D(sl(e,p,U)),[e,p,D]),Ue=u.useCallback(U=>{D(sh(e,p,U)),v(null),_(null)},[e,p,D]),Me=u.useCallback((U,ue)=>D(ah(e,p,U,ue)),[e,p,D]),Oe=u.useCallback(U=>D(dh(e,p,U)),[e,p,D]),Ye=u.useCallback(U=>{D(ch(e,p,U)),v(null),_(null)},[e,p,D]),ze=u.useCallback((U,ue)=>D(lh(e,p,U,ue)),[e,p,D]),Xe=u.useCallback(()=>{if(!h||!y)return;const U=al(e,p,h.r,h.c,y.r,y.c);U.ok&&(D(U.table),v({r:Math.min(h.r,y.r),c:Math.min(h.c,y.c)}),_(null))},[e,p,h,y,D]),ve=u.useCallback(()=>{h&&(D(uh(e,p,h.r,h.c)),_(null))},[e,p,h,D]),qe=u.useCallback(U=>{if(!h)return;const ue=Math.min(h.r,y?.r??h.r),fe=Math.max(h.r,y?.r??h.r),xe=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<=fe;ne++)for(let pe=xe;pe<=he;pe++)j=Ii(j,p,ne,pe,U);D(j)},[e,p,h,y,D]),We=u.useCallback(async(U,ue)=>{const fe=`${U}:${ue}`,xe=w[fe];if(xe===void 0)return;const he=Ve(f,U,ue);if(!he)return;const{node:j,path:ne}=fl(he.cell);if(ne===null)return;const pe=Ah(j,c,d);if(pe.editable){if(xe===pe.display){k(Q=>{const le={...Q};return delete le[fe],le});return}$(!0);try{const Q=oN(j);if(Q)await vr(c,Q,d,xe),await tn(c,d);else{const le=await qn(c,l,d,xe);if(le.kind==="ok"&&le.resource){const Ae=`$t:${le.resource.translation_key}`;if(ne.length===0)D(ph(e,p,U,ue,Ae));else{const dt=rr(he.cell,ne,Ae);D(fh(e,p,U,ue,dt))}await tn(c,d)}}}finally{$(!1),k(Q=>{const le={...Q};return delete le[fe],le})}}},[w,f,c,d,l,e,p,D]),ce=u.useMemo(()=>{if(!B)return null;const{node:U,path:ue}=fl(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=Ve(f,h.r,h.c);if(!ue)return;const fe=or(ue.cell);if(fe!==null)if(fe.length===0)D(ph(e,p,h.r,h.c,U));else{const xe=rr(ue.cell,fe,U);D(fh(e,p,h.r,h.c,xe))}},[h,f,e,p,D]),ie=u.useCallback((U,ue,fe)=>{fe?_({r:U,c:ue}):(v({r:U,c:ue}),_(null))},[]),se=u.useMemo(()=>Array.from({length:f.colCount},(U,ue)=>ue),[f.colCount]),me=!!(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:iN,children:[i.jsx("div",{style:sN,children:n("layout_editor.table_editor.title")}),i.jsx("div",{style:{overflowX:"auto"},children:i.jsxs("table",{"data-testid":"g7le-table-editor-grid",style:aN,children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{style:lN}),se.map(U=>{const ue=De(U,-1),fe=De(U,1),xe=M===U;return i.jsx("th",{style:dN,"data-testid":`g7le-table-colgutter-${U}`,onMouseEnter:()=>E(U),onMouseLeave:()=>E(he=>he===U?null:he),children:i.jsxs("div",{style:{...uN,visibility:xe?"visible":"hidden"},children:[i.jsx("button",{type:"button",title:ue.ok?n("layout_editor.table_editor.move_col_left"):be(ue.reason)||n("layout_editor.table_editor.move_col_left"),disabled:!ue.ok||x,onClick:()=>ze(U,-1),"data-testid":`g7le-table-col-left-${U}`,style:ue.ok?vn:Ai,children:"←"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.add_col"),disabled:x,onClick:()=>Oe(U),"data-testid":`g7le-table-col-add-${U}`,style:vn,children:"+"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.remove_col"),disabled:f.colCount<=1||x,onClick:()=>Ye(U),"data-testid":`g7le-table-col-remove-${U}`,style:Th,children:"✕"}),i.jsx("button",{type:"button",title:fe.ok?n("layout_editor.table_editor.move_col_right"):be(fe.reason)||n("layout_editor.table_editor.move_col_right"),disabled:!fe.ok||x,onClick:()=>ze(U,1),"data-testid":`g7le-table-col-right-${U}`,style:fe.ok?vn:Ai,children:"→"})]})},U)})]})}),i.jsx("tbody",{children:f.rows.map((U,ue)=>{const fe=U.cells[0]?.gridRow??ue,xe=O===fe;return i.jsxs("tr",{"data-testid":`g7le-table-row-${fe}`,onMouseEnter:()=>C(fe),onMouseLeave:()=>C(he=>he===fe?null:he),children:[i.jsx("td",{style:cN,"data-testid":`g7le-table-rowgutter-${fe}`,children:(()=>{const he=Ee(fe,-1),j=Ee(fe,1);return i.jsxs("div",{style:{...pN,visibility:xe?"visible":"hidden"},children:[i.jsx("button",{type:"button",title:he.ok?n("layout_editor.table_editor.move_row_up"):be(he.reason)||n("layout_editor.table_editor.move_row_up"),disabled:!he.ok||x,onClick:()=>Me(fe,-1),"data-testid":`g7le-table-row-up-${fe}`,style:he.ok?vn:Ai,children:"↑"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.add_row"),disabled:x,onClick:()=>Se(fe),"data-testid":`g7le-table-row-add-${fe}`,style:vn,children:"+"}),i.jsx("button",{type:"button",title:n("layout_editor.table_editor.remove_row"),disabled:f.rows.length<=1||x,onClick:()=>Ue(fe),"data-testid":`g7le-table-row-remove-${fe}`,style:Th,children:"✕"}),i.jsx("button",{type:"button",title:j.ok?n("layout_editor.table_editor.move_row_down"):be(j.reason)||n("layout_editor.table_editor.move_row_down"),disabled:!j.ok||x,onClick:()=>Me(fe,1),"data-testid":`g7le-table-row-down-${fe}`,style:j.ok?vn:Ai,children:"↓"})]})})()}),U.cells.map(he=>{const j=`${he.gridRow}:${he.gridCol}`,{node:ne,path:pe}=fl(he.cell),Q=Ah(ne,c,d),le=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=>ie(he.gridRow,he.gridCol,je.shiftKey),style:{...fN,...Qz(he.cell,b,A),...Rz(he.cell,g,A),...he.isHeader?gN:{},...ot?hN:{},...Le&&!ot?yN:{}},children:le?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(),ie(he.gridRow,he.gridCol,je.shiftKey)},onClick:je=>je.stopPropagation(),onChange:je=>k(Je=>({...Je,[j]:je.target.value})),onBlur:()=>void We(he.gridRow,he.gridCol),style:bN}):Ae?i.jsx("span",{"data-testid":`g7le-table-cell-struct-${he.gridRow}-${he.gridCol}`,style:Dh,children:n("layout_editor.table_editor.structural_cell")}):i.jsx("span",{style:Dh,children:Q.display})},j)})]},ue)})})]})}),i.jsxs("button",{type:"button","data-testid":"g7le-table-add-row-bottom",onClick:()=>Se(f.rows.length-1),disabled:x,style:mN,children:["+ ",n("layout_editor.table_editor.add_row")]}),i.jsxs("div",{style:vN,"data-testid":"g7le-table-cell-tools",children:[i.jsx("button",{type:"button","data-testid":"g7le-table-merge",onClick:Xe,disabled:!me||x,style:zh,children:n("layout_editor.table_editor.merge_cells")}),i.jsx("button",{type:"button","data-testid":"g7le-table-unmerge",onClick:ve,disabled:!Ce||x,style:zh,children:n("layout_editor.table_editor.unmerge_cells")})]}),B&&ce&&i.jsxs("div",{style:xN,"data-testid":"g7le-table-cell-i18n-section",children:[i.jsx("div",{style:wN,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:_N,"data-testid":"g7le-table-cell-color-section",children:[i.jsx(kh,{colorScheme:A,onChange:N,t:n,disabled:x}),b&&i.jsx("div",{style:gl,"data-testid":"g7le-table-cell-border-row",children:i.jsx(yh,{className:$e,catalog:b,t:n,onChange:qe,colorScheme:A,onPresetToken:F,colorStyle:Y,onColorStyle:I,disabled:x})}),i.jsx("div",{style:gl,"data-testid":"g7le-table-cell-fill-row",children:i.jsx(_h,{colorStyle:ge,className:V,catalog:g,t:n,colorScheme:A,onPresetToken:ae,onCustomColor:oe,onClear:G,disabled:x})})]}),B&&i.jsx("div",{style:gl,"data-testid":"g7le-table-cell-padding-row",children:i.jsx(xh,{paddingStyle:te,catalog:m,t:n,onChange:ee,disabled:x})}),B&&!b&&i.jsxs("label",{style:kN,"data-testid":"g7le-table-cell-border-row",children:[i.jsx("span",{style:SN,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:CN})]}),!f.valid&&i.jsx("div",{"data-testid":"g7le-table-grid-warning",style:$N,children:n("layout_editor.table_editor.grid_invalid")}),i.jsx("div",{style:EN,children:n("layout_editor.table_editor.select_hint")})]})}const iN={display:"flex",flexDirection:"column",gap:8,width:"100%",marginBottom:12},sN={fontSize:12,fontWeight:700,color:"#0f172a"},aN={borderCollapse:"collapse",width:"auto"},lN={width:28,background:"transparent",border:"none"},dN={padding:2,border:"none",background:"transparent"},cN={padding:2,border:"none",background:"transparent",verticalAlign:"middle"},uN={display:"flex",gap:2,justifyContent:"center"},pN={display:"grid",gridTemplateColumns:"repeat(2, 16px)",gap:2,justifyContent:"center"},vn={width:16,height:16,lineHeight:"14px",padding:0,fontSize:10,border:"1px solid #cbd5e1",borderRadius:4,background:"#fff",color:"#475569",cursor:"pointer"},Th={...vn,border:"1px solid #fecaca",color:"#dc2626"},Ai={...vn,cursor:"not-allowed",opacity:.4,color:"#94a3b8",borderColor:"#e2e8f0"},fN={border:"1px solid #cbd5e1",padding:0,width:64,minWidth:64,maxWidth:120,height:24,background:"#fff",cursor:"pointer"},gN={background:"#f1f5f9",fontWeight:600},hN={outline:"2px solid #2563eb",outlineOffset:-2},yN={background:"#dbeafe"},bN={width:"100%",boxSizing:"border-box",padding:"2px 5px",fontSize:11,height:22,lineHeight:"18px",border:"none",background:"transparent",outline:"none"},Dh={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"},vN={display:"flex",gap:6},zh={padding:"4px 8px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},_N={display:"flex",flexDirection:"column",gap:8,borderTop:"1px solid #f1f5f9",paddingTop:8},xN={display:"flex",flexDirection:"column",gap:6,borderTop:"1px solid #f1f5f9",paddingTop:8},wN={fontSize:12,fontWeight:700,color:"#0f172a"},gl={display:"flex",flexDirection:"column",gap:6},kN={display:"flex",alignItems:"center",gap:6},SN={fontSize:12,color:"#475569",minWidth:60},CN={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},$N={fontSize:11,color:"#b45309",background:"#fffbeb",border:"1px solid #fde68a",borderRadius:6,padding:"4px 6px"},EN={fontSize:11,color:"#94a3b8"},IN=/\{\{.*?\}\}/;function AN(e,t,n){const r=(e.props??{})[t];return Array.isArray(r)?r:r===void 0&&n?JSON.parse(JSON.stringify(n)):[]}function TN(e){return typeof e=="string"&&IN.test(e)}function hl(e,t,n){return e?e.startsWith("$t:")?t(e.slice(3)):e:n}function DN(e,t,n){return typeof e=="object"&&e!==null?e[t.key]:n?e:void 0}function zN(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 Nh({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=hl(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?AN(e,a,m):[],v=u.useCallback($=>{if(!a)return;const S={...e.props??{}};S[a]=$,o({...e,props:S})},[a,e,o]),y=u.useCallback(()=>{if(p)return JSON.parse(JSON.stringify(p));if(f!==null)return f;const $={};for(const S of l)(S.widget??"text")==="boolean"?$[S.key]=!1:$[S.key]="";return $},[p,f,l]),_=u.useCallback(()=>{v([...h,y()])},[v,h,y]),w=u.useCallback($=>{v(h.filter((S,C)=>C!==$))},[v,h]),k=u.useCallback(($,S)=>{const C=$+S;if(C<0||C>=h.length)return;const T=[...h];[T[$],T[C]]=[T[C],T[$]],v(T)},[v,h]),x=u.useCallback(($,S,C)=>{const T=S.key===b,E=h.map((A,N)=>N===$?zN(A,S,T,C):A);v(E)},[h,v,b]);return a?TN(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:HN,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:NN,children:[i.jsx("div",{style:MN,children:n("layout_editor.array_editor.items_title")}),h.length===0&&i.jsx("div",{"data-testid":"g7le-array-empty",style:Lh,children:n("layout_editor.array_editor.empty")}),h.map(($,S)=>i.jsxs("div",{"data-testid":`g7le-array-row-${S}`,style:LN,children:[i.jsxs("div",{style:PN,children:[i.jsxs("span",{style:ON,children:["#",S+1]}),i.jsx("div",{style:{flex:1}}),i.jsx("button",{type:"button","data-testid":`g7le-array-up-${S}`,title:n("layout_editor.array_editor.move_up"),disabled:S===0,onClick:()=>k(S,-1),style:Mh,children:"↑"}),i.jsx("button",{type:"button","data-testid":`g7le-array-down-${S}`,title:n("layout_editor.array_editor.move_down"),disabled:S===h.length-1,onClick:()=>k(S,1),style:Mh,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-array-remove-${S}`,title:n("layout_editor.array_editor.remove"),onClick:()=>w(S),style:WN,children:"✕"})]}),l.map(C=>{const T=C.widget??"text",E=C.key===b,A=hl(C.label,n,C.key),N=DN($,C,E),D=`g7le-array-field-${S}-${C.key}`;if(T==="boolean")return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsx("input",{type:"checkbox","data-testid":D,checked:N===!0,onChange:M=>x(S,C,M.target.checked)})]},C.key);if(T==="select"){const M=Array.isArray(C.options)?C.options:[];return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsxs("select",{"data-testid":D,value:N==null?"":String(N),onChange:O=>x(S,C,O.target.value===""?void 0:O.target.value),style:sr,children:[i.jsx("option",{value:"",children:"—"}),M.map((O,z)=>i.jsx("option",{value:String(O.value),children:hl(O.label,n,String(O.value))},z))]})]},C.key)}if(T==="i18n-text"){const M=typeof N=="string"?N:N==null?"":String(N);return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsx("div",{"data-testid":D,style:{flex:1,minWidth:0},children:i.jsx(_t,{value:M,onChange:O=>x(S,C,O===""?void 0:O),t:n,placeholder:A,testidPrefix:`${D}-i18n`,candidates:s,enableExpressionTree:!0,expressionTreeCollapsible:!0})})]},C.key)}if(T==="number"){const M=N==null?"":String(N);return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsx("input",{type:"number","data-testid":D,value:M,onChange:O=>{const z=O.target.value;x(S,C,z===""?void 0:Number(z))},style:sr})]},C.key)}if(T==="color"){const M=typeof N=="string"?N:"",O=/^#[0-9a-fA-F]{6}$/.test(M)?M:"#000000";return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsx("input",{type:"color","data-testid":`${D}-swatch`,value:O,onChange:z=>x(S,C,z.target.value),style:BN}),i.jsx("input",{type:"text","data-testid":D,value:M,placeholder:"#7C3AED",onChange:z=>x(S,C,z.target.value===""?void 0:z.target.value),style:sr})]},C.key)}if(T==="number-list"){const M=Array.isArray(N)?N.join(", "):"";return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsx("input",{type:"text","data-testid":D,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(S,C,z)},style:sr})]},C.key)}const B=N==null?"":String(N);return i.jsxs("label",{style:Wn,children:[i.jsx("span",{style:jn,children:A}),i.jsx("input",{type:"text","data-testid":D,value:B,placeholder:T==="icon"?n("layout_editor.array_editor.icon_placeholder"):A,onChange:M=>x(S,C,M.target.value===""?void 0:M.target.value),style:sr})]},C.key)})]},S)),i.jsx("button",{type:"button","data-testid":"g7le-array-add",onClick:_,style:jN,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:Lh,children:n("layout_editor.array_editor.no_array_prop")})}const NN={display:"flex",flexDirection:"column",gap:8,width:"100%",marginBottom:12},MN={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:2},LN={display:"flex",flexDirection:"column",gap:4,padding:8,border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc"},PN={display:"flex",gap:4,alignItems:"center"},ON={fontSize:11,fontWeight:700,color:"#64748b"},Wn={display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},jn={fontSize:11,color:"#475569",minWidth:64,flexShrink:0},sr={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},BN={width:32,height:28,padding:0,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",cursor:"pointer",flexShrink:0},Mh={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},WN={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},jN={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},Lh={fontSize:11,color:"#94a3b8",fontStyle:"italic"},HN={fontSize:11,color:"#b45309",fontStyle:"italic",padding:"4px 2px"};function FN(e,t){return e?e.startsWith("$t:")?t(e.slice(3)):e:null}function KN(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:GN,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:VN,children:o.map((r,s)=>{const a=FN(r.title,n),{title:l,...d}=r;return i.jsxs("div",{"data-testid":`g7le-array-group-${r.arrayProp??s}`,style:UN,children:[a&&i.jsx("div",{style:qN,children:a}),i.jsx(Nh,{...e,params:d})]},r.arrayProp??s)})})}const VN={display:"flex",flexDirection:"column",gap:16,width:"100%",marginBottom:12},UN={display:"flex",flexDirection:"column",gap:4},qN={fontSize:12,fontWeight:700,color:"#1e293b",borderBottom:"1px solid #e2e8f0",paddingBottom:4},GN={fontSize:11,color:"#94a3b8",fontStyle:"italic"},YN=/\{\{.*?\}\}/;function XN(e){return typeof e=="string"&&YN.test(e)}function JN(e,t,n){return e?e.startsWith("$t:")?t(e.slice(3)):e:n}function ZN(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=JN(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 S={...t.props??{}};S[s]=$,r({...t,props:S})},[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((S,C)=>C!==$)),f(null)},[m,g]),_=u.useCallback(($,S)=>{const C=$+S;if(C<0||C>=g.length)return;const T=[...g];[T[$],T[C]]=[T[C],T[$]],m(T)},[m,g]),w=u.useCallback(($,S)=>{const C=g.map((T,E)=>E===$?{...T,[a]:S}:T);m(C)},[g,m,a]),k=u.useCallback($=>({type:"composite",name:"CardGridCell",children:Array.isArray($[l])?$[l]:[]}),[l]),x=u.useCallback($=>S=>{const C=Array.isArray(S.children)?S.children:[],T=g.map((E,A)=>A===$?{...E,[l]:C}:E);m(T)},[g,m,l]);return s?XN(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:lM,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:QN,children:[i.jsx("div",{style:RN,children:o("layout_editor.cell_tree_editor.columns_title")}),g.length===0&&i.jsx("div",{"data-testid":"g7le-cell-tree-empty",style:Oh,children:o("layout_editor.array_editor.empty")}),g.map(($,S)=>{const C=typeof $[a]=="string"?$[a]:"",T=p===S;return i.jsxs("div",{"data-testid":`g7le-cell-tree-row-${S}`,style:eM,children:[i.jsxs("div",{style:tM,children:[i.jsxs("span",{style:nM,children:["#",S+1]}),i.jsx("input",{type:"text","data-testid":`g7le-cell-tree-id-${S}`,value:C,placeholder:o("layout_editor.cell_tree_editor.id_placeholder"),onChange:E=>w(S,E.target.value),style:oM}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-up-${S}`,title:o("layout_editor.array_editor.move_up"),disabled:S===0,onClick:()=>_(S,-1),style:Ph,children:"↑"}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-down-${S}`,title:o("layout_editor.array_editor.move_down"),disabled:S===g.length-1,onClick:()=>_(S,1),style:Ph,children:"↓"}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-remove-${S}`,title:o("layout_editor.array_editor.remove"),onClick:()=>y(S),style:rM,children:"✕"})]}),i.jsx("button",{type:"button","data-testid":`g7le-cell-tree-toggle-${S}`,onClick:()=>f(T?null:S),style:iM,children:o(T?"layout_editor.cell_tree_editor.collapse_cells":"layout_editor.cell_tree_editor.expand_cells")}),T&&i.jsx("div",{"data-testid":`g7le-cell-tree-cells-${S}`,style:sM,children:i.jsx(Rg,{...e,node:k($),params:{childComponent:d},onPatchNode:x(S)})})]},S)}),i.jsx("button",{type:"button","data-testid":"g7le-cell-tree-add",onClick:v,style:aM,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:Oh,children:o("layout_editor.array_editor.no_array_prop")})}const QN={display:"flex",flexDirection:"column",gap:8,width:"100%",marginBottom:12},RN={fontSize:12,fontWeight:700,color:"#0f172a",marginBottom:2},eM={display:"flex",flexDirection:"column",gap:6,padding:8,border:"1px solid #e2e8f0",borderRadius:8,background:"#f8fafc"},tM={display:"flex",gap:4,alignItems:"center"},nM={fontSize:11,fontWeight:700,color:"#64748b",flexShrink:0},oM={flex:1,minWidth:0,padding:"4px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6},Ph={padding:"2px 6px",fontSize:12,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"},rM={padding:"2px 6px",fontSize:12,border:"1px solid #fecaca",borderRadius:6,background:"#fff",color:"#dc2626",cursor:"pointer"},iM={padding:"3px 8px",fontSize:11,border:"1px solid #cbd5e1",borderRadius:6,background:"#fff",color:"#2563eb",cursor:"pointer",alignSelf:"flex-start"},sM={paddingLeft:8,borderLeft:"2px solid #e2e8f0"},aM={padding:"4px 8px",fontSize:12,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer",alignSelf:"flex-start"},Oh={fontSize:11,color:"#94a3b8",fontStyle:"italic"},lM={fontSize:11,color:"#b45309",fontStyle:"italic",padding:"4px 2px"};function dM(e,t,n){const o=Pe(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=il(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 yl=26,bl=50,ml=6,Bh=44,Wh=18,jh="g7le-table-inplace-empty-cell-style";function cM(){if(typeof document>"u"||document.getElementById(jh))return;const e=document.createElement("style");e.id=jh,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 uM({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(()=>dM(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=il(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&&Ve(f,b.r,b.c)?b:v,[b,v,f]),[_,w]=u.useState(!1),[k,x]=u.useState(s==="dark"?"dark":"light"),[$,S]=u.useState(null),[C,T]=u.useState(null),E=u.useRef(null),A=u.useCallback(()=>{E.current!==null&&(clearTimeout(E.current),E.current=null)},[]),N=u.useCallback(()=>{A(),E.current=setTimeout(()=>{S(null),T(null),E.current=null},240)},[A]);u.useEffect(()=>()=>A(),[A]),u.useEffect(()=>{cM()},[]);const D=u.useCallback(j=>l(j),[l]),B=u.useMemo(()=>y?Ve(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=>D(sl(e,c,j)),[e,c,D]),z=u.useCallback(j=>D(sh(e,c,j)),[e,c,D]),H=u.useCallback((j,ne)=>D(ah(e,c,j,ne)),[e,c,D]),P=u.useCallback(j=>D(dh(e,c,j)),[e,c,D]),I=u.useCallback(j=>D(ch(e,c,j)),[e,c,D]),L=u.useCallback((j,ne)=>D(lh(e,c,j,ne)),[e,c,D]),F=u.useCallback(j=>{if(!B)return;const ne=B.gridRow,pe=B.gridCol,Q=j==="down"?ne+B.rowSpan:ne+B.rowSpan-1,le=j==="right"?pe+B.colSpan:pe+B.colSpan-1;if(Q>=f.rows.length||le>=f.colCount)return;const Ae=al(e,c,ne,pe,Q,le);Ae.ok&&D(Ae.table)},[B,f,e,c,D]),Y=!!(B&&B.gridCol+B.colSpan<f.colCount),K=!!(B&&B.gridRow+B.rowSpan<f.rows.length),X=u.useMemo(()=>!y||!m||!Ve(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 le=`${Q.gridRow}:${Q.gridCol}`;j.has(le)||(j.add(le),ne.push({r:Q.gridRow,c:Q.gridCol}))}return ne},[X,f]),ae=Z.length>1,oe=u.useCallback(()=>{if(!X)return;const j=al(e,c,X.r0,X.c0,X.r1,X.c1);j.ok&&(D(j.table),h(null))},[X,e,c,D]),G=u.useCallback(()=>{y&&D(uh(e,c,y.r,y.c))},[e,c,y,D]),ee=u.useMemo(()=>{const j=c?.cellBorder;return j&&typeof j=="object"?j:null},[c]),ge=u.useMemo(()=>{const j=c?.cellBackground;return j&&typeof j=="object"?j:null},[c]),V=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 le=`${Q.gridRow}:${Q.gridCol}`;j.has(le)||(j.add(le),ne.push({r:Q.gridRow,c:Q.gridCol}))}return ne}return ae?Z:y?[{r:y.r,c:y.c}]:[]},[_,ae,Z,y,f]),be=u.useCallback(j=>{if(te.length===0)return;let ne=e;for(const pe of te){const Q=(ee?.colors??[]).map(Ae=>Ae.token),le=j.split(/\s+/).filter(Ae=>Ae&&!Q.includes(Ae)).join(" ");ne=Ii(ne,c,pe.r,pe.c,le)}D(ne)},[e,c,te,ee,D]),Ee=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(Ee.length===0)return j;const Q=(ee?.sides??[]).map(Le=>Le.prefix),le=Ve(Pe(j,c),ne,pe),dt=(typeof le?.cell?.props?.className=="string"?le.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,...Ee].join(" ").trim();return Ii(j,c,ne,pe,ot)},[Ee,ee,c]),Se=u.useCallback((j,ne)=>{if(j.length===0)return;const pe=new Set(j.map(le=>`${le.r}:${le.c}`));let Q=e;for(const le of j){if(Q=De(Q,le.r,le.c),Q=Jt(Q,c,le.r,le.c,"borderColor",ne),le.r>0&&!pe.has(`${le.r-1}:${le.c}`)){const Ae=Ve(Pe(Q,c),le.r-1,le.c);Ae&&(Q=Jt(Q,c,Ae.gridRow,Ae.gridCol,"borderBottomColor",ne))}if(le.c>0&&!pe.has(`${le.r}:${le.c-1}`)){const Ae=Ve(Pe(Q,c),le.r,le.c-1);Ae&&(Q=Jt(Q,c,Ae.gridRow,Ae.gridCol,"borderRightColor",ne))}}D(Q)},[e,c,D,De]),Ue=u.useMemo(()=>(ee?.colors??[]).map(j=>j.token).filter(Boolean),[ee]),Me=u.useCallback(j=>{if(te.length===0||Ue.length===0)return;let ne=e;for(const pe of te)ne=De(ne,pe.r,pe.c),ne=ho(ne,c,pe.r,pe.c,j,Ue,k);D(ne)},[te,e,c,D,De,Ue,k]),Oe=u.useCallback(j=>Se(te,j),[Se,te]),Ye=u.useMemo(()=>{if(k==="dark")return"";const j=B?.cell.props?.style;return typeof j?.borderColor=="string"?j.borderColor:""},[B,k]),ze=u.useCallback((j,ne)=>{if(te.length===0)return;let pe=e;for(const Q of te)pe=Jt(pe,c,Q.r,Q.c,j,ne);D(pe)},[te,e,c,D]),Xe=u.useMemo(()=>(ge?.colors??[]).map(j=>j.token).filter(j=>!!j),[ge]),ve=u.useCallback(j=>{if(te.length===0||Xe.length===0)return;let ne=e;for(const pe of te)ne=ho(ne,c,pe.r,pe.c,j,Xe,k);D(ne)},[te,e,c,D,Xe,k]),qe=u.useCallback(j=>ze("backgroundColor",j),[ze]),We=u.useCallback(()=>{if(te.length===0)return;let j=e;for(const ne of te)j=ho(j,c,ne.r,ne.c,void 0,Xe,k),k==="light"&&(j=Jt(j,c,ne.r,ne.c,"backgroundColor",void 0));D(j)},[te,e,c,D,Xe,k]),ce=u.useCallback(j=>ze("padding",j),[ze]),q=u.useMemo(()=>{if(k==="dark")return"";const j=B?.cell.props?.style;return typeof j?.backgroundColor=="string"?j.backgroundColor:""},[B,k]),ie=u.useMemo(()=>typeof B?.cell.props?.className=="string"?B.cell.props.className:"",[B]),se=u.useMemo(()=>{const j=B?.cell.props?.style;return typeof j?.padding=="string"?j.padding:""},[B]),me=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 le=Q?.closest?.("[data-dnd-handle-path]");le&&le.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=C!==null?C:y?.c??null,fe=$!==null?$:y?.r??null,xe=n.top-yl-ml-Bh,he=n.left-bl-ml-Bh;return i.jsxs("div",{className:"g7le-table-inplace","data-testid":"g7le-table-inplace",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:j7},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:()=>{A(),S(j.ref.gridRow),T(j.ref.gridCol)},onMouseLeave:()=>{N()},onPointerDown:Q=>me(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 le=il(e,j.ref,c).map(Ae=>`children.${Ae}`).join(".");d?.(le)}},style:{position:"absolute",top:j.box.top,left:j.box.left,width:j.box.width,height:j.box.height,minWidth:Wh,minHeight:Wh,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:A,onMouseLeave:N,style:{position:"absolute",top:xe,left:n.left,width:n.width,height:yl,pointerEvents:"none"},children:ue!==null&&Ce.has(ue)&&(()=>{const j=ue,ne=Ce.get(j),pe=Ci(f,j,-1),Q=Ci(f,j,1),le=ne.left-n.left;return i.jsxs("div",{"data-testid":`g7le-inplace-colgutter-${j}`,onMouseEnter:()=>{A(),T(j)},onMouseLeave:N,style:{position:"absolute",top:0,left:le,width:ne.width,minWidth:96,height:yl,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?_n:Ti,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:_n,children:"+"}),i.jsx("button",{type:"button",title:a("layout_editor.table_inplace.remove_col"),disabled:f.colCount<=1,onClick:()=>I(j),"data-testid":`g7le-inplace-col-remove-${j}`,style:Hh,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?_n:Ti,children:"→"})]},`colgut-${j}`)})()}),i.jsx("div",{"data-testid":"g7le-inplace-row-rail",style:{position:"absolute",top:n.top,left:he,width:bl,height:n.height,pointerEvents:"none"},children:fe!==null&&$e.has(fe)&&(()=>{const j=fe,ne=$e.get(j),pe=Si(f,j,-1),Q=Si(f,j,1),le=ne.top-n.top;return i.jsxs("div",{"data-testid":`g7le-inplace-rowgutter-${j}`,onMouseEnter:()=>{A(),S(j)},onMouseLeave:N,style:{position:"absolute",top:le,left:0,width:bl,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?_n:Ti,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:_n,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:Hh,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?_n:Ti,children:"↓"})]},`rowgut-${j}`)})()}),i.jsxs("div",{"data-testid":"g7le-inplace-corner-add",style:{position:"absolute",top:n.top+n.height+ml,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:Fh,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:Fh,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:[ae&&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:[ae?i.jsx("button",{type:"button","data-testid":"g7le-inplace-merge-range",onClick:oe,style:ar,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?ar:vl,children:a("layout_editor.table_inplace.merge_right")}),i.jsx("button",{type:"button","data-testid":"g7le-inplace-merge-down",disabled:!K,onClick:()=>F("down"),style:K?ar:vl,children:a("layout_editor.table_inplace.merge_down")})]}),i.jsx("button",{type:"button","data-testid":"g7le-inplace-unmerge",disabled:!U,onClick:G,style:U?ar:vl,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(kh,{colorScheme:k,onChange:x,t:a}),ee&&i.jsx("div",{"data-testid":"g7le-inplace-cell-border",children:i.jsx(yh,{className:_?"":M,catalog:ee,t:a,onChange:be,colorScheme:k,onPresetToken:Me,colorStyle:_?"":Ye,onColorStyle:Oe})}),i.jsx("div",{"data-testid":"g7le-inplace-cell-fill",children:i.jsx(_h,{colorStyle:_?"":q,className:_?"":ie,catalog:ge,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(xh,{paddingStyle:_?"":se,catalog:V,t:a,onChange:ce})})]})]})]})}const _n={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)"},Hh={..._n,border:"1px solid #fecaca",color:"#dc2626"},Ti={..._n,cursor:"not-allowed",opacity:.4,color:"#94a3b8",borderColor:"#e2e8f0"},ar={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)"},vl={...ar,cursor:"not-allowed",opacity:.4},Fh={padding:"3px 8px",fontSize:11,border:"1px dashed #94a3b8",borderRadius:6,background:"#fff",color:"#475569",cursor:"pointer"};let Kh=!1;function pM(){Kh||(Pn("children",Rg),Pn("table",rN),Pn("array",Nh),Pn("array-group",KN),Pn("array-cell-tree",ZN),ja("table",uM),Kh=!0)}function fM(){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:Ze,registerNodeEditor:Pn,registerCanvasOverlay:ja,onReady:r=>{typeof r=="function"&&r()}};for(const r of n){const[s,...a]=r;try{s==="widget"?Ze(a[0],a[1]):s==="nodeEditor"?Pn(a[0],a[1]):s==="canvasOverlay"&&ja(a[0],a[1])}catch{}}for(const r of o)try{r()}catch{}}const gM=1280;_z(),pM(),fM();async function hM(e){if(typeof fetch!="function")return[];try{const t=await fetch(en(`/api/admin/templates/${encodeURIComponent(e)}/editor/permission-candidates`,"json"),{credentials:"same-origin",headers:Ne()});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 yM({templateIdentifier:e}){FD({templateIdentifier:e}),KD(e);const{state:t,dispatch:n}=Qe(),{t:o}=tt(),r=bo(),s=Dp(),a=XD(),l=t.selectedRoute?.layoutName??null,d=RD(e,l),c=t.editMode==="extension",p=u.useMemo(()=>c?ZD(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),[S,C]=u.useState([]);u.useEffect(()=>{let q=!1;return(async()=>{try{const ie=await fetch(en(`/api/templates/${encodeURIComponent(e)}/components`,"json"),{credentials:"same-origin",headers:{Accept:"application/json"}});if(!ie.ok)return;const se=await ie.json().catch(()=>null);!q&&se&&typeof se=="object"&&b(se)}catch{}})(),()=>{q=!0}},[e]),u.useEffect(()=>{let q=!1;return(async()=>{const{spec:ie,sampleGlobalSources:se}=await ab({templateIdentifier:e,coreSeed:e8()});q||(m(ie),v(se),mM(e,ie,se))})(),()=>{q=!0}},[e]),u.useEffect(()=>{let q=!1;return(async()=>{if(typeof fetch=="function")try{const ie=await fetch(`/api/admin/templates/${encodeURIComponent(e)}`,{credentials:"same-origin",headers:Ne()});if(!ie.ok)return;const me=(await ie.json().catch(()=>null))?.data,Ce=me?.type;q||((Ce==="admin"||Ce==="user")&&_(Ce),typeof me?.name=="string"&&me.name&&k(me.name),typeof me?.version=="string"&&me.version&&$(me.version))}catch{}})(),()=>{q=!0}},[e]),u.useEffect(()=>{let q=!1;return(async()=>{if(typeof fetch=="function")try{const ie=await fetch("/api/admin/templates/?per_page=100&page=1",{credentials:"same-origin",headers:Ne()});if(!ie.ok)return;const me=(await ie.json().catch(()=>null))?.data?.data;if(!q&&Array.isArray(me)){const Ce=[];for(const $e of me){if(!$e||typeof $e!="object")continue;const U=$e.identifier;if(typeof U!="string"||!U||$e.is_pending===!0)continue;const fe=$e.type==="admin"?"admin":"user",xe=$e.name,he=$e.version;Ce.push({identifier:U,name:typeof xe=="string"?xe:U,version:typeof he=="string"?he:"",type:fe})}C(Ce)}}catch{}})(),()=>{q=!0}},[e]);const T=g?.nesting??null,E=t.selectedRoute?.path??null,A=t.editMode,N=t.selectedRoute?.layoutName??(c?a.document?.hostLayoutName??null:null),D=t.routeTree,B=u.useMemo(()=>{if(A!=="extension"||!N)return null;const q=xl(D,N);return q||`__base__/${N}`},[A,N,D]),M=c&&t.returnRoute===null&&!!N;u.useEffect(()=>{if(!M||!N)return;const q=xl(D,N);q&&n({type:"SET_RETURN_ROUTE",route:{path:q,layoutName:N}})},[M,N,D,n]),u.useEffect(()=>{const q=xD(A,E,B),ie=wD(g?.states?.groups,q);n({type:"SET_AVAILABLE_STATES",states:ie,activeStateId:kD(ie)})},[g,A,E,B,n]);const[O,z]=u.useState([]);u.useEffect(()=>{let q=!1;return(async()=>{const ie=await hM(e);q||z(ie)})(),()=>{q=!0}},[e]),VD(),UD();const H=u.useCallback(q=>{const ie=t.routeTree,se=q.split("?")[0]?.split("#")[0]??q;return bM(ie,se)?"route_in_tree":"route_not_in_tree"},[t.routeTree]),P=u.useCallback(q=>{const ie=q.split("?")[0]?.split("#")[0]??q,se=_l(t.routeTree,ie);se&&(p.isDirty&&!(!(typeof window<"u")||window.confirm(o("layout_editor.chrome.dirty_guard.message")))||n({type:"SELECT_ROUTE",route:{path:se.path,layoutName:se.layoutName}}))},[t.routeTree,p.isDirty,n]),I=u.useRef([]),L=u.useCallback(q=>{I.current=q},[]),[F,Y]=u.useState(null),K=u.useCallback(()=>Y(null),[]),X=u.useRef(null),Z=u.useRef(null);u.useEffect(()=>{const q=Z.current,ie=X.current;if(!q||!ie||typeof ResizeObserver>"u")return;const se=()=>{ie.style.setProperty("--g7le-header-h",`${Math.round(q.getBoundingClientRect().height)}px`)};se();const me=new ResizeObserver(se);return me.observe(q),()=>me.disconnect()},[]);const ae=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 ie=ea(q);window.G7Core?.dispatch?.({handler:"openWindow",params:{path:ie,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(wE,{templateIdentifier:e,t:o,onClose:()=>r.close(q)})})},[r,e,o]),ge=typeof window<"u"&&(!!window.G7Config?.customAssetsDisabled||new URLSearchParams(window.location.search).get("custom")==="off"),V=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(ge){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,ge,o]),te=u.useCallback(()=>{const q=s7(e,t.selectedRoute?.path??null);window.G7Core?.dispatch?.({handler:"openWindow",params:{path:q}})},[e,t.selectedRoute]),be=u.useCallback(()=>{const q=t.selectedRoute?.layoutName??"";if(!q)return;const ie=r.open({ariaLabel:o("layout_editor.attachment_manager.title"),width:720,maxHeightRatio:.82,content:u.createElement(Bl,{templateIdentifier:e,layoutName:q,t:o,onClose:()=>r.close(ie)})})},[r,e,t.selectedRoute,o]),Ee=u.useCallback(()=>{const q=t.selectedRoute?.layoutName??"";if(!q)return;const ie=Yy(s.document?.raw??{}),se=r.open({ariaLabel:o("layout_editor.translation_manager.title"),width:720,maxHeightRatio:.82,content:u.createElement(ym,{templateIdentifier:e,layoutName:q,t:o,referencedKeys:ie,onClose:()=>r.close(se)})})},[r,e,t.selectedRoute,o,s.document]),De=u.useCallback((q,ie)=>{const se=window.G7Core;if(se&&typeof se.t=="function"){const me=se.t(q,ie);if(me&&me!==q&&!me.startsWith("$t:"))return me}return o(q,ie)},[o]),Se=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]),Ue=u.useCallback(async()=>{const q=await d.createPreview(s.document?.raw??null);if(q.kind!=="success"){const ie=q.kind==="network_error"?q.message:o("layout_editor.preview_action.no_document");typeof window<"u"&&window.alert(ie)}},[d,s.document,o]),Me=u.useCallback(()=>{const q=t.selectedRoute?.layoutName??"",ie=t.selectedRoute?.path??"",se=t.editMode==="extension"&&ie.startsWith("__extension__/")?ie.slice(14):null,me=se?{kind:"extension",extensionId:se}:q?{kind:"layout",layoutName:q}:null;if(!me)return;const Ce=r.open({ariaLabel:o("layout_editor.version_history.title"),width:640,maxHeightRatio:.82,content:u.createElement(nE,{templateIdentifier:e,target:me,t:o,onRestored:async $e=>{typeof $e=="number"&&(me.kind==="extension"?n({type:"SET_EXTENSION_VERSION",extensionId:me.extensionId,version:$e}):n({type:"SET_LAYOUT_VERSION",layoutName:me.layoutName,version:$e})),await p.reload()},onClose:()=>r.close(Ce)})})},[r,e,t.selectedRoute,t.editMode,o,p,n]),Oe=p.dirtyKeys.size>0||p.isDirty;u.useEffect(()=>{if(!Oe)return;const q=ie=>{ie.preventDefault(),ie.returnValue=""};return window.addEventListener("beforeunload",q),()=>window.removeEventListener("beforeunload",q)},[Oe]);const Ye=u.useCallback(()=>{!p.isDirty||!(!(typeof window<"u")||window.confirm(o("layout_editor.chrome.reset_guard.message")))||p.reload()},[p,o]),ze=u.useCallback(async()=>{const q=await p.save({sessionAddedPaths:I.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]),Xe=u.useCallback(()=>{const q=r.open({ariaLabel:o("layout_editor.shortcuts.title"),width:560,maxHeightRatio:.85,content:u.createElement(DE,{t:o,onClose:()=>r.close(q)})})},[r,o]),ve=u.useMemo(()=>({save:()=>{ze()},exit:oe,editCode:te,reset:Ye,translations:Ee,addElement:()=>{t.selectedRoute&&n({type:"TOGGLE_PALETTE"})},help:Xe,preview:()=>{t.selectedRoute?.layoutName&&Ue()}}),[ze,oe,te,Ye,Ee,t.selectedRoute,n,Xe,Ue]),[qe,We]=u.useState(!1);u.useEffect(()=>{const q=window.setInterval(()=>{We(!!window.__g7LayoutEditorHasSelection)},200);return()=>window.clearInterval(q)},[]),lp({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(qa,{error:t.routesError})}):i.jsx("div",{className:"g7le-chrome","data-testid":"g7le-chrome",ref:X,style:{position:"static",minHeight:"100vh",minWidth:gM,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(yy,{value:ce,children:[c&&a.needsHostPicker&&a.document&&i.jsx(QD,{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(Sy,{onSave:()=>{ze()},isDirty:p.isDirty,onExit:oe,onEditCode:te,onManageImages:be,onManageTranslations:Ee,onPageSettings:Se,onReset:Ye,onShowShortcuts:Xe,onPreview:Ue,onShowVersions:Me,templateName:w,templateVersion:x,templateList:S,onSwitchTemplate:G,onToggleCustomAssets:V,customAssetsDisabled:ge,onManageCustomAssets:ee}),i.jsx(GE,{result:F,onDismiss:K,onLoadLatest:ae}),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(vD,{}),i.jsx(_D,{})]})]}),i.jsxs("div",{className:"g7le-chrome__body",style:{display:"grid",gridTemplateColumns:"auto 1fr",alignItems:"stretch"},children:[i.jsx(f7,{}),i.jsx(gD,{manifest:f,nesting:T,componentPalette:g?.componentPalette??null,spec:g,permissionCandidates:O,sampleGlobalSources:h,resolveRouteMatch:H,onNavigateToDestination:P,onSessionAddedPathsChange:L})]}),i.jsx(vy,{})]})})}function _l(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=_l(n.children,t);if(o)return o}}return null}function bM(e,t){return _l(e,t)!==null}function xl(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=xl(n.children,t);if(o)return o}}return null}function mM(e,t,n){const o=[];Ya({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;iy({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 Vh({templateIdentifier:e,initialLocale:t}){return u.useEffect(()=>()=>{Zh(),Rh(),ty(),ny(),oy(),ry(),sy(),ay(),ly()},[]),i.jsx(hy,{templateIdentifier:e,initialLocale:t,children:i.jsx(my,{children:i.jsx(yM,{templateIdentifier:e})})})}if(typeof window<"u"){const e=window.G7Core||(window.G7Core={});if(e.__LayoutEditorChrome=Vh,typeof e.__onChromeReady=="function")try{e.__onChromeReady()}catch{}}dn.LayoutEditorChrome=Vh,Object.defineProperty(dn,Symbol.toStringTag,{value:"Module"})})(this.G7LayoutEditor=this.G7LayoutEditor||{},ReactJSXRuntime,React,ReactDOM);
|