File "AppListContainer-1.0.13-5c0fb7c4.js"

Full Path: /home/vantageo/public_html/cache/.wp-cli/wp-content/plugins/wp-data-access/assets/dist/AppListContainer-1.0.13-5c0fb7c4.js
File size: 42.51 KB
MIME-type: text/plain
Charset: utf-8

import{r as j,j as e,s as os,l as a,a as ps,b as ls,A as v,g as Oe,c as cs,e as u,C as D,d as ds,f as us,h as xs,i as hs,k as ms,m as gs,n as fs,o as js,p as bs,q as As,t as ys,u as Ts,R as X,v as pe,w as Cs,x as Ss,P as vs,y as De,z as Fe,B as Ms,D as he,E as Ds,F as Ie,G as Be,H as Re,I as ke,J as Is,K as we,L as Rs,M as ks,N as Ne,O as Le,Q as ws,S as Ns,T as Ls,U as Es,V as Ps,W as _s,X as Ee,Y as zs,Z as be,$ as Os}from"./main-1.0.13.js";import{A as se,a as Fs}from"./AdminTheme-1.0.13-a1e60de2.js";import{u as P,B as o,a as W,M as Bs,b as Ws,c as ce,d as Gs,e as ue,T as $,f as qs,A as We,g as Ge,h as qe,i as me,j as Hs,k as $s,l as Ys,m as Js,n as Vs,o as Zs,p as Ks,S as Qs,q as Xs,r as Us,s as He,D as H,v as et,t as st,w as tt,x as rt,y as nt,z as at}from"./main-1.0.13-4cbe632d.js";import{T as Ae,C as ne,s as it,S as ae,R as ot,a as ye,B as pt,b as lt,c as ct,d as dt,e as Te}from"./settings-1.0.13-650559d5.js";import{C as $e,a as Ye,b as Je,u as je}from"./useApp-1.0.13-075adc22.js";import{A as _,a as z}from"./AccordionSummary-1.0.13-0885ed32.js";import{T as Z,F as B,I as Ve,S as Ze,a as G,A as ge,C as fe,b as Se}from"./TextField-1.0.13-7258d491.js";import{F as ut}from"./index.esm-1.0.13-0afa0259.js";import{l as Pe,g as xt,M as te}from"./MenuItem-1.0.13-e7719456.js";import{L as ht}from"./ListItemIcon-1.0.13-2bfd9865.js";import{s as mt,_ as le,u as gt,a as ft,T as re,c as jt,b as bt,I as Y,P as Ke}from"./iconBase-1.0.13-98e06aa9.js";import{L as At,M as yt}from"./Menu-1.0.13-2a06ef00.js";import{A as de,L as K}from"./Link-1.0.13-03de5435.js";import{B as J,C as ve,a as Me}from"./useScreenSize-1.0.13-fa31f819.js";import{P as Tt}from"./PremiumFeature-1.0.13-d257b3ff.js";import{F as ie}from"./FormControlLabel-1.0.13-143a10df.js";import{a as Ct,b as St,c as vt,d as Mt,e as Dt,f as It,g as Rt,h as kt,i as wt}from"./ActionsApp-1.0.13-9ce21fa9.js";import{R as Nt}from"./RadioGroup-1.0.13-1d87a31c.js";import{R as _e}from"./Radio-1.0.13-befab7cd.js";import{l as Lt,C as Et,a as Pt}from"./index-1.0.13-8e548ee7.js";import{T as Ce}from"./Tabs-1.0.13-f71c8d5c.js";import{F as _t}from"./FileSaver.min-1.0.13-c93578bb.js";import{c as zt}from"./index-1.0.13-93f67fc3.js";import{S as Ot,a as Ft,b as Bt}from"./Stepper-1.0.13-4e64ee4c.js";import{A as Wt}from"./AppMetaData-1.0.13-6be54eba.js";import{I as Gt}from"./InputAdornment-1.0.13-83724c3f.js";import"./Close-1.0.13-b137ce2f.js";import"./DialogContent-1.0.13-5873ffb9.js";import"./Checkbox-1.0.13-3ec10fcc.js";import"./ActionsExplorer-1.0.13-5e860b61.js";import"./useSlot-1.0.13-62ad37b6.js";import"./Alert-1.0.13-3cded9f0.js";import"./index.esm-1.0.13-8cdddba7.js";import"./AlertTitle-1.0.13-80063b16.js";const qt=["children","className","disableTypography","inset","primary","primaryTypographyProps","secondary","secondaryTypographyProps"],Ht=s=>{const{classes:r,inset:t,primary:i,secondary:x,dense:p}=s;return bt({root:["root",t&&"inset",p&&"dense",i&&x&&"multiline"],primary:["primary"],secondary:["secondary"]},xt,r)},$t=mt("div",{name:"MuiListItemText",slot:"Root",overridesResolver:(s,r)=>{const{ownerState:t}=s;return[{[`& .${Pe.primary}`]:r.primary},{[`& .${Pe.secondary}`]:r.secondary},r.root,t.inset&&r.inset,t.primary&&t.secondary&&r.multiline,t.dense&&r.dense]}})(({ownerState:s})=>le({flex:"1 1 auto",minWidth:0,marginTop:4,marginBottom:4},s.primary&&s.secondary&&{marginTop:6,marginBottom:6},s.inset&&{paddingLeft:56})),Yt=j.forwardRef(function(r,t){const i=gt({props:r,name:"MuiListItemText"}),{children:x,className:p,disableTypography:c=!1,inset:m=!1,primary:y,primaryTypographyProps:l,secondary:d,secondaryTypographyProps:g}=i,C=ft(i,qt),{dense:M}=j.useContext(At);let S=y??x,f=d;const b=le({},i,{disableTypography:c,inset:m,primary:!!S,secondary:!!f,dense:M}),L=Ht(b);return S!=null&&S.type!==re&&!c&&(S=e.jsx(re,le({variant:M?"body2":"body1",className:L.primary,component:l!=null&&l.variant?void 0:"span",display:"block"},l,{children:S}))),f!=null&&f.type!==re&&!c&&(f=e.jsx(re,le({variant:"body2",className:L.secondary,color:"text.secondary",display:"block"},g,{children:f}))),e.jsxs($t,le({className:jt(L.root,p),ownerState:b,ref:t},C,{children:[S,f]}))}),Jt=Yt,Vt=()=>{const s=P(r=>os(r));return a.debug("appApps",s),s},Zt=({app:s,setIsUpdated:r})=>(a.debug(s),e.jsxs(o,{children:[e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx($e,{setIsUpdated:r})})}),e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(Ye,{setIsUpdated:r})})}),e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(Je,{app:s,setIsUpdated:r})})})]})),Qe=({app:s,hasErrors:r,setIsUpdated:t})=>{a.debug(s,r);const i=W();return e.jsx(Z,{type:"text",label:"App Name",error:r,fullWidth:!0,required:!0,helperText:"App name must be unique.",value:s.appName,autoFocus:!0,autoComplete:"off",onChange:x=>{i(ps({appName:x.target.value})),t&&t(!0)}})},Xe=({app:s,hasErrors:r,setIsUpdated:t})=>{a.debug(s,r);const i=W();return e.jsx(Z,{type:"text",label:"App Title",error:r,fullWidth:!0,required:!0,helperText:"App title describes the purpose of the app.",value:s.appTitle,autoComplete:"off",onChange:x=>{i(ls({appTitle:x.target.value})),t&&t(!0)}})},Ue=({appType:s})=>s==v.APPCONTAINER?e.jsx(o,{sx:{fontSize:"26px",display:"flex",width:"28px",justifyContent:"center",alignContent:"center",marginRight:"5px"},children:e.jsx(Bs,{})}):s==v.DATAENTRY?e.jsx(o,{sx:{fontSize:"22px",display:"flex",width:"28px",justifyContent:"center",alignContent:"center",marginRight:"5px"},children:e.jsx(Ws,{})}):e.jsx(o,{sx:{fontSize:"20px",display:"flex",width:"28px",justifyContent:"center",alignContent:"center",marginRight:"5px"},children:e.jsx(ut,{})}),es=({app:s,isNew:r,setIsUpdated:t})=>{a.debug(s);const i=W(),x=Oe(),p=r?"Select App Type *":"App Type *";return e.jsxs(B,{fullWidth:!0,children:[e.jsx(Ve,{variant:"outlined",children:p}),e.jsxs(Ze,{MenuProps:{id:"pp-select-menu"},label:p,value:s.appType,disabled:r!==!0&&s.appType==v.APPCONTAINER,onChange:c=>{i(cs({appType:c.target.value})),t&&t(!0)},sx:{"& .MuiSelect-select":{display:"flex",alignItems:"center"}},children:[...x.map(c=>{let m=c.id===v.DATATABLE||c.id===v.DATAENTRY||c.id===v.APPCONTAINER;return r!==!0&&c.id===v.APPCONTAINER&&(m=!1),e.jsxs(te,{value:c.id,disabled:!m,children:[e.jsx(ht,{sx:{minWidth:"unset"},children:e.jsx(Ue,{appType:c.id})}),e.jsx(Jt,{children:c.text})]})})]}),e.jsxs(G,{children:["Select ",e.jsx("strong",{children:"Data Table"})," to create a read-only app, or ",e.jsx("strong",{children:"Data Administration"})," to enable transactions. To create an app that contains one or more other apps, select ",e.jsx("strong",{children:"Data App"}),"."]})]})},Kt=({app:s})=>{a.debug(s);const[r,t]=j.useState(!1),[i,x]=j.useState(void 0),p=()=>{switch(i){case"form":return"Reset Form Builder?";case"theme":return"Reset Theme?";default:return"Reset Table Builder?"}};return e.jsxs(e.Fragment,{children:[e.jsxs(_,{disableGutters:!0,children:[e.jsx(z,{expandIcon:e.jsx(ce,{}),children:"Reset"}),e.jsx(de,{children:e.jsxs(B,{sx:{display:"grid",gridGap:"20px"},children:[e.jsx(J,{variant:"contained",color:"primary",onClick:()=>{x(Ae.TABLE),t(!0)},children:"Reset Table Builder"}),e.jsx(J,{variant:"contained",color:"primary",onClick:()=>{x(Ae.FORM),t(!0)},children:"Reset Form Builder"}),e.jsx(J,{variant:"contained",color:"primary",onClick:()=>{x(Ae.THEME),t(!0)},children:"Reset Theme"}),e.jsxs(G,{sx:{display:"inline-grid",gridTemplateColumns:"20px auto",gridGap:"5px",alignItems:"center","& svg":{fontSize:"20px"}},error:!0,children:[e.jsx(Gs,{}),"A reset cannot be undone!"]})]})})]}),e.jsx(ne,{title:p(),message:"Are you sure? This action cannot be undone!",open:r,setOpen:t,onConfirm:()=>{i!==void 0&&it(s.appDbId,s.appCntId,i,null,null,c=>{if(c!=null&&c.code&&(c==null?void 0:c.message)!==void 0)switch(c.code){case"ok":u(c.message,{variant:"success"});break;case"info":u(c.message,{variant:"info"});break;default:u(c.message??D.contactSupport,{variant:"error"})}else a.error(c),u(D.contactSupport,{variant:"error"})},c=>{a.error("error",c),u(c??D.contactSupport,{variant:"error"})})}})]})},ss=()=>{const s=P(r=>ds(r));return a.debug("appMetaData",s),s},Qt=()=>{const s=P(r=>us());return a.debug("appLanguage",s),s},ts=({app:s,setIsUpdated:r})=>{a.debug(s);const t=W();ss();const i=Qt(),x=P(m=>xs(m));a.debug("updateSiteLanguage",x),j.useEffect(()=>{const m={appLanguage:hs.code};t(ms(m))},[]);const[p,c]=j.useState(!1);return e.jsxs(o,{sx:{width:"100%"},children:[e.jsxs(B,{fullWidth:!0,disabled:!0,children:[e.jsx(Ve,{variant:"outlined",children:"App Language"}),e.jsxs(Ze,{MenuProps:{id:"pp-select-menu"},label:"App Language",value:i,onChange:m=>{},children:[...gs.map(m=>e.jsx(te,{value:m.code,children:m.language},m.code))]}),e.jsx(G,{children:"Selected app language is applied to all (master and detail) tables and forms."})]}),!1,e.jsx(B,{children:e.jsxs(G,{component:"div",sx:{marginLeft:0},children:[e.jsx(o,{sx:{marginTop:"20px"},children:e.jsxs(K,{sx:{textDecoration:"none",cursor:"pointer",display:"inline-flex","& svg":{fontSize:"1rem",marginRight:"2px"}},onClick:()=>c(!p),children:[e.jsx(ue,{}),"Which app information is localized?"]})}),p&&e.jsxs(e.Fragment,{children:[e.jsxs(o,{sx:{marginTop:"20px"},children:[e.jsx("strong",{children:"Information provided in the selected app language:"}),e.jsxs("ul",{style:{listStyle:"disc",padding:"0 40px"},children:[e.jsx("li",{children:"Tooltips"}),e.jsx("li",{children:"Field labels"}),e.jsx("li",{children:"Field hints"}),e.jsx("li",{children:"Info and success messages"}),e.jsx("li",{children:"Most error messages"})]})]}),e.jsxs(o,{sx:{marginTop:"20px"},children:[e.jsx("strong",{children:"Information not provided in the selected language:"}),e.jsxs("ul",{style:{listStyle:"disc",padding:"0 40px"},children:[e.jsx("li",{children:"Builders, Wizards and Managers are provided in English"}),e.jsx("li",{children:"Database and server errors are not translated"})]})]}),e.jsx(o,{sx:{marginTop:"20px"},children:"If you discover any translation errors, please let us know. We are committed to improving our translations."})]})]})}),e.jsx(Tt,{})]})},Xt=()=>{const s=P(r=>fs(r));return a.debug("appFullscreen",s),s},Ut=()=>{const s=P(r=>js(r));return a.debug("appSafeMode",s),s},er=({app:s,setIsUpdated:r})=>{a.debug(s);const t=W(),i=Xt(),x=Ut();return e.jsxs(e.Fragment,{children:[e.jsx(ie,{control:e.jsx(ae,{checked:i,onChange:(p,c)=>{t(bs({fullScreen:c})),r&&r(!0),p.stopPropagation()}}),label:"Enable full screen support",labelPlacement:"end"}),e.jsx(B,{fullWidth:!0,children:e.jsx(G,{children:"Adds an icon to the app toolbar, allowing the user to switch to full-screen mode."})}),e.jsx(ie,{control:e.jsx(ae,{checked:x,onChange:(p,c)=>{t(As({safeMode:c})),r&&r(!0),p.stopPropagation()}}),label:"Enable safe mode",labelPlacement:"end"}),e.jsx(B,{fullWidth:!0,children:e.jsx(G,{children:"Disables all custom code, including hooks and computed code fields."})})]})},sr=({app:s,setIsUpdated:r})=>(a.debug(s),e.jsxs(o,{children:[e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(Qe,{app:s,hasErrors:!1,setIsUpdated:r})})}),e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(Xe,{app:s,hasErrors:!1,setIsUpdated:r})})}),e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(es,{app:s,setIsUpdated:r})})}),e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(ts,{app:s,setIsUpdated:r})})}),e.jsxs(_,{disableGutters:!0,children:[e.jsx(z,{expandIcon:e.jsx(ce,{}),children:"Settings"}),e.jsx(de,{children:e.jsx(er,{app:s,setIsUpdated:r})})]}),e.jsx(Kt,{app:s})]})),rs=()=>{const s=P(r=>ys(r));return a.debug("apps",s),s},ns=({app:s,setIsUpdated:r})=>{const t=W(),[i,x]=j.useState(!1),p=rs(),c=p.filter(l=>s.appDbId!==l.appId&&l.appType!=v.APPCONTAINER),m=[];s.appApps.map(l=>{const d=p.filter(g=>g.appId===l);d.length===1&&m.push(d[0])});const y=l=>l.appName+(i?" ("+l.appTitle+")":"");return e.jsxs(B,{sx:{width:"100%",marginTop:"8px"},children:[e.jsx(ge,{multiple:!0,options:c,value:m,disableCloseOnSelect:!0,getOptionLabel:l=>y(l),onChange:(l,d)=>{t(Ts({appApps:d.map(g=>g.appId)})),r&&r(!0),l.stopPropagation()},renderInput:l=>e.jsx(Z,{...l,label:"Apps"}),renderTags:(l,d)=>l.map((g,C)=>{const{key:M,...S}=d({index:C});return e.jsx(fe,{variant:"outlined",label:y(g),...S},M)})}),e.jsxs(G,{component:"div",sx:{display:"grid",gridTemplateColumns:"auto auto",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:"Apps will be added in the order they are entered here."}),e.jsx(ie,{sx:{"& span.MuiFormControlLabel-label":{fontSize:"0.75rem"}},control:e.jsx(ae,{checked:i,onChange:l=>{x(!i),l.stopPropagation()}}),label:"Show title",labelPlacement:"end"})]})]})},tr=({app:s,setIsUpdated:r})=>e.jsx(_,{disableGutters:!0,children:e.jsx(z,{children:e.jsx(ns,{app:s,setIsUpdated:r})})}),as=({setIsUpdated:s})=>{const r=W(),t=je(),i=ss(),x=j.useMemo(()=>{const d=[];if((i==null?void 0:i.roles)!==void 0)for(const g in i.roles)d.push({key:g,value:i.roles[g]});return d},[i.roles]);a.debug(x);const p=j.useMemo(()=>{const d=[];if((i==null?void 0:i.users)!==void 0)for(const g in i.users)d.push({key:g,value:i.users[g]});return d},[i.users]);a.debug(p);const c=j.useMemo(()=>x.filter(d=>t.appRestApi.authorized_roles.includes(d.key)),[t.appRestApi.authorized_roles,x]),m=j.useMemo(()=>p.filter(d=>t.appRestApi.authorized_users.includes(d.key)),[t.appRestApi.authorized_users,p]),[y,l]=j.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("fieldset",{className:"pp-fieldset",style:{padding:"20px"},children:[e.jsx("legend",{children:"Authorization"}),e.jsx(B,{sx:{width:"100%"},children:e.jsxs(Nt,{children:[e.jsxs(Se,{className:"align-label-radio",sx:{cursor:"pointer"},children:[e.jsx(_e,{checked:t.appRestApi.authorization===X.AUTHORIZED,onChange:d=>{r(pe({restApiActions:{...t.appRestApi,authorization:X.AUTHORIZED}})),s&&s(!0),d.stopPropagation()}}),"Authorized access only"]}),e.jsxs(o,{sx:{display:"grid",gridGap:"10px",margin:"20px 20px 15px 42px"},children:[e.jsx(ge,{multiple:!0,options:x,disableCloseOnSelect:!0,getOptionLabel:d=>d.value,value:c,onChange:(d,g)=>{r(pe({restApiActions:{...t.appRestApi,authorized_roles:g.map(C=>C.key)}})),s&&s(!0),d.stopPropagation()},renderInput:d=>e.jsx(Z,{...d,label:"Roles"}),renderTags:(d,g)=>d.map((C,M)=>{const{key:S,...f}=g({index:M});return e.jsx(fe,{variant:"outlined",label:C.value,...f},S)})}),e.jsx(ge,{multiple:!0,options:p,disableCloseOnSelect:!0,getOptionLabel:d=>d.value,value:m,onChange:(d,g)=>{r(pe({restApiActions:{...t.appRestApi,authorized_users:g.map(C=>C.key)}})),s&&s(!0),d.stopPropagation()},renderInput:d=>e.jsx(Z,{...d,label:"Users"}),renderTags:(d,g)=>d.map((C,M)=>{const{key:S,...f}=g({index:M});return e.jsx(fe,{variant:"outlined",label:C.value,...f},S)})})]}),e.jsxs(Se,{className:"align-label-radio",sx:{cursor:"pointer"},children:[e.jsx(_e,{checked:t.appRestApi.authorization===X.ANONYMOUS,onChange:d=>{r(pe({restApiActions:{...t.appRestApi,authorization:X.ANONYMOUS}})),s&&s(!0),d.stopPropagation()}}),"Anonymous access"]})]})})]}),e.jsx(B,{children:e.jsxs(G,{component:"div",sx:{marginLeft:0},children:[e.jsx(o,{sx:{marginTop:"25px"},children:e.jsxs(K,{sx:{textDecoration:"none",cursor:"pointer",display:"inline-flex","& svg":{fontSize:"1rem",marginRight:"2px"}},onClick:()=>l(!y),children:[e.jsx(ue,{}),"What is the difference between authorized and anonymous access?"]})}),y&&e.jsxs(e.Fragment,{children:[e.jsxs(o,{sx:{marginTop:"20px"},children:[e.jsx("strong",{children:"Authorized access:"}),e.jsxs("ul",{style:{listStyle:"disc",padding:"0 40px"},children:[e.jsx("li",{children:"Users with the selected roles can access this app"}),e.jsx("li",{children:"Selected users can access this app"}),e.jsx("li",{children:"Other registered users cannot access this app"}),e.jsx("li",{children:"Anonymous users cannot access this app"})]})]}),e.jsxs(o,{sx:{marginTop:"20px"},children:[e.jsx("strong",{children:"Anonymous access:"}),e.jsx("ul",{style:{listStyle:"disc",padding:"0 40px"},children:e.jsx("li",{children:"Any user can access this app"})})]}),e.jsx(o,{sx:{marginTop:"20px"},children:"App authorization is applied to both back-end and front-end usage. Back-end access is restricted to registered users only. A Data Table app displayed on the front-end typically allows anonymous access, enabling visitors to view the table. In contrast, Data Management apps usually require authorized access to prevent unauthorized users from altering table data."})]})]})})]})},rr=({app:s,setIsUpdated:r})=>{a.debug(s);const t=W(),[i,x]=j.useState(!1);return e.jsxs(o,{sx:{display:"grid",gridGap:"30px"},children:[e.jsxs(o,{children:[e.jsx(o,{children:e.jsx(ie,{control:e.jsx(ae,{checked:s.appAddToMenu,onChange:(p,c)=>{t(Cs({appAddToMenu:c})),r&&r(!0),p.stopPropagation()}}),label:"Add App to WordPress dashboard menu",labelPlacement:"end"})}),e.jsx(B,{children:e.jsxs(G,{component:"div",children:[e.jsx(o,{children:e.jsxs(K,{sx:{textDecoration:"none",cursor:"pointer",display:"inline-flex","& svg":{fontSize:"1rem",marginRight:"2px"}},onClick:()=>x(!i),children:[e.jsx(ue,{}),"What is a WordPress dashboard menu?"]})}),i&&e.jsx(o,{sx:{marginTop:"20px"},children:"The WordPress dashboard provides a navigation menu with options to navigate to built-in or custom pages. Enabling this option adds a menu item to the WordPress dashboard for all authorized users, allowing easy access to this app."})]})})]}),s.appAddToMenu&&e.jsx(Z,{type:"text",label:"Title",fullWidth:!0,required:!0,helperText:"Title shown in WordPress dashboard menu.",value:s.appMenuTitle,autoComplete:"off",onChange:p=>{t(Ss({appMenuTitle:p.target.value})),r&&r(!0),p.stopPropagation()}})]})},nr=({app:s,setIsUpdated:r})=>{a.debug(s);const t=()=>`[wpda_app app_id="${s.appDbId}"${i?' feedback="true"':""}${m?' builders="false"':""}]`,[i,x]=j.useState(!1),[p,c]=j.useState(!1),[m,y]=j.useState(!1),[l,d]=j.useState(!1),[g,C]=j.useState(t());return j.useEffect(()=>{C(t())},[i,m]),e.jsxs(o,{sx:{display:"grid",gridGap:"20px"},children:[e.jsxs(o,{children:[e.jsxs(Se,{children:["App short code",e.jsx(o,{sx:{marginLeft:"5px",display:"inline-block"},children:e.jsx(Lt.CopyToClipboard,{text:g,onCopy:()=>{u("Shortcode was copied to your clipboard",{variant:"info"})},children:e.jsx($,{title:"Copy shortcode to clipboard",children:e.jsx(Y,{children:e.jsx(qs,{})})})})})]}),e.jsx(o,{sx:{display:"grid",gridTemplateColumns:"auto auto",justifyContent:"space-between",alignItems:"center","& pre":{backgroundColor:"#ccc",padding:"4px"}},children:e.jsx("pre",{children:g})})]}),e.jsx(o,{children:e.jsxs(B,{children:[e.jsx(ie,{control:e.jsx(ae,{checked:i,onChange:(M,S)=>{x(S),r&&r(!0),M.stopPropagation()}}),label:"Feedback",labelPlacement:"end"}),e.jsxs(G,{component:"div",children:[e.jsxs(K,{sx:{textDecoration:"none",cursor:"pointer",display:"inline-flex","& svg":{fontSize:"1rem",marginRight:"2px"}},onClick:()=>{c(!p)},children:[e.jsx(ue,{}),"Show authorization and usage errors"]}),p&&e.jsx(o,{sx:{marginTop:"20px"},children:"Authorization and usage errors are hidden by default to prevent errors from appearing on front-end pages for unauthorized users. If you want to display authorization and usage errors, enable feedback."})]})]})}),e.jsx(o,{children:e.jsxs(B,{children:[e.jsx(ie,{control:e.jsx(ae,{checked:m,onChange:(M,S)=>{y(S),r&&r(!0),M.stopPropagation()}}),label:"Disable builders on front-end",labelPlacement:"end"}),e.jsxs(G,{component:"div",children:[e.jsxs(K,{sx:{textDecoration:"none",cursor:"pointer",display:"inline-flex","& svg":{fontSize:"1rem",marginRight:"2px"}},onClick:()=>{d(!l)},children:[e.jsx(ue,{}),"Disables builder access for administrators"]}),l&&e.jsx(o,{sx:{marginTop:"20px"},children:"Builder access is automatically enabled on front-end pages for administrators, allowing them to change app settings directly. Disabling builder access will remove all Table Builder and Form Builder icons from these pages. Please note that anonymous users and non-admin users cannot see these builder icons and have no access to app settings."})]})]})})]})},ar=({app:s,setIsUpdated:r})=>(a.debug(s),e.jsxs(o,{children:[e.jsxs(_,{disableGutters:!0,children:[e.jsx(z,{expandIcon:e.jsx(ce,{}),children:"Authorize Roles & Users"}),e.jsx(de,{children:e.jsx(as,{setIsUpdated:r})})]}),e.jsxs(_,{disableGutters:!0,children:[e.jsx(z,{expandIcon:e.jsx(ce,{}),children:"Back-end Access"}),e.jsx(de,{children:e.jsx(rr,{app:s,setIsUpdated:r})})]}),e.jsxs(_,{disableGutters:!0,children:[e.jsx(z,{expandIcon:e.jsx(ce,{}),children:"Front-end Access"}),e.jsx(de,{children:e.jsx(nr,{app:s})})]})]})),ir=({appDbId:s})=>{var L,E;a.debug(s);const r=W(),t=je(),i=((L=se)==null?void 0:L.palette.mode)===vs.LIGHT?(E=se)==null?void 0:E.palette.primary.main:"",[x,p]=j.useState(!1);a.debug(x);const[c,m]=j.useState(!1);a.debug(c);const y=()=>{r(Fe({}))},l=()=>{x?m(!0):y()},d=()=>{if(!t.appName)return u("App name is required",{variant:"error"}),!1;if(!t.appTitle)return u("App title is required",{variant:"error"}),!1;if(t.appType==v.APPCONTAINER)t.appApps.length===0&&u("No apps added",{variant:"info"});else{if(!t.appDatabase)return u("Database is required",{variant:"error"}),!1;if(!t.appTable)return u("Table is required",{variant:"error"}),!1;if(t.appColumns.filter(A=>A.isSelected).length===0)return u("At least one column must be selected",{variant:"error"}),!1}return!0},g=()=>{d()&&Ct(t,A=>{if(a.debug(A),A!=null&&A.code&&(A==null?void 0:A.message)!==void 0)switch(A.code){case"ok":u(A.message,{variant:"success"}),r(he({}));break;case"info":u(A.message,{variant:"info"});break;default:a.error(A),u(A.message??D.contactSupport,{variant:"error"})}else a.error(A),u(D.contactSupport,{variant:"error"})},A=>{a.error("error",A),u(A??D.contactSupport,{variant:"error"})})},C=()=>{d()&&(g(),y())},M=A=>{r(Ms({anchor:A}))},[S,f]=j.useState("1"),b=(A,q)=>{f(q)};return e.jsxs(e.Fragment,{children:[e.jsxs(ot,{closeDrawer:l,children:[e.jsx(We,{position:"static",elevation:4,sx:{borderRadius:0},children:e.jsxs(Ge,{className:"pp-setting-toolbar",sx:{borderRadius:0},children:[e.jsxs(o,{sx:{flexGrow:1},children:[e.jsx(re,{variant:"h5",noWrap:!0,component:"div",className:"unselectable",sx:{display:{xs:"none",sm:"block"},paddingLeft:"6px"},children:"Manage App"}),e.jsx(re,{sx:{fontSize:"10px",display:{xs:"none",sm:"block"},paddingLeft:"10px"},children:t.appName})]}),e.jsx(ye,{title:"Dock to left",position:"bottom",children:e.jsx(Y,{onClick:()=>{M(De.LEFT)},size:"large",color:"inherit",sx:{fontSize:"1em"},children:e.jsx(pt,{})})}),e.jsx(ye,{title:"Dock to right",position:"bottom",children:e.jsx(Y,{onClick:()=>{M(De.RIGHT)},size:"large",color:"inherit",sx:{fontSize:"1em"},children:e.jsx(lt,{})})}),e.jsx(ye,{title:"Close",position:"bottom",children:e.jsx(Y,{onClick:l,size:"large",color:"inherit",sx:{fontSize:"1.4em"},children:e.jsx(qe,{})})})]})}),e.jsx(ve,{className:"pp-settings-container",children:e.jsx(Me,{sx:{padding:0,margin:0},children:e.jsxs(ct,{value:S,children:[e.jsxs(dt,{variant:"fullWidth",textColor:"primary",onChange:b,sx:{width:"100%",height:"80px",padding:0,margin:0,backgroundColor:"rgb(242, 242, 242)"},children:[e.jsx(Ce,{label:"App Info",value:"1",sx:{fontWeight:"bold",fontSize:"110%",height:"80px"}}),e.jsx(Ce,{label:t.appType==v.APPCONTAINER?"Apps":"Data Source",value:"2",sx:{fontWeight:"bold",fontSize:"110%",height:"80px"}}),e.jsx(Ce,{label:"Access",value:"3",sx:{fontWeight:"bold",fontSize:"110%",height:"80px"}})]}),e.jsxs(o,{sx:{margin:0,padding:0,overflowY:"auto",height:"calc(100vh - 250px)","& > div.MuiTabPanel-root":{padding:0}},children:[e.jsx(Te,{value:"1",children:e.jsx(sr,{app:t,setIsUpdated:p})}),e.jsx(Te,{value:"2",children:t.appType==v.APPCONTAINER?e.jsx(tr,{app:t,setIsUpdated:p}):e.jsx(Zt,{app:t,setIsUpdated:p})}),e.jsx(Te,{value:"3",children:e.jsx(ar,{app:t,setIsUpdated:p})})]})]})})}),e.jsx(ve,{className:"pp-setting-footer",sx:{borderRadius:0,backgroundColor:i},children:e.jsxs(Me,{className:"pp-setting-footer-buttons",sx:{borderRadius:0},children:[e.jsx(J,{variant:"outlined",className:"footer_action_button_apply",onClick:g,children:"Apply"}),e.jsx(J,{variant:"outlined",className:"footer_action_button",onClick:C,children:"OK"}),e.jsx(J,{variant:"outlined",className:"footer_action_button",onClick:l,children:"Cancel"})]})})]}),e.jsx(ne,{title:"Close App Manager?",message:"All uncommitted changes will be lost!",open:c,setOpen:m,onConfirm:()=>{y()},onKeep:()=>{y()}})]})},or=()=>{const s=P(r=>Ds(r));return a.debug("showAppStructure",s),s},ze=({app:s})=>{var E,A,q,V;a.debug(s);const r=W(),[t,i]=j.useState(!1),[x,p]=j.useState(!1),[c,m]=j.useState(!1),y=n=>{let O={};try{O=JSON.parse(n.app_settings)}catch(R){O.rest_api={authorization:X.AUTHORIZED,authorized_roles:[],authorized_users:[]},a.error("Invalid JSON - app settings"),a.error(R),u("Invalid JSON, check console",{variant:"error"})}return O},l=n=>{St(n,O=>{var h,T,F,Q,U,k,xe,ee;const R=O==null?void 0:O.data;if(a.debug("response data",R),R.app&&R.app.app&&Array.isArray(R.app.app)&&R.app.container&&Array.isArray(R.app.container)&&R.app.apps&&Array.isArray(R.app.apps)){const w=R.app.app[0];if(a.debug(w),w.app_type===v.APPCONTAINER.toString()){const I=y(w),oe=R.app.apps;a.debug(oe),r(Re({appDbId:n,appId:ke(n),appName:w.app_name,appTitle:w.app_title,appType:w.app_type,appCntId:0,appCntSeqNr:0,appDatabase:null,appTable:null,appColumns:[],appRelationTable:null,appRelationColumns:[],appRestApi:I==null?void 0:I.rest_api,appAddToMenu:w.app_add_to_menu!=="0",appMenuTitle:((h=I==null?void 0:I.settings)==null?void 0:h.app_menu_title)??w.app_title,appMetaData:R,appLanguage:(T=I==null?void 0:I.settings)==null?void 0:T.app_language,fullScreen:((F=I==null?void 0:I.settings)==null?void 0:F.app_fullscreen)??!0,safeMode:((Q=I==null?void 0:I.settings)==null?void 0:Q.app_safe_mode)??!1,appApps:oe}))}else{const I=R.app.container[0];a.debug(I);let oe=[];try{oe=JSON.parse(I.cnt_cls)}catch(is){a.error("Invalid JSON - app columns"),a.error(is),u("Invalid JSON, check console",{variant:"error"})}const N=y(w);r(Re({appDbId:n,appId:ke(n),appName:w.app_name,appTitle:w.app_title,appType:w.app_type,appCntId:I.cnt_id,appCntSeqNr:I.cnt_seq_nr,appDatabase:I.cnt_dbs,appTable:I.cnt_tbl,appColumns:oe,appRelationTable:null,appRelationColumns:[],appRestApi:N==null?void 0:N.rest_api,appAddToMenu:w.app_add_to_menu!=="0",appMenuTitle:((U=N==null?void 0:N.settings)==null?void 0:U.app_menu_title)??w.app_title,appMetaData:R,appLanguage:(k=N==null?void 0:N.settings)==null?void 0:k.app_language,fullScreen:((xe=N==null?void 0:N.settings)==null?void 0:xe.app_fullscreen)??!0,safeMode:((ee=N==null?void 0:N.settings)==null?void 0:ee.app_safe_mode)??!1}))}}else u(D.contactSupport,{variant:"error"})},O=>{a.error("error",O),u(O??D.contactSupport,{variant:"error"})})},d=()=>{vt(s.appId,n=>{if(a.debug(n),n!=null&&n.code&&(n==null?void 0:n.message)!==void 0)switch(n.code){case"ok":u(n.message,{variant:"success"}),r(he({}));break;case"info":u(n.message,{variant:"info"});break;default:a.error(n),u(n.message??D.contactSupport,{variant:"error"})}else a.error(n),u(D.contactSupport,{variant:"error"});i(!1)},n=>{a.error("error",n),u(n??D.contactSupport,{variant:"error"}),i(!1)})},g=()=>{Mt(s.appId,n=>{a.debug(n),n!=null&&n.code&&(n==null?void 0:n.message)!==void 0?n.data.data?_t(new Blob([n.data.data],{type:"text/json;charset=utf-8"}),"wpda-export-"+s.appName+".sql"):(a.error(n),u(n.message??D.contactSupport,{variant:"error"})):(a.error(n),u(D.contactSupport,{variant:"error"})),i(!1)},n=>{a.error("error",n),u(n??D.contactSupport,{variant:"error"}),i(!1)})},C=()=>{Dt(s.appId,n=>{if(a.debug(n),n!=null&&n.code&&(n==null?void 0:n.message)!==void 0)switch(n.code){case"ok":u(n.message,{variant:"success"}),r(he({}));break;case"info":u(n.message,{variant:"info"});break;default:a.error(n),u(n.message??D.contactSupport,{variant:"error"})}else a.error(n),u(D.contactSupport,{variant:"error"});m(!1)},n=>{a.error("error",n),u(n??D.contactSupport,{variant:"error"}),m(!1)})},M=me("(max-width:700px)"),S=me("(max-width:900px)"),[f,b]=j.useState(null),L=!!f;return e.jsxs(e.Fragment,{children:[e.jsxs(o,{sx:{display:"grid",gridTemplateColumns:"auto auto",justifyContent:"space-between",alignItems:"center",padding:"24px",...S&&{".pp-row-actions":{width:0}},"&:hover":{".pp-row-title":{display:S?"inline-block":"none"},".pp-row-actions":{visibility:S?"hidden":"visible"}}},children:[e.jsxs(o,{sx:{display:"grid",gridTemplateColumns:"auto auto",alignItems:"center"},children:[e.jsxs(o,{sx:{width:"100%",display:"grid",gridTemplateColumns:"auto 1fr",gridGap:"10px",justifyContent:"center",alignItems:"center"},children:[e.jsx(Ue,{appType:s.appType}),e.jsxs(o,{sx:{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"},children:[s.appName,e.jsxs(o,{className:"pp-row-title",sx:{display:"inline-block",marginLeft:"5px",fontSize:"80%"},children:["−",e.jsx(o,{sx:{display:"inline-block",width:"5px"}}),s.appTitle," (App ID: ",s.appId,")"]})]})]}),e.jsxs(o,{sx:{display:"grid",visibility:"hidden",gridTemplateColumns:"auto auto auto auto",gridGap:"10px",marginLeft:"10px",alignItems:"center"},className:"pp-row-actions",children:[e.jsx(o,{sx:{borderLeft:"1px solid black",height:"100%"}}),e.jsx($,{title:"Manage App",children:e.jsx(K,{sx:{cursor:"pointer"},underline:"none",onClick:n=>{l(s.appId),n.preventDefault(),n.stopPropagation()},children:"Manage"})}),e.jsx(o,{sx:{borderLeft:"1px solid black",height:"100%"}}),e.jsx($,{title:"Run & Build App",children:e.jsx(K,{sx:{cursor:"pointer"},underline:"none",onClick:n=>{r(Ie({isActive:!0,appDbId:s.appId})),n.preventDefault(),n.stopPropagation()},children:"Run & Build"})})]})]}),e.jsxs(o,{sx:{display:"grid",gridTemplateColumns:"auto auto auto auto auto auto auto",justifyContent:M?"end":"space-evenly",alignItems:"center"},children:[e.jsx(o,{sx:{paddingRight:"10px"},children:M?"":Be(s.appType)}),e.jsx($,{title:"Manage App",children:e.jsx(Y,{sx:{color:(E=se)==null?void 0:E.palette.primary.main},onClick:n=>{l(s.appId),n.preventDefault(),n.stopPropagation()},children:e.jsx(Hs,{})})}),e.jsx($,{title:"Run & Build App",children:e.jsx(Y,{sx:{color:(A=se)==null?void 0:A.palette.primary.main},onClick:n=>{r(Ie({isActive:!0,appDbId:s.appId})),n.preventDefault(),n.stopPropagation()},children:e.jsx($s,{})})}),e.jsx($,{title:"More App actions",children:e.jsx(Y,{sx:{color:(q=se)==null?void 0:q.palette.primary.main},onClick:n=>{b(n.currentTarget),n.preventDefault(),n.stopPropagation()},children:e.jsx(Ys,{})})}),e.jsxs(yt,{id:"pp-app-builder-more-actions",anchorEl:f,open:L,onClose:()=>{b(null)},MenuListProps:{"aria-labelledby":"pp-app-builder-more-actions"},sx:{zIndex:9999999999},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},children:[e.jsxs(te,{onClick:n=>{b(null),i(!0),n.preventDefault(),n.stopPropagation()},children:[e.jsx(Js,{}),e.jsx("span",{style:{margin:"0 10px"},children:"Copy"})]}),e.jsxs(te,{onClick:n=>{b(null),p(!0),n.preventDefault(),n.stopPropagation()},children:[e.jsx(Vs,{}),e.jsx("span",{style:{margin:"0 10px"},children:"Export"})]}),e.jsx(Et,{text:`[wpda_app app_id="${s.appId}"]`,onCopy:()=>{u(`Shortcode [wpda_app app_id="${s.appId}"] was copied to your clipboard`,{variant:"info"})},children:e.jsxs(te,{onClick:n=>{b(null),n.preventDefault(),n.stopPropagation()},children:[e.jsx(Zs,{}),e.jsx("span",{style:{margin:"0 10px"},children:"Shortcode"})]})}),e.jsxs(te,{onClick:n=>{b(null),m(!0),n.preventDefault(),n.stopPropagation()},sx:{color:(V=se)==null?void 0:V.palette.error.main},children:[e.jsx(Ks,{}),e.jsx("span",{style:{margin:"0 10px"},children:"Delete"})]})]})]})]}),t&&e.jsx(ne,{title:"Please confirm",message:"Copy this app including all containers?",open:t,setOpen:i,onConfirm:()=>d()}),x&&e.jsx(ne,{title:"Please confirm",message:"Export this app including all containers?",open:x,setOpen:p,onConfirm:()=>g()}),c&&e.jsx(ne,{title:"Delete App?",message:"Are you sure you want to delete app "+s.appName+"? This action cannot be undone!",open:c,setOpen:m,onConfirm:()=>C()})]})},pr=({apps:s,appApps:r,search:t,types:i,isLoading:x})=>{a.debug(s,r,t,i);const p=or(),c=l=>{if(i.length===0&&t.trim()==="")return!0;if(p&&r[l.appId]){let d=!1;if(r[l.appId].map(g=>{const C=s.filter(M=>M.appId==g)[0];we(C.appName+" "+C.appTitle,t)&&(d=!0),i.filter(M=>M.id===Number(C.appType)).length>0&&(d=!0)}),d)return!0}return!(!we(l.appName+" "+l.appTitle,t)||i.length>0&&i.filter(d=>d.id===Number(l.appType)).length===0)},m=s.filter(l=>c(l)?l:null),y=l=>r[l]?e.jsxs(o,{sx:{marginLeft:"64px","& > div":{borderTop:"1px solid #ddd",borderRadius:"0 !important"}},children:[...r[l].map(d=>{const g=s.filter(C=>C.appId==d);return g.length>0?e.jsx(ze,{app:g[0]}):null})]}):null;return e.jsx(Ke,{elevation:4,children:e.jsxs(o,{sx:{backgroundColor:"#fff",borderRadius:"4px","& .MuiBox-root:first-of-type":{borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},"& .MuiBox-root:hover":{backgroundColor:"rgb(242, 242, 242)"},"& .pp-app-details:nth-of-type(odd)":{backgroundColor:"#f9f9f9"}},children:[...s.map(l=>{const d=c(l);return p&&Object.keys(r).filter(g=>r[g].includes(Number(l.appId))).length>0?null:e.jsxs(o,{className:"pp-app-details",sx:{visibility:d?"visible":"hidden",position:d?"relative":"fixed",borderTop:"1px solid #ddd","&:first-of-type":{borderTop:"unset"}},children:[e.jsx(ze,{app:l}),p&&y(l.appId)]})}),m.length===0&&e.jsx(o,{sx:{padding:"35px",borderRadius:"4px"},children:x?e.jsx(Qs,{title:"Loading apps...",align:Is.LEFT}):e.jsx(o,{children:"No apps found"})})]})})},lr=({setMode:s})=>{const r=W(),t=je(),i=()=>t.appType===v.APPCONTAINER,x=i()?["App info","Apps","Authorization"]:["App info","Data source","Authorization"],[p,c]=j.useState(0);j.useEffect(()=>{let f=null;switch(t.appType){case v.DATATABLE:f=X.ANONYMOUS;break;case v.DATAENTRY:case v.MASTERDETAIL:case v.REGISTRATION:case v.UPDATEFORM:case v.APPCONTAINER:f=X.AUTHORIZED;break}f!==null?r(pe({restApiActions:Rs(f)})):u(D.contactSupport,{variant:"error"})},[t.appType]);const[m,y]=j.useState({appName:!1,appTitle:!1,appDatabase:!1,appTable:!1,appColumns:!1});a.debug(m);const l=()=>{const f=zt(ks);f.table.transactions.insert=Number(t.appType)===v.DATAENTRY||Number(t.appType)===v.MASTERDETAIL||Number(t.appType)===v.REGISTRATION,f.table.transactions.update=Number(t.appType)===v.DATAENTRY||Number(t.appType)===v.MASTERDETAIL||Number(t.appType)===v.UPDATEFORM,f.table.transactions.delete=Number(t.appType)===v.DATAENTRY||Number(t.appType)===v.MASTERDETAIL,It(t,f,b=>{if(a.debug(b),b!=null&&b.code&&(b==null?void 0:b.message)!==void 0)switch(b.code){case"ok":u(b.message,{variant:"success"}),s(H.TABLE),r(he({}));break;case"info":u(b.message,{variant:"info"});break;default:a.error(b),u(b.message??D.contactSupport,{variant:"error"})}else a.error(b),u(D.contactSupport,{variant:"error"})},b=>{a.error("error",b),u(b??D.contactSupport,{variant:"error"})}),t.updateSiteLanguage&&t.appLanguage!==void 0&&Rt(t.appLanguage,()=>{},()=>{})},d=()=>{var b,L;let f=!0;if(p===0){let E=!1,A=!1;t.appName.trim()===""&&(u("App name is required",{variant:"error"}),E=!0,f=!1),t.appTitle.trim()===""&&(u("App title is required",{variant:"error"}),A=!0,f=!1),y({...m,appName:E,appTitle:A})}if(p===1){let E=!1,A=!1,q=!1;i()?t.appApps.length===0&&u("No apps added",{variant:"info"}):(((b=t.appDatabase)==null?void 0:b.trim())===""&&(u("Database is required",{variant:"error"}),E=!0,f=!1),((L=t.appTable)==null?void 0:L.trim())===""&&(u("Table is required",{variant:"error"}),A=!0,f=!1),t.appColumns.filter(V=>V.isSelected===!0).length===0&&(u("No columns selected",{variant:"error"}),q=!0,f=!1)),y({...m,appDatabase:E,appTable:A,appColumns:q})}return p===x.length-1&&l(),a.debug(f),f},g=()=>e.jsxs(o,{sx:{textAlign:"right",display:"grid",gridTemplateColumns:"auto auto",justifyContent:"space-between",alignItems:"center"},children:[p>0?e.jsx(J,{variant:"outlined",size:"medium",sx:{width:"160px",marginRight:"10px"},onClick:()=>{c(p-1)},startIcon:e.jsx(Xs,{}),children:e.jsx(o,{children:"Back"})}):e.jsx(o,{}),e.jsx(J,{variant:"contained",size:"medium",sx:{width:"160px"},onClick:()=>{d()&&p<x.length-1&&c(p+1)},startIcon:p>=x.length-1&&e.jsx(Us,{}),endIcon:p<x.length-1&&e.jsx(He,{}),children:e.jsx(o,{children:p<x.length-1?"Next":"Finish"})})]}),C=()=>e.jsxs(e.Fragment,{children:[e.jsx(Qe,{app:t,hasErrors:m.appName}),e.jsx(Xe,{app:t,hasErrors:m.appName}),e.jsx(ts,{app:t}),g()]}),M=()=>i()?e.jsxs(e.Fragment,{children:[e.jsx(ns,{app:t}),g()]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{}),e.jsx(o,{sx:{display:t.appDatabase?"block":"none"},children:e.jsx(Ye,{})}),e.jsx(o,{sx:{display:t.appTable?"block":"none"},children:e.jsx(Je,{app:t})}),g()]}),S=()=>e.jsxs(e.Fragment,{children:[e.jsx(o,{children:e.jsx(as,{})}),g()]});return e.jsxs(e.Fragment,{children:[e.jsx(Ot,{activeStep:p,sx:{margin:"10px 0 30px 0"},children:x.map((f,b)=>(a.debug(f,b),e.jsx(Ft,{children:e.jsx(Bt,{children:f})},f)))}),e.jsxs("form",{onSubmit:f=>(f.preventDefault(),d()&&c(p+1),!1),style:{display:"grid",gridGap:"40px"},children:[p===0&&C(),p===1&&M(),p===2&&S(),e.jsx("input",{type:"submit",style:{display:"none"}})]})]})},cr=({setMode:s})=>{const r=je();a.debug(r);const[t,i]=j.useState(!1),[x,p]=j.useState(!1),c=t?`Add new ${Be(r.appType)} app`:"Add new app";return e.jsxs(e.Fragment,{children:[e.jsxs(ve,{sx:{padding:"50px 70px 40px 70px",display:"grid",gridGap:"40px"},elevation:4,children:[e.jsxs(o,{sx:{display:"grid",gridTemplateColumns:"auto auto",justifyContent:"space-between",alignItems:"start"},children:[e.jsx(Pt,{title:"App Wizard",subheader:c,sx:{padding:0}}),e.jsx(o,{children:e.jsx($,{title:"Close",children:e.jsx(K,{sx:{cursor:"pointer"},underline:"none",onClick:m=>{p(!0),m.preventDefault(),m.stopPropagation()},children:e.jsx(o,{sx:{fontSize:"1.5rem",color:"#000"},children:e.jsx(qe,{})})})})})]}),e.jsx(Me,{sx:{padding:0,display:"grid",gridGap:"30px"},children:t?e.jsx(lr,{setMode:s}):e.jsxs(o,{sx:{display:"grid",gap:"10px"},children:[e.jsx(es,{app:r,isNew:!0}),e.jsx(o,{sx:{textAlign:"end"},children:e.jsx(J,{variant:"contained",size:"medium",endIcon:e.jsx(He,{}),onClick:()=>{i(!0)},sx:{width:"160px"},children:"Start Wizard"})})]})})]}),e.jsx(ne,{title:"Close App Wizard?",message:"All uncommitted changes will be lost!",open:x,setOpen:p,onConfirm:()=>{s(H.TABLE)}})]})};const $r=()=>{const s=W(),r=j.useMemo(()=>et(),[]),[t,i]=j.useState(H.TABLE);a.debug(t),j.useEffect(()=>{const h=localStorage.getItem("ppAppsDbsSearch");h!==null&&s(Ne({dbSearch:h}));const T=localStorage.getItem("ppAppsDbsSearchType");if(T!==null){const F=JSON.parse(T);s(Le({dbTypes:F}))}},[]);const x=rs(),p=Vt(),c=P(h=>ws(h));a.debug("appDbId",c);const m=P(h=>Ns(h));a.debug("dbSearch",m);const y=P(h=>Ls(h));a.debug("dbTypes",y);const l=P(h=>Es(h));a.debug("designMode",l);const d=P(h=>Ps(h));a.debug("reload",d);const[g,C]=j.useState(!0);j.useEffect(()=>{S(),M()},[d]);const M=()=>{kt(function(h){const T=h==null?void 0:h.data;a.debug("response data",T);const F=h==null?void 0:h.context;if(a.debug("response context",F),Array.isArray(T)){const Q=[];for(let k=0;k<T.length;k++)Q.push({appId:T[k].app_id,appName:T[k].app_name,appTitle:T[k].app_title,appType:T[k].app_type,appSettings:T[k].app_settings,appAddToMenu:T[k].app_add_to_menu});const U=F.reduce((k,xe)=>{const{app_id:ee,app_id_detail:w}=xe;return k[ee]=k[ee]??[],k[ee].push(Number(w)),k},{});s(be({appList:Q,appApps:U}))}else a.error(T),u((T==null?void 0:T.message)??D.contactSupport,{variant:"error"}),s(be({appList:[],appApps:[]}));C(!1)},h=>{a.error("error",h),u(h??D.contactSupport,{variant:"error"}),s(be({appList:[],appApps:[]})),C(!1)})},S=()=>{wt(function(h){const T=h==null?void 0:h.data;a.debug("response data",T),s(Os({appMetaData:T}))},h=>{a.error("error",h),u(h??D.contactSupport,{variant:"error"})})};j.useEffect(()=>{t===H.TABLE&&S()},[t]),j.useEffect(()=>{_s.appPlugin&&(t===1||l.isActive===!0&&l.appDbId>0?window.document.documentElement.style.setProperty("--addAppIconVisibility","hidden"):window.document.documentElement.style.setProperty("--addAppIconVisibility","visible"),window.ppActionCreateApp=function(){t===0&&!(l.isActive===!0&&l.appDbId>0)&&i(H.FORM)})},[t,l]);const[f,b]=j.useState(250),L=me("(max-width: 600px)"),E=me("(max-width: 900px)");j.useEffect(()=>{V.current&&b(V.current.offsetWidth)},[y]);const A=Fs(),q=Oe();a.debug(q);const V=j.useRef(),n=()=>l.isActive===!0&&l.appDbId>0,O=()=>e.jsx($,{title:"Add new app",children:e.jsx(Y,{sx:{color:"inherit"},onClick:()=>{s(Fe({})),i(H.FORM)},children:e.jsx(at,{})})}),R={};return n()&&(R.visibility="hidden"),e.jsxs(st,{theme:A,children:[e.jsxs(o,{className:"pp-applist",sx:{width:"100%",visibility:n()?"hidden":"visible",position:n()?"fixed":"auto",height:n()?0:"auto",...n()&&{"& *":{visibility:"hidden"}},"& .pp-app-details":{...R}},children:[e.jsx(We,{position:"relative",elevation:4,sx:{margin:"0 0 5px 0"},children:e.jsxs(Ge,{className:"pp-applist-toolbar",sx:{display:"grid",gap:"12px",paddingRight:"12px !important",...L?{gap:0,paddingRight:"10px",paddingBottom:"10px",paddingLeft:"10px","& .pp-applist-search":{gridTemplateColumns:"1fr",gridGap:"2px"}}:{...E?{gap:0,paddingRight:"10px",paddingBottom:"10px",paddingLeft:"10px","& .pp-applist-search":{justifyContent:"end",gridTemplateColumns:"auto auto auto"}}:{justifyContent:"space-between",gridTemplateColumns:"auto 1fr"}}},children:[e.jsxs(o,{className:"pp-applist-title",sx:{display:"inline-grid",gridTemplateColumns:"auto auto",justifyContent:"start",alignItems:"center",gridGap:"10px"},children:[e.jsx(o,{sx:{fontSize:"18px",lineHeight:"18px",fontWeight:"bold",whiteSpace:"nowrap"},children:"Apps"}),e.jsx(o,{children:O()})]}),e.jsxs(o,{className:"pp-applist-search",sx:{display:"grid",gridTemplateColumns:"auto auto auto",gridGap:"10px",justifyContent:"end",alignItems:"center"},children:[e.jsxs(o,{children:[e.jsx($,{title:"App View",children:e.jsx(Y,{onClick:()=>{s(Ee({showAppStructure:!0}))},sx:{color:"#fff"},children:e.jsx(tt,{})})}),e.jsx($,{title:"List View",children:e.jsx(Y,{onClick:()=>{s(Ee({showAppStructure:!1}))},sx:{color:"#fff"},children:e.jsx(rt,{})})})]}),e.jsx(Z,{value:m,type:"search",placeholder:"Search",disabled:t===H.FORM,onChange:h=>{s(Ne({dbSearch:h.target.value})),localStorage.setItem("ppAppsDbsSearch",h.target.value)},sx:{backgroundColor:"#fff",fontSize:"1em",margin:0,padding:0,borderRadius:"4px","&.MuiFormControl-root.MuiTextField-root .MuiInputBase-root":{paddingRight:0},"&.MuiFormControl-root.MuiTextField-root input":{padding:"8px"}},InputProps:{startAdornment:e.jsx(Gt,{position:"end",sx:{fontSize:"1.5rem",padding:0,margin:0},children:e.jsx(nt,{})})}}),e.jsx(ge,{multiple:!0,size:"small",options:q,getOptionLabel:h=>h.text,isOptionEqualToValue:(h,T)=>h.id===T.id,value:y,disableCloseOnSelect:!0,disabled:t===H.FORM,onChange:(h,T)=>{s(Le({dbTypes:T.map(F=>({id:F.id,text:Object.values(zs)[F.id]}))})),localStorage.setItem("ppAppsDbsSearchType",JSON.stringify(T))},PaperComponent:({children:h})=>e.jsx(Ke,{sx:{width:`${f}px`},children:h}),renderInput:h=>e.jsx(o,{ref:V,children:e.jsx(Z,{...h,sx:{minWidth:"250px","& .MuiInputBase-root":{backgroundColor:"#fff",padding:"0",maxHeight:"39px",overflow:"hidden"},"& .MuiButtonBase-root.MuiChip-root.MuiAutocomplete-tag":{height:"auto"}},placeholder:y.length===0?"Select app types":""})}),renderTags:(h,T)=>h.map((F,Q)=>{const{key:U,...k}=T({index:Q});return e.jsx(fe,{variant:"outlined",label:F.text,...k},U)})})]})]})}),t===H.TABLE&&e.jsx(pr,{apps:x,appApps:p,search:m,types:y,isLoading:g}),t===H.FORM&&e.jsx(cr,{setMode:i}),c!==0&&c!==void 0&&e.jsx(ir,{appDbId:c})]}),l.isActive===!0&&l.appDbId>0&&e.jsx(Wt,{appId:r,appDbId:l.appDbId,designMode:!0,isExploring:!0})]})};export{$r as default};