@mieweb/forms-renderer 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blaze.js +0 -2
- package/dist/blaze.js.map +1 -1
- package/dist/blaze.umd.cjs +1 -1
- package/dist/blaze.umd.cjs.map +1 -1
- package/dist/standalone.js +0 -2
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.umd.cjs +1 -1
- package/dist/standalone.umd.cjs.map +1 -1
- package/package.json +2 -2
package/dist/standalone.umd.cjs
CHANGED
|
@@ -2223,5 +2223,5 @@ Check the top-level render call using <`+G+">.")}return O}}function ii(m,O){{if(
|
|
|
2223
2223
|
<%s {...props} />
|
|
2224
2224
|
React keys must be passed directly to JSX without using spread:
|
|
2225
2225
|
let props = %s;
|
|
2226
|
-
<%s key={someKey} {...props} />`,ct,Zn,Sa,Zn),ur[Zn+ct]=!0}}return m===C?yr(st):Wi(st),st}}function Ua(m,O,G){return In(m,O,G,!0)}function xa(m,O,G){return In(m,O,G,!1)}var Fa=xa,Pa=Ua;yv.Fragment=C,yv.jsx=Fa,yv.jsxs=Pa})()),yv}var rb;function pE(){return rb||(rb=1,process.env.NODE_ENV==="production"?hy.exports=fE():hy.exports=dE()),hy.exports}var _=pE();const mc=(v,S)=>v.className===S.className,vE=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:_.jsx("path",{d:"M4 7h16M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3m-5 5l4 4m0-4l-4 4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2"})})),gv=tt.memo(({className:v=""})=>_.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",className:v,children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 7h16m-10 4v6m4-6v6M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3"})}));tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2m-8 0V9M9 9h6"})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8.56 3.69a9 9 0 0 0-2.92 1.95M3.69 8.56A9 9 0 0 0 3 12m.69 3.44a9 9 0 0 0 1.95 2.92m2.92 1.95A9 9 0 0 0 12 21m3.44-.69a9 9 0 0 0 2.92-1.95m1.95-2.92A9 9 0 0 0 21 12m-.69-3.44a9 9 0 0 0-1.95-2.92m-2.92-1.95A9 9 0 0 0 12 3"})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8.56 3.69a9 9 0 0 0-2.92 1.95M3.69 8.56A9 9 0 0 0 3 12m.69 3.44a9 9 0 0 0 1.95 2.92m2.92 1.95A9 9 0 0 0 12 21m3.44-.69a9 9 0 0 0 2.92-1.95m1.95-2.92A9 9 0 0 0 21 12m-.69-3.44a9 9 0 0 0-1.95-2.92m-2.92-1.95A9 9 0 0 0 12 3m-3 9l2 2l4-4"})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),_.jsx("path",{d:"m9 11l3 3l3-3"})]})}));const hE=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"currentColor",d:"m12 2l.324.001l.318.004l.616.017l.299.013l.579.034l.553.046c4.785.464 6.732 2.411 7.196 7.196l.046.553l.034.579q.008.147.013.299l.017.616L22 12l-.005.642l-.017.616l-.013.299l-.034.579l-.046.553c-.464 4.785-2.411 6.732-7.196 7.196l-.553.046l-.579.034q-.147.008-.299.013l-.616.017L12 22l-.642-.005l-.616-.017l-.299-.013l-.579-.034l-.553-.046c-4.785-.464-6.732-2.411-7.196-7.196l-.046-.553l-.034-.579l-.013-.299l-.017-.616Q2 12.327 2 12l.001-.324l.004-.318l.017-.616l.013-.299l.034-.579l.046-.553c.464-4.785 2.411-6.732 7.196-7.196l.553-.046l.579-.034q.147-.008.299-.013l.616-.017Q11.673 2 12 2m0 6a1 1 0 0 0-1 1v2H9l-.117.007A1 1 0 0 0 9 13h2v2l.007.117A1 1 0 0 0 13 15v-2h2l.117-.007A1 1 0 0 0 15 11h-2V9l-.007-.117A1 1 0 0 0 12 8"})})),wv=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16H6a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v1m-4 7h6m-3-3v6"})}));tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M10 8V6a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2v-2"}),_.jsx("path",{d:"M15 12H3l3-3m0 6l-3-3"})]})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0-4 0"}),_.jsx("path",{d:"M13.048 17.942A9 9 0 0 1 12 18q-5.4 0-9-6q3.6-6 9-6t9 6a18 18 0 0 1-1.362 1.975M22 22l-5-5m0 5l5-5"})]})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0-4 0"}),_.jsx("path",{d:"M11.192 17.966Q6.33 17.546 3 12q3.6-6 9-6q4.989 0 8.442 5.122M18.42 15.61a2.1 2.1 0 0 1 2.97 2.97L18 22h-3v-3z"})]})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M18 6L6 18M6 6l12 12"})}));const mE=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M7 7H6a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-1"}),_.jsx("path",{d:"M20.385 6.585a2.1 2.1 0 0 0-2.97-2.97L9 12v3h3zM16 5l3 3"})]})}),mc);tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M6 9l6 6l6 -6"})]}),mc),tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),_.jsx("path",{d:"M7 11l5 5l5 -5"}),_.jsx("path",{d:"M12 4l0 12"})]})),tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),_.jsx("path",{d:"M7 9l5 -5l5 5"}),_.jsx("path",{d:"M12 4l0 12"})]}),mc),tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M7 8l-4 4l4 4"}),_.jsx("path",{d:"M17 8l4 4l-4 4"}),_.jsx("path",{d:"M14 4l-4 16"})]}),mc);const yE=tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M12 10v-7l3 3"}),_.jsx("path",{d:"M9 6l3 -3"}),_.jsx("path",{d:"M12 14v7l3 -3"}),_.jsx("path",{d:"M9 18l3 3"}),_.jsx("path",{d:"M18 3h1a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-1"}),_.jsx("path",{d:"M6 3h-1a2 2 0 0 0 -2 2v14a2 2 0 0 0 2 2h1"})]}),mc),gE=tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M12 3v7l3 -3"}),_.jsx("path",{d:"M9 7l3 3"}),_.jsx("path",{d:"M12 21v-7l3 3"}),_.jsx("path",{d:"M9 17l3 -3"}),_.jsx("path",{d:"M18 9h1a2 2 0 0 1 2 2v2a2 2 0 0 1 -2 2h-1"}),_.jsx("path",{d:"M6 9h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1"})]}),mc);function Ko({ctrl:v,children:S}){var b,C,R,M;const[g,A]=Gu.useState(!0),U=K=>{var V;K.stopPropagation(),v.selected||(V=v.onRowClick)==null||V.call(v,K),v.toggleEdit()},$=K=>{K.stopPropagation(),v.remove()},re=K=>{var V;v.insideSection||(V=v.onRowClick)==null||V.call(v,K)};return v.isPreview||v.insideSection?_.jsxs("div",{className:v.wrapperClass,onClick:v.insideSection?void 0:v.onRowClick,"data-field-id":(b=v.field)==null?void 0:b.id,"data-inside-section":v.insideSection?"true":"false","data-selected":v.selected?"true":"false","aria-selected":v.selected||void 0,tabIndex:-1,children:[v.isPreview?null:_.jsx("div",{children:v.insideSection?`${v.label}`:`(${v.label}) ${v.field.title}`}),typeof S=="function"?S({api:v.api,isPreview:v.isPreview,field:v.field,insideSection:v.insideSection,sectionId:v.sectionId,selected:v.selected}):S]}):_.jsxs("div",{className:v.wrapperClass+" group",onClick:re,"data-field-id":(C=v.field)==null?void 0:C.id,"data-inside-section":v.insideSection?"true":"false","data-selected":v.selected?"true":"false","aria-selected":v.selected||void 0,tabIndex:-1,children:[_.jsxs("div",{className:`flex justify-between items-center ${g?"pb-2.5":""}`,children:[_.jsx("div",{className:"text-left w-full select-none",children:v.insideSection?`${v.label}`:v.field.fieldType==="section"?`(${v.label}) ${v.field.title}`:`${v.label} ${v.field.question}`}),_.jsxs("div",{className:`flex items-center gap-2 ml-2 ${v.insideSection?"hidden":""}`,children:[_.jsx("button",{onClick:U,className:"block lg:hidden",title:"Edit","aria-label":"Edit field",children:_.jsx(mE,{className:"h-6 w-6"})}),_.jsx("button",{type:"button",onClick:K=>{K.stopPropagation(),A(V=>!V)},"aria-expanded":g,"aria-controls":`fw-body-${(R=v.field)==null?void 0:R.id}`,title:g?"Collapse":"Expand","aria-label":g?"Collapse field":"Expand field",className:"p-1",children:g?_.jsx(gE,{className:"h-5 w-5"}):_.jsx(yE,{className:"h-5 w-5"})}),_.jsx("button",{onClick:$,title:"Delete","aria-label":"Delete field",children:_.jsx(vE,{className:"h-6 w-6"})})]})]}),g&&_.jsx("div",{id:`fw-body-${(M=v.field)==null?void 0:M.id}`,children:typeof S=="function"?S({api:v.api,isPreview:v.isPreview,field:v.field,insideSection:v.insideSection,sectionId:v.sectionId,selected:v.selected}):S})]})}function my(v="",S="",b=new Set){const C=S||"field";if(!b.has(C))return C;let R=1,M=`${C}-${R}`;for(;b.has(M);)R++,M=`${C}-${R}`;return M}function yy(v="",S=new Set,b=""){const C=b?`${b}-option`:"option";if(!S.has(C))return C;let R=1,M=`${C}-${R}`;for(;S.has(M);)R++,M=`${C}-${R}`;return M}const wE=(v,S="")=>{if(!Array.isArray(v))return[];const b=new Set;return v.map(C=>{if(typeof C=="string"){const R=yy(C,b,S);return b.add(R),{id:R,value:C}}else{const R=C.id||yy(C.value,b,S);return b.add(R),{id:R,...C}}})},gy=v=>{const{fieldType:S,id:b,question:C,title:R,...M}=v;return{fieldType:S,id:b,...v.fieldType==="section"?{title:R}:{question:C},...M,...!["text","longtext"].includes(S)&&{options:wE(M.options||[],b)}}};function bE(v){switch(v==null?void 0:v.fieldType){case"text":case"longtext":return v.answer??"";case"radio":case"dropdown":return v.selected??null;case"check":return Array.isArray(v.selected)?v.selected:Array.isArray(v.options)?v.options.filter(S=>S==null?void 0:S.selected).map(S=>S.id??S.value):[];default:return null}}function ab(v){return v.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xE(v,S){const b=S==null?void 0:S[v==null?void 0:v.targetId];if(!b)return!1;const C=bE(b),R=v==null?void 0:v.value;switch(v==null?void 0:v.operator){case"equals":return Array.isArray(C)?!1:String(C??"")===String(R??"");case"contains":{const M=$=>String($??"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase(),g=M(C).replace(/[^a-z0-9]+/g," ").trim(),A=M(R).trim();if(!A)return!1;const U=A.split(/\s+/);return(U.length===1?new RegExp(`(?:^|\\s)${ab(U[0])}(?:\\s|$)`):new RegExp(`(?:^|\\s)${U.map($=>ab($)).join("\\s+")}(?:\\s|$)`)).test(g)}case"includes":return Array.isArray(C)?C.map(String).includes(String(R)):!1;default:return!1}}function ib(v,S){const b=v==null?void 0:v.enableWhen;if(!b||!Array.isArray(b.conditions)||b.conditions.length===0)return!0;const C=Array.isArray(S)?S.reduce((M,g)=>(g!=null&&g.id&&(M[g.id]=g),M),{}):S,R=b.conditions.map(M=>xE(M,C));return(b.logic||"AND").toUpperCase()==="AND"?R.every(Boolean):R.some(Boolean)}const lb=(v,S)=>{if(v===S)return!0;if(!v||!S)return!1;const b=Object.keys(v),C=Object.keys(S);if(b.length!==C.length)return!1;for(const R of b)if(v[R]!==S[R])return!1;return!0},ob=(v,S,b)=>typeof b!="number"||b<0||b>v.length?[...v,S]:[...v.slice(0,b),S,...v.slice(b)],SE=v=>{const S={},b=[],C=new Set;return(v||[]).forEach(R=>{let M=R.id;if(!M){const A=R.question||R.title||"",U=R.fieldType||"field";M=my(A,U,C)}C.add(M);const g=gy({...R,id:M});g.fieldType==="section"&&Array.isArray(g.fields)&&(g.fields=g.fields.map(A=>{let U=A.id;if(!U){const $=A.question||A.title||"",re=A.fieldType||"field";U=my($,re,C),C.add(U)}return gy({...A,id:U})})),S[M]=g,b.push(M)}),{byId:S,order:b}};function Xu(v,S,b,C,R={}){const{onIdChange:M,forbidCollision:g=!0}=R;if(!b){const V=v.byId[S];if(!V)return null;const I=C(V,null);if(!I||lb(V,I))return null;if(I.id&&I.id!==S){const ce=I.id;if(g&&v.byId[ce])return null;const{[S]:ze,...Oe}=v.byId,ht={...Oe,[ce]:I},we=v.order.map($e=>$e===S?ce:$e);return M==null||M(ce,S),{byId:ht,order:we}}return{byId:{...v.byId,[S]:I}}}const A=v.byId[b];if(!A||!Array.isArray(A.fields))return null;let U=!1,$=null;const re=A.fields.map(V=>{if(V.id!==S)return V;const I=C(V,A);if(!I||lb(V,I))return V;if(I.id&&I.id!==S){if(g&&A.fields.some(ce=>ce.id===I.id&&ce!==V))return V;$=I.id}return U=!0,I});if(!U)return null;const K={...v.byId,[b]:{...A,fields:re}};return $&&(M==null||M($,S)),{byId:K}}const Zr=eb((v,S)=>({byId:{},order:[],setEnableWhen:(b,C)=>v(R=>{const M=R.byId[b];if(!M)return R;const g=C&&Array.isArray(C.conditions)?{logic:C.logic||"AND",conditions:C.conditions}:void 0;return{byId:{...R.byId,[b]:{...M,...g?{enableWhen:g}:{enableWhen:void 0}}}}}),replaceAll:b=>v(()=>SE(b)),addField:(b,C={})=>v(R=>{var M,g;const{sectionId:A,initialPatch:U={},index:$}=C,re=(M=xv[b])==null?void 0:M.defaultProps;if(!re)return R;const K=new Set(Object.keys(R.byId));A&&(g=R.byId[A])!=null&&g.fields&&R.byId[A].fields.forEach(we=>K.add(we.id));const V=(U==null?void 0:U.question)||re.question||"",I=(U==null?void 0:U.title)||re.title||"",ce=my(b==="section"?I:V,b,K),ze=gy({...re,...U,id:ce});if(!A)return{byId:{...R.byId,[ce]:ze},order:ob(R.order,ce,$)};const Oe=R.byId[A];if(!Oe||!Array.isArray(Oe.fields))return R;const ht=ob(Oe.fields,ze,$);return{byId:{...R.byId,[A]:{...Oe,fields:ht}}}}),updateField:(b,C,R={})=>v(M=>{const{sectionId:g,onIdChange:A}=R;return Xu(M,b,g,$=>{const re=typeof C=="function"?C($):C;if(!re)return null;const{fieldType:K,id:V,question:I,title:ce,...ze}={...$,...re};return{fieldType:K,id:V,...K==="section"?{title:ce}:{question:I},...ze}},{onIdChange:A,forbidCollision:!0})||M}),deleteField:(b,C={})=>v(R=>{const{sectionId:M}=C;if(!M){if(!R.byId[b])return R;const{[b]:U,...$}=R.byId;return{byId:$,order:R.order.filter(re=>re!==b)}}const g=R.byId[M];if(!g||!Array.isArray(g.fields))return R;const A=g.fields.filter(U=>U.id!==b);return A.length===g.fields.length?R:{byId:{...R.byId,[M]:{...g,fields:A}}}}),addOption:(b,C="",R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=Array.isArray(U.options)?U.options:[],re=new Set($.map(I=>I.id)),K=yy(C,re,b),V=[...$,{id:K,value:C}];return{...U,options:V}})||M}),updateOption:(b,C,R,M={})=>v(g=>{const{sectionId:A}=M;return Xu(g,b,A,$=>{const re=Array.isArray($.options)?$.options:[];let K=!1;const V=re.map(I=>I.id!==C||I.value===R?I:(K=!0,{id:I.id,value:R}));return K?{...$,options:V}:null})||g}),updateOptionAnswer:(b,C,R,M={})=>v(g=>{const{sectionId:A}=M;return Xu(g,b,A,$=>{const re=Array.isArray($.options)?$.options:[];let K=!1;const V=re.map(I=>I.id!==C||I.answer===R?I:(K=!0,{...I,answer:R}));return K?{...$,options:V}:null})||g}),deleteOption:(b,C,R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=Array.isArray(U.options)?U.options:[],re=$.filter(V=>V.id!==C);if(re.length===$.length)return null;const K={...U,options:re};if(Array.isArray(U.selected)){const V=U.selected.filter(I=>I!==C);V.length!==U.selected.length&&(K.selected=V)}else U.selected===C&&(K.selected="");return K})||M}),selectSingle:(b,C,R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=C??"";return U.selected===$?null:{...U,selected:$}})||M}),toggleMulti:(b,C,R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=Array.isArray(U.selected)?U.selected:[],re=$.includes(C),K=re?$.filter(V=>V!==C):[...$,C];return K.length===$.length&&re?null:{...U,selected:K}})||M})})),EE=v=>{const S=Zr(C=>C.order),b=Zr(C=>C.byId);return tt.useMemo(()=>{const C=S.map(M=>b[M]),R=[];return C.forEach(M=>{R.push(M),(M==null?void 0:M.fieldType)==="section"&&Array.isArray(M.fields)&&R.push(...M.fields)}),v?{fields:C.filter(M=>ib(M,R)),allFlat:R}:{fields:C,allFlat:R}},[S,b,v])},Un=eb((v,S)=>({isPreview:!1,setPreview:b=>v({isPreview:!!b}),togglePreview:()=>v(b=>({isPreview:!b.isPreview})),isEditModalOpen:!1,setEditModalOpen:b=>v(C=>({isEditModalOpen:typeof b=="function"?!!b(C.isEditModalOpen):!!b})),panelResetKey:0,selectedFieldId:null,setSelectField:b=>v(C=>{const R=b??null;return C.selectedFieldId===R?{}:{selectedFieldId:R,panelResetKey:C.panelResetKey+1}}),clearSelectedField:()=>v({selectedFieldId:null}),renameSelectedFieldId:b=>v({selectedFieldId:b}),selectedChildId:{parentId:null,childId:null},setSelectedChildId:(b,C)=>v(R=>{const M=b??null,g=C??null;return R.selectedChildId.parentId===M&&R.selectedChildId.childId===g?{}:{selectedChildId:{parentId:M,childId:g}}}),clearSelectedChildId:()=>v(b=>b.selectedChildId.parentId===null&&b.selectedChildId.childId===null?{}:{selectedChildId:{parentId:null,childId:null}}),renameSelectedChildParentId:b=>v(C=>({selectedChildId:{...C.selectedChildId,parentId:b??null}})),renameSelectedChildId:b=>v(C=>({selectedChildId:{...C.selectedChildId,childId:b??null}})),conversionReport:null,setConversionReport:b=>v({conversionReport:b}),clearConversionReport:()=>v({conversionReport:null}),hideUnsupportedFields:!1,setHideUnsupportedFields:b=>v({hideUnsupportedFields:!!b})})),CE=(v,S)=>{const b=Zr(V=>V.addField),C=Zr(V=>V.updateField),R=Zr(V=>V.deleteField),M=Zr(V=>V.addOption),g=Zr(V=>V.updateOption),A=Zr(V=>V.updateOptionAnswer),U=Zr(V=>V.deleteOption),$=Zr(V=>V.selectSingle),re=Zr(V=>V.toggleMulti),K=tt.useCallback((V,I)=>{var ce,ze;const Oe=Un.getState();Oe.selectedFieldId===I&&((ce=Oe.renameSelectedFieldId)==null||ce.call(Oe,V)),(ze=Oe.renameSectionIdInHighlight)==null||ze.call(Oe,I,V)},[]);return tt.useMemo(()=>({field:{add:(V,I,ce)=>b(V,{sectionId:S,initialPatch:I,index:ce}),update:(V,I)=>C(v,{[V]:I},{sectionId:S,onIdChange:K}),patch:V=>C(v,V,{sectionId:S,onIdChange:K}),renameId:V=>C(v,{id:V},{sectionId:S,onIdChange:K}),remove:()=>R(v,{sectionId:S})},option:{add:(V="")=>M(v,V,{sectionId:S}),update:(V,I)=>g(v,V,I,{sectionId:S}),updateAnswer:(V,I)=>A(v,V,I,{sectionId:S}),remove:V=>U(v,V,{sectionId:S})},selection:{single:V=>$(v,V,{sectionId:S}),multiToggle:V=>re(v,V,{sectionId:S})},section:{addChild:(V,I,ce)=>b(V,{sectionId:v,initialPatch:I,index:ce})}}),[v,S,b,C,R,M,g,A,U,$,re,K])},bv=()=>{const v=Un(ve=>ve.isPreview),S=Un(ve=>ve.panelResetKey),b=Un(ve=>ve.selectedFieldId),C=Un(ve=>ve.isEditModalOpen),R=Un(ve=>ve.conversionReport),M=Un(ve=>ve.setPreview),g=Un(ve=>ve.togglePreview),A=Un(ve=>ve.setSelectField),U=Un(ve=>ve.clearSelectedField),$=Un(ve=>ve.renameSelectedFieldId),re=Un(ve=>ve.setEditModalOpen),K=Un(ve=>ve.setConversionReport),V=Un(ve=>ve.clearConversionReport),I=Un(ve=>ve.setHideUnsupportedFields),ce=Un(ve=>ve.selectedChildId),ze=Un(ve=>ve.setSelectedChildId),Oe=Un(ve=>ve.clearSelectedChildId),ht=Un(ve=>ve.renameSelectedChildParentId),we=Un(ve=>ve.renameSelectedChildId),$e=tt.useCallback(()=>re(!0),[re]),dt=tt.useCallback(()=>re(!1),[re]),Ne=tt.useCallback(()=>re(ve=>!ve),[re]);return tt.useMemo(()=>({state:{isPreview:v,isEditModalOpen:C,panelResetKey:S},isPreview:v,preview:{set:M,toggle:g},modal:{set:re,open:$e,close:dt,toggle:Ne},selectedFieldId:{value:b,set:A,clear:U,rename:$},selectedChildId:{ChildId:(ce==null?void 0:ce.childId)??null,ParentId:(ce==null?void 0:ce.parentId)??null,BothId:ce||{parentId:null,childId:null},set:ze,clear:Oe,renameParentId:ht,renameChildId:we},conversionReport:R,setConversionReport:K,clearConversionReport:V,setHideUnsupportedFields:I}),[v,C,S,M,g,b,A,U,$,re,$e,dt,Ne,ce,ze,Oe,ht,we,R,K,V,I])};function Xo(v,S){var b;const C=bv(),R=CE(v.id,S),M=((b=xv[v.fieldType])==null?void 0:b.label)??"Field",g=!!S,A=C.selectedFieldId.value===v.id,U=tt.useCallback(K=>{var V;C.state.isPreview||((V=K==null?void 0:K.stopPropagation)==null||V.call(K),C.selectedFieldId.value!==v.id&&C.selectedFieldId.set(v.id))},[C,v.id]),$=tt.useCallback(()=>{R.field.remove(),A&&C.selectedFieldId.clear()},[R,A,C]),re=["rounded-lg bg-white",C.state.isPreview?"":"border",!g&&C.state.isPreview?"border":"",v.fieldType==="section"&&C.state.isPreview?"p-0 border":"p-4",A?"border-blue-300 border-2 border-dashed":"border-gray-200"].join(" ");return{field:v,sectionId:S,label:M,insideSection:g,isPreview:C.state.isPreview,selected:A,isEditModalOpen:C.state.isEditModalOpen,onRowClick:U,toggleEdit:C.modal.toggle,remove:$,api:R,wrapperClass:re}}const kE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("input",{type:"text",value:g.answer||"",onChange:A=>C.field.update("answer",A.target.value),placeholder:"Type your answer",className:"px-4 py-2 w-full border border-black/10 shadow-2xs rounded"})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),_.jsx("input",{type:"text",value:g.answer||"",placeholder:"Type your answer",className:"px-4 py-2 my-1.5 w-full border border-black/10 shadow-2xs rounded",disabled:!0})]})})}),RE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("textarea",{value:g.answer||"",onChange:A=>C.field.update("answer",A.target.value),placeholder:"Type your answer",className:"px-3 py-2 w-full border border-black/10 shadow-2xs rounded min-h-24 max-h-60 resize-y",rows:4})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),ange:!0,name:!0,placeholder:"Enter question"}),_.jsx("textarea",{value:g.answer||"",placeholder:"Type your answer",className:"px-3 py-2 my-1.5 w-full border border-black/10 shadow-2xs rounded min-h-24 max-h-56 resize-y",rows:4,disabled:!0})]})})}),TE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{className:"space-y-2",children:(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center border border-black/10 shadow-2xs rounded overflow-hidden",children:[_.jsx("label",{className:"px-4 py-2 text-sm text-gray-500 bg-gray-50 whitespace-nowrap border-r border-black/10",children:A.value}),_.jsx("input",{type:"text",value:A.answer||"",onChange:U=>C.option.updateAnswer(A.id,U.target.value),placeholder:"",className:"flex-1 px-4 py-2 border-0 outline-none focus:ring-0"})]},A.id))})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-4 my-1.5 shadow border border-black/10 rounded-lg",children:[_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Field label",className:"w-full py-2"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Field"]})]})})}),_E=tt.memo(function({id:v,name:S,value:b,checked:C,onSelect:R,onUnselect:M,className:g="",...A}){const U=tt.useRef(C);return tt.useEffect(()=>{U.current=C},[C]),_.jsx("input",{id:v,type:"radio",name:S,value:b,className:g,checked:C,onClick:()=>{U.current?M==null||M(b):R==null||R(b)},onChange:()=>{},...A})}),DE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{children:(g.options||[]).map(A=>{const U=`${g.id}-${A.id}`,$=g.selected===A.id;return _.jsxs("label",{htmlFor:U,className:"flex items-center px-3 py-1 my-2 cursor-pointer",children:[_.jsx(_E,{id:U,name:`question-${g.id}`,value:A.id,checked:$,onSelect:()=>C.selection.single(A.id),onUnselect:()=>C.field.update("selected",null),className:"mr-2 h-9 w-9 flex-shrink-0 cursor-pointer"}),A.value]},A.id)})})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-4 my-1.5 shadow border border-black/10 rounded-lg",children:[_.jsx("input",{type:"radio",disabled:!0,className:"mr-2"}),_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Option text",className:"w-full py-2"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Option"]})]})})}),OE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{children:(g.options||[]).map(A=>_.jsxs("label",{className:"flex items-center px-3 py-1 my-2",children:[_.jsx("input",{type:"checkbox",className:"mr-2 w-9 h-9",checked:Array.isArray(g.selected)&&g.selected.includes(A.id),onChange:()=>C.selection.multiToggle(A.id)}),A.value]},A.id))})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-3 shadow my-1.5 border border-black/10 rounded-lg h-10",children:[_.jsx("input",{type:"checkbox",disabled:!0,className:"mr-2"}),_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Option text",className:"w-full"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Option"]})]})})}),NE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{children:_.jsxs("select",{className:"w-full px-4 shadow border border-black/10 rounded-lg h-10",value:g.selected||"",onChange:A=>C.selection.single(A.target.value),children:[_.jsx("option",{value:"",children:"Select an option"}),(g.options||[]).map(A=>_.jsx("option",{value:A.id,children:A.value},A.id))]})})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),_.jsx("div",{className:"mt-2",children:_.jsxs("select",{className:"w-full px-4 shadow border border-black/10 rounded-lg h-10",disabled:!0,children:[_.jsx("option",{value:"",children:"Select an option"}),(g.options||[]).map(A=>_.jsx("option",{value:A.id,children:A.value},A.id))]})}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-3 shadow my-1.5 border border-black/10 rounded-lg h-10",children:[_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Option text",className:"w-full"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Option"]})]})})}),ME=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>{var A;const U=((A=g.options)==null?void 0:A.length)===2?g.options:[{id:"yes",value:"Yes"},{id:"no",value:"No"}];return R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{className:"flex gap-2",children:U.map($=>_.jsxs("label",{className:`flex-1 flex items-center justify-center px-4 py-2 border rounded-lg cursor-pointer ${g.selected===$.id?"bg-[#0076a8] text-white border-[#0076a8]":"border-black/10 hover:bg-gray-50"}`,onClick:re=>{re.preventDefault(),g.selected===$.id?C.field.update("selected",null):C.selection.single($.id)},children:[_.jsx("input",{type:"radio",name:g.fieldId,checked:g.selected===$.id,onChange:()=>{},className:"sr-only"}),_.jsx("span",{children:$.value})]},$.id))})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:$=>C.field.update("question",$.target.value),placeholder:"Enter question"}),U.map(($,re)=>_.jsxs("div",{className:"flex items-center px-4 my-1.5 shadow border border-black/10 rounded-lg",children:[_.jsx("input",{type:"radio",name:`${g.fieldId}-edit`,disabled:!0,className:"mr-2"}),_.jsx("input",{type:"text",value:$.value,onChange:K=>C.option.update(re,"value",K.target.value),placeholder:`Option ${re+1}`,className:"w-full py-2"})]},$.id))]})}})});function LE({field:v}){const[S,b]=Gu.useState(!1),C=v.unsupportedType||"unknown",R=v.unsupportedData||v._sourceData||{};return _.jsxs("div",{className:"border-2 border-dashed border-orange-500 rounded-lg p-4 bg-orange-50 mb-4",children:[_.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[_.jsx("span",{className:"text-xl",children:"⚠️"}),_.jsxs("div",{className:"flex-1",children:[_.jsxs("strong",{className:"text-orange-700",children:["Unsupported Field Type: ",C]}),_.jsx("div",{className:"text-sm text-gray-600 mt-1",children:v.question||R.title||R.name||"No title"})]})]}),_.jsxs("div",{className:"mt-3 p-3 bg-white border border-gray-300 rounded text-sm",children:[_.jsx("div",{className:"text-xs text-gray-500 mb-2 font-semibold",children:"Original Data Preview:"}),_.jsxs("div",{className:"space-y-1 text-gray-700",children:[Object.entries(R).slice(0,5).map(([M,g])=>typeof g=="object"&&g!==null?_.jsxs("div",{className:"truncate",children:[_.jsxs("span",{className:"font-mono text-xs text-blue-600",children:[M,":"]})," ",_.jsx("span",{className:"text-gray-500 italic",children:Array.isArray(g)?"[Array]":"{Object}"})]},M):_.jsxs("div",{className:"truncate",children:[_.jsxs("span",{className:"font-mono text-xs text-blue-600",children:[M,":"]})," ",_.jsx("span",{className:"text-gray-800",children:String(g)})]},M)),Object.keys(R).length>5&&_.jsxs("div",{className:"text-xs text-gray-400 italic",children:["... and ",Object.keys(R).length-5," more properties"]})]})]}),_.jsxs("button",{type:"button",onClick:()=>b(!S),className:"mt-3 px-3 py-1.5 bg-orange-500 text-white rounded hover:bg-orange-600 text-sm transition-colors",children:[S?"▼ Hide":"▶ Show"," Full Data"]}),S&&_.jsxs("div",{className:"mt-3",children:[_.jsx("div",{className:"text-xs text-gray-600 mb-2 font-semibold",children:"Full SurveyJS data for manual conversion:"}),_.jsx("pre",{className:"bg-gray-100 p-3 rounded text-xs overflow-auto max-h-[300px] border border-gray-300",children:JSON.stringify(R,null,2)})]}),_.jsx("div",{className:"mt-3 text-xs text-gray-600 italic",children:"💡 This field type is not yet supported. Manual implementation required."})]})}const xv={section:{label:"Section Field",componentKey:"section",defaultProps:{fieldType:"section",title:"New section",fields:[]}},text:{label:"Text Field",componentKey:"text",defaultProps:{fieldType:"text",question:"",answer:""}},longtext:{label:"Long Text Field",componentKey:"longtext",defaultProps:{fieldType:"longtext",question:"",answer:""}},multitext:{label:"Multi Text Field",componentKey:"multitext",defaultProps:{fieldType:"multitext",question:"",options:[{value:"Field 1"},{value:"Field 2"},{value:"Field 3"}]}},radio:{label:"Radio Field",componentKey:"radio",defaultProps:{fieldType:"radio",question:"",options:[{value:"Option 1"},{value:"Option 2"},{value:"Option 3"}],selected:null}},check:{label:"Check Field",componentKey:"check",defaultProps:{fieldType:"check",question:"",options:[{value:"Option 1"},{value:"Option 2"},{value:"Option 3"}],selected:[]}},boolean:{label:"Boolean Field",componentKey:"boolean",defaultProps:{fieldType:"boolean",question:"",options:[{id:"yes",value:"Yes"},{id:"no",value:"No"}],selected:null}},dropdown:{label:"Dropdown Field",componentKey:"dropdown",defaultProps:{fieldType:"dropdown",question:"",options:[{value:"Option 1"},{value:"Option 2"},{value:"Option 3"}],selected:null}},unsupported:{label:"Unsupported Field",componentKey:"unsupported",defaultProps:{fieldType:"unsupported",question:"Unsupported field type",unsupportedType:"unknown",unsupportedData:{}}}},wy={text:kE,longtext:RE,multitext:TE,radio:DE,check:OE,boolean:ME,dropdown:NE,unsupported:LE};function jE(v,S){wy[v]||(wy[v]=S)}function by(v){return wy[v]||null}const AE=tt.memo(function({field:v}){const S=Xo(v),b=bv(),C=Un(I=>I.hideUnsupportedFields),R=b.selectedChildId.ParentId,M=b.selectedChildId.ChildId,g=R===v.id?M:null,A=Gu.useRef({}),U=Zr(I=>I.byId),$=Gu.useMemo(()=>{const I=Object.values(U),ce=[];return I.forEach(ze=>{ze&&(ce.push(ze),ze.fieldType==="section"&&Array.isArray(ze.fields)&&ce.push(...ze.fields))}),ce},[U]);Gu.useEffect(()=>{var I;if(S.isPreview||!g)return;const ce=A.current[g];(I=ce==null?void 0:ce.scrollIntoView)==null||I.call(ce,{behavior:"smooth",block:"nearest"})},[g,S.isPreview]);const re=I=>C&&I.fieldType==="unsupported",K=(I,ce)=>{const ze=by(I.fieldType);return!ze||re(I)||!ib(I,$)?null:_.jsx("div",{ref:Oe=>Oe&&(A.current[I.id]=Oe),children:_.jsx(ze,{field:I,sectionId:ce})},I.id)},V=(I,ce)=>{const ze=by(I.fieldType);if(!ze||re(I))return null;const Oe=g===I.id;return _.jsx("div",{ref:ht=>ht&&(A.current[I.id]=ht),className:["rounded-lg mb-3",Oe?"border-2 border-blue-400 border-dashed":"border border-transparent"].join(" "),children:_.jsx(ze,{field:I,sectionId:ce})},I.id)};return _.jsx(Ko,{ctrl:S,children:({api:I,isPreview:ce,insideSection:ze,field:Oe})=>{const ht=Array.isArray(Oe.fields)?Oe.fields:[];return ce?_.jsxs("section",{className:ze?"border-b border-gray-200":"border-0",children:[_.jsx("div",{className:"bg-[#0076a8] text-white text-xl px-4 py-2 rounded-t-lg",children:Oe.title||"Section"}),ht.map(we=>K(we,Oe.id))]}):_.jsxs("div",{children:[_.jsx("div",{className:"flex justify-between items-center mb-3 gap-2",children:_.jsx("div",{className:"flex-1",children:_.jsx("input",{type:"text",className:"w-full px-3 py-2 border border-gray-200 rounded-md",value:Oe.title||"",onChange:we=>I.field.update("title",we.target.value),placeholder:"Section title (e.g., Data Consent)"})})}),_.jsx("div",{children:ht.map(we=>V(we,Oe.id))}),_.jsxs("div",{className:"mb-3",children:[_.jsx("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"Add a field"}),_.jsx("div",{className:"flex flex-wrap gap-2",children:Object.keys(xv).filter(we=>we!=="section").map(we=>_.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-2 text-sm border border-gray-300 rounded-md hover:bg-gray-50",onClick:()=>{var $e,dt,Ne;return($e=I.section)!=null&&$e.addChild?I.section.addChild(we):(Ne=(dt=I.field).add)==null?void 0:Ne.call(dt,we,void 0,void 0)},children:[_.jsx(hE,{className:"h-4 w-4"}),"Add ",xv[we].label]},we))})]})]})}})});jE("section",AE);function zE(v,S="inhouse"){if(!v)return{fields:[],conversionReport:null};switch(S){case"surveyjs":return UE(v);case"inhouse":return{fields:Array.isArray(v)?v:v.fields&&Array.isArray(v.fields)?v.fields:[],conversionReport:null};default:throw new Error(`Unsupported schema type: ${S}`)}}function UE(v){if(!v)return{fields:[],conversionReport:null};const S={sourceType:"surveyjs",timestamp:new Date().toISOString(),surveyMetadata:PE(v),totalElements:0,convertedFields:0,droppedFields:[],warnings:[]};let b=[];Array.isArray(v.elements)?b=v.elements:Array.isArray(v.pages)&&(b=v.pages.flatMap(g=>g.elements||[]),v.pages.length>1&&S.warnings.push({type:"page_structure_lost",message:`Multi-page survey with ${v.pages.length} pages flattened into single form`,impact:"high"})),S.totalElements=b.length;const C=new Set,R=g=>{g.forEach(A=>{A.name&&C.add(A.name),A.elements&&Array.isArray(A.elements)&&R(A.elements)})};R(b);const M=b.map(g=>{const A=ub(g,C);return A?(S.convertedFields++,A._conversionWarnings&&A._conversionWarnings.length>0&&S.warnings.push(...A._conversionWarnings.map(U=>({...U,fieldId:A.id,fieldName:g.name})))):S.droppedFields.push({name:g.name||"unnamed",type:g.type||"unknown",title:g.title||""}),A}).filter(Boolean);return $E(M),{fields:M,conversionReport:S}}function ub(v,S=new Set){if(!v||!v.type)return null;const b=FE(v.type),C=[],R={id:v.name||`field-${Date.now()}-${Math.random().toString(36).substring(2,11)}`,fieldType:b||"unsupported",question:v.title||v.name||""};if(!b){R.fieldType="unsupported",R.unsupportedType=v.type;const M={...v};return M.elements&&Array.isArray(M.elements)&&(M.elements=M.elements.map(g=>g.name).filter(Boolean)),R.unsupportedData=M,C.push({type:"unsupported_field_type",property:"type",value:v.type,message:`Field type "${v.type}" is not supported. Displayed as placeholder.`,impact:"high"}),R._sourceData=v,R._conversionWarnings=C,R}switch(b){case"input":R.answer=v.defaultValue||"",HE(v,C);break;case"radio":case"dropdown":R.options=cb(v.choices),R.selected=v.defaultValue||null,fb(v,C);break;case"check":R.options=cb(v.choices),R.selected=Array.isArray(v.defaultValue)?v.defaultValue:[],fb(v,C);break;case"section":R.title=v.title||v.name||"Section",R.fields=Array.isArray(v.elements)?v.elements.map(M=>ub(M,S)).filter(Boolean):[];break}if(v.type==="boolean"&&R.fieldType==="radio"&&(R.options=[{id:"yes",value:v.labelTrue||"Yes"},{id:"no",value:v.labelFalse||"No"}],v.defaultValue===!0?R.selected="yes":v.defaultValue===!1?R.selected="no":R.selected=null),v.isRequired&&(R.required=!0),v.visibleIf){const M=db(v.visibleIf,S);M&&(R.enableWhen=M,sb(C,"conditional_logic_lost","visibleIf"))}if(v.enableIf&&!R.enableWhen){const M=db(v.enableIf,S);M&&(R.enableWhen=M,sb(C,"conditional_logic_lost","enableIf"))}return IE(v,C),R.fieldType==="section"&&v.elements&&Array.isArray(v.elements)?R._sourceData={...v,elements:v.elements.map(M=>M.name).filter(Boolean)}:R._sourceData=v,R._conversionWarnings=C,R}function sb(v,S,b){const C=v.findIndex(R=>R.type===S&&R.property===b);C!==-1&&v.splice(C,1)}function FE(v){return{text:"text",comment:"text",multipletext:"text",radiogroup:"radio",dropdown:"dropdown",boolean:"radio",checkbox:"check",panel:"section",paneldynamic:"section"}[v]||null}function cb(v){return Array.isArray(v)?v.map((S,b)=>typeof S=="string"?{id:`opt-${b}`,value:S}:{id:S.value||`opt-${b}`,value:S.text||S.value||""}):[]}function PE(v){const S={};return["title","description","logo","logoPosition","showProgressBar","progressBarType","showQuestionNumbers","completedHtml","loadingHtml","locale","questionsOnPageMode","calculatedValues","triggers"].forEach(b=>{v[b]!==void 0&&(S[b]=v[b])}),S}function HE(v,S){v.inputType&&v.inputType!=="text"&&S.push({type:"input_type_lost",property:"inputType",value:v.inputType,message:`Input type "${v.inputType}" not supported (date, tel, email, number will render as text)`,impact:"medium"}),v.placeHolder&&S.push({type:"placeholder_lost",property:"placeHolder",value:v.placeHolder,message:"Placeholder text not supported",impact:"low"}),v.maxLength&&S.push({type:"validation_lost",property:"maxLength",value:v.maxLength,message:"Max length validation not supported",impact:"medium"}),(v.min!==void 0||v.max!==void 0)&&S.push({type:"validation_lost",property:"min/max",value:`${v.min||""} - ${v.max||""}`,message:"Numeric min/max constraints not supported",impact:"high"})}function fb(v,S){v.hasOther&&S.push({type:"other_option_lost",property:"hasOther",value:v.otherText||"Other",message:'"Other" option with text input not supported',impact:"medium"}),(v.labelTrue||v.labelFalse)&&S.push({type:"boolean_labels_lost",property:"labelTrue/labelFalse",value:`${v.labelTrue||"Yes"} / ${v.labelFalse||"No"}`,message:"Custom boolean labels not supported (using Yes/No)",impact:"low"}),v.choicesOrder&&v.choicesOrder!=="none"&&S.push({type:"choice_order_lost",property:"choicesOrder",value:v.choicesOrder,message:"Choice ordering not supported",impact:"low"})}function IE(v,S){v.visibleIf&&S.push({type:"conditional_logic_lost",property:"visibleIf",value:v.visibleIf,message:"Conditional visibility logic not supported (field always visible)",impact:"high"}),v.enableIf&&S.push({type:"conditional_logic_lost",property:"enableIf",value:v.enableIf,message:"Conditional enable/disable logic not supported",impact:"high"}),v.requiredIf&&S.push({type:"conditional_logic_lost",property:"requiredIf",value:v.requiredIf,message:"Conditional required logic not supported",impact:"high"}),v.validators&&v.validators.length>0&&S.push({type:"validation_lost",property:"validators",value:v.validators.map(b=>b.type).join(", "),message:`Validators not supported: ${v.validators.map(b=>b.type).join(", ")}`,impact:"high"}),v.readOnly&&S.push({type:"readonly_lost",property:"readOnly",value:!0,message:"Read-only field not supported",impact:"medium"})}function db(v,S=new Set){if(!v||typeof v!="string")return null;try{let b=v.trim(),C="AND";const R=/ or /i.test(b),M=/ and /i.test(b);if(R&&M)return console.warn(`[schemaAdapter] Mixed AND/OR logic not supported in: ${v}`),null;R&&(C="OR");const g=b.split(R?/ or /i:/ and /i),A=[];for(const U of g){const $=VE(U.trim());if($){if(S.size>0&&!S.has($.targetId)){console.warn(`[schemaAdapter] Skipping condition - field "${$.targetId}" not found (may be calculated value or metadata): ${U}`);continue}A.push($)}else console.warn(`[schemaAdapter] Unable to parse condition: ${U}`)}return A.length===0?null:{logic:A.length===1?"AND":C,conditions:A}}catch(b){return console.warn(`[schemaAdapter] Error converting visibleIf: ${v}`,b),null}}function VE(v){const S=C=>v.match(C);let b=S(/\{(\w+)\}\s*=\s*'([^']+)'/)||S(/\{(\w+)\}\s*=\s*"([^"]+)"/)||S(/\{(\w+)\}\s*=\s*([\w.-]+)/);if(b){const C=b[2],R=C==="true"?"yes":C==="false"?"no":C;return{targetId:b[1],operator:"equals",value:R}}return b=S(/\{(\w+)\}\s*(?:<>|!=)\s*'([^']+)'/)||S(/\{(\w+)\}\s*(?:<>|!=)\s*"([^"]+)"/)||S(/\{(\w+)\}\s*(?:<>|!=)\s*([\w.-]+)/),b?(console.warn(`[schemaAdapter] "not equal" operator not yet supported: ${v}`),null):(b=S(/\{(\w+)\}\s+contains\s+'([^']+)'/)||S(/\{(\w+)\}\s+contains\s+"([^"]+)"/)||S(/\{(\w+)\}\s+contains\s+([\w.-]+)/),b?{targetId:b[1],operator:"contains",value:b[2]}:(b=S(/\{(\w+)\}\s+empty/i),b?{targetId:b[1],operator:"equals",value:""}:(b=S(/\{(\w+)\}\s+notempty/i),b&&console.warn(`[schemaAdapter] "notempty" operator not yet supported: ${v}`),null)))}function BE(v){const S=new Map,b=C=>{C.forEach(R=>{S.set(R.id,R),R.fields&&Array.isArray(R.fields)&&b(R.fields)})};return b(v),S}function $E(v){const S=BE(v),b=C=>{C.enableWhen&&C.enableWhen.conditions&&C.enableWhen.conditions.forEach(R=>{const M=S.get(R.targetId);if(M&&M.options&&Array.isArray(M.options)){const g=M.options.find(A=>A.value===R.value);g?R.value=g.id:console.warn(`[schemaAdapter] No matching option found for value "${R.value}" in field "${R.targetId}"`)}}),C.fields&&Array.isArray(C.fields)&&C.fields.forEach(b)};v.forEach(b)}function YE(v,S="inhouse",b=!1){const C=tt.useRef(!1),R=bv();tt.useEffect(()=>{if(C.current||!v)return;const M=zE(v,S),g=M.fields||M;M.conversionReport&&R.setConversionReport(M.conversionReport),Zr.getState().replaceAll(g),R.preview.set(!0),C.current=!0},[v,S,R]),tt.useEffect(()=>{R.setHideUnsupportedFields(b)},[b,R])}const WE=tt.memo(function({id:S}){const b=Zr(tt.useCallback(R=>R.byId[S],[S]));if(!b)return null;const C=by(b.fieldType);return C?Ku.jsx("div",{className:"mb-1.5","data-field-type":b.fieldType,"data-field-id":b.id,children:Ku.jsx(C,{field:b})}):null});function QE(){const v=bv(),{fields:S}=EE(v.state.isPreview),b=Un(R=>R.hideUnsupportedFields),C=Gu.useMemo(()=>(b?S.filter(M=>M.fieldType!=="unsupported"):S).map(M=>M.id),[S,b]);return Ku.jsx("div",{children:C.map(R=>Ku.jsx(WE,{id:R},R))})}function qE({fields:v,schemaType:S="inhouse",onChange:b,className:C="",fullHeight:R=!1,hideUnsupportedFields:M=!1}){YE(v,S,M),tt.useEffect(()=>b?Zr.subscribe(U=>{const $=U.order.map(re=>U.byId[re]);b($)}):void 0,[b]);const g=["qb-render-root","bg-gray-100","font-titillium",R?"min-h-screen":"",C].filter(Boolean).join(" ");return Ku.jsx("div",{className:g,children:Ku.jsx("div",{className:"max-w-4xl mx-auto px-2 pb-8 pt-4",children:Ku.jsx(QE,{})})})}function pb(v){switch(v.fieldType){case"text":case"longtext":return v.answer?[{valueString:String(v.answer)}]:[];case"radio":return v.selected?[{valueString:xy(v,v.selected)}]:[];case"check":return(v.selected||[]).map(S=>({valueString:xy(v,S)}));case"selection":return v.selected?[{valueString:xy(v,v.selected)}]:[];default:return[]}}function xy(v,S){const b=(v.options||[]).find(C=>C.id===S||C.value===S);return b?b.value:""}function GE(v,S,b){const C=[];return(v||[]).forEach(R=>{if(R.fieldType==="section"&&Array.isArray(R.fields)){R.fields.forEach(M=>{M&&C.push({linkId:M.id,text:M.question||M.title||"",answer:pb(M)})});return}R.fieldType!=="section"&&C.push({linkId:R.id,text:R.question||R.title||"",answer:pb(R)})}),{resourceType:"QuestionnaireResponse",questionnaire:S,status:"in-progress",subject:b?{reference:`Patient/${b}`}:void 0,item:C}}class vb extends HTMLElement{static get observedAttributes(){return["fields","schema-type","full-height","hide-unsupported-fields"]}constructor(){super(),this._root=null,this._fields=[],this._schemaType="inhouse",this._hideUnsupportedFields=!1,this._onChange=null}connectedCallback(){this._mount()}disconnectedCallback(){this._unmount()}attributeChangedCallback(S,b,C){b!==C&&this._render()}set fields(S){this._fields=S,this._render()}get fields(){return this._fields}set onChange(S){this._onChange=S,this._render()}get onChange(){return this._onChange}set schemaType(S){this._schemaType=S||"inhouse",this._render()}get schemaType(){return this._schemaType}set hideUnsupportedFields(S){this._hideUnsupportedFields=!!S,this._render()}get hideUnsupportedFields(){return this._hideUnsupportedFields}getQuestionnaireResponse(S="questionnaire-1",b){const C=Zr.getState(),R=C.order.map(M=>C.byId[M]);return GE(R,S,b)}_mount(){this._root||(this._root=aE.createRoot(this)),this._render()}_unmount(){this._root&&(this._root.unmount(),this._root=null)}_render(){if(!this._root)return;let S=this._fields;const b=this.getAttribute("fields");if(b&&!this._fields.length)try{S=JSON.parse(b)}catch{S=[]}const C=this.getAttribute("schema-type")||this._schemaType||"inhouse",R=this.hasAttribute("full-height"),M=this.hasAttribute("hide-unsupported-fields")||this._hideUnsupportedFields,g=this.getAttribute("class")||"";this._root.render(tt.createElement(qE,{fields:S,schemaType:C,hideUnsupportedFields:M,onChange:this._onChange,className:g,fullHeight:R}))}}customElements.get("questionnaire-renderer")||customElements.define("questionnaire-renderer",vb),pc.QuestionnaireRendererElement=vb,Object.defineProperty(pc,Symbol.toStringTag,{value:"Module"})}));
|
|
2226
|
+
<%s key={someKey} {...props} />`,ct,Zn,Sa,Zn),ur[Zn+ct]=!0}}return m===C?yr(st):Wi(st),st}}function Ua(m,O,G){return In(m,O,G,!0)}function xa(m,O,G){return In(m,O,G,!1)}var Fa=xa,Pa=Ua;yv.Fragment=C,yv.jsx=Fa,yv.jsxs=Pa})()),yv}var rb;function pE(){return rb||(rb=1,process.env.NODE_ENV==="production"?hy.exports=fE():hy.exports=dE()),hy.exports}var _=pE();const mc=(v,S)=>v.className===S.className,vE=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:_.jsx("path",{d:"M4 7h16M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3m-5 5l4 4m0-4l-4 4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2"})})),gv=tt.memo(({className:v=""})=>_.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",className:v,children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 7h16m-10 4v6m4-6v6M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3"})}));tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2m-8 0V9M9 9h6"})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8.56 3.69a9 9 0 0 0-2.92 1.95M3.69 8.56A9 9 0 0 0 3 12m.69 3.44a9 9 0 0 0 1.95 2.92m2.92 1.95A9 9 0 0 0 12 21m3.44-.69a9 9 0 0 0 2.92-1.95m1.95-2.92A9 9 0 0 0 21 12m-.69-3.44a9 9 0 0 0-1.95-2.92m-2.92-1.95A9 9 0 0 0 12 3"})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8.56 3.69a9 9 0 0 0-2.92 1.95M3.69 8.56A9 9 0 0 0 3 12m.69 3.44a9 9 0 0 0 1.95 2.92m2.92 1.95A9 9 0 0 0 12 21m3.44-.69a9 9 0 0 0 2.92-1.95m1.95-2.92A9 9 0 0 0 21 12m-.69-3.44a9 9 0 0 0-1.95-2.92m-2.92-1.95A9 9 0 0 0 12 3m-3 9l2 2l4-4"})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),_.jsx("path",{d:"m9 11l3 3l3-3"})]})}));const hE=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"currentColor",d:"m12 2l.324.001l.318.004l.616.017l.299.013l.579.034l.553.046c4.785.464 6.732 2.411 7.196 7.196l.046.553l.034.579q.008.147.013.299l.017.616L22 12l-.005.642l-.017.616l-.013.299l-.034.579l-.046.553c-.464 4.785-2.411 6.732-7.196 7.196l-.553.046l-.579.034q-.147.008-.299.013l-.616.017L12 22l-.642-.005l-.616-.017l-.299-.013l-.579-.034l-.553-.046c-4.785-.464-6.732-2.411-7.196-7.196l-.046-.553l-.034-.579l-.013-.299l-.017-.616Q2 12.327 2 12l.001-.324l.004-.318l.017-.616l.013-.299l.034-.579l.046-.553c.464-4.785 2.411-6.732 7.196-7.196l.553-.046l.579-.034q.147-.008.299-.013l.616-.017Q11.673 2 12 2m0 6a1 1 0 0 0-1 1v2H9l-.117.007A1 1 0 0 0 9 13h2v2l.007.117A1 1 0 0 0 13 15v-2h2l.117-.007A1 1 0 0 0 15 11h-2V9l-.007-.117A1 1 0 0 0 12 8"})})),wv=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16H6a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v1m-4 7h6m-3-3v6"})}));tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M10 8V6a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2v-2"}),_.jsx("path",{d:"M15 12H3l3-3m0 6l-3-3"})]})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0-4 0"}),_.jsx("path",{d:"M13.048 17.942A9 9 0 0 1 12 18q-5.4 0-9-6q3.6-6 9-6t9 6a18 18 0 0 1-1.362 1.975M22 22l-5-5m0 5l5-5"})]})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M10 12a2 2 0 1 0 4 0a2 2 0 0 0-4 0"}),_.jsx("path",{d:"M11.192 17.966Q6.33 17.546 3 12q3.6-6 9-6q4.989 0 8.442 5.122M18.42 15.61a2.1 2.1 0 0 1 2.97 2.97L18 22h-3v-3z"})]})})),tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsx("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M18 6L6 18M6 6l12 12"})}));const mE=tt.memo(({className:v=""})=>_.jsx("svg",{className:v,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",children:_.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",children:[_.jsx("path",{d:"M7 7H6a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-1"}),_.jsx("path",{d:"M20.385 6.585a2.1 2.1 0 0 0-2.97-2.97L9 12v3h3zM16 5l3 3"})]})}),mc);tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M6 9l6 6l6 -6"})]}),mc),tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),_.jsx("path",{d:"M7 11l5 5l5 -5"}),_.jsx("path",{d:"M12 4l0 12"})]})),tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2"}),_.jsx("path",{d:"M7 9l5 -5l5 5"}),_.jsx("path",{d:"M12 4l0 12"})]}),mc),tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M7 8l-4 4l4 4"}),_.jsx("path",{d:"M17 8l4 4l-4 4"}),_.jsx("path",{d:"M14 4l-4 16"})]}),mc);const yE=tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M12 10v-7l3 3"}),_.jsx("path",{d:"M9 6l3 -3"}),_.jsx("path",{d:"M12 14v7l3 -3"}),_.jsx("path",{d:"M9 18l3 3"}),_.jsx("path",{d:"M18 3h1a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-1"}),_.jsx("path",{d:"M6 3h-1a2 2 0 0 0 -2 2v14a2 2 0 0 0 2 2h1"})]}),mc),gE=tt.memo(({className:v=""})=>_.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:v,children:[_.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),_.jsx("path",{d:"M12 3v7l3 -3"}),_.jsx("path",{d:"M9 7l3 3"}),_.jsx("path",{d:"M12 21v-7l3 3"}),_.jsx("path",{d:"M9 17l3 -3"}),_.jsx("path",{d:"M18 9h1a2 2 0 0 1 2 2v2a2 2 0 0 1 -2 2h-1"}),_.jsx("path",{d:"M6 9h-1a2 2 0 0 0 -2 2v2a2 2 0 0 0 2 2h1"})]}),mc);function Ko({ctrl:v,children:S}){var b,C,R,M;const[g,A]=Gu.useState(!0),U=K=>{var V;K.stopPropagation(),v.selected||(V=v.onRowClick)==null||V.call(v,K),v.toggleEdit()},$=K=>{K.stopPropagation(),v.remove()},re=K=>{var V;v.insideSection||(V=v.onRowClick)==null||V.call(v,K)};return v.isPreview||v.insideSection?_.jsxs("div",{className:v.wrapperClass,onClick:v.insideSection?void 0:v.onRowClick,"data-field-id":(b=v.field)==null?void 0:b.id,"data-inside-section":v.insideSection?"true":"false","data-selected":v.selected?"true":"false","aria-selected":v.selected||void 0,tabIndex:-1,children:[v.isPreview?null:_.jsx("div",{children:v.insideSection?`${v.label}`:`(${v.label}) ${v.field.title}`}),typeof S=="function"?S({api:v.api,isPreview:v.isPreview,field:v.field,insideSection:v.insideSection,sectionId:v.sectionId,selected:v.selected}):S]}):_.jsxs("div",{className:v.wrapperClass+" group",onClick:re,"data-field-id":(C=v.field)==null?void 0:C.id,"data-inside-section":v.insideSection?"true":"false","data-selected":v.selected?"true":"false","aria-selected":v.selected||void 0,tabIndex:-1,children:[_.jsxs("div",{className:`flex justify-between items-center ${g?"pb-2.5":""}`,children:[_.jsx("div",{className:"text-left w-full select-none",children:v.insideSection?`${v.label}`:v.field.fieldType==="section"?`(${v.label}) ${v.field.title}`:`${v.label} ${v.field.question}`}),_.jsxs("div",{className:`flex items-center gap-2 ml-2 ${v.insideSection?"hidden":""}`,children:[_.jsx("button",{onClick:U,className:"block lg:hidden",title:"Edit","aria-label":"Edit field",children:_.jsx(mE,{className:"h-6 w-6"})}),_.jsx("button",{type:"button",onClick:K=>{K.stopPropagation(),A(V=>!V)},"aria-expanded":g,"aria-controls":`fw-body-${(R=v.field)==null?void 0:R.id}`,title:g?"Collapse":"Expand","aria-label":g?"Collapse field":"Expand field",className:"p-1",children:g?_.jsx(gE,{className:"h-5 w-5"}):_.jsx(yE,{className:"h-5 w-5"})}),_.jsx("button",{onClick:$,title:"Delete","aria-label":"Delete field",children:_.jsx(vE,{className:"h-6 w-6"})})]})]}),g&&_.jsx("div",{id:`fw-body-${(M=v.field)==null?void 0:M.id}`,children:typeof S=="function"?S({api:v.api,isPreview:v.isPreview,field:v.field,insideSection:v.insideSection,sectionId:v.sectionId,selected:v.selected}):S})]})}function my(v="",S="",b=new Set){const C=S||"field";if(!b.has(C))return C;let R=1,M=`${C}-${R}`;for(;b.has(M);)R++,M=`${C}-${R}`;return M}function yy(v="",S=new Set,b=""){const C=b?`${b}-option`:"option";if(!S.has(C))return C;let R=1,M=`${C}-${R}`;for(;S.has(M);)R++,M=`${C}-${R}`;return M}const wE=(v,S="")=>{if(!Array.isArray(v))return[];const b=new Set;return v.map(C=>{if(typeof C=="string"){const R=yy(C,b,S);return b.add(R),{id:R,value:C}}else{const R=C.id||yy(C.value,b,S);return b.add(R),{id:R,...C}}})},gy=v=>{const{fieldType:S,id:b,question:C,title:R,...M}=v;return{fieldType:S,id:b,...v.fieldType==="section"?{title:R}:{question:C},...M,...!["text","longtext"].includes(S)&&{options:wE(M.options||[],b)}}};function bE(v){switch(v==null?void 0:v.fieldType){case"text":case"longtext":return v.answer??"";case"radio":case"dropdown":return v.selected??null;case"check":return Array.isArray(v.selected)?v.selected:Array.isArray(v.options)?v.options.filter(S=>S==null?void 0:S.selected).map(S=>S.id??S.value):[];default:return null}}function ab(v){return v.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xE(v,S){const b=S==null?void 0:S[v==null?void 0:v.targetId];if(!b)return!1;const C=bE(b),R=v==null?void 0:v.value;switch(v==null?void 0:v.operator){case"equals":return Array.isArray(C)?!1:String(C??"")===String(R??"");case"contains":{const M=$=>String($??"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase(),g=M(C).replace(/[^a-z0-9]+/g," ").trim(),A=M(R).trim();if(!A)return!1;const U=A.split(/\s+/);return(U.length===1?new RegExp(`(?:^|\\s)${ab(U[0])}(?:\\s|$)`):new RegExp(`(?:^|\\s)${U.map($=>ab($)).join("\\s+")}(?:\\s|$)`)).test(g)}case"includes":return Array.isArray(C)?C.map(String).includes(String(R)):!1;default:return!1}}function ib(v,S){const b=v==null?void 0:v.enableWhen;if(!b||!Array.isArray(b.conditions)||b.conditions.length===0)return!0;const C=Array.isArray(S)?S.reduce((M,g)=>(g!=null&&g.id&&(M[g.id]=g),M),{}):S,R=b.conditions.map(M=>xE(M,C));return(b.logic||"AND").toUpperCase()==="AND"?R.every(Boolean):R.some(Boolean)}const lb=(v,S)=>{if(v===S)return!0;if(!v||!S)return!1;const b=Object.keys(v),C=Object.keys(S);if(b.length!==C.length)return!1;for(const R of b)if(v[R]!==S[R])return!1;return!0},ob=(v,S,b)=>typeof b!="number"||b<0||b>v.length?[...v,S]:[...v.slice(0,b),S,...v.slice(b)],SE=v=>{const S={},b=[],C=new Set;return(v||[]).forEach(R=>{let M=R.id;if(!M){const A=R.question||R.title||"",U=R.fieldType||"field";M=my(A,U,C)}C.add(M);const g=gy({...R,id:M});g.fieldType==="section"&&Array.isArray(g.fields)&&(g.fields=g.fields.map(A=>{let U=A.id;if(!U){const $=A.question||A.title||"",re=A.fieldType||"field";U=my($,re,C),C.add(U)}return gy({...A,id:U})})),S[M]=g,b.push(M)}),{byId:S,order:b}};function Xu(v,S,b,C,R={}){const{onIdChange:M,forbidCollision:g=!0}=R;if(!b){const V=v.byId[S];if(!V)return null;const I=C(V,null);if(!I||lb(V,I))return null;if(I.id&&I.id!==S){const ce=I.id;if(g&&v.byId[ce])return null;const{[S]:ze,...Oe}=v.byId,ht={...Oe,[ce]:I},we=v.order.map($e=>$e===S?ce:$e);return M==null||M(ce,S),{byId:ht,order:we}}return{byId:{...v.byId,[S]:I}}}const A=v.byId[b];if(!A||!Array.isArray(A.fields))return null;let U=!1,$=null;const re=A.fields.map(V=>{if(V.id!==S)return V;const I=C(V,A);if(!I||lb(V,I))return V;if(I.id&&I.id!==S){if(g&&A.fields.some(ce=>ce.id===I.id&&ce!==V))return V;$=I.id}return U=!0,I});if(!U)return null;const K={...v.byId,[b]:{...A,fields:re}};return $&&(M==null||M($,S)),{byId:K}}const Zr=eb((v,S)=>({byId:{},order:[],setEnableWhen:(b,C)=>v(R=>{const M=R.byId[b];if(!M)return R;const g=C&&Array.isArray(C.conditions)?{logic:C.logic||"AND",conditions:C.conditions}:void 0;return{byId:{...R.byId,[b]:{...M,...g?{enableWhen:g}:{enableWhen:void 0}}}}}),replaceAll:b=>v(()=>SE(b)),addField:(b,C={})=>v(R=>{var M,g;const{sectionId:A,initialPatch:U={},index:$}=C,re=(M=xv[b])==null?void 0:M.defaultProps;if(!re)return R;const K=new Set(Object.keys(R.byId));A&&(g=R.byId[A])!=null&&g.fields&&R.byId[A].fields.forEach(we=>K.add(we.id));const V=(U==null?void 0:U.question)||re.question||"",I=(U==null?void 0:U.title)||re.title||"",ce=my(b==="section"?I:V,b,K),ze=gy({...re,...U,id:ce});if(!A)return{byId:{...R.byId,[ce]:ze},order:ob(R.order,ce,$)};const Oe=R.byId[A];if(!Oe||!Array.isArray(Oe.fields))return R;const ht=ob(Oe.fields,ze,$);return{byId:{...R.byId,[A]:{...Oe,fields:ht}}}}),updateField:(b,C,R={})=>v(M=>{const{sectionId:g,onIdChange:A}=R;return Xu(M,b,g,$=>{const re=typeof C=="function"?C($):C;if(!re)return null;const{fieldType:K,id:V,question:I,title:ce,...ze}={...$,...re};return{fieldType:K,id:V,...K==="section"?{title:ce}:{question:I},...ze}},{onIdChange:A,forbidCollision:!0})||M}),deleteField:(b,C={})=>v(R=>{const{sectionId:M}=C;if(!M){if(!R.byId[b])return R;const{[b]:U,...$}=R.byId;return{byId:$,order:R.order.filter(re=>re!==b)}}const g=R.byId[M];if(!g||!Array.isArray(g.fields))return R;const A=g.fields.filter(U=>U.id!==b);return A.length===g.fields.length?R:{byId:{...R.byId,[M]:{...g,fields:A}}}}),addOption:(b,C="",R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=Array.isArray(U.options)?U.options:[],re=new Set($.map(I=>I.id)),K=yy(C,re,b),V=[...$,{id:K,value:C}];return{...U,options:V}})||M}),updateOption:(b,C,R,M={})=>v(g=>{const{sectionId:A}=M;return Xu(g,b,A,$=>{const re=Array.isArray($.options)?$.options:[];let K=!1;const V=re.map(I=>I.id!==C||I.value===R?I:(K=!0,{id:I.id,value:R}));return K?{...$,options:V}:null})||g}),updateOptionAnswer:(b,C,R,M={})=>v(g=>{const{sectionId:A}=M;return Xu(g,b,A,$=>{const re=Array.isArray($.options)?$.options:[];let K=!1;const V=re.map(I=>I.id!==C||I.answer===R?I:(K=!0,{...I,answer:R}));return K?{...$,options:V}:null})||g}),deleteOption:(b,C,R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=Array.isArray(U.options)?U.options:[],re=$.filter(V=>V.id!==C);if(re.length===$.length)return null;const K={...U,options:re};if(Array.isArray(U.selected)){const V=U.selected.filter(I=>I!==C);V.length!==U.selected.length&&(K.selected=V)}else U.selected===C&&(K.selected="");return K})||M}),selectSingle:(b,C,R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=C??"";return U.selected===$?null:{...U,selected:$}})||M}),toggleMulti:(b,C,R={})=>v(M=>{const{sectionId:g}=R;return Xu(M,b,g,U=>{const $=Array.isArray(U.selected)?U.selected:[],re=$.includes(C),K=re?$.filter(V=>V!==C):[...$,C];return K.length===$.length&&re?null:{...U,selected:K}})||M})})),EE=v=>{const S=Zr(C=>C.order),b=Zr(C=>C.byId);return tt.useMemo(()=>{const C=S.map(M=>b[M]),R=[];return C.forEach(M=>{R.push(M),(M==null?void 0:M.fieldType)==="section"&&Array.isArray(M.fields)&&R.push(...M.fields)}),v?{fields:C.filter(M=>ib(M,R)),allFlat:R}:{fields:C,allFlat:R}},[S,b,v])},Un=eb((v,S)=>({isPreview:!1,setPreview:b=>v({isPreview:!!b}),togglePreview:()=>v(b=>({isPreview:!b.isPreview})),isEditModalOpen:!1,setEditModalOpen:b=>v(C=>({isEditModalOpen:typeof b=="function"?!!b(C.isEditModalOpen):!!b})),panelResetKey:0,selectedFieldId:null,setSelectField:b=>v(C=>{const R=b??null;return C.selectedFieldId===R?{}:{selectedFieldId:R,panelResetKey:C.panelResetKey+1}}),clearSelectedField:()=>v({selectedFieldId:null}),renameSelectedFieldId:b=>v({selectedFieldId:b}),selectedChildId:{parentId:null,childId:null},setSelectedChildId:(b,C)=>v(R=>{const M=b??null,g=C??null;return R.selectedChildId.parentId===M&&R.selectedChildId.childId===g?{}:{selectedChildId:{parentId:M,childId:g}}}),clearSelectedChildId:()=>v(b=>b.selectedChildId.parentId===null&&b.selectedChildId.childId===null?{}:{selectedChildId:{parentId:null,childId:null}}),renameSelectedChildParentId:b=>v(C=>({selectedChildId:{...C.selectedChildId,parentId:b??null}})),renameSelectedChildId:b=>v(C=>({selectedChildId:{...C.selectedChildId,childId:b??null}})),conversionReport:null,setConversionReport:b=>v({conversionReport:b}),clearConversionReport:()=>v({conversionReport:null}),hideUnsupportedFields:!1,setHideUnsupportedFields:b=>v({hideUnsupportedFields:!!b})})),CE=(v,S)=>{const b=Zr(V=>V.addField),C=Zr(V=>V.updateField),R=Zr(V=>V.deleteField),M=Zr(V=>V.addOption),g=Zr(V=>V.updateOption),A=Zr(V=>V.updateOptionAnswer),U=Zr(V=>V.deleteOption),$=Zr(V=>V.selectSingle),re=Zr(V=>V.toggleMulti),K=tt.useCallback((V,I)=>{var ce,ze;const Oe=Un.getState();Oe.selectedFieldId===I&&((ce=Oe.renameSelectedFieldId)==null||ce.call(Oe,V)),(ze=Oe.renameSectionIdInHighlight)==null||ze.call(Oe,I,V)},[]);return tt.useMemo(()=>({field:{add:(V,I,ce)=>b(V,{sectionId:S,initialPatch:I,index:ce}),update:(V,I)=>C(v,{[V]:I},{sectionId:S,onIdChange:K}),patch:V=>C(v,V,{sectionId:S,onIdChange:K}),renameId:V=>C(v,{id:V},{sectionId:S,onIdChange:K}),remove:()=>R(v,{sectionId:S})},option:{add:(V="")=>M(v,V,{sectionId:S}),update:(V,I)=>g(v,V,I,{sectionId:S}),updateAnswer:(V,I)=>A(v,V,I,{sectionId:S}),remove:V=>U(v,V,{sectionId:S})},selection:{single:V=>$(v,V,{sectionId:S}),multiToggle:V=>re(v,V,{sectionId:S})},section:{addChild:(V,I,ce)=>b(V,{sectionId:v,initialPatch:I,index:ce})}}),[v,S,b,C,R,M,g,A,U,$,re,K])},bv=()=>{const v=Un(ve=>ve.isPreview),S=Un(ve=>ve.panelResetKey),b=Un(ve=>ve.selectedFieldId),C=Un(ve=>ve.isEditModalOpen),R=Un(ve=>ve.conversionReport),M=Un(ve=>ve.setPreview),g=Un(ve=>ve.togglePreview),A=Un(ve=>ve.setSelectField),U=Un(ve=>ve.clearSelectedField),$=Un(ve=>ve.renameSelectedFieldId),re=Un(ve=>ve.setEditModalOpen),K=Un(ve=>ve.setConversionReport),V=Un(ve=>ve.clearConversionReport),I=Un(ve=>ve.setHideUnsupportedFields),ce=Un(ve=>ve.selectedChildId),ze=Un(ve=>ve.setSelectedChildId),Oe=Un(ve=>ve.clearSelectedChildId),ht=Un(ve=>ve.renameSelectedChildParentId),we=Un(ve=>ve.renameSelectedChildId),$e=tt.useCallback(()=>re(!0),[re]),dt=tt.useCallback(()=>re(!1),[re]),Ne=tt.useCallback(()=>re(ve=>!ve),[re]);return tt.useMemo(()=>({state:{isPreview:v,isEditModalOpen:C,panelResetKey:S},isPreview:v,preview:{set:M,toggle:g},modal:{set:re,open:$e,close:dt,toggle:Ne},selectedFieldId:{value:b,set:A,clear:U,rename:$},selectedChildId:{ChildId:(ce==null?void 0:ce.childId)??null,ParentId:(ce==null?void 0:ce.parentId)??null,BothId:ce||{parentId:null,childId:null},set:ze,clear:Oe,renameParentId:ht,renameChildId:we},conversionReport:R,setConversionReport:K,clearConversionReport:V,setHideUnsupportedFields:I}),[v,C,S,M,g,b,A,U,$,re,$e,dt,Ne,ce,ze,Oe,ht,we,R,K,V,I])};function Xo(v,S){var b;const C=bv(),R=CE(v.id,S),M=((b=xv[v.fieldType])==null?void 0:b.label)??"Field",g=!!S,A=C.selectedFieldId.value===v.id,U=tt.useCallback(K=>{var V;C.state.isPreview||((V=K==null?void 0:K.stopPropagation)==null||V.call(K),C.selectedFieldId.value!==v.id&&C.selectedFieldId.set(v.id))},[C,v.id]),$=tt.useCallback(()=>{R.field.remove(),A&&C.selectedFieldId.clear()},[R,A,C]),re=["rounded-lg bg-white",C.state.isPreview?"":"border",!g&&C.state.isPreview?"border":"",v.fieldType==="section"&&C.state.isPreview?"p-0 border":"p-4",A?"border-blue-300 border-2 border-dashed":"border-gray-200"].join(" ");return{field:v,sectionId:S,label:M,insideSection:g,isPreview:C.state.isPreview,selected:A,isEditModalOpen:C.state.isEditModalOpen,onRowClick:U,toggleEdit:C.modal.toggle,remove:$,api:R,wrapperClass:re}}const kE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("input",{type:"text",value:g.answer||"",onChange:A=>C.field.update("answer",A.target.value),placeholder:"Type your answer",className:"px-4 py-2 w-full border border-black/10 shadow-2xs rounded"})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),_.jsx("input",{type:"text",value:g.answer||"",placeholder:"Type your answer",className:"px-4 py-2 my-1.5 w-full border border-black/10 shadow-2xs rounded",disabled:!0})]})})}),RE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("textarea",{value:g.answer||"",onChange:A=>C.field.update("answer",A.target.value),placeholder:"Type your answer",className:"px-3 py-2 w-full border border-black/10 shadow-2xs rounded min-h-24 max-h-60 resize-y",rows:4})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),_.jsx("textarea",{value:g.answer||"",placeholder:"Type your answer",className:"px-3 py-2 my-1.5 w-full border border-black/10 shadow-2xs rounded min-h-24 max-h-56 resize-y",rows:4,disabled:!0})]})})}),TE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{className:"space-y-2",children:(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center border border-black/10 shadow-2xs rounded overflow-hidden",children:[_.jsx("label",{className:"px-4 py-2 text-sm text-gray-500 bg-gray-50 whitespace-nowrap border-r border-black/10",children:A.value}),_.jsx("input",{type:"text",value:A.answer||"",onChange:U=>C.option.updateAnswer(A.id,U.target.value),placeholder:"",className:"flex-1 px-4 py-2 border-0 outline-none focus:ring-0"})]},A.id))})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-4 my-1.5 shadow border border-black/10 rounded-lg",children:[_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Field label",className:"w-full py-2"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Field"]})]})})}),_E=tt.memo(function({id:v,name:S,value:b,checked:C,onSelect:R,onUnselect:M,className:g="",...A}){const U=tt.useRef(C);return tt.useEffect(()=>{U.current=C},[C]),_.jsx("input",{id:v,type:"radio",name:S,value:b,className:g,checked:C,onClick:()=>{U.current?M==null||M(b):R==null||R(b)},onChange:()=>{},...A})}),DE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{children:(g.options||[]).map(A=>{const U=`${g.id}-${A.id}`,$=g.selected===A.id;return _.jsxs("label",{htmlFor:U,className:"flex items-center px-3 py-1 my-2 cursor-pointer",children:[_.jsx(_E,{id:U,name:`question-${g.id}`,value:A.id,checked:$,onSelect:()=>C.selection.single(A.id),onUnselect:()=>C.field.update("selected",null),className:"mr-2 h-9 w-9 flex-shrink-0 cursor-pointer"}),A.value]},A.id)})})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-4 my-1.5 shadow border border-black/10 rounded-lg",children:[_.jsx("input",{type:"radio",disabled:!0,className:"mr-2"}),_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Option text",className:"w-full py-2"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Option"]})]})})}),OE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{children:(g.options||[]).map(A=>_.jsxs("label",{className:"flex items-center px-3 py-1 my-2",children:[_.jsx("input",{type:"checkbox",className:"mr-2 w-9 h-9",checked:Array.isArray(g.selected)&&g.selected.includes(A.id),onChange:()=>C.selection.multiToggle(A.id)}),A.value]},A.id))})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-3 shadow my-1.5 border border-black/10 rounded-lg h-10",children:[_.jsx("input",{type:"checkbox",disabled:!0,className:"mr-2"}),_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Option text",className:"w-full"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Option"]})]})})}),NE=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{children:_.jsxs("select",{className:"w-full px-4 shadow border border-black/10 rounded-lg h-10",value:g.selected||"",onChange:A=>C.selection.single(A.target.value),children:[_.jsx("option",{value:"",children:"Select an option"}),(g.options||[]).map(A=>_.jsx("option",{value:A.id,children:A.value},A.id))]})})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:A=>C.field.update("question",A.target.value),placeholder:"Enter question"}),_.jsx("div",{className:"mt-2",children:_.jsxs("select",{className:"w-full px-4 shadow border border-black/10 rounded-lg h-10",disabled:!0,children:[_.jsx("option",{value:"",children:"Select an option"}),(g.options||[]).map(A=>_.jsx("option",{value:A.id,children:A.value},A.id))]})}),(g.options||[]).map(A=>_.jsxs("div",{className:"flex items-center px-3 shadow my-1.5 border border-black/10 rounded-lg h-10",children:[_.jsx("input",{type:"text",value:A.value,onChange:U=>C.option.update(A.id,U.target.value),placeholder:"Option text",className:"w-full"}),_.jsx("button",{onClick:()=>C.option.remove(A.id),children:_.jsx(gv,{className:"h-5 w-5"})})]},A.id)),_.jsxs("button",{onClick:()=>C.option.add(),className:"mt-2 ml-2 flex gap-3 justify-center",children:[_.jsx(wv,{className:"h-6 w-6"})," Add Option"]})]})})}),ME=tt.memo(function({field:v,sectionId:S}){const b=Xo(v,S);return _.jsx(Ko,{ctrl:b,children:({api:C,isPreview:R,insideSection:M,field:g})=>{var A;const U=((A=g.options)==null?void 0:A.length)===2?g.options:[{id:"yes",value:"Yes"},{id:"no",value:"No"}];return R?_.jsx("div",{className:M?"border-b border-gray-200":"border-0",children:_.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 pb-4",children:[_.jsx("div",{className:"font-light",children:g.question||"Question"}),_.jsx("div",{className:"flex gap-2",children:U.map($=>_.jsxs("label",{className:`flex-1 flex items-center justify-center px-4 py-2 border rounded-lg cursor-pointer ${g.selected===$.id?"bg-[#0076a8] text-white border-[#0076a8]":"border-black/10 hover:bg-gray-50"}`,onClick:re=>{re.preventDefault(),g.selected===$.id?C.field.update("selected",null):C.selection.single($.id)},children:[_.jsx("input",{type:"radio",name:g.fieldId,checked:g.selected===$.id,onChange:()=>{},className:"sr-only"}),_.jsx("span",{children:$.value})]},$.id))})]})}):_.jsxs("div",{children:[_.jsx("input",{className:"px-3 py-2 w-full border border-black/40 rounded",type:"text",value:g.question||"",onChange:$=>C.field.update("question",$.target.value),placeholder:"Enter question"}),U.map(($,re)=>_.jsxs("div",{className:"flex items-center px-4 my-1.5 shadow border border-black/10 rounded-lg",children:[_.jsx("input",{type:"radio",name:`${g.fieldId}-edit`,disabled:!0,className:"mr-2"}),_.jsx("input",{type:"text",value:$.value,onChange:K=>C.option.update(re,"value",K.target.value),placeholder:`Option ${re+1}`,className:"w-full py-2"})]},$.id))]})}})});function LE({field:v}){const[S,b]=Gu.useState(!1),C=v.unsupportedType||"unknown",R=v.unsupportedData||v._sourceData||{};return _.jsxs("div",{className:"border-2 border-dashed border-orange-500 rounded-lg p-4 bg-orange-50 mb-4",children:[_.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[_.jsx("span",{className:"text-xl",children:"⚠️"}),_.jsxs("div",{className:"flex-1",children:[_.jsxs("strong",{className:"text-orange-700",children:["Unsupported Field Type: ",C]}),_.jsx("div",{className:"text-sm text-gray-600 mt-1",children:v.question||R.title||R.name||"No title"})]})]}),_.jsxs("div",{className:"mt-3 p-3 bg-white border border-gray-300 rounded text-sm",children:[_.jsx("div",{className:"text-xs text-gray-500 mb-2 font-semibold",children:"Original Data Preview:"}),_.jsxs("div",{className:"space-y-1 text-gray-700",children:[Object.entries(R).slice(0,5).map(([M,g])=>typeof g=="object"&&g!==null?_.jsxs("div",{className:"truncate",children:[_.jsxs("span",{className:"font-mono text-xs text-blue-600",children:[M,":"]})," ",_.jsx("span",{className:"text-gray-500 italic",children:Array.isArray(g)?"[Array]":"{Object}"})]},M):_.jsxs("div",{className:"truncate",children:[_.jsxs("span",{className:"font-mono text-xs text-blue-600",children:[M,":"]})," ",_.jsx("span",{className:"text-gray-800",children:String(g)})]},M)),Object.keys(R).length>5&&_.jsxs("div",{className:"text-xs text-gray-400 italic",children:["... and ",Object.keys(R).length-5," more properties"]})]})]}),_.jsxs("button",{type:"button",onClick:()=>b(!S),className:"mt-3 px-3 py-1.5 bg-orange-500 text-white rounded hover:bg-orange-600 text-sm transition-colors",children:[S?"▼ Hide":"▶ Show"," Full Data"]}),S&&_.jsxs("div",{className:"mt-3",children:[_.jsx("div",{className:"text-xs text-gray-600 mb-2 font-semibold",children:"Full SurveyJS data for manual conversion:"}),_.jsx("pre",{className:"bg-gray-100 p-3 rounded text-xs overflow-auto max-h-[300px] border border-gray-300",children:JSON.stringify(R,null,2)})]}),_.jsx("div",{className:"mt-3 text-xs text-gray-600 italic",children:"💡 This field type is not yet supported. Manual implementation required."})]})}const xv={section:{label:"Section Field",componentKey:"section",defaultProps:{fieldType:"section",title:"New section",fields:[]}},text:{label:"Text Field",componentKey:"text",defaultProps:{fieldType:"text",question:"",answer:""}},longtext:{label:"Long Text Field",componentKey:"longtext",defaultProps:{fieldType:"longtext",question:"",answer:""}},multitext:{label:"Multi Text Field",componentKey:"multitext",defaultProps:{fieldType:"multitext",question:"",options:[{value:"Field 1"},{value:"Field 2"},{value:"Field 3"}]}},radio:{label:"Radio Field",componentKey:"radio",defaultProps:{fieldType:"radio",question:"",options:[{value:"Option 1"},{value:"Option 2"},{value:"Option 3"}],selected:null}},check:{label:"Check Field",componentKey:"check",defaultProps:{fieldType:"check",question:"",options:[{value:"Option 1"},{value:"Option 2"},{value:"Option 3"}],selected:[]}},boolean:{label:"Boolean Field",componentKey:"boolean",defaultProps:{fieldType:"boolean",question:"",options:[{id:"yes",value:"Yes"},{id:"no",value:"No"}],selected:null}},dropdown:{label:"Dropdown Field",componentKey:"dropdown",defaultProps:{fieldType:"dropdown",question:"",options:[{value:"Option 1"},{value:"Option 2"},{value:"Option 3"}],selected:null}},unsupported:{label:"Unsupported Field",componentKey:"unsupported",defaultProps:{fieldType:"unsupported",question:"Unsupported field type",unsupportedType:"unknown",unsupportedData:{}}}},wy={text:kE,longtext:RE,multitext:TE,radio:DE,check:OE,boolean:ME,dropdown:NE,unsupported:LE};function jE(v,S){wy[v]||(wy[v]=S)}function by(v){return wy[v]||null}const AE=tt.memo(function({field:v}){const S=Xo(v),b=bv(),C=Un(I=>I.hideUnsupportedFields),R=b.selectedChildId.ParentId,M=b.selectedChildId.ChildId,g=R===v.id?M:null,A=Gu.useRef({}),U=Zr(I=>I.byId),$=Gu.useMemo(()=>{const I=Object.values(U),ce=[];return I.forEach(ze=>{ze&&(ce.push(ze),ze.fieldType==="section"&&Array.isArray(ze.fields)&&ce.push(...ze.fields))}),ce},[U]);Gu.useEffect(()=>{var I;if(S.isPreview||!g)return;const ce=A.current[g];(I=ce==null?void 0:ce.scrollIntoView)==null||I.call(ce,{behavior:"smooth",block:"nearest"})},[g,S.isPreview]);const re=I=>C&&I.fieldType==="unsupported",K=(I,ce)=>{const ze=by(I.fieldType);return!ze||re(I)||!ib(I,$)?null:_.jsx("div",{ref:Oe=>Oe&&(A.current[I.id]=Oe),children:_.jsx(ze,{field:I,sectionId:ce})},I.id)},V=(I,ce)=>{const ze=by(I.fieldType);if(!ze||re(I))return null;const Oe=g===I.id;return _.jsx("div",{ref:ht=>ht&&(A.current[I.id]=ht),className:["rounded-lg mb-3",Oe?"border-2 border-blue-400 border-dashed":"border border-transparent"].join(" "),children:_.jsx(ze,{field:I,sectionId:ce})},I.id)};return _.jsx(Ko,{ctrl:S,children:({api:I,isPreview:ce,insideSection:ze,field:Oe})=>{const ht=Array.isArray(Oe.fields)?Oe.fields:[];return ce?_.jsxs("section",{className:ze?"border-b border-gray-200":"border-0",children:[_.jsx("div",{className:"bg-[#0076a8] text-white text-xl px-4 py-2 rounded-t-lg",children:Oe.title||"Section"}),ht.map(we=>K(we,Oe.id))]}):_.jsxs("div",{children:[_.jsx("div",{className:"flex justify-between items-center mb-3 gap-2",children:_.jsx("div",{className:"flex-1",children:_.jsx("input",{type:"text",className:"w-full px-3 py-2 border border-gray-200 rounded-md",value:Oe.title||"",onChange:we=>I.field.update("title",we.target.value),placeholder:"Section title (e.g., Data Consent)"})})}),_.jsx("div",{children:ht.map(we=>V(we,Oe.id))}),_.jsxs("div",{className:"mb-3",children:[_.jsx("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"Add a field"}),_.jsx("div",{className:"flex flex-wrap gap-2",children:Object.keys(xv).filter(we=>we!=="section").map(we=>_.jsxs("button",{className:"inline-flex items-center gap-2 px-3 py-2 text-sm border border-gray-300 rounded-md hover:bg-gray-50",onClick:()=>{var $e,dt,Ne;return($e=I.section)!=null&&$e.addChild?I.section.addChild(we):(Ne=(dt=I.field).add)==null?void 0:Ne.call(dt,we,void 0,void 0)},children:[_.jsx(hE,{className:"h-4 w-4"}),"Add ",xv[we].label]},we))})]})]})}})});jE("section",AE);function zE(v,S="inhouse"){if(!v)return{fields:[],conversionReport:null};switch(S){case"surveyjs":return UE(v);case"inhouse":return{fields:Array.isArray(v)?v:v.fields&&Array.isArray(v.fields)?v.fields:[],conversionReport:null};default:throw new Error(`Unsupported schema type: ${S}`)}}function UE(v){if(!v)return{fields:[],conversionReport:null};const S={sourceType:"surveyjs",timestamp:new Date().toISOString(),surveyMetadata:PE(v),totalElements:0,convertedFields:0,droppedFields:[],warnings:[]};let b=[];Array.isArray(v.elements)?b=v.elements:Array.isArray(v.pages)&&(b=v.pages.flatMap(g=>g.elements||[]),v.pages.length>1&&S.warnings.push({type:"page_structure_lost",message:`Multi-page survey with ${v.pages.length} pages flattened into single form`,impact:"high"})),S.totalElements=b.length;const C=new Set,R=g=>{g.forEach(A=>{A.name&&C.add(A.name),A.elements&&Array.isArray(A.elements)&&R(A.elements)})};R(b);const M=b.map(g=>{const A=ub(g,C);return A?(S.convertedFields++,A._conversionWarnings&&A._conversionWarnings.length>0&&S.warnings.push(...A._conversionWarnings.map(U=>({...U,fieldId:A.id,fieldName:g.name})))):S.droppedFields.push({name:g.name||"unnamed",type:g.type||"unknown",title:g.title||""}),A}).filter(Boolean);return $E(M),{fields:M,conversionReport:S}}function ub(v,S=new Set){if(!v||!v.type)return null;const b=FE(v.type),C=[],R={id:v.name||`field-${Date.now()}-${Math.random().toString(36).substring(2,11)}`,fieldType:b||"unsupported",question:v.title||v.name||""};if(!b){R.fieldType="unsupported",R.unsupportedType=v.type;const M={...v};return M.elements&&Array.isArray(M.elements)&&(M.elements=M.elements.map(g=>g.name).filter(Boolean)),R.unsupportedData=M,C.push({type:"unsupported_field_type",property:"type",value:v.type,message:`Field type "${v.type}" is not supported. Displayed as placeholder.`,impact:"high"}),R._sourceData=v,R._conversionWarnings=C,R}switch(b){case"input":R.answer=v.defaultValue||"",HE(v,C);break;case"radio":case"dropdown":R.options=cb(v.choices),R.selected=v.defaultValue||null,fb(v,C);break;case"check":R.options=cb(v.choices),R.selected=Array.isArray(v.defaultValue)?v.defaultValue:[],fb(v,C);break;case"section":R.title=v.title||v.name||"Section",R.fields=Array.isArray(v.elements)?v.elements.map(M=>ub(M,S)).filter(Boolean):[];break}if(v.type==="boolean"&&R.fieldType==="radio"&&(R.options=[{id:"yes",value:v.labelTrue||"Yes"},{id:"no",value:v.labelFalse||"No"}],v.defaultValue===!0?R.selected="yes":v.defaultValue===!1?R.selected="no":R.selected=null),v.isRequired&&(R.required=!0),v.visibleIf){const M=db(v.visibleIf,S);M&&(R.enableWhen=M,sb(C,"conditional_logic_lost","visibleIf"))}if(v.enableIf&&!R.enableWhen){const M=db(v.enableIf,S);M&&(R.enableWhen=M,sb(C,"conditional_logic_lost","enableIf"))}return IE(v,C),R.fieldType==="section"&&v.elements&&Array.isArray(v.elements)?R._sourceData={...v,elements:v.elements.map(M=>M.name).filter(Boolean)}:R._sourceData=v,R._conversionWarnings=C,R}function sb(v,S,b){const C=v.findIndex(R=>R.type===S&&R.property===b);C!==-1&&v.splice(C,1)}function FE(v){return{text:"text",comment:"text",multipletext:"text",radiogroup:"radio",dropdown:"dropdown",boolean:"radio",checkbox:"check",panel:"section",paneldynamic:"section"}[v]||null}function cb(v){return Array.isArray(v)?v.map((S,b)=>typeof S=="string"?{id:`opt-${b}`,value:S}:{id:S.value||`opt-${b}`,value:S.text||S.value||""}):[]}function PE(v){const S={};return["title","description","logo","logoPosition","showProgressBar","progressBarType","showQuestionNumbers","completedHtml","loadingHtml","locale","questionsOnPageMode","calculatedValues","triggers"].forEach(b=>{v[b]!==void 0&&(S[b]=v[b])}),S}function HE(v,S){v.inputType&&v.inputType!=="text"&&S.push({type:"input_type_lost",property:"inputType",value:v.inputType,message:`Input type "${v.inputType}" not supported (date, tel, email, number will render as text)`,impact:"medium"}),v.placeHolder&&S.push({type:"placeholder_lost",property:"placeHolder",value:v.placeHolder,message:"Placeholder text not supported",impact:"low"}),v.maxLength&&S.push({type:"validation_lost",property:"maxLength",value:v.maxLength,message:"Max length validation not supported",impact:"medium"}),(v.min!==void 0||v.max!==void 0)&&S.push({type:"validation_lost",property:"min/max",value:`${v.min||""} - ${v.max||""}`,message:"Numeric min/max constraints not supported",impact:"high"})}function fb(v,S){v.hasOther&&S.push({type:"other_option_lost",property:"hasOther",value:v.otherText||"Other",message:'"Other" option with text input not supported',impact:"medium"}),(v.labelTrue||v.labelFalse)&&S.push({type:"boolean_labels_lost",property:"labelTrue/labelFalse",value:`${v.labelTrue||"Yes"} / ${v.labelFalse||"No"}`,message:"Custom boolean labels not supported (using Yes/No)",impact:"low"}),v.choicesOrder&&v.choicesOrder!=="none"&&S.push({type:"choice_order_lost",property:"choicesOrder",value:v.choicesOrder,message:"Choice ordering not supported",impact:"low"})}function IE(v,S){v.visibleIf&&S.push({type:"conditional_logic_lost",property:"visibleIf",value:v.visibleIf,message:"Conditional visibility logic not supported (field always visible)",impact:"high"}),v.enableIf&&S.push({type:"conditional_logic_lost",property:"enableIf",value:v.enableIf,message:"Conditional enable/disable logic not supported",impact:"high"}),v.requiredIf&&S.push({type:"conditional_logic_lost",property:"requiredIf",value:v.requiredIf,message:"Conditional required logic not supported",impact:"high"}),v.validators&&v.validators.length>0&&S.push({type:"validation_lost",property:"validators",value:v.validators.map(b=>b.type).join(", "),message:`Validators not supported: ${v.validators.map(b=>b.type).join(", ")}`,impact:"high"}),v.readOnly&&S.push({type:"readonly_lost",property:"readOnly",value:!0,message:"Read-only field not supported",impact:"medium"})}function db(v,S=new Set){if(!v||typeof v!="string")return null;try{let b=v.trim(),C="AND";const R=/ or /i.test(b),M=/ and /i.test(b);if(R&&M)return console.warn(`[schemaAdapter] Mixed AND/OR logic not supported in: ${v}`),null;R&&(C="OR");const g=b.split(R?/ or /i:/ and /i),A=[];for(const U of g){const $=VE(U.trim());if($){if(S.size>0&&!S.has($.targetId)){console.warn(`[schemaAdapter] Skipping condition - field "${$.targetId}" not found (may be calculated value or metadata): ${U}`);continue}A.push($)}else console.warn(`[schemaAdapter] Unable to parse condition: ${U}`)}return A.length===0?null:{logic:A.length===1?"AND":C,conditions:A}}catch(b){return console.warn(`[schemaAdapter] Error converting visibleIf: ${v}`,b),null}}function VE(v){const S=C=>v.match(C);let b=S(/\{(\w+)\}\s*=\s*'([^']+)'/)||S(/\{(\w+)\}\s*=\s*"([^"]+)"/)||S(/\{(\w+)\}\s*=\s*([\w.-]+)/);if(b){const C=b[2],R=C==="true"?"yes":C==="false"?"no":C;return{targetId:b[1],operator:"equals",value:R}}return b=S(/\{(\w+)\}\s*(?:<>|!=)\s*'([^']+)'/)||S(/\{(\w+)\}\s*(?:<>|!=)\s*"([^"]+)"/)||S(/\{(\w+)\}\s*(?:<>|!=)\s*([\w.-]+)/),b?(console.warn(`[schemaAdapter] "not equal" operator not yet supported: ${v}`),null):(b=S(/\{(\w+)\}\s+contains\s+'([^']+)'/)||S(/\{(\w+)\}\s+contains\s+"([^"]+)"/)||S(/\{(\w+)\}\s+contains\s+([\w.-]+)/),b?{targetId:b[1],operator:"contains",value:b[2]}:(b=S(/\{(\w+)\}\s+empty/i),b?{targetId:b[1],operator:"equals",value:""}:(b=S(/\{(\w+)\}\s+notempty/i),b&&console.warn(`[schemaAdapter] "notempty" operator not yet supported: ${v}`),null)))}function BE(v){const S=new Map,b=C=>{C.forEach(R=>{S.set(R.id,R),R.fields&&Array.isArray(R.fields)&&b(R.fields)})};return b(v),S}function $E(v){const S=BE(v),b=C=>{C.enableWhen&&C.enableWhen.conditions&&C.enableWhen.conditions.forEach(R=>{const M=S.get(R.targetId);if(M&&M.options&&Array.isArray(M.options)){const g=M.options.find(A=>A.value===R.value);g?R.value=g.id:console.warn(`[schemaAdapter] No matching option found for value "${R.value}" in field "${R.targetId}"`)}}),C.fields&&Array.isArray(C.fields)&&C.fields.forEach(b)};v.forEach(b)}function YE(v,S="inhouse",b=!1){const C=tt.useRef(!1),R=bv();tt.useEffect(()=>{if(C.current||!v)return;const M=zE(v,S),g=M.fields||M;M.conversionReport&&R.setConversionReport(M.conversionReport),Zr.getState().replaceAll(g),R.preview.set(!0),C.current=!0},[v,S,R]),tt.useEffect(()=>{R.setHideUnsupportedFields(b)},[b,R])}const WE=tt.memo(function({id:S}){const b=Zr(tt.useCallback(R=>R.byId[S],[S]));if(!b)return null;const C=by(b.fieldType);return C?Ku.jsx("div",{className:"mb-1.5","data-field-type":b.fieldType,"data-field-id":b.id,children:Ku.jsx(C,{field:b})}):null});function QE(){const v=bv(),{fields:S}=EE(v.state.isPreview),b=Un(R=>R.hideUnsupportedFields),C=Gu.useMemo(()=>(b?S.filter(M=>M.fieldType!=="unsupported"):S).map(M=>M.id),[S,b]);return Ku.jsx("div",{children:C.map(R=>Ku.jsx(WE,{id:R},R))})}function qE({fields:v,schemaType:S="inhouse",onChange:b,className:C="",fullHeight:R=!1,hideUnsupportedFields:M=!1}){YE(v,S,M),tt.useEffect(()=>b?Zr.subscribe(U=>{const $=U.order.map(re=>U.byId[re]);b($)}):void 0,[b]);const g=["qb-render-root","bg-gray-100","font-titillium",R?"min-h-screen":"",C].filter(Boolean).join(" ");return Ku.jsx("div",{className:g,children:Ku.jsx("div",{className:"max-w-4xl mx-auto px-2 pb-8 pt-4",children:Ku.jsx(QE,{})})})}function pb(v){switch(v.fieldType){case"text":case"longtext":return v.answer?[{valueString:String(v.answer)}]:[];case"radio":return v.selected?[{valueString:xy(v,v.selected)}]:[];case"check":return(v.selected||[]).map(S=>({valueString:xy(v,S)}));case"selection":return v.selected?[{valueString:xy(v,v.selected)}]:[];default:return[]}}function xy(v,S){const b=(v.options||[]).find(C=>C.id===S||C.value===S);return b?b.value:""}function GE(v,S,b){const C=[];return(v||[]).forEach(R=>{if(R.fieldType==="section"&&Array.isArray(R.fields)){R.fields.forEach(M=>{M&&C.push({linkId:M.id,text:M.question||M.title||"",answer:pb(M)})});return}R.fieldType!=="section"&&C.push({linkId:R.id,text:R.question||R.title||"",answer:pb(R)})}),{resourceType:"QuestionnaireResponse",questionnaire:S,status:"in-progress",subject:b?{reference:`Patient/${b}`}:void 0,item:C}}class vb extends HTMLElement{static get observedAttributes(){return["fields","schema-type","full-height","hide-unsupported-fields"]}constructor(){super(),this._root=null,this._fields=[],this._schemaType="inhouse",this._hideUnsupportedFields=!1,this._onChange=null}connectedCallback(){this._mount()}disconnectedCallback(){this._unmount()}attributeChangedCallback(S,b,C){b!==C&&this._render()}set fields(S){this._fields=S,this._render()}get fields(){return this._fields}set onChange(S){this._onChange=S,this._render()}get onChange(){return this._onChange}set schemaType(S){this._schemaType=S||"inhouse",this._render()}get schemaType(){return this._schemaType}set hideUnsupportedFields(S){this._hideUnsupportedFields=!!S,this._render()}get hideUnsupportedFields(){return this._hideUnsupportedFields}getQuestionnaireResponse(S="questionnaire-1",b){const C=Zr.getState(),R=C.order.map(M=>C.byId[M]);return GE(R,S,b)}_mount(){this._root||(this._root=aE.createRoot(this)),this._render()}_unmount(){this._root&&(this._root.unmount(),this._root=null)}_render(){if(!this._root)return;let S=this._fields;const b=this.getAttribute("fields");if(b&&!this._fields.length)try{S=JSON.parse(b)}catch{S=[]}const C=this.getAttribute("schema-type")||this._schemaType||"inhouse",R=this.hasAttribute("full-height"),M=this.hasAttribute("hide-unsupported-fields")||this._hideUnsupportedFields,g=this.getAttribute("class")||"";this._root.render(tt.createElement(qE,{fields:S,schemaType:C,hideUnsupportedFields:M,onChange:this._onChange,className:g,fullHeight:R}))}}customElements.get("questionnaire-renderer")||customElements.define("questionnaire-renderer",vb),pc.QuestionnaireRendererElement=vb,Object.defineProperty(pc,Symbol.toStringTag,{value:"Module"})}));
|
|
2227
2227
|
//# sourceMappingURL=standalone.umd.cjs.map
|