@kizenapps/cli 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/chunk-4Z6S6LWP.js +6134 -0
  2. package/dist/chunk-4Z6S6LWP.js.map +1 -0
  3. package/dist/chunk-HJPLDI45.js +6134 -0
  4. package/dist/chunk-HJPLDI45.js.map +1 -0
  5. package/dist/chunk-LSHHXCC6.js +3639 -0
  6. package/dist/chunk-LSHHXCC6.js.map +1 -0
  7. package/dist/chunk-SEGVTWSK.js +44 -0
  8. package/dist/chunk-SEGVTWSK.js.map +1 -0
  9. package/dist/chunk-ZWE3DS7E.js +39 -0
  10. package/dist/chunk-ZWE3DS7E.js.map +1 -0
  11. package/dist/devtools-LZRAH4XS.js +90 -0
  12. package/dist/devtools-LZRAH4XS.js.map +1 -0
  13. package/dist/dist-C3F6UOWF.js +8472 -0
  14. package/dist/dist-C3F6UOWF.js.map +1 -0
  15. package/dist/dist-NUJOSN7W.js +8472 -0
  16. package/dist/dist-NUJOSN7W.js.map +1 -0
  17. package/dist/dist-QHDMIBVE.js +135 -0
  18. package/dist/dist-QHDMIBVE.js.map +1 -0
  19. package/dist/dist-ZIZQOSY3.js +135 -0
  20. package/dist/dist-ZIZQOSY3.js.map +1 -0
  21. package/dist/gzip-size-K37OQCQ2.js +137 -0
  22. package/dist/gzip-size-K37OQCQ2.js.map +1 -0
  23. package/dist/gzip-size-QRGIYYEQ.js +137 -0
  24. package/dist/gzip-size-QRGIYYEQ.js.map +1 -0
  25. package/dist/index.js +575 -552
  26. package/dist/index.js.map +1 -1
  27. package/dist/viewer/assets/AppDetailPage-BJrg5Wsz.js +1 -0
  28. package/dist/viewer/assets/{BootstrapContext-CEWgv2oI.js → BootstrapContext-D3lhzWap.js} +1 -1
  29. package/dist/viewer/assets/Card-CPMAuqAb.js +1 -0
  30. package/dist/viewer/assets/ConfigurationPage-D8I8rWjF.js +1 -0
  31. package/dist/viewer/assets/SandboxPage-ByixszHi.js +1 -0
  32. package/dist/viewer/assets/{VersionsPage-DOd2Hv8M.js → VersionsPage-BKul6bXI.js} +1 -1
  33. package/dist/viewer/assets/index-BoSQQwMQ.css +2 -0
  34. package/dist/viewer/assets/index-Bomh3C3X.js +5 -0
  35. package/dist/viewer/assets/useObjectLookups-Cx6A7PGj.js +14 -0
  36. package/dist/viewer/index.html +4 -4
  37. package/package.json +10 -10
  38. package/dist/viewer/assets/AppDetailPage-ObugMPkn.js +0 -1
  39. package/dist/viewer/assets/Card-BSwG5koM.js +0 -1
  40. package/dist/viewer/assets/ConfigurationPage-SnFNzZgJ.js +0 -1
  41. package/dist/viewer/assets/SandboxPage-BFVVe-i3.js +0 -1
  42. package/dist/viewer/assets/configStorage-Bb-A9Nvj.js +0 -14
  43. package/dist/viewer/assets/index-B-4D4w_w.js +0 -5
  44. package/dist/viewer/assets/index-D6Un_G7k.css +0 -2
