@object-ui/plugin-designer 3.1.3 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7004 -6697
- package/dist/index.umd.cjs +2 -2
- package/package.json +10 -10
package/dist/index.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@object-ui/core`),require(`react`),require(`lucide-react`),require(`clsx`),require(`tailwind-merge`),require(`@object-ui/types`),require(`@object-ui/react`)):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`lucide-react`,`clsx`,`tailwind-merge`,`@object-ui/types`,`@object-ui/react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDesigner={},e.ObjectUICore,e.React,e.lucide_react,e.clsx,e.tailwind_merge,e.ObjectUITypes,e.ObjectUIReact))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:c(f(e)),h(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(n);function g(e,t={}){let{maxHistory:r=50}=t,[i,a]=(0,n.useState)(e),o=(0,n.useRef)([]),s=(0,n.useRef)([]),c=(0,n.useCallback)(e=>{a(t=>(o.current=[...o.current.slice(-(r-1)),t],s.current=[],e))},[r]),l=(0,n.useCallback)(()=>{o.current.length!==0&&a(e=>{let t=[...o.current],n=t.pop();return o.current=t,s.current=[e,...s.current],n})},[]),u=(0,n.useCallback)(()=>{s.current.length!==0&&a(e=>{let t=[...s.current],n=t.shift();return s.current=t,o.current=[...o.current,e],n})},[]),d=(0,n.useCallback)(e=>{o.current=[],s.current=[],a(e)},[]);return{current:i,canUndo:o.current.length>0,canRedo:s.current.length>0,undoCount:o.current.length,redoCount:s.current.length,push:c,undo:l,redo:u,reset:d}}function _(){let[e,t]=(0,n.useState)(!1),[r,i]=(0,n.useState)(``),[a,o]=(0,n.useState)(``),s=(0,n.useRef)(null);return{isOpen:e,title:r,message:a,confirm:(0,n.useCallback)((e,n)=>(i(e),o(n),t(!0),new Promise(e=>{s.current=e})),[]),onConfirm:(0,n.useCallback)(()=>{t(!1),s.current?.(!0),s.current=null},[]),onCancel:(0,n.useCallback)(()=>{t(!1),s.current?.(!1),s.current=null},[])}}function v(){let[e,t]=(0,n.useState)(new Set);return{selectedIds:e,toggle:(0,n.useCallback)((e,n=!1)=>{t(t=>{let r=new Set(n?t:[]);return t.has(e)&&n?r.delete(e):r.add(e),r})},[]),selectOne:(0,n.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,n.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,n.useCallback)(()=>{t(new Set)},[]),isSelected:(0,n.useCallback)(t=>e.has(t),[e]),count:e.size}}function y(){let[e,t]=(0,n.useState)(null);return{clipboard:e,copy:(0,n.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,n.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function b(e={}){let{minZoom:t=.25,maxZoom:r=3,zoomStep:i=.1,initialZoom:a=1}=e,[o,s]=(0,n.useState)(a),[c,l]=(0,n.useState)({x:0,y:0}),u=(0,n.useRef)(!1),d=(0,n.useRef)({x:0,y:0}),f=(0,n.useCallback)(e=>Math.min(r,Math.max(t,+e.toFixed(2))),[t,r]);return{zoom:o,panOffset:c,zoomIn:(0,n.useCallback)(()=>s(e=>f(e+i)),[f,i]),zoomOut:(0,n.useCallback)(()=>s(e=>f(e-i)),[f,i]),resetZoom:(0,n.useCallback)(()=>{s(1),l({x:0,y:0})},[]),setZoom:(0,n.useCallback)(e=>s(f(e)),[f]),handleWheel:(0,n.useCallback)(e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();let t=e.deltaY>0?-i:i;s(e=>f(e+t))}},[f,i]),startPan:(0,n.useCallback)(e=>{if(e.button===1||e.button===0&&e.altKey){e.preventDefault(),u.current=!0,d.current={x:e.clientX,y:e.clientY};let t=e=>{if(!u.current)return;let t=e.clientX-d.current.x,n=e.clientY-d.current.y;d.current={x:e.clientX,y:e.clientY},l(e=>({x:e.x+t,y:e.y+n}))},n=()=>{u.current=!1,document.removeEventListener(`mousemove`,t),document.removeEventListener(`mouseup`,n)};document.addEventListener(`mousemove`,t),document.addEventListener(`mouseup`,n)}},[]),transformStyle:{transform:`translate(${c.x}px, ${c.y}px) scale(${o})`,transformOrigin:`0 0`}}}var x=m((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),S=m((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,O,E,H,E),G[E+O]=!0)}if(E=null,T!==void 0&&(n(T),E=""+T),c(B)&&(n(B.key),E=""+B.key),"key"in B){T={};for(var Y in B)Y!=="key"&&(T[Y]=B[Y])}else T=B;return E&&f(T,typeof h=="function"?h.displayName||h.name||"Unknown":h),l(h,E,T,r(),F,y)}function d(h){g(h)?h._store&&(h._store.validated=1):typeof h=="object"&&h!==null&&h.$$typeof===S&&(h._payload.status==="fulfilled"?g(h._payload.value)&&h._payload.value._store&&(h._payload.value._store.validated=1):h._store&&(h._store.validated=1))}function g(h){return typeof h=="object"&&h!==null&&h.$$typeof===x}var v=a,x=Symbol.for("react.transitional.element"),w=Symbol.for("react.portal"),L=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),$=Symbol.for("react.consumer"),V=Symbol.for("react.context"),D=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),_=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),K=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),U=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ae=Object.prototype.hasOwnProperty,ne=Array.isArray,z=console.createTask?console.createTask:function(){return null};v={react_stack_bottom_frame:function(h){return h()}};var R,q={},k=v.react_stack_bottom_frame.bind(v,o)(),W=z(i(o)),G={};Ee.Fragment=L,Ee.jsx=function(h,B,T){var O=1e4>U.recentlyCreatedOwnerStacks++;return m(h,B,T,!1,O?Error("react-stack-top-frame"):k,O?z(i(h)):W)},Ee.jsxs=function(h,B,T){var O=1e4>U.recentlyCreatedOwnerStacks++;return m(h,B,T,!0,O?Error("react-stack-top-frame"):k,O?z(i(h)):W)}})()),Ee}var rt;function $t(){return rt||(rt=1,process.env.NODE_ENV==="production"?Me.exports=_t():Me.exports=Mt()),Me.exports}var e=$t();function he(t,s={}){const{maxHistory:n=50}=s,[i,r]=a.useState(t),o=a.useRef([]),c=a.useRef([]),f=a.useCallback(d=>{r(g=>(o.current=[...o.current.slice(-(n-1)),g],c.current=[],d))},[n]),b=a.useCallback(()=>{o.current.length!==0&&r(d=>{const g=[...o.current],v=g.pop();return o.current=g,c.current=[d,...c.current],v})},[]),l=a.useCallback(()=>{c.current.length!==0&&r(d=>{const g=[...c.current],v=g.shift();return c.current=g,o.current=[...o.current,d],v})},[]),m=a.useCallback(d=>{o.current=[],c.current=[],r(d)},[]);return{current:i,canUndo:o.current.length>0,canRedo:c.current.length>0,undoCount:o.current.length,redoCount:c.current.length,push:f,undo:b,redo:l,reset:m}}function we(){const[t,s]=a.useState(!1),[n,i]=a.useState(""),[r,o]=a.useState(""),c=a.useRef(null),f=a.useCallback((m,d)=>(i(m),o(d),s(!0),new Promise(g=>{c.current=g})),[]),b=a.useCallback(()=>{s(!1),c.current?.(!0),c.current=null},[]),l=a.useCallback(()=>{s(!1),c.current?.(!1),c.current=null},[]);return{isOpen:t,title:n,message:r,confirm:f,onConfirm:b,onCancel:l}}function Te(){const[t,s]=a.useState(new Set),n=a.useCallback((f,b=!1)=>{s(l=>{const m=new Set(b?l:[]);return l.has(f)&&b?m.delete(f):m.add(f),m})},[]),i=a.useCallback(f=>{s(new Set([f]))},[]),r=a.useCallback(f=>{s(new Set(f))},[]),o=a.useCallback(()=>{s(new Set)},[]),c=a.useCallback(f=>t.has(f),[t]);return{selectedIds:t,toggle:n,selectOne:i,selectMany:r,clearSelection:o,isSelected:c,count:t.size}}function Pe(){const[t,s]=a.useState(null),n=a.useCallback(r=>{s(structuredClone(r))},[]),i=a.useCallback(()=>t?structuredClone(t):null,[t]);return{clipboard:t,copy:n,paste:i,hasContent:t!==null}}function $e(t={}){const{minZoom:s=.25,maxZoom:n=3,zoomStep:i=.1,initialZoom:r=1}=t,[o,c]=a.useState(r),[f,b]=a.useState({x:0,y:0}),l=a.useRef(!1),m=a.useRef({x:0,y:0}),d=a.useCallback($=>Math.min(n,Math.max(s,+$.toFixed(2))),[s,n]),g=a.useCallback(()=>c($=>d($+i)),[d,i]),v=a.useCallback(()=>c($=>d($-i)),[d,i]),x=a.useCallback(()=>{c(1),b({x:0,y:0})},[]),w=a.useCallback($=>c(d($)),[d]),L=a.useCallback($=>{if($.ctrlKey||$.metaKey){$.preventDefault();const V=$.deltaY>0?-i:i;c(D=>d(D+V))}},[d,i]),A=a.useCallback($=>{if($.button===1||$.button===0&&$.altKey){$.preventDefault(),l.current=!0,m.current={x:$.clientX,y:$.clientY};const V=P=>{if(!l.current)return;const j=P.clientX-m.current.x,_=P.clientY-m.current.y;m.current={x:P.clientX,y:P.clientY},b(S=>({x:S.x+j,y:S.y+_}))},D=()=>{l.current=!1,document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",D)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",D)}},[]),M={transform:`translate(${f.x}px, ${f.y}px) scale(${o})`,transformOrigin:"0 0"};return{zoom:o,panOffset:f,zoomIn:g,zoomOut:v,resetZoom:x,setZoom:w,handleWheel:L,startPan:A,transformStyle:M}}function Ft(...t){return ie.twMerge(le.clsx(t))}function Ie({isOpen:t,title:s,message:n,confirmLabel:i="Delete",cancelLabel:r="Cancel",destructive:o=!0,onConfirm:c,onCancel:f}){const b=a.useRef(null);return a.useEffect(()=>{const l=b.current;l&&(t&&!l.open?l.showModal():!t&&l.open&&l.close())},[t]),t?e.jsx("dialog",{ref:b,className:"fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50",onClose:f,"aria-labelledby":"confirm-title","aria-describedby":"confirm-message",children:e.jsxs("div",{className:"w-80 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[o&&e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10",children:e.jsx(u.AlertTriangle,{className:"h-5 w-5 text-destructive"})}),e.jsx("h2",{id:"confirm-title",className:"text-lg font-semibold",children:s})]}),e.jsx("p",{id:"confirm-message",className:"text-sm text-muted-foreground mb-6",children:n}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:f,className:"px-4 py-2 text-sm rounded-md border hover:bg-accent",children:r}),e.jsx("button",{onClick:c,className:Ft("px-4 py-2 text-sm rounded-md font-medium",o?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"),autoFocus:!0,children:i})]})]})}):null}function Ut(...t){return ie.twMerge(le.clsx(t))}function Le({title:t="Properties",fields:s,onChange:n,className:i}){const[r,o]=a.useState(new Set),c=a.useCallback(b=>{o(l=>{const m=new Set(l);return m.has(b)?m.delete(b):m.add(b),m})},[]),f=s.reduce((b,l)=>{const m=l.group??"General";return b[m]||(b[m]=[]),b[m].push(l),b},{});return e.jsxs("div",{className:Ut("flex flex-col",i),role:"region","aria-label":t,children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:t}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Object.entries(f).map(([b,l])=>e.jsxs("div",{className:"border-b last:border-b-0",children:[e.jsxs("button",{onClick:()=>c(b),className:"w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50",children:[r.has(b)?e.jsx(u.ChevronRight,{className:"h-3 w-3"}):e.jsx(u.ChevronDown,{className:"h-3 w-3"}),b]}),!r.has(b)&&e.jsx("div",{className:"px-3 pb-2 space-y-2",children:l.map(m=>e.jsx(zt,{field:m,onChange:n},m.name))})]},b)),s.length===0&&e.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"Select an element to edit its properties"})]})]})}function zt({field:t,onChange:s}){const n=i=>{s(t.name,i)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:t.label}),t.type==="text"&&e.jsx("input",{type:"text",value:String(t.value??""),onChange:i=>n(i.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),t.type==="number"&&e.jsx("input",{type:"number",value:Number(t.value??0),onChange:i=>n(Number(i.target.value)),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),t.type==="boolean"&&e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!t.value,onChange:i=>n(i.target.checked),className:"rounded"}),e.jsx("span",{className:"text-xs",children:t.value?"Yes":"No"})]}),t.type==="select"&&e.jsx("select",{value:String(t.value??""),onChange:i=>n(i.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background",children:t.options?.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))}),t.type==="color"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:String(t.value??"#000000"),onChange:i=>n(i.target.value),className:"h-6 w-6 rounded border cursor-pointer"}),e.jsx("span",{className:"text-xs font-mono",children:String(t.value??"#000000")})]}),t.type==="textarea"&&e.jsx("textarea",{value:String(t.value??""),onChange:i=>n(i.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background resize-y",rows:3}),t.description&&e.jsx("p",{className:"text-[0.65rem] text-muted-foreground/70",children:t.description})]})}function Gt(...t){return ie.twMerge(le.clsx(t))}function Fe({items:t,canvasWidth:s,canvasHeight:n,position:i="bottom-right",size:r=150,className:o}){const c=Math.min(r/s,r/n),f=s*c,b=n*c,l={"top-left":"top-2 left-2","top-right":"top-2 right-2","bottom-left":"bottom-2 left-2","bottom-right":"bottom-2 right-2"};return e.jsx("div",{className:Gt("absolute border rounded bg-background/90 shadow-sm overflow-hidden",l[i],o),role:"img","aria-label":"Canvas minimap",children:e.jsxs("svg",{width:f,height:b,viewBox:`0 0 ${s} ${n}`,children:[e.jsx("rect",{width:s,height:n,fill:"hsl(var(--muted))",opacity:"0.3"}),t.map(m=>e.jsx("rect",{x:m.x,y:m.y,width:m.width,height:m.height,fill:m.selected?"hsl(var(--primary))":m.color??"hsl(var(--foreground) / 0.3)",rx:"2"},m.id))]})})}function Kt(...t){return ie.twMerge(le.clsx(t))}const Ue=a.createContext(null);Ue.displayName="CollaborationContext";function Ot({config:t,user:s,onOperation:n,onPresenceChange:i,children:r}){const o=a.useRef(null),[c,f]=a.useState([]),[b,l]=a.useState("disconnected"),m=a.useRef(0),d=a.useRef(null);a.useEffect(()=>{if(!t.enabled||!s||!t.serverUrl||!(typeof WebSocket<"u"))return;function A(){let M;try{if(M=new URL(t.serverUrl),M.protocol!=="ws:"&&M.protocol!=="wss:")return}catch{return}t.roomId&&M.searchParams.set("room",t.roomId),M.searchParams.set("userId",s.id),l("connecting");const $=new WebSocket(M.toString());$.onopen=()=>{l("connected"),$.send(JSON.stringify({type:"join",userId:s.id,userName:s.name,avatar:s.avatar}))},$.onmessage=V=>{try{const D=JSON.parse(V.data);if(D.type==="presence"){const P=D.users||[];f(P.filter(j=>j.userId!==s.id)),i?.(P)}else D.type==="operation"&&n?.(D.operation)}catch{}},$.onclose=()=>{l("disconnected"),o.current=null,t.enabled&&(d.current=setTimeout(A,t.autoSaveInterval??3e3))},$.onerror=()=>{l("error")},o.current=$}return A(),()=>{d.current&&clearTimeout(d.current),o.current&&(o.current.onclose=null,o.current.close(),o.current=null),l("disconnected")}},[t.enabled,t.serverUrl,t.roomId,t.autoSaveInterval,s,n,i]);const g=a.useMemo(()=>!t.enabled||!s?[]:[{userId:s.id,userName:s.name,avatar:s.avatar,color:Vt(s.id),status:"active",lastActivity:new Date().toISOString()},...c],[t.enabled,s,c]),v=t.enabled&&!!s&&(t.serverUrl?b==="connected":!0),x=a.useCallback(L=>{if(!t.enabled||!s)return;m.current+=1;const A={...L,id:`op-${Date.now()}-${m.current}`,userId:s.id,timestamp:new Date().toISOString(),version:m.current};o.current?.readyState===WebSocket.OPEN&&o.current.send(JSON.stringify({type:"operation",operation:A})),n?.(A)},[t.enabled,s,n]),w=a.useMemo(()=>({users:g,isConnected:v,sendOperation:x,currentUserId:s?.id,connectionState:b,versionCount:m.current}),[g,v,x,s?.id,b]);return e.jsx(Ue.Provider,{value:w,children:r})}function ze(){return a.useContext(Ue)}function Ht({className:t}){const s=a.useContext(Ue);if(!s)return null;const{connectionState:n,users:i}=s,r={connected:{color:"bg-green-500",label:"Connected"},connecting:{color:"bg-yellow-500 animate-pulse",label:"Connecting…"},disconnected:{color:"bg-gray-400",label:"Disconnected"},error:{color:"bg-red-500",label:"Connection error"}},{color:o,label:c}=r[n]??r.disconnected;return e.jsxs("div",{className:Kt("flex items-center gap-2 text-xs",t),role:"status","aria-live":"polite","aria-label":`Collaboration: ${c}`,children:[e.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${o}`}),e.jsx("span",{children:c}),n==="connected"&&i.length>1&&e.jsxs("span",{className:"text-muted-foreground",children:["(",i.length," users)"]})]})}function Vt(t){const s=["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#f97316","#14b8a6","#f43f5e","#a855f7","#84cc16","#0ea5e9","#e879f9","#fb923c","#facc15"];let n=0;for(let i=0;i<t.length;i++)n=(n<<5)-n+t.charCodeAt(i)|0;return s[Math.abs(n)%s.length]}function pe(...t){return ie.twMerge(le.clsx(t))}function nt({canvas:t={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:s=[],palette:n=Wt,showComponentTree:i=!0,undoRedo:r=!0,propertyEditor:o=!0,readOnly:c=!1,showMinimap:f=!1,onChange:b,className:l}){const m=he(s),d=m.current,g=a.useCallback(y=>{m.push(y),b?.(y)},[m,b]),v=$e({initialZoom:t.zoom??1}),{zoom:x}=v,w=Te(),L=a.useMemo(()=>{const y=Array.from(w.selectedIds);return y.length>0?y[0]:null},[w.selectedIds]),A=a.useMemo(()=>d.find(y=>y.id===L),[d,L]),M=Pe(),$=we(),V=ze(),D=a.useCallback(y=>{V&&V.sendOperation({...y,userId:V.currentUserId??""})},[V]),[P,j]=a.useState(!0),[_,S]=a.useState(!0),[K,Q]=a.useState(f),U=a.useRef(null),ae=a.useRef(null),ne=a.useCallback(y=>!t.snapToGrid||!t.gridSize?y:Math.round(y/t.gridSize)*t.gridSize,[t.snapToGrid,t.gridSize]),z=a.useCallback((y,E)=>{if(c)return;const H=n.flatMap(oe=>oe.items).find(oe=>oe.type===y),Y=H?.defaultSize,ee={id:`comp-${Date.now()}`,type:y,label:E,position:{x:100,y:100,width:Y?.width??200,height:Y?.height??100},props:H?.defaultProps??{}},re=[...d,ee];g(re),w.selectOne(ee.id),D({type:"insert",elementId:ee.id,data:{component:ee}})},[d,c,n,g,w,D]),R=a.useCallback(y=>{if(c)return;const E=d.filter(H=>H.id!==y);g(E),w.isSelected(y)&&w.clearSelection(),D({type:"delete",elementId:y,data:{}})},[d,c,g,w,D]),q=a.useCallback(async()=>{if(c||w.count===0||!await $.confirm("Delete components",`Are you sure you want to delete ${w.count} component${w.count>1?"s":""}?`))return;const E=w.selectedIds,H=d.filter(Y=>!E.has(Y.id));g(H),w.clearSelection(),E.forEach(Y=>{D({type:"delete",elementId:Y,data:{}})})},[c,w,$,d,g,D]),k=a.useCallback((y,E)=>{if(c||!L)return;const H=d.map(Y=>Y.id!==L?Y:y==="label"?{...Y,label:String(E)}:y==="x"?{...Y,position:{...Y.position,x:Number(E)}}:y==="y"?{...Y,position:{...Y.position,y:Number(E)}}:y==="width"?{...Y,position:{...Y.position,width:Number(E)}}:y==="height"?{...Y,position:{...Y.position,height:Number(E)}}:{...Y,props:{...Y.props,[y]:E}});g(H),D({type:"update",elementId:L,data:{[y]:E}})},[c,L,d,g,D]),W=a.useCallback(()=>{const y=w.selectedIds;if(y.size===0)return;const E=d.filter(H=>y.has(H.id));M.copy(E)},[w,d,M]),G=a.useCallback(()=>{if(c)return;const y=M.paste();if(!y||y.length===0)return;let E=0;const H=y.map(ee=>({...ee,id:`comp-${Date.now()}-${++E}-${Math.random().toString(36).slice(2,7)}`,position:{...ee.position,x:ee.position.x+20,y:ee.position.y+20}})),Y=[...d,...H];g(Y),w.selectMany(H.map(ee=>ee.id)),H.forEach(ee=>{D({type:"insert",elementId:ee.id,data:{component:ee}})})},[c,M,d,g,w,D]),h=a.useCallback((y,E)=>{c||(U.current={id:E.id,startX:y.clientX,startY:y.clientY},y.dataTransfer.effectAllowed="move",y.dataTransfer.setData("text/plain",E.id))},[c]),B=a.useCallback(y=>{y.preventDefault(),y.dataTransfer.dropEffect="move"},[]),T=a.useCallback(y=>{y.preventDefault();const E=U.current;if(!E||c)return;const H=(y.clientX-E.startX)/x,Y=(y.clientY-E.startY)/x,ee=d.map(re=>re.id!==E.id?re:{...re,position:{...re.position,x:ne(re.position.x+H),y:ne(re.position.y+Y)}});g(ee),D({type:"move",elementId:E.id,data:{}}),U.current=null},[c,x,d,g,ne,D]),O=a.useMemo(()=>A?[{name:"label",label:"Label",type:"text",value:A.label??"",group:"General"},{name:"x",label:"X",type:"number",value:A.position.x,group:"Position"},{name:"y",label:"Y",type:"number",value:A.position.y,group:"Position"},{name:"width",label:"Width",type:"number",value:A.position.width,group:"Size"},{name:"height",label:"Height",type:"number",value:A.position.height,group:"Size"}]:[],[A]),F=a.useMemo(()=>d.map(y=>({id:y.id,x:y.position.x,y:y.position.y,width:typeof y.position.width=="number"?y.position.width:100,height:typeof y.position.height=="number"?y.position.height:50,selected:w.isSelected(y.id)})),[d,w]);return a.useEffect(()=>{const y=ae.current;if(!y)return;const E=H=>{const Y=["INPUT","TEXTAREA","SELECT"].includes(H.target.tagName),ee=H.ctrlKey||H.metaKey;if((H.key==="Delete"||H.key==="Backspace")&&w.count>0&&!Y){H.preventDefault(),q();return}if(H.key==="Escape"){w.clearSelection();return}if(!Y){if(ee&&H.key==="z"&&!H.shiftKey&&r&&!c){H.preventDefault(),m.undo();return}if(ee&&(H.key==="z"&&H.shiftKey||H.key==="y")&&r&&!c){H.preventDefault(),m.redo();return}if(ee&&H.key==="c"){H.preventDefault(),W();return}if(ee&&H.key==="v"&&!c){H.preventDefault(),G();return}if(ee&&H.key==="a"){H.preventDefault(),w.selectMany(d.map(re=>re.id));return}}};return y.addEventListener("keydown",E),()=>y.removeEventListener("keydown",E)},[w,q,r,c,m,W,G,d]),e.jsxs("div",{ref:ae,tabIndex:0,className:pe("flex h-full w-full border rounded-lg overflow-hidden bg-background",l),children:[!c&&e.jsx("div",{className:pe("border-r bg-muted/30 flex flex-col transition-[width] duration-200",P?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component palette",children:P&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:"Components"}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:n.map(y=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1 uppercase",children:y.label}),y.items.map(E=>e.jsxs("button",{onClick:()=>z(E.type,E.label),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left",children:[e.jsx(u.Plus,{className:"h-3 w-3"}),E.label]},E.type))]},y.name))})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Designer toolbar",children:[!c&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:P?"Collapse palette":"Expand palette","aria-label":P?"Collapse palette":"Expand palette",onClick:()=>j(y=>!y),children:e.jsx(u.PanelLeftClose,{className:pe("h-4 w-4",!P&&"rotate-180")})}),r&&!c&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:pe("p-1.5 rounded hover:bg-accent",!m.canUndo&&"opacity-40 pointer-events-none"),title:"Undo (Ctrl+Z)","aria-label":"Undo",disabled:!m.canUndo,onClick:()=>m.undo(),children:e.jsx(u.Undo2,{className:"h-4 w-4"})}),e.jsx("button",{className:pe("p-1.5 rounded hover:bg-accent",!m.canRedo&&"opacity-40 pointer-events-none"),title:"Redo (Ctrl+Shift+Z)","aria-label":"Redo",disabled:!m.canRedo,onClick:()=>m.redo(),children:e.jsx(u.Redo2,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:pe("p-1.5 rounded hover:bg-accent",w.count===0&&"opacity-40 pointer-events-none"),title:"Copy (Ctrl+C)","aria-label":"Copy",disabled:w.count===0,onClick:W,children:e.jsx(u.Copy,{className:"h-4 w-4"})}),e.jsx("button",{className:pe("p-1.5 rounded hover:bg-accent",!M.hasContent&&"opacity-40 pointer-events-none"),title:"Paste (Ctrl+V)","aria-label":"Paste",disabled:!M.hasContent,onClick:G,children:e.jsx(u.Clipboard,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!c&&e.jsx("button",{className:pe("p-1.5 rounded hover:bg-accent",w.count===0&&"opacity-40 pointer-events-none"),title:"Delete selected","aria-label":"Delete selected",disabled:w.count===0,onClick:q,children:e.jsx(u.Trash2,{className:"h-4 w-4"})}),e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:"Preview","aria-label":"Preview",children:e.jsx(u.Eye,{className:"h-4 w-4"})}),e.jsx("button",{className:pe("p-1.5 rounded hover:bg-accent",K&&"bg-accent"),title:"Toggle minimap","aria-label":"Toggle minimap",onClick:()=>Q(y=>!y),children:e.jsx(u.Map,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom out",onClick:v.zoomOut,children:e.jsx(u.Minus,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-center",children:[Math.round(x*100),"%"]}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom in",onClick:v.zoomIn,children:e.jsx(u.Plus,{className:"h-3 w-3"})}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Reset zoom",onClick:v.resetZoom,children:e.jsx(u.Maximize2,{className:"h-3 w-3"})})]}),i&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:_?"Collapse panel":"Expand panel","aria-label":_?"Collapse panel":"Expand panel",onClick:()=>S(y=>!y),children:e.jsx(u.PanelRightClose,{className:pe("h-4 w-4",!_&&"rotate-180")})})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4 relative",role:"region","aria-label":"Design canvas",onWheel:v.handleWheel,onMouseDown:v.startPan,onDragOver:B,onDrop:T,children:e.jsxs("div",{className:"relative bg-background border rounded shadow-sm mx-auto",style:{width:t.width*x,height:t.height*x,transform:`translate(${v.panOffset.x}px, ${v.panOffset.y}px)`,backgroundImage:t.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:t.showGrid&&t.gridSize?`${t.gridSize*x}px ${t.gridSize*x}px`:void 0},children:[d.map(y=>{const E=w.isSelected(y.id);return e.jsxs("div",{draggable:!c,onDragStart:H=>h(H,y),className:pe("absolute border rounded cursor-move select-none transition-shadow",E?"border-primary ring-2 ring-primary/20 shadow-md":"border-border hover:border-primary/50"),style:{left:y.position.x*x,top:y.position.y*x,width:typeof y.position.width=="number"?y.position.width*x:y.position.width,height:typeof y.position.height=="number"?y.position.height*x:y.position.height},onClick:H=>w.toggle(y.id,H.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b",children:[e.jsx(u.GripVertical,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:y.label??y.type}),!c&&e.jsx("button",{onClick:H=>{H.stopPropagation(),R(y.id)},className:"ml-auto p-0.5 rounded hover:bg-destructive/10","aria-label":`Delete ${y.label??y.type}`,children:e.jsx(u.Trash2,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"p-2 text-xs text-muted-foreground",children:y.type})]},y.id)}),K&&e.jsx(Fe,{items:F,canvasWidth:t.width,canvasHeight:t.height})]})})]}),i&&e.jsx("div",{className:pe("border-l bg-muted/30 flex flex-col transition-[width] duration-200",_?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component tree",children:_&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 border-b font-medium text-sm flex items-center gap-2",children:[e.jsx(u.Layers,{className:"h-4 w-4"}),"Component Tree"]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:d.length===0?e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:"No components added yet. Click a component in the palette to add it to the canvas."}):d.map(y=>e.jsx("button",{onClick:E=>w.toggle(y.id,E.shiftKey),className:pe("w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left",w.isSelected(y.id)?"bg-accent":"hover:bg-accent/50"),children:e.jsx("span",{className:"truncate",children:y.label??y.type})},y.id))}),o&&A?e.jsx("div",{className:"border-t",children:e.jsx(Le,{title:`Properties – ${A.label??A.type}`,fields:O,onChange:k})}):A&&e.jsxs("div",{className:"border-t p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Properties"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:["Type: ",A.type]}),e.jsxs("div",{children:["ID: ",A.id]}),e.jsxs("div",{children:["Position: ",A.position.x,","," ",A.position.y]}),e.jsxs("div",{children:["Size: ",A.position.width," ×"," ",A.position.height]})]})]})]})}),e.jsx(Ie,{isOpen:$.isOpen,title:$.title,message:$.message,onConfirm:$.onConfirm,onCancel:$.onCancel})]})}const Wt=[{name:"layout",label:"Layout",items:[{type:"container",label:"Container",defaultSize:{width:400,height:300}},{type:"flex",label:"Flex",defaultSize:{width:400,height:200}},{type:"grid",label:"Grid",defaultSize:{width:400,height:300}},{type:"card",label:"Card",defaultSize:{width:300,height:200}},{type:"tabs",label:"Tabs",defaultSize:{width:400,height:300}}]},{name:"form",label:"Form",items:[{type:"input",label:"Input",defaultSize:{width:300,height:60}},{type:"textarea",label:"Textarea",defaultSize:{width:300,height:120}},{type:"select",label:"Select",defaultSize:{width:300,height:60}},{type:"checkbox",label:"Checkbox",defaultSize:{width:200,height:40}},{type:"button",label:"Button",defaultSize:{width:120,height:40}}]},{name:"data",label:"Data",items:[{type:"table",label:"Table",defaultSize:{width:600,height:400}},{type:"chart",label:"Chart",defaultSize:{width:400,height:300}},{type:"list",label:"List",defaultSize:{width:300,height:400}},{type:"statistic",label:"Statistic",defaultSize:{width:200,height:100}}]}];function ot(t,s={}){return he(t,s)}function We(...t){return ie.twMerge(le.clsx(t))}const Bt=["text","number","boolean","date","datetime","uuid","email","url","phone","json","integer","float","decimal","currency","percent","textarea","select","multiselect","lookup","attachment","formula","autonumber"];function Yt(t,s=4,n=280,i=250,r=50,o=50){return t.map((c,f)=>({...c,position:{x:r+f%s*n,y:o+Math.floor(f/s)*i}}))}function lt({entities:t=[],relationships:s=[],canvas:n={width:1200,height:800,showGrid:!0},showRelationshipLabels:i=!0,readOnly:r=!1,onEntitiesChange:o,onRelationshipsChange:c,className:f}){const b=a.useRef(null),l=ot({entities:t,relationships:s},{maxHistory:50}),{entities:m,relationships:d}=l.current,g=a.useCallback(N=>{l.push(N),o?.(N.entities),c?.(N.relationships)},[l,o,c]),v=we(),x=Te(),w=x.count>0?Array.from(x.selectedIds)[0]:null,L=Pe(),A=$e({minZoom:.25,maxZoom:3,zoomStep:.1}),M=ze(),[$,V]=a.useState(!0),[D,P]=a.useState(!0),[j,_]=a.useState(null),[S,K]=a.useState(""),[Q,U]=a.useState(null),[ae,ne]=a.useState(""),z=a.useRef(null),R=a.useCallback(()=>{if(r)return;const N=l.current,p={id:`entity-${Date.now()}`,name:`new_entity_${N.entities.length+1}`,label:`New Entity ${N.entities.length+1}`,fields:[{name:"id",type:"uuid",primaryKey:!0,required:!0},{name:"created_at",type:"datetime",required:!0},{name:"updated_at",type:"datetime",required:!0}],position:{x:50+N.entities.length%4*280,y:50+Math.floor(N.entities.length/4)*250}},I={entities:[...N.entities,p],relationships:N.relationships};g(I),x.selectOne(p.id),M?.sendOperation({type:"insert",userId:M?.currentUserId??"",elementId:p.id,data:{name:p.name,label:p.label}})},[r,l,g,x,M]),q=a.useCallback(async N=>{if(r)return;const p=m.find(J=>J.id===N);if(!await v.confirm("Delete Entity",`Are you sure you want to delete "${p?.label??N}"? This action cannot be undone.`))return;const C=l.current,X={entities:C.entities.filter(J=>J.id!==N),relationships:C.relationships.filter(J=>J.sourceEntity!==N&&J.targetEntity!==N)};g(X),x.isSelected(N)&&x.clearSelection(),M?.sendOperation({type:"delete",userId:M?.currentUserId??"",elementId:N,data:{}})},[r,m,v,l,g,x,M]),k=a.useCallback(async()=>{if(r||x.count===0)return;const N=Array.from(x.selectedIds);if(!await v.confirm("Delete Entities",`Are you sure you want to delete ${N.length} selected entity(s)? This action cannot be undone.`))return;const I=l.current,C=new Set(N),X={entities:I.entities.filter(J=>!C.has(J.id)),relationships:I.relationships.filter(J=>!C.has(J.sourceEntity)&&!C.has(J.targetEntity))};g(X),x.clearSelection()},[r,x,v,l,g]),W=a.useCallback(()=>{if(r)return;const N=l.current,p={entities:Yt(N.entities),relationships:N.relationships};g(p)},[r,l,g]),G=a.useCallback(()=>{const N=m.filter(p=>x.isSelected(p.id));N.length>0&&L.copy(N)},[m,x,L]),h=a.useCallback(()=>{if(r)return;const N=L.paste();if(!N||N.length===0)return;const p=l.current,I=N.map((X,J)=>({...X,id:`entity-${Date.now()}-${J}`,name:`${X.name}_copy`,label:`${X.label} (Copy)`,position:{x:X.position.x+30,y:X.position.y+30}})),C={entities:[...p.entities,...I],relationships:p.relationships};g(C),x.selectMany(I.map(X=>X.id))},[r,L,l,g,x]),B=a.useCallback(N=>{if(r)return;const p=l.current,I={entities:p.entities.map(C=>{if(C.id!==N)return C;const X={name:`field_${C.fields.length+1}`,type:"text",required:!1};return{...C,fields:[...C.fields,X]}}),relationships:p.relationships};g(I)},[r,l,g]),T=a.useCallback((N,p,I)=>{r||(_({entityId:N,fieldIndex:p}),K(I))},[r]),O=a.useCallback(()=>{if(!j)return;const N=S.trim();if(N===""){_(null);return}const p=l.current,I={entities:p.entities.map(C=>{if(C.id!==j.entityId)return C;const X=C.fields.map((J,se)=>se===j.fieldIndex?{...J,name:N}:J);return{...C,fields:X}}),relationships:p.relationships};g(I),_(null)},[j,S,l,g]),F=a.useCallback(()=>{_(null)},[]),y=a.useCallback((N,p)=>{r||(U(N),ne(p))},[r]),E=a.useCallback(()=>{if(!Q)return;const N=ae.trim();if(N===""){U(null);return}const p=l.current,I={entities:p.entities.map(C=>C.id===Q?{...C,label:N}:C),relationships:p.relationships};g(I),U(null)},[Q,ae,l,g]),H=a.useCallback(()=>{U(null)},[]),Y=a.useCallback((N,p,I)=>{if(r)return;const C=l.current,X={entities:C.entities.map(J=>{if(J.id!==N)return J;const se=J.fields.map((me,fe)=>fe===p?{...me,type:I}:me);return{...J,fields:se}}),relationships:C.relationships};g(X)},[r,l,g]),ee=a.useCallback((N,p)=>{if(r||!m.find(X=>X.id===p))return;const C=N.target.getBoundingClientRect();z.current={entityId:p,offsetX:N.clientX-C.left,offsetY:N.clientY-C.top},N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",p)},[r,m]),re=a.useCallback(N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},[]),oe=a.useCallback(N=>{if(N.preventDefault(),!z.current)return;const p=N.currentTarget.getBoundingClientRect(),I=A.zoom,C=(N.clientX-p.left-A.panOffset.x)/I-z.current.offsetX,X=(N.clientY-p.top-A.panOffset.y)/I-z.current.offsetY,J=l.current,se={entities:J.entities.map(me=>me.id===z.current.entityId?{...me,position:{x:Math.max(0,Math.round(C)),y:Math.max(0,Math.round(X))}}:me),relationships:J.relationships};g(se),z.current=null},[A.zoom,A.panOffset,l,g]),ce=w?m.find(N=>N.id===w):null,Je=ce?[{name:"name",label:"Name",type:"text",value:ce.name,group:"General"},{name:"label",label:"Label",type:"text",value:ce.label,group:"General"},{name:"description",label:"Description",type:"textarea",value:ce.description??"",group:"General"},{name:"color",label:"Color",type:"color",value:ce.color??"#3b82f6",group:"Appearance"},{name:"position.x",label:"X Position",type:"number",value:ce.position.x,group:"Position"},{name:"position.y",label:"Y Position",type:"number",value:ce.position.y,group:"Position"}]:[],Qe=a.useCallback((N,p)=>{if(!w)return;const I=l.current,C={entities:I.entities.map(X=>X.id!==w?X:N==="position.x"?{...X,position:{...X.position,x:Number(p)}}:N==="position.y"?{...X,position:{...X.position,y:Number(p)}}:{...X,[N]:p}),relationships:I.relationships};g(C)},[w,l,g]);a.useEffect(()=>{const N=b.current;if(!N)return;const p=I=>{const C=I.target.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT")return;const X=I.ctrlKey||I.metaKey;X&&I.key==="z"?(I.preventDefault(),l.undo()):X&&(I.key==="y"||I.shiftKey&&I.key==="Z")?(I.preventDefault(),l.redo()):X&&I.key==="c"?(I.preventDefault(),G()):X&&I.key==="v"?(I.preventDefault(),h()):(I.key==="Delete"||I.key==="Backspace")&&x.count>0?(I.preventDefault(),k()):I.key==="Escape"&&(x.clearSelection(),_(null),U(null))};return N.addEventListener("keydown",p),()=>N.removeEventListener("keydown",p)},[l,G,h,k,x]);const Re=m.map(N=>({id:N.id,x:N.position.x,y:N.position.y,width:240,height:40+N.fields.length*24,color:N.color,selected:x.isSelected(N.id)}));return e.jsxs("div",{ref:b,tabIndex:0,className:We("flex h-full w-full border rounded-lg overflow-hidden bg-background",f),children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{role:"toolbar","aria-label":"Designer toolbar",className:"flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap",children:[e.jsx(u.Database,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:"Data Model Designer"}),e.jsxs("div",{className:"flex items-center gap-1 ml-2 border-l pl-2",children:[e.jsx("button",{onClick:()=>l.undo(),disabled:!l.canUndo,"aria-label":"Undo",title:"Undo (Ctrl+Z)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(u.Undo2,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>l.redo(),disabled:!l.canRedo,"aria-label":"Redo",title:"Redo (Ctrl+Y)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(u.Redo2,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:A.zoomOut,"aria-label":"Zoom Out",title:"Zoom Out",className:"p-1 rounded hover:bg-accent",children:e.jsx(u.ZoomOut,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"text-xs tabular-nums w-10 text-center",children:[Math.round(A.zoom*100),"%"]}),e.jsx("button",{onClick:A.zoomIn,"aria-label":"Zoom In",title:"Zoom In",className:"p-1 rounded hover:bg-accent",children:e.jsx(u.ZoomIn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:A.resetZoom,"aria-label":"Reset Zoom",title:"Reset Zoom",className:"p-1 rounded hover:bg-accent",children:e.jsx(u.RotateCcw,{className:"h-3 w-3"})})]}),!r&&e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:G,disabled:x.count===0,"aria-label":"Copy",title:"Copy (Ctrl+C)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(u.Copy,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:h,disabled:!L.hasContent,"aria-label":"Paste",title:"Paste (Ctrl+V)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(u.Clipboard,{className:"h-3.5 w-3.5"})})]}),!r&&e.jsxs("button",{onClick:W,"aria-label":"Auto Layout",title:"Auto Layout",className:"flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent",children:[e.jsx(u.Grid3X3,{className:"h-3 w-3"})," Auto Layout"]}),e.jsx("div",{className:"flex-1"}),M?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx(u.Users,{className:"h-3 w-3"}),e.jsxs("span",{children:[M.users.length," user",M.users.length!==1?"s":""]})]}),x.count>1&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[x.count," selected"]}),!r&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:R,"aria-label":"Add Entity",className:"flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(u.Plus,{className:"h-3 w-3"})," Add Entity"]}),e.jsxs("button",{"aria-label":"Add Relationship",title:"Add Relationship (coming soon)",className:"flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80",children:[e.jsx(u.Link2,{className:"h-3 w-3"})," Add Relationship"]})]})]}),e.jsxs("div",{role:"region","aria-label":"Canvas",className:"flex-1 overflow-auto bg-muted/10 p-4 relative",onWheel:A.handleWheel,onMouseDown:A.startPan,onDragOver:re,onDrop:oe,children:[e.jsxs("div",{className:"relative",style:{width:n.width,minHeight:n.height,...A.transformStyle,backgroundImage:n.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:n.showGrid?"20px 20px":void 0},children:[e.jsx("svg",{className:"absolute inset-0 pointer-events-none",width:n.width,height:n.height,children:d.map(N=>{const p=m.find(C=>C.id===N.sourceEntity),I=m.find(C=>C.id===N.targetEntity);return!p||!I?null:e.jsxs("g",{children:[e.jsx("line",{x1:p.position.x+120,y1:p.position.y+50,x2:I.position.x+120,y2:I.position.y+50,stroke:"hsl(var(--primary))",strokeWidth:"2",strokeDasharray:N.type==="many-to-many"?"5,5":void 0}),i&&N.label&&e.jsx("text",{x:(p.position.x+I.position.x)/2+120,y:(p.position.y+I.position.y)/2+50-8,textAnchor:"middle",className:"text-xs fill-muted-foreground",children:N.label})]},N.id)})}),m.length===0&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-muted-foreground text-sm",children:"No entities in the model. Click 'Add Entity' to create your first entity."}),m.map(N=>e.jsxs("div",{role:"group","aria-label":N.label,draggable:!r,onDragStart:p=>ee(p,N.id),className:We("absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing",x.isSelected(N.id)?"border-primary ring-2 ring-primary/20":"border-border hover:border-primary/50"),style:{left:N.position.x,top:N.position.y},onClick:p=>x.toggle(N.id,p.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm",style:{backgroundColor:N.color??"hsl(var(--primary) / 0.1)"},children:[e.jsx(u.Database,{className:"h-3.5 w-3.5"}),Q===N.id?e.jsx("input",{type:"text",value:ae,onChange:p=>ne(p.target.value),onBlur:E,onKeyDown:p=>{p.key==="Enter"&&E(),p.key==="Escape"&&H()},className:"text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary",autoFocus:!0,onClick:p=>p.stopPropagation(),"data-testid":`entity-label-input-${N.id}`}):e.jsx("span",{className:"truncate cursor-text",onDoubleClick:p=>{p.stopPropagation(),y(N.id,N.label)},title:"Double-click to edit label","data-testid":`entity-label-${N.id}`,children:N.label}),!r&&e.jsx("button",{onClick:p=>{p.stopPropagation(),q(N.id)},"aria-label":`Delete ${N.label}`,className:"ml-auto p-0.5 rounded hover:bg-destructive/20",children:e.jsx(u.Trash2,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"px-3 py-1 divide-y",children:N.fields.map((p,I)=>e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs",children:[j&&j.entityId===N.id&&j.fieldIndex===I?e.jsx("input",{type:"text",value:S,onChange:C=>K(C.target.value),onBlur:O,onKeyDown:C=>{C.key==="Enter"&&O(),C.key==="Escape"&&F()},className:"font-mono text-xs px-1 py-0 border rounded bg-background w-24 focus:outline-none focus:ring-1 focus:ring-primary",autoFocus:!0,onClick:C=>C.stopPropagation()}):e.jsxs("span",{className:We("font-mono cursor-text",p.primaryKey&&"font-bold text-primary"),onClick:C=>{C.stopPropagation(),T(N.id,I,p.name)},title:"Click to edit field name",children:[p.primaryKey&&e.jsx("span",{className:"text-[0.65rem] font-semibold text-primary mr-0.5",children:"PK"}),p.name]}),r?e.jsx("span",{className:"text-muted-foreground ml-auto",children:p.type}):e.jsx("select",{value:p.type,onChange:C=>{C.stopPropagation(),Y(N.id,I,C.target.value)},onClick:C=>C.stopPropagation(),className:"text-xs text-muted-foreground ml-auto bg-transparent border-none focus:ring-1 focus:ring-primary rounded cursor-pointer p-0","data-testid":`field-type-${N.id}-${I}`,children:Bt.map(C=>e.jsx("option",{value:C,children:C},C))}),p.required&&e.jsx("span",{className:"text-destructive",children:"*"})]},`${p.name}-${I}`))}),!r&&e.jsx("div",{className:"px-3 py-1 border-t",children:e.jsxs("button",{onClick:p=>{p.stopPropagation(),B(N.id)},"aria-label":`Add field to ${N.label}`,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5",children:[e.jsx(u.Plus,{className:"h-3 w-3"})," Add Field"]})})]},N.id))]}),D&&m.length>0&&e.jsx(Fe,{items:Re,canvasWidth:n.width,canvasHeight:n.height,position:"bottom-right",size:150})]})]}),e.jsxs("div",{className:"w-64 border-l flex flex-col bg-background shrink-0",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsxs("button",{onClick:()=>V(N=>!N),className:"flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 border-b","aria-expanded":$,"aria-controls":"property-editor-panel",children:[$?e.jsx(u.ChevronDown,{className:"h-3 w-3"}):e.jsx(u.ChevronRight,{className:"h-3 w-3"}),"Properties"]}),$&&e.jsx("div",{id:"property-editor-panel",className:"flex-1 overflow-y-auto",children:e.jsx(Le,{title:ce?ce.label:"Properties",fields:Je,onChange:Qe})})]}),e.jsx("div",{className:"border-t",children:e.jsxs("button",{onClick:()=>P(N=>!N),className:"flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 w-full","aria-expanded":D,children:[D?e.jsx(u.ChevronDown,{className:"h-3 w-3"}):e.jsx(u.ChevronRight,{className:"h-3 w-3"}),"Minimap"]})})]}),e.jsx(Ie,{isOpen:v.isOpen,title:v.title,message:v.message,onConfirm:v.onConfirm,onCancel:v.onCancel,destructive:!0})]})}function Ge(...t){return ie.twMerge(le.clsx(t))}const Ce=120,Ae=50;function Zt(t,s){if(t.length===0)return t;const n=200,i=100,r=new Map,o=new Map;for(const d of t)r.set(d.id,0),o.set(d.id,[]);for(const d of s)r.set(d.target,(r.get(d.target)??0)+1),o.get(d.source)?.push(d.target);const c=[],f=new Set;let b=t.filter(d=>(r.get(d.id)??0)===0).map(d=>d.id);for(b.length===0&&(b=[t[0].id]);b.length>0;){c.push(b);for(const g of b)f.add(g);const d=new Set;for(const g of b)for(const v of o.get(g)??[])f.has(v)||d.add(v);b=Array.from(d)}const l=t.filter(d=>!f.has(d.id)).map(d=>d.id);l.length>0&&c.push(l);const m=new Map;for(let d=0;d<c.length;d++){const g=c[d];for(let v=0;v<g.length;v++)m.set(g[v],{x:80+d*n,y:80+v*i})}return t.map(d=>({...d,position:m.get(d.id)??d.position}))}function it({processName:t="New Process",nodes:s=[],edges:n=[],lanes:i,canvas:r={width:1400,height:800,showGrid:!0},showMinimap:o=!0,showToolbar:c=!0,readOnly:f=!1,onNodesChange:b,onEdgesChange:l,className:m}){const d=he({nodes:s,edges:n},{maxHistory:50}),g=d.current.nodes,v=d.current.edges,x=a.useCallback((p,I)=>{d.push({nodes:p,edges:I}),b?.(p),l?.(I)},[d,b,l]),w=we(),L=Te(),A=Pe(),M=$e({initialZoom:1}),$=ze(),[V,D]=a.useState(null),[P,j]=a.useState(!1),[_,S]=a.useState(null),[K,Q]=a.useState(null),[U,ae]=a.useState(!0),[ne,z]=a.useState(null),[R,q]=a.useState({x:0,y:0}),k=a.useRef(null),W=a.useRef(b),G=a.useRef(l);W.current=b,G.current=l,a.useEffect(()=>{W.current?.(g),G.current?.(v)},[d.current]);const h=a.useCallback((p,I)=>{if(f)return;const C={id:`node-${Date.now()}`,type:p,label:I,position:{x:200+g.length*160,y:200}},X=[...g,C];x(X,v),D(C.id),L.selectOne(C.id),$?.sendOperation({type:"insert",elementId:C.id,data:{label:I},userId:$.currentUserId??""})},[g,v,f,x,L,$]),B=a.useCallback(async p=>{if(f)return;const I=g.find(se=>se.id===p);if(!await w.confirm("Delete Node",`Are you sure you want to delete "${I?.label??p}"? This will also remove all connected edges.`))return;const X=g.filter(se=>se.id!==p),J=v.filter(se=>se.source!==p&&se.target!==p);x(X,J),V===p&&D(null),L.clearSelection(),$?.sendOperation({type:"delete",elementId:p,data:{},userId:$.currentUserId??""})},[g,v,V,f,x,w,L,$]),T=a.useCallback(async()=>{if(f||L.count===0||!await w.confirm("Delete Selected Nodes",`Are you sure you want to delete ${L.count} selected node(s) and their connected edges?`))return;const I=L.selectedIds,C=g.filter(J=>!I.has(J.id)),X=v.filter(J=>!I.has(J.source)&&!I.has(J.target));x(C,X),D(null),L.clearSelection()},[g,v,f,x,w,L]),O=a.useCallback(()=>{const p=L.count>0?L.selectedIds:V?new Set([V]):new Set;if(p.size===0)return;const I=g.filter(C=>p.has(C.id));A.copy(I)},[g,V,L,A]),F=a.useCallback(()=>{if(f)return;const p=A.paste();if(!p||p.length===0)return;const I=40,C=p.map(J=>({...J,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:J.position.x+I,y:J.position.y+I}})),X=[...g,...C];x(X,v),L.selectMany(C.map(J=>J.id)),D(C[0].id)},[f,g,v,A,x,L]),y=a.useCallback(()=>{j(p=>p?(S(null),!1):!0)},[]),E=a.useCallback(p=>{if(!P)return!1;if(!_)return S(p),!0;if(_===p)return!0;const I={id:`edge-${Date.now()}`,source:_,target:p},C=[...v,I];return x(g,C),S(null),j(!1),$?.sendOperation({type:"insert",elementId:I.id,data:{source:_,target:p},userId:$.currentUserId??""}),!0},[P,_,g,v,x,$]),H=a.useCallback(()=>{if(f||g.length===0)return;const p=Zt(g,v);x(p,v)},[g,v,f,x]),Y=a.useCallback((p,I)=>{if(f||!g.find(J=>J.id===I))return;z(I);const X=p.target.getBoundingClientRect();q({x:p.clientX-X.left,y:p.clientY-X.top}),p.dataTransfer.effectAllowed="move",p.dataTransfer.setData("text/plain",I)},[f,g]),ee=a.useCallback(p=>{if(p.preventDefault(),f||!ne)return;const I=p.currentTarget.getBoundingClientRect(),C=M.zoom,X=(p.clientX-I.left-M.panOffset.x)/C-R.x,J=(p.clientY-I.top-M.panOffset.y)/C-R.y,se=Math.max(0,Math.round(X/20)*20),me=Math.max(0,Math.round(J/20)*20),fe=g.map(Ne=>Ne.id===ne?{...Ne,position:{x:se,y:me}}:Ne);x(fe,v),z(null)},[f,ne,R,g,v,M.zoom,M.panOffset,x]),re=a.useCallback(p=>{p.preventDefault(),p.dataTransfer.dropEffect="move"},[]),oe=a.useMemo(()=>g.find(p=>p.id===V)??null,[g,V]),ce=a.useMemo(()=>oe?[{name:"label",label:"Name",type:"text",value:oe.label,group:"General"},{name:"type",label:"Type",type:"select",value:oe.type,options:[{label:"Start Event",value:"start-event"},{label:"End Event",value:"end-event"},{label:"User Task",value:"user-task"},{label:"Service Task",value:"service-task"},{label:"Script Task",value:"script-task"},{label:"Exclusive Gateway",value:"exclusive-gateway"},{label:"Parallel Gateway",value:"parallel-gateway"},{label:"Inclusive Gateway",value:"inclusive-gateway"}],group:"General"},{name:"description",label:"Description",type:"textarea",value:oe.description??"",group:"General"}]:[],[oe]),Je=a.useCallback((p,I)=>{if(f||!V)return;const C=g.map(X=>X.id===V?{...X,[p]:I}:X);x(C,v)},[f,V,g,v,x]),Qe=p=>{switch(p){case"start-event":return"rounded-full bg-green-100 border-green-500 text-green-700";case"end-event":return"rounded-full bg-red-100 border-red-500 text-red-700";case"exclusive-gateway":case"parallel-gateway":case"inclusive-gateway":case"event-based-gateway":return"rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700";case"user-task":return"rounded bg-blue-100 border-blue-500 text-blue-700";case"service-task":case"script-task":return"rounded bg-purple-100 border-purple-500 text-purple-700";default:return"rounded bg-gray-100 border-gray-500 text-gray-700"}},Re=a.useMemo(()=>g.map(p=>({id:p.id,x:p.position.x,y:p.position.y,width:Ce,height:Ae,selected:L.isSelected(p.id)||p.id===V})),[g,L,V]);a.useEffect(()=>{const p=k.current;if(!p)return;const I=C=>{const X=C.target?.tagName;if(X==="INPUT"||X==="TEXTAREA"||X==="SELECT")return;const J=C.ctrlKey||C.metaKey;if(J&&C.key==="z"&&!C.shiftKey){C.preventDefault(),d.undo();return}if(J&&C.key==="y"||J&&C.key==="z"&&C.shiftKey){C.preventDefault(),d.redo();return}if(J&&C.key==="c"){C.preventDefault(),O();return}if(J&&C.key==="v"){C.preventDefault(),F();return}if(C.key==="Delete"||C.key==="Backspace"){L.count>0?(C.preventDefault(),T()):V&&(C.preventDefault(),B(V));return}if(C.key==="Escape"){P?(j(!1),S(null)):(D(null),L.clearSelection());return}};return p.addEventListener("keydown",I),()=>p.removeEventListener("keydown",I)},[V,P,L,d,O,F,B,T]);const N=a.useCallback(p=>{p.target===p.currentTarget&&(D(null),L.clearSelection(),P&&(j(!1),S(null)))},[P,L]);return e.jsxs("div",{ref:k,tabIndex:0,className:Ge("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",m),children:[e.jsx(Ie,{isOpen:w.isOpen,title:w.title,message:w.message,onConfirm:w.onConfirm,onCancel:w.onCancel,destructive:!0}),c&&e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Process toolbar",children:[e.jsx(u.GitBranch,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm","aria-label":"Process name",children:t}),$?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),$.users.length," user",$.users.length!==1?"s":""]}),e.jsx("div",{className:"flex-1"}),!f&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>d.undo(),disabled:!d.canUndo,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Undo (Ctrl+Z)","aria-label":"Undo",children:e.jsx(u.Undo2,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>d.redo(),disabled:!d.canRedo,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Redo (Ctrl+Y)","aria-label":"Redo",children:e.jsx(u.Redo2,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:O,disabled:L.count===0&&!V,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Copy (Ctrl+C)","aria-label":"Copy",children:e.jsx(u.Copy,{className:"h-3 w-3"})}),e.jsx("button",{onClick:F,disabled:!A.hasContent,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40",title:"Paste (Ctrl+V)","aria-label":"Paste",children:e.jsx(u.Clipboard,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:y,className:Ge("flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",P&&"bg-primary text-primary-foreground"),title:"Connect nodes","aria-label":"Connect nodes","aria-pressed":P,children:[e.jsx(u.Link,{className:"h-3 w-3"})," Connect"]}),e.jsxs("button",{onClick:H,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Auto layout","aria-label":"Auto layout",children:[e.jsx(u.Layout,{className:"h-3 w-3"})," Layout"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:M.zoomIn,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Zoom in","aria-label":"Zoom in",children:e.jsx(u.ZoomIn,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs tabular-nums min-w-[3ch] text-center","aria-label":"Zoom level",children:[Math.round(M.zoom*100),"%"]}),e.jsx("button",{onClick:M.zoomOut,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Zoom out","aria-label":"Zoom out",children:e.jsx(u.ZoomOut,{className:"h-3 w-3"})}),e.jsx("button",{onClick:M.resetZoom,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Reset zoom","aria-label":"Reset zoom",children:e.jsx(u.RotateCcw,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:()=>h("start-event","Start"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add Start Event","aria-label":"Add Start Event",children:[e.jsx(u.Play,{className:"h-3 w-3 text-green-600"})," Start"]}),e.jsxs("button",{onClick:()=>h("user-task","User Task"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add User Task","aria-label":"Add User Task",children:[e.jsx(u.Square,{className:"h-3 w-3 text-blue-600"})," Task"]}),e.jsxs("button",{onClick:()=>h("exclusive-gateway","Decision"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add Gateway","aria-label":"Add Gateway",children:[e.jsx(u.Diamond,{className:"h-3 w-3 text-yellow-600"})," Gateway"]}),e.jsxs("button",{onClick:()=>h("end-event","End"),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Add End Event","aria-label":"Add End Event",children:[e.jsx(u.Square,{className:"h-3 w-3 text-red-600"})," End"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:()=>ae(p=>!p),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:U?"Hide properties":"Show properties","aria-label":U?"Hide property panel":"Show property panel","aria-expanded":U,children:U?e.jsx(u.PanelRightClose,{className:"h-3 w-3"}):e.jsx(u.PanelRightOpen,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4",role:"region","aria-label":"Process canvas",onWheel:M.handleWheel,onMouseDown:M.startPan,children:e.jsxs("div",{className:"relative",style:{...M.transformStyle,width:r.width,minHeight:r.height,backgroundImage:r.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:r.showGrid?"20px 20px":void 0},onClick:N,onDrop:ee,onDragOver:re,children:[e.jsxs("svg",{className:"absolute inset-0 pointer-events-none",width:r.width,height:r.height,children:[e.jsx("defs",{children:e.jsx("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--foreground))"})})}),v.map(p=>{const I=g.find(et=>et.id===p.source),C=g.find(et=>et.id===p.target);if(!I||!C)return null;I.position.x+Ce/2;const X=I.position.y+Ae/2;C.position.x+Ce/2;const J=C.position.y+Ae/2,se=I.position.x+Ce,me=X,fe=C.position.x,Ne=J,Va=(se+fe)/2,Wa=`M ${se} ${me} Q ${Va} ${me}, ${(se+fe)/2} ${(me+Ne)/2} T ${fe} ${Ne}`;return e.jsxs("g",{children:[e.jsx("path",{d:Wa,fill:"none",stroke:"hsl(var(--foreground) / 0.5)",strokeWidth:"2",markerEnd:"url(#arrowhead)"}),p.label&&e.jsx("text",{x:(se+fe)/2,y:(me+Ne)/2-8,textAnchor:"middle",className:"text-[10px] fill-muted-foreground",children:p.label})]},p.id)})]}),g.length===0&&e.jsx("div",{className:"flex items-center justify-center h-full min-h-[200px] text-muted-foreground text-sm",children:"No nodes in the process. Use the toolbar buttons to add start events, tasks, gateways, and end events."}),g.map(p=>{const I=L.isSelected(p.id)||V===p.id,C=_===p.id,X=K===p.id,J=P||X;return e.jsxs("div",{className:"absolute select-none",style:{left:p.position.x,top:p.position.y},role:"group","aria-label":p.label,draggable:!f&&!P,onDragStart:se=>Y(se,p.id),onMouseEnter:()=>Q(p.id),onMouseLeave:()=>Q(null),onClick:se=>{E(p.id)||(se.shiftKey?L.toggle(p.id,!0):(D(p.id),L.selectOne(p.id)))},children:[e.jsx("div",{className:Ge("flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow",Qe(p.type),I&&"ring-2 ring-primary shadow-md",C&&"ring-2 ring-blue-400 shadow-lg",P&&!C&&"cursor-crosshair"),children:e.jsx("span",{className:Ge("text-xs font-medium",(p.type==="exclusive-gateway"||p.type==="parallel-gateway"||p.type==="inclusive-gateway"||p.type==="event-based-gateway")&&"-rotate-45"),children:p.label})}),J&&!f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{left:-6,top:Ae/2-6},title:"Input port",onClick:se=>{se.stopPropagation(),E(p.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{right:-6,top:Ae/2-6},title:"Output port",onClick:se=>{se.stopPropagation(),P?E(p.id):(j(!0),S(p.id))}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:Ce/2-6,top:-6},title:"Port",onClick:se=>{se.stopPropagation(),E(p.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:Ce/2-6,bottom:-6},title:"Port",onClick:se=>{se.stopPropagation(),E(p.id)}})]}),!f&&I&&!P&&e.jsx("button",{onClick:se=>{se.stopPropagation(),B(p.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":"Delete node",children:e.jsx(u.Trash2,{className:"h-3 w-3"})})]},p.id)}),o&&g.length>0&&e.jsx(Fe,{items:Re,canvasWidth:r.width??1400,canvasHeight:r.height??800,position:"bottom-right"})]})}),U&&!f&&e.jsx("div",{className:"w-64 border-l bg-background overflow-y-auto flex-shrink-0",role:"complementary","aria-label":"Property panel",children:e.jsx(Le,{title:oe?`Properties: ${oe.label}`:"Properties",fields:ce,onChange:Je})})]})]})}function xe(...t){return ie.twMerge(le.clsx(t))}const Z={untitledReport:"Untitled Report",reportCanvas:"Report canvas",properties:"Properties",propertiesPanel:"Properties panel",designerToolbar:"Report designer toolbar",selectElementPrompt:"Select an element to edit its properties",addElementsPrompt:"Add elements using the buttons above",addText:"Add Text",addField:"Add Field",addImage:"Add Image",addChart:"Add Chart",addTable:"Add Table",undo:"Undo",undoShortcut:"Undo (Ctrl+Z)",redo:"Redo",redoShortcut:"Redo (Ctrl+Shift+Z)",copy:"Copy",copyShortcut:"Copy (Ctrl+C)",paste:"Paste",pasteShortcut:"Paste (Ctrl+V)",deleteSelected:"Delete selected",deleteElement:"Delete element",deleteElementsTitle:"Delete elements",deleteElementMessage:t=>`Are you sure you want to delete ${t} element${t>1?"s":""}?`,collapsePanel:"Collapse panel",expandPanel:"Expand panel",collaborationConnected:"Connected",sectionHeader:"Report Header",sectionPageHeader:"Page Header",sectionGroupHeader:"Group Header",sectionDetail:"Detail",sectionGroupFooter:"Group Footer",sectionPageFooter:"Page Footer",sectionFooter:"Report Footer",elementText:"Text",elementImage:"🖼 Image",elementChart:"📊 Chart",elementTable:"📋 Table",propLabel:"Label",propX:"X",propY:"Y",propWidth:"Width",propHeight:"Height",propText:"Text",propField:"Field",groupPosition:"Position",groupSize:"Size",groupContent:"Content",groupGeneral:"General"},Xt={A4:{width:595,height:842},A3:{width:842,height:1191},Letter:{width:612,height:792},Legal:{width:612,height:1008},Tabloid:{width:792,height:1224}},qt=[{type:"header",height:80,elements:[]},{type:"detail",height:400,elements:[],repeat:!0},{type:"footer",height:60,elements:[]}];function dt({reportName:t=Z.untitledReport,objectName:s,pageSize:n="A4",orientation:i="portrait",margins:r={top:40,right:40,bottom:40,left:40},sections:o=[],showToolbar:c=!0,showPropertyPanel:f=!0,readOnly:b=!1,onSectionsChange:l,className:m}){const d=he(o.length>0?o:qt),g=d.current,v=a.useCallback(T=>{d.push(T),l?.(T)},[d,l]),x=Te(),w=a.useMemo(()=>{const T=Array.from(x.selectedIds);return T.length>0?T[0]:null},[x.selectedIds]),L=Pe(),A=we(),M=ze(),$=a.useCallback(T=>{M&&M.sendOperation({...T,userId:M.currentUserId??""})},[M]),[V,D]=a.useState(!0),P=a.useRef(null),j=a.useRef(null),_=Xt[n],S=i==="landscape"?_.height:_.width,K=i==="landscape"?_.width:_.height,Q=T=>{switch(T){case"header":return Z.sectionHeader;case"page-header":return Z.sectionPageHeader;case"group-header":return Z.sectionGroupHeader;case"detail":return Z.sectionDetail;case"group-footer":return Z.sectionGroupFooter;case"page-footer":return Z.sectionPageFooter;case"footer":return Z.sectionFooter;default:return T}},U=a.useMemo(()=>w?g.flatMap(T=>T.elements).find(T=>T.id===w):null,[w,g]),ae=a.useCallback((T,O)=>{if(b)return;const F={id:`elem-${Date.now()}`,type:O,position:{x:r.left,y:10,width:200,height:30},properties:{text:O==="text"?"New Text":void 0,field:O==="field"?"field_name":void 0}},y=g.map((E,H)=>H===T?{...E,elements:[...E.elements,F]}:E);v(y),x.selectOne(F.id),$({type:"insert",elementId:F.id,data:{element:F}})},[g,r.left,b,v,x,$]),ne=a.useCallback(T=>{if(b)return;const O=g.map(F=>({...F,elements:F.elements.filter(y=>y.id!==T)}));v(O),x.isSelected(T)&&x.clearSelection(),$({type:"delete",elementId:T,data:{}})},[g,b,v,x,$]),z=a.useCallback(async()=>{if(b||x.count===0||!await A.confirm(Z.deleteElementsTitle,Z.deleteElementMessage(x.count)))return;const O=x.selectedIds,F=g.map(y=>({...y,elements:y.elements.filter(E=>!O.has(E.id))}));v(F),x.clearSelection(),O.forEach(y=>{$({type:"delete",elementId:y,data:{}})})},[b,x,A,g,v,$]),R=a.useCallback((T,O)=>{if(b||!w)return;const F=g.map(y=>({...y,elements:y.elements.map(E=>E.id!==w?E:T==="x"?{...E,position:{...E.position,x:Number(O)}}:T==="y"?{...E,position:{...E.position,y:Number(O)}}:T==="width"?{...E,position:{...E.position,width:Number(O)}}:T==="height"?{...E,position:{...E.position,height:Number(O)}}:{...E,properties:{...E.properties,[T]:O}})}));v(F),$({type:"update",elementId:w,data:{[T]:O}})},[b,w,g,v,$]),q=a.useCallback(()=>{const T=x.selectedIds;if(T.size===0)return;const F=g.flatMap(y=>y.elements).filter(y=>T.has(y.id));L.copy(F)},[x,g,L]),k=a.useCallback(()=>{if(b)return;const T=L.paste();if(!T||T.length===0)return;let O=0;const F=T.map(Y=>({...Y,id:`elem-${Date.now()}-${++O}-${Math.random().toString(36).slice(2,7)}`,position:{...Y.position,x:Y.position.x+20,y:Y.position.y+20}})),y=g.findIndex(Y=>Y.type==="detail"),E=y>=0?y:0,H=g.map((Y,ee)=>ee===E?{...Y,elements:[...Y.elements,...F]}:Y);v(H),x.selectMany(F.map(Y=>Y.id)),F.forEach(Y=>{$({type:"insert",elementId:Y.id,data:{element:Y}})})},[b,L,g,v,x,$]),W=a.useCallback((T,O,F)=>{b||(P.current={id:O.id,sectionIndex:F,startX:T.clientX,startY:T.clientY},T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",O.id))},[b]),G=a.useCallback(T=>{T.preventDefault(),T.dataTransfer.dropEffect="move"},[]),h=a.useCallback((T,O)=>{T.preventDefault();const F=P.current;if(!F||b)return;const y=T.clientX-F.startX,E=T.clientY-F.startY;if(F.sectionIndex===O){const H=g.map((Y,ee)=>ee!==O?Y:{...Y,elements:Y.elements.map(re=>re.id!==F.id?re:{...re,position:{...re.position,x:Math.max(0,re.position.x+y),y:Math.max(0,(typeof re.position.y=="number"?re.position.y:0)+E)}})});v(H)}else{let H=null;const Y=g.map((ee,re)=>{if(re!==F.sectionIndex)return ee;const oe=ee.elements.find(ce=>ce.id===F.id);return oe&&(H={...oe,position:{...oe.position,x:Math.max(0,oe.position.x+y),y:Math.max(0,10)}}),{...ee,elements:ee.elements.filter(ce=>ce.id!==F.id)}});if(H){const ee=Y.map((re,oe)=>oe!==O?re:{...re,elements:[...re.elements,H]});v(ee)}}$({type:"move",elementId:F.id,data:{}}),P.current=null},[b,g,v,$]),B=a.useMemo(()=>{if(!U)return[];const T=[{name:"x",label:Z.propX,type:"number",value:U.position.x,group:Z.groupPosition},{name:"y",label:Z.propY,type:"number",value:U.position.y,group:Z.groupPosition},{name:"width",label:Z.propWidth,type:"number",value:U.position.width,group:Z.groupSize},{name:"height",label:Z.propHeight,type:"number",value:U.position.height,group:Z.groupSize}];return U.type==="text"&&T.push({name:"text",label:Z.propText,type:"text",value:U.properties.text??"",group:Z.groupContent}),U.type==="field"&&T.push({name:"field",label:Z.propField,type:"text",value:U.properties.field??"",group:Z.groupContent}),T},[U]);return a.useEffect(()=>{const T=j.current;if(!T)return;const O=F=>{const y=["INPUT","TEXTAREA","SELECT"].includes(F.target.tagName),E=F.ctrlKey||F.metaKey;if((F.key==="Delete"||F.key==="Backspace")&&x.count>0&&!y){F.preventDefault(),z();return}if(F.key==="Escape"){x.clearSelection();return}if(!y){if(E&&F.key==="z"&&!F.shiftKey&&!b){F.preventDefault(),d.undo();return}if(E&&(F.key==="z"&&F.shiftKey||F.key==="y")&&!b){F.preventDefault(),d.redo();return}if(E&&F.key==="c"){F.preventDefault(),q();return}if(E&&F.key==="v"&&!b){F.preventDefault(),k();return}if(E&&F.key==="a"){F.preventDefault();const H=g.flatMap(Y=>Y.elements).map(Y=>Y.id);x.selectMany(H);return}}};return T.addEventListener("keydown",O),()=>T.removeEventListener("keydown",O)},[x,z,b,d,q,k,g]),e.jsxs("div",{ref:j,tabIndex:0,className:xe("flex h-full w-full border rounded-lg overflow-hidden bg-background",m),children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[c&&e.jsxs("div",{role:"toolbar","aria-label":Z.designerToolbar,className:"flex items-center gap-2 p-2 border-b bg-muted/20",children:[e.jsx(u.FileText,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:t}),s&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s,")"]}),!b&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:xe("p-1.5 rounded hover:bg-accent",!d.canUndo&&"opacity-40 pointer-events-none"),title:Z.undoShortcut,"aria-label":Z.undo,disabled:!d.canUndo,onClick:()=>d.undo(),children:e.jsx(u.Undo2,{className:"h-4 w-4"})}),e.jsx("button",{className:xe("p-1.5 rounded hover:bg-accent",!d.canRedo&&"opacity-40 pointer-events-none"),title:Z.redoShortcut,"aria-label":Z.redo,disabled:!d.canRedo,onClick:()=>d.redo(),children:e.jsx(u.Redo2,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!b&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:xe("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:Z.copyShortcut,"aria-label":Z.copy,disabled:x.count===0,onClick:q,children:e.jsx(u.Copy,{className:"h-4 w-4"})}),e.jsx("button",{className:xe("p-1.5 rounded hover:bg-accent",!L.hasContent&&"opacity-40 pointer-events-none"),title:Z.pasteShortcut,"aria-label":Z.paste,disabled:!L.hasContent,onClick:k,children:e.jsx(u.Clipboard,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!b&&e.jsx("button",{className:xe("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:Z.deleteSelected,"aria-label":Z.deleteSelected,disabled:x.count===0,onClick:z,children:e.jsx(u.Trash2,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),M?.isConnected&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),Z.collaborationConnected,M.users.length>1&&` (${M.users.length})`]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[n," ",i]}),f&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:V?Z.collapsePanel:Z.expandPanel,"aria-label":V?Z.collapsePanel:Z.expandPanel,onClick:()=>D(T=>!T),children:e.jsx(u.PanelRightClose,{className:xe("h-4 w-4",!V&&"rotate-180")})})]}),e.jsx("div",{role:"region","aria-label":Z.reportCanvas,className:"flex-1 overflow-auto bg-muted/10 p-4 flex justify-center",children:e.jsx("div",{className:"bg-white shadow-lg border",style:{width:S,minHeight:K},children:g.map((T,O)=>e.jsxs("div",{className:"relative border-b border-dashed border-gray-300",style:{minHeight:T.height},onDragOver:G,onDrop:F=>h(F,O),children:[e.jsxs("div",{className:"absolute left-0 top-0 px-2 py-0.5 bg-muted text-xs text-muted-foreground border-r border-b rounded-br",children:[Q(T.type),T.repeat&&" ↻"]}),!b&&e.jsxs("div",{className:"absolute right-1 top-0 flex items-center gap-0.5",children:[e.jsx("button",{onClick:()=>ae(O,"text"),className:"p-0.5 rounded hover:bg-accent",title:Z.addText,"aria-label":Z.addText,children:e.jsx(u.Type,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>ae(O,"field"),className:"p-0.5 rounded hover:bg-accent",title:Z.addField,"aria-label":Z.addField,children:e.jsx(u.Plus,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>ae(O,"image"),className:"p-0.5 rounded hover:bg-accent",title:Z.addImage,"aria-label":Z.addImage,children:e.jsx(u.ImageIcon,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>ae(O,"chart"),className:"p-0.5 rounded hover:bg-accent",title:Z.addChart,"aria-label":Z.addChart,children:e.jsx(u.BarChart3,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>ae(O,"table"),className:"p-0.5 rounded hover:bg-accent",title:Z.addTable,"aria-label":Z.addTable,children:e.jsx(u.Table2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"relative",style:{minHeight:T.height,paddingTop:24},children:[T.elements.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground text-center pt-4",children:Z.addElementsPrompt}),T.elements.map(F=>{const y=x.isSelected(F.id);return e.jsxs("div",{draggable:!b,onDragStart:E=>W(E,F,O),className:xe("absolute border rounded px-2 py-1 text-xs cursor-pointer",y?"border-primary ring-1 ring-primary/30 bg-primary/5":"border-dashed border-gray-400 hover:border-primary/50"),style:{left:F.position.x,top:(typeof F.position.y=="number"?F.position.y:0)+24,width:F.position.width,height:F.position.height},onClick:E=>x.toggle(F.id,E.shiftKey),children:[e.jsxs("span",{className:"text-muted-foreground",children:[F.type==="text"&&(F.properties.text??Z.elementText),F.type==="field"&&`{${F.properties.field??"field"}}`,F.type==="image"&&Z.elementImage,F.type==="chart"&&Z.elementChart,F.type==="table"&&Z.elementTable]}),!b&&y&&e.jsx("button",{onClick:E=>{E.stopPropagation(),ne(F.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":Z.deleteElement,children:e.jsx(u.Trash2,{className:"h-2.5 w-2.5"})})]},F.id)})]})]},`${T.type}-${O}`))})})]}),f&&e.jsx("div",{role:"region","aria-label":Z.propertiesPanel,className:xe("border-l bg-muted/30 flex flex-col transition-[width] duration-200",V?"w-56":"w-0 overflow-hidden"),children:V&&(w&&U?e.jsx(Le,{title:`${Z.properties} – ${U.type}`,fields:B,onChange:R}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:Z.properties}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3",children:e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:Z.selectElementPrompt})})]}))}),e.jsx(Ie,{isOpen:A.isOpen,title:A.title,message:A.message,onConfirm:A.onConfirm,onCancel:A.onCancel})]})}const Jt=(t,s,n,i)=>{const r=[n,{code:s,...i||{}}];if(t?.services?.logger?.forward)return t.services.logger.forward(r,"warn","react-i18next::",!0);ve(r[0])&&(r[0]=`react-i18next:: ${r[0]}`),t?.services?.logger?.warn?t.services.logger.warn(...r):console?.warn&&console.warn(...r)},ct={},ut=(t,s,n,i)=>{ve(n)&&ct[n]||(ve(n)&&(ct[n]=new Date),Jt(t,s,n,i))},pt=(t,s)=>()=>{if(t.isInitialized)s();else{const n=()=>{setTimeout(()=>{t.off("initialized",n)},0),s()};t.on("initialized",n)}},Be=(t,s,n)=>{t.loadNamespaces(s,pt(t,n))},mt=(t,s,n,i)=>{if(ve(n)&&(n=[n]),t.options.preload&&t.options.preload.indexOf(s)>-1)return Be(t,n,i);n.forEach(r=>{t.options.ns.indexOf(r)<0&&t.options.ns.push(r)}),t.loadLanguages(s,pt(t,i))},Qt=(t,s,n={})=>!s.languages||!s.languages.length?(ut(s,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:s.languages}),!0):s.hasLoadedNamespace(t,{lng:n.lng,precheck:(i,r)=>{if(n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&i.services.backendConnector.backend&&i.isLanguageChangingTo&&!r(i.isLanguageChangingTo,t))return!1}}),ve=t=>typeof t=="string",Rt=t=>typeof t=="object"&&t!==null,ea=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,ta={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'," ":" "," ":" ","©":"©","©":"©","®":"®","®":"®","…":"…","…":"…","/":"/","/":"/"},aa=t=>ta[t];let sa={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:t=>t.replace(ea,aa),transDefaultProps:void 0};const ra=()=>sa;let na;const oa=()=>na,la=a.createContext();class ia{constructor(){this.usedNamespaces={}}addUsedNamespaces(s){s.forEach(n=>{this.usedNamespaces[n]||(this.usedNamespaces[n]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}var Ke={exports:{}},Ye={};var gt;function da(){if(gt)return Ye;gt=1;var t=a;function s(d,g){return d===g&&(d!==0||1/d===1/g)||d!==d&&g!==g}var n=typeof Object.is=="function"?Object.is:s,i=t.useState,r=t.useEffect,o=t.useLayoutEffect,c=t.useDebugValue;function f(d,g){var v=g(),x=i({inst:{value:v,getSnapshot:g}}),w=x[0].inst,L=x[1];return o(function(){w.value=v,w.getSnapshot=g,b(w)&&L({inst:w})},[d,v,g]),r(function(){return b(w)&&L({inst:w}),d(function(){b(w)&&L({inst:w})})},[d]),c(v),v}function b(d){var g=d.getSnapshot;d=d.value;try{var v=g();return!n(d,v)}catch{return!0}}function l(d,g){return g()}var m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?l:f;return Ye.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:m,Ye}var Ze={};var xt;function ca(){return xt||(xt=1,process.env.NODE_ENV!=="production"&&(function(){function t(v,x){return v===x&&(v!==0||1/v===1/x)||v!==v&&x!==x}function s(v,x){m||r.startTransition===void 0||(m=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var w=x();if(!d){var L=x();o(w,L)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),d=!0)}L=c({inst:{value:w,getSnapshot:x}});var A=L[0].inst,M=L[1];return b(function(){A.value=w,A.getSnapshot=x,n(A)&&M({inst:A})},[v,w,x]),f(function(){return n(A)&&M({inst:A}),v(function(){n(A)&&M({inst:A})})},[v]),l(w),w}function n(v){var x=v.getSnapshot;v=v.value;try{var w=x();return!o(v,w)}catch{return!0}}function i(v,x){return x()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=a,o=typeof Object.is=="function"?Object.is:t,c=r.useState,f=r.useEffect,b=r.useLayoutEffect,l=r.useDebugValue,m=!1,d=!1,g=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?i:s;Ze.useSyncExternalStore=r.useSyncExternalStore!==void 0?r.useSyncExternalStore:g,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),Ze}var bt;function ua(){return bt||(bt=1,process.env.NODE_ENV==="production"?Ke.exports=da():Ke.exports=ca()),Ke.exports}var pa=ua();const ma={t:(t,s)=>ve(s)?s:Rt(s)&&ve(s.defaultValue)?s.defaultValue:Array.isArray(t)?t[t.length-1]:t,ready:!1},ga=()=>()=>{},xa=(t,s={})=>{const{i18n:n}=s,{i18n:i,defaultNS:r}=a.useContext(la)||{},o=n||i||oa();o&&!o.reportNamespaces&&(o.reportNamespaces=new ia),o||ut(o,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const c=a.useMemo(()=>({...ra(),...o?.options?.react,...s}),[o,s]),{useSuspense:f,keyPrefix:b}=c,l=r||o?.options?.defaultNS,m=ve(l)?[l]:l||["translation"],d=a.useMemo(()=>m,m);o?.reportNamespaces?.addUsedNamespaces?.(d);const g=a.useRef(0),v=a.useCallback(S=>{if(!o)return ga;const{bindI18n:K,bindI18nStore:Q}=c,U=()=>{g.current+=1,S()};return K&&o.on(K,U),Q&&o.store.on(Q,U),()=>{K&&K.split(" ").forEach(ae=>o.off(ae,U)),Q&&Q.split(" ").forEach(ae=>o.store.off(ae,U))}},[o,c]),x=a.useRef(),w=a.useCallback(()=>{if(!o)return ma;const S=!!(o.isInitialized||o.initializedStoreOnce)&&d.every(z=>Qt(z,o,c)),K=s.lng||o.language,Q=g.current,U=x.current;if(U&&U.ready===S&&U.lng===K&&U.keyPrefix===b&&U.revision===Q)return U;const ne={t:o.getFixedT(K,c.nsMode==="fallback"?d:d[0],b),ready:S,lng:K,keyPrefix:b,revision:Q};return x.current=ne,ne},[o,d,b,c,s.lng]),[L,A]=a.useState(0),{t:M,ready:$}=pa.useSyncExternalStore(v,w,w);a.useEffect(()=>{if(o&&!$&&!f){const S=()=>A(K=>K+1);s.lng?mt(o,s.lng,d,S):Be(o,d,S)}},[o,s.lng,d,$,f,L]);const V=o||{},D=a.useRef(null),P=a.useRef(),j=S=>{const K=Object.getOwnPropertyDescriptors(S);K.__original&&delete K.__original;const Q=Object.create(Object.getPrototypeOf(S),K);if(!Object.prototype.hasOwnProperty.call(Q,"__original"))try{Object.defineProperty(Q,"__original",{value:S,writable:!1,enumerable:!1,configurable:!1})}catch{}return Q},_=a.useMemo(()=>{const S=V,K=S?.language;let Q=S;S&&(D.current&&D.current.__original===S?P.current!==K?(Q=j(S),D.current=Q,P.current=K):Q=D.current:(Q=j(S),D.current=Q,P.current=K));const U=[M,Q,$];return U.t=M,U.i18n=Q,U.ready=$,U},[M,V,$,V.resolvedLanguage,V.language,V.languages]);if(o&&f&&!$)throw new Promise(S=>{const K=()=>S();s.lng?mt(o,s.lng,d,K):Be(o,d,K)});return _},ba=a.createContext(null);function ha(t){const s=a.useContext(ba),{t:n,i18n:i}=xa();return{t:n,language:s?.language||i.language||"en",changeLanguage:s?.changeLanguage||(async r=>{await i.changeLanguage(r)}),direction:s?.direction||"ltr",i18n:i}}const ht={"appDesigner.basicInfo":"Basic Info","appDesigner.objects":"Objects","appDesigner.navigation":"Navigation","appDesigner.branding":"Branding","appDesigner.stepBasicDesc":"Name, title, and layout","appDesigner.stepObjectsDesc":"Select business objects","appDesigner.stepNavigationDesc":"Build navigation tree","appDesigner.stepBrandingDesc":"Logo, colors, and favicon","appDesigner.appName":"App Name","appDesigner.appTitle":"Title","appDesigner.appDescription":"Description","appDesigner.appIcon":"Icon","appDesigner.template":"Template","appDesigner.layout":"Layout","appDesigner.layoutSidebar":"Sidebar","appDesigner.layoutHeader":"Header","appDesigner.layoutEmpty":"Empty","appDesigner.snakeCaseHint":"Must be snake_case (e.g. my_app)","appDesigner.searchObjects":"Search objects…","appDesigner.selectAll":"Select All","appDesigner.deselectAll":"Deselect All","appDesigner.noObjectsFound":"No objects found.","appDesigner.addGroup":"Add Group","appDesigner.addUrl":"Add URL","appDesigner.addSeparator":"Add Separator","appDesigner.noNavItemsHint":"No navigation items yet. Select objects in the previous step or add items manually.","appDesigner.separatorLabel":"— Separator —","appDesigner.newGroup":"New Group","appDesigner.newLink":"New Link","appDesigner.logoUrl":"Logo URL","appDesigner.primaryColor":"Primary Color","appDesigner.faviconUrl":"Favicon URL","appDesigner.preview":"Preview","common.cancel":"Cancel","common.back":"Back","common.next":"Next","common.close":"Close","appDesigner.complete":"Complete","appDesigner.saveDraft":"Save Draft","appDesigner.cancelConfirmTitle":"Discard changes?","appDesigner.cancelConfirmMessage":"You have unsaved changes. Are you sure you want to cancel?","appDesigner.confirmDiscard":"Discard","appDesigner.keepEditing":"Keep Editing","appDesigner.navNoItems":"No navigation items. Click buttons above to add items.","appDesigner.navNoPreviewItems":"No items","appDesigner.navLivePreview":"Live Preview","appDesigner.navCollapseGroup":"Collapse group","appDesigner.navExpandGroup":"Expand group","appDesigner.navAddChild":"Add child","appDesigner.navMoveUp":"Move up","appDesigner.navMoveDown":"Move down","appDesigner.navRemove":"Remove","appDesigner.navObjectPage":"Object Page","appDesigner.navDashboard":"Dashboard","appDesigner.navPage":"Page","appDesigner.navReport":"Report","appDesigner.navGroup":"Group","appDesigner.navUrl":"URL","appDesigner.navSeparator":"Separator","appDesigner.navTypeObject":"Object","appDesigner.navTypeDashboard":"Dashboard","appDesigner.navTypePage":"Page","appDesigner.navTypeReport":"Report","appDesigner.navTypeUrl":"URL","appDesigner.navTypeGroup":"Group","appDesigner.navTypeSeparator":"Separator","appDesigner.navTypeAction":"Action","appDesigner.navEditIcon":"Edit icon","appDesigner.navToggleVisible":"Toggle visibility","appDesigner.navHidden":"Hidden","appDesigner.navExportSchema":"Export JSON","appDesigner.navImportSchema":"Import JSON","appDesigner.navExportSuccess":"Navigation schema exported","appDesigner.navImportSuccess":"Navigation schema imported","appDesigner.navImportError":"Invalid navigation JSON","appDesigner.navIconPlaceholder":"Icon name (e.g. Users)","appDesigner.dashboardEditor":"Dashboard Editor","appDesigner.noWidgets":"No widgets. Click a button above to add one.","appDesigner.widgetLayoutSize":"Layout Size","appDesigner.widgetWidth":"Width","appDesigner.widgetHeight":"Height","appDesigner.dashboardPreview":"Dashboard Preview","appDesigner.noWidgetsPreview":"No widgets to preview","appDesigner.pageCanvasEditor":"Page Canvas Editor","appDesigner.emptyPage":"Empty page. Click a button above to add a component.","appDesigner.pagePreview":"Page Preview","appDesigner.noComponentsPreview":"No components to preview","appDesigner.modePage":"Page","appDesigner.modeDashboard":"Dashboard","appDesigner.undo":"Undo","appDesigner.redo":"Redo","appDesigner.brandingEditor":"Branding Editor","appDesigner.brandingExport":"Export JSON","appDesigner.brandingImport":"Import JSON","appDesigner.brandingPreview":"Preview","appDesigner.brandingSampleButton":"Sample Button","appDesigner.brandingSampleText":"This is how your brand theme will look.","appDesigner.colorPalette":"Color Palette","appDesigner.fontFamily":"Font Family","appDesigner.fontDefault":"Default (System)","appDesigner.modeLight":"Light","appDesigner.modeDark":"Dark","appDesigner.mobilePreview":"Mobile Preview"};function ft(t){return(s,n)=>{let i=t[s]||s;if(n)for(const[r,o]of Object.entries(n))i=i.replace(`{{${r}}}`,String(o));return i}}function be(){try{const t=ha();return t.t("appDesigner.basicInfo")==="appDesigner.basicInfo"?{t:ft(ht)}:{t:t.t}}catch{return{t:ft(ht)}}}function ge(...t){return ie.twMerge(le.clsx(t))}const fa={name:"",title:"",description:"",icon:"",template:"",layout:"sidebar",objects:[],navigation:[],branding:{logo:"",primaryColor:"#3b82f6",favicon:""}};function yt(t){return t.filter(s=>s.selected).map(s=>({id:s.name,type:"object",label:s.label,icon:s.icon,objectName:s.name}))}let vt=0;function ya(t){return vt+=1,`${t}_${Date.now()}_${vt}`}function va({steps:t,currentIndex:s,onStepClick:n}){return e.jsx("nav",{className:"flex items-center justify-center gap-0 px-4 py-6",children:t.map((i,r)=>{const o=r<s,c=r===s;return e.jsxs(a.Fragment,{children:[r>0&&e.jsx("div",{className:ge("h-0.5 w-12 sm:w-20",o?"bg-blue-500":"bg-gray-200")}),e.jsxs("button",{type:"button","data-testid":`wizard-step-${i.id}`,onClick:()=>n(r),className:ge("flex flex-col items-center gap-1 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg px-2 py-1",c&&"cursor-default",!c&&"cursor-pointer"),children:[e.jsx("div",{className:ge("flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold transition-colors",o&&"bg-blue-500 text-white",c&&"bg-blue-600 text-white ring-2 ring-blue-300",!o&&!c&&"bg-gray-200 text-gray-500"),children:o?e.jsx(u.Check,{className:"h-4 w-4"}):r+1}),e.jsx("span",{className:ge("text-xs font-medium",c?"text-blue-600":"text-gray-500"),children:i.label})]})]},i.id)})})}function ja({draft:t,templates:s,readOnly:n,onChange:i,t:r}){const o=t.name.length>0&&!tt.isValidAppName(t.name);return e.jsxs("div",{"data-testid":"wizard-step-basic-content",className:"mx-auto max-w-lg space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{htmlFor:"app-name",className:"block text-sm font-medium text-gray-700",children:[r("appDesigner.appName")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{id:"app-name","data-testid":"app-name-input",type:"text",value:t.name,onChange:c=>i({name:c.target.value}),placeholder:"my_app",disabled:n,className:ge("block w-full rounded-md border px-3 py-2 text-sm shadow-sm outline-none transition-colors","focus:border-blue-500 focus:ring-1 focus:ring-blue-500","disabled:cursor-not-allowed disabled:bg-gray-50",o?"border-red-400":"border-gray-300")}),o&&e.jsx("p",{className:"text-xs text-red-500",children:r("appDesigner.snakeCaseHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{htmlFor:"app-title",className:"block text-sm font-medium text-gray-700",children:[r("appDesigner.appTitle")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{id:"app-title","data-testid":"app-title-input",type:"text",value:t.title,onChange:c=>i({title:c.target.value}),placeholder:"My Application",disabled:n,className:"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"app-description",className:"block text-sm font-medium text-gray-700",children:r("appDesigner.appDescription")}),e.jsx("textarea",{id:"app-description","data-testid":"app-description-input",value:t.description??"",onChange:c=>i({description:c.target.value}),rows:3,disabled:n,className:"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 resize-none"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"app-icon",className:"block text-sm font-medium text-gray-700",children:r("appDesigner.appIcon")}),e.jsx("input",{id:"app-icon",type:"text",value:t.icon??"",onChange:c=>i({icon:c.target.value}),placeholder:"LayoutDashboard",disabled:n,className:"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]}),s.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"app-template",className:"block text-sm font-medium text-gray-700",children:r("appDesigner.template")}),e.jsxs("select",{id:"app-template",value:t.template??"",onChange:c=>i({template:c.target.value}),disabled:n,className:"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50",children:[e.jsx("option",{value:"",children:"None"}),s.map(c=>e.jsx("option",{value:c.id,children:c.label},c.id))]})]}),e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium text-gray-700",children:r("appDesigner.layout")}),e.jsx("div",{className:"flex gap-3",children:[{value:"sidebar",labelKey:"appDesigner.layoutSidebar",Icon:u.PanelLeft},{value:"header",labelKey:"appDesigner.layoutHeader",Icon:u.Layout},{value:"empty",labelKey:"appDesigner.layoutEmpty",Icon:u.LayoutTemplate}].map(({value:c,labelKey:f,Icon:b})=>e.jsxs("label",{"data-testid":`app-layout-${c}`,className:ge("flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-lg border-2 p-3 transition-colors",t.layout===c?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300",n&&"pointer-events-none opacity-60"),children:[e.jsx(b,{className:"h-5 w-5 text-gray-600"}),e.jsx("span",{className:"text-xs font-medium text-gray-700",children:r(f)}),e.jsx("input",{type:"radio",name:"layout",value:c,checked:t.layout===c,onChange:()=>i({layout:c}),disabled:n,className:"sr-only"})]},c))})]})]})}function Na({objects:t,readOnly:s,onToggle:n,onToggleAll:i,search:r,onSearchChange:o,t:c}){const f=a.useMemo(()=>{if(!r)return t;const l=r.toLowerCase();return t.filter(m=>m.name.toLowerCase().includes(l)||m.label.toLowerCase().includes(l))},[t,r]),b=t.length>0&&t.every(l=>l.selected);return t.every(l=>!l.selected),e.jsxs("div",{"data-testid":"wizard-step-objects-content",className:"mx-auto max-w-2xl space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(u.Search,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{"data-testid":"object-search",type:"text",value:r,onChange:l=>o(l.target.value),placeholder:c("appDesigner.searchObjects"),className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500"})]}),e.jsx("button",{type:"button",onClick:()=>i(!b),disabled:s,className:"rounded-md border border-gray-300 px-3 py-2 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:c(b?"appDesigner.deselectAll":"appDesigner.selectAll")})]}),f.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-gray-400",children:c("appDesigner.noObjectsFound")}):e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3",children:f.map(l=>e.jsxs("button",{type:"button","data-testid":`object-card-${l.name}`,disabled:s,onClick:()=>n(l.name),className:ge("flex flex-col items-start gap-1 rounded-lg border-2 p-3 text-left transition-colors",l.selected?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300",s&&"pointer-events-none opacity-60"),children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-gray-800",children:l.label}),e.jsx("div",{className:ge("flex h-5 w-5 items-center justify-center rounded border transition-colors",l.selected?"border-blue-500 bg-blue-500 text-white":"border-gray-300"),children:l.selected&&e.jsx(u.Check,{className:"h-3 w-3"})})]}),e.jsx("span",{className:"text-xs text-gray-500",children:l.name}),l.icon&&e.jsx("span",{className:"text-xs text-gray-400",children:l.icon})]},l.name))})]})}const wa={object:"bg-green-100 text-green-700",group:"bg-purple-100 text-purple-700",url:"bg-sky-100 text-sky-700",separator:"bg-gray-100 text-gray-600",dashboard:"bg-amber-100 text-amber-700",page:"bg-teal-100 text-teal-700",report:"bg-rose-100 text-rose-700",action:"bg-orange-100 text-orange-700"};function Ca({items:t,readOnly:s,onAdd:n,onRemove:i,onReorder:r,t:o}){return e.jsxs("div",{"data-testid":"wizard-step-navigation-content",className:"mx-auto max-w-lg space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button","data-testid":"add-group-btn",onClick:()=>n("group"),disabled:s,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(u.FolderOpen,{className:"h-3.5 w-3.5"}),o("appDesigner.addGroup")]}),e.jsxs("button",{type:"button","data-testid":"add-url-btn",onClick:()=>n("url"),disabled:s,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(u.Link,{className:"h-3.5 w-3.5"}),o("appDesigner.addUrl")]}),e.jsxs("button",{type:"button","data-testid":"add-separator-btn",onClick:()=>n("separator"),disabled:s,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(u.Minus,{className:"h-3.5 w-3.5"}),o("appDesigner.addSeparator")]})]}),t.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-gray-400",children:o("appDesigner.noNavItemsHint")}):e.jsx("ul",{className:"space-y-1.5",children:t.map((c,f)=>e.jsxs("li",{"data-testid":`nav-item-${c.id}`,className:"flex items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2",children:[c.icon&&e.jsx("span",{className:"text-xs text-gray-400",children:c.icon}),e.jsx("span",{className:"flex-1 truncate text-sm text-gray-800",children:c.type==="separator"?o("appDesigner.separatorLabel"):ye.resolveI18nLabel(c.label)}),e.jsx("span",{className:ge("rounded-full px-2 py-0.5 text-[10px] font-medium",wa[c.type]??"bg-gray-100 text-gray-600"),children:c.type}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{type:"button",onClick:()=>r(c.id,"up"),disabled:s||f===0,className:"rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30","aria-label":"Move up",children:e.jsx(u.ChevronUp,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>r(c.id,"down"),disabled:s||f===t.length-1,className:"rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30","aria-label":"Move down",children:e.jsx(u.ChevronDown,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>i(c.id),disabled:s,className:"rounded p-0.5 text-gray-400 transition-colors hover:text-red-500 disabled:opacity-30","aria-label":"Remove",children:e.jsx(u.Trash2,{className:"h-3.5 w-3.5"})})]})]},c.id))})]})}function ka({branding:t,title:s,readOnly:n,onChange:i,t:r}){return e.jsxs("div",{"data-testid":"wizard-step-branding-content",className:"mx-auto max-w-lg space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"branding-logo",className:"block text-sm font-medium text-gray-700",children:r("appDesigner.logoUrl")}),e.jsxs("div",{className:"relative",children:[e.jsx(u.Image,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{id:"branding-logo","data-testid":"branding-logo-input",type:"text",value:t.logo??"",onChange:o=>i({logo:o.target.value}),placeholder:"https://example.com/logo.svg",disabled:n,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"branding-color",className:"block text-sm font-medium text-gray-700",children:r("appDesigner.primaryColor")}),e.jsxs("div",{className:"relative",children:[e.jsx(u.Palette,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{id:"branding-color","data-testid":"branding-color-input",type:"text",value:t.primaryColor??"#3b82f6",onChange:o=>i({primaryColor:o.target.value}),placeholder:"#3b82f6",disabled:n,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"branding-favicon",className:"block text-sm font-medium text-gray-700",children:r("appDesigner.faviconUrl")}),e.jsxs("div",{className:"relative",children:[e.jsx(u.Globe,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{id:"branding-favicon","data-testid":"branding-favicon-input",type:"text",value:t.favicon??"",onChange:o=>i({favicon:o.target.value}),placeholder:"https://example.com/favicon.ico",disabled:n,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"block text-sm font-medium text-gray-700",children:r("appDesigner.preview")}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.logo?e.jsx("img",{src:t.logo,alt:"App logo",className:"h-8 w-8 rounded object-contain"}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400",children:"Logo"}),e.jsx("span",{className:"text-sm font-semibold text-gray-800",children:s||r("appDesigner.appTitle")})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 rounded-full border border-gray-200",style:{backgroundColor:t.primaryColor||"#3b82f6"}}),e.jsx("span",{className:"text-xs text-gray-500",children:t.primaryColor||"#3b82f6"})]}),t.favicon&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("img",{src:t.favicon,alt:"Favicon",className:"h-4 w-4 rounded object-contain"}),e.jsx("span",{className:"text-xs text-gray-500",children:"Favicon"})]})]})]})]})}function jt({availableObjects:t=[],templates:s=[],initialDraft:n,onComplete:i,onCancel:r,onSaveDraft:o,readOnly:c=!1,className:f}){const{t:b}=be(),l=we(),[m,d]=a.useState(0),[g,v]=a.useState(""),[x,w]=a.useState(()=>({...fa,objects:t.map(k=>({...k})),...n})),L=a.useMemo(()=>[{id:"basic",label:b("appDesigner.basicInfo"),description:b("appDesigner.stepBasicDesc"),icon:"Settings"},{id:"objects",label:b("appDesigner.objects"),description:b("appDesigner.stepObjectsDesc"),icon:"Database"},{id:"navigation",label:b("appDesigner.navigation"),description:b("appDesigner.stepNavigationDesc"),icon:"Menu"},{id:"branding",label:b("appDesigner.branding"),description:b("appDesigner.stepBrandingDesc"),icon:"Palette"}],[b]),A=m===0,M=m===L.length-1,$=a.useMemo(()=>x.name.length>0&&tt.isValidAppName(x.name)&&x.title.trim().length>0,[x.name,x.title]),V=a.useMemo(()=>m===0?$:!0,[m,$]),D=a.useCallback(k=>{w(W=>({...W,...k}))},[]),P=a.useCallback(k=>{w(W=>({...W,branding:{...W.branding,...k}}))},[]),j=a.useCallback(k=>{w(W=>({...W,objects:W.objects.map(G=>G.name===k?{...G,selected:!G.selected}:G)}))},[]),_=a.useCallback(k=>{w(W=>({...W,objects:W.objects.map(G=>({...G,selected:k}))}))},[]),S=a.useCallback(k=>{const W={id:ya(k),type:k,label:k==="separator"?"":k==="group"?"New Group":"New Link",...k==="group"?{children:[]}:{},...k==="url"?{url:""}:{}};w(G=>({...G,navigation:[...G.navigation,W]}))},[]),K=a.useCallback(k=>{w(W=>({...W,navigation:W.navigation.filter(G=>G.id!==k)}))},[]),Q=a.useCallback((k,W)=>{w(G=>{const h=[...G.navigation],B=h.findIndex(O=>O.id===k);if(B<0)return G;const T=W==="up"?B-1:B+1;return T<0||T>=h.length?G:([h[B],h[T]]=[h[T],h[B]],{...G,navigation:h})})},[]),U=a.useCallback(()=>{M||(m===1&&w(k=>({...k,navigation:yt(k.objects)})),d(k=>k+1))},[m,M]),ae=a.useCallback(()=>{A||d(k=>k-1)},[A]),ne=a.useCallback(()=>{i?.(x)},[x,i]),z=a.useCallback(async()=>{(x.name.length>0||x.title.length>0)&&r?await l.confirm(b("appDesigner.cancelConfirmTitle"),b("appDesigner.cancelConfirmMessage"))&&r():r?.()},[x.name,x.title,r,l,b]),R=a.useCallback(()=>{o?.(x)},[x,o]),q=a.useCallback(k=>{k<=m?d(k):k===m+1&&V&&(m===1&&k===2&&w(W=>({...W,navigation:yt(W.objects)})),d(k))},[m,V]);return e.jsxs("div",{className:ge("flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm",f),children:[l.isOpen&&e.jsx("div",{"data-testid":"cancel-confirm-dialog",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:l.title}),e.jsx("button",{type:"button",onClick:l.onCancel,className:"rounded p-1 text-gray-400 hover:text-gray-600","aria-label":b("common.close"),children:e.jsx(u.X,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:l.message}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button","data-testid":"cancel-confirm-keep",onClick:l.onCancel,className:"rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50",children:b("appDesigner.keepEditing")}),e.jsx("button",{type:"button","data-testid":"cancel-confirm-discard",onClick:l.onConfirm,className:"rounded-md bg-red-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-700",children:b("appDesigner.confirmDiscard")})]})]})}),e.jsx("div",{className:"border-b border-gray-100",children:e.jsx(va,{steps:L,currentIndex:m,onStepClick:q})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[m===0&&e.jsx(ja,{draft:x,templates:s,readOnly:c,onChange:D,t:b}),m===1&&e.jsx(Na,{objects:x.objects,readOnly:c,onToggle:j,onToggleAll:_,search:g,onSearchChange:v,t:b}),m===2&&e.jsx(Ca,{items:x.navigation,readOnly:c,onAdd:S,onRemove:K,onReorder:Q,t:b}),m===3&&e.jsx(ka,{branding:x.branding,title:x.title,readOnly:c,onChange:P,t:b})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-100 px-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button","data-testid":"wizard-cancel",onClick:z,disabled:c,className:"rounded-md px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",children:b("common.cancel")}),o&&e.jsx("button",{type:"button","data-testid":"wizard-save-draft",onClick:R,disabled:c,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:b("appDesigner.saveDraft")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!A&&e.jsxs("button",{type:"button","data-testid":"wizard-back",onClick:ae,disabled:c,className:"inline-flex items-center gap-1 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(u.ChevronLeft,{className:"h-4 w-4"}),b("common.back")]}),M?e.jsxs("button",{type:"button","data-testid":"wizard-complete",onClick:ne,disabled:c||!V,className:"inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(u.Check,{className:"h-4 w-4"}),b("appDesigner.complete")]}):e.jsxs("button",{type:"button","data-testid":"wizard-next",onClick:U,disabled:c||!V,className:"inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50",children:[b("common.next"),e.jsx(u.ChevronRight,{className:"h-4 w-4"})]})]})]})]})}function ke(...t){return ie.twMerge(le.clsx(t))}let Nt=0;function wt(t){return Nt+=1,`${t}_${Date.now()}_${Nt}`}const _e={object:{labelKey:"appDesigner.navTypeObject",color:"bg-green-100 text-green-700",Icon:u.Database},dashboard:{labelKey:"appDesigner.navTypeDashboard",color:"bg-amber-100 text-amber-700",Icon:u.LayoutDashboard},page:{labelKey:"appDesigner.navTypePage",color:"bg-teal-100 text-teal-700",Icon:u.FileText},report:{labelKey:"appDesigner.navTypeReport",color:"bg-rose-100 text-rose-700",Icon:u.BarChart3},url:{labelKey:"appDesigner.navTypeUrl",color:"bg-sky-100 text-sky-700",Icon:u.Link},group:{labelKey:"appDesigner.navTypeGroup",color:"bg-purple-100 text-purple-700",Icon:u.FolderOpen},separator:{labelKey:"appDesigner.navTypeSeparator",color:"bg-gray-100 text-gray-600",Icon:u.Minus},action:{labelKey:"appDesigner.navTypeAction",color:"bg-orange-100 text-orange-700",Icon:u.MousePointerClick}},Da=[{type:"object",labelKey:"appDesigner.navObjectPage"},{type:"dashboard",labelKey:"appDesigner.navDashboard"},{type:"page",labelKey:"appDesigner.navPage"},{type:"report",labelKey:"appDesigner.navReport"},{type:"group",labelKey:"appDesigner.navGroup"},{type:"url",labelKey:"appDesigner.navUrl"},{type:"separator",labelKey:"appDesigner.navSeparator"}];function Ct({item:t,depth:s,index:n,total:i,readOnly:r,onRemove:o,onMoveUp:c,onMoveDown:f,onToggleExpand:b,onUpdateLabel:l,onUpdateIcon:m,onToggleVisible:d,onAddChild:g,expandedIds:v,t:x}){const[w,L]=a.useState(!1),[A,M]=a.useState(ye.resolveI18nLabel(t.label)??""),[$,V]=a.useState(!1),[D,P]=a.useState(t.icon||""),j=_e[t.type];t.type==="group"&&t.children&&t.children.length>0;const _=v.has(t.id),S=t.visible===!1,K=()=>{A.trim()?l(t.id,A.trim()):M(ye.resolveI18nLabel(t.label)??""),L(!1)},Q=()=>{m(t.id,D.trim()),V(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs("li",{"data-testid":`nav-designer-item-${t.id}`,className:ke("flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 transition-colors hover:bg-gray-50",S&&"opacity-50"),style:{marginLeft:s*20},children:[e.jsx(u.GripVertical,{className:"h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300"}),t.type==="group"?e.jsx("button",{type:"button",onClick:()=>b(t.id),className:"rounded p-0.5 text-gray-400 hover:text-gray-600","aria-label":x(_?"appDesigner.navCollapseGroup":"appDesigner.navExpandGroup"),children:_?e.jsx(u.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(u.ChevronRight,{className:"h-3.5 w-3.5"})}):e.jsx("span",{className:"w-5"}),$&&!r?e.jsx("input",{type:"text",value:D,onChange:U=>P(U.target.value),onBlur:Q,onKeyDown:U=>{U.key==="Enter"&&Q(),U.key==="Escape"&&(P(t.icon||""),V(!1))},autoFocus:!0,placeholder:x("appDesigner.navIconPlaceholder"),"data-testid":`nav-designer-icon-input-${t.id}`,className:"w-24 rounded border border-blue-300 px-1 py-0.5 text-xs outline-none focus:ring-1 focus:ring-blue-400"}):e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(j.Icon,{className:"h-3.5 w-3.5 shrink-0 text-gray-500"}),!r&&t.type!=="separator"&&e.jsx("button",{type:"button",onClick:()=>{P(t.icon||""),V(!0)},className:"rounded p-0.5 text-gray-300 hover:text-blue-500","aria-label":x("appDesigner.navEditIcon"),"data-testid":`nav-designer-edit-icon-${t.id}`,children:e.jsx(u.Pencil,{className:"h-2.5 w-2.5"})})]}),t.type==="separator"?e.jsx("span",{className:"flex-1 text-xs italic text-gray-400",children:x("appDesigner.separatorLabel")}):w&&!r?e.jsx("input",{type:"text",value:A,onChange:U=>M(U.target.value),onBlur:K,onKeyDown:U=>{U.key==="Enter"&&K(),U.key==="Escape"&&(M(ye.resolveI18nLabel(t.label)??""),L(!1))},autoFocus:!0,className:"flex-1 rounded border border-blue-300 px-1.5 py-0.5 text-sm outline-none focus:ring-1 focus:ring-blue-400"}):e.jsx("span",{className:ke("flex-1 truncate text-sm text-gray-800",!r&&"cursor-text"),onDoubleClick:()=>{!r&&t.type!=="separator"&&(M(ye.resolveI18nLabel(t.label)??""),L(!0))},children:ye.resolveI18nLabel(t.label)}),e.jsx("span",{className:ke("rounded-full px-2 py-0.5 text-[10px] font-medium",j.color),children:x(j.labelKey)}),S&&e.jsx("span",{className:"rounded-full bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-500","data-testid":`nav-designer-hidden-badge-${t.id}`,children:x("appDesigner.navHidden")}),!r&&t.type!=="separator"&&e.jsx("button",{type:"button",onClick:()=>d(t.id),className:"rounded p-0.5 text-gray-400 hover:text-gray-700","aria-label":x("appDesigner.navToggleVisible"),"data-testid":`nav-designer-toggle-visible-${t.id}`,children:S?e.jsx(u.EyeOff,{className:"h-3.5 w-3.5"}):e.jsx(u.Eye,{className:"h-3.5 w-3.5"})}),t.type==="group"&&!r&&e.jsx("button",{type:"button",onClick:()=>g(t.id,"page"),className:"rounded p-0.5 text-gray-400 hover:text-blue-500","aria-label":x("appDesigner.navAddChild"),"data-testid":`nav-designer-add-child-${t.id}`,children:e.jsx(u.Plus,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>c(t.id),disabled:r||n===0,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":x("appDesigner.navMoveUp"),children:e.jsx(u.ChevronUp,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>f(t.id),disabled:r||n===i-1,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":x("appDesigner.navMoveDown"),children:e.jsx(u.ChevronDown,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>o(t.id),disabled:r,className:"rounded p-0.5 text-gray-400 hover:text-red-500 disabled:opacity-30","aria-label":x("appDesigner.navRemove"),"data-testid":`nav-designer-remove-${t.id}`,children:e.jsx(u.Trash2,{className:"h-3.5 w-3.5"})})]}),t.type==="group"&&_&&t.children&&e.jsx(e.Fragment,{children:t.children.map((U,ae)=>e.jsx(Ct,{item:U,depth:s+1,index:ae,total:t.children.length,readOnly:r,onRemove:o,onMoveUp:c,onMoveDown:f,onToggleExpand:b,onUpdateLabel:l,onUpdateIcon:m,onToggleVisible:d,onAddChild:g,expandedIds:v,t:x},U.id))})]})}function Sa({items:t,t:s}){return e.jsxs("div",{"data-testid":"nav-designer-preview",className:"w-56 shrink-0 rounded-lg border border-gray-200 bg-gray-50 p-3",children:[e.jsx("h4",{className:"mb-2 text-xs font-semibold uppercase text-gray-500",children:s("appDesigner.navLivePreview")}),t.length===0?e.jsx("p",{className:"text-xs text-gray-400",children:s("appDesigner.navNoPreviewItems")}):e.jsx("ul",{className:"space-y-0.5",children:t.map(n=>e.jsx(kt,{item:n,depth:0},n.id))})]})}function kt({item:t,depth:s}){const n=_e[t.type];return t.type==="separator"?e.jsx("li",{className:"my-1 border-t border-gray-200",style:{marginLeft:s*12}}):e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-gray-700 hover:bg-gray-100",style:{marginLeft:s*12},children:[e.jsx(n.Icon,{className:"h-3 w-3 text-gray-400"}),e.jsx("span",{className:"truncate",children:ye.resolveI18nLabel(t.label)})]}),t.type==="group"&&t.children?.map(i=>e.jsx(kt,{item:i,depth:s+1},i.id))]})}function Dt({items:t,onChange:s,readOnly:n=!1,showPreview:i=!0,className:r,onExport:o,onImport:c}){const{t:f}=be(),b=a.useRef(null),[l,m]=a.useState(()=>new Set(t.filter(D=>D.type==="group").map(D=>D.id))),d=a.useCallback(D=>{function P(j){return j.filter(_=>_.id!==D).map(_=>_.children?{..._,children:P(_.children)}:_)}s(P(t))},[t,s]),g=a.useCallback((D,P)=>{function j(_){const S=_.findIndex(K=>K.id===D);if(S>=0){const K=P==="up"?S-1:S+1;if(K>=0&&K<_.length){const Q=[..._];return[Q[S],Q[K]]=[Q[K],Q[S]],Q}return _}return _.map(K=>K.children?{...K,children:j(K.children)}:K)}s(j(t))},[t,s]),v=a.useCallback((D,P)=>{function j(_){return _.map(S=>S.id===D?{...S,label:P}:S.children?{...S,children:j(S.children)}:S)}s(j(t))},[t,s]),x=a.useCallback((D,P)=>{function j(_){return _.map(S=>S.id===D?{...S,icon:P||void 0}:S.children?{...S,children:j(S.children)}:S)}s(j(t))},[t,s]),w=a.useCallback(D=>{function P(j){return j.map(_=>_.id===D?{..._,visible:_.visible===!1}:_.children?{..._,children:P(_.children)}:_)}s(P(t))},[t,s]),L=a.useCallback((D,P)=>{const j={id:wt(P),type:P,label:P==="separator"?"":`New ${f(_e[P].labelKey)}`,...P==="group"?{children:[]}:{},...P==="url"?{url:""}:{}};function _(S){return S.map(K=>K.id===D&&K.type==="group"?{...K,children:[...K.children||[],j]}:K.children?{...K,children:_(K.children)}:K)}s(_(t)),m(S=>new Set(S).add(D))},[t,s]),A=a.useCallback(D=>{const P={id:wt(D),type:D,label:D==="separator"?"":`New ${f(_e[D].labelKey)}`,...D==="group"?{children:[]}:{},...D==="url"?{url:""}:{}};s([...t,P])},[t,s,f]),M=a.useCallback(D=>{m(P=>{const j=new Set(P);return j.has(D)?j.delete(D):j.add(D),j})},[]),$=a.useCallback(()=>{if(o)o(t);else{const D=JSON.stringify(t,null,2),P=new Blob([D],{type:"application/json"}),j=URL.createObjectURL(P),_=document.createElement("a");_.href=j,_.download="navigation-schema.json",_.click(),URL.revokeObjectURL(j)}},[t,o]),V=a.useCallback(D=>{const P=D.target.files?.[0];if(!P)return;const j=new FileReader;j.onload=_=>{try{const S=JSON.parse(_.target?.result);Array.isArray(S)&&(c?c(S):s(S))}catch{}},j.readAsText(P),b.current&&(b.current.value="")},[s,c]);return e.jsxs("div",{"data-testid":"navigation-designer",className:ke("flex flex-col gap-4 sm:flex-row",r),children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[Da.map(({type:D,labelKey:P})=>{const{Icon:j,color:_}=_e[D];return e.jsxs("button",{type:"button","data-testid":`nav-designer-add-${D}`,onClick:()=>A(D),disabled:n,className:ke("inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50"),children:[e.jsx(u.Plus,{className:"h-3 w-3"}),f(P)]},D)}),e.jsx("span",{className:"mx-1 hidden h-4 w-px bg-gray-200 sm:block"}),e.jsxs("button",{type:"button","data-testid":"nav-designer-export",onClick:$,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50",children:[e.jsx(u.Download,{className:"h-3 w-3"}),f("appDesigner.navExportSchema")]}),e.jsxs("label",{"data-testid":"nav-designer-import",className:ke("inline-flex cursor-pointer items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50",n&&"cursor-not-allowed opacity-50"),children:[e.jsx(u.Upload,{className:"h-3 w-3"}),f("appDesigner.navImportSchema"),e.jsx("input",{ref:b,type:"file",accept:".json",className:"hidden",onChange:V,disabled:n,"data-testid":"nav-designer-import-input"})]})]}),t.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-gray-400",children:f("appDesigner.navNoItems")}):e.jsx("ul",{className:"space-y-1","data-testid":"nav-designer-tree",children:t.map((D,P)=>e.jsx(Ct,{item:D,depth:0,index:P,total:t.length,readOnly:n,onRemove:d,onMoveUp:j=>g(j,"up"),onMoveDown:j=>g(j,"down"),onToggleExpand:M,onUpdateLabel:v,onUpdateIcon:x,onToggleVisible:w,onAddChild:L,expandedIds:l,t:f},D.id))})]}),i&&e.jsx(Sa,{items:t,t:f})]})}function St(...t){return ie.twMerge(le.clsx(t))}const Ea=[{value:"edit",label:"Edit",Icon:u.Pencil},{value:"preview",label:"Preview",Icon:u.Eye},{value:"code",label:"Code",Icon:u.Code}];function Ta({mode:t,onChange:s,disabled:n=!1,className:i}){return e.jsx("div",{"data-testid":"editor-mode-toggle",className:St("inline-flex items-center rounded-lg border border-gray-200 bg-gray-50 p-0.5",i),role:"radiogroup","aria-label":"Editor mode",children:Ea.map(({value:r,label:o,Icon:c})=>e.jsxs("button",{type:"button",role:"radio","aria-checked":t===r,"data-testid":`editor-mode-${r}`,onClick:()=>s(r),disabled:n,className:St("inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",t===r?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700",n&&"cursor-not-allowed opacity-50"),children:[e.jsx(c,{className:"h-3.5 w-3.5"}),o]},r))})}function Xe(...t){return ie.twMerge(le.clsx(t))}const De=[{type:"metric",label:"KPI Metric",Icon:u.TrendingUp},{type:"bar",label:"Bar Chart",Icon:u.BarChart3},{type:"line",label:"Line Chart",Icon:u.LineChart},{type:"pie",label:"Pie Chart",Icon:u.PieChart},{type:"table",label:"Table",Icon:u.Table2},{type:"grid",label:"Grid",Icon:u.LayoutGrid}];let Et=0;function Pa(){return Et+=1,`widget_${Date.now()}_${Et}`}function Ia({widget:t,index:s,total:n,selected:i,readOnly:r,onSelect:o,onRemove:c,onMoveUp:f,onMoveDown:b}){const l=t.type||"metric",m=De.find(d=>d.type===l)||De[0];return e.jsxs("div",{"data-testid":`dashboard-widget-${t.id}`,onClick:o,className:Xe("group cursor-pointer rounded-lg border-2 p-3 transition-colors",i?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300"),children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u.GripVertical,{className:"h-4 w-4 text-gray-300"}),e.jsx(m.Icon,{className:"h-4 w-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-800",children:t.title||`Widget ${s+1}`})]}),!r&&e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),f()},disabled:s===0,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":"Move up",children:e.jsx(u.ChevronUp,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),b()},disabled:s===n-1,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":"Move down",children:e.jsx(u.ChevronDown,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),c()},className:"rounded p-0.5 text-gray-400 hover:text-red-500","aria-label":"Remove widget","data-testid":`dashboard-widget-remove-${t.id}`,children:e.jsx(u.Trash2,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsx("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-600",children:m.label}),t.object&&e.jsx("span",{className:"text-[10px] text-gray-400",children:t.object})]})]})}function La({widget:t,readOnly:s,onChange:n,onClose:i}){const{t:r}=be();return e.jsxs("div",{"data-testid":"widget-property-panel",className:"shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-800",children:r("appDesigner.widgetProperties")}),e.jsx("button",{type:"button",onClick:i,className:"rounded p-0.5 text-gray-400 hover:text-gray-600","aria-label":"Close",children:e.jsx(u.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"widget-title",className:"text-xs font-medium text-gray-600",children:"Title"}),e.jsx("input",{id:"widget-title","data-testid":"widget-prop-title",type:"text",value:t.title??"",onChange:o=>n({title:o.target.value}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"widget-type",className:"text-xs font-medium text-gray-600",children:"Type"}),e.jsx("select",{id:"widget-type","data-testid":"widget-prop-type",value:t.type??"metric",onChange:o=>n({type:o.target.value}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50",children:De.map(o=>e.jsx("option",{value:o.type,children:o.label},o.type))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"widget-object",className:"text-xs font-medium text-gray-600",children:"Data Source (Object)"}),e.jsx("input",{id:"widget-object","data-testid":"widget-prop-object",type:"text",value:t.object??"",onChange:o=>n({object:o.target.value}),disabled:s,placeholder:"e.g. orders",className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"widget-value-field",className:"text-xs font-medium text-gray-600",children:"Value Field"}),e.jsx("input",{id:"widget-value-field","data-testid":"widget-prop-value-field",type:"text",value:t.valueField??"",onChange:o=>n({valueField:o.target.value}),disabled:s,placeholder:"e.g. amount",className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"widget-aggregate",className:"text-xs font-medium text-gray-600",children:"Aggregate"}),e.jsxs("select",{id:"widget-aggregate","data-testid":"widget-prop-aggregate",value:t.aggregate??"count",onChange:o=>n({aggregate:o.target.value}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50",children:[e.jsx("option",{value:"count",children:"Count"}),e.jsx("option",{value:"sum",children:"Sum"}),e.jsx("option",{value:"avg",children:"Average"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"widget-color",className:"text-xs font-medium text-gray-600",children:"Color Variant"}),e.jsxs("select",{id:"widget-color","data-testid":"widget-prop-color",value:t.colorVariant??"default",onChange:o=>n({colorVariant:o.target.value}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50",children:[e.jsx("option",{value:"default",children:"Default"}),e.jsx("option",{value:"blue",children:"Blue"}),e.jsx("option",{value:"teal",children:"Teal"}),e.jsx("option",{value:"orange",children:"Orange"}),e.jsx("option",{value:"purple",children:"Purple"}),e.jsx("option",{value:"success",children:"Success"}),e.jsx("option",{value:"warning",children:"Warning"}),e.jsx("option",{value:"danger",children:"Danger"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:r("appDesigner.widgetLayoutSize")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{htmlFor:"widget-width",className:"text-[10px] text-gray-400",children:r("appDesigner.widgetWidth")}),e.jsx("input",{id:"widget-width","data-testid":"widget-prop-width",type:"number",min:1,value:t.layout?.w??1,onChange:o=>n({layout:{...t.layout,w:Number(o.target.value)||1}}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{htmlFor:"widget-height",className:"text-[10px] text-gray-400",children:r("appDesigner.widgetHeight")}),e.jsx("input",{id:"widget-height","data-testid":"widget-prop-height",type:"number",min:1,value:t.layout?.h??1,onChange:o=>n({layout:{...t.layout,h:Number(o.target.value)||1}}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50"})]})]})]})]})}function Aa({schema:t}){const{t:s}=be(),n=t.widgets||[];return e.jsxs("div",{"data-testid":"dashboard-preview",className:"rounded-lg border border-gray-200 bg-gray-50 p-4",children:[e.jsx("h4",{className:"mb-3 text-sm font-semibold text-gray-700",children:t.title||s("appDesigner.dashboardPreview")}),n.length===0?e.jsx("div",{className:"text-xs text-gray-400",children:s("appDesigner.noWidgetsPreview")}):e.jsx("div",{className:"grid gap-2",style:{gridTemplateColumns:`repeat(${t.columns??2}, 1fr)`},children:n.map(i=>{const r=De.find(o=>o.type===(i.type||"metric"))||De[0];return e.jsxs("div",{className:"rounded-md border border-gray-200 bg-white p-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(r.Icon,{className:"h-3 w-3 text-gray-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-600",children:i.title||"Untitled"})]}),e.jsx("div",{className:"mt-1 text-[10px] text-gray-400",children:r.label})]},i.id)})})]})}function Tt({schema:t,onChange:s,readOnly:n=!1,className:i,onExport:r,onImport:o,selectedWidgetId:c,onWidgetSelect:f}){const{t:b}=be(),[l,m]=a.useState(null),[d,g]=a.useState(!1),v=a.useRef(null),x=a.useRef(null),w=c!==void 0,L=w?c:l,A=a.useCallback(k=>{f&&f(k),w||m(k)},[w,f,m]),{current:M,canUndo:$,canRedo:V,push:D,undo:P,redo:j}=he(t),_=a.useCallback(k=>{D(k),s(k)},[D,s]),S=M.widgets||[],K=S.find(k=>k.id===L),Q=a.useCallback(k=>{const W=Pa(),G={id:W,title:"",type:k,layout:{x:0,y:S.length,w:M.columns??2,h:1}};_({...M,widgets:[...S,G]}),A(W)},[M,S,_,A]),U=a.useCallback(k=>{_({...M,widgets:S.filter(W=>W.id!==k)}),L===k&&A(null)},[M,S,L,_,A]),ae=a.useCallback((k,W)=>{const G=S.findIndex(T=>T.id===k);if(G<0)return;const h=W==="up"?G-1:G+1;if(h<0||h>=S.length)return;const B=[...S];[B[G],B[h]]=[B[h],B[G]],_({...M,widgets:B})},[M,S,_]),ne=a.useCallback(k=>{L&&_({...M,widgets:S.map(W=>W.id===L?{...W,...k}:W)})},[M,S,L,_]);a.useEffect(()=>{const k=v.current;if(!k)return;const W=G=>{if(!n){if((G.ctrlKey||G.metaKey)&&G.key==="z"&&!G.shiftKey){G.preventDefault(),P();return}if((G.ctrlKey||G.metaKey)&&(G.key==="y"||G.key==="z"&&G.shiftKey)){G.preventDefault(),j();return}if((G.key==="Delete"||G.key==="Backspace")&&L){const h=G.target;if(h.tagName==="INPUT"||h.tagName==="SELECT"||h.tagName==="TEXTAREA")return;G.preventDefault(),U(L)}}};return k.addEventListener("keydown",W),()=>k.removeEventListener("keydown",W)},[n,P,j,L,U]);const z=a.useCallback(()=>{r&&r(M)},[M,r]),R=a.useCallback(()=>{x.current?.click()},[]),q=a.useCallback(k=>{const W=k.target.files?.[0];if(!W)return;const G=new FileReader;G.onload=()=>{try{const h=JSON.parse(G.result);h&&h.type==="dashboard"&&(_(h),o?.(h))}catch{}},G.readAsText(W),k.target.value=""},[_,o]);return e.jsxs("div",{ref:v,tabIndex:0,"data-testid":"dashboard-editor",className:Xe("flex flex-col gap-4 outline-none",i),children:[e.jsx("input",{ref:x,type:"file",accept:".json",className:"hidden","data-testid":"dashboard-import-input",onChange:q}),K&&!d&&e.jsx(La,{widget:K,readOnly:n,onChange:ne,onClose:()=>A(null)}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:[b("appDesigner.addWidget"),":"]}),De.map(({type:k,label:W,Icon:G})=>e.jsxs("button",{type:"button","data-testid":`dashboard-add-${k}`,onClick:()=>Q(k),disabled:n||d,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(G,{className:"h-3.5 w-3.5"}),W]},k))]}),e.jsxs("div",{className:"flex items-center gap-1",children:[!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-testid":"dashboard-undo",onClick:P,disabled:!$,className:"rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":b("appDesigner.undo"),children:e.jsx(u.Undo2,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","data-testid":"dashboard-redo",onClick:j,disabled:!V,className:"rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":b("appDesigner.redo"),children:e.jsx(u.Redo2,{className:"h-4 w-4"})})]}),e.jsx("button",{type:"button","data-testid":"dashboard-export",onClick:z,className:"rounded p-1.5 text-gray-400 hover:text-gray-700","aria-label":b("appDesigner.navExportSchema"),children:e.jsx(u.Download,{className:"h-4 w-4"})}),!n&&e.jsx("button",{type:"button","data-testid":"dashboard-import",onClick:R,className:"rounded p-1.5 text-gray-400 hover:text-gray-700","aria-label":b("appDesigner.navImportSchema"),children:e.jsx(u.Upload,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","data-testid":"dashboard-preview-toggle",onClick:()=>g(k=>!k),className:Xe("rounded p-1.5 transition-colors",d?"bg-blue-100 text-blue-600":"text-gray-400 hover:text-gray-700"),"aria-label":b(d?"appDesigner.modeEdit":"appDesigner.preview"),children:d?e.jsx(u.EyeOff,{className:"h-4 w-4"}):e.jsx(u.Eye,{className:"h-4 w-4"})})]})]}),d?e.jsx(Aa,{schema:M}):S.length===0?e.jsx("div",{className:"flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400",children:b("appDesigner.noWidgets")}):e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:`repeat(${M.columns??2}, 1fr)`},children:S.map((k,W)=>e.jsx(Ia,{widget:k,index:W,total:S.length,selected:k.id===L,readOnly:n,onSelect:()=>A(k.id??null),onRemove:()=>U(k.id),onMoveUp:()=>ae(k.id,"up"),onMoveDown:()=>ae(k.id,"down")},k.id))})]})]})}function Oe(...t){return ie.twMerge(le.clsx(t))}const je=[{type:"grid",label:"Data Grid",Icon:u.Table2},{type:"kanban",label:"Kanban Board",Icon:u.Kanban},{type:"calendar",label:"Calendar",Icon:u.CalendarDays},{type:"gallery",label:"Gallery",Icon:u.GalleryHorizontalEnd},{type:"dashboard",label:"Dashboard",Icon:u.BarChart3},{type:"form",label:"Form",Icon:u.FileText},{type:"layout-grid",label:"Grid Layout",Icon:u.LayoutGrid}],_a=[{value:"page",labelKey:"appDesigner.modePage"},{value:"dashboard",labelKey:"appDesigner.modeDashboard"}];let Pt=0;function Ma(){return Pt+=1,`component_${Date.now()}_${Pt}`}function $a({component:t,index:s,total:n,selected:i,readOnly:r,onSelect:o,onRemove:c,onMoveUp:f,onMoveDown:b}){const l=je.find(m=>m.type===t.type)||je[0];return e.jsxs("div",{"data-testid":`canvas-component-${t.id}`,onClick:o,className:Oe("group flex cursor-pointer items-center gap-3 rounded-lg border-2 px-3 py-3 transition-colors",i?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300"),children:[e.jsx(u.GripVertical,{className:"h-4 w-4 shrink-0 cursor-grab text-gray-300"}),e.jsx(l.Icon,{className:"h-5 w-5 shrink-0 text-gray-500"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm font-medium text-gray-800",children:t.label}),e.jsx("span",{className:"ml-2 text-[10px] text-gray-400",children:l.label})]}),!r&&e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),f()},disabled:s===0,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":"Move up",children:e.jsx(u.ChevronUp,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),b()},disabled:s===n-1,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":"Move down",children:e.jsx(u.ChevronDown,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),c()},className:"rounded p-0.5 text-gray-400 hover:text-red-500","aria-label":"Remove component","data-testid":`canvas-component-remove-${t.id}`,children:e.jsx(u.Trash2,{className:"h-3.5 w-3.5"})})]})]})}function Fa({component:t,readOnly:s,onChange:n,onClose:i}){const{t:r}=be();return e.jsxs("div",{"data-testid":"component-property-panel",className:"w-64 shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-800",children:r("appDesigner.componentProperties")}),e.jsx("button",{type:"button",onClick:i,className:"rounded p-0.5 text-gray-400 hover:text-gray-600","aria-label":"Close",children:e.jsx(u.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"component-label",className:"text-xs font-medium text-gray-600",children:"Label"}),e.jsx("input",{id:"component-label","data-testid":"component-prop-label",type:"text",value:t.label,onChange:o=>n({label:o.target.value}),disabled:s,className:"block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Type"}),e.jsx("div",{className:"rounded-md bg-gray-50 px-2.5 py-1.5 text-sm text-gray-600",children:je.find(o=>o.type===t.type)?.label??t.type})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"ID"}),e.jsx("div",{className:"rounded-md bg-gray-50 px-2.5 py-1.5 text-xs font-mono text-gray-500",children:t.id})]})]})}function Ua({schema:t,components:s}){const{t:n}=be();return e.jsxs("div",{"data-testid":"page-preview",className:"rounded-lg border border-gray-200 bg-gray-50 p-4",children:[e.jsx("h4",{className:"mb-3 text-sm font-semibold text-gray-700",children:t.title||n("appDesigner.pagePreview")}),s.length===0?e.jsx("div",{className:"text-xs text-gray-400",children:n("appDesigner.noComponentsPreview")}):e.jsx("div",{className:"space-y-2",children:s.map(i=>{const r=je.find(o=>o.type===i.type)||je[0];return e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-gray-200 bg-white p-2",children:[e.jsx(r.Icon,{className:"h-4 w-4 text-gray-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-600",children:i.label}),e.jsx("span",{className:"text-[10px] text-gray-400",children:r.label})]},i.id)})})]})}function It({schema:t,onChange:s,readOnly:n=!1,className:i,onExport:r,onImport:o}){const{t:c}=be(),f=a.useRef(null),b=a.useRef(null),[l,m]=a.useState(()=>(t.children?Array.isArray(t.children)?t.children:[t.children]:[]).map((R,q)=>({id:R.id||`existing_${q}`,type:R.type||"grid",label:R.title||R.label||`Component ${q+1}`,props:R}))),[d,g]=a.useState(null),[v,x]=a.useState(!1),[w,L]=a.useState("page"),A=l.find(z=>z.id===d),{canUndo:M,canRedo:$,push:V,undo:D,redo:P}=he(l),j=a.useCallback(z=>{m(z),V(z),s({...t,children:z.map(R=>({type:R.type,id:R.id,title:R.label,...R.props}))})},[t,s,V]),_=a.useCallback(z=>{const R=Ma(),q=je.find(G=>G.type===z),k={id:R,type:z,label:q?.label||z},W=[...l,k];j(W),g(R)},[l,j]),S=a.useCallback(z=>{const R=l.filter(q=>q.id!==z);j(R),d===z&&g(null)},[l,d,j]),K=a.useCallback((z,R)=>{const q=l.findIndex(G=>G.id===z);if(q<0)return;const k=R==="up"?q-1:q+1;if(k<0||k>=l.length)return;const W=[...l];[W[q],W[k]]=[W[k],W[q]],j(W)},[l,j]),Q=a.useCallback(z=>{if(!d)return;const R=l.map(q=>q.id===d?{...q,...z}:q);j(R)},[l,d,j]);a.useEffect(()=>{const z=f.current;if(!z)return;const R=q=>{if(!n){if((q.ctrlKey||q.metaKey)&&q.key==="z"&&!q.shiftKey){q.preventDefault(),D();return}if((q.ctrlKey||q.metaKey)&&(q.key==="y"||q.key==="z"&&q.shiftKey)){q.preventDefault(),P();return}if((q.key==="Delete"||q.key==="Backspace")&&d){const k=q.target;if(k.tagName==="INPUT"||k.tagName==="SELECT"||k.tagName==="TEXTAREA")return;q.preventDefault(),S(d)}}};return z.addEventListener("keydown",R),()=>z.removeEventListener("keydown",R)},[n,D,P,d,S]);const U=a.useCallback(()=>{r&&r(t)},[t,r]),ae=a.useCallback(()=>{b.current?.click()},[]),ne=a.useCallback(z=>{const R=z.target.files?.[0];if(!R)return;const q=new FileReader;q.onload=()=>{try{const k=JSON.parse(q.result);if(k&&k.type==="page"){const G=(k.children?Array.isArray(k.children)?k.children:[k.children]:[]).map((h,B)=>({id:h.id||`imported_${B}`,type:h.type||"grid",label:h.title||h.label||`Component ${B+1}`,props:h}));m(G),V(G),s(k),o?.(k)}}catch{}},q.readAsText(R),z.target.value=""},[s,V,o]);return e.jsxs("div",{ref:f,tabIndex:0,"data-testid":"page-canvas-editor",className:Oe("flex flex-col gap-4 outline-none sm:flex-row",i),children:[e.jsx("input",{ref:b,type:"file",accept:".json",className:"hidden","data-testid":"canvas-import-input",onChange:ne}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-gray-200 pb-2",role:"tablist",children:_a.map(z=>e.jsx("button",{type:"button",role:"tab","data-testid":`canvas-mode-${z.value}`,"aria-selected":w===z.value,onClick:()=>L(z.value),className:Oe("rounded-t-md px-3 py-1.5 text-xs font-medium transition-colors",w===z.value?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"),children:c(z.labelKey)},z.value))}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:[c("appDesigner.addComponent"),":"]}),je.map(({type:z,label:R,Icon:q})=>e.jsxs("button",{type:"button","data-testid":`canvas-add-${z}`,onClick:()=>_(z),disabled:n||v,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(q,{className:"h-3.5 w-3.5"}),R]},z))]}),e.jsxs("div",{className:"flex items-center gap-1",children:[!n&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-testid":"canvas-undo",onClick:D,disabled:!M,className:"rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":c("appDesigner.undo"),children:e.jsx(u.Undo2,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","data-testid":"canvas-redo",onClick:P,disabled:!$,className:"rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":c("appDesigner.redo"),children:e.jsx(u.Redo2,{className:"h-4 w-4"})})]}),e.jsx("button",{type:"button","data-testid":"canvas-export",onClick:U,className:"rounded p-1.5 text-gray-400 hover:text-gray-700","aria-label":c("appDesigner.navExportSchema"),children:e.jsx(u.Download,{className:"h-4 w-4"})}),!n&&e.jsx("button",{type:"button","data-testid":"canvas-import",onClick:ae,className:"rounded p-1.5 text-gray-400 hover:text-gray-700","aria-label":c("appDesigner.navImportSchema"),children:e.jsx(u.Upload,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","data-testid":"canvas-preview-toggle",onClick:()=>x(z=>!z),className:Oe("rounded p-1.5 transition-colors",v?"bg-blue-100 text-blue-600":"text-gray-400 hover:text-gray-700"),"aria-label":c(v?"appDesigner.modeEdit":"appDesigner.preview"),children:v?e.jsx(u.EyeOff,{className:"h-4 w-4"}):e.jsx(u.Eye,{className:"h-4 w-4"})})]})]}),v?e.jsx(Ua,{schema:t,components:l}):l.length===0?e.jsx("div",{className:"flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400",children:c("appDesigner.emptyPage")}):e.jsx("div",{className:"space-y-2",children:l.map((z,R)=>e.jsx($a,{component:z,index:R,total:l.length,selected:z.id===d,readOnly:n,onSelect:()=>g(z.id),onRemove:()=>S(z.id),onMoveUp:()=>K(z.id,"up"),onMoveDown:()=>K(z.id,"down")},z.id))})]}),A&&!v&&e.jsx(Fa,{component:A,readOnly:n,onChange:Q,onClose:()=>g(null)})]})}function He(...t){return ie.twMerge(le.clsx(t))}const za={grid:{label:"Grid",Icon:u.LayoutGrid},kanban:{label:"Kanban",Icon:u.Kanban},calendar:{label:"Calendar",Icon:u.CalendarDays},gallery:{label:"Gallery",Icon:u.GalleryHorizontalEnd},timeline:{label:"Timeline",Icon:u.Clock},map:{label:"Map",Icon:u.Map},gantt:{label:"Gantt",Icon:u.GanttChart}},Ga=[{value:"compact",label:"Compact"},{value:"medium",label:"Medium"},{value:"tall",label:"Tall"}];function Ve({title:t,icon:s,defaultOpen:n=!0,children:i}){const[r,o]=a.useState(n);return e.jsxs("div",{className:"border-b border-gray-100 pb-3",children:[e.jsxs("button",{type:"button",onClick:()=>o(!r),className:"flex w-full items-center gap-2 py-2 text-left",children:[s,e.jsx("span",{className:"flex-1 text-xs font-semibold uppercase text-gray-500",children:t}),r?e.jsx(u.ChevronUp,{className:"h-3.5 w-3.5 text-gray-400"}):e.jsx(u.ChevronDown,{className:"h-3.5 w-3.5 text-gray-400"})]}),r&&e.jsx("div",{className:"space-y-2",children:i})]})}function Lt({config:t,onChange:s,availableViewTypes:n=["grid","kanban","calendar","gallery","timeline","map","gantt"],readOnly:i=!1,className:r}){const o=a.useCallback(l=>{s({...t,...l})},[t,s]),c=a.useCallback(l=>{o({columns:t.columns.map(m=>m.name===l?{...m,visible:!m.visible}:m)})},[t,o]),f=a.useCallback((l,m)=>{const d=[...t.columns],g=d.findIndex(x=>x.name===l);if(g<0)return;const v=m==="up"?g-1:g+1;v<0||v>=d.length||([d[g],d[v]]=[d[v],d[g]],o({columns:d}))},[t,o]),b=a.useMemo(()=>t.columns.filter(l=>l.visible).length,[t.columns]);return e.jsxs("div",{"data-testid":"object-view-configurator",className:He("w-72 space-y-3 rounded-lg border border-gray-200 bg-white p-4",r),children:[e.jsx(Ve,{title:"View Type",icon:e.jsx(u.LayoutGrid,{className:"h-3.5 w-3.5 text-gray-500"}),children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(l=>{const{label:m,Icon:d}=za[l];return e.jsxs("button",{type:"button","data-testid":`view-type-${l}`,onClick:()=>o({viewType:l}),disabled:i,className:He("inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",t.viewType===l?"bg-blue-100 text-blue-700":"text-gray-600 hover:bg-gray-100",i&&"cursor-not-allowed opacity-50"),children:[e.jsx(d,{className:"h-3 w-3"}),m]},l)})})}),e.jsx(Ve,{title:`Fields (${b}/${t.columns.length})`,icon:e.jsx(u.Columns3,{className:"h-3.5 w-3.5 text-gray-500"}),children:t.columns.length===0?e.jsx("p",{className:"text-xs text-gray-400",children:"No fields configured."}):e.jsx("ul",{className:"space-y-0.5",children:t.columns.map((l,m)=>e.jsxs("li",{"data-testid":`view-column-${l.name}`,className:"flex items-center gap-1.5 rounded px-1.5 py-1 text-xs hover:bg-gray-50",children:[e.jsx("button",{type:"button",onClick:()=>c(l.name),disabled:i,className:He("rounded p-0.5 transition-colors",l.visible?"text-blue-500":"text-gray-300"),"aria-label":l.visible?"Hide field":"Show field",children:l.visible?e.jsx(u.Eye,{className:"h-3 w-3"}):e.jsx(u.EyeOff,{className:"h-3 w-3"})}),e.jsx("span",{className:"flex-1 truncate text-gray-700",children:l.label}),e.jsx("button",{type:"button",onClick:()=>f(l.name,"up"),disabled:i||m===0,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":"Move up",children:e.jsx(u.ChevronUp,{className:"h-3 w-3"})}),e.jsx("button",{type:"button",onClick:()=>f(l.name,"down"),disabled:i||m===t.columns.length-1,className:"rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30","aria-label":"Move down",children:e.jsx(u.ChevronDown,{className:"h-3 w-3"})})]},l.name))})}),e.jsx(Ve,{title:"Toolbar",icon:e.jsx(u.Filter,{className:"h-3.5 w-3.5 text-gray-500"}),children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.showSearch,onChange:l=>o({showSearch:l.target.checked}),disabled:i,"data-testid":"view-toggle-search",className:"h-3.5 w-3.5 rounded border-gray-300"}),e.jsx("span",{className:"text-xs text-gray-700",children:"Show Search"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.showFilters,onChange:l=>o({showFilters:l.target.checked}),disabled:i,"data-testid":"view-toggle-filters",className:"h-3.5 w-3.5 rounded border-gray-300"}),e.jsx("span",{className:"text-xs text-gray-700",children:"Show Filters"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.showSort,onChange:l=>o({showSort:l.target.checked}),disabled:i,"data-testid":"view-toggle-sort",className:"h-3.5 w-3.5 rounded border-gray-300"}),e.jsx("span",{className:"text-xs text-gray-700",children:"Show Sort"})]})]})}),e.jsx(Ve,{title:"Appearance",icon:e.jsx(u.Settings2,{className:"h-3.5 w-3.5 text-gray-500"}),defaultOpen:!1,children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-medium text-gray-500",children:"Row Height"}),e.jsx("div",{className:"flex gap-1",children:Ga.map(({value:l,label:m})=>e.jsx("button",{type:"button","data-testid":`view-row-height-${l}`,onClick:()=>o({rowHeight:l}),disabled:i,className:He("flex-1 rounded px-2 py-1 text-[10px] font-medium transition-colors",t.rowHeight===l?"bg-blue-100 text-blue-700":"bg-gray-50 text-gray-500 hover:bg-gray-100"),children:m},l))})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.striped,onChange:l=>o({striped:l.target.checked}),disabled:i,"data-testid":"view-toggle-striped",className:"h-3.5 w-3.5 rounded border-gray-300"}),e.jsx("span",{className:"text-xs text-gray-700",children:"Striped Rows"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.bordered,onChange:l=>o({bordered:l.target.checked}),disabled:i,"data-testid":"view-toggle-bordered",className:"h-3.5 w-3.5 rounded border-gray-300"}),e.jsx("span",{className:"text-xs text-gray-700",children:"Bordered"})]})]})})]})}function de(...t){return ie.twMerge(le.clsx(t))}const Ka=[{hex:"#3b82f6",name:"Blue"},{hex:"#6366f1",name:"Indigo"},{hex:"#8b5cf6",name:"Violet"},{hex:"#a855f7",name:"Purple"},{hex:"#ec4899",name:"Pink"},{hex:"#ef4444",name:"Red"},{hex:"#f97316",name:"Orange"},{hex:"#f59e0b",name:"Amber"},{hex:"#eab308",name:"Yellow"},{hex:"#22c55e",name:"Green"},{hex:"#14b8a6",name:"Teal"},{hex:"#06b6d4",name:"Cyan"},{hex:"#0ea5e9",name:"Sky"},{hex:"#64748b",name:"Slate"},{hex:"#1e293b",name:"Dark"},{hex:"#0f172a",name:"Navy"}],Oa=["Inter","Roboto","Open Sans","Lato","Montserrat","Poppins","Source Sans Pro","Noto Sans","system-ui"];function At({branding:t,onChange:s,appTitle:n="My App",readOnly:i=!1,className:r,onExport:o,onImport:c}){const{t:f}=be(),[b,l]=a.useState("light"),{current:m,push:d,canUndo:g,canRedo:v,undo:x,redo:w}=he(t),L=a.useRef(!0);a.useEffect(()=>{if(L.current){L.current=!1;return}s(m)},[m]);const A=a.useCallback(j=>{const _={...m,...j};L.current=!0,d(_),s(_)},[m,d,s]),M=a.useCallback(()=>{if(o){o(m);return}const j=new Blob([JSON.stringify(m,null,2)],{type:"application/json"}),_=URL.createObjectURL(j),S=document.createElement("a");S.href=_,S.download="branding.json",S.click(),URL.revokeObjectURL(_)},[m,o]),$=a.useCallback(()=>{if(c){c(m);return}const j=document.createElement("input");j.type="file",j.accept=".json",j.onchange=_=>{const S=_.target.files?.[0];if(!S)return;const K=new FileReader;K.onload=Q=>{try{const U=JSON.parse(Q.target?.result);if(typeof U=="object"&&U!==null){const ae={...m,...U};d(ae),s(ae)}}catch{}},K.readAsText(S)},j.click()},[m,d,s,c]),V=a.useCallback(j=>{i||((j.ctrlKey||j.metaKey)&&j.key==="z"&&(j.preventDefault(),j.shiftKey?w():x()),(j.ctrlKey||j.metaKey)&&j.key==="y"&&(j.preventDefault(),w()))},[i,x,w]),D=m.primaryColor||"#3b82f6",P=b==="dark";return e.jsxs("div",{"data-testid":"branding-editor",className:de("flex flex-col gap-4 sm:gap-6",r),onKeyDown:V,tabIndex:0,children:[e.jsxs("div",{"data-testid":"branding-editor-toolbar",className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 mr-auto",children:f("appDesigner.brandingEditor")}),e.jsxs("button",{"data-testid":"branding-undo",type:"button",onClick:x,disabled:!g||i,className:de("inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors",g&&!i?"border-gray-300 bg-white text-gray-700 hover:bg-gray-50":"border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed"),title:f("appDesigner.undo"),children:[e.jsx(u.Undo2,{className:"h-3.5 w-3.5"}),f("appDesigner.undo")]}),e.jsxs("button",{"data-testid":"branding-redo",type:"button",onClick:w,disabled:!v||i,className:de("inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors",v&&!i?"border-gray-300 bg-white text-gray-700 hover:bg-gray-50":"border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed"),title:f("appDesigner.redo"),children:[e.jsx(u.Redo2,{className:"h-3.5 w-3.5"}),f("appDesigner.redo")]}),e.jsxs("button",{"data-testid":"branding-export",type:"button",onClick:M,className:"inline-flex items-center gap-1 rounded-md border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-sm transition-colors hover:bg-gray-50",title:f("appDesigner.brandingExport"),children:[e.jsx(u.Download,{className:"h-3.5 w-3.5"}),f("appDesigner.brandingExport")]}),e.jsxs("button",{"data-testid":"branding-import",type:"button",onClick:$,disabled:i,className:de("inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors",i?"border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed":"border-gray-300 bg-white text-gray-700 hover:bg-gray-50"),title:f("appDesigner.brandingImport"),children:[e.jsx(u.Upload,{className:"h-3.5 w-3.5"}),f("appDesigner.brandingImport")]})]}),e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"be-logo",className:"block text-sm font-medium text-gray-700",children:f("appDesigner.logoUrl")}),e.jsxs("div",{className:"relative",children:[e.jsx(u.Image,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{id:"be-logo","data-testid":"branding-logo-input",type:"text",value:m.logo??"",onChange:j=>A({logo:j.target.value}),placeholder:"https://example.com/logo.svg",disabled:i,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"be-color",className:"block text-sm font-medium text-gray-700",children:f("appDesigner.primaryColor")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(u.Palette,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{id:"be-color","data-testid":"branding-color-input",type:"text",value:m.primaryColor??"#3b82f6",onChange:j=>A({primaryColor:j.target.value}),placeholder:"#3b82f6",disabled:i,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]}),e.jsx("input",{"data-testid":"branding-color-picker",type:"color",value:D,onChange:j=>A({primaryColor:j.target.value}),disabled:i,className:"h-9 w-9 cursor-pointer rounded-md border border-gray-300 p-0.5 disabled:cursor-not-allowed"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:f("appDesigner.colorPalette")}),e.jsx("div",{"data-testid":"branding-color-palette",className:"flex flex-wrap gap-1.5",children:Ka.map(j=>e.jsx("button",{"data-testid":`branding-swatch-${j.hex.slice(1)}`,type:"button",onClick:()=>!i&&A({primaryColor:j.hex}),disabled:i,className:de("h-6 w-6 rounded-full border-2 transition-transform hover:scale-110 disabled:cursor-not-allowed",D===j.hex?"border-gray-800 ring-2 ring-offset-1 ring-gray-400":"border-transparent"),style:{backgroundColor:j.hex},title:j.name},j.hex))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"be-favicon",className:"block text-sm font-medium text-gray-700",children:f("appDesigner.faviconUrl")}),e.jsxs("div",{className:"relative",children:[e.jsx(u.Globe,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsx("input",{id:"be-favicon","data-testid":"branding-favicon-input",type:"text",value:m.favicon??"",onChange:j=>A({favicon:j.target.value}),placeholder:"https://example.com/favicon.ico",disabled:i,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"be-font",className:"block text-sm font-medium text-gray-700",children:f("appDesigner.fontFamily")}),e.jsxs("div",{className:"relative",children:[e.jsx(u.Type,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),e.jsxs("select",{id:"be-font","data-testid":"branding-font-select",value:m.fontFamily??"",onChange:j=>A({fontFamily:j.target.value||void 0}),disabled:i,className:"block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 appearance-none",children:[e.jsx("option",{value:"",children:f("appDesigner.fontDefault")}),Oa.map(j=>e.jsx("option",{value:j,children:j},j))]})]})]})]}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:f("appDesigner.brandingPreview")}),e.jsxs("div",{"data-testid":"branding-mode-toggle",className:"flex rounded-md border border-gray-300 overflow-hidden",children:[e.jsxs("button",{"data-testid":"branding-mode-light",type:"button",onClick:()=>l("light"),className:de("inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors",b==="light"?"bg-blue-50 text-blue-700":"bg-white text-gray-600 hover:bg-gray-50"),children:[e.jsx(u.Sun,{className:"h-3.5 w-3.5"}),f("appDesigner.modeLight")]}),e.jsxs("button",{"data-testid":"branding-mode-dark",type:"button",onClick:()=>l("dark"),className:de("inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors",b==="dark"?"bg-gray-800 text-gray-100":"bg-white text-gray-600 hover:bg-gray-50"),children:[e.jsx(u.Moon,{className:"h-3.5 w-3.5"}),f("appDesigner.modeDark")]})]})]}),e.jsxs("div",{"data-testid":"branding-preview",className:de("rounded-lg border p-4 transition-colors",P?"border-gray-700 bg-gray-900 text-gray-100":"border-gray-200 bg-white text-gray-800"),style:{fontFamily:m.fontFamily||"inherit"},children:[e.jsx("div",{className:"rounded-md p-3 mb-3",style:{backgroundColor:D},children:e.jsxs("div",{className:"flex items-center gap-3",children:[m.logo?e.jsx("img",{src:m.logo,alt:"Logo",className:"h-8 w-8 rounded object-contain bg-white/20"}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white",children:"Logo"}),e.jsx("span",{className:"text-sm font-semibold text-white",children:n})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 rounded-full border border-gray-200",style:{backgroundColor:D}}),e.jsx("span",{className:de("text-xs",P?"text-gray-400":"text-gray-500"),children:D})]}),e.jsx("button",{type:"button",className:"rounded-md px-3 py-1.5 text-xs font-medium text-white transition-colors",style:{backgroundColor:D},tabIndex:-1,children:f("appDesigner.brandingSampleButton")}),e.jsx("p",{className:de("text-xs",P?"text-gray-400":"text-gray-500"),children:f("appDesigner.brandingSampleText")}),m.favicon&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:m.favicon,alt:"Favicon",className:"h-4 w-4 rounded object-contain"}),e.jsx("span",{className:de("text-xs",P?"text-gray-400":"text-gray-500"),children:"Favicon"})]}),m.fontFamily&&e.jsxs("div",{className:de("text-xs",P?"text-gray-400":"text-gray-500"),children:[f("appDesigner.fontFamily"),": ",m.fontFamily]})]})]}),e.jsxs("div",{"data-testid":"branding-preview-mobile",className:de("mx-auto w-48 rounded-xl border-2 p-2 transition-colors",P?"border-gray-700 bg-gray-900":"border-gray-300 bg-white"),style:{fontFamily:m.fontFamily||"inherit"},children:[e.jsx("div",{className:"text-center text-[10px] font-medium text-gray-400 mb-1",children:f("appDesigner.mobilePreview")}),e.jsx("div",{className:"rounded-md p-2 mb-1",style:{backgroundColor:D},children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.logo?e.jsx("img",{src:m.logo,alt:"Logo",className:"h-4 w-4 rounded object-contain bg-white/20"}):e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white",children:"L"}),e.jsx("span",{className:"text-[9px] font-semibold text-white truncate",children:n})]})}),e.jsxs("div",{className:"space-y-1 px-1",children:[e.jsx("div",{className:de("h-2 w-3/4 rounded",P?"bg-gray-700":"bg-gray-200")}),e.jsx("div",{className:de("h-2 w-1/2 rounded",P?"bg-gray-700":"bg-gray-200")}),e.jsx("div",{className:de("h-2 w-2/3 rounded",P?"bg-gray-700":"bg-gray-200")})]})]})]})]})]})}function qe(...t){return ie.twMerge(le.clsx(t))}function Ha({versions:t,onRestore:s,className:n}){return e.jsxs("div",{className:qe("flex flex-col",n),role:"region","aria-label":"Version history",children:[e.jsxs("div",{className:"p-3 border-b font-medium text-sm flex items-center gap-2",children:[e.jsx(u.History,{className:"h-4 w-4"}),"Version History"]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:t.length===0?e.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"No version history available"}):e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-5 top-0 bottom-0 w-px bg-border"}),t.map(i=>e.jsxs("div",{className:qe("relative flex items-start gap-3 px-3 py-2 hover:bg-accent/50",i.isCurrent&&"bg-accent/30"),children:[e.jsx("div",{className:qe("relative z-10 mt-1 h-2.5 w-2.5 rounded-full border-2 bg-background",i.isCurrent?"border-primary":"border-muted-foreground")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsxs("span",{className:"font-medium",children:["v",i.version]}),i.isCurrent&&e.jsx("span",{className:"px-1 py-0.5 rounded bg-primary/10 text-primary text-[0.6rem]",children:"Current"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:i.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-[0.65rem] text-muted-foreground/70",children:[e.jsx(u.User,{className:"h-2.5 w-2.5"}),e.jsx("span",{children:i.userName}),e.jsx(u.Clock,{className:"h-2.5 w-2.5 ml-1"}),e.jsx("span",{children:new Date(i.timestamp).toLocaleString()})]}),!i.isCurrent&&s&&e.jsx("button",{onClick:()=>s(i.version),className:"mt-1 text-[0.65rem] text-primary hover:underline",children:"Restore this version"})]})]},i.version))]})})]})}ue.ComponentRegistry.register("page-designer",nt,{label:"Page Designer",category:"Designer",inputs:[{name:"canvas",type:"code",label:"Canvas Configuration"},{name:"components",type:"code",label:"Components"},{name:"showComponentTree",type:"boolean",label:"Show Component Tree",defaultValue:!0},{name:"undoRedo",type:"boolean",label:"Undo/Redo",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("data-model-designer",lt,{label:"Data Model Designer",category:"Designer",inputs:[{name:"entities",type:"code",label:"Entities"},{name:"relationships",type:"code",label:"Relationships"},{name:"autoLayout",type:"boolean",label:"Auto Layout",defaultValue:!1},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("process-designer",it,{label:"Process Designer (BPMN)",category:"Designer",inputs:[{name:"processName",type:"string",label:"Process Name"},{name:"nodes",type:"code",label:"Nodes"},{name:"edges",type:"code",label:"Edges"},{name:"showMinimap",type:"boolean",label:"Show Minimap",defaultValue:!1},{name:"showToolbar",type:"boolean",label:"Show Toolbar",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("report-designer",dt,{label:"Report Designer",category:"Designer",inputs:[{name:"reportName",type:"string",label:"Report Name"},{name:"objectName",type:"string",label:"Data Source Object"},{name:"sections",type:"code",label:"Sections"},{name:"showToolbar",type:"boolean",label:"Show Toolbar",defaultValue:!0},{name:"showPropertyPanel",type:"boolean",label:"Show Property Panel",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("app-creation-wizard",jt,{label:"App Creation Wizard",category:"Designer",inputs:[{name:"availableObjects",type:"code",label:"Available Objects"},{name:"templates",type:"code",label:"Templates"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("navigation-designer",Dt,{label:"Navigation Designer",category:"Designer",inputs:[{name:"items",type:"code",label:"Navigation Items"},{name:"showPreview",type:"boolean",label:"Show Preview",defaultValue:!0},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("dashboard-editor",Tt,{label:"Dashboard Editor",category:"Designer",inputs:[{name:"schema",type:"code",label:"Dashboard Schema"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("page-canvas-editor",It,{label:"Page Canvas Editor",category:"Designer",inputs:[{name:"schema",type:"code",label:"Page Schema"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("object-view-configurator",Lt,{label:"Object View Configurator",category:"Designer",inputs:[{name:"config",type:"code",label:"View Config"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),ue.ComponentRegistry.register("branding-editor",At,{label:"Branding Editor",category:"Designer",inputs:[{name:"branding",type:"code",label:"Branding Config"},{name:"appTitle",type:"string",label:"App Title"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]}),te.AppCreationWizard=jt,te.BrandingEditor=At,te.CollaborationProvider=Ot,te.ConfirmDialog=Ie,te.ConnectionStatusIndicator=Ht,te.DashboardEditor=Tt,te.DataModelDesigner=lt,te.EditorModeToggle=Ta,te.Minimap=Fe,te.NavigationDesigner=Dt,te.ObjectViewConfigurator=Lt,te.PageCanvasEditor=It,te.PageDesigner=nt,te.ProcessDesigner=it,te.PropertyEditor=Le,te.ReportDesigner=dt,te.VersionHistory=Ha,te.useCanvasPanZoom=$e,te.useClipboard=Pe,te.useConfirmDialog=we,te.useDesignerHistory=ot,te.useMultiSelect=Te,te.useUndoRedo=he,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
|
|
6
|
+
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),C=m(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=x():t.exports=S()}))();function w(...e){return(0,a.twMerge)((0,i.clsx)(e))}function T({isOpen:e,title:t,message:i,confirmLabel:a=`Delete`,cancelLabel:o=`Cancel`,destructive:s=!0,onConfirm:c,onCancel:l}){let u=(0,n.useRef)(null);return(0,n.useEffect)(()=>{let t=u.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,C.jsx)(`dialog`,{ref:u,className:`fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50`,onClose:l,"aria-labelledby":`confirm-title`,"aria-describedby":`confirm-message`,children:(0,C.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[s&&(0,C.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,C.jsx)(r.AlertTriangle,{className:`h-5 w-5 text-destructive`})}),(0,C.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,C.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:i}),(0,C.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,C.jsx)(`button`,{onClick:l,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:o}),(0,C.jsx)(`button`,{onClick:c,className:w(`px-4 py-2 text-sm rounded-md font-medium`,s?`bg-destructive text-destructive-foreground hover:bg-destructive/90`:`bg-primary text-primary-foreground hover:bg-primary/90`),autoFocus:!0,children:a})]})]})}):null}function E(...e){return(0,a.twMerge)((0,i.clsx)(e))}function D({title:e=`Properties`,fields:t,onChange:i,className:a}){let[o,s]=(0,n.useState)(new Set),c=(0,n.useCallback)(e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),l=t.reduce((e,t)=>{let n=t.group??`General`;return e[n]||(e[n]=[]),e[n].push(t),e},{});return(0,C.jsxs)(`div`,{className:E(`flex flex-col`,a),role:`region`,"aria-label":e,children:[(0,C.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,C.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(l).map(([e,t])=>(0,C.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,C.jsxs)(`button`,{onClick:()=>c(e),className:`w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50`,children:[o.has(e)?(0,C.jsx)(r.ChevronRight,{className:`h-3 w-3`}):(0,C.jsx)(r.ChevronDown,{className:`h-3 w-3`}),e]}),!o.has(e)&&(0,C.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,C.jsx)(O,{field:e,onChange:i},e.name))})]},e)),t.length===0&&(0,C.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function O({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,C.jsx)(`input`,{type:`text`,value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`number`&&(0,C.jsx)(`input`,{type:`number`,value:Number(e.value??0),onChange:e=>n(Number(e.target.value)),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`boolean`&&(0,C.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,C.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,C.jsx)(`select`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`,children:e.options?.map(e=>(0,C.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`color`,value:String(e.value??`#000000`),onChange:e=>n(e.target.value),className:`h-6 w-6 rounded border cursor-pointer`}),(0,C.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,C.jsx)(`textarea`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background resize-y`,rows:3}),e.description&&(0,C.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function k(...e){return(0,a.twMerge)((0,i.clsx)(e))}function A({items:e,canvasWidth:t,canvasHeight:n,position:r=`bottom-right`,size:i=150,className:a}){let o=Math.min(i/t,i/n),s=t*o,c=n*o;return(0,C.jsx)(`div`,{className:k(`absolute border rounded bg-background/90 shadow-sm overflow-hidden`,{"top-left":`top-2 left-2`,"top-right":`top-2 right-2`,"bottom-left":`bottom-2 left-2`,"bottom-right":`bottom-2 right-2`}[r],a),role:`img`,"aria-label":`Canvas minimap`,children:(0,C.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,C.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,C.jsx)(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:e.selected?`hsl(var(--primary))`:e.color??`hsl(var(--foreground) / 0.3)`,rx:`2`},e.id))]})})}function j(...e){return(0,a.twMerge)((0,i.clsx)(e))}var M=(0,n.createContext)(null);M.displayName=`CollaborationContext`;function N({config:e,user:t,onOperation:r,onPresenceChange:i,children:a}){let o=(0,n.useRef)(null),[s,c]=(0,n.useState)([]),[l,u]=(0,n.useState)(`disconnected`),d=(0,n.useRef)(0),f=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!e.enabled||!t||!e.serverUrl||!(typeof WebSocket<`u`))return;function n(){let a;try{if(a=new URL(e.serverUrl),a.protocol!==`ws:`&&a.protocol!==`wss:`)return}catch{return}e.roomId&&a.searchParams.set(`room`,e.roomId),a.searchParams.set(`userId`,t.id),u(`connecting`);let s=new WebSocket(a.toString());s.onopen=()=>{u(`connected`),s.send(JSON.stringify({type:`join`,userId:t.id,userName:t.name,avatar:t.avatar}))},s.onmessage=e=>{try{let n=JSON.parse(e.data);if(n.type===`presence`){let e=n.users||[];c(e.filter(e=>e.userId!==t.id)),i?.(e)}else n.type===`operation`&&r?.(n.operation)}catch{}},s.onclose=()=>{u(`disconnected`),o.current=null,e.enabled&&(f.current=setTimeout(n,e.autoSaveInterval??3e3))},s.onerror=()=>{u(`error`)},o.current=s}return n(),()=>{f.current&&clearTimeout(f.current),o.current&&=(o.current.onclose=null,o.current.close(),null),u(`disconnected`)}},[e.enabled,e.serverUrl,e.roomId,e.autoSaveInterval,t,r,i]);let p=(0,n.useMemo)(()=>!e.enabled||!t?[]:[{userId:t.id,userName:t.name,avatar:t.avatar,color:I(t.id),status:`active`,lastActivity:new Date().toISOString()},...s],[e.enabled,t,s]),m=e.enabled&&!!t&&(e.serverUrl?l===`connected`:!0),h=(0,n.useCallback)(n=>{if(!e.enabled||!t)return;d.current+=1;let i={...n,id:`op-${Date.now()}-${d.current}`,userId:t.id,timestamp:new Date().toISOString(),version:d.current};o.current?.readyState===WebSocket.OPEN&&o.current.send(JSON.stringify({type:`operation`,operation:i})),r?.(i)},[e.enabled,t,r]),g=(0,n.useMemo)(()=>({users:p,isConnected:m,sendOperation:h,currentUserId:t?.id,connectionState:l,versionCount:d.current}),[p,m,h,t?.id,l]);return(0,C.jsx)(M.Provider,{value:g,children:a})}function P(){return(0,n.useContext)(M)}function F({className:e}){let t=(0,n.useContext)(M);if(!t)return null;let{connectionState:r,users:i}=t,a={connected:{color:`bg-green-500`,label:`Connected`},connecting:{color:`bg-yellow-500 animate-pulse`,label:`Connecting…`},disconnected:{color:`bg-gray-400`,label:`Disconnected`},error:{color:`bg-red-500`,label:`Connection error`}},{color:o,label:s}=a[r]??a.disconnected;return(0,C.jsxs)(`div`,{className:j(`flex items-center gap-2 text-xs`,e),role:`status`,"aria-live":`polite`,"aria-label":`Collaboration: ${s}`,children:[(0,C.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full ${o}`}),(0,C.jsx)(`span`,{children:s}),r===`connected`&&i.length>1&&(0,C.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,i.length,` users)`]})]})}function I(e){let t=[`#3b82f6`,`#ef4444`,`#22c55e`,`#f59e0b`,`#8b5cf6`,`#ec4899`,`#06b6d4`,`#f97316`,`#14b8a6`,`#f43f5e`,`#a855f7`,`#84cc16`,`#0ea5e9`,`#e879f9`,`#fb923c`,`#facc15`],n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t)|0;return t[Math.abs(n)%t.length]}function L(...e){return(0,a.twMerge)((0,i.clsx)(e))}function R({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:i=z,showComponentTree:a=!0,undoRedo:o=!0,propertyEditor:s=!0,readOnly:c=!1,showMinimap:l=!1,onChange:u,className:d}){let f=g(t),p=f.current,m=(0,n.useCallback)(e=>{f.push(e),u?.(e)},[f,u]),h=b({initialZoom:e.zoom??1}),{zoom:x}=h,S=v(),w=(0,n.useMemo)(()=>{let e=Array.from(S.selectedIds);return e.length>0?e[0]:null},[S.selectedIds]),E=(0,n.useMemo)(()=>p.find(e=>e.id===w),[p,w]),O=y(),k=_(),j=P(),M=(0,n.useCallback)(e=>{j&&j.sendOperation({...e,userId:j.currentUserId??``})},[j]),[N,F]=(0,n.useState)(!0),[I,R]=(0,n.useState)(!0),[B,V]=(0,n.useState)(l),H=(0,n.useRef)(null),ee=(0,n.useRef)(null),U=(0,n.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),te=(0,n.useCallback)((e,t)=>{if(c)return;let n=i.flatMap(e=>e.items).find(t=>t.type===e),r=n?.defaultSize,a={id:`comp-${Date.now()}`,type:e,label:t,position:{x:100,y:100,width:r?.width??200,height:r?.height??100},props:n?.defaultProps??{}};m([...p,a]),S.selectOne(a.id),M({type:`insert`,elementId:a.id,data:{component:a}})},[p,c,i,m,S,M]),W=(0,n.useCallback)(e=>{c||(m(p.filter(t=>t.id!==e)),S.isSelected(e)&&S.clearSelection(),M({type:`delete`,elementId:e,data:{}}))},[p,c,m,S,M]),G=(0,n.useCallback)(async()=>{if(c||S.count===0||!await k.confirm(`Delete components`,`Are you sure you want to delete ${S.count} component${S.count>1?`s`:``}?`))return;let e=S.selectedIds;m(p.filter(t=>!e.has(t.id))),S.clearSelection(),e.forEach(e=>{M({type:`delete`,elementId:e,data:{}})})},[c,S,k,p,m,M]),ne=(0,n.useCallback)((e,t)=>{c||!w||(m(p.map(n=>n.id===w?e===`label`?{...n,label:String(t)}:e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,props:{...n.props,[e]:t}}:n)),M({type:`update`,elementId:w,data:{[e]:t}}))},[c,w,p,m,M]),re=(0,n.useCallback)(()=>{let e=S.selectedIds;if(e.size===0)return;let t=p.filter(t=>e.has(t.id));O.copy(t)},[S,p,O]),K=(0,n.useCallback)(()=>{if(c)return;let e=O.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`comp-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}}));m([...p,...n]),S.selectMany(n.map(e=>e.id)),n.forEach(e=>{M({type:`insert`,elementId:e.id,data:{component:e}})})},[c,O,p,m,S,M]),q=(0,n.useCallback)((e,t)=>{c||(H.current={id:t.id,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[c]),ie=(0,n.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ae=(0,n.useCallback)(e=>{e.preventDefault();let t=H.current;if(!t||c)return;let n=(e.clientX-t.startX)/x,r=(e.clientY-t.startY)/x;m(p.map(e=>e.id===t.id?{...e,position:{...e.position,x:U(e.position.x+n),y:U(e.position.y+r)}}:e)),M({type:`move`,elementId:t.id,data:{}}),H.current=null},[c,x,p,m,U,M]),oe=(0,n.useMemo)(()=>E?[{name:`label`,label:`Label`,type:`text`,value:E.label??``,group:`General`},{name:`x`,label:`X`,type:`number`,value:E.position.x,group:`Position`},{name:`y`,label:`Y`,type:`number`,value:E.position.y,group:`Position`},{name:`width`,label:`Width`,type:`number`,value:E.position.width,group:`Size`},{name:`height`,label:`Height`,type:`number`,value:E.position.height,group:`Size`}]:[],[E]),se=(0,n.useMemo)(()=>p.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:typeof e.position.width==`number`?e.position.width:100,height:typeof e.position.height==`number`?e.position.height:50,selected:S.isSelected(e.id)})),[p,S]);return(0,n.useEffect)(()=>{let e=ee.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&S.count>0&&!t){e.preventDefault(),G();return}if(e.key===`Escape`){S.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&o&&!c){e.preventDefault(),f.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&o&&!c){e.preventDefault(),f.redo();return}if(n&&e.key===`c`){e.preventDefault(),re();return}if(n&&e.key===`v`&&!c){e.preventDefault(),K();return}if(n&&e.key===`a`){e.preventDefault(),S.selectMany(p.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[S,G,o,c,f,re,K,p]),(0,C.jsxs)(`div`,{ref:ee,tabIndex:0,className:L(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,d),children:[!c&&(0,C.jsx)(`div`,{className:L(`border-r bg-muted/30 flex flex-col transition-[width] duration-200`,N?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component palette`,children:N&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:i.map(e=>(0,C.jsxs)(`div`,{className:`mb-3`,children:[(0,C.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,C.jsxs)(`button`,{onClick:()=>te(e.type,e.label),className:`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left`,children:[(0,C.jsx)(r.Plus,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,C.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!c&&(0,C.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:N?`Collapse palette`:`Expand palette`,"aria-label":N?`Collapse palette`:`Expand palette`,onClick:()=>F(e=>!e),children:(0,C.jsx)(r.PanelLeftClose,{className:L(`h-4 w-4`,!N&&`rotate-180`)})}),o&&!c&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,C.jsx)(`button`,{className:L(`p-1.5 rounded hover:bg-accent`,!f.canUndo&&`opacity-40 pointer-events-none`),title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,disabled:!f.canUndo,onClick:()=>f.undo(),children:(0,C.jsx)(r.Undo2,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{className:L(`p-1.5 rounded hover:bg-accent`,!f.canRedo&&`opacity-40 pointer-events-none`),title:`Redo (Ctrl+Shift+Z)`,"aria-label":`Redo`,disabled:!f.canRedo,onClick:()=>f.redo(),children:(0,C.jsx)(r.Redo2,{className:`h-4 w-4`})}),(0,C.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`button`,{className:L(`p-1.5 rounded hover:bg-accent`,S.count===0&&`opacity-40 pointer-events-none`),title:`Copy (Ctrl+C)`,"aria-label":`Copy`,disabled:S.count===0,onClick:re,children:(0,C.jsx)(r.Copy,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{className:L(`p-1.5 rounded hover:bg-accent`,!O.hasContent&&`opacity-40 pointer-events-none`),title:`Paste (Ctrl+V)`,"aria-label":`Paste`,disabled:!O.hasContent,onClick:K,children:(0,C.jsx)(r.Clipboard,{className:`h-4 w-4`})}),(0,C.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,C.jsx)(`button`,{className:L(`p-1.5 rounded hover:bg-accent`,S.count===0&&`opacity-40 pointer-events-none`),title:`Delete selected`,"aria-label":`Delete selected`,disabled:S.count===0,onClick:G,children:(0,C.jsx)(r.Trash2,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,C.jsx)(r.Eye,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{className:L(`p-1.5 rounded hover:bg-accent`,B&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>V(e=>!e),children:(0,C.jsx)(r.Map,{className:`h-4 w-4`})}),(0,C.jsx)(`div`,{className:`flex-1`}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,C.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:h.zoomOut,children:(0,C.jsx)(r.Minus,{className:`h-3 w-3`})}),(0,C.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(x*100),`%`]}),(0,C.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:h.zoomIn,children:(0,C.jsx)(r.Plus,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:h.resetZoom,children:(0,C.jsx)(r.Maximize2,{className:`h-3 w-3`})})]}),a&&(0,C.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:I?`Collapse panel`:`Expand panel`,"aria-label":I?`Collapse panel`:`Expand panel`,onClick:()=>R(e=>!e),children:(0,C.jsx)(r.PanelRightClose,{className:L(`h-4 w-4`,!I&&`rotate-180`)})})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,role:`region`,"aria-label":`Design canvas`,onWheel:h.handleWheel,onMouseDown:h.startPan,onDragOver:ie,onDrop:ae,children:(0,C.jsxs)(`div`,{className:`relative bg-background border rounded shadow-sm mx-auto`,style:{width:e.width*x,height:e.height*x,transform:`translate(${h.panOffset.x}px, ${h.panOffset.y}px)`,backgroundImage:e.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:e.showGrid&&e.gridSize?`${e.gridSize*x}px ${e.gridSize*x}px`:void 0},children:[p.map(e=>{let t=S.isSelected(e.id);return(0,C.jsxs)(`div`,{draggable:!c,onDragStart:t=>q(t,e),className:L(`absolute border rounded cursor-move select-none transition-shadow`,t?`border-primary ring-2 ring-primary/20 shadow-md`:`border-border hover:border-primary/50`),style:{left:e.position.x*x,top:e.position.y*x,width:typeof e.position.width==`number`?e.position.width*x:e.position.width,height:typeof e.position.height==`number`?e.position.height*x:e.position.height},onClick:t=>S.toggle(e.id,t.shiftKey),children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,C.jsx)(r.GripVertical,{className:`h-3 w-3 text-muted-foreground`}),(0,C.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!c&&(0,C.jsx)(`button`,{onClick:t=>{t.stopPropagation(),W(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,C.jsx)(r.Trash2,{className:`h-3 w-3 text-destructive`})})]}),(0,C.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),B&&(0,C.jsx)(A,{items:se,canvasWidth:e.width,canvasHeight:e.height})]})})]}),a&&(0,C.jsx)(`div`,{className:L(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,I?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component tree`,children:I&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,C.jsx)(r.Layers,{className:`h-4 w-4`}),`Component Tree`]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:p.length===0?(0,C.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:`No components added yet. Click a component in the palette to add it to the canvas.`}):p.map(e=>(0,C.jsx)(`button`,{onClick:t=>S.toggle(e.id,t.shiftKey),className:L(`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left`,S.isSelected(e.id)?`bg-accent`:`hover:bg-accent/50`),children:(0,C.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),s&&E?(0,C.jsx)(`div`,{className:`border-t`,children:(0,C.jsx)(D,{title:`Properties – ${E.label??E.type}`,fields:oe,onChange:ne})}):E&&(0,C.jsxs)(`div`,{className:`border-t p-3`,children:[(0,C.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,C.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,C.jsxs)(`div`,{children:[`Type: `,E.type]}),(0,C.jsxs)(`div`,{children:[`ID: `,E.id]}),(0,C.jsxs)(`div`,{children:[`Position: `,E.position.x,`,`,` `,E.position.y]}),(0,C.jsxs)(`div`,{children:[`Size: `,E.position.width,` ×`,` `,E.position.height]})]})]})]})}),(0,C.jsx)(T,{isOpen:k.isOpen,title:k.title,message:k.message,onConfirm:k.onConfirm,onCancel:k.onCancel})]})}var z=[{name:`layout`,label:`Layout`,items:[{type:`container`,label:`Container`,defaultSize:{width:400,height:300}},{type:`flex`,label:`Flex`,defaultSize:{width:400,height:200}},{type:`grid`,label:`Grid`,defaultSize:{width:400,height:300}},{type:`card`,label:`Card`,defaultSize:{width:300,height:200}},{type:`tabs`,label:`Tabs`,defaultSize:{width:400,height:300}}]},{name:`form`,label:`Form`,items:[{type:`input`,label:`Input`,defaultSize:{width:300,height:60}},{type:`textarea`,label:`Textarea`,defaultSize:{width:300,height:120}},{type:`select`,label:`Select`,defaultSize:{width:300,height:60}},{type:`checkbox`,label:`Checkbox`,defaultSize:{width:200,height:40}},{type:`button`,label:`Button`,defaultSize:{width:120,height:40}}]},{name:`data`,label:`Data`,items:[{type:`table`,label:`Table`,defaultSize:{width:600,height:400}},{type:`chart`,label:`Chart`,defaultSize:{width:400,height:300}},{type:`list`,label:`List`,defaultSize:{width:300,height:400}},{type:`statistic`,label:`Statistic`,defaultSize:{width:200,height:100}}]}];function B(e,t={}){return g(e,t)}function V(...e){return(0,a.twMerge)((0,i.clsx)(e))}var H=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function ee(e,t=4,n=280,r=250,i=50,a=50){return e.map((e,o)=>({...e,position:{x:i+o%t*n,y:a+Math.floor(o/t)*r}}))}function U({entities:e=[],relationships:t=[],canvas:i={width:1200,height:800,showGrid:!0},showRelationshipLabels:a=!0,readOnly:o=!1,onEntitiesChange:s,onRelationshipsChange:c,className:l}){let u=(0,n.useRef)(null),d=B({entities:e,relationships:t},{maxHistory:50}),{entities:f,relationships:p}=d.current,m=(0,n.useCallback)(e=>{d.push(e),s?.(e.entities),c?.(e.relationships)},[d,s,c]),h=_(),g=v(),x=g.count>0?Array.from(g.selectedIds)[0]:null,S=y(),w=b({minZoom:.25,maxZoom:3,zoomStep:.1}),E=P(),[O,k]=(0,n.useState)(!0),[j,M]=(0,n.useState)(!0),[N,F]=(0,n.useState)(null),[I,L]=(0,n.useState)(``),[R,z]=(0,n.useState)(null),[U,te]=(0,n.useState)(``),W=(0,n.useRef)(null),G=(0,n.useCallback)(()=>{if(o)return;let e=d.current,t={id:`entity-${Date.now()}`,name:`new_entity_${e.entities.length+1}`,label:`New Entity ${e.entities.length+1}`,fields:[{name:`id`,type:`uuid`,primaryKey:!0,required:!0},{name:`created_at`,type:`datetime`,required:!0},{name:`updated_at`,type:`datetime`,required:!0}],position:{x:50+e.entities.length%4*280,y:50+Math.floor(e.entities.length/4)*250}};m({entities:[...e.entities,t],relationships:e.relationships}),g.selectOne(t.id),E?.sendOperation({type:`insert`,userId:E?.currentUserId??``,elementId:t.id,data:{name:t.name,label:t.label}})},[o,d,m,g,E]),ne=(0,n.useCallback)(async e=>{if(o)return;let t=f.find(t=>t.id===e);if(!await h.confirm(`Delete Entity`,`Are you sure you want to delete "${t?.label??e}"? This action cannot be undone.`))return;let n=d.current;m({entities:n.entities.filter(t=>t.id!==e),relationships:n.relationships.filter(t=>t.sourceEntity!==e&&t.targetEntity!==e)}),g.isSelected(e)&&g.clearSelection(),E?.sendOperation({type:`delete`,userId:E?.currentUserId??``,elementId:e,data:{}})},[o,f,h,d,m,g,E]),re=(0,n.useCallback)(async()=>{if(o||g.count===0)return;let e=Array.from(g.selectedIds);if(!await h.confirm(`Delete Entities`,`Are you sure you want to delete ${e.length} selected entity(s)? This action cannot be undone.`))return;let t=d.current,n=new Set(e);m({entities:t.entities.filter(e=>!n.has(e.id)),relationships:t.relationships.filter(e=>!n.has(e.sourceEntity)&&!n.has(e.targetEntity))}),g.clearSelection()},[o,g,h,d,m]),K=(0,n.useCallback)(()=>{if(o)return;let e=d.current;m({entities:ee(e.entities),relationships:e.relationships})},[o,d,m]),q=(0,n.useCallback)(()=>{let e=f.filter(e=>g.isSelected(e.id));e.length>0&&S.copy(e)},[f,g,S]),ie=(0,n.useCallback)(()=>{if(o)return;let e=S.paste();if(!e||e.length===0)return;let t=d.current,n=e.map((e,t)=>({...e,id:`entity-${Date.now()}-${t}`,name:`${e.name}_copy`,label:`${e.label} (Copy)`,position:{x:e.position.x+30,y:e.position.y+30}}));m({entities:[...t.entities,...n],relationships:t.relationships}),g.selectMany(n.map(e=>e.id))},[o,S,d,m,g]),ae=(0,n.useCallback)(e=>{if(o)return;let t=d.current;m({entities:t.entities.map(t=>{if(t.id!==e)return t;let n={name:`field_${t.fields.length+1}`,type:`text`,required:!1};return{...t,fields:[...t.fields,n]}}),relationships:t.relationships})},[o,d,m]),oe=(0,n.useCallback)((e,t,n)=>{o||(F({entityId:e,fieldIndex:t}),L(n))},[o]),se=(0,n.useCallback)(()=>{if(!N)return;let e=I.trim();if(e===``){F(null);return}let t=d.current;m({entities:t.entities.map(t=>{if(t.id!==N.entityId)return t;let n=t.fields.map((t,n)=>n===N.fieldIndex?{...t,name:e}:t);return{...t,fields:n}}),relationships:t.relationships}),F(null)},[N,I,d,m]),ce=(0,n.useCallback)(()=>{F(null)},[]),le=(0,n.useCallback)((e,t)=>{o||(z(e),te(t))},[o]),ue=(0,n.useCallback)(()=>{if(!R)return;let e=U.trim();if(e===``){z(null);return}let t=d.current;m({entities:t.entities.map(t=>t.id===R?{...t,label:e}:t),relationships:t.relationships}),z(null)},[R,U,d,m]),J=(0,n.useCallback)(()=>{z(null)},[]),de=(0,n.useCallback)((e,t,n)=>{if(o)return;let r=d.current;m({entities:r.entities.map(r=>{if(r.id!==e)return r;let i=r.fields.map((e,r)=>r===t?{...e,type:n}:e);return{...r,fields:i}}),relationships:r.relationships})},[o,d,m]),fe=(0,n.useCallback)((e,t)=>{if(o||!f.find(e=>e.id===t))return;let n=e.target.getBoundingClientRect();W.current={entityId:t,offsetX:e.clientX-n.left,offsetY:e.clientY-n.top},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[o,f]),Y=(0,n.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),pe=(0,n.useCallback)(e=>{if(e.preventDefault(),!W.current)return;let t=e.currentTarget.getBoundingClientRect(),n=w.zoom,r=(e.clientX-t.left-w.panOffset.x)/n-W.current.offsetX,i=(e.clientY-t.top-w.panOffset.y)/n-W.current.offsetY,a=d.current;m({entities:a.entities.map(e=>e.id===W.current.entityId?{...e,position:{x:Math.max(0,Math.round(r)),y:Math.max(0,Math.round(i))}}:e),relationships:a.relationships}),W.current=null},[w.zoom,w.panOffset,d,m]),X=x?f.find(e=>e.id===x):null,me=X?[{name:`name`,label:`Name`,type:`text`,value:X.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:X.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:X.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:X.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:X.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:X.position.y,group:`Position`}]:[],he=(0,n.useCallback)((e,t)=>{if(!x)return;let n=d.current;m({entities:n.entities.map(n=>n.id===x?e===`position.x`?{...n,position:{...n.position,x:Number(t)}}:e===`position.y`?{...n,position:{...n.position,y:Number(t)}}:{...n,[e]:t}:n),relationships:n.relationships})},[x,d,m]);(0,n.useEffect)(()=>{let e=u.current;if(!e)return;let t=e=>{let t=e.target.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;n&&e.key===`z`?(e.preventDefault(),d.undo()):n&&(e.key===`y`||e.shiftKey&&e.key===`Z`)?(e.preventDefault(),d.redo()):n&&e.key===`c`?(e.preventDefault(),q()):n&&e.key===`v`?(e.preventDefault(),ie()):(e.key===`Delete`||e.key===`Backspace`)&&g.count>0?(e.preventDefault(),re()):e.key===`Escape`&&(g.clearSelection(),F(null),z(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[d,q,ie,re,g]);let ge=f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:240,height:40+e.fields.length*24,color:e.color,selected:g.isSelected(e.id)}));return(0,C.jsxs)(`div`,{ref:u,tabIndex:0,className:V(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[(0,C.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{role:`toolbar`,"aria-label":`Designer toolbar`,className:`flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap`,children:[(0,C.jsx)(r.Database,{className:`h-4 w-4`}),(0,C.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,C.jsx)(`button`,{onClick:()=>d.undo(),disabled:!d.canUndo,"aria-label":`Undo`,title:`Undo (Ctrl+Z)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,C.jsx)(r.Undo2,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{onClick:()=>d.redo(),disabled:!d.canRedo,"aria-label":`Redo`,title:`Redo (Ctrl+Y)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,C.jsx)(r.Redo2,{className:`h-3.5 w-3.5`})})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,C.jsx)(`button`,{onClick:w.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,C.jsx)(r.ZoomOut,{className:`h-3.5 w-3.5`})}),(0,C.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(w.zoom*100),`%`]}),(0,C.jsx)(`button`,{onClick:w.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,C.jsx)(r.ZoomIn,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{onClick:w.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,C.jsx)(r.RotateCcw,{className:`h-3 w-3`})})]}),!o&&(0,C.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,C.jsx)(`button`,{onClick:q,disabled:g.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,C.jsx)(r.Copy,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{onClick:ie,disabled:!S.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,C.jsx)(r.Clipboard,{className:`h-3.5 w-3.5`})})]}),!o&&(0,C.jsxs)(`button`,{onClick:K,"aria-label":`Auto Layout`,title:`Auto Layout`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent`,children:[(0,C.jsx)(r.Grid3X3,{className:`h-3 w-3`}),` Auto Layout`]}),(0,C.jsx)(`div`,{className:`flex-1`}),E?.isConnected&&(0,C.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,C.jsx)(r.Users,{className:`h-3 w-3`}),(0,C.jsxs)(`span`,{children:[E.users.length,` user`,E.users.length===1?``:`s`]})]}),g.count>1&&(0,C.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[g.count,` selected`]}),!o&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`button`,{onClick:G,"aria-label":`Add Entity`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,C.jsx)(r.Plus,{className:`h-3 w-3`}),` Add Entity`]}),(0,C.jsxs)(`button`,{"aria-label":`Add Relationship`,title:`Add Relationship (coming soon)`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80`,children:[(0,C.jsx)(r.Link2,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,C.jsxs)(`div`,{role:`region`,"aria-label":`Canvas`,className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,onWheel:w.handleWheel,onMouseDown:w.startPan,onDragOver:Y,onDrop:pe,children:[(0,C.jsxs)(`div`,{className:`relative`,style:{width:i.width,minHeight:i.height,...w.transformStyle,backgroundImage:i.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:i.showGrid?`20px 20px`:void 0},children:[(0,C.jsx)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:p.map(e=>{let t=f.find(t=>t.id===e.sourceEntity),n=f.find(t=>t.id===e.targetEntity);return!t||!n?null:(0,C.jsxs)(`g`,{children:[(0,C.jsx)(`line`,{x1:t.position.x+120,y1:t.position.y+50,x2:n.position.x+120,y2:n.position.y+50,stroke:`hsl(var(--primary))`,strokeWidth:`2`,strokeDasharray:e.type===`many-to-many`?`5,5`:void 0}),a&&e.label&&(0,C.jsx)(`text`,{x:(t.position.x+n.position.x)/2+120,y:(t.position.y+n.position.y)/2+50-8,textAnchor:`middle`,className:`text-xs fill-muted-foreground`,children:e.label})]},e.id)})}),f.length===0&&(0,C.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-muted-foreground text-sm`,children:`No entities in the model. Click 'Add Entity' to create your first entity.`}),f.map(e=>(0,C.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!o,onDragStart:t=>fe(t,e.id),className:V(`absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing`,g.isSelected(e.id)?`border-primary ring-2 ring-primary/20`:`border-border hover:border-primary/50`),style:{left:e.position.x,top:e.position.y},onClick:t=>g.toggle(e.id,t.shiftKey),children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm`,style:{backgroundColor:e.color??`hsl(var(--primary) / 0.1)`},children:[(0,C.jsx)(r.Database,{className:`h-3.5 w-3.5`}),R===e.id?(0,C.jsx)(`input`,{type:`text`,value:U,onChange:e=>te(e.target.value),onBlur:ue,onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&J()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,C.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),le(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!o&&(0,C.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ne(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,C.jsx)(r.Trash2,{className:`h-3 w-3 text-destructive`})})]}),(0,C.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,C.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[N&&N.entityId===e.id&&N.fieldIndex===n?(0,C.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),onBlur:se,onKeyDown:e=>{e.key===`Enter`&&se(),e.key===`Escape`&&ce()},className:`font-mono text-xs px-1 py-0 border rounded bg-background w-24 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation()}):(0,C.jsxs)(`span`,{className:V(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),oe(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,C.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),o?(0,C.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,C.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),de(e.id,n,t.target.value)},onClick:e=>e.stopPropagation(),className:`text-xs text-muted-foreground ml-auto bg-transparent border-none focus:ring-1 focus:ring-primary rounded cursor-pointer p-0`,"data-testid":`field-type-${e.id}-${n}`,children:H.map(e=>(0,C.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,C.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!o&&(0,C.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,C.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),ae(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,C.jsx)(r.Plus,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),j&&f.length>0&&(0,C.jsx)(A,{items:ge,canvasWidth:i.width,canvasHeight:i.height,position:`bottom-right`,size:150})]})]}),(0,C.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,C.jsxs)(`button`,{onClick:()=>k(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 border-b`,"aria-expanded":O,"aria-controls":`property-editor-panel`,children:[O?(0,C.jsx)(r.ChevronDown,{className:`h-3 w-3`}):(0,C.jsx)(r.ChevronRight,{className:`h-3 w-3`}),`Properties`]}),O&&(0,C.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,C.jsx)(D,{title:X?X.label:`Properties`,fields:me,onChange:he})})]}),(0,C.jsx)(`div`,{className:`border-t`,children:(0,C.jsxs)(`button`,{onClick:()=>M(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 w-full`,"aria-expanded":j,children:[j?(0,C.jsx)(r.ChevronDown,{className:`h-3 w-3`}):(0,C.jsx)(r.ChevronRight,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,C.jsx)(T,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0})]})}function te(...e){return(0,a.twMerge)((0,i.clsx)(e))}var W=120,G=50;function ne(e,t){if(e.length===0)return e;let n=new Map,r=new Map;for(let t of e)n.set(t.id,0),r.set(t.id,[]);for(let e of t)n.set(e.target,(n.get(e.target)??0)+1),r.get(e.source)?.push(e.target);let i=[],a=new Set,o=e.filter(e=>(n.get(e.id)??0)===0).map(e=>e.id);for(o.length===0&&(o=[e[0].id]);o.length>0;){i.push(o);for(let e of o)a.add(e);let e=new Set;for(let t of o)for(let n of r.get(t)??[])a.has(n)||e.add(n);o=Array.from(e)}let s=e.filter(e=>!a.has(e.id)).map(e=>e.id);s.length>0&&i.push(s);let c=new Map;for(let e=0;e<i.length;e++){let t=i[e];for(let n=0;n<t.length;n++)c.set(t[n],{x:80+e*200,y:80+n*100})}return e.map(e=>({...e,position:c.get(e.id)??e.position}))}function re({processName:e=`New Process`,nodes:t=[],edges:i=[],lanes:a,canvas:o={width:1400,height:800,showGrid:!0},showMinimap:s=!0,showToolbar:c=!0,readOnly:l=!1,onNodesChange:u,onEdgesChange:d,className:f}){let p=g({nodes:t,edges:i},{maxHistory:50}),m=p.current.nodes,h=p.current.edges,x=(0,n.useCallback)((e,t)=>{p.push({nodes:e,edges:t}),u?.(e),d?.(t)},[p,u,d]),S=_(),w=v(),E=y(),O=b({initialZoom:1}),k=P(),[j,M]=(0,n.useState)(null),[N,F]=(0,n.useState)(!1),[I,L]=(0,n.useState)(null),[R,z]=(0,n.useState)(null),[B,V]=(0,n.useState)(!0),[H,ee]=(0,n.useState)(null),[U,re]=(0,n.useState)({x:0,y:0}),K=(0,n.useRef)(null),q=(0,n.useRef)(u),ie=(0,n.useRef)(d);q.current=u,ie.current=d,(0,n.useEffect)(()=>{q.current?.(m),ie.current?.(h)},[p.current]);let ae=(0,n.useCallback)((e,t)=>{if(l)return;let n={id:`node-${Date.now()}`,type:e,label:t,position:{x:200+m.length*160,y:200}};x([...m,n],h),M(n.id),w.selectOne(n.id),k?.sendOperation({type:`insert`,elementId:n.id,data:{label:t},userId:k.currentUserId??``})},[m,h,l,x,w,k]),oe=(0,n.useCallback)(async e=>{if(l)return;let t=m.find(t=>t.id===e);await S.confirm(`Delete Node`,`Are you sure you want to delete "${t?.label??e}"? This will also remove all connected edges.`)&&(x(m.filter(t=>t.id!==e),h.filter(t=>t.source!==e&&t.target!==e)),j===e&&M(null),w.clearSelection(),k?.sendOperation({type:`delete`,elementId:e,data:{},userId:k.currentUserId??``}))},[m,h,j,l,x,S,w,k]),se=(0,n.useCallback)(async()=>{if(l||w.count===0||!await S.confirm(`Delete Selected Nodes`,`Are you sure you want to delete ${w.count} selected node(s) and their connected edges?`))return;let e=w.selectedIds;x(m.filter(t=>!e.has(t.id)),h.filter(t=>!e.has(t.source)&&!e.has(t.target))),M(null),w.clearSelection()},[m,h,l,x,S,w]),ce=(0,n.useCallback)(()=>{let e=w.count>0?w.selectedIds:j?new Set([j]):new Set;if(e.size===0)return;let t=m.filter(t=>e.has(t.id));E.copy(t)},[m,j,w,E]),le=(0,n.useCallback)(()=>{if(l)return;let e=E.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));x([...m,...t],h),w.selectMany(t.map(e=>e.id)),M(t[0].id)},[l,m,h,E,x,w]),ue=(0,n.useCallback)(()=>{F(e=>e?(L(null),!1):!0)},[]),J=(0,n.useCallback)(e=>{if(!N)return!1;if(!I)return L(e),!0;if(I===e)return!0;let t={id:`edge-${Date.now()}`,source:I,target:e};return x(m,[...h,t]),L(null),F(!1),k?.sendOperation({type:`insert`,elementId:t.id,data:{source:I,target:e},userId:k.currentUserId??``}),!0},[N,I,m,h,x,k]),de=(0,n.useCallback)(()=>{l||m.length===0||x(ne(m,h),h)},[m,h,l,x]),fe=(0,n.useCallback)((e,t)=>{if(l||!m.find(e=>e.id===t))return;ee(t);let n=e.target.getBoundingClientRect();re({x:e.clientX-n.left,y:e.clientY-n.top}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[l,m]),Y=(0,n.useCallback)(e=>{if(e.preventDefault(),l||!H)return;let t=e.currentTarget.getBoundingClientRect(),n=O.zoom,r=(e.clientX-t.left-O.panOffset.x)/n-U.x,i=(e.clientY-t.top-O.panOffset.y)/n-U.y,a=Math.max(0,Math.round(r/20)*20),o=Math.max(0,Math.round(i/20)*20);x(m.map(e=>e.id===H?{...e,position:{x:a,y:o}}:e),h),ee(null)},[l,H,U,m,h,O.zoom,O.panOffset,x]),pe=(0,n.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),X=(0,n.useMemo)(()=>m.find(e=>e.id===j)??null,[m,j]),me=(0,n.useMemo)(()=>X?[{name:`label`,label:`Name`,type:`text`,value:X.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:X.type,options:[{label:`Start Event`,value:`start-event`},{label:`End Event`,value:`end-event`},{label:`User Task`,value:`user-task`},{label:`Service Task`,value:`service-task`},{label:`Script Task`,value:`script-task`},{label:`Exclusive Gateway`,value:`exclusive-gateway`},{label:`Parallel Gateway`,value:`parallel-gateway`},{label:`Inclusive Gateway`,value:`inclusive-gateway`}],group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:X.description??``,group:`General`}]:[],[X]),he=(0,n.useCallback)((e,t)=>{l||!j||x(m.map(n=>n.id===j?{...n,[e]:t}:n),h)},[l,j,m,h,x]),ge=e=>{switch(e){case`start-event`:return`rounded-full bg-green-100 border-green-500 text-green-700`;case`end-event`:return`rounded-full bg-red-100 border-red-500 text-red-700`;case`exclusive-gateway`:case`parallel-gateway`:case`inclusive-gateway`:case`event-based-gateway`:return`rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700`;case`user-task`:return`rounded bg-blue-100 border-blue-500 text-blue-700`;case`service-task`:case`script-task`:return`rounded bg-purple-100 border-purple-500 text-purple-700`;default:return`rounded bg-gray-100 border-gray-500 text-gray-700`}},_e=(0,n.useMemo)(()=>m.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:W,height:G,selected:w.isSelected(e.id)||e.id===j})),[m,w,j]);(0,n.useEffect)(()=>{let e=K.current;if(!e)return;let t=e=>{let t=e.target?.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;if(n&&e.key===`z`&&!e.shiftKey){e.preventDefault(),p.undo();return}if(n&&e.key===`y`||n&&e.key===`z`&&e.shiftKey){e.preventDefault(),p.redo();return}if(n&&e.key===`c`){e.preventDefault(),ce();return}if(n&&e.key===`v`){e.preventDefault(),le();return}if(e.key===`Delete`||e.key===`Backspace`){w.count>0?(e.preventDefault(),se()):j&&(e.preventDefault(),oe(j));return}if(e.key===`Escape`){N?(F(!1),L(null)):(M(null),w.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[j,N,w,p,ce,le,oe,se]);let ve=(0,n.useCallback)(e=>{e.target===e.currentTarget&&(M(null),w.clearSelection(),N&&(F(!1),L(null)))},[N,w]);return(0,C.jsxs)(`div`,{ref:K,tabIndex:0,className:te(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,f),children:[(0,C.jsx)(T,{isOpen:S.isOpen,title:S.title,message:S.message,onConfirm:S.onConfirm,onCancel:S.onCancel,destructive:!0}),c&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,C.jsx)(r.GitBranch,{className:`h-4 w-4`}),(0,C.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),k?.isConnected&&(0,C.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,C.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),k.users.length,` user`,k.users.length===1?``:`s`]}),(0,C.jsx)(`div`,{className:`flex-1`}),!l&&(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,C.jsx)(`button`,{onClick:()=>p.undo(),disabled:!p.canUndo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,children:(0,C.jsx)(r.Undo2,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:()=>p.redo(),disabled:!p.canRedo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Redo (Ctrl+Y)`,"aria-label":`Redo`,children:(0,C.jsx)(r.Redo2,{className:`h-3 w-3`})}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,C.jsx)(`button`,{onClick:ce,disabled:w.count===0&&!j,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Copy (Ctrl+C)`,"aria-label":`Copy`,children:(0,C.jsx)(r.Copy,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:le,disabled:!E.hasContent,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Paste (Ctrl+V)`,"aria-label":`Paste`,children:(0,C.jsx)(r.Clipboard,{className:`h-3 w-3`})}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,C.jsxs)(`button`,{onClick:ue,className:te(`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,N&&`bg-primary text-primary-foreground`),title:`Connect nodes`,"aria-label":`Connect nodes`,"aria-pressed":N,children:[(0,C.jsx)(r.Link,{className:`h-3 w-3`}),` Connect`]}),(0,C.jsxs)(`button`,{onClick:de,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,C.jsx)(r.Layout,{className:`h-3 w-3`}),` Layout`]}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,C.jsx)(`button`,{onClick:O.zoomIn,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom in`,"aria-label":`Zoom in`,children:(0,C.jsx)(r.ZoomIn,{className:`h-3 w-3`})}),(0,C.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(O.zoom*100),`%`]}),(0,C.jsx)(`button`,{onClick:O.zoomOut,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom out`,"aria-label":`Zoom out`,children:(0,C.jsx)(r.ZoomOut,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:O.resetZoom,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Reset zoom`,"aria-label":`Reset zoom`,children:(0,C.jsx)(r.RotateCcw,{className:`h-3 w-3`})}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,C.jsxs)(`button`,{onClick:()=>ae(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,C.jsx)(r.Play,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,C.jsxs)(`button`,{onClick:()=>ae(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,C.jsx)(r.Square,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,C.jsxs)(`button`,{onClick:()=>ae(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,C.jsx)(r.Diamond,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,C.jsxs)(`button`,{onClick:()=>ae(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,C.jsx)(r.Square,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,C.jsx)(`button`,{onClick:()=>V(e=>!e),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:B?`Hide properties`:`Show properties`,"aria-label":B?`Hide property panel`:`Show property panel`,"aria-expanded":B,children:B?(0,C.jsx)(r.PanelRightClose,{className:`h-3 w-3`}):(0,C.jsx)(r.PanelRightOpen,{className:`h-3 w-3`})})]})]}),(0,C.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,C.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4`,role:`region`,"aria-label":`Process canvas`,onWheel:O.handleWheel,onMouseDown:O.startPan,children:(0,C.jsxs)(`div`,{className:`relative`,style:{...O.transformStyle,width:o.width,minHeight:o.height,backgroundImage:o.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:o.showGrid?`20px 20px`:void 0},onClick:ve,onDrop:Y,onDragOver:pe,children:[(0,C.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:o.width,height:o.height,children:[(0,C.jsx)(`defs`,{children:(0,C.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,C.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--foreground))`})})}),h.map(e=>{let t=m.find(t=>t.id===e.source),n=m.find(t=>t.id===e.target);if(!t||!n)return null;t.position.x+W/2;let r=t.position.y+G/2;n.position.x+W/2;let i=n.position.y+G/2,a=t.position.x+W,o=r,s=n.position.x,c=i;return(0,C.jsxs)(`g`,{children:[(0,C.jsx)(`path`,{d:`M ${a} ${o} Q ${(a+s)/2} ${o}, ${(a+s)/2} ${(o+c)/2} T ${s} ${c}`,fill:`none`,stroke:`hsl(var(--foreground) / 0.5)`,strokeWidth:`2`,markerEnd:`url(#arrowhead)`}),e.label&&(0,C.jsx)(`text`,{x:(a+s)/2,y:(o+c)/2-8,textAnchor:`middle`,className:`text-[10px] fill-muted-foreground`,children:e.label})]},e.id)})]}),m.length===0&&(0,C.jsx)(`div`,{className:`flex items-center justify-center h-full min-h-[200px] text-muted-foreground text-sm`,children:`No nodes in the process. Use the toolbar buttons to add start events, tasks, gateways, and end events.`}),m.map(e=>{let t=w.isSelected(e.id)||j===e.id,n=I===e.id,i=R===e.id,a=N||i;return(0,C.jsxs)(`div`,{className:`absolute select-none`,style:{left:e.position.x,top:e.position.y},role:`group`,"aria-label":e.label,draggable:!l&&!N,onDragStart:t=>fe(t,e.id),onMouseEnter:()=>z(e.id),onMouseLeave:()=>z(null),onClick:t=>{J(e.id)||(t.shiftKey?w.toggle(e.id,!0):(M(e.id),w.selectOne(e.id)))},children:[(0,C.jsx)(`div`,{className:te(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,ge(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,N&&!n&&`cursor-crosshair`),children:(0,C.jsx)(`span`,{className:te(`text-xs font-medium`,(e.type===`exclusive-gateway`||e.type===`parallel-gateway`||e.type===`inclusive-gateway`||e.type===`event-based-gateway`)&&`-rotate-45`),children:e.label})}),a&&!l&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:G/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),J(e.id)}}),(0,C.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:G/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),N?J(e.id):(F(!0),L(e.id))}}),(0,C.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:W/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),J(e.id)}}),(0,C.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:W/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),J(e.id)}})]}),!l&&t&&!N&&(0,C.jsx)(`button`,{onClick:t=>{t.stopPropagation(),oe(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,C.jsx)(r.Trash2,{className:`h-3 w-3`})})]},e.id)}),s&&m.length>0&&(0,C.jsx)(A,{items:_e,canvasWidth:o.width??1400,canvasHeight:o.height??800,position:`bottom-right`})]})}),B&&!l&&(0,C.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto flex-shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,C.jsx)(D,{title:X?`Properties: ${X.label}`:`Properties`,fields:me,onChange:he})})]})]})}function K(...e){return(0,a.twMerge)((0,i.clsx)(e))}var q={untitledReport:`Untitled Report`,reportCanvas:`Report canvas`,properties:`Properties`,propertiesPanel:`Properties panel`,designerToolbar:`Report designer toolbar`,selectElementPrompt:`Select an element to edit its properties`,addElementsPrompt:`Add elements using the buttons above`,addText:`Add Text`,addField:`Add Field`,addImage:`Add Image`,addChart:`Add Chart`,addTable:`Add Table`,undo:`Undo`,undoShortcut:`Undo (Ctrl+Z)`,redo:`Redo`,redoShortcut:`Redo (Ctrl+Shift+Z)`,copy:`Copy`,copyShortcut:`Copy (Ctrl+C)`,paste:`Paste`,pasteShortcut:`Paste (Ctrl+V)`,deleteSelected:`Delete selected`,deleteElement:`Delete element`,deleteElementsTitle:`Delete elements`,deleteElementMessage:e=>`Are you sure you want to delete ${e} element${e>1?`s`:``}?`,collapsePanel:`Collapse panel`,expandPanel:`Expand panel`,collaborationConnected:`Connected`,sectionHeader:`Report Header`,sectionPageHeader:`Page Header`,sectionGroupHeader:`Group Header`,sectionDetail:`Detail`,sectionGroupFooter:`Group Footer`,sectionPageFooter:`Page Footer`,sectionFooter:`Report Footer`,elementText:`Text`,elementImage:`🖼 Image`,elementChart:`📊 Chart`,elementTable:`📋 Table`,propLabel:`Label`,propX:`X`,propY:`Y`,propWidth:`Width`,propHeight:`Height`,propText:`Text`,propField:`Field`,groupPosition:`Position`,groupSize:`Size`,groupContent:`Content`,groupGeneral:`General`},ie={A4:{width:595,height:842},A3:{width:842,height:1191},Letter:{width:612,height:792},Legal:{width:612,height:1008},Tabloid:{width:792,height:1224}},ae=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function oe({reportName:e=q.untitledReport,objectName:t,pageSize:i=`A4`,orientation:a=`portrait`,margins:o={top:40,right:40,bottom:40,left:40},sections:s=[],showToolbar:c=!0,showPropertyPanel:l=!0,readOnly:u=!1,onSectionsChange:d,className:f}){let p=g(s.length>0?s:ae),m=p.current,h=(0,n.useCallback)(e=>{p.push(e),d?.(e)},[p,d]),b=v(),x=(0,n.useMemo)(()=>{let e=Array.from(b.selectedIds);return e.length>0?e[0]:null},[b.selectedIds]),S=y(),w=_(),E=P(),O=(0,n.useCallback)(e=>{E&&E.sendOperation({...e,userId:E.currentUserId??``})},[E]),[k,A]=(0,n.useState)(!0),j=(0,n.useRef)(null),M=(0,n.useRef)(null),N=ie[i],F=a===`landscape`?N.height:N.width,I=a===`landscape`?N.width:N.height,L=e=>{switch(e){case`header`:return q.sectionHeader;case`page-header`:return q.sectionPageHeader;case`group-header`:return q.sectionGroupHeader;case`detail`:return q.sectionDetail;case`group-footer`:return q.sectionGroupFooter;case`page-footer`:return q.sectionPageFooter;case`footer`:return q.sectionFooter;default:return e}},R=(0,n.useMemo)(()=>x?m.flatMap(e=>e.elements).find(e=>e.id===x):null,[x,m]),z=(0,n.useCallback)((e,t)=>{if(u)return;let n={id:`elem-${Date.now()}`,type:t,position:{x:o.left,y:10,width:200,height:30},properties:{text:t===`text`?`New Text`:void 0,field:t===`field`?`field_name`:void 0}};h(m.map((t,r)=>r===e?{...t,elements:[...t.elements,n]}:t)),b.selectOne(n.id),O({type:`insert`,elementId:n.id,data:{element:n}})},[m,o.left,u,h,b,O]),B=(0,n.useCallback)(e=>{u||(h(m.map(t=>({...t,elements:t.elements.filter(t=>t.id!==e)}))),b.isSelected(e)&&b.clearSelection(),O({type:`delete`,elementId:e,data:{}}))},[m,u,h,b,O]),V=(0,n.useCallback)(async()=>{if(u||b.count===0||!await w.confirm(q.deleteElementsTitle,q.deleteElementMessage(b.count)))return;let e=b.selectedIds;h(m.map(t=>({...t,elements:t.elements.filter(t=>!e.has(t.id))}))),b.clearSelection(),e.forEach(e=>{O({type:`delete`,elementId:e,data:{}})})},[u,b,w,m,h,O]),H=(0,n.useCallback)((e,t)=>{u||!x||(h(m.map(n=>({...n,elements:n.elements.map(n=>n.id===x?e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,properties:{...n.properties,[e]:t}}:n)}))),O({type:`update`,elementId:x,data:{[e]:t}}))},[u,x,m,h,O]),ee=(0,n.useCallback)(()=>{let e=b.selectedIds;if(e.size===0)return;let t=m.flatMap(e=>e.elements).filter(t=>e.has(t.id));S.copy(t)},[b,m,S]),U=(0,n.useCallback)(()=>{if(u)return;let e=S.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`elem-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}})),r=m.findIndex(e=>e.type===`detail`),i=r>=0?r:0;h(m.map((e,t)=>t===i?{...e,elements:[...e.elements,...n]}:e)),b.selectMany(n.map(e=>e.id)),n.forEach(e=>{O({type:`insert`,elementId:e.id,data:{element:e}})})},[u,S,m,h,b,O]),te=(0,n.useCallback)((e,t,n)=>{u||(j.current={id:t.id,sectionIndex:n,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[u]),W=(0,n.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),G=(0,n.useCallback)((e,t)=>{e.preventDefault();let n=j.current;if(!n||u)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;if(n.sectionIndex===t)h(m.map((e,a)=>a===t?{...e,elements:e.elements.map(e=>e.id===n.id?{...e,position:{...e.position,x:Math.max(0,e.position.x+r),y:Math.max(0,(typeof e.position.y==`number`?e.position.y:0)+i)}}:e)}:e));else{let e=null,i=m.map((t,i)=>{if(i!==n.sectionIndex)return t;let a=t.elements.find(e=>e.id===n.id);return a&&(e={...a,position:{...a.position,x:Math.max(0,a.position.x+r),y:10}}),{...t,elements:t.elements.filter(e=>e.id!==n.id)}});e&&h(i.map((n,r)=>r===t?{...n,elements:[...n.elements,e]}:n))}O({type:`move`,elementId:n.id,data:{}}),j.current=null},[u,m,h,O]),ne=(0,n.useMemo)(()=>{if(!R)return[];let e=[{name:`x`,label:q.propX,type:`number`,value:R.position.x,group:q.groupPosition},{name:`y`,label:q.propY,type:`number`,value:R.position.y,group:q.groupPosition},{name:`width`,label:q.propWidth,type:`number`,value:R.position.width,group:q.groupSize},{name:`height`,label:q.propHeight,type:`number`,value:R.position.height,group:q.groupSize}];return R.type===`text`&&e.push({name:`text`,label:q.propText,type:`text`,value:R.properties.text??``,group:q.groupContent}),R.type===`field`&&e.push({name:`field`,label:q.propField,type:`text`,value:R.properties.field??``,group:q.groupContent}),e},[R]);return(0,n.useEffect)(()=>{let e=M.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&b.count>0&&!t){e.preventDefault(),V();return}if(e.key===`Escape`){b.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&!u){e.preventDefault(),p.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&!u){e.preventDefault(),p.redo();return}if(n&&e.key===`c`){e.preventDefault(),ee();return}if(n&&e.key===`v`&&!u){e.preventDefault(),U();return}if(n&&e.key===`a`){e.preventDefault();let t=m.flatMap(e=>e.elements).map(e=>e.id);b.selectMany(t);return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,V,u,p,ee,U,m]),(0,C.jsxs)(`div`,{ref:M,tabIndex:0,className:K(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,f),children:[(0,C.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[c&&(0,C.jsxs)(`div`,{role:`toolbar`,"aria-label":q.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,C.jsx)(r.FileText,{className:`h-4 w-4`}),(0,C.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,C.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!u&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,C.jsx)(`button`,{className:K(`p-1.5 rounded hover:bg-accent`,!p.canUndo&&`opacity-40 pointer-events-none`),title:q.undoShortcut,"aria-label":q.undo,disabled:!p.canUndo,onClick:()=>p.undo(),children:(0,C.jsx)(r.Undo2,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{className:K(`p-1.5 rounded hover:bg-accent`,!p.canRedo&&`opacity-40 pointer-events-none`),title:q.redoShortcut,"aria-label":q.redo,disabled:!p.canRedo,onClick:()=>p.redo(),children:(0,C.jsx)(r.Redo2,{className:`h-4 w-4`})}),(0,C.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!u&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`button`,{className:K(`p-1.5 rounded hover:bg-accent`,b.count===0&&`opacity-40 pointer-events-none`),title:q.copyShortcut,"aria-label":q.copy,disabled:b.count===0,onClick:ee,children:(0,C.jsx)(r.Copy,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{className:K(`p-1.5 rounded hover:bg-accent`,!S.hasContent&&`opacity-40 pointer-events-none`),title:q.pasteShortcut,"aria-label":q.paste,disabled:!S.hasContent,onClick:U,children:(0,C.jsx)(r.Clipboard,{className:`h-4 w-4`})}),(0,C.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!u&&(0,C.jsx)(`button`,{className:K(`p-1.5 rounded hover:bg-accent`,b.count===0&&`opacity-40 pointer-events-none`),title:q.deleteSelected,"aria-label":q.deleteSelected,disabled:b.count===0,onClick:V,children:(0,C.jsx)(r.Trash2,{className:`h-4 w-4`})}),(0,C.jsx)(`div`,{className:`flex-1`}),E?.isConnected&&(0,C.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,C.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),q.collaborationConnected,E.users.length>1&&` (${E.users.length})`]}),(0,C.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[i,` `,a]}),l&&(0,C.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:k?q.collapsePanel:q.expandPanel,"aria-label":k?q.collapsePanel:q.expandPanel,onClick:()=>A(e=>!e),children:(0,C.jsx)(r.PanelRightClose,{className:K(`h-4 w-4`,!k&&`rotate-180`)})})]}),(0,C.jsx)(`div`,{role:`region`,"aria-label":q.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,C.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:F,minHeight:I},children:m.map((e,t)=>(0,C.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:W,onDrop:e=>G(e,t),children:[(0,C.jsxs)(`div`,{className:`absolute left-0 top-0 px-2 py-0.5 bg-muted text-xs text-muted-foreground border-r border-b rounded-br`,children:[L(e.type),e.repeat&&` ↻`]}),!u&&(0,C.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,C.jsx)(`button`,{onClick:()=>z(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:q.addText,"aria-label":q.addText,children:(0,C.jsx)(r.Type,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:()=>z(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:q.addField,"aria-label":q.addField,children:(0,C.jsx)(r.Plus,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:()=>z(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:q.addImage,"aria-label":q.addImage,children:(0,C.jsx)(r.ImageIcon,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:()=>z(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:q.addChart,"aria-label":q.addChart,children:(0,C.jsx)(r.BarChart3,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{onClick:()=>z(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:q.addTable,"aria-label":q.addTable,children:(0,C.jsx)(r.Table2,{className:`h-3 w-3`})})]}),(0,C.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,C.jsx)(`div`,{className:`text-xs text-muted-foreground text-center pt-4`,children:q.addElementsPrompt}),e.elements.map(e=>{let n=b.isSelected(e.id);return(0,C.jsxs)(`div`,{draggable:!u,onDragStart:n=>te(n,e,t),className:K(`absolute border rounded px-2 py-1 text-xs cursor-pointer`,n?`border-primary ring-1 ring-primary/30 bg-primary/5`:`border-dashed border-gray-400 hover:border-primary/50`),style:{left:e.position.x,top:(typeof e.position.y==`number`?e.position.y:0)+24,width:e.position.width,height:e.position.height},onClick:t=>b.toggle(e.id,t.shiftKey),children:[(0,C.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.type===`text`&&(e.properties.text??q.elementText),e.type===`field`&&`{${e.properties.field??`field`}}`,e.type===`image`&&q.elementImage,e.type===`chart`&&q.elementChart,e.type===`table`&&q.elementTable]}),!u&&n&&(0,C.jsx)(`button`,{onClick:t=>{t.stopPropagation(),B(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":q.deleteElement,children:(0,C.jsx)(r.Trash2,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),l&&(0,C.jsx)(`div`,{role:`region`,"aria-label":q.propertiesPanel,className:K(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,k?`w-56`:`w-0 overflow-hidden`),children:k&&(x&&R?(0,C.jsx)(D,{title:`${q.properties} – ${R.type}`,fields:ne,onChange:H}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:q.properties}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,C.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:q.selectElementPrompt})})]}))}),(0,C.jsx)(T,{isOpen:w.isOpen,title:w.title,message:w.message,onConfirm:w.onConfirm,onCancel:w.onCancel})]})}var se=(e,t,n,r)=>{let i=[n,{code:t,...r||{}}];if(e?.services?.logger?.forward)return e.services.logger.forward(i,`warn`,`react-i18next::`,!0);Y(i[0])&&(i[0]=`react-i18next:: ${i[0]}`),e?.services?.logger?.warn?e.services.logger.warn(...i):console?.warn&&console.warn(...i)},ce={},le=(e,t,n,r)=>{Y(n)&&ce[n]||(Y(n)&&(ce[n]=new Date),se(e,t,n,r))},ue=(e,t)=>()=>{if(e.isInitialized)t();else{let n=()=>{setTimeout(()=>{e.off(`initialized`,n)},0),t()};e.on(`initialized`,n)}},J=(e,t,n)=>{e.loadNamespaces(t,ue(e,n))},de=(e,t,n,r)=>{if(Y(n)&&(n=[n]),e.options.preload&&e.options.preload.indexOf(t)>-1)return J(e,n,r);n.forEach(t=>{e.options.ns.indexOf(t)<0&&e.options.ns.push(t)}),e.loadLanguages(t,ue(e,r))},fe=(e,t,n={})=>!t.languages||!t.languages.length?(le(t,`NO_LANGUAGES`,`i18n.languages were undefined or empty`,{languages:t.languages}),!0):t.hasLoadedNamespace(e,{lng:n.lng,precheck:(t,r)=>{if(n.bindI18n&&n.bindI18n.indexOf(`languageChanging`)>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!r(t.isLanguageChangingTo,e))return!1}}),Y=e=>typeof e==`string`,pe=e=>typeof e==`object`&&!!e,X=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,me={"&":`&`,"&":`&`,"<":`<`,"<":`<`,">":`>`,">":`>`,"'":`'`,"'":`'`,""":`"`,""":`"`," ":` `," ":` `,"©":`©`,"©":`©`,"®":`®`,"®":`®`,"…":`…`,"…":`…`,"/":`/`,"/":`/`},he=e=>me[e],ge={bindI18n:`languageChanged`,bindI18nStore:``,transEmptyNodeValue:``,transSupportBasicHtmlNodes:!0,transWrapTextNodes:``,transKeepBasicHtmlNodesFor:[`br`,`strong`,`i`,`p`],useSuspense:!0,unescape:e=>e.replace(X,he),transDefaultProps:void 0},_e=()=>ge,ve,ye=()=>ve,be=(0,n.createContext)(),xe=class{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(e=>{this.usedNamespaces[e]||(this.usedNamespaces[e]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}},Se=m((e=>{var t=require(`react`);function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var r=typeof Object.is==`function`?Object.is:n,i=t.useState,a=t.useEffect,o=t.useLayoutEffect,s=t.useDebugValue;function c(e,t){var n=t(),r=i({inst:{value:n,getSnapshot:t}}),c=r[0].inst,u=r[1];return o(function(){c.value=n,c.getSnapshot=t,l(c)&&u({inst:c})},[e,n,t]),a(function(){return l(c)&&u({inst:c}),e(function(){l(c)&&u({inst:c})})},[e]),s(n),n}function l(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}function u(e,t){return t()}var d=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?u:c;e.useSyncExternalStore=t.useSyncExternalStore===void 0?d:t.useSyncExternalStore})),Ce=m((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}function n(e,t){d||a.startTransition===void 0||(d=!0,console.error(`You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.`));var n=t();if(!f){var i=t();o(n,i)||(console.error(`The result of getSnapshot should be cached to avoid an infinite loop`),f=!0)}i=s({inst:{value:n,getSnapshot:t}});var p=i[0].inst,m=i[1];return l(function(){p.value=n,p.getSnapshot=t,r(p)&&m({inst:p})},[e,n,t]),c(function(){return r(p)&&m({inst:p}),e(function(){r(p)&&m({inst:p})})},[e]),u(n),n}function r(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!o(e,n)}catch{return!0}}function i(e,t){return t()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart==`function`&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var a=require(`react`),o=typeof Object.is==`function`?Object.is:t,s=a.useState,c=a.useEffect,l=a.useLayoutEffect,u=a.useDebugValue,d=!1,f=!1,p=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?i:n;e.useSyncExternalStore=a.useSyncExternalStore===void 0?p:a.useSyncExternalStore,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop==`function`&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()})),we=m(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=Se():t.exports=Ce()}))(),Te={t:(e,t)=>{if(Y(t))return t;if(pe(t)&&Y(t.defaultValue))return t.defaultValue;if(typeof e==`function`)return``;if(Array.isArray(e)){let t=e[e.length-1];return typeof t==`function`?``:t}return e},ready:!1},Ee=()=>()=>{},De=(e,t={})=>{let{i18n:r}=t,{i18n:i,defaultNS:a}=(0,n.useContext)(be)||{},o=r||i||ye();o&&!o.reportNamespaces&&(o.reportNamespaces=new xe),o||le(o,`NO_I18NEXT_INSTANCE`,`useTranslation: You will need to pass in an i18next instance by using initReactI18next`);let s=(0,n.useMemo)(()=>({..._e(),...o?.options?.react,...t}),[o,t]),{useSuspense:c,keyPrefix:l}=s,u=e||a||o?.options?.defaultNS,d=Y(u)?[u]:u||[`translation`],f=(0,n.useMemo)(()=>d,d);o?.reportNamespaces?.addUsedNamespaces?.(f);let p=(0,n.useRef)(0),m=(0,n.useCallback)(e=>{if(!o)return Ee;let{bindI18n:t,bindI18nStore:n}=s,r=()=>{p.current+=1,e()};return t&&o.on(t,r),n&&o.store.on(n,r),()=>{t&&t.split(` `).forEach(e=>o.off(e,r)),n&&n.split(` `).forEach(e=>o.store.off(e,r))}},[o,s]),h=(0,n.useRef)(),g=(0,n.useCallback)(()=>{if(!o)return Te;let e=!!(o.isInitialized||o.initializedStoreOnce)&&f.every(e=>fe(e,o,s)),n=t.lng||o.language,r=p.current,i=h.current;if(i&&i.ready===e&&i.lng===n&&i.keyPrefix===l&&i.revision===r)return i;let a={t:o.getFixedT(n,s.nsMode===`fallback`?f:f[0],l),ready:e,lng:n,keyPrefix:l,revision:r};return h.current=a,a},[o,f,l,s,t.lng]),[_,v]=(0,n.useState)(0),{t:y,ready:b}=(0,we.useSyncExternalStore)(m,g,g);(0,n.useEffect)(()=>{if(o&&!b&&!c){let e=()=>v(e=>e+1);t.lng?de(o,t.lng,f,e):J(o,f,e)}},[o,t.lng,f,b,c,_]);let x=o||{},S=(0,n.useRef)(null),C=(0,n.useRef)(),w=e=>{let t=Object.getOwnPropertyDescriptors(e);t.__original&&delete t.__original;let n=Object.create(Object.getPrototypeOf(e),t);if(!Object.prototype.hasOwnProperty.call(n,`__original`))try{Object.defineProperty(n,`__original`,{value:e,writable:!1,enumerable:!1,configurable:!1})}catch{}return n},T=(0,n.useMemo)(()=>{let e=x,t=e?.language,n=e;e&&(S.current&&S.current.__original===e&&C.current===t?n=S.current:(n=w(e),S.current=n,C.current=t));let r=!b&&!c?(...e)=>(le(o,`USE_T_BEFORE_READY`,`useTranslation: t was called before ready. When using useSuspense: false, make sure to check the ready flag before using t.`),y(...e)):y,i=[r,n,b];return i.t=r,i.i18n=n,i.ready=b,i},[y,x,b,x.resolvedLanguage,x.language,x.languages]);if(o&&c&&!b)throw new Promise(e=>{let n=()=>e();t.lng?de(o,t.lng,f,n):J(o,f,n)});return T},Oe=(0,n.createContext)(null);function ke(e){let t=(0,n.useContext)(Oe),{t:r,i18n:i}=De(e);return{t:r,language:t?.language||i.language||`en`,changeLanguage:t?.changeLanguage||(async e=>{await i.changeLanguage(e)}),direction:t?.direction||`ltr`,i18n:i}}var Ae={"appDesigner.basicInfo":`Basic Info`,"appDesigner.objects":`Objects`,"appDesigner.navigation":`Navigation`,"appDesigner.branding":`Branding`,"appDesigner.stepBasicDesc":`Name, title, and layout`,"appDesigner.stepObjectsDesc":`Select business objects`,"appDesigner.stepNavigationDesc":`Build navigation tree`,"appDesigner.stepBrandingDesc":`Logo, colors, and favicon`,"appDesigner.appName":`App Name`,"appDesigner.appTitle":`Title`,"appDesigner.appDescription":`Description`,"appDesigner.appIcon":`Icon`,"appDesigner.template":`Template`,"appDesigner.layout":`Layout`,"appDesigner.layoutSidebar":`Sidebar`,"appDesigner.layoutHeader":`Header`,"appDesigner.layoutEmpty":`Empty`,"appDesigner.snakeCaseHint":`Must be snake_case (e.g. my_app)`,"appDesigner.searchObjects":`Search objects…`,"appDesigner.selectAll":`Select All`,"appDesigner.deselectAll":`Deselect All`,"appDesigner.noObjectsFound":`No objects found.`,"appDesigner.addGroup":`Add Group`,"appDesigner.addUrl":`Add URL`,"appDesigner.addSeparator":`Add Separator`,"appDesigner.noNavItemsHint":`No navigation items yet. Select objects in the previous step or add items manually.`,"appDesigner.separatorLabel":`— Separator —`,"appDesigner.newGroup":`New Group`,"appDesigner.newLink":`New Link`,"appDesigner.logoUrl":`Logo URL`,"appDesigner.primaryColor":`Primary Color`,"appDesigner.faviconUrl":`Favicon URL`,"appDesigner.preview":`Preview`,"common.cancel":`Cancel`,"common.back":`Back`,"common.next":`Next`,"common.close":`Close`,"appDesigner.complete":`Complete`,"appDesigner.saveDraft":`Save Draft`,"appDesigner.cancelConfirmTitle":`Discard changes?`,"appDesigner.cancelConfirmMessage":`You have unsaved changes. Are you sure you want to cancel?`,"appDesigner.confirmDiscard":`Discard`,"appDesigner.keepEditing":`Keep Editing`,"appDesigner.navNoItems":`No navigation items. Click buttons above to add items.`,"appDesigner.navNoPreviewItems":`No items`,"appDesigner.navLivePreview":`Live Preview`,"appDesigner.navCollapseGroup":`Collapse group`,"appDesigner.navExpandGroup":`Expand group`,"appDesigner.navAddChild":`Add child`,"appDesigner.navMoveUp":`Move up`,"appDesigner.navMoveDown":`Move down`,"appDesigner.navRemove":`Remove`,"appDesigner.navObjectPage":`Object Page`,"appDesigner.navDashboard":`Dashboard`,"appDesigner.navPage":`Page`,"appDesigner.navReport":`Report`,"appDesigner.navGroup":`Group`,"appDesigner.navUrl":`URL`,"appDesigner.navSeparator":`Separator`,"appDesigner.navTypeObject":`Object`,"appDesigner.navTypeDashboard":`Dashboard`,"appDesigner.navTypePage":`Page`,"appDesigner.navTypeReport":`Report`,"appDesigner.navTypeUrl":`URL`,"appDesigner.navTypeGroup":`Group`,"appDesigner.navTypeSeparator":`Separator`,"appDesigner.navTypeAction":`Action`,"appDesigner.navEditIcon":`Edit icon`,"appDesigner.navToggleVisible":`Toggle visibility`,"appDesigner.navHidden":`Hidden`,"appDesigner.navExportSchema":`Export JSON`,"appDesigner.navImportSchema":`Import JSON`,"appDesigner.navExportSuccess":`Navigation schema exported`,"appDesigner.navImportSuccess":`Navigation schema imported`,"appDesigner.navImportError":`Invalid navigation JSON`,"appDesigner.navIconPlaceholder":`Icon name (e.g. Users)`,"appDesigner.dashboardEditor":`Dashboard Editor`,"appDesigner.noWidgets":`No widgets. Click a button above to add one.`,"appDesigner.widgetLayoutSize":`Layout Size`,"appDesigner.widgetWidth":`Width`,"appDesigner.widgetHeight":`Height`,"appDesigner.dashboardPreview":`Dashboard Preview`,"appDesigner.noWidgetsPreview":`No widgets to preview`,"appDesigner.pageCanvasEditor":`Page Canvas Editor`,"appDesigner.emptyPage":`Empty page. Click a button above to add a component.`,"appDesigner.pagePreview":`Page Preview`,"appDesigner.noComponentsPreview":`No components to preview`,"appDesigner.modePage":`Page`,"appDesigner.modeDashboard":`Dashboard`,"appDesigner.undo":`Undo`,"appDesigner.redo":`Redo`,"appDesigner.brandingEditor":`Branding Editor`,"appDesigner.brandingExport":`Export JSON`,"appDesigner.brandingImport":`Import JSON`,"appDesigner.brandingPreview":`Preview`,"appDesigner.brandingSampleButton":`Sample Button`,"appDesigner.brandingSampleText":`This is how your brand theme will look.`,"appDesigner.colorPalette":`Color Palette`,"appDesigner.fontFamily":`Font Family`,"appDesigner.fontDefault":`Default (System)`,"appDesigner.modeLight":`Light`,"appDesigner.modeDark":`Dark`,"appDesigner.mobilePreview":`Mobile Preview`};function je(e){return(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}function Z(){try{let e=ke();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:je(Ae)}:{t:e.t}}catch{return{t:je(Ae)}}}function Q(...e){return(0,a.twMerge)((0,i.clsx)(e))}var Me={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function Ne(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var Pe=0;function Fe(e){return Pe+=1,`${e}_${Date.now()}_${Pe}`}function Ie({steps:e,currentIndex:t,onStepClick:i}){return(0,C.jsx)(`nav`,{className:`flex items-center justify-center gap-0 px-4 py-6`,children:e.map((e,a)=>{let o=a<t,s=a===t;return(0,C.jsxs)(n.default.Fragment,{children:[a>0&&(0,C.jsx)(`div`,{className:Q(`h-0.5 w-12 sm:w-20`,o?`bg-blue-500`:`bg-gray-200`)}),(0,C.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>i(a),className:Q(`flex flex-col items-center gap-1 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg px-2 py-1`,s&&`cursor-default`,!s&&`cursor-pointer`),children:[(0,C.jsx)(`div`,{className:Q(`flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold transition-colors`,o&&`bg-blue-500 text-white`,s&&`bg-blue-600 text-white ring-2 ring-blue-300`,!o&&!s&&`bg-gray-200 text-gray-500`),children:o?(0,C.jsx)(r.Check,{className:`h-4 w-4`}):a+1}),(0,C.jsx)(`span`,{className:Q(`text-xs font-medium`,s?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function Le({draft:e,templates:t,readOnly:n,onChange:i,t:a}){let s=e.name.length>0&&!(0,o.isValidAppName)(e.name);return(0,C.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[a(`appDesigner.appName`),` `,(0,C.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,C.jsx)(`input`,{id:`app-name`,"data-testid":`app-name-input`,type:`text`,value:e.name,onChange:e=>i({name:e.target.value}),placeholder:`my_app`,disabled:n,className:Q(`block w-full rounded-md border px-3 py-2 text-sm shadow-sm outline-none transition-colors`,`focus:border-blue-500 focus:ring-1 focus:ring-blue-500`,`disabled:cursor-not-allowed disabled:bg-gray-50`,s?`border-red-400`:`border-gray-300`)}),s&&(0,C.jsx)(`p`,{className:`text-xs text-red-500`,children:a(`appDesigner.snakeCaseHint`)})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[a(`appDesigner.appTitle`),` `,(0,C.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,C.jsx)(`input`,{id:`app-title`,"data-testid":`app-title-input`,type:`text`,value:e.title,onChange:e=>i({title:e.target.value}),placeholder:`My Application`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.appDescription`)}),(0,C.jsx)(`textarea`,{id:`app-description`,"data-testid":`app-description-input`,value:e.description??``,onChange:e=>i({description:e.target.value}),rows:3,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 resize-none`})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.appIcon`)}),(0,C.jsx)(`input`,{id:`app-icon`,type:`text`,value:e.icon??``,onChange:e=>i({icon:e.target.value}),placeholder:`LayoutDashboard`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),t.length>0&&(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.template`)}),(0,C.jsxs)(`select`,{id:`app-template`,value:e.template??``,onChange:e=>i({template:e.target.value}),disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`,children:[(0,C.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,C.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,C.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,C.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:a(`appDesigner.layout`)}),(0,C.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:r.PanelLeft},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:r.Layout},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:r.LayoutTemplate}].map(({value:t,labelKey:r,Icon:o})=>(0,C.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:Q(`flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-lg border-2 p-3 transition-colors`,e.layout===t?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,n&&`pointer-events-none opacity-60`),children:[(0,C.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,C.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:a(r)}),(0,C.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>i({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function Re({objects:e,readOnly:t,onToggle:i,onToggleAll:a,search:o,onSearchChange:s,t:c}){let l=(0,n.useMemo)(()=>{if(!o)return e;let t=o.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t))},[e,o]),u=e.length>0&&e.every(e=>e.selected);return e.every(e=>!e.selected),(0,C.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`div`,{className:`relative flex-1`,children:[(0,C.jsx)(r.Search,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{"data-testid":`object-search`,type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:c(`appDesigner.searchObjects`),className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500`})]}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>a(!u),disabled:t,className:`rounded-md border border-gray-300 px-3 py-2 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:c(u?`appDesigner.deselectAll`:`appDesigner.selectAll`)})]}),l.length===0?(0,C.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:c(`appDesigner.noObjectsFound`)}):(0,C.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:l.map(e=>(0,C.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>i(e.name),className:Q(`flex flex-col items-start gap-1 rounded-lg border-2 p-3 text-left transition-colors`,e.selected?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,t&&`pointer-events-none opacity-60`),children:[(0,C.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,C.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,C.jsx)(`div`,{className:Q(`flex h-5 w-5 items-center justify-center rounded border transition-colors`,e.selected?`border-blue-500 bg-blue-500 text-white`:`border-gray-300`),children:e.selected&&(0,C.jsx)(r.Check,{className:`h-3 w-3`})})]}),(0,C.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,C.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var ze={object:`bg-green-100 text-green-700`,group:`bg-purple-100 text-purple-700`,url:`bg-sky-100 text-sky-700`,separator:`bg-gray-100 text-gray-600`,dashboard:`bg-amber-100 text-amber-700`,page:`bg-teal-100 text-teal-700`,report:`bg-rose-100 text-rose-700`,action:`bg-orange-100 text-orange-700`};function Be({items:e,readOnly:t,onAdd:n,onRemove:i,onReorder:a,t:o}){return(0,C.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,C.jsxs)(`div`,{className:`flex gap-2`,children:[(0,C.jsxs)(`button`,{type:`button`,"data-testid":`add-group-btn`,onClick:()=>n(`group`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(r.FolderOpen,{className:`h-3.5 w-3.5`}),o(`appDesigner.addGroup`)]}),(0,C.jsxs)(`button`,{type:`button`,"data-testid":`add-url-btn`,onClick:()=>n(`url`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(r.Link,{className:`h-3.5 w-3.5`}),o(`appDesigner.addUrl`)]}),(0,C.jsxs)(`button`,{type:`button`,"data-testid":`add-separator-btn`,onClick:()=>n(`separator`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(r.Minus,{className:`h-3.5 w-3.5`}),o(`appDesigner.addSeparator`)]})]}),e.length===0?(0,C.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noNavItemsHint`)}):(0,C.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,c)=>(0,C.jsxs)(`li`,{"data-testid":`nav-item-${n.id}`,className:`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2`,children:[n.icon&&(0,C.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,C.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?o(`appDesigner.separatorLabel`):(0,s.resolveI18nLabel)(n.label)}),(0,C.jsx)(`span`,{className:Q(`rounded-full px-2 py-0.5 text-[10px] font-medium`,ze[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,C.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>a(n.id,`up`),disabled:t||c===0,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,C.jsx)(r.ChevronUp,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>a(n.id,`down`),disabled:t||c===e.length-1,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,C.jsx)(r.ChevronDown,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>i(n.id),disabled:t,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-red-500 disabled:opacity-30`,"aria-label":`Remove`,children:(0,C.jsx)(r.Trash2,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function Ve({branding:e,title:t,readOnly:n,onChange:i,t:a}){return(0,C.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.logoUrl`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(r.Image,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{id:`branding-logo`,"data-testid":`branding-logo-input`,type:`text`,value:e.logo??``,onChange:e=>i({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.primaryColor`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(r.Palette,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{id:`branding-color`,"data-testid":`branding-color-input`,type:`text`,value:e.primaryColor??`#3b82f6`,onChange:e=>i({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.faviconUrl`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(r.Globe,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{id:`branding-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:e.favicon??``,onChange:e=>i({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:a(`appDesigner.preview`)}),(0,C.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,C.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,C.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,C.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||a(`appDesigner.appTitle`)})]}),(0,C.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,C.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,C.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,C.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,C.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,C.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function He({availableObjects:e=[],templates:t=[],initialDraft:i,onComplete:a,onCancel:s,onSaveDraft:c,readOnly:l=!1,className:u}){let{t:d}=Z(),f=_(),[p,m]=(0,n.useState)(0),[h,g]=(0,n.useState)(``),[v,y]=(0,n.useState)(()=>({...Me,objects:e.map(e=>({...e})),...i})),b=(0,n.useMemo)(()=>[{id:`basic`,label:d(`appDesigner.basicInfo`),description:d(`appDesigner.stepBasicDesc`),icon:`Settings`},{id:`objects`,label:d(`appDesigner.objects`),description:d(`appDesigner.stepObjectsDesc`),icon:`Database`},{id:`navigation`,label:d(`appDesigner.navigation`),description:d(`appDesigner.stepNavigationDesc`),icon:`Menu`},{id:`branding`,label:d(`appDesigner.branding`),description:d(`appDesigner.stepBrandingDesc`),icon:`Palette`}],[d]),x=p===0,S=p===b.length-1,w=(0,n.useMemo)(()=>v.name.length>0&&(0,o.isValidAppName)(v.name)&&v.title.trim().length>0,[v.name,v.title]),T=(0,n.useMemo)(()=>p===0?w:!0,[p,w]),E=(0,n.useCallback)(e=>{y(t=>({...t,...e}))},[]),D=(0,n.useCallback)(e=>{y(t=>({...t,branding:{...t.branding,...e}}))},[]),O=(0,n.useCallback)(e=>{y(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),k=(0,n.useCallback)(e=>{y(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),A=(0,n.useCallback)(e=>{let t={id:Fe(e),type:e,label:e===`separator`?``:e===`group`?`New Group`:`New Link`,...e===`group`?{children:[]}:{},...e===`url`?{url:``}:{}};y(e=>({...e,navigation:[...e.navigation,t]}))},[]),j=(0,n.useCallback)(e=>{y(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),M=(0,n.useCallback)((e,t)=>{y(n=>{let r=[...n.navigation],i=r.findIndex(t=>t.id===e);if(i<0)return n;let a=t===`up`?i-1:i+1;return a<0||a>=r.length?n:([r[i],r[a]]=[r[a],r[i]],{...n,navigation:r})})},[]),N=(0,n.useCallback)(()=>{S||(p===1&&y(e=>({...e,navigation:Ne(e.objects)})),m(e=>e+1))},[p,S]),P=(0,n.useCallback)(()=>{x||m(e=>e-1)},[x]),F=(0,n.useCallback)(()=>{a?.(v)},[v,a]),I=(0,n.useCallback)(async()=>{(v.name.length>0||v.title.length>0)&&s?await f.confirm(d(`appDesigner.cancelConfirmTitle`),d(`appDesigner.cancelConfirmMessage`))&&s():s?.()},[v.name,v.title,s,f,d]),L=(0,n.useCallback)(()=>{c?.(v)},[v,c]),R=(0,n.useCallback)(e=>{e<=p?m(e):e===p+1&&T&&(p===1&&e===2&&y(e=>({...e,navigation:Ne(e.objects)})),m(e))},[p,T]);return(0,C.jsxs)(`div`,{className:Q(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,u),children:[f.isOpen&&(0,C.jsx)(`div`,{"data-testid":`cancel-confirm-dialog`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,role:`dialog`,"aria-modal":`true`,children:(0,C.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:f.title}),(0,C.jsx)(`button`,{type:`button`,onClick:f.onCancel,className:`rounded p-1 text-gray-400 hover:text-gray-600`,"aria-label":d(`common.close`),children:(0,C.jsx)(r.X,{className:`h-4 w-4`})})]}),(0,C.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:f.message}),(0,C.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,C.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-keep`,onClick:f.onCancel,className:`rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50`,children:d(`appDesigner.keepEditing`)}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-discard`,onClick:f.onConfirm,className:`rounded-md bg-red-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:d(`appDesigner.confirmDiscard`)})]})]})}),(0,C.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,C.jsx)(Ie,{steps:b,currentIndex:p,onStepClick:R})}),(0,C.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[p===0&&(0,C.jsx)(Le,{draft:v,templates:t,readOnly:l,onChange:E,t:d}),p===1&&(0,C.jsx)(Re,{objects:v.objects,readOnly:l,onToggle:O,onToggleAll:k,search:h,onSearchChange:g,t:d}),p===2&&(0,C.jsx)(Be,{items:v.navigation,readOnly:l,onAdd:A,onRemove:j,onReorder:M,t:d}),p===3&&(0,C.jsx)(Ve,{branding:v.branding,title:v.title,readOnly:l,onChange:D,t:d})]}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`button`,{type:`button`,"data-testid":`wizard-cancel`,onClick:I,disabled:l,className:`rounded-md px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50`,children:d(`common.cancel`)}),c&&(0,C.jsx)(`button`,{type:`button`,"data-testid":`wizard-save-draft`,onClick:L,disabled:l,className:`rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:d(`appDesigner.saveDraft`)})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!x&&(0,C.jsxs)(`button`,{type:`button`,"data-testid":`wizard-back`,onClick:P,disabled:l,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(r.ChevronLeft,{className:`h-4 w-4`}),d(`common.back`)]}),S?(0,C.jsxs)(`button`,{type:`button`,"data-testid":`wizard-complete`,onClick:F,disabled:l||!T,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(r.Check,{className:`h-4 w-4`}),d(`appDesigner.complete`)]}):(0,C.jsxs)(`button`,{type:`button`,"data-testid":`wizard-next`,onClick:N,disabled:l||!T,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[d(`common.next`),(0,C.jsx)(r.ChevronRight,{className:`h-4 w-4`})]})]})]})]})}function Ue(...e){return(0,a.twMerge)((0,i.clsx)(e))}var We=0;function Ge(e){return We+=1,`${e}_${Date.now()}_${We}`}var Ke={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:r.Database},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:r.LayoutDashboard},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:r.FileText},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:r.BarChart3},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:r.Link},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:r.FolderOpen},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:r.Minus},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:r.MousePointerClick}},qe=[{type:`object`,labelKey:`appDesigner.navObjectPage`},{type:`dashboard`,labelKey:`appDesigner.navDashboard`},{type:`page`,labelKey:`appDesigner.navPage`},{type:`report`,labelKey:`appDesigner.navReport`},{type:`group`,labelKey:`appDesigner.navGroup`},{type:`url`,labelKey:`appDesigner.navUrl`},{type:`separator`,labelKey:`appDesigner.navSeparator`}];function Je({item:e,depth:t,index:i,total:a,readOnly:o,onRemove:c,onMoveUp:l,onMoveDown:u,onToggleExpand:d,onUpdateLabel:f,onUpdateIcon:p,onToggleVisible:m,onAddChild:h,expandedIds:g,t:_}){let[v,y]=(0,n.useState)(!1),[b,x]=(0,n.useState)((0,s.resolveI18nLabel)(e.label)??``),[S,w]=(0,n.useState)(!1),[T,E]=(0,n.useState)(e.icon||``),D=Ke[e.type];e.type===`group`&&e.children&&e.children.length;let O=g.has(e.id),k=e.visible===!1,A=()=>{b.trim()?f(e.id,b.trim()):x((0,s.resolveI18nLabel)(e.label)??``),y(!1)},j=()=>{p(e.id,T.trim()),w(!1)};return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:Ue(`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 transition-colors hover:bg-gray-50`,k&&`opacity-50`),style:{marginLeft:t*20},children:[(0,C.jsx)(r.GripVertical,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,C.jsx)(`button`,{type:`button`,onClick:()=>d(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":_(O?`appDesigner.navCollapseGroup`:`appDesigner.navExpandGroup`),children:O?(0,C.jsx)(r.ChevronDown,{className:`h-3.5 w-3.5`}):(0,C.jsx)(r.ChevronRight,{className:`h-3.5 w-3.5`})}):(0,C.jsx)(`span`,{className:`w-5`}),S&&!o?(0,C.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:j,onKeyDown:t=>{t.key===`Enter`&&j(),t.key===`Escape`&&(E(e.icon||``),w(!1))},autoFocus:!0,placeholder:_(`appDesigner.navIconPlaceholder`),"data-testid":`nav-designer-icon-input-${e.id}`,className:`w-24 rounded border border-blue-300 px-1 py-0.5 text-xs outline-none focus:ring-1 focus:ring-blue-400`}):(0,C.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,C.jsx)(D.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!o&&e.type!==`separator`&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>{E(e.icon||``),w(!0)},className:`rounded p-0.5 text-gray-300 hover:text-blue-500`,"aria-label":_(`appDesigner.navEditIcon`),"data-testid":`nav-designer-edit-icon-${e.id}`,children:(0,C.jsx)(r.Pencil,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,C.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:_(`appDesigner.separatorLabel`)}):v&&!o?(0,C.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),onBlur:A,onKeyDown:t=>{t.key===`Enter`&&A(),t.key===`Escape`&&(x((0,s.resolveI18nLabel)(e.label)??``),y(!1))},autoFocus:!0,className:`flex-1 rounded border border-blue-300 px-1.5 py-0.5 text-sm outline-none focus:ring-1 focus:ring-blue-400`}):(0,C.jsx)(`span`,{className:Ue(`flex-1 truncate text-sm text-gray-800`,!o&&`cursor-text`),onDoubleClick:()=>{!o&&e.type!==`separator`&&(x((0,s.resolveI18nLabel)(e.label)??``),y(!0))},children:(0,s.resolveI18nLabel)(e.label)}),(0,C.jsx)(`span`,{className:Ue(`rounded-full px-2 py-0.5 text-[10px] font-medium`,D.color),children:_(D.labelKey)}),k&&(0,C.jsx)(`span`,{className:`rounded-full bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-500`,"data-testid":`nav-designer-hidden-badge-${e.id}`,children:_(`appDesigner.navHidden`)}),!o&&e.type!==`separator`&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>m(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-700`,"aria-label":_(`appDesigner.navToggleVisible`),"data-testid":`nav-designer-toggle-visible-${e.id}`,children:k?(0,C.jsx)(r.EyeOff,{className:`h-3.5 w-3.5`}):(0,C.jsx)(r.Eye,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!o&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>h(e.id,`page`),className:`rounded p-0.5 text-gray-400 hover:text-blue-500`,"aria-label":_(`appDesigner.navAddChild`),"data-testid":`nav-designer-add-child-${e.id}`,children:(0,C.jsx)(r.Plus,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>l(e.id),disabled:o||i===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":_(`appDesigner.navMoveUp`),children:(0,C.jsx)(r.ChevronUp,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),disabled:o||i===a-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":_(`appDesigner.navMoveDown`),children:(0,C.jsx)(r.ChevronDown,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>c(e.id),disabled:o,className:`rounded p-0.5 text-gray-400 hover:text-red-500 disabled:opacity-30`,"aria-label":_(`appDesigner.navRemove`),"data-testid":`nav-designer-remove-${e.id}`,children:(0,C.jsx)(r.Trash2,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&O&&e.children&&(0,C.jsx)(C.Fragment,{children:e.children.map((n,r)=>(0,C.jsx)(Je,{item:n,depth:t+1,index:r,total:e.children.length,readOnly:o,onRemove:c,onMoveUp:l,onMoveDown:u,onToggleExpand:d,onUpdateLabel:f,onUpdateIcon:p,onToggleVisible:m,onAddChild:h,expandedIds:g,t:_},n.id))})]})}function Ye({items:e,t}){return(0,C.jsxs)(`div`,{"data-testid":`nav-designer-preview`,className:`w-56 shrink-0 rounded-lg border border-gray-200 bg-gray-50 p-3`,children:[(0,C.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,C.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,C.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,C.jsx)(Xe,{item:e,depth:0},e.id))})]})}function Xe({item:e,depth:t}){let n=Ke[e.type];return e.type===`separator`?(0,C.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-gray-700 hover:bg-gray-100`,style:{marginLeft:t*12},children:[(0,C.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,C.jsx)(`span`,{className:`truncate`,children:(0,s.resolveI18nLabel)(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,C.jsx)(Xe,{item:e,depth:t+1},e.id))]})}function Ze({items:e,onChange:t,readOnly:i=!1,showPreview:a=!0,className:o,onExport:s,onImport:c}){let{t:l}=Z(),u=(0,n.useRef)(null),[d,f]=(0,n.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),p=(0,n.useCallback)(n=>{function r(e){return e.filter(e=>e.id!==n).map(e=>e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),m=(0,n.useCallback)((n,r)=>{function i(e){let t=e.findIndex(e=>e.id===n);if(t>=0){let n=r===`up`?t-1:t+1;if(n>=0&&n<e.length){let r=[...e];return[r[t],r[n]]=[r[n],r[t]],r}return e}return e.map(e=>e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),h=(0,n.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,label:r}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),g=(0,n.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,icon:r||void 0}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),_=(0,n.useCallback)(n=>{function r(e){return e.map(e=>e.id===n?{...e,visible:e.visible===!1}:e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),v=(0,n.useCallback)((n,r)=>{let i={id:Ge(r),type:r,label:r===`separator`?``:`New ${l(Ke[r].labelKey)}`,...r===`group`?{children:[]}:{},...r===`url`?{url:``}:{}};function a(e){return e.map(e=>e.id===n&&e.type===`group`?{...e,children:[...e.children||[],i]}:e.children?{...e,children:a(e.children)}:e)}t(a(e)),f(e=>new Set(e).add(n))},[e,t]),y=(0,n.useCallback)(n=>{let r={id:Ge(n),type:n,label:n===`separator`?``:`New ${l(Ke[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,l]),b=(0,n.useCallback)(e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),x=(0,n.useCallback)(()=>{if(s)s(e);else{let t=JSON.stringify(e,null,2),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`navigation-schema.json`,i.click(),URL.revokeObjectURL(r)}},[e,s]),S=(0,n.useCallback)(e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);Array.isArray(n)&&(c?c(n):t(n))}catch{}},r.readAsText(n),u.current&&(u.current.value=``)},[t,c]);return(0,C.jsxs)(`div`,{"data-testid":`navigation-designer`,className:Ue(`flex flex-col gap-4 sm:flex-row`,o),children:[(0,C.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[qe.map(({type:e,labelKey:t})=>{let{Icon:n,color:a}=Ke[e];return(0,C.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>y(e),disabled:i,className:Ue(`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`),children:[(0,C.jsx)(r.Plus,{className:`h-3 w-3`}),l(t)]},e)}),(0,C.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,C.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-export`,onClick:x,className:`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,children:[(0,C.jsx)(r.Download,{className:`h-3 w-3`}),l(`appDesigner.navExportSchema`)]}),(0,C.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:Ue(`inline-flex cursor-pointer items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,i&&`cursor-not-allowed opacity-50`),children:[(0,C.jsx)(r.Upload,{className:`h-3 w-3`}),l(`appDesigner.navImportSchema`),(0,C.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:S,disabled:i,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,C.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:l(`appDesigner.navNoItems`)}):(0,C.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,n)=>(0,C.jsx)(Je,{item:t,depth:0,index:n,total:e.length,readOnly:i,onRemove:p,onMoveUp:e=>m(e,`up`),onMoveDown:e=>m(e,`down`),onToggleExpand:b,onUpdateLabel:h,onUpdateIcon:g,onToggleVisible:_,onAddChild:v,expandedIds:d,t:l},t.id))})]}),a&&(0,C.jsx)(Ye,{items:e,t:l})]})}function Qe(...e){return(0,a.twMerge)((0,i.clsx)(e))}var $e=[{value:`edit`,label:`Edit`,Icon:r.Pencil},{value:`preview`,label:`Preview`,Icon:r.Eye},{value:`code`,label:`Code`,Icon:r.Code}];function et({mode:e,onChange:t,disabled:n=!1,className:r}){return(0,C.jsx)(`div`,{"data-testid":`editor-mode-toggle`,className:Qe(`inline-flex items-center rounded-lg border border-gray-200 bg-gray-50 p-0.5`,r),role:`radiogroup`,"aria-label":`Editor mode`,children:$e.map(({value:r,label:i,Icon:a})=>(0,C.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":e===r,"data-testid":`editor-mode-${r}`,onClick:()=>t(r),disabled:n,className:Qe(`inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors`,e===r?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`,n&&`cursor-not-allowed opacity-50`),children:[(0,C.jsx)(a,{className:`h-3.5 w-3.5`}),i]},r))})}function tt(...e){return(0,a.twMerge)((0,i.clsx)(e))}var nt=[{type:`metric`,label:`KPI Metric`,Icon:r.TrendingUp},{type:`bar`,label:`Bar Chart`,Icon:r.BarChart3},{type:`line`,label:`Line Chart`,Icon:r.LineChart},{type:`pie`,label:`Pie Chart`,Icon:r.PieChart},{type:`table`,label:`Table`,Icon:r.Table2},{type:`grid`,label:`Grid`,Icon:r.LayoutGrid}],rt=0;function it(){return rt+=1,`widget_${Date.now()}_${rt}`}function at({widget:e,index:t,total:n,selected:i,readOnly:a,onSelect:o,onRemove:s,onMoveUp:c,onMoveDown:l}){let u=e.type||`metric`,d=nt.find(e=>e.type===u)||nt[0];return(0,C.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:o,className:tt(`group cursor-pointer rounded-lg border-2 p-3 transition-colors`,i?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`),children:[(0,C.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(r.GripVertical,{className:`h-4 w-4 text-gray-300`}),(0,C.jsx)(d.Icon,{className:`h-4 w-4 text-gray-500`}),(0,C.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!a&&(0,C.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:t===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,C.jsx)(r.ChevronUp,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:t===n-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,C.jsx)(r.ChevronDown,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},className:`rounded p-0.5 text-gray-400 hover:text-red-500`,"aria-label":`Remove widget`,"data-testid":`dashboard-widget-remove-${e.id}`,children:(0,C.jsx)(r.Trash2,{className:`h-3.5 w-3.5`})})]})]}),(0,C.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,C.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-600`,children:d.label}),e.object&&(0,C.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function ot({widget:e,readOnly:t,onChange:n,onClose:i}){let{t:a}=Z();return(0,C.jsxs)(`div`,{"data-testid":`widget-property-panel`,className:`shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:a(`appDesigner.widgetProperties`)}),(0,C.jsx)(`button`,{type:`button`,onClick:i,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,C.jsx)(r.X,{className:`h-4 w-4`})})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,C.jsx)(`input`,{id:`widget-title`,"data-testid":`widget-prop-title`,type:`text`,value:e.title??``,onChange:e=>n({title:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,C.jsx)(`select`,{id:`widget-type`,"data-testid":`widget-prop-type`,value:e.type??`metric`,onChange:e=>n({type:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:nt.map(e=>(0,C.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,C.jsx)(`input`,{id:`widget-object`,"data-testid":`widget-prop-object`,type:`text`,value:e.object??``,onChange:e=>n({object:e.target.value}),disabled:t,placeholder:`e.g. orders`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,C.jsx)(`input`,{id:`widget-value-field`,"data-testid":`widget-prop-value-field`,type:`text`,value:e.valueField??``,onChange:e=>n({valueField:e.target.value}),disabled:t,placeholder:`e.g. amount`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,C.jsxs)(`select`,{id:`widget-aggregate`,"data-testid":`widget-prop-aggregate`,value:e.aggregate??`count`,onChange:e=>n({aggregate:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,C.jsx)(`option`,{value:`count`,children:`Count`}),(0,C.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,C.jsx)(`option`,{value:`avg`,children:`Average`}),(0,C.jsx)(`option`,{value:`min`,children:`Min`}),(0,C.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,C.jsxs)(`select`,{id:`widget-color`,"data-testid":`widget-prop-color`,value:e.colorVariant??`default`,onChange:e=>n({colorVariant:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,C.jsx)(`option`,{value:`default`,children:`Default`}),(0,C.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,C.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,C.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,C.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,C.jsx)(`option`,{value:`success`,children:`Success`}),(0,C.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,C.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:a(`appDesigner.widgetLayoutSize`)}),(0,C.jsxs)(`div`,{className:`flex gap-2`,children:[(0,C.jsxs)(`div`,{className:`flex-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:a(`appDesigner.widgetWidth`)}),(0,C.jsx)(`input`,{id:`widget-width`,"data-testid":`widget-prop-width`,type:`number`,min:1,value:e.layout?.w??1,onChange:t=>n({layout:{...e.layout,w:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,C.jsxs)(`div`,{className:`flex-1`,children:[(0,C.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:a(`appDesigner.widgetHeight`)}),(0,C.jsx)(`input`,{id:`widget-height`,"data-testid":`widget-prop-height`,type:`number`,min:1,value:e.layout?.h??1,onChange:t=>n({layout:{...e.layout,h:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]})]})]})]})}function st({schema:e}){let{t}=Z(),n=e.widgets||[];return(0,C.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,C.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,C.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,C.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=nt.find(t=>t.type===(e.type||`metric`))||nt[0];return(0,C.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,C.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,C.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,C.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function ct({schema:e,onChange:t,readOnly:i=!1,className:a,onExport:o,onImport:s,selectedWidgetId:c,onWidgetSelect:l}){let{t:u}=Z(),[d,f]=(0,n.useState)(null),[p,m]=(0,n.useState)(!1),h=(0,n.useRef)(null),_=(0,n.useRef)(null),v=c!==void 0,y=v?c:d,b=(0,n.useCallback)(e=>{l&&l(e),v||f(e)},[v,l,f]),{current:x,canUndo:S,canRedo:w,push:T,undo:E,redo:D}=g(e),O=(0,n.useCallback)(e=>{T(e),t(e)},[T,t]),k=x.widgets||[],A=k.find(e=>e.id===y),j=(0,n.useCallback)(e=>{let t=it(),n={id:t,title:``,type:e,layout:{x:0,y:k.length,w:x.columns??2,h:1}};O({...x,widgets:[...k,n]}),b(t)},[x,k,O,b]),M=(0,n.useCallback)(e=>{O({...x,widgets:k.filter(t=>t.id!==e)}),y===e&&b(null)},[x,k,y,O,b]),N=(0,n.useCallback)((e,t)=>{let n=k.findIndex(t=>t.id===e);if(n<0)return;let r=t===`up`?n-1:n+1;if(r<0||r>=k.length)return;let i=[...k];[i[n],i[r]]=[i[r],i[n]],O({...x,widgets:i})},[x,k,O]),P=(0,n.useCallback)(e=>{y&&O({...x,widgets:k.map(t=>t.id===y?{...t,...e}:t)})},[x,k,y,O]);(0,n.useEffect)(()=>{let e=h.current;if(!e)return;let t=e=>{if(!i){if((e.ctrlKey||e.metaKey)&&e.key===`z`&&!e.shiftKey){e.preventDefault(),E();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`z`&&e.shiftKey)){e.preventDefault(),D();return}if((e.key===`Delete`||e.key===`Backspace`)&&y){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`SELECT`||t.tagName===`TEXTAREA`)return;e.preventDefault(),M(y)}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[i,E,D,y,M]);let F=(0,n.useCallback)(()=>{o&&o(x)},[x,o]),I=(0,n.useCallback)(()=>{_.current?.click()},[]),L=(0,n.useCallback)(e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=()=>{try{let e=JSON.parse(n.result);e&&e.type===`dashboard`&&(O(e),s?.(e))}catch{}},n.readAsText(t),e.target.value=``},[O,s]);return(0,C.jsxs)(`div`,{ref:h,tabIndex:0,"data-testid":`dashboard-editor`,className:tt(`flex flex-col gap-4 outline-none`,a),children:[(0,C.jsx)(`input`,{ref:_,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:L}),A&&!p&&(0,C.jsx)(ot,{widget:A,readOnly:i,onChange:P,onClose:()=>b(null)}),(0,C.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,C.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[u(`appDesigner.addWidget`),`:`]}),nt.map(({type:e,label:t,Icon:n})=>(0,C.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>j(e),disabled:i||p,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(n,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!i&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`button`,{type:`button`,"data-testid":`dashboard-undo`,onClick:E,disabled:!S,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":u(`appDesigner.undo`),children:(0,C.jsx)(r.Undo2,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`dashboard-redo`,onClick:D,disabled:!w,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":u(`appDesigner.redo`),children:(0,C.jsx)(r.Redo2,{className:`h-4 w-4`})})]}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`dashboard-export`,onClick:F,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":u(`appDesigner.navExportSchema`),children:(0,C.jsx)(r.Download,{className:`h-4 w-4`})}),!i&&(0,C.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:I,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":u(`appDesigner.navImportSchema`),children:(0,C.jsx)(r.Upload,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>m(e=>!e),className:tt(`rounded p-1.5 transition-colors`,p?`bg-blue-100 text-blue-600`:`text-gray-400 hover:text-gray-700`),"aria-label":u(p?`appDesigner.modeEdit`:`appDesigner.preview`),children:p?(0,C.jsx)(r.EyeOff,{className:`h-4 w-4`}):(0,C.jsx)(r.Eye,{className:`h-4 w-4`})})]})]}),p?(0,C.jsx)(st,{schema:x}):k.length===0?(0,C.jsx)(`div`,{className:`flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400`,children:u(`appDesigner.noWidgets`)}):(0,C.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${x.columns??2}, 1fr)`},children:k.map((e,t)=>(0,C.jsx)(at,{widget:e,index:t,total:k.length,selected:e.id===y,readOnly:i,onSelect:()=>b(e.id??null),onRemove:()=>M(e.id),onMoveUp:()=>N(e.id,`up`),onMoveDown:()=>N(e.id,`down`)},e.id))})]})]})}function lt(...e){return(0,a.twMerge)((0,i.clsx)(e))}var ut=[{type:`grid`,label:`Data Grid`,Icon:r.Table2},{type:`kanban`,label:`Kanban Board`,Icon:r.Kanban},{type:`calendar`,label:`Calendar`,Icon:r.CalendarDays},{type:`gallery`,label:`Gallery`,Icon:r.GalleryHorizontalEnd},{type:`dashboard`,label:`Dashboard`,Icon:r.BarChart3},{type:`form`,label:`Form`,Icon:r.FileText},{type:`layout-grid`,label:`Grid Layout`,Icon:r.LayoutGrid}],dt=[{value:`page`,labelKey:`appDesigner.modePage`},{value:`dashboard`,labelKey:`appDesigner.modeDashboard`}],ft=0;function pt(){return ft+=1,`component_${Date.now()}_${ft}`}function mt({component:e,index:t,total:n,selected:i,readOnly:a,onSelect:o,onRemove:s,onMoveUp:c,onMoveDown:l}){let u=ut.find(t=>t.type===e.type)||ut[0];return(0,C.jsxs)(`div`,{"data-testid":`canvas-component-${e.id}`,onClick:o,className:lt(`group flex cursor-pointer items-center gap-3 rounded-lg border-2 px-3 py-3 transition-colors`,i?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`),children:[(0,C.jsx)(r.GripVertical,{className:`h-4 w-4 shrink-0 cursor-grab text-gray-300`}),(0,C.jsx)(u.Icon,{className:`h-5 w-5 shrink-0 text-gray-500`}),(0,C.jsxs)(`div`,{className:`flex-1`,children:[(0,C.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,C.jsx)(`span`,{className:`ml-2 text-[10px] text-gray-400`,children:u.label})]}),!a&&(0,C.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:t===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,C.jsx)(r.ChevronUp,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:t===n-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,C.jsx)(r.ChevronDown,{className:`h-3.5 w-3.5`})}),(0,C.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},className:`rounded p-0.5 text-gray-400 hover:text-red-500`,"aria-label":`Remove component`,"data-testid":`canvas-component-remove-${e.id}`,children:(0,C.jsx)(r.Trash2,{className:`h-3.5 w-3.5`})})]})]})}function ht({component:e,readOnly:t,onChange:n,onClose:i}){let{t:a}=Z();return(0,C.jsxs)(`div`,{"data-testid":`component-property-panel`,className:`w-64 shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:a(`appDesigner.componentProperties`)}),(0,C.jsx)(`button`,{type:`button`,onClick:i,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,C.jsx)(r.X,{className:`h-4 w-4`})})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{htmlFor:`component-label`,className:`text-xs font-medium text-gray-600`,children:`Label`}),(0,C.jsx)(`input`,{id:`component-label`,"data-testid":`component-prop-label`,type:`text`,value:e.label,onChange:e=>n({label:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,C.jsx)(`div`,{className:`rounded-md bg-gray-50 px-2.5 py-1.5 text-sm text-gray-600`,children:ut.find(t=>t.type===e.type)?.label??e.type})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:`ID`}),(0,C.jsx)(`div`,{className:`rounded-md bg-gray-50 px-2.5 py-1.5 text-xs font-mono text-gray-500`,children:e.id})]})]})}function gt({schema:e,components:t}){let{t:n}=Z();return(0,C.jsxs)(`div`,{"data-testid":`page-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,C.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||n(`appDesigner.pagePreview`)}),t.length===0?(0,C.jsx)(`div`,{className:`text-xs text-gray-400`,children:n(`appDesigner.noComponentsPreview`)}):(0,C.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>{let t=ut.find(t=>t.type===e.type)||ut[0];return(0,C.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-gray-200 bg-white p-2`,children:[(0,C.jsx)(t.Icon,{className:`h-4 w-4 text-gray-400`}),(0,C.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.label}),(0,C.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function _t({schema:e,onChange:t,readOnly:i=!1,className:a,onExport:o,onImport:s}){let{t:c}=Z(),l=(0,n.useRef)(null),u=(0,n.useRef)(null),[d,f]=(0,n.useState)(()=>(e.children?Array.isArray(e.children)?e.children:[e.children]:[]).map((e,t)=>({id:e.id||`existing_${t}`,type:e.type||`grid`,label:e.title||e.label||`Component ${t+1}`,props:e}))),[p,m]=(0,n.useState)(null),[h,_]=(0,n.useState)(!1),[v,y]=(0,n.useState)(`page`),b=d.find(e=>e.id===p),{canUndo:x,canRedo:S,push:w,undo:T,redo:E}=g(d),D=(0,n.useCallback)(n=>{f(n),w(n),t({...e,children:n.map(e=>({type:e.type,id:e.id,title:e.label,...e.props}))})},[e,t,w]),O=(0,n.useCallback)(e=>{let t=pt(),n={id:t,type:e,label:ut.find(t=>t.type===e)?.label||e};D([...d,n]),m(t)},[d,D]),k=(0,n.useCallback)(e=>{D(d.filter(t=>t.id!==e)),p===e&&m(null)},[d,p,D]),A=(0,n.useCallback)((e,t)=>{let n=d.findIndex(t=>t.id===e);if(n<0)return;let r=t===`up`?n-1:n+1;if(r<0||r>=d.length)return;let i=[...d];[i[n],i[r]]=[i[r],i[n]],D(i)},[d,D]),j=(0,n.useCallback)(e=>{p&&D(d.map(t=>t.id===p?{...t,...e}:t))},[d,p,D]);(0,n.useEffect)(()=>{let e=l.current;if(!e)return;let t=e=>{if(!i){if((e.ctrlKey||e.metaKey)&&e.key===`z`&&!e.shiftKey){e.preventDefault(),T();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`z`&&e.shiftKey)){e.preventDefault(),E();return}if((e.key===`Delete`||e.key===`Backspace`)&&p){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`SELECT`||t.tagName===`TEXTAREA`)return;e.preventDefault(),k(p)}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[i,T,E,p,k]);let M=(0,n.useCallback)(()=>{o&&o(e)},[e,o]),N=(0,n.useCallback)(()=>{u.current?.click()},[]),P=(0,n.useCallback)(e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=()=>{try{let e=JSON.parse(r.result);if(e&&e.type===`page`){let n=(e.children?Array.isArray(e.children)?e.children:[e.children]:[]).map((e,t)=>({id:e.id||`imported_${t}`,type:e.type||`grid`,label:e.title||e.label||`Component ${t+1}`,props:e}));f(n),w(n),t(e),s?.(e)}}catch{}},r.readAsText(n),e.target.value=``},[t,w,s]);return(0,C.jsxs)(`div`,{ref:l,tabIndex:0,"data-testid":`page-canvas-editor`,className:lt(`flex flex-col gap-4 outline-none sm:flex-row`,a),children:[(0,C.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`canvas-import-input`,onChange:P}),(0,C.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,C.jsx)(`div`,{className:`flex items-center gap-2 border-b border-gray-200 pb-2`,role:`tablist`,children:dt.map(e=>(0,C.jsx)(`button`,{type:`button`,role:`tab`,"data-testid":`canvas-mode-${e.value}`,"aria-selected":v===e.value,onClick:()=>y(e.value),className:lt(`rounded-t-md px-3 py-1.5 text-xs font-medium transition-colors`,v===e.value?`border-b-2 border-blue-500 text-blue-600`:`text-gray-500 hover:text-gray-700`),children:c(e.labelKey)},e.value))}),(0,C.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,C.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addComponent`),`:`]}),ut.map(({type:e,label:t,Icon:n})=>(0,C.jsxs)(`button`,{type:`button`,"data-testid":`canvas-add-${e}`,onClick:()=>O(e),disabled:i||h,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,C.jsx)(n,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!i&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`button`,{type:`button`,"data-testid":`canvas-undo`,onClick:T,disabled:!x,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.undo`),children:(0,C.jsx)(r.Undo2,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`canvas-redo`,onClick:E,disabled:!S,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.redo`),children:(0,C.jsx)(r.Redo2,{className:`h-4 w-4`})})]}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`canvas-export`,onClick:M,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navExportSchema`),children:(0,C.jsx)(r.Download,{className:`h-4 w-4`})}),!i&&(0,C.jsx)(`button`,{type:`button`,"data-testid":`canvas-import`,onClick:N,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,C.jsx)(r.Upload,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,"data-testid":`canvas-preview-toggle`,onClick:()=>_(e=>!e),className:lt(`rounded p-1.5 transition-colors`,h?`bg-blue-100 text-blue-600`:`text-gray-400 hover:text-gray-700`),"aria-label":c(h?`appDesigner.modeEdit`:`appDesigner.preview`),children:h?(0,C.jsx)(r.EyeOff,{className:`h-4 w-4`}):(0,C.jsx)(r.Eye,{className:`h-4 w-4`})})]})]}),h?(0,C.jsx)(gt,{schema:e,components:d}):d.length===0?(0,C.jsx)(`div`,{className:`flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400`,children:c(`appDesigner.emptyPage`)}):(0,C.jsx)(`div`,{className:`space-y-2`,children:d.map((e,t)=>(0,C.jsx)(mt,{component:e,index:t,total:d.length,selected:e.id===p,readOnly:i,onSelect:()=>m(e.id),onRemove:()=>k(e.id),onMoveUp:()=>A(e.id,`up`),onMoveDown:()=>A(e.id,`down`)},e.id))})]}),b&&!h&&(0,C.jsx)(ht,{component:b,readOnly:i,onChange:j,onClose:()=>m(null)})]})}function vt(...e){return(0,a.twMerge)((0,i.clsx)(e))}var yt={grid:{label:`Grid`,Icon:r.LayoutGrid},kanban:{label:`Kanban`,Icon:r.Kanban},calendar:{label:`Calendar`,Icon:r.CalendarDays},gallery:{label:`Gallery`,Icon:r.GalleryHorizontalEnd},timeline:{label:`Timeline`,Icon:r.Clock},map:{label:`Map`,Icon:r.Map},gantt:{label:`Gantt`,Icon:r.GanttChart}},bt=[{value:`compact`,label:`Compact`},{value:`medium`,label:`Medium`},{value:`tall`,label:`Tall`}];function xt({title:e,icon:t,defaultOpen:i=!0,children:a}){let[o,s]=(0,n.useState)(i);return(0,C.jsxs)(`div`,{className:`border-b border-gray-100 pb-3`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex w-full items-center gap-2 py-2 text-left`,children:[t,(0,C.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase text-gray-500`,children:e}),o?(0,C.jsx)(r.ChevronUp,{className:`h-3.5 w-3.5 text-gray-400`}):(0,C.jsx)(r.ChevronDown,{className:`h-3.5 w-3.5 text-gray-400`})]}),o&&(0,C.jsx)(`div`,{className:`space-y-2`,children:a})]})}function St({config:e,onChange:t,availableViewTypes:i=[`grid`,`kanban`,`calendar`,`gallery`,`timeline`,`map`,`gantt`],readOnly:a=!1,className:o}){let s=(0,n.useCallback)(n=>{t({...e,...n})},[e,t]),c=(0,n.useCallback)(t=>{s({columns:e.columns.map(e=>e.name===t?{...e,visible:!e.visible}:e)})},[e,s]),l=(0,n.useCallback)((t,n)=>{let r=[...e.columns],i=r.findIndex(e=>e.name===t);if(i<0)return;let a=n===`up`?i-1:i+1;a<0||a>=r.length||([r[i],r[a]]=[r[a],r[i]],s({columns:r}))},[e,s]),u=(0,n.useMemo)(()=>e.columns.filter(e=>e.visible).length,[e.columns]);return(0,C.jsxs)(`div`,{"data-testid":`object-view-configurator`,className:vt(`w-72 space-y-3 rounded-lg border border-gray-200 bg-white p-4`,o),children:[(0,C.jsx)(xt,{title:`View Type`,icon:(0,C.jsx)(r.LayoutGrid,{className:`h-3.5 w-3.5 text-gray-500`}),children:(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.map(t=>{let{label:n,Icon:r}=yt[t];return(0,C.jsxs)(`button`,{type:`button`,"data-testid":`view-type-${t}`,onClick:()=>s({viewType:t}),disabled:a,className:vt(`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors`,e.viewType===t?`bg-blue-100 text-blue-700`:`text-gray-600 hover:bg-gray-100`,a&&`cursor-not-allowed opacity-50`),children:[(0,C.jsx)(r,{className:`h-3 w-3`}),n]},t)})})}),(0,C.jsx)(xt,{title:`Fields (${u}/${e.columns.length})`,icon:(0,C.jsx)(r.Columns3,{className:`h-3.5 w-3.5 text-gray-500`}),children:e.columns.length===0?(0,C.jsx)(`p`,{className:`text-xs text-gray-400`,children:`No fields configured.`}):(0,C.jsx)(`ul`,{className:`space-y-0.5`,children:e.columns.map((t,n)=>(0,C.jsxs)(`li`,{"data-testid":`view-column-${t.name}`,className:`flex items-center gap-1.5 rounded px-1.5 py-1 text-xs hover:bg-gray-50`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>c(t.name),disabled:a,className:vt(`rounded p-0.5 transition-colors`,t.visible?`text-blue-500`:`text-gray-300`),"aria-label":t.visible?`Hide field`:`Show field`,children:t.visible?(0,C.jsx)(r.Eye,{className:`h-3 w-3`}):(0,C.jsx)(r.EyeOff,{className:`h-3 w-3`})}),(0,C.jsx)(`span`,{className:`flex-1 truncate text-gray-700`,children:t.label}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>l(t.name,`up`),disabled:a||n===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,C.jsx)(r.ChevronUp,{className:`h-3 w-3`})}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>l(t.name,`down`),disabled:a||n===e.columns.length-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,C.jsx)(r.ChevronDown,{className:`h-3 w-3`})})]},t.name))})}),(0,C.jsx)(xt,{title:`Toolbar`,icon:(0,C.jsx)(r.Filter,{className:`h-3.5 w-3.5 text-gray-500`}),children:(0,C.jsxs)(`div`,{className:`space-y-2`,children:[(0,C.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:e.showSearch,onChange:e=>s({showSearch:e.target.checked}),disabled:a,"data-testid":`view-toggle-search`,className:`h-3.5 w-3.5 rounded border-gray-300`}),(0,C.jsx)(`span`,{className:`text-xs text-gray-700`,children:`Show Search`})]}),(0,C.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:e.showFilters,onChange:e=>s({showFilters:e.target.checked}),disabled:a,"data-testid":`view-toggle-filters`,className:`h-3.5 w-3.5 rounded border-gray-300`}),(0,C.jsx)(`span`,{className:`text-xs text-gray-700`,children:`Show Filters`})]}),(0,C.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:e.showSort,onChange:e=>s({showSort:e.target.checked}),disabled:a,"data-testid":`view-toggle-sort`,className:`h-3.5 w-3.5 rounded border-gray-300`}),(0,C.jsx)(`span`,{className:`text-xs text-gray-700`,children:`Show Sort`})]})]})}),(0,C.jsx)(xt,{title:`Appearance`,icon:(0,C.jsx)(r.Settings2,{className:`h-3.5 w-3.5 text-gray-500`}),defaultOpen:!1,children:(0,C.jsxs)(`div`,{className:`space-y-2`,children:[(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`label`,{className:`text-[10px] font-medium text-gray-500`,children:`Row Height`}),(0,C.jsx)(`div`,{className:`flex gap-1`,children:bt.map(({value:t,label:n})=>(0,C.jsx)(`button`,{type:`button`,"data-testid":`view-row-height-${t}`,onClick:()=>s({rowHeight:t}),disabled:a,className:vt(`flex-1 rounded px-2 py-1 text-[10px] font-medium transition-colors`,e.rowHeight===t?`bg-blue-100 text-blue-700`:`bg-gray-50 text-gray-500 hover:bg-gray-100`),children:n},t))})]}),(0,C.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:e.striped,onChange:e=>s({striped:e.target.checked}),disabled:a,"data-testid":`view-toggle-striped`,className:`h-3.5 w-3.5 rounded border-gray-300`}),(0,C.jsx)(`span`,{className:`text-xs text-gray-700`,children:`Striped Rows`})]}),(0,C.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:e.bordered,onChange:e=>s({bordered:e.target.checked}),disabled:a,"data-testid":`view-toggle-bordered`,className:`h-3.5 w-3.5 rounded border-gray-300`}),(0,C.jsx)(`span`,{className:`text-xs text-gray-700`,children:`Bordered`})]})]})})]})}function $(...e){return(0,a.twMerge)((0,i.clsx)(e))}var Ct=[{hex:`#3b82f6`,name:`Blue`},{hex:`#6366f1`,name:`Indigo`},{hex:`#8b5cf6`,name:`Violet`},{hex:`#a855f7`,name:`Purple`},{hex:`#ec4899`,name:`Pink`},{hex:`#ef4444`,name:`Red`},{hex:`#f97316`,name:`Orange`},{hex:`#f59e0b`,name:`Amber`},{hex:`#eab308`,name:`Yellow`},{hex:`#22c55e`,name:`Green`},{hex:`#14b8a6`,name:`Teal`},{hex:`#06b6d4`,name:`Cyan`},{hex:`#0ea5e9`,name:`Sky`},{hex:`#64748b`,name:`Slate`},{hex:`#1e293b`,name:`Dark`},{hex:`#0f172a`,name:`Navy`}],wt=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function Tt({branding:e,onChange:t,appTitle:i=`My App`,readOnly:a=!1,className:o,onExport:s,onImport:c}){let{t:l}=Z(),[u,d]=(0,n.useState)(`light`),{current:f,push:p,canUndo:m,canRedo:h,undo:_,redo:v}=g(e),y=(0,n.useRef)(!0);(0,n.useEffect)(()=>{if(y.current){y.current=!1;return}t(f)},[f]);let b=(0,n.useCallback)(e=>{let n={...f,...e};y.current=!0,p(n),t(n)},[f,p,t]),x=(0,n.useCallback)(()=>{if(s){s(f);return}let e=new Blob([JSON.stringify(f,null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`branding.json`,n.click(),URL.revokeObjectURL(t)},[f,s]),S=(0,n.useCallback)(()=>{if(c){c(f);return}let e=document.createElement(`input`);e.type=`file`,e.accept=`.json`,e.onchange=e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);if(typeof n==`object`&&n){let e={...f,...n};p(e),t(e)}}catch{}},r.readAsText(n)},e.click()},[f,p,t,c]),w=(0,n.useCallback)(e=>{a||((e.ctrlKey||e.metaKey)&&e.key===`z`&&(e.preventDefault(),e.shiftKey?v():_()),(e.ctrlKey||e.metaKey)&&e.key===`y`&&(e.preventDefault(),v()))},[a,_,v]),T=f.primaryColor||`#3b82f6`,E=u===`dark`;return(0,C.jsxs)(`div`,{"data-testid":`branding-editor`,className:$(`flex flex-col gap-4 sm:gap-6`,o),onKeyDown:w,tabIndex:0,children:[(0,C.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,C.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:l(`appDesigner.brandingEditor`)}),(0,C.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:_,disabled:!m||a,className:$(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,m&&!a?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:l(`appDesigner.undo`),children:[(0,C.jsx)(r.Undo2,{className:`h-3.5 w-3.5`}),l(`appDesigner.undo`)]}),(0,C.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:v,disabled:!h||a,className:$(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,h&&!a?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:l(`appDesigner.redo`),children:[(0,C.jsx)(r.Redo2,{className:`h-3.5 w-3.5`}),l(`appDesigner.redo`)]}),(0,C.jsxs)(`button`,{"data-testid":`branding-export`,type:`button`,onClick:x,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-sm transition-colors hover:bg-gray-50`,title:l(`appDesigner.brandingExport`),children:[(0,C.jsx)(r.Download,{className:`h-3.5 w-3.5`}),l(`appDesigner.brandingExport`)]}),(0,C.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:S,disabled:a,className:$(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,a?`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`:`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`),title:l(`appDesigner.brandingImport`),children:[(0,C.jsx)(r.Upload,{className:`h-3.5 w-3.5`}),l(`appDesigner.brandingImport`)]})]}),(0,C.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,C.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:l(`appDesigner.logoUrl`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(r.Image,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{id:`be-logo`,"data-testid":`branding-logo-input`,type:`text`,value:f.logo??``,onChange:e=>b({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:a,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:l(`appDesigner.primaryColor`)}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(`div`,{className:`relative flex-1`,children:[(0,C.jsx)(r.Palette,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{id:`be-color`,"data-testid":`branding-color-input`,type:`text`,value:f.primaryColor??`#3b82f6`,onChange:e=>b({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:a,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,C.jsx)(`input`,{"data-testid":`branding-color-picker`,type:`color`,value:T,onChange:e=>b({primaryColor:e.target.value}),disabled:a,className:`h-9 w-9 cursor-pointer rounded-md border border-gray-300 p-0.5 disabled:cursor-not-allowed`})]}),(0,C.jsxs)(`div`,{className:`space-y-1`,children:[(0,C.jsx)(`span`,{className:`text-xs text-gray-500`,children:l(`appDesigner.colorPalette`)}),(0,C.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:Ct.map(e=>(0,C.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!a&&b({primaryColor:e.hex}),disabled:a,className:$(`h-6 w-6 rounded-full border-2 transition-transform hover:scale-110 disabled:cursor-not-allowed`,T===e.hex?`border-gray-800 ring-2 ring-offset-1 ring-gray-400`:`border-transparent`),style:{backgroundColor:e.hex},title:e.name},e.hex))})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:l(`appDesigner.faviconUrl`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(r.Globe,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsx)(`input`,{id:`be-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:f.favicon??``,onChange:e=>b({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:a,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:l(`appDesigner.fontFamily`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(r.Type,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,C.jsxs)(`select`,{id:`be-font`,"data-testid":`branding-font-select`,value:f.fontFamily??``,onChange:e=>b({fontFamily:e.target.value||void 0}),disabled:a,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 appearance-none`,children:[(0,C.jsx)(`option`,{value:``,children:l(`appDesigner.fontDefault`)}),wt.map(e=>(0,C.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,C.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:l(`appDesigner.brandingPreview`)}),(0,C.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,C.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>d(`light`),className:$(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,u===`light`?`bg-blue-50 text-blue-700`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,C.jsx)(r.Sun,{className:`h-3.5 w-3.5`}),l(`appDesigner.modeLight`)]}),(0,C.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>d(`dark`),className:$(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,u===`dark`?`bg-gray-800 text-gray-100`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,C.jsx)(r.Moon,{className:`h-3.5 w-3.5`}),l(`appDesigner.modeDark`)]})]})]}),(0,C.jsxs)(`div`,{"data-testid":`branding-preview`,className:$(`rounded-lg border p-4 transition-colors`,E?`border-gray-700 bg-gray-900 text-gray-100`:`border-gray-200 bg-white text-gray-800`),style:{fontFamily:f.fontFamily||`inherit`},children:[(0,C.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:T},children:(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[f.logo?(0,C.jsx)(`img`,{src:f.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,C.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,C.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:i})]})}),(0,C.jsxs)(`div`,{className:`space-y-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:T}}),(0,C.jsx)(`span`,{className:$(`text-xs`,E?`text-gray-400`:`text-gray-500`),children:T})]}),(0,C.jsx)(`button`,{type:`button`,className:`rounded-md px-3 py-1.5 text-xs font-medium text-white transition-colors`,style:{backgroundColor:T},tabIndex:-1,children:l(`appDesigner.brandingSampleButton`)}),(0,C.jsx)(`p`,{className:$(`text-xs`,E?`text-gray-400`:`text-gray-500`),children:l(`appDesigner.brandingSampleText`)}),f.favicon&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`img`,{src:f.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,C.jsx)(`span`,{className:$(`text-xs`,E?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),f.fontFamily&&(0,C.jsxs)(`div`,{className:$(`text-xs`,E?`text-gray-400`:`text-gray-500`),children:[l(`appDesigner.fontFamily`),`: `,f.fontFamily]})]})]}),(0,C.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:$(`mx-auto w-48 rounded-xl border-2 p-2 transition-colors`,E?`border-gray-700 bg-gray-900`:`border-gray-300 bg-white`),style:{fontFamily:f.fontFamily||`inherit`},children:[(0,C.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:l(`appDesigner.mobilePreview`)}),(0,C.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:T},children:(0,C.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[f.logo?(0,C.jsx)(`img`,{src:f.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,C.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,C.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:i})]})}),(0,C.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,C.jsx)(`div`,{className:$(`h-2 w-3/4 rounded`,E?`bg-gray-700`:`bg-gray-200`)}),(0,C.jsx)(`div`,{className:$(`h-2 w-1/2 rounded`,E?`bg-gray-700`:`bg-gray-200`)}),(0,C.jsx)(`div`,{className:$(`h-2 w-2/3 rounded`,E?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function Et(...e){return(0,a.twMerge)((0,i.clsx)(e))}function Dt({versions:e,onRestore:t,className:n}){return(0,C.jsxs)(`div`,{className:Et(`flex flex-col`,n),role:`region`,"aria-label":`Version history`,children:[(0,C.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,C.jsx)(r.History,{className:`h-4 w-4`}),`Version History`]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:e.length===0?(0,C.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`No version history available`}):(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`div`,{className:`absolute left-5 top-0 bottom-0 w-px bg-border`}),e.map(e=>(0,C.jsxs)(`div`,{className:Et(`relative flex items-start gap-3 px-3 py-2 hover:bg-accent/50`,e.isCurrent&&`bg-accent/30`),children:[(0,C.jsx)(`div`,{className:Et(`relative z-10 mt-1 h-2.5 w-2.5 rounded-full border-2 bg-background`,e.isCurrent?`border-primary`:`border-muted-foreground`)}),(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,C.jsxs)(`span`,{className:`font-medium`,children:[`v`,e.version]}),e.isCurrent&&(0,C.jsx)(`span`,{className:`px-1 py-0.5 rounded bg-primary/10 text-primary text-[0.6rem]`,children:`Current`})]}),(0,C.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 truncate`,children:e.description}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[0.65rem] text-muted-foreground/70`,children:[(0,C.jsx)(r.User,{className:`h-2.5 w-2.5`}),(0,C.jsx)(`span`,{children:e.userName}),(0,C.jsx)(r.Clock,{className:`h-2.5 w-2.5 ml-1`}),(0,C.jsx)(`span`,{children:new Date(e.timestamp).toLocaleString()})]}),!e.isCurrent&&t&&(0,C.jsx)(`button`,{onClick:()=>t(e.version),className:`mt-1 text-[0.65rem] text-primary hover:underline`,children:`Restore this version`})]})]},e.version))]})})]})}t.ComponentRegistry.register(`page-designer`,R,{label:`Page Designer`,category:`Designer`,inputs:[{name:`canvas`,type:`code`,label:`Canvas Configuration`},{name:`components`,type:`code`,label:`Components`},{name:`showComponentTree`,type:`boolean`,label:`Show Component Tree`,defaultValue:!0},{name:`undoRedo`,type:`boolean`,label:`Undo/Redo`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`data-model-designer`,U,{label:`Data Model Designer`,category:`Designer`,inputs:[{name:`entities`,type:`code`,label:`Entities`},{name:`relationships`,type:`code`,label:`Relationships`},{name:`autoLayout`,type:`boolean`,label:`Auto Layout`,defaultValue:!1},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`process-designer`,re,{label:`Process Designer (BPMN)`,category:`Designer`,inputs:[{name:`processName`,type:`string`,label:`Process Name`},{name:`nodes`,type:`code`,label:`Nodes`},{name:`edges`,type:`code`,label:`Edges`},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`report-designer`,oe,{label:`Report Designer`,category:`Designer`,inputs:[{name:`reportName`,type:`string`,label:`Report Name`},{name:`objectName`,type:`string`,label:`Data Source Object`},{name:`sections`,type:`code`,label:`Sections`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showPropertyPanel`,type:`boolean`,label:`Show Property Panel`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`app-creation-wizard`,He,{label:`App Creation Wizard`,category:`Designer`,inputs:[{name:`availableObjects`,type:`code`,label:`Available Objects`},{name:`templates`,type:`code`,label:`Templates`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`navigation-designer`,Ze,{label:`Navigation Designer`,category:`Designer`,inputs:[{name:`items`,type:`code`,label:`Navigation Items`},{name:`showPreview`,type:`boolean`,label:`Show Preview`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`dashboard-editor`,ct,{label:`Dashboard Editor`,category:`Designer`,inputs:[{name:`schema`,type:`code`,label:`Dashboard Schema`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`page-canvas-editor`,_t,{label:`Page Canvas Editor`,category:`Designer`,inputs:[{name:`schema`,type:`code`,label:`Page Schema`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`object-view-configurator`,St,{label:`Object View Configurator`,category:`Designer`,inputs:[{name:`config`,type:`code`,label:`View Config`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),t.ComponentRegistry.register(`branding-editor`,Tt,{label:`Branding Editor`,category:`Designer`,inputs:[{name:`branding`,type:`code`,label:`Branding Config`},{name:`appTitle`,type:`string`,label:`App Title`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),e.AppCreationWizard=He,e.BrandingEditor=Tt,e.CollaborationProvider=N,e.ConfirmDialog=T,e.ConnectionStatusIndicator=F,e.DashboardEditor=ct,e.DataModelDesigner=U,e.EditorModeToggle=et,e.Minimap=A,e.NavigationDesigner=Ze,e.ObjectViewConfigurator=St,e.PageCanvasEditor=_t,e.PageDesigner=R,e.ProcessDesigner=re,e.PropertyEditor=D,e.ReportDesigner=oe,e.VersionHistory=Dt,e.useCanvasPanZoom=b,e.useClipboard=y,e.useConfirmDialog=_,e.useDesignerHistory=B,e.useMultiSelect=v,e.useUndoRedo=g});
|