@nice2dev/ui 1.0.5 → 1.0.8

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.
Files changed (130) hide show
  1. package/README.md +253 -207
  2. package/dist/NiceAPIFlow.doc-DnQLPUie.js +30 -0
  3. package/dist/NiceAPIFlow.doc-Dx4qw1lm.cjs +6 -0
  4. package/dist/NiceBranchManager.doc-BXjiENlD.cjs +6 -0
  5. package/dist/NiceBranchManager.doc-xLB82YwU.js +30 -0
  6. package/dist/NiceButton-B5RXLDwI.cjs +1 -0
  7. package/dist/NiceButton-CDiS45Ya.cjs +1 -0
  8. package/dist/NiceButton-D9l39Rs7.js +595 -0
  9. package/dist/NiceButton-DmTHNHet.js +450 -0
  10. package/dist/NiceCodeTemplate.doc-BWxTE4C_.cjs +6 -0
  11. package/dist/NiceCodeTemplate.doc-CA2U5F-v.js +30 -0
  12. package/dist/NiceDataBranchGraph.doc-CkitupWc.js +29 -0
  13. package/dist/NiceDataBranchGraph.doc-DDUgipqH.cjs +5 -0
  14. package/dist/NiceDataBranchManager.doc-B0ODKOs4.js +30 -0
  15. package/dist/NiceDataBranchManager.doc-CC5o8ihs.cjs +6 -0
  16. package/dist/NiceDataConflictResolver.doc-CdzScNie.cjs +5 -0
  17. package/dist/NiceDataConflictResolver.doc-V8vxYAeo.js +29 -0
  18. package/dist/NiceDataDiffViewer.doc-CR14Bq3A.cjs +6 -0
  19. package/dist/NiceDataDiffViewer.doc-w2I2QjhX.js +30 -0
  20. package/dist/NiceDataMapper.doc-C7jSyHRM.js +30 -0
  21. package/dist/NiceDataMapper.doc-DXjQHz87.cjs +6 -0
  22. package/dist/NiceDataMergeBuilder.doc-CV32WC_w.cjs +6 -0
  23. package/dist/NiceDataMergeBuilder.doc-DtuYb3nx.js +30 -0
  24. package/dist/NiceDataSnapshot.doc-CFLkY3ry.js +30 -0
  25. package/dist/NiceDataSnapshot.doc-CpZyQ17u.cjs +6 -0
  26. package/dist/NiceErrorBoundary-BAeqfoSc.cjs +1 -0
  27. package/dist/NiceErrorBoundary-D1hh5GGe.js +732 -0
  28. package/dist/NiceErrorBoundary-Dta4TGee.cjs +1 -0
  29. package/dist/NiceErrorBoundary-niMx1aSJ.js +837 -0
  30. package/dist/NiceEventOrchestrator.doc-C4SJfIDV.js +30 -0
  31. package/dist/NiceEventOrchestrator.doc-CxjsLxBG.cjs +6 -0
  32. package/dist/NiceGitBlame.doc-BG3_K9_0.cjs +6 -0
  33. package/dist/NiceGitBlame.doc-DrJABEat.js +30 -0
  34. package/dist/NiceGitConflictResolver.doc-BK7hAfz6.js +30 -0
  35. package/dist/NiceGitConflictResolver.doc-CgroGM9_.cjs +6 -0
  36. package/dist/NiceGitDiffViewer.doc-BAwgcY_3.cjs +6 -0
  37. package/dist/NiceGitDiffViewer.doc-BXKJeP-E.js +30 -0
  38. package/dist/NiceGitGraph.doc-B-WtGuzn.cjs +5 -0
  39. package/dist/NiceGitGraph.doc-DxnDPCgC.js +29 -0
  40. package/dist/NiceGitHooks.doc-BrEizvMp.js +29 -0
  41. package/dist/NiceGitHooks.doc-C4EdV5zj.cjs +5 -0
  42. package/dist/NiceMergeRequestBuilder.doc-C5p8mYuh.cjs +6 -0
  43. package/dist/NiceMergeRequestBuilder.doc-Ct9RCmU8.js +30 -0
  44. package/dist/NiceModuleLifecyclePanel-BapdidD6.js +4776 -0
  45. package/dist/NiceModuleLifecyclePanel-Brg1RLwi.cjs +1 -0
  46. package/dist/NiceModuleLifecyclePanel-CsFsm534.cjs +1 -0
  47. package/dist/NiceModuleLifecyclePanel-I_TXRiiY.js +5053 -0
  48. package/dist/NicePinCodeInput-4q8yULuo.js +13359 -0
  49. package/dist/NicePinCodeInput-CrMfdxxc.js +15287 -0
  50. package/dist/NicePinCodeInput-D0aF9MK8.cjs +692 -0
  51. package/dist/NicePinCodeInput-eD2q8nGa.cjs +692 -0
  52. package/dist/NicePinCodeInput.css +1 -0
  53. package/dist/NicePipelineEditor.doc-0eGt8zbX.cjs +5 -0
  54. package/dist/NicePipelineEditor.doc-DTmaOebn.js +29 -0
  55. package/dist/NicePipelineMonitor.doc-67CmsRcf.cjs +5 -0
  56. package/dist/NicePipelineMonitor.doc-mSMdhuG8.js +29 -0
  57. package/dist/NiceSavedQueryPanel-BZNvqSQW.cjs +596 -0
  58. package/dist/NiceSavedQueryPanel-CUAsdOjJ.js +6190 -0
  59. package/dist/NiceSavedQueryPanel-DUw8plYP.js +5666 -0
  60. package/dist/NiceSavedQueryPanel-xpk09zy1.cjs +596 -0
  61. package/dist/NiceSavedQueryPanel.css +1 -0
  62. package/dist/NiceStateDesigner.doc-B36u0hNU.js +29 -0
  63. package/dist/NiceStateDesigner.doc-MPmvNHSx.cjs +5 -0
  64. package/dist/NiceStockChart-CHlOnWzN.cjs +287 -0
  65. package/dist/NiceStockChart-Cpmv9_Cc.js +2341 -0
  66. package/dist/NiceStockChart.css +1 -0
  67. package/dist/NiceTestBuilder.doc-BFInj8GJ.js +30 -0
  68. package/dist/NiceTestBuilder.doc-CB03U_uR.cjs +6 -0
  69. package/dist/NiceToggle-C1UKGXmJ.js +209 -0
  70. package/dist/NiceToggle-CaY1u82g.js +277 -0
  71. package/dist/NiceToggle-DFJFQv_Z.cjs +1 -0
  72. package/dist/NiceToggle-lVi-ETi0.cjs +1 -0
  73. package/dist/NiceWindow-D1awkyFl.js +1636 -0
  74. package/dist/NiceWindow-IdHAcP70.cjs +1 -0
  75. package/dist/NiceWindow-SiCaREbq.js +1408 -0
  76. package/dist/NiceWindow-yARTUJsg.cjs +1 -0
  77. package/dist/charts-Bx_kNBsE.js +4280 -0
  78. package/dist/charts-DECVsCHX.cjs +754 -0
  79. package/dist/charts.cjs +1 -0
  80. package/dist/charts.css +1 -0
  81. package/dist/charts.d.ts +1043 -0
  82. package/dist/charts.mjs +23 -0
  83. package/dist/core-BZBTsGWN.cjs +96 -0
  84. package/dist/core-BpghV7Ls.js +17555 -0
  85. package/dist/core-CfXsl755.js +16305 -0
  86. package/dist/core-DGJSUW64.cjs +96 -0
  87. package/dist/data-branching-De4ExX-S.cjs +1 -0
  88. package/dist/data-branching-DiRfob1f.js +6071 -0
  89. package/dist/data-branching.cjs +1 -0
  90. package/dist/data-branching.d.ts +401 -0
  91. package/dist/data-branching.mjs +9 -0
  92. package/dist/data.cjs +1 -0
  93. package/dist/data.d.ts +2003 -0
  94. package/dist/data.mjs +21 -0
  95. package/dist/devops-BnYinjkT.cjs +17 -0
  96. package/dist/devops-Ckh57eti.js +7198 -0
  97. package/dist/devops.cjs +1 -0
  98. package/dist/devops.d.ts +758 -0
  99. package/dist/devops.mjs +12 -0
  100. package/dist/editors.cjs +1 -0
  101. package/dist/editors.d.ts +2728 -0
  102. package/dist/editors.mjs +66 -0
  103. package/dist/feedback.cjs +1 -0
  104. package/dist/feedback.d.ts +339 -0
  105. package/dist/feedback.mjs +16 -0
  106. package/dist/index-C853adw1.cjs +6199 -0
  107. package/dist/index-CBIZ6mTQ.cjs +5734 -0
  108. package/dist/index-CIl98Vbm.js +72951 -0
  109. package/dist/index-CNwVELPJ.js +62857 -0
  110. package/dist/index-CUx_-gKK.cjs +1 -0
  111. package/dist/index-x8mRM4Jc.js +17 -0
  112. package/dist/index.cjs +1 -7866
  113. package/dist/index.css +1 -0
  114. package/dist/index.d.ts +4888 -180
  115. package/dist/index.mjs +1021 -105889
  116. package/dist/lazy.cjs +1 -0
  117. package/dist/lazy.d.ts +1880 -0
  118. package/dist/lazy.mjs +98 -0
  119. package/dist/navigation.cjs +1 -0
  120. package/dist/navigation.d.ts +1862 -0
  121. package/dist/navigation.mjs +576 -0
  122. package/dist/no-code-BCuadkm4.cjs +332 -0
  123. package/dist/no-code-TL7PyulA.js +7005 -0
  124. package/dist/no-code.cjs +1 -0
  125. package/dist/no-code.d.ts +870 -0
  126. package/dist/no-code.mjs +13 -0
  127. package/dist/overlays.cjs +1 -0
  128. package/dist/overlays.d.ts +706 -0
  129. package/dist/overlays.mjs +482 -0
  130. package/package.json +51 -1