@@ -1 +0,0 @@
1
- import{n as e}from"./rolldown-runtime-DF2fYuay.js";import{D as t,O as n,b as r,k as i}from"./fa-core-mHW_3JUd.js";import{n as a,r as o,t as s,z as c}from"./Card-BSwG5koM.js";import{a as l,i as u,n as d}from"./BootstrapContext-CEWgv2oI.js";import{_ as f,a as p,b as m,c as h,i as g,l as _,n as v,o as y,r as b,s as x,t as S,u as C,v as w,y as T}from"./configStorage-Bb-A9Nvj.js";import{r as E}from"./CredentialsContext-BLZX6RwF.js";var D=e(i(),1),O=n(),k=({field:e,disabled:t=!1})=>{let{state:n,setState:r,evaluateExpression:i,shouldHideField:a,getFieldErrorState:o,registerFieldResetter:s,afterFieldChange:c,disabledKeys:l}=f(),u=n[e.key]?.value??e.default??!1,d=u===!0||u===`true`,p=l.includes(e.key)||t,m=(0,D.useCallback)(t=>{r(n=>({...n,[e.key]:{type:`boolean`,value:t}})),c(e.key)},[e.key,r,c]);if((0,D.useEffect)(()=>{s(e.key,()=>{m(void 0)})},[e.key,s,m]),(0,D.useEffect)(()=>{e.when&&i(e.when,e.key)},[e.when,i,e.key]),a(e.key))return null;let h=o(e.key);return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>{m(e.target.checked)},disabled:p,className:`h-3.5 w-3.5 cursor-pointer accent-blue-600`}),(0,O.jsxs)(`span`,{className:`text-[13px] ${p?`text-neutral-400`:`text-neutral-700`}`,children:[e.label,e.required&&(0,O.jsx)(`span`,{className:`text-red-500 ml-0.5`,children:`*`})]}),e.tooltip&&(0,O.jsx)(`span`,{className:`text-[11px] text-neutral-400`,title:e.tooltip,children:`?`})]}),h?.showMessage&&h.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:h.message})]})},A=({field:e,pluginApiName:t,disabled:n=!1})=>{let{evaluateExpression:r,shouldHideField:i}=f(),a=e.columns??1;return(0,D.useEffect)(()=>{e.when&&r(e.when,e.key)},[e.when,r,e.key]),i(e.key)?null:(0,O.jsxs)(`div`,{children:[e.label&&(0,O.jsx)(`h3`,{className:`text-[14px] font-semibold text-neutral-800 mb-3 mt-4`,children:e.label}),(0,O.jsx)(`div`,{className:`gap-4`,style:{display:`grid`,gridTemplateColumns:`repeat(${String(a)}, 1fr)`},children:e.fields?.map(e=>(0,O.jsx)(N,{field:e,pluginApiName:t,disabled:n},e.key))})]})},j=({field:e})=>e.label?(0,O.jsxs)(`label`,{className:`text-[12px] font-medium text-neutral-600`,children:[e.label,e.required&&(0,O.jsx)(`span`,{className:`text-red-500 ml-0.5`,children:`*`}),e.tooltip&&(0,O.jsx)(`span`,{className:`ml-1 text-neutral-400 cursor-help`,title:e.tooltip,children:`?`})]}):null,M={container:A,custom_object:({field:e,disabled:t=!1})=>{let{state:n,setState:r,getNestedFields:i,reInferFieldsForObject:a,evaluateExpression:o,shouldHideField:s,shouldDisableField:c,getFieldErrorState:u,registerFieldResetter:p,afterFieldChange:m,disabledKeys:g}=f(),_=n[e.key]?.value,v=g.includes(e.key)||t,y=c(e.key)||v,[b,x]=(0,D.useState)(_?.objectName??``),[S,C]=(0,D.useState)([]),[w,T]=(0,D.useState)(!1),E=(0,D.useRef)(null),k=l(),A=d(),M=(0,D.useCallback)(async e=>{T(!0);try{let t=new URLSearchParams({page_size:`20`});e&&t.set(`search`,e);let n=await(await k(`/custom-objects?${t.toString()}`)).json(),r=(Array.isArray(n)?n:n.results??[]).map(e=>({id:e.id,label:e.object_name})),i=A?.business.client_object;i?.access&&(!e||i.object_name.toLowerCase().includes(e.toLowerCase()))&&r.unshift({id:i.id,label:i.object_name}),C(r)}catch{C([])}finally{T(!1)}},[k,A]),N=(0,D.useCallback)(t=>{x(t),_&&(r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),m(e.key)),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{M(t)},300)},[_,e.key,r,m,M]),P=(0,D.useCallback)((t,n)=>{x(n),r(r=>({...r,[e.key]:{type:`custom_object`,value:{id:t,objectName:n}}}));let o=i().filter(t=>t.object_id?.includes(e.key));for(let e of o)r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key)));a(e.key),m(e.key)},[e.key,r,i,a,m]);if((0,D.useEffect)(()=>{p(e.key,()=>{r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),x(``)})},[e.key,p,r]),(0,D.useEffect)(()=>{e.when&&o(e.when,e.key)},[e.when,o,e.key]),s(e.key))return null;let F=u(e.key);return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(h,{value:b,onChange:N,onSelect:P,options:S,loading:w,placeholder:e.placeholder??`Search for an object...`,disabled:y}),_&&(0,O.jsx)(`button`,{type:`button`,onClick:()=>{r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),x(``),m(e.key)},disabled:y,className:`absolute right-2 top-1/2 -translate-y-1/2 text-[11px] text-neutral-400 hover:text-neutral-600`,"aria-label":`Clear selection`,children:`×`})]}),F?.showMessage&&F.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:F.message})]})},field:({field:e,disabled:t=!1})=>{let{interpolateValue:n,state:r,setState:i,evaluateExpression:a,shouldHideField:o,getFieldErrorState:s,registerFieldResetter:c,afterFieldChange:u,disabledKeys:d}=f(),p=d.includes(e.key)||t,m=n(e.object_id??``),[h,g]=(0,D.useState)([]),[_,v]=(0,D.useState)(``),[y,b]=(0,D.useState)(!1),[x,S]=(0,D.useState)(null),C=l();(0,D.useEffect)(()=>{!m||m===x||o(e.key)||(async()=>{b(!0);try{v((await(await C(`/custom-objects/${m}`)).json()).object_name??``);let e=await(await C(`/custom-objects/${m}/fields`)).json();g((Array.isArray(e)?e:e.results??[]).map(e=>({label:e.display_name,value:e.id}))),S(m)}catch{g([])}finally{b(!1)}})()},[m,x,C,e.key,o]);let w=r[e.key]?.value,T=(0,D.useCallback)(t=>{i(n=>({...n,[e.key]:{type:`field`,value:t,associatedObject:{id:m,name:_}}})),u(e.key)},[e.key,i,m,_,u]);if((0,D.useEffect)(()=>{c(e.key,()=>{i(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key)))})},[e.key,c,i]),(0,D.useEffect)(()=>{e.when&&a(e.when,e.key)},[e.when,a,e.key]),o(e.key))return null;let E=s(e.key),k=!m||p;if(e.allow_multiple){let t=Array.isArray(w)?w:[];return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),(0,O.jsx)(`div`,{className:`rounded border p-2 text-[13px] ${E?.error?`border-red-300`:`border-black/10`} ${k?`bg-neutral-50`:`bg-white`}`,children:y?(0,O.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`Loading fields...`}):m?h.length===0?(0,O.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`No fields available`}):(0,O.jsx)(`div`,{className:`flex flex-col gap-1 max-h-48 overflow-y-auto`,children:h.map(e=>{let n=t.some(t=>t.value===e.value);return(0,O.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:n,disabled:k,onChange:()=>{T(n?t.filter(t=>t.value!==e.value):[...t,e])},className:`h-3 w-3 accent-blue-600`}),(0,O.jsx)(`span`,{className:`text-[12px]`,children:e.label})]},e.value)})}):(0,O.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`Select an object first`})}),E?.showMessage&&E.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:E.message})]})}let A=w&&!Array.isArray(w)?w.value:``;return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),y?(0,O.jsx)(`div`,{className:`w-full rounded border border-black/10 px-2 py-1.5 text-[12px] text-neutral-400 bg-neutral-50`,children:`Loading fields...`}):(0,O.jsxs)(`select`,{value:A,onChange:e=>{let t=h.find(t=>t.value===e.target.value);t&&T(t)},disabled:k,className:`w-full rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${E?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${k?`bg-neutral-50 text-neutral-400`:`bg-white`}`,children:[(0,O.jsx)(`option`,{value:``,children:m?`Choose a field`:`Select an object first`}),h.map(e=>(0,O.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),E?.showMessage&&E.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:E.message})]})},text:({field:e,disabled:t=!1})=>{let{state:n,setState:r,evaluateExpression:i,shouldHideField:a,getFieldErrorState:o,registerFieldResetter:s,afterFieldChange:c,disabledKeys:l}=f(),[u,d]=(0,D.useState)(n[e.key]?.value??e.default??``),p=l.includes(e.key)||t,m=(0,D.useCallback)(t=>{r(n=>({...n,[e.key]:{type:`text`,value:t}})),c(e.key)},[e.key,r,c]);if((0,D.useEffect)(()=>{s(e.key,()=>{d(``),m(``)})},[e.key,s,m]),(0,D.useEffect)(()=>{let e=setTimeout(()=>{m(u)},300);return()=>{clearTimeout(e)}},[u,m]),(0,D.useEffect)(()=>{e.when&&i(e.when,e.key)},[e.when,i,e.key]),a(e.key))return null;let h=o(e.key);return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),(0,O.jsx)(`input`,{type:`text`,value:u,onChange:e=>{d(e.target.value)},placeholder:e.placeholder??e.default??`Enter text`,disabled:p,className:`rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${h?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${p?`bg-neutral-50 text-neutral-400`:`bg-white`}`}),h?.showMessage&&h.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:h.message})]})},description:({field:e})=>{let{evaluateExpression:t,shouldHideField:n}=f();return(0,D.useEffect)(()=>{e.when&&t(e.when,e.key)},[e.when,t,e.key]),n(e.key)?null:(0,O.jsx)(`div`,{className:`text-[13px] text-neutral-500 leading-relaxed`,children:e.content})},number:({field:e,disabled:t=!1})=>{let{state:n,setState:r,evaluateExpression:i,shouldHideField:a,getFieldErrorState:o,registerFieldResetter:s,afterFieldChange:c,disabledKeys:l}=f(),u=n[e.key]?.value??e.default??``,[d,p]=(0,D.useState)(String(u)),m=l.includes(e.key)||t,h=(0,D.useCallback)(t=>{r(n=>({...n,[e.key]:{type:`number`,value:t}})),c(e.key)},[e.key,r,c]);if((0,D.useEffect)(()=>{s(e.key,()=>{p(``),h(``)})},[e.key,s,h]),(0,D.useEffect)(()=>{let e=setTimeout(()=>{h(d)},300);return()=>{clearTimeout(e)}},[d,h]),(0,D.useEffect)(()=>{e.when&&i(e.when,e.key)},[e.when,i,e.key]),a(e.key))return null;let g=o(e.key);return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),(0,O.jsx)(`input`,{type:`number`,value:d,onChange:e=>{p(e.target.value)},placeholder:e.placeholder??e.default??`Enter a number`,disabled:m,className:`rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${g?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${m?`bg-neutral-50 text-neutral-400`:`bg-white`}`}),g?.showMessage&&g.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:g.message})]})},select:({field:e,pluginApiName:t,disabled:n=!1})=>{let{state:r,setState:i,evaluateExpression:a,shouldHideField:o,getFieldErrorState:s,inferencePending:c,initialExpressionsPending:u,expressionsIdle:d,afterFieldChange:p,registerFieldResetter:h,disabledKeys:g}=f(),_=!c&&!u&&d,[v,y]=(0,D.useState)([]),[b,x]=(0,D.useState)(!1),S=(0,D.useRef)(null),C=!!(e.getFetchUrl??e.optionMapper),E=r[e.key]?.value,k=g.includes(e.key)||n,A=l(),M=(0,D.useCallback)(t=>{i(n=>({...n,[e.key]:{type:`select`,value:t}})),p(e.key)},[p,e.key,i]);(0,D.useEffect)(()=>{h(e.key,()=>{i(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key)))})},[e.key,h,i]),(0,D.useEffect)(()=>{e.when&&a(e.when,e.key)},[e.when,a,e.key]);let N=(0,D.useMemo)(()=>JSON.stringify(r),[r]);if((0,D.useEffect)(()=>{!C||!_||o(e.key)||S.current===N||(async()=>{x(!0),S.current=N;try{let n={__kizen_state:{value:{...r,pluginApiName:t}}},i;if(e.getFetchUrl){let t=await m(e.getFetchUrl,n);if(t){let r=e.fetchMethod??`GET`,a={"Content-Type":`application/json`},o=null;if(e.getHeaders&&(a=await w(e.getHeaders,n)),r===`POST`&&e.getBody){let t=await w(e.getBody,n);o=JSON.stringify(t)}if(t.startsWith(`/`))i={data:await(await A(t,{method:r,headers:a,...o!=null&&{body:o}})).json()};else{let e=await fetch(t,{method:r,headers:a,...o!=null&&{body:o}});e.ok&&(i=await e.json())}}}if(e.optionMapper){let n=await T(e.optionMapper,{__kizen_state:{value:{...r,result:i,pluginApiName:t}}});y(structuredClone(n))}else Array.isArray(i)&&y(i)}catch{y([])}finally{x(!1)}})()},[C,_,N,r,e,t,A,o]),o(e.key))return null;let P=s(e.key),F=C?v:e.options??[];if(e.allow_multiple){let t=Array.isArray(E)?E:[];return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),(0,O.jsx)(`div`,{className:`rounded border p-2 text-[13px] ${P?.error?`border-red-300`:`border-black/10`} ${k?`bg-neutral-50`:`bg-white`}`,children:b?(0,O.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`Loading options...`}):F.length===0?(0,O.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`No options available`}):(0,O.jsx)(`div`,{className:`flex flex-col gap-1 max-h-48 overflow-y-auto`,children:F.map(e=>{let n=t.some(t=>t.value===e.value);return(0,O.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:n,disabled:k,onChange:()=>{M(n?t.filter(t=>t.value!==e.value):[...t,e])},className:`h-3 w-3 accent-blue-600`}),(0,O.jsx)(`span`,{className:`text-[12px]`,children:e.label})]},e.value)})})}),P?.showMessage&&P.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:P.message})]})}let I=E&&!Array.isArray(E)?E.value:``;return(0,O.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,O.jsx)(j,{field:e}),b?(0,O.jsx)(`div`,{className:`w-full rounded border border-black/10 px-2 py-1.5 text-[12px] text-neutral-400 bg-neutral-50`,children:`Loading options...`}):(0,O.jsxs)(`select`,{value:I,onChange:e=>{let t=F.find(t=>t.value===e.target.value);t&&M(t)},disabled:k,className:`w-full rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${P?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${k?`bg-neutral-50 text-neutral-400`:`bg-white`}`,children:[(0,O.jsx)(`option`,{value:``,children:e.placeholder??`Choose an option`}),F.map(e=>(0,O.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),P?.showMessage&&P.message&&(0,O.jsx)(`span`,{className:`text-[11px] text-red-500`,children:P.message})]})},boolean:k},N=({field:e,pluginApiName:t,disabled:n=!1})=>{let r=M[e.type];return(0,O.jsx)(r,{field:e,pluginApiName:t,disabled:n})},P=({apiName:e})=>{let t=b(e),[n,r]=(0,D.useState)(t?.__kizen_clean_config?JSON.stringify(t.__kizen_clean_config,null,2):`{}`),[i,a]=(0,D.useState)(null),[o,s]=(0,D.useState)(!1);return(0,O.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,O.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,O.jsx)(`p`,{className:`text-[13px] text-neutral-500 m-0`,children:`No setup assistant defined. Enter configuration as JSON.`})}),(0,O.jsx)(`textarea`,{value:n,onChange:e=>{r(e.target.value),a(null),s(!1)},spellCheck:!1,className:`w-full min-h-[300px] rounded border p-3 text-[13px] font-mono leading-relaxed focus:outline-none focus:ring-1 ${i?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`}`}),i&&(0,O.jsxs)(`span`,{className:`text-[12px] text-red-500`,children:[`Parse error: `,i]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`button`,{onClick:()=>{try{y(e,JSON.parse(n)),a(null),s(!0),setTimeout(()=>{s(!1)},2e3)}catch(e){a(e instanceof Error?e.message:`Invalid JSON`),s(!1)}},className:`rounded bg-blue-600 px-4 py-1.5 text-[13px] font-medium text-white hover:bg-blue-700 active:bg-blue-800`,children:`Save Configuration`}),(0,O.jsx)(`button`,{onClick:()=>{S(e),r(`{}`),a(null),s(!1)},className:`rounded border border-black/10 px-4 py-1.5 text-[13px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:`Reset`}),o&&(0,O.jsx)(`span`,{className:`text-[12px] text-green-600 font-medium`,children:`Saved`})]})]})},F=({config:e,apiName:t,loadFn:n,saveFn:r,clearFn:i})=>{let a=n(t)?.__kizen_setup_assistant_values,o=(0,D.useRef)({}),[s,c]=(0,D.useState)(!1),u=l(),f=d(),p=(0,D.useCallback)(async e=>{try{let t=await(await u(`/api/custom-objects?filters=${encodeURIComponent(JSON.stringify({api_name:e}))}`)).json(),n=Array.isArray(t)?t:t.results;if(n&&n.length>0)return n}catch{}let t=f?.business.client_object;if(t?.access&&t.name===e)return[{id:t.id,object_name:t.object_name}]},[u,f]),m=(0,D.useCallback)(async e=>{try{let[t,n]=await Promise.all([u(`/api/custom-objects/${e}`),u(`/api/custom-objects/${e}/fields`)]),r=await t.json(),i=await n.json(),a=Array.isArray(i)?i:i.results??[];return{id:e,objectName:r.object_name??``,fields:a.map(e=>({id:e.id,name:e.name,displayName:e.display_name}))}}catch{return{id:e,objectName:``,fields:[]}}},[u]),h=(0,D.useCallback)(e=>{o.current=e},[]);return(0,O.jsx)(C,{config:e,value:a,onStateChange:h,disabledKeys:[],getObjectByAPIName:p,getCustomObjectDetails:m,children:(0,O.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[e.fields?.map(e=>(0,O.jsx)(N,{field:e,pluginApiName:t},e.key)),(0,O.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,O.jsx)(`button`,{onClick:()=>{let n=o.current;r(t,n,e),c(!0),setTimeout(()=>{c(!1)},2e3)},className:`rounded bg-blue-600 px-4 py-1.5 text-[13px] font-medium text-white hover:bg-blue-700 active:bg-blue-800`,children:`Save Configuration`}),(0,O.jsx)(`button`,{onClick:()=>{i(t),window.location.reload()},className:`rounded border border-black/10 px-4 py-1.5 text-[13px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:`Reset`}),s&&(0,O.jsx)(`span`,{className:`text-[12px] text-green-600 font-medium`,children:`Saved`})]})]})})},I=({config:e,apiName:n,loadFn:i,saveFn:a,clearFn:o})=>{let s=d(),c=l(),{environment:f}=E(),p=u[f],[m,h]=(0,D.useState)(!1),[g,v]=(0,D.useState)(!1);return s?(0,O.jsx)(_,{appPath:p,user:{id:s.team.user,crm_client_id:``},business:s.business,clientObject:s.business.client_object?{id:s.business.client_object.id,objectName:s.business.client_object.object_name}:void 0,teamMember:s.team,onNavigate:()=>{},performFileUpload:()=>Promise.resolve({url:``}),monitoringExceptionHelper:()=>{},performRequest:async(e,t,n,r)=>{let i=n?.headers,a=r instanceof FormData||r instanceof Blob,o=r!=null&&!a?{"Content-Type":`application/json`,...i}:i,s=await c(t,{method:e.toUpperCase(),...r!=null&&{body:a?r:JSON.stringify(r)},...o!=null&&{headers:o}});return s.status===204||s.headers.get(`content-length`)===`0`?{data:{}}:{data:await s.json()}},modal:{showing:m,show:g,showPrompt:()=>{h(!0),v(!0)},onConfirm:()=>{h(!1),v(!1)},onHide:()=>{h(!1),v(!1)}},showToast:()=>{},clearToasts:()=>{},children:()=>(0,O.jsx)(F,{config:e,apiName:n,loadFn:i,saveFn:a,clearFn:o})}):(0,O.jsx)(t,{icon:r,className:`animate-spin text-neutral-400`})},L=()=>{let{apiName:e}=c({strict:!1}),{data:t,isLoading:n,isError:r}=o(a);if(n)return(0,O.jsx)(s,{children:(0,O.jsx)(`p`,{className:`m-0 text-[13px] text-neutral-400`,children:`Fetching bundle.json…`})});if(r)return(0,O.jsx)(s,{children:(0,O.jsx)(`p`,{className:`m-0 text-[13px] text-red-700`,children:`Could not load bundle.json.`})});let i=t?.find(t=>t.api_name===e);if(!i)return(0,O.jsx)(s,{children:(0,O.jsxs)(`p`,{className:`m-0 text-[13px] text-neutral-500`,children:[`No app found with api_name`,` `,(0,O.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 py-0.5`,children:e}),`.`]})});let l=i.base_config,u=l?.setup_assistant,d=l?.user_setup_assistant,f=(u?.fields?.length??0)>0,m=(d?.fields?.length??0)>0;return!f&&!m?(0,O.jsx)(s,{children:(0,O.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-[15px] font-bold text-neutral-900 m-0`,children:`Configuration`}),(0,O.jsx)(`p`,{className:`text-[12px] text-neutral-400 m-0 mt-1`,children:`Enter plugin configuration as JSON.`})]}),(0,O.jsx)(P,{apiName:e??``})]})}):(0,O.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[f&&u&&(0,O.jsx)(s,{className:`lg:flex-1 lg:min-w-0`,children:(0,O.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-[15px] font-bold text-neutral-900 m-0`,children:`Business Configuration`}),(0,O.jsxs)(`p`,{className:`text-[12px] text-neutral-400 m-0 mt-1`,children:[`Configure the business-level setup assistant fields. These values are shared across the whole business and exposed to plugin scripts at`,` `,(0,O.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 font-mono text-[11px]`,children:`this.config`}),`.`]})]}),(0,O.jsx)(I,{config:u,apiName:e??``,loadFn:b,saveFn:p,clearFn:S})]})}),m&&d&&(0,O.jsx)(s,{className:`lg:flex-1 lg:min-w-0`,children:(0,O.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`h2`,{className:`text-[15px] font-bold text-neutral-900 m-0`,children:`User Configuration`}),(0,O.jsxs)(`p`,{className:`text-[12px] text-neutral-400 m-0 mt-1`,children:[`Configure the per-user setup assistant fields. These values are scoped to the logged-in user and exposed to plugin scripts at`,` `,(0,O.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 font-mono text-[11px]`,children:`this.userConfig`}),`.`]})]}),(0,O.jsx)(I,{config:d,apiName:e??``,loadFn:g,saveFn:x,clearFn:v})]})})]})};export{L as ConfigurationPage};