@@ -0,0 +1,332 @@
1
+ "use strict";const e=require("react/jsx-runtime"),y=require("react"),he=({projectId:i,components:v=[],theme:k="light",onChange:f,onSave:S,className:h})=>{const[j,l]=y.useState("design");return e.jsxs("div",{className:`nice-lowcode-studio nice-lowcode-studio--${k} ${h||""}`,"data-project":i,children:[e.jsxs("header",{className:"nice-lowcode-studio__header",children:[e.jsx("h1",{children:"Low-Code Studio"}),e.jsxs("nav",{className:"nice-lowcode-studio__tabs",children:[e.jsx("button",{onClick:()=>l("design"),className:j==="design"?"active":"",children:"Design"}),e.jsx("button",{onClick:()=>l("preview"),className:j==="preview"?"active":"",children:"Preview"}),e.jsx("button",{onClick:()=>l("code"),className:j==="code"?"active":"",children:"Code"})]}),e.jsx("button",{onClick:()=>S?.({}),children:"Save"})]}),e.jsxs("div",{className:"nice-lowcode-studio__body",children:[e.jsxs("aside",{className:"nice-lowcode-studio__sidebar",children:[e.jsx("h2",{children:"Components"}),e.jsx("ul",{children:v.map(x=>e.jsx("li",{draggable:!0,children:x.name},x.id))})]}),e.jsxs("main",{className:"nice-lowcode-studio__canvas",children:[j==="design"&&e.jsx("div",{className:"nice-lowcode-studio__design-canvas",children:e.jsx("p",{children:"Drop components here"})}),j==="preview"&&e.jsx("div",{className:"nice-lowcode-studio__preview",children:e.jsx("p",{children:"Preview mode"})}),j==="code"&&e.jsx("div",{className:"nice-lowcode-studio__code",children:e.jsx("pre",{children:"// Generated code will appear here"})})]}),e.jsxs("aside",{className:"nice-lowcode-studio__properties",children:[e.jsx("h2",{children:"Properties"}),e.jsx("p",{children:"Select a component to edit properties"})]})]})]})},ye=({component:i,propTypes:v=[],onChange:k,theme:f="light",className:S})=>{const[h,j]=y.useState(i||{name:"NewComponent",props:[]}),l=x=>{const a={...h,...x};j(a),k?.(a)};return e.jsxs("div",{className:`nice-component-designer nice-component-designer--${f} ${S||""}`,children:[e.jsxs("section",{className:"nice-component-designer__header",children:[e.jsx("input",{type:"text",value:h.name,onChange:x=>l({name:x.target.value}),placeholder:"Component Name"}),e.jsx("input",{type:"text",value:h.description||"",onChange:x=>l({description:x.target.value}),placeholder:"Description"})]}),e.jsxs("section",{className:"nice-component-designer__props",children:[e.jsx("h3",{children:"Props"}),h.props.map((x,a)=>e.jsxs("div",{className:"nice-component-designer__prop",children:[e.jsx("input",{type:"text",value:x.name,readOnly:!0}),e.jsx("span",{children:x.type}),x.required&&e.jsx("span",{children:"required"})]},a)),e.jsx("button",{onClick:()=>l({props:[...h.props,{name:"newProp",type:"string"}]}),children:"Add Prop"})]}),e.jsxs("section",{className:"nice-component-designer__preview",children:[e.jsx("h3",{children:"Preview"}),e.jsx("pre",{children:`interface ${h.name}Props {
2
+ ${h.props.map(x=>` ${x.name}${x.required?"":"?"}: ${x.type};`).join(`
3
+ `)}
4
+ }
5
+
6
+ export const ${h.name}: React.FC<${h.name}Props> = (props) => {
7
+ return <div>Component</div>;
8
+ };`})]})]})},fe=({initialLayout:i,components:v=[],grid:k={columns:12,gap:16,padding:24},onChange:f,onSave:S,theme:h="light",previewMode:j="desktop",className:l})=>{const[x,a]=y.useState(i||{id:"page-1",name:"New Page",rows:[]}),[d,R]=y.useState(null),z=C=>{a(C),f?.(C)},w=()=>{const C={id:`row-${Date.now()}`,columns:[{id:`col-${Date.now()}`,width:12,components:[]}]};z({...x,rows:[...x.rows,C]})},L={desktop:"100%",tablet:"768px",mobile:"375px"}[j];return e.jsxs("div",{className:`nice-page-builder nice-page-builder--${h} ${l||""}`,children:[e.jsxs("aside",{className:"nice-page-builder__sidebar",children:[e.jsx("h3",{children:"Components"}),e.jsx("ul",{className:"nice-page-builder__components",children:v.map(C=>e.jsxs("li",{draggable:!0,className:"nice-page-builder__component-item",children:[C.icon&&e.jsx("span",{children:C.icon}),C.name]},C.id))})]}),e.jsxs("main",{className:"nice-page-builder__canvas",children:[e.jsxs("header",{className:"nice-page-builder__toolbar",children:[e.jsx("input",{type:"text",value:x.name,onChange:C=>z({...x,name:C.target.value})}),e.jsxs("div",{className:"nice-page-builder__preview-modes",children:[e.jsx("button",{className:j==="desktop"?"active":"",children:"Desktop"}),e.jsx("button",{className:j==="tablet"?"active":"",children:"Tablet"}),e.jsx("button",{className:j==="mobile"?"active":"",children:"Mobile"})]}),e.jsx("button",{onClick:()=>S?.(x),children:"Save"})]}),e.jsxs("div",{className:"nice-page-builder__viewport",style:{maxWidth:L},children:[x.rows.map(C=>e.jsx("div",{className:"nice-page-builder__row",children:C.columns.map(N=>e.jsx("div",{className:"nice-page-builder__column",style:{width:`${N.width/12*100}%`},children:N.components.length===0?e.jsx("div",{className:"nice-page-builder__dropzone",children:"Drop components here"}):N.components.map(P=>e.jsx("div",{className:`nice-page-builder__placed-component ${d===P.id?"selected":""}`,onClick:()=>R(P.id),children:P.type},P.id))},N.id))},C.id)),e.jsx("button",{onClick:w,className:"nice-page-builder__add-row",children:"+ Add Row"})]})]}),e.jsxs("aside",{className:"nice-page-builder__properties",children:[e.jsx("h3",{children:"Properties"}),d?e.jsx("p",{children:"Edit properties for selected component"}):e.jsx("p",{children:"Select a component to edit"})]})]})},be=({code:i,language:v="typescript",lineNumbers:k=!0,livePreview:f=!1,showDiff:S=!1,previousCode:h,theme:j="light",copyable:l=!0,onCopy:x,className:a})=>{const[d,R]=y.useState(!1),z=async()=>{await navigator.clipboard.writeText(i),R(!0),x?.(),setTimeout(()=>R(!1),2e3)},w=i.split(`
9
+ `),L=()=>e.jsx("div",{className:"nice-code-preview__line-numbers",children:w.map((q,A)=>e.jsx("span",{children:A+1},A))}),C=()=>e.jsx("pre",{className:`nice-code-preview__code language-${v}`,children:e.jsx("code",{children:i})}),N=()=>h?(h.split(`
10
+ `),i.split(`
11
+ `),e.jsxs("div",{className:"nice-code-preview__diff",children:[e.jsxs("div",{className:"nice-code-preview__diff-panel nice-code-preview__diff-panel--old",children:[e.jsx("h4",{children:"Previous"}),e.jsx("pre",{children:h})]}),e.jsxs("div",{className:"nice-code-preview__diff-panel nice-code-preview__diff-panel--new",children:[e.jsx("h4",{children:"Current"}),e.jsx("pre",{children:i})]})]})):null,P=()=>v!=="html"&&v!=="jsx"&&v!=="tsx"?e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("p",{children:"Live preview only available for HTML, JSX, and TSX"})}):e.jsx("div",{className:"nice-code-preview__live-preview",children:e.jsx("iframe",{srcDoc:v==="html"?i:'<div id="root"></div><script>/* Preview not available for JSX */<\/script>',title:"Live Preview",sandbox:"allow-scripts"})});return e.jsxs("div",{className:`nice-code-preview nice-code-preview--${j} ${a||""}`,children:[e.jsxs("header",{className:"nice-code-preview__header",children:[e.jsx("span",{className:"nice-code-preview__language",children:v}),l&&e.jsx("button",{onClick:z,className:"nice-code-preview__copy-btn",children:d?"✓ Copied":"Copy"})]}),S&&h?N():e.jsxs("div",{className:"nice-code-preview__body",children:[k&&L(),C()]}),f&&e.jsxs("div",{className:"nice-code-preview__preview-section",children:[e.jsx("h4",{children:"Preview"}),P()]})]})},ve={id:"store-1",name:"AppStore",description:"Main application state store",slices:[{id:"slice-auth",name:"auth",description:"Authentication state",state:[{id:"f1",name:"user",type:"object",nullable:!0,description:"Current user"},{id:"f2",name:"isAuthenticated",type:"boolean",defaultValue:!1},{id:"f3",name:"token",type:"string",nullable:!0},{id:"f4",name:"loading",type:"boolean",defaultValue:!1},{id:"f5",name:"error",type:"string",nullable:!0}],actions:[{id:"a1",name:"login",description:"Authenticate user",async:!0,params:[{id:"p1",name:"email",type:"string",required:!0},{id:"p2",name:"password",type:"string",required:!0}],reducerSteps:[{id:"s1",type:"set",field:"loading",value:"true"},{id:"s2",type:"set",field:"error",value:"null"},{id:"s3",type:"set",field:"user",value:"response.user"},{id:"s4",type:"set",field:"token",value:"response.token"},{id:"s5",type:"set",field:"isAuthenticated",value:"true"},{id:"s6",type:"set",field:"loading",value:"false"}]},{id:"a2",name:"logout",description:"Clear user session",params:[],reducerSteps:[{id:"s1",type:"reset",field:"user"},{id:"s2",type:"set",field:"isAuthenticated",value:"false"},{id:"s3",type:"reset",field:"token"}]}],selectors:[{id:"sel1",name:"selectUser",expression:"state.auth.user",dependencies:["user"],memoized:!0},{id:"sel2",name:"selectIsLoggedIn",expression:"state.auth.isAuthenticated",dependencies:["isAuthenticated"]}]},{id:"slice-cart",name:"cart",description:"Shopping cart state",state:[{id:"f1",name:"items",type:"array",defaultValue:[],description:"Cart items"},{id:"f2",name:"total",type:"number",defaultValue:0},{id:"f3",name:"currency",type:"string",defaultValue:"USD"}],actions:[{id:"a1",name:"addItem",params:[{id:"p1",name:"item",type:"object",required:!0}],reducerSteps:[{id:"s1",type:"push",field:"items",value:"item"},{id:"s2",type:"update",field:"total",value:"state.total + item.price"}]},{id:"a2",name:"removeItem",params:[{id:"p1",name:"itemId",type:"string",required:!0}],reducerSteps:[{id:"s1",type:"remove",field:"items",value:"item.id !== itemId"}]},{id:"a3",name:"clearCart",params:[],reducerSteps:[{id:"s1",type:"set",field:"items",value:"[]"},{id:"s2",type:"set",field:"total",value:"0"}]}],selectors:[{id:"sel1",name:"selectCartItems",expression:"state.cart.items",dependencies:["items"]},{id:"sel2",name:"selectCartCount",expression:"state.cart.items.length",dependencies:["items"],memoized:!0},{id:"sel3",name:"selectCartTotal",expression:"state.cart.total",dependencies:["total"]}],computed:[{id:"c1",name:"itemCount",expression:"items.length",dependencies:["items"]}]}],middleware:[{type:"immer",enabled:!0},{type:"devtools",enabled:!0},{type:"persist",enabled:!0}],persist:{enabled:!0,key:"app-store",storage:"localStorage",whitelist:["auth.token","cart.items"],version:1},devtools:{enabled:!0,name:"AppStore",trace:!0}},je=[{id:"tpl-auth",name:"Authentication",description:"User authentication with token",icon:"🔐",store:{slices:[{id:"auth",name:"auth",state:[{id:"user",name:"user",type:"object",nullable:!0},{id:"token",name:"token",type:"string",nullable:!0},{id:"isAuthenticated",name:"isAuthenticated",type:"boolean",defaultValue:!1}],actions:[],selectors:[]}]}},{id:"tpl-crud",name:"CRUD Entity",description:"Standard entity with loading states",icon:"📦",store:{slices:[{id:"entity",name:"entity",state:[{id:"items",name:"items",type:"array",defaultValue:[]},{id:"selected",name:"selected",type:"object",nullable:!0},{id:"loading",name:"loading",type:"boolean",defaultValue:!1},{id:"error",name:"error",type:"string",nullable:!0}],actions:[],selectors:[]}]}},{id:"tpl-ui",name:"UI State",description:"Theme, sidebar, modal states",icon:"🎨",store:{slices:[{id:"ui",name:"ui",state:[{id:"theme",name:"theme",type:"enum",defaultValue:"light"},{id:"sidebarOpen",name:"sidebarOpen",type:"boolean",defaultValue:!0},{id:"activeModal",name:"activeModal",type:"string",nullable:!0}],actions:[],selectors:[]}]}}],X={string:"📝",number:"🔢",boolean:"✓",array:"📋",object:"{}",date:"📅",enum:"📊",custom:"⚙️"},Q=i=>{const v=["import { create } from 'zustand'"];i.middleware?.some(a=>a.type==="devtools"&&a.enabled)&&v.push("import { devtools } from 'zustand/middleware'"),i.middleware?.some(a=>a.type==="persist"&&a.enabled)&&v.push("import { persist } from 'zustand/middleware'"),i.middleware?.some(a=>a.type==="immer"&&a.enabled)&&v.push("import { immer } from 'zustand/middleware/immer'");const k=[];i.slices.forEach(a=>{k.push(`interface ${Z(a.name)}State {`),a.state.forEach(d=>{const R=ee(d.type,d.nullable);k.push(` ${d.name}: ${R};`)}),k.push("}"),k.push("")}),k.push("interface Actions {"),i.slices.forEach(a=>{a.actions.forEach(d=>{const R=d.params.map(w=>`${w.name}: ${ee(w.type)}`).join(", "),z=d.async?"Promise<void>":"void";k.push(` ${d.name}: (${R}) => ${z};`)})}),k.push("}");const f=i.slices.map(a=>`${Z(a.name)}State`).join(" & ");k.push(""),k.push(`type StoreState = ${f} & Actions;`);const S=[];i.slices.forEach(a=>{a.state.forEach(d=>{const R=d.defaultValue!==void 0?JSON.stringify(d.defaultValue):d.nullable?"null":ae(d.type);S.push(` ${d.name}: ${R},`)})});const h=[];i.slices.forEach(a=>{a.actions.forEach(d=>{const R=d.params.map(w=>w.name).join(", "),z=d.async?"async ":"";h.push(` ${d.name}: ${z}(${R}) => {`),d.async?(h.push(" set({ loading: true, error: null });"),h.push(" try {"),h.push(" // TODO: API call"),h.push(` // const response = await api.${d.name}(${R});`),d.reducerSteps.forEach(w=>{w.type==="set"&&h.push(` set({ ${w.field}: ${w.value} });`)}),h.push(" } catch (error) {"),h.push(" set({ error: error.message, loading: false });"),h.push(" }")):(h.push(" set((state) => {"),d.reducerSteps.forEach(w=>{w.type==="set"?h.push(` state.${w.field} = ${w.value};`):w.type==="push"?h.push(` state.${w.field}.push(${w.value});`):w.type==="reset"&&h.push(` state.${w.field} = null;`)}),h.push(" });")),h.push(" },")})});let j="",l="";if(i.middleware?.some(a=>a.type==="immer"&&a.enabled)&&(j+="immer(",l=")"+l),i.middleware?.some(a=>a.type==="devtools"&&a.enabled)&&(j+="devtools(",l=`, { name: '${i.devtools?.name||i.name}' })`+l),i.persist?.enabled){j+="persist(";const a=[`name: '${i.persist.key}'`];i.persist.whitelist&&a.push(`partialize: (state) => ({ ${i.persist.whitelist.map(d=>d.split(".").pop()).join(", ")} })`),l=`, { ${a.join(", ")} })`+l}return`${v.join(`
12
+ `)}
13
+
14
+ // Types
15
+ ${k.join(`
16
+ `)}
17
+
18
+ // Store
19
+ export const use${i.name} = create<StoreState>()(
20
+ ${j}(set, get) => ({
21
+ // Initial State
22
+ ${S.join(`
23
+ `)}
24
+
25
+ // Actions
26
+ ${h.join(`
27
+ `)}
28
+ })${l}
29
+ );
30
+
31
+ // Selectors
32
+ ${i.slices.flatMap(a=>a.selectors.map(d=>`export const ${d.name} = (state: StoreState) => ${d.expression.replace("state.","state.")};`)).join(`
33
+ `)}
34
+ `},Z=i=>i.charAt(0).toUpperCase()+i.slice(1),ee=(i,v)=>{const k={string:"string",number:"number",boolean:"boolean",array:"unknown[]",object:"Record<string, unknown>",date:"Date",enum:"string",custom:"unknown"}[i];return v?`${k} | null`:k},ae=i=>({string:"''",number:"0",boolean:"false",array:"[]",object:"{}",date:"new Date()",enum:"''",custom:"null"})[i],de=({store:i=ve,templates:v=je,onStoreChange:k,onExport:f,onSave:S,className:h,style:j,"data-testid":l})=>{const[x,a]=y.useState(i),[d,R]=y.useState("slices"),[z,w]=y.useState(x.slices[0]?.id||null),[L,C]=y.useState(null),[N,P]=y.useState("zustand"),[q,A]=y.useState(!1),[W,g]=y.useState(null),[T,D]=y.useState(""),[B,H]=y.useState("string"),M=y.useMemo(()=>x.slices.find(r=>r.id===z),[x.slices,z]),F=y.useCallback(r=>{const s={...x,...r};a(s),k?.(s)},[x,k]),U=()=>{const r={id:`slice-${Date.now()}`,name:"newSlice",state:[],actions:[],selectors:[]};F({slices:[...x.slices,r]}),w(r.id)},u=()=>{if(!M||!T)return;const r={id:`field-${Date.now()}`,name:T,type:B,defaultValue:ae(B).replace(/'/g,"")},s=x.slices.map($=>$.id===M.id?{...$,state:[...$.state,r]}:$);F({slices:s}),D("")},t=()=>{if(!M)return;const r={id:`action-${Date.now()}`,name:"newAction",params:[],reducerSteps:[]},s=x.slices.map($=>$.id===M.id?{...$,actions:[...$.actions,r]}:$);F({slices:s}),C(r.id)},n=y.useCallback(()=>{let r="";N==="zustand"?r=Q(x):r=`// Export for ${N} coming soon...
35
+ // Store: ${x.name}`,f?.(r,N)},[x,N,f]),m=y.useMemo(()=>N==="zustand"?Q(x):`// ${N} export coming soon...`,[x,N]),o={bg:"#1e1e1e",cardBg:"#252525",border:"#333",text:"#e0e0e0",textMuted:"#888",accent:"#3b82f6"};return e.jsxs("div",{className:`nice-state-designer ${h||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:o.bg,color:o.text,fontFamily:"system-ui, sans-serif",...j},"data-testid":l,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${o.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsx("h3",{style:{margin:0,fontSize:18},children:"🗂️ State Designer"}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8},children:e.jsx("input",{type:"text",value:x.name,onChange:r=>F({name:r.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:14,fontWeight:600}})}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>A(!0),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:13},children:"📋 Templates"}),e.jsx("button",{onClick:()=>S?.(x),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"#22c55e",color:"white",cursor:"pointer",fontSize:13,fontWeight:500},children:"💾 Save"})]})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${o.border}`,padding:"0 20px"},children:["slices","actions","selectors","settings","preview"].map(r=>e.jsxs("button",{onClick:()=>R(r),style:{padding:"12px 20px",border:"none",background:"transparent",color:d===r?o.text:o.textMuted,cursor:"pointer",fontSize:13,fontWeight:d===r?600:400,borderBottom:d===r?`2px solid ${o.accent}`:"2px solid transparent",marginBottom:-1},children:[r==="slices"&&"📦 Slices",r==="actions"&&"⚡ Actions",r==="selectors"&&"🎯 Selectors",r==="settings"&&"⚙️ Settings",r==="preview"&&"👁️ Preview"]},r))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(d==="slices"||d==="actions"||d==="selectors")&&e.jsxs("div",{style:{width:200,borderRight:`1px solid ${o.border}`,padding:12,display:"flex",flexDirection:"column",gap:8},children:[e.jsx("div",{style:{fontSize:11,color:o.textMuted,marginBottom:4},children:"SLICES"}),x.slices.map(r=>e.jsxs("button",{onClick:()=>w(r.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:z===r.id?o.accent+"30":o.cardBg,color:o.text,cursor:"pointer",textAlign:"left",fontSize:13},children:["📦 ",r.name,e.jsxs("div",{style:{fontSize:10,color:o.textMuted},children:[r.state.length," fields • ",r.actions.length," actions"]})]},r.id)),e.jsx("button",{onClick:U,style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${o.border}`,background:"transparent",color:o.textMuted,cursor:"pointer",fontSize:13},children:"+ Add Slice"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[d==="slices"&&M&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20},children:[e.jsxs("h4",{style:{margin:0},children:["📦 ",M.name]}),e.jsx("input",{type:"text",value:M.name,onChange:r=>{const s=x.slices.map($=>$.id===M.id?{...$,name:r.target.value}:$);F({slices:s})},style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13}})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsxs("div",{style:{fontSize:12,color:o.textMuted,marginBottom:12},children:["STATE FIELDS (",M.state.length,")"]}),e.jsxs("div",{style:{border:`1px solid ${o.border}`,borderRadius:8,overflow:"hidden"},children:[M.state.map(r=>e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${o.border}`,display:"flex",alignItems:"center",gap:12},children:[e.jsx("span",{style:{fontSize:16},children:X[r.type]}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500,fontFamily:"monospace"},children:r.name}),e.jsxs("div",{style:{fontSize:11,color:o.textMuted},children:[r.type,r.nullable&&"?",r.defaultValue!==void 0&&` = ${JSON.stringify(r.defaultValue)}`]})]}),e.jsx("button",{onClick:()=>{const s=x.slices.map($=>$.id===M.id?{...$,state:$.state.filter(c=>c.id!==r.id)}:$);F({slices:s})},style:{padding:4,border:"none",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:14},children:"🗑️"})]},r.id)),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",alignItems:"center",gap:8,background:o.cardBg},children:[e.jsx("input",{type:"text",placeholder:"fieldName",value:T,onChange:r=>D(r.target.value),style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:13,fontFamily:"monospace"}}),e.jsx("select",{value:B,onChange:r=>H(r.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.bg,color:o.text,fontSize:13},children:Object.keys(X).map(r=>e.jsx("option",{value:r,children:r},r))}),e.jsx("button",{onClick:u,disabled:!T,style:{padding:"8px 16px",borderRadius:4,border:"none",background:T?o.accent:o.border,color:"white",cursor:T?"pointer":"not-allowed",fontSize:13},children:"+ Add"})]})]})]})]}),d==="actions"&&M&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20},children:[e.jsxs("h4",{style:{margin:0},children:["⚡ Actions for ",M.name]}),e.jsx("button",{onClick:t,style:{padding:"6px 12px",borderRadius:4,border:"none",background:o.accent,color:"white",cursor:"pointer",fontSize:12},children:"+ Add Action"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:M.actions.map(r=>e.jsxs("div",{style:{padding:16,background:o.cardBg,borderRadius:8,border:`1px solid ${L===r.id?o.accent:o.border}`,cursor:"pointer"},onClick:()=>C(r.id),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:r.name}),r.async&&e.jsx("span",{style:{padding:"2px 6px",background:"#8b5cf620",color:"#8b5cf6",borderRadius:4,fontSize:10},children:"async"}),e.jsxs("span",{style:{fontSize:11,color:o.textMuted},children:["(",r.params.map(s=>`${s.name}: ${s.type}`).join(", "),")"]})]}),r.description&&e.jsx("div",{style:{fontSize:12,color:o.textMuted,marginTop:4},children:r.description}),e.jsxs("div",{style:{fontSize:11,color:o.textMuted,marginTop:8},children:[r.reducerSteps.length," reducer steps"]})]},r.id))})]}),d==="selectors"&&M&&e.jsxs("div",{children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20},children:e.jsxs("h4",{style:{margin:0},children:["🎯 Selectors for ",M.name]})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:M.selectors.map(r=>e.jsxs("div",{style:{padding:16,background:o.cardBg,borderRadius:8,border:`1px solid ${o.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontWeight:600,fontFamily:"monospace"},children:r.name}),r.memoized&&e.jsx("span",{style:{padding:"2px 6px",background:"#22c55e20",color:"#22c55e",borderRadius:4,fontSize:10},children:"memoized"})]}),e.jsx("code",{style:{display:"block",marginTop:8,padding:8,background:o.bg,borderRadius:4,fontSize:12,color:"#f59e0b"},children:r.expression})]},r.id))})]}),d==="settings"&&e.jsxs("div",{style:{maxWidth:600},children:[e.jsx("h4",{style:{marginTop:0},children:"Middleware"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:24},children:x.middleware?.map(r=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,padding:12,background:o.cardBg,borderRadius:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:r.enabled,onChange:s=>{const $=x.middleware?.map(c=>c.type===r.type?{...c,enabled:s.target.checked}:c);F({middleware:$})}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,textTransform:"capitalize"},children:r.type}),e.jsxs("div",{style:{fontSize:11,color:o.textMuted},children:[r.type==="immer"&&"Enable immutable state updates",r.type==="devtools"&&"Redux DevTools integration",r.type==="persist"&&"Persist state to storage"]})]})]},r.type))}),x.persist?.enabled&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Persistence"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:o.textMuted,marginBottom:4},children:"Storage Key"}),e.jsx("input",{type:"text",value:x.persist.key,onChange:r=>F({persist:{...x.persist,key:r.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13,width:"100%",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:o.textMuted,marginBottom:4},children:"Storage Type"}),e.jsxs("select",{value:x.persist.storage,onChange:r=>F({persist:{...x.persist,storage:r.target.value}}),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13},children:[e.jsx("option",{value:"localStorage",children:"localStorage"}),e.jsx("option",{value:"sessionStorage",children:"sessionStorage"}),e.jsx("option",{value:"indexedDB",children:"indexedDB"})]})]})]})]})]}),d==="preview"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:16},children:[e.jsxs("select",{value:N,onChange:r=>P(r.target.value),style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${o.border}`,background:o.cardBg,color:o.text,fontSize:13},children:[e.jsx("option",{value:"zustand",children:"Zustand"}),e.jsx("option",{value:"redux-toolkit",children:"Redux Toolkit"}),e.jsx("option",{value:"jotai",children:"Jotai"}),e.jsx("option",{value:"recoil",children:"Recoil"}),e.jsx("option",{value:"mobx",children:"MobX"})]}),e.jsx("button",{onClick:n,style:{padding:"8px 16px",borderRadius:4,border:"none",background:o.accent,color:"white",cursor:"pointer",fontSize:13},children:"📤 Export"}),e.jsx("button",{onClick:()=>navigator.clipboard.writeText(m),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${o.border}`,background:"transparent",color:o.text,cursor:"pointer",fontSize:13},children:"📋 Copy"})]}),e.jsx("pre",{style:{flex:1,padding:16,background:o.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:m})]})]})]}),q&&e.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>A(!1),children:e.jsxs("div",{style:{background:o.cardBg,borderRadius:12,padding:24,width:500,maxHeight:"80vh",overflow:"auto"},onClick:r=>r.stopPropagation(),children:[e.jsx("h4",{style:{margin:"0 0 16px"},children:"📋 State Templates"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:v.map(r=>e.jsx("button",{onClick:()=>{r.store.slices&&F({slices:[...x.slices,...r.store.slices]}),A(!1)},style:{padding:16,borderRadius:8,border:`1px solid ${o.border}`,background:o.bg,color:o.text,cursor:"pointer",textAlign:"left"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:24},children:r.icon}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:r.name}),e.jsx("div",{style:{fontSize:12,color:o.textMuted},children:r.description})]})]})},r.id))})]})})]})},Se=Object.freeze(Object.defineProperty({__proto__:null,NiceStateDesigner:de},Symbol.toStringTag,{value:"Module"})),ke={id:"api-1",name:"UserAPI",description:"User management API client",baseUrl:"https://api.example.com/v1",version:"1.0.0",endpoints:[{id:"ep-1",name:"getUsers",description:"Get list of users",method:"GET",path:"/users",tags:["users"],queryParams:[{id:"p1",name:"page",type:"number",defaultValue:1},{id:"p2",name:"limit",type:"number",defaultValue:10},{id:"p3",name:"search",type:"string"}],responses:[{status:200,description:"Success",schema:{type:"array",items:{type:"object"}}},{status:401,description:"Unauthorized"}],cache:{enabled:!0,ttl:60,strategy:"stale-while-revalidate"}},{id:"ep-2",name:"getUserById",description:"Get single user by ID",method:"GET",path:"/users/{id}",tags:["users"],pathParams:[{id:"p1",name:"id",type:"string",required:!0}],responses:[{status:200,description:"Success"},{status:404,description:"Not found"}],cache:{enabled:!0,ttl:300,strategy:"cache-first"}},{id:"ep-3",name:"createUser",description:"Create new user",method:"POST",path:"/users",tags:["users"],body:{contentType:"application/json",schema:{type:"object",properties:{name:{type:"string"},email:{type:"string"},role:{type:"string"}},required:["name","email"]}},responses:[{status:201,description:"Created"},{status:400,description:"Validation error"}],retry:{enabled:!0,maxAttempts:3,backoff:"exponential",retryOn:[500,502,503]}},{id:"ep-4",name:"updateUser",description:"Update user by ID",method:"PUT",path:"/users/{id}",tags:["users"],pathParams:[{id:"p1",name:"id",type:"string",required:!0}],body:{contentType:"application/json",schema:{type:"object",properties:{name:{type:"string"},email:{type:"string"}}}},responses:[{status:200,description:"Updated"},{status:404,description:"Not found"}]},{id:"ep-5",name:"deleteUser",description:"Delete user by ID",method:"DELETE",path:"/users/{id}",tags:["users"],pathParams:[{id:"p1",name:"id",type:"string",required:!0}],responses:[{status:204,description:"Deleted"},{status:404,description:"Not found"}]}],auth:{type:"bearer",tokenSource:"state.auth.token",headerName:"Authorization",prefix:"Bearer"},globalHeaders:{"Content-Type":"application/json",Accept:"application/json"},errorHandling:{globalErrorHandler:!0,retryOnNetworkError:!0,transformError:!0},cacheConfig:{enabled:!0,storage:"memory",defaultTTL:300}},J={GET:"#22c55e",POST:"#3b82f6",PUT:"#f59e0b",PATCH:"#8b5cf6",DELETE:"#ef4444",HEAD:"#6b7280",OPTIONS:"#6b7280"},we=i=>{const v=["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';"],k=[];i.endpoints.forEach(l=>{l.body?.schema&&k.push(`export interface ${G(l.name)}Request ${le(l.body.schema)}`),k.push(`export interface ${G(l.name)}Response {
36
+ // TODO: Define response type based on schema
37
+ data: unknown;
38
+ }`)});const f=[];i.endpoints.forEach(l=>{const x=l.pathParams?.map(C=>`${C.name}: ${C.type}`).join(", ")||"",a=l.queryParams?.length?`params?: { ${l.queryParams.map(C=>`${C.name}${C.required?"":"?"}: ${C.type}`).join("; ")} }`:"",d=l.body?`data: ${G(l.name)}Request`:"",R=[x,a,d].filter(Boolean).join(", ");let z=`'${l.path}'`;l.pathParams?.forEach(C=>{z=z.replace(`{${C.name}}`,`\${${C.name}}`)}),l.pathParams?.length&&(z="`"+z.slice(1,-1)+"`");const w=l.cache?.enabled?`
39
+ // Cache: ${l.cache.strategy}, TTL: ${l.cache.ttl}s`:"",L=l.retry?.enabled?`
40
+ // Retry: ${l.retry.maxAttempts} attempts, ${l.retry.backoff} backoff`:"";f.push(`
41
+ /**
42
+ * ${l.description||l.name}${w}${L}
43
+ */
44
+ async ${l.name}(${R}): Promise<${G(l.name)}Response> {
45
+ const response = await this.client.${l.method.toLowerCase()}<${G(l.name)}Response>(
46
+ ${z}${l.queryParams?.length?", { params }":""}${l.body?", data":""}
47
+ );
48
+ return response.data;
49
+ }`)});let S="";i.auth?.type==="bearer"&&(S=`
50
+ // Auth interceptor
51
+ this.client.interceptors.request.use((config) => {
52
+ const token = ${i.auth.tokenSource||"getToken()"};
53
+ if (token) {
54
+ config.headers['${i.auth.headerName||"Authorization"}'] = '${i.auth.prefix||"Bearer"} ' + token;
55
+ }
56
+ return config;
57
+ });`);const h=i.errorHandling?.globalErrorHandler?`
58
+ // Error interceptor
59
+ this.client.interceptors.response.use(
60
+ (response) => response,
61
+ (error) => {
62
+ // Transform and handle errors
63
+ const message = error.response?.data?.message || error.message;
64
+ console.error('[API Error]', message);
65
+ return Promise.reject(error);
66
+ }
67
+ );`:"";return`${v.join(`
68
+ `)}
69
+
70
+ // Types
71
+ ${k.join(`
72
+
73
+ `)}
74
+
75
+ // API Client
76
+ export class ${i.name} {
77
+ private client: AxiosInstance;
78
+
79
+ constructor(baseURL: string = '${i.baseUrl}') {
80
+ this.client = axios.create({
81
+ baseURL,
82
+ headers: ${JSON.stringify(i.globalHeaders||{},null,8).replace(/\n/g,`
83
+ `)},
84
+ });
85
+ ${S}${h}
86
+ }
87
+ ${f.join("")}
88
+ }
89
+
90
+ // Default instance
91
+ export const ${i.name.charAt(0).toLowerCase()+i.name.slice(1)} = new ${i.name}();
92
+ `},G=i=>i.charAt(0).toUpperCase()+i.slice(1),le=i=>i.type==="object"&&i.properties?`{
93
+ ${Object.entries(i.properties).map(([k,f])=>{const S=i.required?.includes(k)?"":"?";return` ${k}${S}: ${ce(f)};`}).join(`
94
+ `)}
95
+ }`:"{}",ce=i=>{switch(i.type){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"array":return i.items?`${ce(i.items)}[]`:"unknown[]";case"object":return i.properties?le(i):"Record<string, unknown>";default:return"unknown"}},pe=({flow:i=ke,dataSources:v=[],onFlowChange:k,onExport:f,onTest:S,onSave:h,className:j,style:l,"data-testid":x})=>{const[a,d]=y.useState(i),[R,z]=y.useState("endpoints"),[w,L]=y.useState(a.endpoints[0]?.id||null),[C,N]=y.useState(!1),[P,q]=y.useState(null),[A,W]=y.useState(!1),g=y.useMemo(()=>a.endpoints.find(t=>t.id===w),[a.endpoints,w]),T=y.useCallback(t=>{const n={...a,...t};d(n),k?.(n)},[a,k]),D=y.useCallback((t,n)=>{const m=a.endpoints.map(o=>o.id===t?{...o,...n}:o);T({endpoints:m})},[a.endpoints,T]),B=t=>{const n={id:`ep-${Date.now()}`,name:"newEndpoint",method:t,path:"/new-path",responses:[{status:200,description:"Success"}]};T({endpoints:[...a.endpoints,n]}),L(n.id),N(!1)},H=t=>{T({endpoints:a.endpoints.filter(n=>n.id!==t)}),w===t&&L(a.endpoints[0]?.id||null)},M=async()=>{g&&(W(!0),q(null),await new Promise(t=>setTimeout(t,1e3)),q({status:200,body:{message:"Mock response",timestamp:new Date().toISOString()}}),W(!1),S?.(g.id))},F=y.useMemo(()=>we(a),[a]),U=()=>{f?.(F)};y.useMemo(()=>{const t=new Set;return a.endpoints.forEach(n=>n.tags?.forEach(m=>t.add(m))),Array.from(t)},[a.endpoints]);const u={bg:"#1e1e1e",cardBg:"#252525",border:"#333",text:"#e0e0e0",textMuted:"#888",accent:"#3b82f6"};return e.jsxs("div",{className:`nice-api-flow ${j||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:u.bg,color:u.text,fontFamily:"system-ui, sans-serif",...l},"data-testid":x,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${u.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsx("h3",{style:{margin:0,fontSize:18},children:"🔌 API Flow"}),e.jsx("input",{type:"text",value:a.name,onChange:t=>T({name:t.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:14,fontWeight:600}}),e.jsx("input",{type:"text",value:a.baseUrl,onChange:t=>T({baseUrl:t.target.value}),placeholder:"Base URL",style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,width:300}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsx("button",{onClick:()=>h?.(a),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"#22c55e",color:"white",cursor:"pointer",fontSize:13,fontWeight:500},children:"💾 Save"})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${u.border}`,padding:"0 20px"},children:["endpoints","auth","settings","test","preview"].map(t=>e.jsxs("button",{onClick:()=>z(t),style:{padding:"12px 20px",border:"none",background:"transparent",color:R===t?u.text:u.textMuted,cursor:"pointer",fontSize:13,fontWeight:R===t?600:400,borderBottom:R===t?`2px solid ${u.accent}`:"2px solid transparent",marginBottom:-1},children:[t==="endpoints"&&"🔗 Endpoints",t==="auth"&&"🔐 Auth",t==="settings"&&"⚙️ Settings",t==="test"&&"🧪 Test",t==="preview"&&"👁️ Preview"]},t))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[R==="endpoints"&&e.jsxs("div",{style:{width:280,borderRight:`1px solid ${u.border}`,padding:12,display:"flex",flexDirection:"column",gap:4,overflow:"auto"},children:[e.jsxs("div",{style:{fontSize:11,color:u.textMuted,marginBottom:8},children:["ENDPOINTS (",a.endpoints.length,")"]}),a.endpoints.map(t=>e.jsxs("button",{onClick:()=>L(t.id),style:{padding:"10px 12px",borderRadius:6,border:"none",background:w===t.id?u.accent+"30":u.cardBg,color:u.text,cursor:"pointer",textAlign:"left",display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{padding:"2px 6px",borderRadius:4,background:J[t.method]+"30",color:J[t.method],fontSize:10,fontWeight:600},children:t.method}),e.jsxs("div",{style:{flex:1,overflow:"hidden"},children:[e.jsx("div",{style:{fontFamily:"monospace",fontSize:12},children:t.name}),e.jsx("div",{style:{fontSize:10,color:u.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.path})]})]},t.id)),e.jsx("button",{onClick:()=>N(!0),style:{padding:"10px 12px",borderRadius:6,border:`1px dashed ${u.border}`,background:"transparent",color:u.textMuted,cursor:"pointer",fontSize:13,marginTop:8},children:"+ Add Endpoint"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[R==="endpoints"&&g&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[e.jsx("select",{value:g.method,onChange:t=>D(g.id,{method:t.target.value}),style:{padding:"8px 12px",borderRadius:6,border:"none",background:J[g.method]+"30",color:J[g.method],fontSize:13,fontWeight:600,cursor:"pointer"},children:["GET","POST","PUT","PATCH","DELETE"].map(t=>e.jsx("option",{value:t,children:t},t))}),e.jsx("input",{type:"text",value:g.path,onChange:t=>D(g.id,{path:t.target.value}),style:{flex:1,padding:"8px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:14,fontFamily:"monospace"}}),e.jsx("button",{onClick:()=>H(g.id),style:{padding:"8px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:13},children:"🗑️ Delete"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:16,marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:u.textMuted,marginBottom:4},children:"Name"}),e.jsx("input",{type:"text",value:g.name,onChange:t=>D(g.id,{name:t.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:u.textMuted,marginBottom:4},children:"Description"}),e.jsx("input",{type:"text",value:g.description||"",onChange:t=>D(g.id,{description:t.target.value}),style:{width:"100%",padding:"8px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,boxSizing:"border-box"}})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h4",{style:{margin:"0 0 12px",display:"flex",alignItems:"center",gap:8},children:"📋 Parameters"}),g.pathParams&&g.pathParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:u.textMuted,marginBottom:8},children:"PATH PARAMETERS"}),g.pathParams.map(t=>e.jsxs("div",{style:{padding:12,background:u.cardBg,borderRadius:6,marginBottom:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("code",{style:{fontWeight:600},children:t.name}),e.jsx("span",{style:{color:u.textMuted,fontSize:12},children:t.type}),t.required&&e.jsx("span",{style:{color:"#ef4444",fontSize:10},children:"required"})]},t.id))]}),g.queryParams&&g.queryParams.length>0&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:u.textMuted,marginBottom:8},children:"QUERY PARAMETERS"}),g.queryParams.map(t=>e.jsxs("div",{style:{padding:12,background:u.cardBg,borderRadius:6,marginBottom:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsx("code",{style:{fontWeight:600},children:t.name}),e.jsx("span",{style:{color:u.textMuted,fontSize:12},children:t.type}),t.defaultValue!==void 0&&e.jsxs("span",{style:{color:"#f59e0b",fontSize:11},children:["= ",JSON.stringify(t.defaultValue)]})]},t.id))]}),g.body&&e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:11,color:u.textMuted,marginBottom:8},children:"REQUEST BODY"}),e.jsxs("div",{style:{padding:12,background:u.cardBg,borderRadius:6},children:[e.jsxs("div",{style:{fontSize:12,marginBottom:8},children:["Content-Type: ",e.jsx("code",{children:g.body.contentType})]}),g.body.schema&&e.jsx("pre",{style:{margin:0,padding:12,background:u.bg,borderRadius:4,fontSize:11,overflow:"auto"},children:JSON.stringify(g.body.schema,null,2)})]})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h4",{style:{margin:"0 0 12px"},children:"📤 Responses"}),e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:g.responses.map(t=>e.jsxs("div",{style:{padding:12,background:u.cardBg,borderRadius:6,minWidth:120},children:[e.jsx("div",{style:{fontSize:18,fontWeight:600,color:t.status<300?"#22c55e":t.status<400?"#f59e0b":"#ef4444"},children:t.status}),e.jsx("div",{style:{fontSize:11,color:u.textMuted},children:t.description})]},t.status))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{style:{padding:16,background:u.cardBg,borderRadius:8},children:[e.jsxs("h5",{style:{margin:"0 0 12px",display:"flex",alignItems:"center",gap:8},children:[e.jsx("input",{type:"checkbox",checked:g.cache?.enabled||!1,onChange:t=>D(g.id,{cache:{...g.cache,enabled:t.target.checked}})}),"📦 Cache"]}),g.cache?.enabled&&e.jsxs("div",{style:{fontSize:12,color:u.textMuted},children:["TTL: ",g.cache.ttl,"s • Strategy: ",g.cache.strategy]})]}),e.jsxs("div",{style:{padding:16,background:u.cardBg,borderRadius:8},children:[e.jsxs("h5",{style:{margin:"0 0 12px",display:"flex",alignItems:"center",gap:8},children:[e.jsx("input",{type:"checkbox",checked:g.retry?.enabled||!1,onChange:t=>D(g.id,{retry:{...g.retry,enabled:t.target.checked,maxAttempts:3,backoff:"exponential"}})}),"🔄 Retry"]}),g.retry?.enabled&&e.jsxs("div",{style:{fontSize:12,color:u.textMuted},children:["Max: ",g.retry.maxAttempts," • ",g.retry.backoff," ","backoff"]})]})]})]}),R==="auth"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsx("h4",{style:{marginTop:0},children:"🔐 Authentication"}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:u.textMuted,marginBottom:8},children:"Auth Type"}),e.jsxs("select",{value:a.auth?.type||"none",onChange:t=>T({auth:{...a.auth,type:t.target.value}}),style:{padding:"10px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,width:"100%"},children:[e.jsx("option",{value:"none",children:"None"}),e.jsx("option",{value:"bearer",children:"Bearer Token"}),e.jsx("option",{value:"basic",children:"Basic Auth"}),e.jsx("option",{value:"api-key",children:"API Key"}),e.jsx("option",{value:"oauth2",children:"OAuth 2.0"})]})]}),a.auth?.type==="bearer"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:u.textMuted,marginBottom:8},children:"Token Source"}),e.jsx("input",{type:"text",value:a.auth.tokenSource||"",onChange:t=>T({auth:{...a.auth,tokenSource:t.target.value}}),placeholder:"state.auth.token",style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,fontFamily:"monospace",boxSizing:"border-box"}})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("label",{style:{display:"block",fontSize:12,color:u.textMuted,marginBottom:8},children:"Header Name"}),e.jsx("input",{type:"text",value:a.auth.headerName||"Authorization",onChange:t=>T({auth:{...a.auth,headerName:t.target.value}}),style:{width:"100%",padding:"10px 12px",borderRadius:6,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,boxSizing:"border-box"}})]})]}),e.jsx("h4",{children:"🌐 Global Headers"}),e.jsx("div",{style:{padding:16,background:u.cardBg,borderRadius:8},children:Object.entries(a.globalHeaders||{}).map(([t,n])=>e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1},children:t}),e.jsx("span",{style:{color:u.textMuted},children:":"}),e.jsx("code",{style:{flex:2,color:"#22c55e"},children:n})]},t))})]}),R==="settings"&&e.jsxs("div",{style:{maxWidth:500},children:[e.jsx("h4",{style:{marginTop:0},children:"⚙️ Global Settings"}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h5",{children:"Error Handling"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.errorHandling?.globalErrorHandler||!1,onChange:t=>T({errorHandling:{...a.errorHandling,globalErrorHandler:t.target.checked}})}),"Global error handler"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.errorHandling?.retryOnNetworkError||!1,onChange:t=>T({errorHandling:{...a.errorHandling,retryOnNetworkError:t.target.checked}})}),"Retry on network errors"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.errorHandling?.transformError||!1,onChange:t=>T({errorHandling:{...a.errorHandling,transformError:t.target.checked}})}),"Transform error responses"]})]})]}),e.jsxs("div",{style:{marginBottom:24},children:[e.jsx("h5",{children:"Default Cache Settings"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.cacheConfig?.enabled||!1,onChange:t=>T({cacheConfig:{...a.cacheConfig,enabled:t.target.checked}})}),"Enable caching"]}),a.cacheConfig?.enabled&&e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:12,color:u.textMuted},children:"Storage"}),e.jsxs("select",{value:a.cacheConfig.storage,onChange:t=>T({cacheConfig:{...a.cacheConfig,storage:t.target.value}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13},children:[e.jsx("option",{value:"memory",children:"Memory"}),e.jsx("option",{value:"localStorage",children:"localStorage"}),e.jsx("option",{value:"sessionStorage",children:"sessionStorage"})]})]}),e.jsxs("div",{children:[e.jsx("label",{style:{fontSize:12,color:u.textMuted},children:"Default TTL (seconds)"}),e.jsx("input",{type:"number",value:a.cacheConfig.defaultTTL,onChange:t=>T({cacheConfig:{...a.cacheConfig,defaultTTL:parseInt(t.target.value)}}),style:{display:"block",marginTop:4,padding:"8px 12px",borderRadius:4,border:`1px solid ${u.border}`,background:u.cardBg,color:u.text,fontSize:13,width:100}})]})]})]})]}),R==="test"&&g&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:24},children:[e.jsx("span",{style:{padding:"4px 8px",borderRadius:4,background:J[g.method]+"30",color:J[g.method],fontSize:12,fontWeight:600},children:g.method}),e.jsxs("code",{style:{flex:1,fontSize:14},children:[a.baseUrl,g.path]}),e.jsx("button",{onClick:M,disabled:A,style:{padding:"10px 20px",borderRadius:6,border:"none",background:u.accent,color:"white",cursor:A?"not-allowed":"pointer",fontSize:13,fontWeight:500,opacity:A?.7:1},children:A?"⏳ Testing...":"🚀 Send Request"})]}),P&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsx("span",{style:{fontSize:18,fontWeight:600,color:P.status<300?"#22c55e":"#ef4444"},children:P.status}),e.jsx("span",{style:{color:u.textMuted},children:P.status<300?"OK":"Error"})]}),e.jsx("pre",{style:{padding:16,background:u.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0},children:JSON.stringify(P.body,null,2)})]})]}),R==="preview"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsx("button",{onClick:U,style:{padding:"8px 16px",borderRadius:4,border:"none",background:u.accent,color:"white",cursor:"pointer",fontSize:13},children:"📤 Export"}),e.jsx("button",{onClick:()=>navigator.clipboard.writeText(F),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${u.border}`,background:"transparent",color:u.text,cursor:"pointer",fontSize:13},children:"📋 Copy"})]}),e.jsx("pre",{style:{flex:1,padding:16,background:u.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:F})]})]})]}),C&&e.jsx("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.7)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:()=>N(!1),children:e.jsxs("div",{style:{background:u.cardBg,borderRadius:12,padding:24,width:400},onClick:t=>t.stopPropagation(),children:[e.jsx("h4",{style:{margin:"0 0 16px"},children:"➕ Add Endpoint"}),e.jsx("p",{style:{color:u.textMuted,fontSize:13,marginBottom:16},children:"Select HTTP method for new endpoint:"}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["GET","POST","PUT","PATCH","DELETE"].map(t=>e.jsx("button",{onClick:()=>B(t),style:{padding:"12px 24px",borderRadius:6,border:"none",background:J[t]+"30",color:J[t],cursor:"pointer",fontSize:14,fontWeight:600},children:t},t))})]})})]})},$e=Object.freeze(Object.defineProperty({__proto__:null,NiceAPIFlow:pe},Symbol.toStringTag,{value:"Module"})),Ce={id:"map-1",name:"UserToContact",description:"Transform User API response to Contact entity",sourceSchema:{name:"UserResponse",type:"object",fields:[{id:"s1",name:"id",path:"id",type:"number"},{id:"s2",name:"firstName",path:"firstName",type:"string"},{id:"s3",name:"lastName",path:"lastName",type:"string"},{id:"s4",name:"email",path:"email",type:"string"},{id:"s5",name:"phone",path:"phone",type:"string",nullable:!0},{id:"s6",name:"address",path:"address",type:"object",children:[{id:"s6a",name:"street",path:"address.street",type:"string"},{id:"s6b",name:"city",path:"address.city",type:"string"},{id:"s6c",name:"zipCode",path:"address.zipCode",type:"string"},{id:"s6d",name:"country",path:"address.country",type:"string"}]},{id:"s7",name:"metadata",path:"metadata",type:"object",children:[{id:"s7a",name:"createdAt",path:"metadata.createdAt",type:"date"},{id:"s7b",name:"updatedAt",path:"metadata.updatedAt",type:"date"}]}]},targetSchema:{name:"Contact",type:"object",fields:[{id:"t1",name:"contactId",path:"contactId",type:"string"},{id:"t2",name:"fullName",path:"fullName",type:"string"},{id:"t3",name:"emailAddress",path:"emailAddress",type:"string"},{id:"t4",name:"phoneNumber",path:"phoneNumber",type:"string",nullable:!0},{id:"t5",name:"location",path:"location",type:"string"},{id:"t6",name:"fullAddress",path:"fullAddress",type:"string"},{id:"t7",name:"createdDate",path:"createdDate",type:"string"},{id:"t8",name:"isActive",path:"isActive",type:"boolean"}]},fieldMappings:[{id:"m1",sourceField:"id",targetField:"contactId",transform:"tr-1"},{id:"m2",sourceField:"firstName,lastName",targetField:"fullName",transform:"tr-2"},{id:"m3",sourceField:"email",targetField:"emailAddress"},{id:"m4",sourceField:"phone",targetField:"phoneNumber",defaultValue:""},{id:"m5",sourceField:"address.city,address.country",targetField:"location",transform:"tr-3"},{id:"m6",sourceField:"address",targetField:"fullAddress",transform:"tr-4"},{id:"m7",sourceField:"metadata.createdAt",targetField:"createdDate",transform:"tr-5"},{id:"m8",sourceField:"",targetField:"isActive",defaultValue:!0}],transformations:[{id:"tr-1",name:"ID to String",type:"format",config:{format:"USR-{value}"}},{id:"tr-2",name:"Full Name",type:"concat",config:{separator:" "}},{id:"tr-3",name:"Location",type:"concat",config:{separator:", "}},{id:"tr-4",name:"Full Address",type:"custom",config:{expression:"`${address.street}, ${address.zipCode} ${address.city}, ${address.country}`"}},{id:"tr-5",name:"Format Date",type:"format",config:{format:"YYYY-MM-DD"}}],validationRules:[{id:"v1",field:"emailAddress",type:"required",message:"Email is required"},{id:"v2",field:"emailAddress",type:"pattern",value:"^\\S+@\\S+\\.\\S+$",message:"Invalid email format"},{id:"v3",field:"contactId",type:"required",message:"Contact ID is required"}]},te={string:"#22c55e",number:"#3b82f6",boolean:"#f59e0b",date:"#8b5cf6",array:"#06b6d4",object:"#ec4899",any:"#6b7280"},ne={string:"📝",number:"🔢",boolean:"✓",date:"📅",array:"📋",object:"{}",any:"❓"},re={direct:"➡️",format:"📝",convert:"🔄",concat:"🔗",split:"✂️",calculate:"🧮",lookup:"🔍",conditional:"❓",custom:"⚙️"},Te=i=>{const v=oe(i.sourceSchema),k=oe(i.targetSchema),f=i.fieldMappings.map(h=>{const j=i.transformations.find(a=>a.id===h.transform),l=h.targetField;if(!h.sourceField)return` result.${l} = ${JSON.stringify(h.defaultValue)};`;const x=h.sourceField.split(",").map(a=>a.trim());if(j)switch(j.type){case"concat":return` result.${l} = [${x.map(a=>`source.${a}`).join(", ")}].filter(Boolean).join('${j.config.separator||" "}');`;case"format":if(x.length===1){const a=j.config.format||"{value}";return a.includes("{value}")?` result.${l} = '${a}'.replace('{value}', String(source.${x[0]}));`:` result.${l} = formatDate(source.${x[0]}, '${a}');`}break;case"custom":return` result.${l} = ${j.config.expression?.replace(/(\w+)\.(\w+)/g,"source.$1.$2")};`;case"convert":return` result.${l} = ${j.config.convertTo}(source.${x[0]});`}if(x.length===1){const a=h.defaultValue!==void 0?` ?? ${JSON.stringify(h.defaultValue)}`:"";return` result.${l} = source.${x[0]}${a};`}return` // TODO: Manual mapping for ${l}`}),S=i.validationRules.map(h=>{switch(h.type){case"required":return` if (!data.${h.field}) errors.push('${h.message||h.field+" is required"}');`;case"pattern":return` if (data.${h.field} && !/${h.value}/.test(data.${h.field})) errors.push('${h.message||"Invalid format"}');`;default:return` // ${h.type} validation for ${h.field}`}});return`/**
96
+ * ${i.name}
97
+ * ${i.description||""}
98
+ * Auto-generated by NiceDataMapper
99
+ */
100
+
101
+ // Source Type
102
+ ${v}
103
+
104
+ // Target Type
105
+ ${k}
106
+
107
+ // Validation
108
+ export function validate${i.targetSchema.name}(data: ${i.targetSchema.name}): string[] {
109
+ const errors: string[] = [];
110
+ ${S.join(`
111
+ `)}
112
+ return errors;
113
+ }
114
+
115
+ // Mapper
116
+ export function ${i.name.charAt(0).toLowerCase()+i.name.slice(1)}(source: ${i.sourceSchema.name}): ${i.targetSchema.name} {
117
+ const result = {} as ${i.targetSchema.name};
118
+
119
+ ${f.join(`
120
+ `)}
121
+
122
+ return result;
123
+ }
124
+
125
+ // Helper functions
126
+ function formatDate(date: string | Date, format: string): string {
127
+ const d = typeof date === 'string' ? new Date(date) : date;
128
+ const year = d.getFullYear();
129
+ const month = String(d.getMonth() + 1).padStart(2, '0');
130
+ const day = String(d.getDate()).padStart(2, '0');
131
+ return format
132
+ .replace('YYYY', String(year))
133
+ .replace('MM', month)
134
+ .replace('DD', day);
135
+ }
136
+ `},oe=(i,v)=>{const k=(S,h)=>{const j=" ".repeat(h),l=S.nullable?"?":"";if(S.type==="object"&&S.children){const a=S.children.map(d=>k(d,h+1)).join(`
137
+ `);return`${j}${S.name}${l}: {
138
+ ${a}
139
+ ${j}};`}const x={string:"string",number:"number",boolean:"boolean",date:"string | Date",array:"unknown[]",object:"Record<string, unknown>",any:"unknown"}[S.type];return`${j}${S.name}${l}: ${x};`},f=i.fields.map(S=>k(S,1)).join(`
140
+ `);return`interface ${i.name} {
141
+ ${f}
142
+ }`},ue=({mapping:i=Ce,sourceSchemas:v=[],targetSchemas:k=[],onMappingChange:f,onExport:S,onTest:h,onSave:j,className:l,style:x,"data-testid":a})=>{const[d,R]=y.useState(i),[z,w]=y.useState("mapping"),[L,C]=y.useState(null),[N,P]=y.useState(""),[q,A]=y.useState(""),[W,g]=y.useState(null),T=y.useCallback(n=>{const m={...d,...n};R(m),f?.(m)},[d,f]),D=(n,m="")=>{const o=[];return n.forEach(r=>{o.push(r),r.children&&o.push(...D(r.children,r.path+"."))}),o},B=y.useMemo(()=>D(d.sourceSchema.fields),[d.sourceSchema.fields]),H=y.useMemo(()=>D(d.targetSchema.fields),[d.targetSchema.fields]),M=(n,m)=>{const o={id:`mapping-${Date.now()}`,sourceField:n,targetField:m};T({fieldMappings:[...d.fieldMappings,o]})},F=n=>{T({fieldMappings:d.fieldMappings.filter(m=>m.id!==n)})},U=()=>{try{const n=JSON.parse(N),m={};d.fieldMappings.forEach(o=>{if(!o.sourceField){m[o.targetField]=o.defaultValue;return}const r=o.sourceField.split(",").map(c=>c.trim()),s=c=>c.split(".").reduce((O,I)=>O?.[I],n),$=d.transformations.find(c=>c.id===o.transform);if($?.type==="concat")m[o.targetField]=r.map(s).filter(Boolean).join($.config.separator||" ");else if($?.type==="format"&&r.length===1){const c=s(r[0]);m[o.targetField]=($.config.format||"{value}").replace("{value}",String(c))}else r.length===1&&(m[o.targetField]=s(r[0])??o.defaultValue)}),A(JSON.stringify(m,null,2)),h?.(m)}catch(n){A(`Error: ${n.message}`)}},u=y.useMemo(()=>Te(d),[d]),t={bg:"#1e1e1e",cardBg:"#252525",border:"#333",text:"#e0e0e0",textMuted:"#888",accent:"#3b82f6"};return e.jsxs("div",{className:`nice-data-mapper ${l||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:t.bg,color:t.text,fontFamily:"system-ui, sans-serif",...x},"data-testid":a,children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsx("h3",{style:{margin:0,fontSize:18},children:"🔄 Data Mapper"}),e.jsx("input",{type:"text",value:d.name,onChange:n=>T({name:n.target.value}),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.cardBg,color:t.text,fontSize:14,fontWeight:600}}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",gap:8},children:e.jsx("button",{onClick:()=>j?.(d),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"#22c55e",color:"white",cursor:"pointer",fontSize:13,fontWeight:500},children:"💾 Save"})})]}),e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${t.border}`,padding:"0 20px"},children:["mapping","transforms","validation","test","preview"].map(n=>e.jsxs("button",{onClick:()=>w(n),style:{padding:"12px 20px",border:"none",background:"transparent",color:z===n?t.text:t.textMuted,cursor:"pointer",fontSize:13,fontWeight:z===n?600:400,borderBottom:z===n?`2px solid ${t.accent}`:"2px solid transparent",marginBottom:-1},children:[n==="mapping"&&"🔗 Mapping",n==="transforms"&&"⚡ Transforms",n==="validation"&&"✓ Validation",n==="test"&&"🧪 Test",n==="preview"&&"👁️ Preview"]},n))}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:20},children:[z==="mapping"&&e.jsxs("div",{style:{display:"flex",gap:24,height:"100%"},children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"#22c55e20",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:["📥 Source: ",d.sourceSchema.name]}),e.jsx("div",{style:{flex:1,border:`1px solid ${t.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:B.map(n=>{const m=n.path.split(".").length-1,o=d.fieldMappings.some(r=>r.sourceField.split(",").some(s=>s.trim()===n.path));return e.jsxs("div",{draggable:!0,onDragStart:()=>g(n.path),onDragEnd:()=>g(null),style:{padding:"10px 12px",paddingLeft:12+m*16,borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",gap:8,cursor:"grab",background:o?"#22c55e10":"transparent",opacity:n.type==="object"&&n.children?.7:1},children:[e.jsx("span",{style:{color:te[n.type],fontSize:14},children:ne[n.type]}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:n.name}),e.jsx("span",{style:{fontSize:10,color:t.textMuted},children:n.type}),o&&e.jsx("span",{style:{marginLeft:"auto",color:"#22c55e",fontSize:10},children:"✓"})]},n.id)})})]}),e.jsxs("div",{style:{width:300,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:t.accent+"20",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:["🔗 Mappings (",d.fieldMappings.length,")"]}),e.jsx("div",{style:{flex:1,border:`1px solid ${t.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto",padding:8},children:d.fieldMappings.map(n=>{const m=d.transformations.find(o=>o.id===n.transform);return e.jsxs("div",{style:{padding:8,background:t.cardBg,borderRadius:6,marginBottom:8,fontSize:11},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginBottom:4},children:[e.jsx("code",{style:{color:"#22c55e"},children:n.sourceField||"(default)"}),e.jsx("span",{style:{color:t.textMuted},children:"→"}),e.jsx("code",{style:{color:"#3b82f6"},children:n.targetField}),e.jsx("button",{onClick:()=>F(n.id),style:{marginLeft:"auto",padding:2,border:"none",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:"✕"})]}),m&&e.jsxs("div",{style:{color:t.textMuted,display:"flex",alignItems:"center",gap:4},children:[re[m.type]," ",m.name]}),n.defaultValue!==void 0&&e.jsxs("div",{style:{color:"#f59e0b"},children:["Default: ",JSON.stringify(n.defaultValue)]})]},n.id)})})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"#3b82f620",borderRadius:"8px 8px 0 0",fontSize:13,fontWeight:600},children:["📤 Target: ",d.targetSchema.name]}),e.jsx("div",{style:{flex:1,border:`1px solid ${t.border}`,borderTop:"none",borderRadius:"0 0 8px 8px",overflow:"auto"},children:H.map(n=>{const m=n.path.split(".").length-1,o=d.fieldMappings.some(r=>r.targetField===n.path);return e.jsxs("div",{onDragOver:r=>r.preventDefault(),onDrop:()=>{W&&!o&&M(W,n.path)},style:{padding:"10px 12px",paddingLeft:12+m*16,borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",gap:8,background:W&&!o?t.accent+"10":o?"#3b82f610":"transparent",transition:"background 0.15s"},children:[e.jsx("span",{style:{color:te[n.type],fontSize:14},children:ne[n.type]}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:n.name}),e.jsx("span",{style:{fontSize:10,color:t.textMuted},children:n.type}),n.nullable&&e.jsx("span",{style:{fontSize:10,color:t.textMuted},children:"?"}),o&&e.jsx("span",{style:{marginLeft:"auto",color:"#3b82f6",fontSize:10},children:"✓"})]},n.id)})})]})]}),z==="transforms"&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsx("h4",{style:{margin:0},children:"⚡ Transformations"}),e.jsx("button",{onClick:()=>{const n={id:`tr-${Date.now()}`,name:"New Transform",type:"direct",config:{}};T({transformations:[...d.transformations,n]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:t.accent,color:"white",cursor:"pointer",fontSize:12},children:"+ Add Transform"})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:16},children:d.transformations.map(n=>e.jsxs("div",{style:{padding:16,background:t.cardBg,borderRadius:8,border:`1px solid ${t.border}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx("span",{style:{fontSize:20},children:re[n.type]}),e.jsx("input",{type:"text",value:n.name,onChange:m=>{const o=d.transformations.map(r=>r.id===n.id?{...r,name:m.target.value}:r);T({transformations:o})},style:{flex:1,padding:"6px 8px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:13,fontWeight:600}})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:"Type"}),e.jsxs("select",{value:n.type,onChange:m=>{const o=d.transformations.map(r=>r.id===n.id?{...r,type:m.target.value}:r);T({transformations:o})},style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:[e.jsx("option",{value:"direct",children:"Direct"}),e.jsx("option",{value:"format",children:"Format"}),e.jsx("option",{value:"convert",children:"Convert"}),e.jsx("option",{value:"concat",children:"Concatenate"}),e.jsx("option",{value:"split",children:"Split"}),e.jsx("option",{value:"calculate",children:"Calculate"}),e.jsx("option",{value:"lookup",children:"Lookup"}),e.jsx("option",{value:"conditional",children:"Conditional"}),e.jsx("option",{value:"custom",children:"Custom"})]})]}),(n.type==="format"||n.type==="concat")&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:n.type==="format"?"Format Pattern":"Separator"}),e.jsx("input",{type:"text",value:n.type==="format"?n.config.format||"":n.config.separator||"",onChange:m=>{const o=d.transformations.map(r=>r.id===n.id?{...r,config:{...r.config,[n.type==="format"?"format":"separator"]:m.target.value}}:r);T({transformations:o})},placeholder:n.type==="format"?"{value} or YYYY-MM-DD":", ",style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,fontFamily:"monospace",boxSizing:"border-box"}})]}),n.type==="custom"&&e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:"Expression"}),e.jsx("textarea",{value:n.config.expression||"",onChange:m=>{const o=d.transformations.map(r=>r.id===n.id?{...r,config:{...r.config,expression:m.target.value}}:r);T({transformations:o})},rows:3,style:{width:"100%",padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,fontFamily:"monospace",resize:"vertical",boxSizing:"border-box"}})]})]},n.id))})]}),z==="validation"&&e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsx("h4",{style:{margin:0},children:"✓ Validation Rules"}),e.jsx("button",{onClick:()=>{const n={id:`v-${Date.now()}`,field:"",type:"required",message:""};T({validationRules:[...d.validationRules,n]})},style:{padding:"6px 12px",borderRadius:4,border:"none",background:t.accent,color:"white",cursor:"pointer",fontSize:12},children:"+ Add Rule"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:d.validationRules.map(n=>e.jsxs("div",{style:{padding:16,background:t.cardBg,borderRadius:8,display:"flex",gap:12,alignItems:"center"},children:[e.jsxs("select",{value:n.field,onChange:m=>{const o=d.validationRules.map(r=>r.id===n.id?{...r,field:m.target.value}:r);T({validationRules:o})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:[e.jsx("option",{value:"",children:"Select field..."}),H.map(m=>e.jsx("option",{value:m.path,children:m.path},m.id))]}),e.jsxs("select",{value:n.type,onChange:m=>{const o=d.validationRules.map(r=>r.id===n.id?{...r,type:m.target.value}:r);T({validationRules:o})},style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:[e.jsx("option",{value:"required",children:"Required"}),e.jsx("option",{value:"type",children:"Type"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"}),e.jsx("option",{value:"pattern",children:"Pattern"}),e.jsx("option",{value:"enum",children:"Enum"}),e.jsx("option",{value:"custom",children:"Custom"})]}),(n.type==="pattern"||n.type==="min"||n.type==="max")&&e.jsx("input",{type:"text",value:String(n.value||""),onChange:m=>{const o=d.validationRules.map(r=>r.id===n.id?{...r,value:m.target.value}:r);T({validationRules:o})},placeholder:"Value",style:{padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,width:150}}),e.jsx("input",{type:"text",value:n.message||"",onChange:m=>{const o=d.validationRules.map(r=>r.id===n.id?{...r,message:m.target.value}:r);T({validationRules:o})},placeholder:"Error message",style:{flex:1,padding:"8px 12px",borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12}}),e.jsx("button",{onClick:()=>{T({validationRules:d.validationRules.filter(m=>m.id!==n.id)})},style:{padding:6,border:"none",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:14},children:"🗑️"})]},n.id))})]}),z==="test"&&e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:20,height:"100%"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsx("h4",{style:{margin:0},children:"📥 Input"}),e.jsx("button",{onClick:()=>{const n={},m=(o,r)=>{o.forEach(s=>{s.children&&s.type==="object"?(r[s.name]={},m(s.children,r[s.name])):r[s.name]={string:"sample",number:42,boolean:!0,date:new Date().toISOString(),array:[],object:{},any:null}[s.type]})};m(d.sourceSchema.fields,n),P(JSON.stringify(n,null,2))},style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:11},children:"Generate Sample"})]}),e.jsx("textarea",{value:N,onChange:n=>P(n.target.value),placeholder:"Paste JSON input here...",style:{flex:1,padding:12,borderRadius:8,border:`1px solid ${t.border}`,background:t.cardBg,color:t.text,fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",resize:"none"}})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:12},children:[e.jsx("h4",{style:{margin:0},children:"📤 Output"}),e.jsx("button",{onClick:U,style:{padding:"6px 16px",borderRadius:4,border:"none",background:t.accent,color:"white",cursor:"pointer",fontSize:12},children:"🔄 Transform"})]}),e.jsx("pre",{style:{flex:1,padding:12,borderRadius:8,background:t.cardBg,margin:0,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace"},children:q||"Run transform to see output"})]})]}),z==="preview"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsx("button",{onClick:()=>S?.(u),style:{padding:"8px 16px",borderRadius:4,border:"none",background:t.accent,color:"white",cursor:"pointer",fontSize:13},children:"📤 Export"}),e.jsx("button",{onClick:()=>navigator.clipboard.writeText(u),style:{padding:"8px 16px",borderRadius:4,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:13},children:"📋 Copy"})]}),e.jsx("pre",{style:{flex:1,padding:16,background:t.cardBg,borderRadius:8,overflow:"auto",fontSize:12,fontFamily:"JetBrains Mono, Consolas, monospace",margin:0,whiteSpace:"pre-wrap"},children:u})]})]})]})},ze=Object.freeze(Object.defineProperty({__proto__:null,NiceDataMapper:ue},Symbol.toStringTag,{value:"Module"})),Re=[{type:"ui-event",label:"UI Event",icon:"🖱️",color:"#3b82f6",configSchema:[{name:"element",label:"Element Selector",type:"string",required:!0},{name:"event",label:"Event Type",type:"select",required:!0,options:[{value:"click",label:"Click"},{value:"change",label:"Change"},{value:"submit",label:"Submit"},{value:"focus",label:"Focus"},{value:"blur",label:"Blur"},{value:"keydown",label:"Key Down"},{value:"keyup",label:"Key Up"}]}]},{type:"api-response",label:"API Response",icon:"🌐",color:"#22c55e",configSchema:[{name:"endpoint",label:"Endpoint Pattern",type:"string",required:!0},{name:"method",label:"Method",type:"select",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"},{value:"*",label:"Any"}]},{name:"statusCode",label:"Status Code",type:"string"}]},{type:"websocket",label:"WebSocket",icon:"🔌",color:"#8b5cf6",configSchema:[{name:"channel",label:"Channel",type:"string",required:!0},{name:"messageType",label:"Message Type",type:"string"}]},{type:"timer",label:"Timer",icon:"⏱️",color:"#f59e0b",configSchema:[{name:"interval",label:"Interval (ms)",type:"number",required:!0,default:1e3},{name:"repeat",label:"Repeat",type:"boolean",default:!0}]},{type:"state-change",label:"State Change",icon:"📊",color:"#ec4899",configSchema:[{name:"selector",label:"State Selector",type:"string",required:!0},{name:"deep",label:"Deep Compare",type:"boolean",default:!1}]},{type:"broadcast",label:"Broadcast",icon:"📡",color:"#06b6d4",configSchema:[{name:"eventName",label:"Event Name",type:"string",required:!0}]}],Ne=[{type:"action",label:"Action",icon:"⚡",color:"#3b82f6",configSchema:[{name:"actionType",label:"Action",type:"string",required:!0},{name:"payload",label:"Payload",type:"json"}]},{type:"transform",label:"Transform",icon:"🔄",color:"#8b5cf6",configSchema:[{name:"expression",label:"Transform Expression",type:"code",required:!0}]},{type:"dispatch",label:"Dispatch",icon:"📤",color:"#22c55e",configSchema:[{name:"eventName",label:"Event Name",type:"string",required:!0},{name:"payload",label:"Payload",type:"json"}]},{type:"api-call",label:"API Call",icon:"🌐",color:"#f59e0b",configSchema:[{name:"endpoint",label:"Endpoint",type:"string",required:!0},{name:"method",label:"Method",type:"select",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"}]},{name:"body",label:"Body",type:"json"}]},{type:"state-update",label:"State Update",icon:"📊",color:"#ec4899",configSchema:[{name:"path",label:"State Path",type:"string",required:!0},{name:"value",label:"Value Expression",type:"code"}]},{type:"notification",label:"Notification",icon:"🔔",color:"#06b6d4",configSchema:[{name:"type",label:"Type",type:"select",options:[{value:"success",label:"Success"},{value:"error",label:"Error"},{value:"warning",label:"Warning"},{value:"info",label:"Info"}]},{name:"message",label:"Message",type:"string",required:!0},{name:"duration",label:"Duration (ms)",type:"number",default:3e3}]},{type:"log",label:"Console Log",icon:"📝",color:"#6b7280",configSchema:[{name:"level",label:"Level",type:"select",options:[{value:"log",label:"Log"},{value:"warn",label:"Warn"},{value:"error",label:"Error"},{value:"debug",label:"Debug"}]},{name:"message",label:"Message",type:"string"}]},{type:"delay",label:"Delay",icon:"⏳",color:"#a855f7",configSchema:[{name:"duration",label:"Duration (ms)",type:"number",required:!0,default:1e3}]},{type:"branch",label:"Conditional Branch",icon:"🔀",color:"#14b8a6",configSchema:[{name:"condition",label:"Condition",type:"code",required:!0},{name:"trueBranch",label:"If True",type:"string"},{name:"falseBranch",label:"If False",type:"string"}]}],Be=[{id:"flow-1",name:"Form Submit Handler",description:"Handle form submission with validation",enabled:!0,source:{id:"src-1",type:"ui-event",config:{element:"#contact-form",event:"submit"}},handlers:[{id:"h-1",type:"transform",config:{expression:"(event) => event.formData"}},{id:"h-2",type:"api-call",config:{endpoint:"/api/contact",method:"POST",body:"{{data}}"},modifiers:[{type:"debounce",value:500,unit:"ms"}]},{id:"h-3",type:"notification",config:{type:"success",message:"Form submitted successfully!"}}],errorHandler:{id:"err-1",type:"notification",config:{type:"error",message:"Failed to submit form"}}},{id:"flow-2",name:"Real-time Updates",description:"Handle WebSocket messages",enabled:!0,source:{id:"src-2",type:"websocket",config:{channel:"notifications",messageType:"update"}},handlers:[{id:"h-4",type:"state-update",config:{path:"notifications",value:"(state, data) => [...state.notifications, data]"}},{id:"h-5",type:"notification",config:{type:"info",message:"{{data.title}}",duration:5e3}}]},{id:"flow-3",name:"Auto-save Draft",description:"Periodically save form draft",enabled:!1,source:{id:"src-3",type:"timer",config:{interval:3e4,repeat:!0}},handlers:[{id:"h-6",type:"transform",config:{expression:"() => getFormData()"}},{id:"h-7",type:"api-call",config:{endpoint:"/api/draft",method:"PUT"},condition:{field:"isDirty",operator:"eq",value:!0}},{id:"h-8",type:"log",config:{level:"debug",message:"Draft saved"}}]}],Ee=i=>{const v=i.filter(f=>f.enabled);return`/**
143
+ * Generated Event Orchestration
144
+ * @generated by NiceEventOrchestrator
145
+ */
146
+
147
+ import { createEventBus, EventHandler, EventSource } from '@nice2dev/events';
148
+
149
+ // Event Bus Instance
150
+ export const eventBus = createEventBus();
151
+
152
+ // Event Types
153
+ ${v.map(f=>`export type ${f.name.replace(/\s+/g,"")}Event = {
154
+ source: '${f.source.type}';
155
+ payload: unknown;
156
+ };`).join(`
157
+
158
+ `)}
159
+
160
+ // Event Handlers
161
+ ${v.map(f=>{const S=JSON.stringify(f.source.config,null,2),h=f.handlers.flatMap(j=>j.modifiers||[]).map(j=>`.${j.type}(${j.value})`).join("");return`
162
+ /**
163
+ * ${f.name}
164
+ * ${f.description||""}
165
+ */
166
+ export const ${f.name.replace(/\s+/g,"").toLowerCase()}Handler = eventBus
167
+ .on('${f.source.type}', ${S})${h}
168
+ .pipe(
169
+ ${f.handlers.map((j,l)=>` // Step ${l+1}: ${j.type}
170
+ async (event) => {
171
+ ${ie(j)}
172
+ },`).join(`
173
+ `)}
174
+ )
175
+ ${f.errorHandler?`.catch(async (error) => {
176
+ ${ie(f.errorHandler)}
177
+ })`:""};`}).join(`
178
+ `)}
179
+
180
+ // Initialize all handlers
181
+ export function initEventOrchestration() {
182
+ ${v.map(f=>` ${f.name.replace(/\s+/g,"").toLowerCase()}Handler.start();`).join(`
183
+ `)}
184
+ console.log('Event orchestration initialized');
185
+ }
186
+
187
+ // Cleanup
188
+ export function destroyEventOrchestration() {
189
+ ${v.map(f=>` ${f.name.replace(/\s+/g,"").toLowerCase()}Handler.stop();`).join(`
190
+ `)}
191
+ }
192
+ `},ie=i=>{switch(i.type){case"action":return`dispatch({ type: '${i.config.actionType}', payload: ${JSON.stringify(i.config.payload)} });`;case"transform":return`return (${i.config.expression})(event);`;case"dispatch":return`eventBus.emit('${i.config.eventName}', ${JSON.stringify(i.config.payload)});`;case"api-call":return`await fetch('${i.config.endpoint}', { method: '${i.config.method}', body: JSON.stringify(event.payload) });`;case"state-update":return`updateState('${i.config.path}', ${i.config.value});`;case"notification":return`showNotification({ type: '${i.config.type}', message: '${i.config.message}' });`;case"log":return`console.${i.config.level||"log"}('${i.config.message}', event);`;case"delay":return`await new Promise(r => setTimeout(r, ${i.config.duration}));`;case"branch":return`if (${i.config.condition}) { /* true branch */ } else { /* false branch */ }`;default:return"// Unknown handler type"}},ge=({flows:i=Be,eventSources:v=Re,eventHandlers:k=Ne,onFlowsChange:f,onExport:S,onTest:h,className:j,style:l,"data-testid":x})=>{const[a,d]=y.useState(i),[R,z]=y.useState(a[0]?.id??null),[w,L]=y.useState("visual"),[C,N]=y.useState(!1),[P,q]=y.useState(""),[A,W]=y.useState(new Set),g=y.useMemo(()=>a.find(n=>n.id===R),[a,R]),T=y.useMemo(()=>Ee(a),[a]),D=y.useCallback((n,m)=>{d(o=>{const r=o.map(s=>s.id===n?{...s,...m}:s);return f?.(r),r})},[f]),B=()=>{if(!P.trim())return;const n={id:`flow-${Date.now()}`,name:P,enabled:!0,source:{id:`src-${Date.now()}`,type:"ui-event",config:{element:"",event:"click"}},handlers:[]};d(m=>{const o=[...m,n];return f?.(o),o}),z(n.id),N(!1),q("")},H=n=>{d(m=>{const o=m.filter(r=>r.id!==n);return f?.(o),o}),R===n&&z(a[0]?.id??null)},M=n=>{if(!g)return;const m=k.find(s=>s.type===n),o={};m?.configSchema.forEach(s=>{s.default!==void 0&&(o[s.name]=s.default)});const r={id:`handler-${Date.now()}`,type:n,config:o};D(g.id,{handlers:[...g.handlers,r]}),W(s=>new Set([...s,r.id]))},F=(n,m)=>{g&&D(g.id,{handlers:g.handlers.map(o=>o.id===n?{...o,...m}:o)})},U=n=>{g&&D(g.id,{handlers:g.handlers.filter(m=>m.id!==n)})},u=(n,m)=>{if(!g)return;const o=g.handlers.find($=>$.id===n);if(!o)return;const s=o.modifiers?.find($=>$.type===m)?o.modifiers?.filter($=>$.type!==m):[...o.modifiers||[],{type:m,value:500,unit:"ms"}];F(n,{modifiers:s})},t={bg:"#1e1e1e",cardBg:"#252525",border:"#333",text:"#e0e0e0",textMuted:"#888"};return e.jsxs("div",{className:`nice-event-orchestrator ${j||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:t.bg,color:t.text,fontFamily:"system-ui, sans-serif",...l},"data-testid":x,children:[e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsx("h3",{style:{margin:0,fontSize:16},children:"⚡ Event Orchestrator"}),e.jsx("div",{style:{display:"flex",border:`1px solid ${t.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(n=>e.jsxs("button",{onClick:()=>L(n),style:{padding:"6px 12px",border:"none",background:w===n?t.cardBg:"transparent",color:t.text,cursor:"pointer",fontSize:12,textTransform:"capitalize"},children:[n==="visual"?"🎨":n==="code"?"📝":"📐"," ",n]},n))}),e.jsx("button",{onClick:()=>S?.(T),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"#22c55e",color:"white",cursor:"pointer",fontSize:13,fontWeight:500},children:"📤 Export"})]}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(w==="visual"||w==="split")&&e.jsxs("div",{style:{width:240,borderRight:`1px solid ${t.border}`,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${t.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600},children:"Event Flows"}),e.jsx("button",{onClick:()=>N(!0),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[a.map(n=>{const m=v.find(o=>o.type===n.source.type);return e.jsxs("div",{onClick:()=>z(n.id),style:{padding:12,background:R===n.id?t.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${R===n.id?t.border:"transparent"}`,opacity:n.enabled?1:.5},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{children:m?.icon??"⚡"}),e.jsx("span",{style:{flex:1,fontSize:13,fontWeight:500},children:n.name}),e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:n.enabled?"#22c55e":"#ef4444"}})]}),e.jsxs("div",{style:{fontSize:10,color:t.textMuted,marginTop:4},children:[n.handlers.length," handler",n.handlers.length!==1?"s":""]})]},n.id)}),C&&e.jsxs("div",{style:{padding:12,background:t.cardBg,borderRadius:6,border:"1px solid #3b82f6"},children:[e.jsx("input",{type:"text",value:P,onChange:n=>q(n.target.value),placeholder:"Flow name...",autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:n=>n.key==="Enter"&&B()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>N(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:11},children:"Cancel"}),e.jsx("button",{onClick:B,style:{flex:1,padding:6,borderRadius:4,border:"none",background:"#3b82f6",color:"white",cursor:"pointer",fontSize:11},children:"Add"})]})]})]})]}),(w==="visual"||w==="split")&&g&&e.jsxs("div",{style:{flex:w==="split"?1:2,overflow:"auto",padding:20},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsx("input",{type:"text",value:g.name,onChange:n=>D(g.id,{name:n.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${t.border}`,background:t.cardBg,color:t.text,fontSize:16,fontWeight:600}}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:g.enabled,onChange:n=>D(g.id,{enabled:n.target.checked})}),e.jsx("span",{style:{fontSize:12},children:"Enabled"})]}),e.jsx("button",{onClick:()=>h?.(g.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${t.border}`,background:"transparent",color:t.text,cursor:"pointer",fontSize:12},children:"▶️ Test"}),e.jsx("button",{onClick:()=>H(g.id),style:{padding:"8px 12px",borderRadius:6,border:"1px solid #ef4444",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:12},children:"🗑️"})]}),e.jsxs("div",{style:{padding:16,background:t.cardBg,borderRadius:8,marginBottom:16,borderLeft:`4px solid ${v.find(n=>n.type===g.source.type)?.color??"#888"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx("span",{style:{fontSize:20},children:v.find(n=>n.type===g.source.type)?.icon??"⚡"}),e.jsx("span",{style:{fontWeight:600},children:"Event Source"})]}),e.jsx("select",{value:g.source.type,onChange:n=>D(g.id,{source:{...g.source,type:n.target.value,config:{}}}),style:{width:"100%",padding:10,borderRadius:6,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:13,marginBottom:12},children:v.map(n=>e.jsxs("option",{value:n.type,children:[n.icon," ",n.label]},n.type))}),v.find(n=>n.type===g.source.type)?.configSchema.map(n=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsxs("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:[n.label," ",n.required&&e.jsx("span",{style:{color:"#ef4444"},children:"*"})]}),n.type==="select"?e.jsx("select",{value:String(g.source.config[n.name]??""),onChange:m=>D(g.id,{source:{...g.source,config:{...g.source.config,[n.name]:m.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:n.options?.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))}):e.jsx("input",{type:n.type==="number"?"number":"text",value:String(g.source.config[n.name]??""),onChange:m=>D(g.id,{source:{...g.source,config:{...g.source.config,[n.name]:n.type==="number"?Number(m.target.value):m.target.value}}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,boxSizing:"border-box"}})]},n.name))]}),e.jsx("div",{style:{textAlign:"center",color:t.textMuted,marginBottom:16},children:"⬇️"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[g.handlers.map((n,m)=>{const o=k.find(s=>s.type===n.type),r=A.has(n.id);return e.jsxs(y.Fragment,{children:[e.jsxs("div",{style:{padding:16,background:t.cardBg,borderRadius:8,borderLeft:`4px solid ${o?.color??"#888"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},onClick:()=>W(s=>{const $=new Set(s);return $.has(n.id)?$.delete(n.id):$.add(n.id),$}),children:[e.jsx("span",{style:{fontSize:16},children:o?.icon??"⚡"}),e.jsxs("span",{style:{fontWeight:500},children:[m+1,". ",o?.label??n.type]}),n.modifiers?.map(s=>e.jsxs("span",{style:{padding:"2px 6px",background:"#8b5cf620",color:"#8b5cf6",borderRadius:4,fontSize:10},children:[s.type,": ",s.value,"ms"]},s.type)),e.jsx("span",{style:{marginLeft:"auto",color:t.textMuted},children:r?"▼":"▶"})]}),r&&e.jsxs("div",{style:{marginTop:12,paddingTop:12,borderTop:`1px solid ${t.border}`},children:[e.jsx("select",{value:n.type,onChange:s=>F(n.id,{type:s.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,marginBottom:12},children:k.map(s=>e.jsxs("option",{value:s.type,children:[s.icon," ",s.label]},s.type))}),o?.configSchema.map(s=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:t.textMuted,marginBottom:4},children:s.label}),s.type==="code"?e.jsx("textarea",{value:String(n.config[s.name]??""),onChange:$=>F(n.id,{config:{...n.config,[s.name]:$.target.value}}),rows:3,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontFamily:"monospace",fontSize:11,resize:"vertical",boxSizing:"border-box"}}):s.type==="select"?e.jsx("select",{value:String(n.config[s.name]??""),onChange:$=>F(n.id,{config:{...n.config,[s.name]:$.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12},children:s.options?.map($=>e.jsx("option",{value:$.value,children:$.label},$.value))}):e.jsx("input",{type:s.type==="number"?"number":"text",value:String(n.config[s.name]??""),onChange:$=>F(n.id,{config:{...n.config,[s.name]:s.type==="number"?Number($.target.value):$.target.value}}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${t.border}`,background:t.bg,color:t.text,fontSize:12,boxSizing:"border-box"}})]},s.name)),e.jsxs("div",{style:{marginTop:12},children:[e.jsx("div",{style:{fontSize:11,color:t.textMuted,marginBottom:8},children:"Modifiers"}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:["debounce","throttle","delay","retry","once"].map(s=>e.jsx("button",{onClick:()=>u(n.id,s),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${n.modifiers?.some($=>$.type===s)?"#8b5cf6":t.border}`,background:n.modifiers?.some($=>$.type===s)?"#8b5cf620":"transparent",color:t.text,cursor:"pointer",fontSize:11},children:s},s))})]}),e.jsx("button",{onClick:()=>U(n.id),style:{marginTop:12,padding:"6px 12px",borderRadius:4,border:"1px solid #ef4444",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:11},children:"🗑️ Remove Handler"})]})]}),m<g.handlers.length-1&&e.jsx("div",{style:{textAlign:"center",color:t.textMuted},children:"⬇️"})]},n.id)}),e.jsxs("div",{style:{padding:16,border:`1px dashed ${t.border}`,borderRadius:8,textAlign:"center"},children:[e.jsx("div",{style:{fontSize:12,color:t.textMuted,marginBottom:12},children:"Add Handler"}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center"},children:k.map(n=>e.jsxs("button",{onClick:()=>M(n.type),style:{padding:"6px 12px",borderRadius:4,border:`1px solid ${n.color}`,background:`${n.color}20`,color:t.text,cursor:"pointer",fontSize:11},children:[n.icon," ",n.label]},n.type))})]})]})]}),(w==="code"||w==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"#0d1117",borderLeft:w==="split"?`1px solid ${t.border}`:void 0},children:e.jsx("pre",{style:{margin:0,fontFamily:"Consolas, Monaco, monospace",fontSize:12,lineHeight:1.5,color:"#e6edf3",whiteSpace:"pre-wrap"},children:T})})]})]})},Me=Object.freeze(Object.defineProperty({__proto__:null,NiceEventOrchestrator:ge},Symbol.toStringTag,{value:"Module"})),Y={render:{label:"Render",icon:"🎨",color:"#3b82f6"},click:{label:"Click",icon:"👆",color:"#22c55e",hasTarget:!0},type:{label:"Type",icon:"⌨️",color:"#f59e0b",hasTarget:!0,hasValue:!0},select:{label:"Select",icon:"📋",color:"#8b5cf6",hasTarget:!0,hasValue:!0},hover:{label:"Hover",icon:"🖱️",color:"#ec4899",hasTarget:!0},focus:{label:"Focus",icon:"🎯",color:"#06b6d4",hasTarget:!0},blur:{label:"Blur",icon:"💨",color:"#6b7280",hasTarget:!0},submit:{label:"Submit",icon:"📤",color:"#14b8a6",hasTarget:!0},keypress:{label:"Key Press",icon:"⌨️",color:"#a855f7",hasValue:!0},wait:{label:"Wait",icon:"⏳",color:"#f97316",hasValue:!0},scroll:{label:"Scroll",icon:"📜",color:"#84cc16",hasTarget:!0},drag:{label:"Drag & Drop",icon:"✋",color:"#eab308",hasTarget:!0,hasValue:!0},assert:{label:"Assert",icon:"✅",color:"#22c55e",hasTarget:!0,hasValue:!0},snapshot:{label:"Snapshot",icon:"📸",color:"#3b82f6"},"a11y-check":{label:"A11y Check",icon:"♿",color:"#8b5cf6"}},De=[{id:"suite-1",name:"Button Component Tests",componentName:"NiceButton",setup:{mocks:[{name:"onClick",type:"function"}]},tests:[{id:"test-1",name:"renders with correct text",type:"unit",steps:[{id:"step-1",action:"render"},{id:"step-2",action:"assert",target:"button",value:{matcher:"toHaveTextContent",expected:"Click me"}}]},{id:"test-2",name:"calls onClick when clicked",type:"unit",steps:[{id:"step-3",action:"render"},{id:"step-4",action:"click",target:"button"},{id:"step-5",action:"assert",value:{mock:"onClick",matcher:"toHaveBeenCalled"}}]},{id:"test-3",name:"is disabled when loading",type:"unit",steps:[{id:"step-6",action:"render"},{id:"step-7",action:"assert",target:"button",value:{matcher:"toHaveAttribute",expected:["disabled","true"]}}]}]},{id:"suite-2",name:"Form Integration Tests",componentName:"ContactForm",setup:{mocks:[{name:"api.submit",type:"api",returnValue:{success:!0}}],providers:[{name:"FormProvider",props:{}}]},tests:[{id:"test-4",name:"submits form with valid data",type:"integration",steps:[{id:"step-8",action:"render"},{id:"step-9",action:"type",target:'input[name="email"]',value:"test@example.com"},{id:"step-10",action:"type",target:'input[name="message"]',value:"Hello!"},{id:"step-11",action:"click",target:'button[type="submit"]'},{id:"step-12",action:"wait",value:{type:"api",timeout:1e3}},{id:"step-13",action:"assert",target:".success-message",value:{matcher:"toBeInTheDocument"}}]},{id:"test-5",name:"shows validation errors",type:"integration",steps:[{id:"step-14",action:"render"},{id:"step-15",action:"click",target:'button[type="submit"]'},{id:"step-16",action:"assert",target:".error",value:{matcher:"toHaveTextContent",expected:"Email is required"}}]}]}],Ie=i=>i.map(v=>{const k=new Set(["import { render, screen, fireEvent, waitFor } from '@testing-library/react';","import userEvent from '@testing-library/user-event';",`import { ${v.componentName} } from './${v.componentName}';`]);v.setup?.mocks.forEach(l=>{l.type==="api"&&(k.add("import { rest } from 'msw';"),k.add("import { setupServer } from 'msw/node';"))});const f=v.setup?.mocks.map(l=>l.type==="function"?`const ${l.name} = jest.fn();`:l.type==="api"?`// API mock: ${l.name}`:"").filter(Boolean).join(`
193
+ `),h=v.setup?.providers&&v.setup.providers.length>0?`const Wrapper = ({ children }) => (
194
+ ${v.setup.providers.map(l=>`<${l.name}>`).join(`
195
+ `)}
196
+ {children}
197
+ ${v.setup.providers.reverse().map(l=>`</${l.name}>`).join(`
198
+ `)}
199
+ );`:"",j=v.tests.map(l=>{const x=l.skip?".skip":l.only?".only":"",a=l.steps.map(d=>Pe(d,v)).join(`
200
+ `);return`
201
+ it${x}('${l.name}', async () => {
202
+ ${a}
203
+ });`}).join(`
204
+ `);return`/**
205
+ * ${v.name}
206
+ * @generated by NiceTestBuilder
207
+ */
208
+
209
+ ${Array.from(k).join(`
210
+ `)}
211
+
212
+ describe('${v.componentName}', () => {
213
+ ${f?` // Mocks
214
+ ${f}
215
+ `:""}
216
+ ${h?` ${h}
217
+ `:""}
218
+ beforeEach(() => {
219
+ jest.clearAllMocks();
220
+ });
221
+ ${j}
222
+ });
223
+ `}).join(`
224
+
225
+ `),Pe=(i,v)=>{switch(Y[i.action],i.action){case"render":const k=v.setup?.providers&&v.setup.providers.length>0,f=v.setup?.props?` {...${JSON.stringify(v.setup.props)}}`:"";return k?`render(<${v.componentName}${f} />, { wrapper: Wrapper });`:`render(<${v.componentName}${f} />);`;case"click":return`await userEvent.click(screen.getByRole('${i.target?.replace(/[[\]'"]/g,"")}'));`;case"type":return`await userEvent.type(screen.getByRole('textbox', { name: /${i.target}/ }), '${i.value}');`;case"select":return`await userEvent.selectOptions(screen.getByRole('combobox'), '${i.value}');`;case"hover":return`await userEvent.hover(screen.getByRole('${i.target}'));`;case"focus":return`screen.getByRole('${i.target}').focus();`;case"blur":return`screen.getByRole('${i.target}').blur();`;case"submit":return"fireEvent.submit(screen.getByRole('form'));";case"wait":if(typeof i.value=="object"&&i.value!==null){const S=i.value;return S.type==="timeout"?`await new Promise(r => setTimeout(r, ${S.value}));`:`await waitFor(() => expect(/* condition */).toBeTruthy(), { timeout: ${S.timeout??1e3} });`}return`await new Promise(r => setTimeout(r, ${i.value}));`;case"assert":if(typeof i.value=="object"&&i.value!==null){const S=i.value;if(S.mock)return`expect(${S.mock}).${S.matcher}(${S.expected?JSON.stringify(S.expected):""});`;const h=i.target?`screen.getByRole('${i.target}')`:"result",j=S.expected!==void 0?JSON.stringify(S.expected):"";return`expect(${h}).${S.matcher}(${j});`}return`expect(screen.getByRole('${i.target}')).toBeInTheDocument();`;case"snapshot":return"expect(container).toMatchSnapshot();";case"a11y-check":return`const results = await axe(container);
226
+ expect(results).toHaveNoViolations();`;default:return`// ${i.action}: ${JSON.stringify(i)}`}},me=({componentName:i="MyComponent",testSuites:v=De,availableMocks:k=[],onSuitesChange:f,onExport:S,onRun:h,onRunAll:j,className:l,style:x,"data-testid":a})=>{const[d,R]=y.useState(v),[z,w]=y.useState(d[0]?.id??null),[L,C]=y.useState(null),[N,P]=y.useState("visual"),[q,A]=y.useState(!1),[W,g]=y.useState(""),[T,D]=y.useState(new Set),B=y.useMemo(()=>d.find(c=>c.id===z),[d,z]);y.useMemo(()=>B?.tests.find(c=>c.id===L),[B,L]);const H=y.useMemo(()=>Ie(d),[d]),M=y.useCallback((c,O)=>{R(I=>{const p=I.map(b=>b.id===c?{...b,...O}:b);return f?.(p),p})},[f]),F=()=>{if(!W.trim())return;const c={id:`suite-${Date.now()}`,name:W,componentName:i,tests:[]};R(O=>{const I=[...O,c];return f?.(I),I}),w(c.id),A(!1),g("")},U=c=>{R(O=>{const I=O.filter(p=>p.id!==c);return f?.(I),I}),z===c&&w(d[0]?.id??null)},u=()=>{if(!B)return;const c={id:`test-${Date.now()}`,name:"New test",type:"unit",steps:[{id:`step-${Date.now()}`,action:"render"}]};M(B.id,{tests:[...B.tests,c]}),C(c.id),D(O=>new Set([...O,c.id]))},t=(c,O)=>{B&&M(B.id,{tests:B.tests.map(I=>I.id===c?{...I,...O}:I)})},n=c=>{B&&(M(B.id,{tests:B.tests.filter(O=>O.id!==c)}),L===c&&C(null))},m=(c,O)=>{if(!B)return;const I=B.tests.find(b=>b.id===c);if(!I)return;const p={id:`step-${Date.now()}`,action:O};t(c,{steps:[...I.steps,p]})},o=(c,O,I)=>{if(!B)return;const p=B.tests.find(b=>b.id===c);p&&t(c,{steps:p.steps.map(b=>b.id===O?{...b,...I}:b)})},r=(c,O)=>{if(!B)return;const I=B.tests.find(p=>p.id===c);I&&t(c,{steps:I.steps.filter(p=>p.id!==O)})},s={bg:"#1e1e1e",cardBg:"#252525",border:"#333",text:"#e0e0e0",textMuted:"#888"},$=y.useMemo(()=>{const c=d.reduce((I,p)=>I+p.tests.length,0),O=d.reduce((I,p)=>I+p.tests.filter(b=>b.skip).length,0);return{total:c,skipped:O}},[d]);return e.jsxs("div",{className:`nice-test-builder ${l||""}`,style:{display:"flex",flexDirection:"column",height:"100%",background:s.bg,color:s.text,fontFamily:"system-ui, sans-serif",...x},"data-testid":a,children:[e.jsxs("div",{style:{padding:"12px 20px",borderBottom:`1px solid ${s.border}`,display:"flex",alignItems:"center",gap:16},children:[e.jsx("h3",{style:{margin:0,fontSize:16},children:"🧪 Test Builder"}),e.jsxs("div",{style:{fontSize:12,color:s.textMuted},children:[$.total," tests • ",$.skipped," skipped"]}),e.jsx("div",{style:{display:"flex",border:`1px solid ${s.border}`,borderRadius:6,overflow:"hidden",marginLeft:"auto"},children:["visual","code","split"].map(c=>e.jsxs("button",{onClick:()=>P(c),style:{padding:"6px 12px",border:"none",background:N===c?s.cardBg:"transparent",color:s.text,cursor:"pointer",fontSize:12,textTransform:"capitalize"},children:[c==="visual"?"🎨":c==="code"?"📝":"📐"," ",c]},c))}),e.jsx("button",{onClick:j,style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${s.border}`,background:"transparent",color:s.text,cursor:"pointer",fontSize:13},children:"▶️ Run All"}),e.jsx("button",{onClick:()=>S?.(H),style:{padding:"8px 16px",borderRadius:6,border:"none",background:"#22c55e",color:"white",cursor:"pointer",fontSize:13,fontWeight:500},children:"📤 Export"})]}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(N==="visual"||N==="split")&&e.jsxs("div",{style:{width:220,borderRight:`1px solid ${s.border}`,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:`1px solid ${s.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600},children:"Test Suites"}),e.jsx("button",{onClick:()=>A(!0),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${s.border}`,background:"transparent",color:s.text,cursor:"pointer",fontSize:12},children:"+"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[d.map(c=>e.jsxs("div",{onClick:()=>{w(c.id),C(null)},style:{padding:12,background:z===c.id?s.cardBg:"transparent",borderRadius:6,cursor:"pointer",marginBottom:4,border:`1px solid ${z===c.id?s.border:"transparent"}`},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:c.name}),e.jsxs("div",{style:{fontSize:10,color:s.textMuted,marginTop:4},children:[c.componentName," • ",c.tests.length," test",c.tests.length!==1?"s":""]})]},c.id)),q&&e.jsxs("div",{style:{padding:12,background:s.cardBg,borderRadius:6,border:"1px solid #3b82f6"},children:[e.jsx("input",{type:"text",value:W,onChange:c=>g(c.target.value),placeholder:"Suite name...",autoFocus:!0,style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${s.border}`,background:s.bg,color:s.text,fontSize:12,marginBottom:8,boxSizing:"border-box"},onKeyDown:c=>c.key==="Enter"&&F()}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>A(!1),style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${s.border}`,background:"transparent",color:s.text,cursor:"pointer",fontSize:11},children:"Cancel"}),e.jsx("button",{onClick:F,style:{flex:1,padding:6,borderRadius:4,border:"none",background:"#3b82f6",color:"white",cursor:"pointer",fontSize:11},children:"Add"})]})]})]})]}),(N==="visual"||N==="split")&&B&&e.jsxs("div",{style:{flex:N==="split"?1:2,overflow:"auto",padding:20},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginBottom:20},children:[e.jsx("input",{type:"text",value:B.name,onChange:c=>M(B.id,{name:c.target.value}),style:{flex:1,padding:10,borderRadius:6,border:`1px solid ${s.border}`,background:s.cardBg,color:s.text,fontSize:16,fontWeight:600}}),e.jsx("button",{onClick:()=>h?.(B.id),style:{padding:"8px 16px",borderRadius:6,border:`1px solid ${s.border}`,background:"transparent",color:s.text,cursor:"pointer",fontSize:12},children:"▶️ Run Suite"}),e.jsx("button",{onClick:()=>U(B.id),style:{padding:"8px 12px",borderRadius:6,border:"1px solid #ef4444",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:12},children:"🗑️"})]}),e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:s.textMuted,marginBottom:6},children:"Component"}),e.jsx("input",{type:"text",value:B.componentName,onChange:c=>M(B.id,{componentName:c.target.value}),style:{width:200,padding:8,borderRadius:4,border:`1px solid ${s.border}`,background:s.cardBg,color:s.text,fontSize:13}})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[B.tests.map((c,O)=>{const I=T.has(c.id),p={unit:{color:"#3b82f6",icon:"🧩"},integration:{color:"#22c55e",icon:"🔗"},e2e:{color:"#8b5cf6",icon:"🌐"},snapshot:{color:"#f59e0b",icon:"📸"},accessibility:{color:"#ec4899",icon:"♿"}};return e.jsxs("div",{style:{background:s.cardBg,borderRadius:8,border:`1px solid ${L===c.id?"#3b82f6":s.border}`,overflow:"hidden"},children:[e.jsxs("div",{style:{padding:12,display:"flex",alignItems:"center",gap:8,cursor:"pointer",borderLeft:`4px solid ${p[c.type].color}`},onClick:()=>{C(c.id),D(b=>{const E=new Set(b);return E.has(c.id)?E.delete(c.id):E.add(c.id),E})},children:[e.jsx("span",{children:p[c.type].icon}),e.jsxs("span",{style:{fontWeight:500,opacity:c.skip?.5:1},children:[O+1,". ",c.name]}),c.skip&&e.jsx("span",{style:{padding:"2px 6px",background:"#f59e0b30",color:"#f59e0b",borderRadius:4,fontSize:10},children:"SKIPPED"}),c.only&&e.jsx("span",{style:{padding:"2px 6px",background:"#8b5cf630",color:"#8b5cf6",borderRadius:4,fontSize:10},children:"ONLY"}),e.jsxs("span",{style:{marginLeft:"auto",fontSize:11,color:s.textMuted},children:[c.steps.length," step",c.steps.length!==1?"s":""]}),e.jsx("span",{style:{color:s.textMuted},children:I?"▼":"▶"})]}),I&&e.jsxs("div",{style:{padding:16,borderTop:`1px solid ${s.border}`},children:[e.jsxs("div",{style:{display:"flex",gap:12,marginBottom:16},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("label",{style:{display:"block",fontSize:11,color:s.textMuted,marginBottom:4},children:"Test Name"}),e.jsx("input",{type:"text",value:c.name,onChange:b=>t(c.id,{name:b.target.value}),style:{width:"100%",padding:8,borderRadius:4,border:`1px solid ${s.border}`,background:s.bg,color:s.text,fontSize:12,boxSizing:"border-box"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,color:s.textMuted,marginBottom:4},children:"Type"}),e.jsxs("select",{value:c.type,onChange:b=>t(c.id,{type:b.target.value}),style:{padding:8,borderRadius:4,border:`1px solid ${s.border}`,background:s.bg,color:s.text,fontSize:12},children:[e.jsx("option",{value:"unit",children:"🧩 Unit"}),e.jsx("option",{value:"integration",children:"🔗 Integration"}),e.jsx("option",{value:"e2e",children:"🌐 E2E"}),e.jsx("option",{value:"snapshot",children:"📸 Snapshot"}),e.jsx("option",{value:"accessibility",children:"♿ A11y"})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:c.skip??!1,onChange:b=>t(c.id,{skip:b.target.checked,only:!1})}),"Skip"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:c.only??!1,onChange:b=>t(c.id,{only:b.target.checked,skip:!1})}),"Only"]})]})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,color:s.textMuted,marginBottom:8},children:"Steps"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:c.steps.map((b,E)=>{const _=Y[b.action];return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:10,background:s.bg,borderRadius:6,borderLeft:`3px solid ${_.color}`},children:[e.jsx("span",{style:{width:20,textAlign:"center",fontSize:11,color:s.textMuted},children:E+1}),e.jsx("span",{children:_.icon}),e.jsx("select",{value:b.action,onChange:V=>o(c.id,b.id,{action:V.target.value}),style:{padding:6,borderRadius:4,border:`1px solid ${s.border}`,background:s.cardBg,color:s.text,fontSize:11},children:Object.entries(Y).map(([V,K])=>e.jsxs("option",{value:V,children:[K.icon," ",K.label]},V))}),_.hasTarget&&e.jsx("input",{type:"text",value:b.target??"",onChange:V=>o(c.id,b.id,{target:V.target.value}),placeholder:"Target selector",style:{flex:1,padding:6,borderRadius:4,border:`1px solid ${s.border}`,background:s.cardBg,color:s.text,fontSize:11}}),_.hasValue&&b.action!=="assert"&&e.jsx("input",{type:"text",value:typeof b.value=="string"?b.value:"",onChange:V=>o(c.id,b.id,{value:V.target.value}),placeholder:"Value",style:{width:120,padding:6,borderRadius:4,border:`1px solid ${s.border}`,background:s.cardBg,color:s.text,fontSize:11}}),e.jsx("button",{onClick:()=>r(c.id,b.id),style:{padding:4,borderRadius:4,border:"none",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:12},children:"×"})]},b.id)})})]}),e.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:Object.entries(Y).slice(0,8).map(([b,E])=>e.jsxs("button",{onClick:()=>m(c.id,b),style:{padding:"4px 8px",borderRadius:4,border:`1px solid ${E.color}40`,background:`${E.color}20`,color:s.text,cursor:"pointer",fontSize:10},children:[E.icon," ",E.label]},b))}),e.jsx("div",{style:{marginTop:16,display:"flex",gap:8},children:e.jsx("button",{onClick:()=>n(c.id),style:{padding:"6px 12px",borderRadius:4,border:"1px solid #ef4444",background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:11},children:"🗑️ Delete Test"})})]})]},c.id)}),e.jsx("button",{onClick:u,style:{padding:16,borderRadius:8,border:`1px dashed ${s.border}`,background:"transparent",color:s.textMuted,cursor:"pointer",fontSize:13},children:"+ Add Test"})]})]}),(N==="code"||N==="split")&&e.jsx("div",{style:{flex:1,overflow:"auto",padding:16,background:"#0d1117",borderLeft:N==="split"?`1px solid ${s.border}`:void 0},children:e.jsx("pre",{style:{margin:0,fontFamily:"Consolas, Monaco, monospace",fontSize:12,lineHeight:1.5,color:"#e6edf3",whiteSpace:"pre-wrap"},children:H})})]})]})},Ae=Object.freeze(Object.defineProperty({__proto__:null,NiceTestBuilder:me},Symbol.toStringTag,{value:"Module"})),Fe=[{id:"react",name:"React",icon:"⚛️",description:"React component templates",templates:[{id:"react-component",name:"React Component",description:"Basic React functional component",category:"components",icon:"📦",engine:"handlebars",variables:[{id:"componentName",name:"componentName",type:"string",required:!0,defaultValue:"MyComponent"},{id:"withProps",name:"withProps",type:"boolean",defaultValue:!0},{id:"withTests",name:"withTests",type:"boolean",defaultValue:!0},{id:"withStory",name:"withStory",type:"boolean",defaultValue:!1}],files:[{id:"component",name:"{{componentName}}.tsx",path:"src/components/{{componentName}}",language:"typescript",content:`import React from 'react';
227
+ {{#if withProps}}
228
+ export interface {{componentName}}Props {
229
+ children?: React.ReactNode;
230
+ className?: string;
231
+ }
232
+ {{/if}}
233
+
234
+ export const {{componentName}}: React.FC{{#if withProps}}<{{componentName}}Props>{{/if}} = ({{#if withProps}}{ children, className }{{/if}}) => {
235
+ return (
236
+ <div className={className}>
237
+ {children}
238
+ </div>
239
+ );
240
+ };
241
+
242
+ export default {{componentName}};
243
+ `},{id:"test",name:"{{componentName}}.test.tsx",path:"src/components/{{componentName}}",language:"typescript",condition:"withTests === true",content:`import { render, screen } from '@testing-library/react';
244
+ import { {{componentName}} } from './{{componentName}}';
245
+
246
+ describe('{{componentName}}', () => {
247
+ it('renders children', () => {
248
+ render(<{{componentName}}>Test Content</{{componentName}}>);
249
+ expect(screen.getByText('Test Content')).toBeInTheDocument();
250
+ });
251
+ });
252
+ `},{id:"story",name:"{{componentName}}.stories.tsx",path:"src/components/{{componentName}}",language:"typescript",condition:"withStory === true",content:`import type { Meta, StoryObj } from '@storybook/react';
253
+ import { {{componentName}} } from './{{componentName}}';
254
+
255
+ const meta: Meta<typeof {{componentName}}> = {
256
+ title: 'Components/{{componentName}}',
257
+ component: {{componentName}},
258
+ };
259
+
260
+ export default meta;
261
+ type Story = StoryObj<typeof {{componentName}}>;
262
+
263
+ export const Default: Story = {
264
+ args: {},
265
+ };
266
+ `},{id:"index",name:"index.ts",path:"src/components/{{componentName}}",language:"typescript",content:`export { {{componentName}} } from './{{componentName}}';
267
+ export type { {{componentName}}Props } from './{{componentName}}';
268
+ `}]}]},{id:"nextjs",name:"Next.js",icon:"▲",description:"Next.js page and API templates",templates:[{id:"nextjs-page",name:"Next.js Page",description:"Next.js App Router page",category:"pages",icon:"📄",engine:"handlebars",variables:[{id:"pageName",name:"pageName",type:"string",required:!0,defaultValue:"about"},{id:"withMetadata",name:"withMetadata",type:"boolean",defaultValue:!0},{id:"withLoading",name:"withLoading",type:"boolean",defaultValue:!1},{id:"withError",name:"withError",type:"boolean",defaultValue:!1}],files:[{id:"page",name:"page.tsx",path:"app/{{pageName}}",language:"typescript",content:`{{#if withMetadata}}
269
+ import type { Metadata } from 'next';
270
+
271
+ export const metadata: Metadata = {
272
+ title: '{{pageName}}',
273
+ description: '{{pageName}} page',
274
+ };
275
+ {{/if}}
276
+
277
+ export default function {{pascalCase pageName}}Page() {
278
+ return (
279
+ <main>
280
+ <h1>{{pageName}}</h1>
281
+ </main>
282
+ );
283
+ }
284
+ `},{id:"loading",name:"loading.tsx",path:"app/{{pageName}}",language:"typescript",condition:"withLoading === true",content:`export default function Loading() {
285
+ return <div>Loading...</div>;
286
+ }
287
+ `},{id:"error",name:"error.tsx",path:"app/{{pageName}}",language:"typescript",condition:"withError === true",content:`'use client';
288
+
289
+ export default function Error({
290
+ error,
291
+ reset,
292
+ }: {
293
+ error: Error & { digest?: string };
294
+ reset: () => void;
295
+ }) {
296
+ return (
297
+ <div>
298
+ <h2>Something went wrong!</h2>
299
+ <button onClick={reset}>Try again</button>
300
+ </div>
301
+ );
302
+ }
303
+ `}]},{id:"nextjs-api",name:"Next.js API Route",description:"Next.js App Router API handler",category:"api",icon:"🔌",engine:"handlebars",variables:[{id:"routeName",name:"routeName",type:"string",required:!0,defaultValue:"users"},{id:"methods",name:"methods",type:"array",defaultValue:["GET","POST"]}],files:[{id:"route",name:"route.ts",path:"app/api/{{routeName}}",language:"typescript",content:`import { NextResponse } from 'next/server';
304
+
305
+ {{#if (includes methods 'GET')}}
306
+ export async function GET() {
307
+ return NextResponse.json({ message: 'GET {{routeName}}' });
308
+ }
309
+ {{/if}}
310
+
311
+ {{#if (includes methods 'POST')}}
312
+ export async function POST(request: Request) {
313
+ const body = await request.json();
314
+ return NextResponse.json({ message: 'POST {{routeName}}', data: body });
315
+ }
316
+ {{/if}}
317
+
318
+ {{#if (includes methods 'PUT')}}
319
+ export async function PUT(request: Request) {
320
+ const body = await request.json();
321
+ return NextResponse.json({ message: 'PUT {{routeName}}', data: body });
322
+ }
323
+ {{/if}}
324
+
325
+ {{#if (includes methods 'DELETE')}}
326
+ export async function DELETE() {
327
+ return NextResponse.json({ message: 'DELETE {{routeName}}' });
328
+ }
329
+ {{/if}}
330
+ `}]}]}],se=(i,v,k)=>{let f=i;Object.entries(v).forEach(([j,l])=>{const x=new RegExp(`\\{\\{\\s*${j}\\s*\\}\\}`,"g");f=f.replace(x,String(l));const a=new RegExp(`\\{\\{\\s*pascalCase\\s+${j}\\s*\\}\\}`,"g");if(typeof l=="string"){const d=l.charAt(0).toUpperCase()+l.slice(1);f=f.replace(a,d)}});const S=/\{\{#if\s+([^}]+)\}\}([\s\S]*?)\{\{\/if\}\}/g;f=f.replace(S,(j,l,x)=>{const a=l.trim(),d=a.match(/(\w+)\s*===?\s*(\w+|true|false|'[^']*'|"[^"]*")/);if(d){const[,z,w]=d,L=v[z];let C=w;return w==="true"?C=!0:w==="false"?C=!1:(w.startsWith("'")||w.startsWith('"'))&&(C=w.slice(1,-1)),L===C?x:""}return v[a]?x:""});const h=/\{\{#if\s+\(includes\s+(\w+)\s+'([^']+)'\)\}\}([\s\S]*?)\{\{\/if\}\}/g;return f=f.replace(h,(j,l,x,a)=>{const d=v[l];return Array.isArray(d)&&d.includes(x)?a:""}),f},_e=(i,v)=>{try{const k=i.split(/\s*(===|!==|==|!=)\s*/);if(k.length===3){const[f,S,h]=k,j=v[f.trim()],l=h.trim();let x=l;switch(l==="true"?x=!0:l==="false"?x=!1:(l.startsWith("'")||l.startsWith('"'))&&(x=l.slice(1,-1)),S){case"===":case"==":return j===x;case"!==":case"!=":return j!==x}}return!!v[i.trim()]}catch{return!0}},xe=({templates:i,presets:v=Fe,selectedTemplate:k,defaultEngine:f="handlebars",showLibrary:S=!0,onTemplateSelect:h,onTemplateCreate:j,onTemplateUpdate:l,onTemplateDelete:x,onGenerate:a,onExport:d,onImport:R,className:z,style:w,"data-testid":L="nice-code-template"})=>{const[C,N]=y.useState(i),[P,q]=y.useState(k||null),[A,W]=y.useState({}),[g,T]=y.useState("editor"),[D,B]=y.useState(null),[H,M]=y.useState(!1),[F,U]=y.useState(!1),u=y.useMemo(()=>{const p=v.flatMap(b=>b.templates);return[...C,...p]},[C,v]),t=y.useMemo(()=>u.find(p=>p.id===P),[u,P]),n=y.useMemo(()=>t?.files.find(p=>p.id===D)||t?.files[0],[t,D]);y.useEffect(()=>{if(t){const p={};t.variables.forEach(b=>{p[b.name]=b.defaultValue??""}),W(p),B(t.files[0]?.id||null)}},[t]);const m=y.useMemo(()=>t?t.files.filter(p=>p.condition?_e(p.condition,A):!0).map(p=>({path:se(`${p.path}/${p.name}`,A,t.engine),content:se(p.content,A,t.engine),language:p.language})):[],[t,A]),o=y.useCallback(p=>{q(p.id),h?.(p)},[h]),r=y.useCallback(()=>{a?.(m,A)},[m,A,a]),s=y.useCallback(()=>{const p={id:crypto.randomUUID(),name:"New Template",description:"Custom template",category:"custom",icon:"📄",engine:f,variables:[{id:"1",name:"name",type:"string",required:!0,defaultValue:"MyName"}],files:[{id:"1",name:"{{name}}.ts",path:"src",language:"typescript",content:`// {{name}}
331
+ export const {{name}} = {};`}]};N(b=>[...b,p]),q(p.id),M(!1),j?.(p)},[f,j]),$=y.useCallback((p,b)=>{if(!t)return;const E={...t,files:t.files.map(_=>_.id===p?{..._,content:b}:_)};N(_=>_.map(V=>V.id===E.id?E:V)),l?.(E)},[t,l]),c=y.useCallback(()=>{if(!t)return;const p={id:crypto.randomUUID(),name:"new-file.ts",path:"src",language:"typescript",content:`// New file
332
+ `},b={...t,files:[...t.files,p]};N(E=>E.map(_=>_.id===b.id?b:_)),B(p.id),l?.(b)},[t,l]),O=y.useCallback(p=>{if(!t)return;const b={...t,files:t.files.filter(E=>E.id!==p)};N(E=>E.map(_=>_.id===b.id?b:_)),B(b.files[0]?.id||null),l?.(b)},[t,l]),I=p=>{const b=A[p.name];switch(p.type){case"boolean":return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!b,onChange:E=>W(_=>({..._,[p.name]:E.target.checked}))}),e.jsx("span",{children:p.name})]});case"select":return e.jsx("select",{value:String(b),onChange:E=>W(_=>({..._,[p.name]:E.target.value})),style:{width:"100%",padding:"8px 12px",background:"#374151",border:"1px solid #4b5563",borderRadius:6,color:"#fff"},children:p.options?.map(E=>e.jsx("option",{value:E,children:E},E))});case"array":return e.jsx("input",{type:"text",value:Array.isArray(b)?b.join(", "):"",onChange:E=>W(_=>({..._,[p.name]:E.target.value.split(",").map(V=>V.trim())})),placeholder:"value1, value2, value3",style:{width:"100%",padding:"8px 12px",background:"#374151",border:"1px solid #4b5563",borderRadius:6,color:"#fff"}});case"number":return e.jsx("input",{type:"number",value:Number(b),onChange:E=>W(_=>({..._,[p.name]:Number(E.target.value)})),style:{width:"100%",padding:"8px 12px",background:"#374151",border:"1px solid #4b5563",borderRadius:6,color:"#fff"}});default:return e.jsx("input",{type:"text",value:String(b??""),onChange:E=>W(_=>({..._,[p.name]:E.target.value})),style:{width:"100%",padding:"8px 12px",background:"#374151",border:"1px solid #4b5563",borderRadius:6,color:"#fff"}})}};return e.jsxs("div",{className:`nice-code-template ${z||""}`,style:{display:"flex",height:"100%",background:"#0d1117",color:"#e6edf3",fontFamily:"system-ui, sans-serif",...w},"data-testid":L,children:[S&&e.jsxs("div",{style:{width:280,borderRight:"1px solid #30363d",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid #30363d",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontWeight:500},children:"📚 Templates"}),e.jsx("button",{onClick:s,style:{padding:"4px 8px",background:"#3b82f6",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:12},children:"+ New"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[C.length>0&&e.jsxs("div",{style:{padding:8},children:[e.jsx("div",{style:{fontSize:11,color:"#8b949e",padding:"8px 8px 4px",fontWeight:500},children:"CUSTOM"}),C.map(p=>e.jsxs("div",{onClick:()=>o(p),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:P===p.id?"rgba(59, 130, 246, 0.15)":"transparent",display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{children:p.icon||"📄"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:p.name}),e.jsx("div",{style:{fontSize:11,color:"#8b949e"},children:p.category})]})]},p.id))]}),v.map(p=>e.jsxs("div",{style:{padding:8},children:[e.jsxs("div",{style:{fontSize:11,color:"#8b949e",padding:"8px 8px 4px",fontWeight:500,display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{children:p.icon}),p.name.toUpperCase()]}),p.templates.map(b=>e.jsxs("div",{onClick:()=>o(b),style:{padding:"10px 12px",borderRadius:6,cursor:"pointer",background:P===b.id?"rgba(59, 130, 246, 0.15)":"transparent",display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{children:b.icon||"📄"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13},children:b.name}),e.jsx("div",{style:{fontSize:11,color:"#8b949e"},children:b.description})]})]},b.id))]},p.id))]})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid #30363d",background:"#161b22",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("span",{style:{fontSize:24},children:t.icon||"📄"}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:t.name}),e.jsx("div",{style:{fontSize:12,color:"#8b949e"},children:t.description})]})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:()=>d?.(t,"json"),style:{padding:"6px 12px",background:"#374151",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12},children:"📤 Export"}),e.jsx("button",{onClick:r,style:{padding:"6px 16px",background:"#22c55e",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:500},children:"⚡ Generate"})]})]}),e.jsx("div",{style:{display:"flex",borderBottom:"1px solid #30363d",background:"#161b22"},children:["variables","editor","preview"].map(p=>e.jsxs("button",{onClick:()=>T(p),style:{padding:"10px 20px",background:g===p?"#0d1117":"transparent",border:"none",borderBottom:g===p?"2px solid #3b82f6":"2px solid transparent",color:g===p?"#fff":"#8b949e",cursor:"pointer",textTransform:"capitalize"},children:[p==="variables"&&"⚙️ ",p==="editor"&&"✏️ ",p==="preview"&&"👁️ ",p]},p))}),e.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[g==="variables"&&e.jsx("div",{style:{flex:1,padding:20,overflow:"auto"},children:e.jsxs("div",{style:{maxWidth:500},children:[e.jsx("h3",{style:{marginBottom:20},children:"Template Variables"}),t.variables.map(p=>e.jsxs("div",{style:{marginBottom:16},children:[e.jsxs("label",{style:{display:"block",fontSize:12,color:"#8b949e",marginBottom:4},children:[p.name,p.required&&e.jsx("span",{style:{color:"#ef4444"},children:" *"})]}),I(p),p.description&&e.jsx("div",{style:{fontSize:11,color:"#6b7280",marginTop:4},children:p.description})]},p.id))]})}),g==="editor"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{width:200,borderRight:"1px solid #30363d",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"8px 12px",borderBottom:"1px solid #30363d",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{fontSize:12,color:"#8b949e"},children:"Files"}),e.jsx("button",{onClick:c,style:{padding:"2px 6px",background:"#374151",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:12},children:"+"})]}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:t.files.map(p=>e.jsxs("div",{onClick:()=>B(p.id),style:{padding:"8px 12px",cursor:"pointer",background:D===p.id?"rgba(59, 130, 246, 0.15)":"transparent",borderLeft:D===p.id?"2px solid #3b82f6":"2px solid transparent",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("div",{style:{fontSize:12,overflow:"hidden",textOverflow:"ellipsis"},children:p.name}),e.jsx("button",{onClick:b=>{b.stopPropagation(),O(p.id)},style:{background:"none",border:"none",color:"#ef4444",cursor:"pointer",fontSize:12,opacity:.7},children:"✕"})]},p.id))})]}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 12px",borderBottom:"1px solid #30363d",background:"#161b22",fontSize:12},children:[n.path,"/",n.name,n.condition&&e.jsxs("span",{style:{color:"#f59e0b",marginLeft:8},children:["(if: ",n.condition,")"]})]}),e.jsx("textarea",{value:n.content,onChange:p=>$(n.id,p.target.value),style:{flex:1,padding:16,background:"#0d1117",color:"#e6edf3",border:"none",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:13,lineHeight:1.5,resize:"none"}})]})})]}),g==="preview"&&e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx("div",{style:{padding:"12px 16px",borderBottom:"1px solid #30363d",background:"#161b22"},children:e.jsxs("span",{style:{fontSize:12,color:"#8b949e"},children:[m.length," file(s) will be generated"]})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:m.map((p,b)=>e.jsxs("div",{style:{borderBottom:"1px solid #30363d"},children:[e.jsxs("div",{style:{padding:"8px 16px",background:"#1f2937",fontFamily:"monospace",fontSize:12,color:"#8b949e"},children:["📄 ",p.path]}),e.jsx("pre",{style:{margin:0,padding:16,background:"#0d1117",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:12,lineHeight:1.5,overflow:"auto"},children:p.content})]},b))})]})]})]}):e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#8b949e"},children:[e.jsx("span",{style:{fontSize:64,marginBottom:16},children:"📚"}),e.jsx("span",{style:{fontSize:18},children:"Select a template"}),e.jsx("span",{style:{fontSize:12,marginTop:4},children:"Choose from the library or create a new template"}),e.jsx("button",{onClick:s,style:{marginTop:20,padding:"10px 20px",background:"#3b82f6",border:"none",borderRadius:6,color:"#fff",cursor:"pointer"},children:"➕ Create Template"})]})})]})},Oe=Object.freeze(Object.defineProperty({__proto__:null,NiceCodeTemplate:xe},Symbol.toStringTag,{value:"Module"}));exports.NiceAPIFlow=pe;exports.NiceAPIFlow$1=$e;exports.NiceCodePreview=be;exports.NiceCodeTemplate=xe;exports.NiceCodeTemplate$1=Oe;exports.NiceComponentDesigner=ye;exports.NiceDataMapper=ue;exports.NiceDataMapper$1=ze;exports.NiceEventOrchestrator=ge;exports.NiceEventOrchestrator$1=Me;exports.NiceLowCodeStudio=he;exports.NicePageBuilder=fe;exports.NiceStateDesigner=de;exports.NiceStateDesigner$1=Se;exports.NiceTestBuilder=me;exports.NiceTestBuilder$1=Ae;