@asaleh37/ui-base 25.8.8 → 25.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementField.tsx +2 -2
- package/src/hooks/index.ts +2 -1
- package/src/util/index.ts +3 -0
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsxs as e,jsx as i,Fragment as t}from"react/jsx-runtime";import{useDispatch as o,useSelector as a,Provider as r}from"react-redux";export{useDispatch,useSelector}from"react-redux";import{library as d}from"@fortawesome/fontawesome-svg-core";import{fab as n}from"@fortawesome/free-brands-svg-icons";import{far as l}from"@fortawesome/free-regular-svg-icons";import{fas as s}from"@fortawesome/free-solid-svg-icons";import"react-toastify/dist/ReactToastify.css";import{Dialog as p,DialogTitle as c,DialogContent as m,DialogContentText as u,DialogActions as T,Button as A,Modal as _,Box as f,AppBar as I,Toolbar as E,Typography as O,IconButton as N,Paper as y,TextField as h,Grid2 as R,ListItemButton as L,FormControlLabel as C,Checkbox as D,Autocomplete as P,Popper as M,Avatar as b,Tooltip as g,styled as S,Badge as U,Divider as v,MenuItem as w,InputAdornment as x,Accordion as F,AccordionSummary as B,AccordionDetails as k,keyframes as W,ClickAwayListener as G,Fade as Y,Menu as V,useTheme as q,Backdrop as K,CircularProgress as z,createTheme as H}from"@mui/material";export*from"@mui/material";import{ThemeContext as Q,CacheProvider as Z,ThemeProvider as j}from"@emotion/react";import*as $ from"react";import X,{useState as J,useEffect as ee,createElement as ie,useRef as te}from"react";import{styled as oe,alpha as ae,useTheme as re}from"@mui/material/styles";import de from"@mui/material/CssBaseline";import ne from"@mui/material/AppBar";import le from"@mui/material/Toolbar";import{FontAwesomeIcon as se}from"@fortawesome/react-fontawesome";export{FontAwesomeIcon}from"@fortawesome/react-fontawesome";import{createSlice as pe,configureStore as ce}from"@reduxjs/toolkit";import{toast as me,ToastContainer as ue}from"react-toastify";export{toast}from"react-toastify";import Te from"axios";import Ae from"i18next";import{useTranslation as _e,initReactI18next as fe}from"react-i18next";export{useTranslation}from"react-i18next";import{useForm as Ie}from"react-hook-form";export{useForm}from"react-hook-form";import{useNavigate as Ee,useParams as Oe,Routes as Ne,Route as ye,BrowserRouter as he}from"react-router-dom";export{useNavigate,useParams}from"react-router-dom";import{zodResolver as Re}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import*as Le from"zod";import{z as Ce}from"zod";export{Le as z};import De from"@mui/material/List";import Pe from"@mui/material/Card";import Me from"@mui/material/CardHeader";import be from"@mui/material/ListItemText";import ge from"@mui/material/ListItemIcon";import Se from"@mui/material/Checkbox";import Ue from"@mui/material/Button";import ve from"@mui/material/Divider";import{LocalizationProvider as we,DatePicker as xe,DateTimePicker as Fe}from"@mui/x-date-pickers";import{AdapterMoment as Be}from"@mui/x-date-pickers/AdapterMoment";import ke from"moment";import We from"@mui/material/CardActions";import Ge from"@mui/material/CardContent";import Ye from"@mui/material/CardMedia";import Ve from"@mui/material/Typography";import{QuickFilter as qe,ToolbarButton as Ke,Toolbar as ze,ColumnsPanelTrigger as He,GridViewColumnIcon as Qe,FilterPanelTrigger as Ze,GridFilterListIcon as je,ExportExcel as $e,QuickFilterTrigger as Xe,QuickFilterControl as Je,QuickFilterClear as ei,GridActionsCellItem as ii,GridExpandMoreIcon as ti,DataGridPremium as oi,GridRowModes as ai}from"@mui/x-data-grid-premium";import{BarChart as ri,Gauge as di,LineChart as ni}from"@mui/x-charts";import li from"@mui/material/LinearProgress";import si from"@mui/material/Box";import{PieChart as pi}from"@mui/x-charts/PieChart";import ci from"@mui/material/IconButton";import mi from"@mui/material/Drawer";import{animated as ui,useSpring as Ti}from"@react-spring/web";import Ai from"@mui/material/Collapse";import{RichTreeView as _i}from"@mui/x-tree-view/RichTreeView";import{treeItemClasses as fi}from"@mui/x-tree-view/TreeItem";import{useTreeItem2 as Ii}from"@mui/x-tree-view/useTreeItem2";import{TreeItem2Root as Ei,TreeItem2Content as Oi,TreeItem2IconContainer as Ni,TreeItem2Checkbox as yi,TreeItem2Label as hi}from"@mui/x-tree-view/TreeItem2";import{TreeItem2Icon as Ri}from"@mui/x-tree-view/TreeItem2Icon";import{TreeItem2Provider as Li}from"@mui/x-tree-view/TreeItem2Provider";import{TreeItem2DragAndDropOverlay as Ci}from"@mui/x-tree-view/TreeItem2DragAndDropOverlay";import Di from"stylis-plugin-rtl";import{prefixer as Pi}from"stylis";import Mi from"@emotion/cache";import bi from"@emotion/styled";import{grey as gi}from"@mui/material/colors";import Si from"@mui/material/SwipeableDrawer";import{LicenseInfo as Ui}from"@mui/x-license";export*from"@mui/lab";export*from"@mui/x-tree-view/models";!function(e,i){void 0===i&&(i={});var t=i.insertAt;if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===t&&o.firstChild?o.insertBefore(a,o.firstChild):o.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}("html,\nbody {\n height: 100vh;\n margin: 0;\n padding: 0;\n}\n\n#root {\n height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n overflow: hidden;\n}\n\n.red-row {\n background-color: #f0d8d8;\n}\n");const vi=(e=768)=>{const[i,t]=J(window.innerWidth<e);return ee(()=>{const i=()=>t(window.innerWidth<e);return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[e]),i},wi=350,xi=pe({name:"AppLayout",initialState:{themeMode:localStorage.getItem("themeMode")||"light",appDirection:"ar"==localStorage.getItem("language")?"rtl":"ltr"},reducers:{setThemeMode:(e,i)=>{e.themeMode=i.payload},setAppDirection:(e,i)=>{e.appDirection=i.payload}}}),Fi=xi.actions;var Bi=xi.reducer;const ki=pe({name:"loadingMask",initialState:{value:{isOpened:!1,message:null}},reducers:{showLoadingMask:(e,i)=>{e.value.isOpened=!0,e.value.message=i.payload},hideLoadingMask:e=>{e.value.isOpened=!1,e.value.message=null}}}),{showLoadingMask:Wi,hideLoadingMask:Gi}=ki.actions;var Yi=ki.reducer;const Vi=()=>{const e=o();return{show:i=>{e(Wi(i))},hide:()=>{e(Gi())}}},qi=pe({name:"UserSession",initialState:{value:{isAuthenticated:null,authorities:[]}},reducers:{setAuthenticated:(e,i)=>{e.value=i.payload},setUnAuthenticated:e=>{e.value={isAuthenticated:!1,authorities:[]}}}}),Ki=qi.actions;var zi=qi.reducer;const Hi=()=>{const e=Vi(),i=o(),t=a(e=>e.AppInfo.value.apiBaseUrl),r=Te.create({baseURL:t,timeout:6e5,withCredentials:!0});r.defaults.withCredentials=!0,r.interceptors.response.use(e=>e,e=>{if(e&&(e.response&&(e.response.status&&401===e.response.status)))i(Ki.setUnAuthenticated()),me.error("your session is now expired, you need to login again",{autoClose:!1});else if(e&&(e.response&&(e.response.status&&403===e.response.status)))me.error("you aren't authorized to process this request");else if(e&&(e.response&&(e.response.status&&500===e.response.status)))if(e.response.data instanceof Blob){e.response.data.text().then(e=>{me.error(e)})}else me.error(e.response.data);else me.error("failed to communicate with the server ... try again later");return"ERROR"});return{handleGetRequest:async i=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);const t=await r.get(i.endPointURI,{params:{...i.parameters},withCredentials:!0,headers:i.headers,responseType:i?.responseType});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},handlePostRequest:async i=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);let t=await r.post(i.endPointURI,i.data,{params:i.parameters,responseType:i?.responseType,headers:i?.headers});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},handleDeleteRequest:async i=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);let t=await r.delete(i.endPointURI,{params:{...i.parameters},responseType:i?.responseType,headers:i?.headers});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},HandleDownloadHTTPPostPDF:async(i={endPointURI:"",parameters:{},data:{}})=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);const t=await r.post(i.endPointURI,i.data,{responseType:"blob"});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},handleUploadRequest:async i=>{if(null===i.files||0===i.files.length)return me.error("You must add files to upload"),"ERROR";const t=new FormData;for(const e of i.files)t.append("files",e);void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);let o=await r.post(i.endPointURI,t,{params:i?.parameters,headers:{"Content-Type":"multipart/form-data"}});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==o?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(o),o):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(o),"ERROR")}}},Qi=t=>{const[o,a]=J(!1),{t:r}=_e();return{ConfirmationWindow:()=>e(p,{open:o,children:[i(c,{children:t.title}),i(m,{children:i(u,{children:t.body})}),e(T,{children:[i(A,{variant:"contained",color:"primary",onClick:()=>{a(!1)},children:r("NO_LABEL")}),i(A,{variant:"contained",color:"error",onClick:()=>{t.onConfirmationCallBk(),a(!1)},autoFocus:!0,children:r("YES_LABEL")})]})]}),open:o,setOpen:a}},Zi=()=>{const e=a(e=>e.UserSession),i=e.value;return{UserSession:e,isUserAuthorized:i=>{if(e?.value?.authorities)for(let t of e.value.authorities){if("DEVELOPMENT_ADMIN"===i&&("DEVELOPMENT_ADMIN"===t?.authority||"ORGANIZATION_ADMIN"===t?.authority))return!0;if("ORGANIZATION_ADMIN"===i&&"ORGANIZATION_ADMIN"===t?.authority)return!0;if("DEVELOPMENT_ADMIN"!==i&&"ORGANIZATION_ADMIN"!==i&&("ORGANIZATION_ADMIN"===t?.authority||"DEVELOPMENT_ADMIN"===t?.authority||"SYSTEM_ADMIN"===t?.authority||t?.authority===i))return!0}return!1},isCurrentOrganizationAuthorizedToModule:e=>{if(i?.currentOrganization?.systemApplicationModules)for(const t of i.currentOrganization.systemApplicationModules)if(t.toLowerCase()==e.toLowerCase())return!0;return!1},UserInfo:i}},ji=t=>{const[o,a]=J(!1);return{windowState:o,setWindowState:a,Window:r=>i(_,{open:o,sx:{zIndex:e=>e.zIndex.drawer},onClose:()=>{!o&&t?.onCloseCallBack&&t.onCloseCallBack()},children:e(f,{sx:{position:"absolute",top:"50%",left:"50%",maxHeight:"90%",transform:"translate(-50%, -50%)",height:t?.height||"80%",width:t?.width||"90%",minWidth:t.minWidth||400,minHeight:t.minHeight||200,overflow:"hidden",bgcolor:"modalBackground.main",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:[i(I,{position:"static",children:e(E,{variant:"dense",children:[i(se,{icon:t?.windowIcon||"window-maximize",style:{marginRight:5}}),i(O,{variant:"h6",color:"inherit",component:"div",children:t?.windowTitle||"window"}),i("div",{style:{flexGrow:1}}),i(N,{onClick:()=>{a(!1),null!=t.onCloseCallBack&&null!=t.onCloseCallBack&&t.onCloseCallBack()},color:"secondary",children:i(se,{icon:"xmark-square"})})]})}),i(y,{sx:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",height:"100%",padding:1,overflow:"hidden"},children:r?.children})]})})}},$i=pe({name:"commonStores",initialState:{stores:{},storeKeys:[]},reducers:{setStoresMetaData:(e,i)=>{e.stores=i.payload,e.storeKeys=Object.keys(i.payload)},setStoreData:(e,i)=>{e.stores[i.payload.storeKey].data=i.payload.data}}}),{setStoreData:Xi,setStoresMetaData:Ji}=$i.actions;var et=$i.reducer;const it=e=>{const i=a(e=>e.commonStores.stores),t=o(),r=Zi(),{handleGetRequest:d,handlePostRequest:n,handleDeleteRequest:l}=Hi();return{reloadData:async o=>{if(e?.commonStoreKey){const o=Object.keys(i);for(const a of o)if(a===e.commonStoreKey&&(void 0===i[a]?.authority||null===i[a]?.authority||r.isUserAuthorized(i[a]?.authority))&&""!=i[a]?.url){await d({endPointURI:i[a].url,showMask:!1,successCallBkFn:i=>{t(Xi({storeKey:a,data:i.data})),e.setData(i.data)},failureCallBkFn:()=>{t(Xi({storeKey:a,data:[]})),e.setData([])}});break}}else e?.findAll&&await d({endPointURI:e.findAll,showMask:!0,parameters:o||{},successCallBkFn:i=>{e.setData(i.data)}})},loadRecordById:async i=>{let t=null;if(e?.findById){const o={};o[e?.findByIdParamName||"id"]=i,await d({endPointURI:e.findById,showMask:!0,parameters:o,successCallBkFn:e=>{t=e.data}})}return t},saveRecord:async i=>{let t=null;return e?.save&&await n({endPointURI:e.save,data:i,showMask:!0,successCallBkFn:e=>{t=e.data}}),t},deleteRecordById:async i=>{let t=!0;if(e?.deleteById){const o={};o[e?.deleteByIdParamName||"id"]=i,await l({endPointURI:e.deleteById,showMask:!0,parameters:o,successCallBkFn:()=>{t=!0},failureCallBkFn:()=>{t=!1}})}return t}}},tt=e=>{const{t:o}=_e();return i(h,{...e,slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:i(t,{children:e?.label?o(e.label):""}),helperText:e?.helperText?o(e.helperText):void 0})};function ot(e,i){return e.filter(e=>-1===i.indexOf(e))}function at(e,i){return e.filter(e=>-1!==i.indexOf(e))}const rt=({valueField:t="id",displayField:o="name",options:a=[],selectedOptions:r=[],setSelection:d})=>{const[n,l]=$.useState([]),[s,p]=$.useState([]),[c,m]=$.useState([]),[u,T]=$.useState(""),[A,_]=$.useState(""),I=at(n,s),E=at(n,c);$.useEffect(()=>{a&&p([...a])},[a]),$.useEffect(()=>{r&&m([...r])},[r]);const O=e=>()=>{const i=n.indexOf(e),t=[...n];-1===i?t.push(e):t.splice(i,1),l(t)},N=e=>at(n,e).length,y=e=>()=>{var i,t;N(e)===e.length?l(ot(n,e)):l((i=n,t=e,[...i,...ot(t,i)]))},h=(a,r,d)=>{const l=r.filter(e=>{if(e[o]){const i=e[o];if("left"===d&&i.toLocaleLowerCase().includes(u.toLocaleLowerCase()))return!0;if("right"===d&&i.toLocaleLowerCase().includes(A.toLocaleLowerCase()))return!0}return!1});return e(Pe,{sx:{height:"100%"},children:[i(Me,{sx:{px:2,py:1},avatar:i(Se,{onClick:y(l),checked:N(l)===l.length&&0!==l.length,indeterminate:N(l)!==l.length&&0!==N(l),disabled:0===l.length,inputProps:{"aria-label":"all items selected"}}),title:a,subheader:`${N(r)} / ${r.length} Selected`}),i(f,{sx:{width:"100%",padding:1},children:i(tt,{fullWidth:!0,label:"search",value:"left"===d?u:A,onChange:e=>{"left"===d?T(e.target.value):_(e.target.value)}})}),i(ve,{}),i(De,{sx:{width:"100%",height:"80%",bgcolor:"secondary",overflow:"auto"},dense:!0,component:"div",role:"list",children:l.map(a=>(a[t],e(L,{role:"listitem",onClick:O(a),sx:{cursor:"pointer"},children:[i(ge,{children:i(Se,{checked:-1!==n.indexOf(a),tabIndex:-1,disableRipple:!0})}),i(be,{id:a[t],primary:a[o]})]},a[t])))})]})};return e(R,{container:!0,spacing:2,sx:{flexGrow:1,overflow:"auto",margin:1,display:"flex",width:"100%"},justifyContent:"center",alignItems:"center",children:[i(R,{sx:{height:"100%",flex:1},children:h("Available Items",s,"left")}),i(R,{children:e(R,{container:!0,direction:"column",alignItems:"center",children:[i(Ue,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{m(e=>{let i=c.concat(I);return d(i),i}),p(ot(s,I)),l(ot(n,I))},disabled:0===I.length,"aria-label":"move selected right",children:">"}),i(Ue,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{p(s.concat(E)),m(e=>{let i=ot(c,E);return d(i),i}),l(ot(n,E))},disabled:0===E.length,"aria-label":"move selected left",children:"<"})]})}),i(R,{sx:{height:"100%",flex:1},children:h("Currently Selected",c,"right")})]})},dt=e=>{const{t:t}=_e();return i(C,{sx:e.sx,hidden:e?.hidden||!1,disabled:e.disabled||!1,required:e.required||!1,control:i(D,{checked:e?.checkedValue==e.value||"true"===e.value||"1"==e.value,onChange:i=>{void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&(i.target.checked?void 0!==e.checkedValue&&null!=e.checkedValue?e.onChangeCallBack(e.checkedValue):e.onChangeCallBack(!0):void 0!==e.unCheckedValue&&null!=e.unCheckedValue?e.onChangeCallBack(e.unCheckedValue):e.onChangeCallBack(!1))}}),label:t(e.label)})},nt=e=>{const t=a(e=>e.AppLayout),{t:o}=_e();return i(P,{sx:e.sx,value:(i=>{for(let t of e.options)if(t[e.valueField]==i)return t;return null})(e.value),options:e.options,disabled:e.disabled,hidden:e?.hidden||!1,onChange:(i,t)=>{if(void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack)if(null!=t){let i=t[e.valueField];e.onChangeCallBack(i,t)}else e.onChangeCallBack(null,null)},clearOnBlur:!0,handleHomeEndKeys:!0,getOptionLabel:i=>null!=i?o(i[e.displayField]):"",renderOption:(t,a)=>i("li",{...t,children:null!=a?o(a[e.displayField]):""}),slots:{popper:e=>i(M,{...e,style:{...e.style,direction:t.appDirection}})},renderInput:t=>i(h,{...t,required:e.required||!1,variant:"outlined",slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:o(e.label),error:null!=e.errorMessage&&void 0!==e.errorMessage,helperText:null!=e.errorMessage&&void 0!==e.errorMessage?o(e.errorMessage):""})})},lt="YYYY-MM-DD",st="YYYY-MM-DD HH:mm:ss",pt="#37505C",ct="#ff6d00",mt="#ea690e",ut="#74776B",Tt=e=>{const{t:o}=_e();return e?.hidden?i(t,{}):i(we,{dateAdapter:Be,children:i(xe,{value:null!=e.value&&void 0!==e.value&&""!==e.value?ke(e.value,e?.format||lt):null,sx:e.sx,label:o(e.label),format:e?.format||lt,disabled:e.disabled,onChange:i=>{let t=null;null!=i&&i.isValid()&&(t=i.format(e?.format||lt)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(t)},slotProps:{textField:{InputLabelProps:{shrink:!0,sx:{fontWeight:"bold"}},variant:"outlined",required:e.required,error:void 0!==e.errorMessage&&null!=e.errorMessage,helperText:void 0!==e.errorMessage&&null!=e.errorMessage?i(t,{children:o(e.errorMessage)}):i(t,{})}}})})},At=e=>{const{t:o}=_e();return e?.hidden?i(t,{}):i(we,{dateAdapter:Be,children:i(Fe,{value:null!=e.value&&void 0!==e.value&&""!==e.value?ke(e.value,e?.format||st):null,label:o(e.label),sx:e.sx,format:e?.format||st,disabled:e.disabled,onChange:i=>{let t=null;null!=i&&i.isValid()&&(t=i.format(e?.format||st)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(t)},slotProps:{textField:{InputLabelProps:{shrink:!0,sx:{fontWeight:"bold"}},variant:"outlined",required:e.required,error:void 0!==e.errorMessage&&null!=e.errorMessage,helperText:void 0!==e.errorMessage&&null!=e.errorMessage?i(t,{children:o(e.errorMessage)}):i(t,{})}}})})},_t=e=>{const t=a(e=>e.AppLayout),o=Zi(),[r,d]=J([]),{handleGetRequest:n}=Hi();return ee(()=>{e.lookupType&&(async()=>{await n({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:e.lookupType},successCallBkFn:e=>{d(e.data)},failureCallBkFn:()=>{d([])}})})()},[e.lookupType,o.UserSession]),i(nt,{...e,options:r,displayField:"ltr"===t.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"})},ft=e=>({...e,type:"string",renderEditCell:e=>i(Tt,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:i=>{e.api.setEditCellValue({id:e.id,field:e.field,value:i})}}),valueParser:(e,i,t)=>{let o=null;return null!==e&&(o=ke(e).format(lt)),o},valueFormatter:(e,i,t)=>i[t.field]}),It=e=>({...e,type:"string",renderEditCell:e=>i(At,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:i=>{e.api.setEditCellValue({id:e.id,field:e.field,value:i})}}),valueParser:(e,i,t)=>{let o=null;return null!==e&&(o=ke(e).format(st)),o},valueFormatter:(e,i,t)=>i[t.field]}),Et=e=>({...e,type:"custom",valueGetter:e=>e?e+"":e,renderCell:e=>{let t=null;try{t=e.colDef.options.find(i=>i[e.colDef.valueField]==e.value)}catch(e){}return i("div",{children:null!=t?t[e.colDef.displayField]:e.value})},renderEditCell:e=>i(nt,{...e,sx:{width:"100%"},options:e.colDef.options,valueField:e.colDef.valueField,displayField:e.colDef.displayField,onChangeCallBack:(i,t)=>{null===i&&e.api.setEditCellValue({id:e.id,field:e.field,value:null}),e.api.setEditCellValue({id:e.id,field:e.field,value:i+""})}})}),Ot=e=>({...e,type:"custom",valueGetter:e=>null==e||null==e?null:e,renderCell:t=>{const o=t?.value;return o===e.checkedValue||"true"===o||1===o||!0===o?i(se,{icon:"check",color:"green"}):i(se,{icon:"xmark",color:"red"})},renderEditCell:t=>i(dt,{...t,checkedValue:e?.checkedValue||!0,unCheckedValue:e?.unCheckedValue||!1,onChangeCallBack:e=>{t.api.setEditCellValue({id:t.id,field:t.field,value:e})}})}),Nt=e=>{const i=[];if("field"===e.type&&"props"===e.mode&&e?.props)i.push(e.props);else if("group"===e.type&&e?.props&&e?.props?.elements)for(const t of e.props.elements)i.push(...Nt(t));return i},yt=e=>{const i=[];for(const t of e)i.push(...Nt(t));return i},ht=(e,i,t)=>{const o=[];for(const a of e)if("text"===a?.fieldType||"number"===a?.fieldType){const e={...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,type:"number"==a?.fieldType?"number":"string",field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200};o.push(e)}else if("date"===a?.fieldType){const e=ft({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else if("datetime"===a?.fieldType){const e=It({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else if("checkbox"===a?.fieldType){const e=Ot({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,checkedValue:a?.checkedValue,unCheckedValue:a?.unCheckedValue,width:150});o.push(e)}else if("combobox"===a?.fieldType){const e=Et({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,valueField:a?.optionValueField||"value",displayField:a?.optionDisplayField||"display",options:a?.options||[],flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else if("lookup"===a?.fieldType){const e=Et({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,lookupType:a?.lookupType,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,valueField:a?.optionValueField||"value",displayField:a?.optionDisplayField||"display",options:a?.options||[],flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else{const e={field:a.fieldName,...a?.gridProps?.muiProps};o.push(e)}return o},Rt=e=>{const i={};for(const t of e)if(t?.fieldName){const e=t.fieldName;"number"===t.fieldType?i[e]=!0===t?.required?Le.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):Le.number().optional().nullable():"checkbox"===t.fieldType?i[e]=!0===t?.required?Le.boolean({required_error:"This field is required"}):Le.boolean().optional().nullable():i[e]=!0===t?.required?Le.string({message:"This field is required"}).min(1,"This field is required"):Le.string().optional().nullable()}return i},Lt=(e,i,t)=>{const o=[],a=[];if("exclude"===e.type&&0===e.ids.size)for(const e of i)o.push(e),a.push(e[t]);else if(e?.ids)for(const r of e.ids){const e=i.find(e=>e[t]===r);o.push(e),a.push(r)}return{selectedRecords:o,selectedRecordIds:a}};function Ct(e,...i){const t=new URL(`https://mui.com/production-error/?code=${e}`);return i.forEach(e=>t.searchParams.append("args[]",e)),`Minified MUI error #${e}; visit ${t} for the full message.`}function Dt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Pt,Mt={exports:{}},bt={exports:{}},gt={};var St,Ut,vt,wt,xt,Ft,Bt,kt,Wt,Gt,Yt,Vt,qt,Kt,zt,Ht={};
|
|
1
|
+
import{jsxs as e,jsx as i,Fragment as t}from"react/jsx-runtime";import{useDispatch as o,useSelector as a,Provider as r}from"react-redux";export{useDispatch,useSelector}from"react-redux";import{library as d}from"@fortawesome/fontawesome-svg-core";import{fab as n}from"@fortawesome/free-brands-svg-icons";import{far as l}from"@fortawesome/free-regular-svg-icons";import{fas as s}from"@fortawesome/free-solid-svg-icons";import"react-toastify/dist/ReactToastify.css";import{Dialog as p,DialogTitle as c,DialogContent as m,DialogContentText as u,DialogActions as T,Button as A,Modal as _,Box as f,AppBar as I,Toolbar as E,Typography as O,IconButton as N,Paper as y,TextField as h,Grid2 as R,ListItemButton as L,FormControlLabel as C,Checkbox as D,Autocomplete as P,Popper as M,Avatar as b,Tooltip as g,styled as S,Badge as U,Divider as v,MenuItem as w,InputAdornment as x,Accordion as F,AccordionSummary as B,AccordionDetails as k,keyframes as W,ClickAwayListener as G,Fade as Y,Menu as V,useTheme as q,Backdrop as K,CircularProgress as z,createTheme as H}from"@mui/material";export*from"@mui/material";import{ThemeContext as Q,CacheProvider as Z,ThemeProvider as j}from"@emotion/react";import*as $ from"react";import X,{useState as J,useEffect as ee,createElement as ie,useRef as te}from"react";import{styled as oe,alpha as ae,useTheme as re}from"@mui/material/styles";import de from"@mui/material/CssBaseline";import ne from"@mui/material/AppBar";import le from"@mui/material/Toolbar";import{FontAwesomeIcon as se}from"@fortawesome/react-fontawesome";export{FontAwesomeIcon}from"@fortawesome/react-fontawesome";import{createSlice as pe,configureStore as ce}from"@reduxjs/toolkit";import{toast as me,ToastContainer as ue}from"react-toastify";export{toast}from"react-toastify";import Te from"axios";export{default as axios}from"axios";import Ae from"i18next";import{useTranslation as _e,initReactI18next as fe}from"react-i18next";export{useTranslation}from"react-i18next";import{useForm as Ie}from"react-hook-form";export{useForm}from"react-hook-form";import{useNavigate as Ee,useParams as Oe,Routes as Ne,Route as ye,BrowserRouter as he}from"react-router-dom";export{useNavigate,useParams}from"react-router-dom";import{zodResolver as Re}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import*as Le from"zod";import{z as Ce}from"zod";export{Le as z};import De from"@mui/material/List";import Pe from"@mui/material/Card";import Me from"@mui/material/CardHeader";import be from"@mui/material/ListItemText";import ge from"@mui/material/ListItemIcon";import Se from"@mui/material/Checkbox";import Ue from"@mui/material/Button";import ve from"@mui/material/Divider";import{LocalizationProvider as we,DatePicker as xe,DateTimePicker as Fe}from"@mui/x-date-pickers";import{AdapterMoment as Be}from"@mui/x-date-pickers/AdapterMoment";import ke from"moment";import We from"@mui/material/CardActions";import Ge from"@mui/material/CardContent";import Ye from"@mui/material/CardMedia";import Ve from"@mui/material/Typography";import{QuickFilter as qe,ToolbarButton as Ke,Toolbar as ze,ColumnsPanelTrigger as He,GridViewColumnIcon as Qe,FilterPanelTrigger as Ze,GridFilterListIcon as je,ExportExcel as $e,QuickFilterTrigger as Xe,QuickFilterControl as Je,QuickFilterClear as ei,GridActionsCellItem as ii,GridExpandMoreIcon as ti,DataGridPremium as oi,GridRowModes as ai}from"@mui/x-data-grid-premium";import{BarChart as ri,Gauge as di,LineChart as ni}from"@mui/x-charts";import li from"@mui/material/LinearProgress";import si from"@mui/material/Box";import{PieChart as pi}from"@mui/x-charts/PieChart";import ci from"@mui/material/IconButton";import mi from"@mui/material/Drawer";import{animated as ui,useSpring as Ti}from"@react-spring/web";import Ai from"@mui/material/Collapse";import{RichTreeView as _i}from"@mui/x-tree-view/RichTreeView";import{treeItemClasses as fi}from"@mui/x-tree-view/TreeItem";import{useTreeItem2 as Ii}from"@mui/x-tree-view/useTreeItem2";import{TreeItem2Root as Ei,TreeItem2Content as Oi,TreeItem2IconContainer as Ni,TreeItem2Checkbox as yi,TreeItem2Label as hi}from"@mui/x-tree-view/TreeItem2";import{TreeItem2Icon as Ri}from"@mui/x-tree-view/TreeItem2Icon";import{TreeItem2Provider as Li}from"@mui/x-tree-view/TreeItem2Provider";import{TreeItem2DragAndDropOverlay as Ci}from"@mui/x-tree-view/TreeItem2DragAndDropOverlay";import Di from"stylis-plugin-rtl";import{prefixer as Pi}from"stylis";import Mi from"@emotion/cache";import bi from"@emotion/styled";import{grey as gi}from"@mui/material/colors";import Si from"@mui/material/SwipeableDrawer";import{LicenseInfo as Ui}from"@mui/x-license";export*from"@mui/lab";export*from"@mui/x-tree-view/models";!function(e,i){void 0===i&&(i={});var t=i.insertAt;if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===t&&o.firstChild?o.insertBefore(a,o.firstChild):o.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}("html,\nbody {\n height: 100vh;\n margin: 0;\n padding: 0;\n}\n\n#root {\n height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n overflow: hidden;\n}\n\n.red-row {\n background-color: #f0d8d8;\n}\n");const vi=(e=768)=>{const[i,t]=J(window.innerWidth<e);return ee(()=>{const i=()=>t(window.innerWidth<e);return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[e]),i},wi=350,xi=pe({name:"AppLayout",initialState:{themeMode:localStorage.getItem("themeMode")||"light",appDirection:"ar"==localStorage.getItem("language")?"rtl":"ltr"},reducers:{setThemeMode:(e,i)=>{e.themeMode=i.payload},setAppDirection:(e,i)=>{e.appDirection=i.payload}}}),Fi=xi.actions;var Bi=xi.reducer;const ki=pe({name:"loadingMask",initialState:{value:{isOpened:!1,message:null}},reducers:{showLoadingMask:(e,i)=>{e.value.isOpened=!0,e.value.message=i.payload},hideLoadingMask:e=>{e.value.isOpened=!1,e.value.message=null}}}),{showLoadingMask:Wi,hideLoadingMask:Gi}=ki.actions;var Yi=ki.reducer;const Vi=()=>{const e=o();return{show:i=>{e(Wi(i))},hide:()=>{e(Gi())}}},qi=pe({name:"UserSession",initialState:{value:{isAuthenticated:null,authorities:[]}},reducers:{setAuthenticated:(e,i)=>{e.value=i.payload},setUnAuthenticated:e=>{e.value={isAuthenticated:!1,authorities:[]}}}}),Ki=qi.actions;var zi=qi.reducer;const Hi=()=>{const e=Vi(),i=o(),t=a(e=>e.AppInfo.value.apiBaseUrl),r=Te.create({baseURL:t,timeout:6e5,withCredentials:!0});r.defaults.withCredentials=!0,r.interceptors.response.use(e=>e,e=>{if(e&&(e.response&&(e.response.status&&401===e.response.status)))i(Ki.setUnAuthenticated()),me.error("your session is now expired, you need to login again",{autoClose:!1});else if(e&&(e.response&&(e.response.status&&403===e.response.status)))me.error("you aren't authorized to process this request");else if(e&&(e.response&&(e.response.status&&500===e.response.status)))if(e.response.data instanceof Blob){e.response.data.text().then(e=>{me.error(e)})}else me.error(e.response.data);else me.error("failed to communicate with the server ... try again later");return"ERROR"});return{handleGetRequest:async i=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);const t=await r.get(i.endPointURI,{params:{...i.parameters},withCredentials:!0,headers:i.headers,responseType:i?.responseType});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},handlePostRequest:async i=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);let t=await r.post(i.endPointURI,i.data,{params:i.parameters,responseType:i?.responseType,headers:i?.headers});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},handleDeleteRequest:async i=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);let t=await r.delete(i.endPointURI,{params:{...i.parameters},responseType:i?.responseType,headers:i?.headers});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},HandleDownloadHTTPPostPDF:async(i={endPointURI:"",parameters:{},data:{}})=>{void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);const t=await r.post(i.endPointURI,i.data,{responseType:"blob"});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==t?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(t),t):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(t),"ERROR")},handleUploadRequest:async i=>{if(null===i.files||0===i.files.length)return me.error("You must add files to upload"),"ERROR";const t=new FormData;for(const e of i.files)t.append("files",e);void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.show(i.loadingMessage);let o=await r.post(i.endPointURI,t,{params:i?.parameters,headers:{"Content-Type":"multipart/form-data"}});return void 0!==i.showMask&&null!=i.showMask&&!0===i.showMask&&e.hide(),"ERROR"!==o?(void 0!==i.successCallBkFn&&null!=i.successCallBkFn&&i.successCallBkFn(o),o):(void 0!==i.failureCallBkFn&&null!=i.failureCallBkFn&&i.failureCallBkFn(o),"ERROR")}}},Qi=t=>{const[o,a]=J(!1),{t:r}=_e();return{ConfirmationWindow:()=>e(p,{open:o,children:[i(c,{children:t.title}),i(m,{children:i(u,{children:t.body})}),e(T,{children:[i(A,{variant:"contained",color:"primary",onClick:()=>{a(!1)},children:r("NO_LABEL")}),i(A,{variant:"contained",color:"error",onClick:()=>{t.onConfirmationCallBk(),a(!1)},autoFocus:!0,children:r("YES_LABEL")})]})]}),open:o,setOpen:a}},Zi=()=>{const e=a(e=>e.UserSession),i=e.value;return{UserSession:e,isUserAuthorized:i=>{if(e?.value?.authorities)for(let t of e.value.authorities){if("DEVELOPMENT_ADMIN"===i&&("DEVELOPMENT_ADMIN"===t?.authority||"ORGANIZATION_ADMIN"===t?.authority))return!0;if("ORGANIZATION_ADMIN"===i&&"ORGANIZATION_ADMIN"===t?.authority)return!0;if("DEVELOPMENT_ADMIN"!==i&&"ORGANIZATION_ADMIN"!==i&&("ORGANIZATION_ADMIN"===t?.authority||"DEVELOPMENT_ADMIN"===t?.authority||"SYSTEM_ADMIN"===t?.authority||t?.authority===i))return!0}return!1},isCurrentOrganizationAuthorizedToModule:e=>{if(i?.currentOrganization?.systemApplicationModules)for(const t of i.currentOrganization.systemApplicationModules)if(t.toLowerCase()==e.toLowerCase())return!0;return!1},UserInfo:i}},ji=t=>{const[o,a]=J(!1);return{windowState:o,setWindowState:a,Window:r=>i(_,{open:o,sx:{zIndex:e=>e.zIndex.drawer},onClose:()=>{!o&&t?.onCloseCallBack&&t.onCloseCallBack()},children:e(f,{sx:{position:"absolute",top:"50%",left:"50%",maxHeight:"90%",transform:"translate(-50%, -50%)",height:t?.height||"80%",width:t?.width||"90%",minWidth:t.minWidth||400,minHeight:t.minHeight||200,overflow:"hidden",bgcolor:"modalBackground.main",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:[i(I,{position:"static",children:e(E,{variant:"dense",children:[i(se,{icon:t?.windowIcon||"window-maximize",style:{marginRight:5}}),i(O,{variant:"h6",color:"inherit",component:"div",children:t?.windowTitle||"window"}),i("div",{style:{flexGrow:1}}),i(N,{onClick:()=>{a(!1),null!=t.onCloseCallBack&&null!=t.onCloseCallBack&&t.onCloseCallBack()},color:"secondary",children:i(se,{icon:"xmark-square"})})]})}),i(y,{sx:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",height:"100%",padding:1,overflow:"hidden"},children:r?.children})]})})}},$i=pe({name:"commonStores",initialState:{stores:{},storeKeys:[]},reducers:{setStoresMetaData:(e,i)=>{e.stores=i.payload,e.storeKeys=Object.keys(i.payload)},setStoreData:(e,i)=>{e.stores[i.payload.storeKey].data=i.payload.data}}}),{setStoreData:Xi,setStoresMetaData:Ji}=$i.actions;var et=$i.reducer;const it=e=>{const i=a(e=>e.commonStores.stores),t=o(),r=Zi(),{handleGetRequest:d,handlePostRequest:n,handleDeleteRequest:l}=Hi();return{reloadData:async o=>{if(e?.commonStoreKey){const o=Object.keys(i);for(const a of o)if(a===e.commonStoreKey&&(void 0===i[a]?.authority||null===i[a]?.authority||r.isUserAuthorized(i[a]?.authority))&&""!=i[a]?.url){await d({endPointURI:i[a].url,showMask:!1,successCallBkFn:i=>{t(Xi({storeKey:a,data:i.data})),e.setData(i.data)},failureCallBkFn:()=>{t(Xi({storeKey:a,data:[]})),e.setData([])}});break}}else e?.findAll&&await d({endPointURI:e.findAll,showMask:!0,parameters:o||{},successCallBkFn:i=>{e.setData(i.data)}})},loadRecordById:async i=>{let t=null;if(e?.findById){const o={};o[e?.findByIdParamName||"id"]=i,await d({endPointURI:e.findById,showMask:!0,parameters:o,successCallBkFn:e=>{t=e.data}})}return t},saveRecord:async i=>{let t=null;return e?.save&&await n({endPointURI:e.save,data:i,showMask:!0,successCallBkFn:e=>{t=e.data}}),t},deleteRecordById:async i=>{let t=!0;if(e?.deleteById){const o={};o[e?.deleteByIdParamName||"id"]=i,await l({endPointURI:e.deleteById,showMask:!0,parameters:o,successCallBkFn:()=>{t=!0},failureCallBkFn:()=>{t=!1}})}return t}}},tt=e=>{const{t:o}=_e();return i(h,{...e,slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:i(t,{children:e?.label?o(e.label):""}),helperText:e?.helperText?o(e.helperText):void 0})};function ot(e,i){return e.filter(e=>-1===i.indexOf(e))}function at(e,i){return e.filter(e=>-1!==i.indexOf(e))}const rt=({valueField:t="id",displayField:o="name",options:a=[],selectedOptions:r=[],setSelection:d})=>{const[n,l]=$.useState([]),[s,p]=$.useState([]),[c,m]=$.useState([]),[u,T]=$.useState(""),[A,_]=$.useState(""),I=at(n,s),E=at(n,c);$.useEffect(()=>{a&&p([...a])},[a]),$.useEffect(()=>{r&&m([...r])},[r]);const O=e=>()=>{const i=n.indexOf(e),t=[...n];-1===i?t.push(e):t.splice(i,1),l(t)},N=e=>at(n,e).length,y=e=>()=>{var i,t;N(e)===e.length?l(ot(n,e)):l((i=n,t=e,[...i,...ot(t,i)]))},h=(a,r,d)=>{const l=r.filter(e=>{if(e[o]){const i=e[o];if("left"===d&&i.toLocaleLowerCase().includes(u.toLocaleLowerCase()))return!0;if("right"===d&&i.toLocaleLowerCase().includes(A.toLocaleLowerCase()))return!0}return!1});return e(Pe,{sx:{height:"100%"},children:[i(Me,{sx:{px:2,py:1},avatar:i(Se,{onClick:y(l),checked:N(l)===l.length&&0!==l.length,indeterminate:N(l)!==l.length&&0!==N(l),disabled:0===l.length,inputProps:{"aria-label":"all items selected"}}),title:a,subheader:`${N(r)} / ${r.length} Selected`}),i(f,{sx:{width:"100%",padding:1},children:i(tt,{fullWidth:!0,label:"search",value:"left"===d?u:A,onChange:e=>{"left"===d?T(e.target.value):_(e.target.value)}})}),i(ve,{}),i(De,{sx:{width:"100%",height:"80%",bgcolor:"secondary",overflow:"auto"},dense:!0,component:"div",role:"list",children:l.map(a=>(a[t],e(L,{role:"listitem",onClick:O(a),sx:{cursor:"pointer"},children:[i(ge,{children:i(Se,{checked:-1!==n.indexOf(a),tabIndex:-1,disableRipple:!0})}),i(be,{id:a[t],primary:a[o]})]},a[t])))})]})};return e(R,{container:!0,spacing:2,sx:{flexGrow:1,overflow:"auto",margin:1,display:"flex",width:"100%"},justifyContent:"center",alignItems:"center",children:[i(R,{sx:{height:"100%",flex:1},children:h("Available Items",s,"left")}),i(R,{children:e(R,{container:!0,direction:"column",alignItems:"center",children:[i(Ue,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{m(e=>{let i=c.concat(I);return d(i),i}),p(ot(s,I)),l(ot(n,I))},disabled:0===I.length,"aria-label":"move selected right",children:">"}),i(Ue,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{p(s.concat(E)),m(e=>{let i=ot(c,E);return d(i),i}),l(ot(n,E))},disabled:0===E.length,"aria-label":"move selected left",children:"<"})]})}),i(R,{sx:{height:"100%",flex:1},children:h("Currently Selected",c,"right")})]})},dt=e=>{const{t:t}=_e();return i(C,{sx:e.sx,hidden:e?.hidden||!1,disabled:e.disabled||!1,required:e.required||!1,control:i(D,{checked:e?.checkedValue==e.value||"true"===e.value||"1"==e.value,onChange:i=>{void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&(i.target.checked?void 0!==e.checkedValue&&null!=e.checkedValue?e.onChangeCallBack(e.checkedValue):e.onChangeCallBack(!0):void 0!==e.unCheckedValue&&null!=e.unCheckedValue?e.onChangeCallBack(e.unCheckedValue):e.onChangeCallBack(!1))}}),label:t(e.label)})},nt=e=>{const t=a(e=>e.AppLayout),{t:o}=_e();return i(P,{sx:e.sx,value:(i=>{for(let t of e.options)if(t[e.valueField]==i)return t;return null})(e.value),options:e.options,disabled:e.disabled,hidden:e?.hidden||!1,onChange:(i,t)=>{if(void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack)if(null!=t){let i=t[e.valueField];e.onChangeCallBack(i,t)}else e.onChangeCallBack(null,null)},clearOnBlur:!0,handleHomeEndKeys:!0,getOptionLabel:i=>null!=i?o(i[e.displayField]):"",renderOption:(t,a)=>i("li",{...t,children:null!=a?o(a[e.displayField]):""}),slots:{popper:e=>i(M,{...e,style:{...e.style,direction:t.appDirection}})},renderInput:t=>i(h,{...t,required:e.required||!1,variant:"outlined",slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:o(e.label),error:null!=e.errorMessage&&void 0!==e.errorMessage,helperText:null!=e.errorMessage&&void 0!==e.errorMessage?o(e.errorMessage):""})})},lt="YYYY-MM-DD",st="YYYY-MM-DD HH:mm:ss",pt="#37505C",ct="#ff6d00",mt="#ea690e",ut="#74776B",Tt=e=>{const{t:o}=_e();return e?.hidden?i(t,{}):i(we,{dateAdapter:Be,children:i(xe,{value:null!=e.value&&void 0!==e.value&&""!==e.value?ke(e.value,e?.format||lt):null,sx:e.sx,label:o(e.label),format:e?.format||lt,disabled:e.disabled,onChange:i=>{let t=null;null!=i&&i.isValid()&&(t=i.format(e?.format||lt)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(t)},slotProps:{textField:{InputLabelProps:{shrink:!0,sx:{fontWeight:"bold"}},variant:"outlined",required:e.required,error:void 0!==e.errorMessage&&null!=e.errorMessage,helperText:void 0!==e.errorMessage&&null!=e.errorMessage?i(t,{children:o(e.errorMessage)}):i(t,{})}}})})},At=e=>{const{t:o}=_e();return e?.hidden?i(t,{}):i(we,{dateAdapter:Be,children:i(Fe,{value:null!=e.value&&void 0!==e.value&&""!==e.value?ke(e.value,e?.format||st):null,label:o(e.label),sx:e.sx,format:e?.format||st,disabled:e.disabled,onChange:i=>{let t=null;null!=i&&i.isValid()&&(t=i.format(e?.format||st)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(t)},slotProps:{textField:{InputLabelProps:{shrink:!0,sx:{fontWeight:"bold"}},variant:"outlined",required:e.required,error:void 0!==e.errorMessage&&null!=e.errorMessage,helperText:void 0!==e.errorMessage&&null!=e.errorMessage?i(t,{children:o(e.errorMessage)}):i(t,{})}}})})},_t=e=>{const t=a(e=>e.AppLayout),o=Zi(),[r,d]=J([]),{handleGetRequest:n}=Hi();return ee(()=>{e.lookupType&&(async()=>{await n({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:e.lookupType},successCallBkFn:e=>{d(e.data)},failureCallBkFn:()=>{d([])}})})()},[e.lookupType,o.UserSession]),i(nt,{...e,options:r,displayField:"ltr"===t.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"})},ft=e=>({...e,type:"string",renderEditCell:e=>i(Tt,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:i=>{e.api.setEditCellValue({id:e.id,field:e.field,value:i})}}),valueParser:(e,i,t)=>{let o=null;return null!==e&&(o=ke(e).format(lt)),o},valueFormatter:(e,i,t)=>i[t.field]}),It=e=>({...e,type:"string",renderEditCell:e=>i(At,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:i=>{e.api.setEditCellValue({id:e.id,field:e.field,value:i})}}),valueParser:(e,i,t)=>{let o=null;return null!==e&&(o=ke(e).format(st)),o},valueFormatter:(e,i,t)=>i[t.field]}),Et=e=>({...e,type:"custom",valueGetter:e=>e?e+"":e,renderCell:e=>{let t=null;try{t=e.colDef.options.find(i=>i[e.colDef.valueField]==e.value)}catch(e){}return i("div",{children:null!=t?t[e.colDef.displayField]:e.value})},renderEditCell:e=>i(nt,{...e,sx:{width:"100%"},options:e.colDef.options,valueField:e.colDef.valueField,displayField:e.colDef.displayField,onChangeCallBack:(i,t)=>{null===i&&e.api.setEditCellValue({id:e.id,field:e.field,value:null}),e.api.setEditCellValue({id:e.id,field:e.field,value:i+""})}})}),Ot=e=>({...e,type:"custom",valueGetter:e=>null==e||null==e?null:e,renderCell:t=>{const o=t?.value;return o===e.checkedValue||"true"===o||1===o||!0===o?i(se,{icon:"check",color:"green"}):i(se,{icon:"xmark",color:"red"})},renderEditCell:t=>i(dt,{...t,checkedValue:e?.checkedValue||!0,unCheckedValue:e?.unCheckedValue||!1,onChangeCallBack:e=>{t.api.setEditCellValue({id:t.id,field:t.field,value:e})}})}),Nt=e=>{const i=[];if("field"===e.type&&"props"===e.mode&&e?.props)i.push(e.props);else if("group"===e.type&&e?.props&&e?.props?.elements)for(const t of e.props.elements)i.push(...Nt(t));return i},yt=e=>{const i=[];for(const t of e)i.push(...Nt(t));return i},ht=(e,i,t)=>{const o=[];for(const a of e)if("text"===a?.fieldType||"number"===a?.fieldType){const e={...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,type:"number"==a?.fieldType?"number":"string",field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200};o.push(e)}else if("date"===a?.fieldType){const e=ft({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else if("datetime"===a?.fieldType){const e=It({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else if("checkbox"===a?.fieldType){const e=Ot({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,checkedValue:a?.checkedValue,unCheckedValue:a?.unCheckedValue,width:150});o.push(e)}else if("combobox"===a?.fieldType){const e=Et({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,valueField:a?.optionValueField||"value",displayField:a?.optionDisplayField||"display",options:a?.options||[],flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else if("lookup"===a?.fieldType){const e=Et({...a?.gridProps?.muiProps,editable:null!=a?.gridProps?.muiProps?.editable?a?.gridProps?.muiProps?.editable:i,lookupType:a?.lookupType,field:a?.fieldName,headerName:t(a?.fieldLabel||a?.fieldName),headerAlign:"center",align:"center",hidden:a?.hidden,searchable:a?.gridProps?.searchable,valueField:a?.optionValueField||"value",displayField:a?.optionDisplayField||"display",options:a?.options||[],flex:a?.gridProps?.muiProps?.width?void 0:1,minWidth:200});o.push(e)}else{const e={field:a.fieldName,...a?.gridProps?.muiProps};o.push(e)}return o},Rt=e=>{const i={};for(const t of e)if(t?.fieldName){const e=t.fieldName;"number"===t.fieldType?i[e]=!0===t?.required?Le.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):Le.number().optional().nullable():"checkbox"===t.fieldType?i[e]=!0===t?.required?Le.boolean({required_error:"This field is required"}):Le.boolean().optional().nullable():i[e]=!0===t?.required?Le.string({message:"This field is required"}).min(1,"This field is required"):Le.string().optional().nullable()}return i},Lt=(e,i,t)=>{const o=[],a=[];if("exclude"===e.type&&0===e.ids.size)for(const e of i)o.push(e),a.push(e[t]);else if(e?.ids)for(const r of e.ids){const e=i.find(e=>e[t]===r);o.push(e),a.push(r)}return{selectedRecords:o,selectedRecordIds:a}};function Ct(e,...i){const t=new URL(`https://mui.com/production-error/?code=${e}`);return i.forEach(e=>t.searchParams.append("args[]",e)),`Minified MUI error #${e}; visit ${t} for the full message.`}function Dt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Pt,Mt={exports:{}},bt={exports:{}},gt={};var St,Ut,vt,wt,xt,Ft,Bt,kt,Wt,Gt,Yt,Vt,qt,Kt,zt,Ht={};
|
|
2
2
|
/** @license React v16.13.1
|
|
3
3
|
* react-is.development.js
|
|
4
4
|
*
|
|
@@ -28,7 +28,7 @@ object-assign
|
|
|
28
28
|
* This source code is licensed under the MIT license found in the
|
|
29
29
|
* LICENSE file in the root directory of this source tree.
|
|
30
30
|
*/
|
|
31
|
-
function(e,i){const t=bi(e,i);return"production"!==process.env.NODE_ENV?(...i)=>{const o=`"${e}"`;return 0===i.length?console.error([`MUI: Seems like you called \`styled(${o})()\` without a \`style\` argument.`,'You must provide a `styles` argument: `styled("div")(styleYouForgotToPass)`.'].join("\n")):i.some(e=>void 0===e)&&console.error(`MUI: the styled(${o})(...args) API requires all its args to be defined.`),t(...i)}:t}("div",{shouldForwardProp:e=>"theme"!==e&&"sx"!==e&&"as"!==e})(Ea),n=$.forwardRef(function(e,n){const l=function(e=ya){return Na(e)}(o),{className:s,component:p="div",...c}=ha(e);return i(d,{as:p,ref:n,className:Da(s,r?r(a):a),theme:t&&l[t]||l,...c})});return n}({defaultClassName:function(e,i,t="Mui"){const o={};return i.forEach(i=>{o[i]=function(e,i,t="Mui"){const o=Pa[i];return o?`${t}-${o}`:`${La.generate(e)}-${i}`}(e,i,t)}),o}("MuiBox",["root"]).root,generateClassName:La.generate});function ba(e){return/^\d+$/.test(e)}function ga(e){return"number"==typeof e&&!isNaN(e)}function Sa(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function Ua(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function va(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function wa(e,i){const t=new Date(e),o=new Date,a=Math.floor((t-o)/1e3),r="rtl"===i?"ar":"en",d=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=[{unit:"year",seconds:31536e3},{unit:"month",seconds:2592e3},{unit:"week",seconds:604800},{unit:"day",seconds:86400},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(const{unit:e,seconds:i}of n){const t=Math.floor(a/i);if(Math.abs(t)>1)return d.format(t,e)}return"ar"===r?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(Ma.propTypes={children:to.node,component:to.elementType,sx:to.oneOfType([to.arrayOf(to.oneOfType([to.func,to.object,to.bool])),to.func,to.object])});const xa=e=>{if(e?.fieldInfo){const o=e.fieldInfo,a=e?.formManager||null,r=e?.formActions||null,d=e?.formValues||null,n=e?.fieldInfo?.fieldName||null,l=e?.fieldInfo?.fieldType||null;return o&&a&&d&&n&&l?e.hiddenFields.includes(n)?i(t,{}):i(R,{size:o?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===l||"number"===l?i(tt,{...o.muiTextFieldProps,fullWidth:!0,type:l,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),label:o?.fieldLabel,value:d[n],onChange:e=>{let i=null;""!=e.target.value&&(i="number"===l&&Sa(e.target.value)?Number(e.target.value):e.target.value),a.setValue(n,i),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(i,a,r)},sx:{"& .MuiInputBase-root":{height:`${o?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...o?.formProps?.style},error:null!=a.formState.errors[n],helperText:a?.formState?.errors[n]?.message?.toString()}):"date"===o?.fieldType?i(Tt,{format:o?.dateFormat||lt,sx:o?.formProps?.style||{width:"100%"},disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),label:o?.fieldLabel,onChangeCallBack:e=>{a.setValue(n,e),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(e,a,r)},value:d[n],error:null!=a.formState.errors[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):"datetime"===o?.fieldType?i(At,{format:o?.dateFormat||st,sx:o?.formProps?.style||{width:"100%"},disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),label:o?.fieldLabel,onChangeCallBack:e=>{a.setValue(n,e),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(e,a,r)},hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),value:d[n],error:null!=a.formState.errors[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):"checkbox"===o?.fieldType?i(dt,{label:o?.fieldLabel,onChangeCallBack:e=>{a.setValue(n,e),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(e,a,r)},hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),value:d[n],checkedValue:o?.checkedValue||!0,unCheckedValue:o?.unCheckedValue||!1,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),sx:o?.formProps?.style}):"combobox"===o?.fieldType?i(nt,{sx:o?.formProps?.style||{width:"100%"},label:o?.fieldLabel,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),onChangeCallBack:(e,i)=>{let t=null;e&&(t=e+""),a.setValue(n,t),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(t,a,r,i)},options:o?.options||[],displayField:o?.optionDisplayField||"",valueField:o?.optionValueField||"",value:d[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):"lookup"===o?.fieldType?i(_t,{sx:o?.formProps?.style||{width:"100%"},label:o?.fieldLabel,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),onChangeCallBack:(e,i)=>{let t=null;e&&(t=e+""),a.setValue(n,t),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(t,a,r,i)},lookupType:o.lookupType,value:d[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):null}):i(t,{})}return i(t,{})},Fa=o=>{const a=Zi(),{ConfirmationWindow:r,setOpen:d}=Qi({body:o?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{o?.actionFn(o?.record)}});return null==o?.authority||a.isUserAuthorized(o.authority)?e(t,{children:[i(r,{}),e(A,{variant:o?.formActionProps?.actionButtonVariant,color:o?.formActionProps?.actionButtonColor,onClick:()=>{if(o?.actionFn){if(o?.preActionValidation&&!o.preActionValidation(o.record))return;!0===o?.isConfirmationRequired?d(!0):o?.actionFn(o.record)}},children:[o?.icon?i(se,{icon:o.icon,style:{marginRight:5,marginLeft:5}}):i(t,{}),i("div",{children:o?.label})]})]}):i(t,{})},Ba=o=>{const{t:a}=_e();return i(t,{children:e(R,{container:!0,sx:o?.style,alignItems:"flex-start",children:[o?.label?i(R,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:o?.icon?e(t,{children:[i(se,{icon:o.icon,style:{marginRight:5,marginLeft:5}}),i("div",{children:a(o.label)})]}):i(t,{children:a(o.label)})}):i(t,{}),o?.elements?o.elements.map(e=>"group"===e.type?i(Ba,{...e.props,formManager:o.formManager,formValues:o.formValues,formActions:o.formActions,hiddenFields:o.hiddenFields,disabledFields:o.disabledFields}):"field"===e.type&&"props"===e.mode?i(xa,{fieldInfo:e.props,formManager:o.formManager,formValues:o.formValues,formActions:o.formActions,hiddenFields:o.hiddenFields,disabledFields:o.disabledFields}):"field"===e.type&&"node"===e.mode?i(R,{size:e?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:i(e.node,{formManager:o.formManager,formValues:o.formValues,formActions:o.formActions})}):void 0):null,o?.actions?i(R,{size:{sm:12},sx:{padding:1},children:o.actions.map(e=>i(Fa,{...e,record:o.formValues}))}):i(t,{})]})})},ka=e=>{const t=a(e=>e.AppInfo.value.apiBaseUrl),[o,r]=J(null);return ee(()=>{(()=>{let i=t+"/api/v1/attachment/";e?.attachmentId?i+="download?attachmentId="+e.attachmentId:(i+=`downloadImage?attachmentCode=${e.attachmentCode}&refKey=${e.refKey}`,e?.category&&(i+=`&category=${e.category}`)),r(i)})()},[e]),e?.showAsAvatar?i(b,{sx:e.style,onError:()=>{r(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:o}):i("img",{src:o,loading:"lazy",alt:"image",onError:()=>{r(e?.onErrorImage?e.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Wa=o=>{const{handleGetRequest:a,handleDeleteRequest:r}=Hi(),{isUserAuthorized:d}=Zi();let n=!0;o?.downloadAuthorityKey&&(n=d(o.downloadAuthorityKey));const{ConfirmationWindow:l,setOpen:s}=Qi({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await r({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:o.attachmentCode,refKey:o.refKey,attachmentId:o.id},successCallBkFn:e=>{o.setAttachmentConfig(e.data)},showMask:!0})})()}});return e(t,{children:[i(l,{}),e(Pe,{sx:{width:300,border:"0.5px solid gray"},children:[i(Ye,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:o?.docType.toLocaleLowerCase().includes("image")?i(ka,{attachmentId:o.id}):i(se,{icon:"file",size:"3x"})}),e(Ge,{children:[i(Ve,{gutterBottom:!0,variant:"h6",component:"div",children:o.fileName}),i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${o?.attachmentSize||"unknown"} kb`}),i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${o?.category||"NA"}`}),i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:o.remark})]}),e(We,{children:[o?.allowDelete?i(N,{size:"small",onClick:()=>{s(!0)},children:i(g,{title:"Delete Attachment",children:i(se,{icon:"trash"})})}):i(t,{}),i("div",{style:{flex:1}}),n?i(N,{size:"small",onClick:async()=>{await a({endPointURI:"api/v1/attachment/download",parameters:{attachmentId:o.id},showMask:!0,responseType:"blob",successCallBkFn:e=>{const i=window.URL.createObjectURL(new Blob([e.data])),t=document.createElement("a");t.href=i,t.setAttribute("download",o.fileName),document.body.appendChild(t),t.click(),t.remove()}})},children:i(g,{title:"Download Attachment",children:i(se,{icon:"download"})})}):i(t,{})]})]})]})},Ga=o=>{const{handleUploadRequest:a,handleGetRequest:r}=Hi(),[d,n]=J(null),[l,s]=J([]),[p,c]=J(null),[m,u]=J(null),[T,_]=J([]),[f,I]=J(null),{isUserAuthorized:E}=Zi(),O=e=>e.split(".").pop()?.toLowerCase()||"";ee(()=>{(async()=>{await r({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:o.attachmentCode,refKey:o.refKey},successCallBkFn:e=>{I(e.data)}})})()},[o.refKey,o.attachmentCode]),ee(()=>{if(_(f?.allowedFileTypes?f.allowedFileTypes.split(","):[]),f?.attachmentCategories){const e=[];for(const i of f.attachmentCategories.split(","))e.push({value:i});s(e)}else s([])},[f]);let N=!0;f?.downloadAuthorityKey&&!E(f?.downloadAuthorityKey)&&(N=!1);let h=!0;return!1===o?.enableAttachment&&(h=!1),f?.uploadAuthorityKey&&!E(f.uploadAuthorityKey)&&(h=!1),e(y,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[i(t,h?{children:null==f?.maxAllowedNumberOfFiles||f?.maxAllowedNumberOfFiles>f.refKeyAttachments.length?e(t,{children:[e("h3",{children:[i(se,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),i("input",{type:"file",style:{margin:20},accept:f?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const i of e.target.files){const e=O(i.name);if(T.length>0&&!T.includes(e))return void me.error(e+" is not allowed")}n(e.target.files)}}),l.length>0?i(nt,{label:"Attachment Type",sx:{width:300,m:1},options:l,displayField:"value",valueField:"value",value:m,onChangeCallBack:e=>{u(e)}}):i(t,{}),i(tt,{label:"Remark",value:p,onChange:e=>c(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),i(A,{sx:{m:1},variant:"contained",onClick:async()=>{let e=f?.refKeyAttachments.length||0;if(f?.maxAllowedNumberOfFiles&&d.length+e>f.maxAllowedNumberOfFiles)me.error("Maximum number of attachments is "+f.maxAllowedNumberOfFiles);else if(!0===f?.isCategoryRequired&&l.length>0&&(null==m||void 0===m||""===m))me.error("You must selected document type to process your request");else if(d){for(const e of d)if(e.type.startsWith("image/")){const i=600,t=1024*i;if(e.size>t)return void me.error(`File ${e.name} is too large. Max allowed is ${i}KB.`)}await a({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:o.refKey,attachmentCode:o.attachmentCode,remark:p,category:m},files:d,successCallBkFn:e=>{I(e.data),n(null),u(null),c(null),me.success("Your request has been process successfully")}})}else me.error("You must add files to upload")},children:"Upload"})]}):i(t,{})}:{}),N&&f?.refKeyAttachments?.length>0?e(t,{children:[e("h3",{children:[i(se,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),i(R,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:f?.refKeyAttachments.map(e=>i(R,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:i(Wa,{...e,attachmentCode:o.attachmentCode,setAttachmentConfig:I,downloadAuthorityKey:f.downloadAuthorityKey,allowDelete:h})}))})]}):i(t,{})]})},Ya=o=>{const r=a(e=>e.AppLayout),{t:d}=_e();return e(y,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[e(f,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[i(se,{icon:"history",style:{marginRight:10,marginLeft:10}}),d("WF_ACTION_HISTORY_LABEL")]}),i(f,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:o.actionHistory.map((a,d)=>i(t,{children:e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[e(f,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[i(f,{sx:{marginBottom:.2},children:a.actionTime}),e(Ve,{children:["via ",a.actionMethod]})]}),e(f,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[i(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:a?.personId+""||"0",style:{m:1,width:70,height:70}}),d!==o.actionHistory.length-1?i(f,{sx:{marginTop:11,position:"absolute"},children:"|"}):i(t,{})]}),e(f,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[e(f,{sx:{width:"100%"},children:["ltr"===r.appDirection?`${a?.documentActionEnName}`:`${a?.documentActionArName}`,a?.actionComment?" - "+a.actionComment:""]}),i(f,{sx:{width:"100%"},children:"ltr"===r.appDirection?`${a?.employeeEnName}`:`${a?.employeeArName}`})]})]})}))})]})},Va=o=>{const{t:a}=_e(),r=Zi(),{ConfirmationWindow:d,setOpen:n}=Qi({body:a(o?.confirmationMessage||"ACTION_CONFIRMATION"),title:a("CONFIRMATION"),onConfirmationCallBk:async()=>{await(o?.actionFn(o.recordsToProcessActionOn,o.recordIdsToProcessActionOn)),o?.reloadData&&o.reloadData()}});let l=!0;if(o.authority&&(l=r.isUserAuthorized(o.authority)),l)return e(t,{children:[i(d,{}),e(A,{onClick:async()=>{if(o?.recordsToProcessActionOn&&o?.recordsToProcessActionOn.length>0){if(o?.preActionValidation)for(const e of o.recordsToProcessActionOn)if(!o.preActionValidation(e))return;!0===o?.isConfirmationRequired?n(!0):(await o.actionFn(o.recordsToProcessActionOn,o.recordIdsToProcessActionOn),o?.reloadData&&o.reloadData())}else me.error(a("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"))},variant:o?.label?"outlined":o?.formActionProps?.actionButtonVariant?o.formActionProps.actionButtonVariant:"text",size:"small",color:o?.formActionProps?.actionButtonColor||"primary",children:[o?.icon?i(se,{style:{marginRight:5,marginLeft:5},icon:o.icon}):i(t,{}),o?.label?a(o.label):i(t,{})]})]})},qa=S(qe)({display:"grid",alignItems:"center"}),Ka=S(Ke)(({theme:e,ownerState:i})=>({gridArea:"1 / 1",width:"min-content",height:"min-content",zIndex:1,opacity:i.expanded?0:1,pointerEvents:i.expanded?"none":"auto",transition:e.transitions.create(["opacity"])})),za=S(h)(({theme:e,ownerState:i})=>({gridArea:"1 / 1",overflowX:"clip",width:i.expanded?260:"var(--trigger-width)",opacity:i.expanded?1:0,transition:e.transitions.create(["width","opacity"])})),Ha=o=>{const{t:a}=_e(),r=Zi(),d=!o?.templateProps?.editAction?.authority||r.isUserAuthorized(o.templateProps.editAction.authority),n=Lt(o?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},o?.templateProps?.data||[],o?.templateProps?.keyColumnName||"id");return e(ze,{children:[d&&"none"!=o?.templateProps?.editMode?.editMode?e(A,{onClick:o?.handleCreateNewRecord,children:[i(se,{icon:"add",style:{marginRight:5,marginLeft:5}}),a("ADD_BTN_LABEL")]}):i(t,{}),o?.templateProps?.rowActions?o.templateProps.rowActions.map((e,i)=>!0===e?.gridActionProps?.multiRecord?ie(Va,{...e,key:i,reloadData:async()=>{o.templateProps.apiActions.reloadData(o?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:n.selectedRecordIds,recordsToProcessActionOn:n.selectedRecords}):null):i(t,{}),i(f,{sx:{flex:1,mx:.5},children:o?.templateProps?.tBar}),i(g,{title:"Columns",children:i(He,{render:i(Ke,{}),children:i(Qe,{fontSize:"small"})})}),i(g,{title:"Filters",children:i(Ze,{render:(e,t)=>i(Ke,{...e,color:"default",children:i(U,{badgeContent:t.filterCount,color:"primary",variant:"dot",children:i(je,{fontSize:"small"})})})})}),o?.templateProps?.gridStateKey?i(g,{title:a("RESET_GRID_STATE"),children:i(N,{onClick:o?.clearGridState,children:i(se,{icon:"eraser"})})}):i(t,{}),i(v,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),i(g,{title:a("EXPORT_EXECL_LABEL"),children:i($e,{render:i(w,{}),children:i(se,{icon:"file-excel",color:"green"})})}),e(qa,{children:[i(Xe,{render:(e,t)=>i(g,{title:a("SEARCH_BTN_LABEL"),enterDelay:0,children:i(Ka,{...e,ownerState:{expanded:t.expanded},color:"default","aria-disabled":t.expanded,children:i(se,{icon:"search"})})})}),i(Je,{render:({ref:e,...t},o)=>i(za,{...t,ownerState:{expanded:o.expanded},inputRef:e,"aria-label":"Search",placeholder:`${a("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:i(x,{position:"start",children:i(se,{icon:"search"})}),endAdornment:o.value?i(x,{position:"end",children:i(ei,{edge:"end",size:"small","aria-label":"Clear search",children:i(se,{icon:"xmark"})})}):null,...t.slotProps?.input},...t.slotProps}})})]}),i(N,{onClick:()=>{o.templateProps.apiActions.reloadData(o?.templateProps?.gridLoadParametersValues)},children:i(se,{icon:"refresh"})})]})},Qa=o=>{const{t:a}=_e(),r=Zi(),{ConfirmationWindow:d,setOpen:n}=Qi({body:a(o?.confirmationMessage||"ACTION_CONFIRMATION"),title:a("CONFIRMATION"),onConfirmationCallBk:async()=>{await(o?.actionFn(o.record)),o?.reloadData&&o.reloadData()}});let l=!0;o.authority&&(l=r.isUserAuthorized(o.authority));let s={};o?.getActionIconStyleForRecord&&(s=o.getActionIconStyleForRecord(o.record));let p=!0;o?.isActionVisibleForRecord&&(p=o?.isActionVisibleForRecord(o.record));let c=!1;if(o?.isActionDisabledForRecord&&(c=o.isActionDisabledForRecord(o.record)),l&&p)return e(t,{children:[i(d,{}),i(ii,{disabled:c,icon:i(g,{title:o?.label?a(o.label):"",children:i(se,{icon:o.icon,style:{...s,color:c?"gray":null!=s?.color?s.color:void 0}})}),showInMenu:o?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!c){if(o?.preActionValidation&&!o.preActionValidation(o.record))return;!0===o?.isConfirmationRequired?n(!0):(await o.actionFn(o.record),!0===o?.gridActionProps?.reloadGridAfterAction&&o?.reloadData&&o.reloadData())}}})]})};let Za=-1;const ja=e=>{try{const i=localStorage.getItem(e);return i?JSON.parse(i):{}}catch(e){return console.error("Failed to load grid state",e),{}}},$a=(e,i)=>{const t=ja(e);localStorage.setItem(e,JSON.stringify({...t,...i}))},Xa=["__check__","actions"],Ja=o=>{const{t:r}=_e(),d=a(e=>e.AppLayout),[n,l]=J({}),[s,p]=J(!0),{getLookupOptions:c}=(()=>{const{handleGetRequest:e}=Hi(),i=a(e=>e.AppLayout),t=async i=>{let t=[];return await e({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:i},successCallBkFn:e=>{t=e.data}}),t};return{generateLookupGridColumn:async e=>{let o=await t(e.lookupType);return{...e,options:o,displayField:"ltr"===i.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:t}})(),{Window:m,setWindowState:u}=ji({windowTitle:r(o.gridTitle)+" Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"50%",onCloseCallBack:()=>{o?.apiActions?.reloadData(o.gridLoadParametersValues)}}),{Window:T,setWindowState:A}=ji({windowTitle:r(o.gridTitle)+" Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"80%",onCloseCallBack:()=>{o?.apiActions?.reloadData(o.gridLoadParametersValues)}}),[_,I]=J([]),E=yt(o.formElements),y=[],h=X.useMemo(()=>o?.gridStateKey?ja(o.gridStateKey):{},[]);for(const e of E)!0===e?.gridProps?.hidden&&y.push(e.fieldName);let R={};if(h?.columnVisibilityModel){R=h.columnVisibilityModel;const e=Object.keys(R);for(const i of y)e.includes(i)||(R[i]=!1)}else for(const e of y)R[e]=!1;const L=a(e=>e.AppLayout.appDirection),[C,D]=X.useState(R),[P,M]=X.useState(h.columnOrder||[]),[b,S]=X.useState(h.columnWidths||{}),[U,w]=J(h.columnGroupingModel||[]);let x=h?.pinnedColumns?.left||[];x=x.filter(e=>!Xa.includes(e));let W=h?.pinnedColumns?.right||[]||[];W=W.filter(e=>!Xa.includes(e));const[G,Y]=J({left:[..."ltr"===L?Xa:[],...x],right:[..."rtl"===L?Xa:[],...W]}),V=Zi(),q=Ee(),[K,z]=J(null),[H,Q]=J(null),[Z,j]=J({}),$=async()=>{let e=ht(E,"row"===o?.editMode?.editMode||!1,r);for(let i of e)i?.lookupType&&(i.displayField="ltr"===d.appDirection?"lookupEnDisplay":"lookupArDisplay",i.options=await c(i.lookupType),i.valueField="lookupValue");I(e)},[ie,te]=J({ids:new Set,type:"include"});let oe="id";o?.keyColumnName&&(oe=o?.keyColumnName);const ae=o.setData,re=Ce.object(Rt(E));let de=!0;o?.editAction?.authority&&(de=V.isUserAuthorized(o.editAction.authority));let ne=!0;o?.deleteAction?.authority&&(ne=V.isUserAuthorized(o.deleteAction.authority));const{ConfirmationWindow:le,setOpen:pe}=Qi({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let e=!0;K&&!0===K?.isNew||(e=await o.apiActions.deleteRecordById(K[oe])),e&&(o?.deleteAction?.postActionCallBack&&await o.deleteAction.postActionCallBack(K),ae(e=>e.filter(e=>e[oe]!=K[oe])))}});let ce,ue,Te,Ae,fe,Ie;"modal"===o?.editMode?.editMode&&(ce=o?.editMode?.specs?.modalHeight||"fit-content",ue=o?.editMode?.specs?.modalWidth||"300",Te=o?.editMode?.specs?.modalMinHeight,Ae=o?.editMode?.specs?.modalMinWidth,fe=o?.editMode?.specs?.modalIcon||"window",Ie=o?.editMode?.specs?.modalTitle||"Record Form");const{Window:Oe,setWindowState:Ne}=ji({height:ce,minHeight:Te,minWidth:Ae,onCloseCallBack:()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},width:ue,windowIcon:fe,windowTitle:Ie}),ye={type:"actions",field:"actions",headerName:"",headerAlign:"center",width:(o?.rowActions?30*o.rowActions.length:0)+(o?.editAction&&o?.editAction?.isEnabled?30:0)+(o?.deleteAction&&o?.deleteAction?.isEnabled?30:0)+(o?.attachment?30:0)+(o?.workFlowDocumentCode?30:0),getActions:e=>{const t=e.row,a=[];if("none"!=o?.editMode?.editMode&&(void 0===o?.disableDefaultAction||!o.disableDefaultAction)){const e=Z[t[oe]]?.mode===ai.Edit;if("row"===o.editMode.editMode&&e)de&&(a.push(i(ii,{icon:i(se,{icon:"save"}),label:r("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const i=e[oe];j({...Z,[i]:{mode:ai.View}})})(t)}})),a.push(i(ii,{icon:i(se,{icon:"cancel"}),label:r("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const i=e[oe];i&&ga(i)&&i<0?(j({...Z,[i]:{mode:ai.View,ignoreModifications:!0}}),ae(e=>{const t=e.filter(e=>e[oe]!=i);return t})):j({...Z,[i]:{mode:ai.View,ignoreModifications:!0}})})(t)},color:"inherit"})));else{if(o?.editAction&&!0===o?.editAction?.isEnabled){let e=!0;o?.editAction?.isActionVisibleForRecord&&(e=o?.editAction?.isActionVisibleForRecord(t));let d=!1;o?.editAction?.isActionDisabledForRecord&&(d=o?.editAction?.isActionDisabledForRecord(t)),de&&e&&a.push(i(ii,{disabled:d,icon:i(g,{title:r("EDIT_BTN_LABEL"),children:i(se,{icon:"edit",style:{color:d?"gray":void 0}})}),showInMenu:o?.editAction?.gridActionProps?.showInMenu||!1,label:r("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{de&&!d&&(async e=>{if(e)if(Q(e),"form"===o.editMode.editMode)q(o.editMode.specs.formRoute+"/"+e[oe]);else if("modal"===o.editMode.editMode)Ne(!0);else if("row"===o?.editMode?.editMode){const i=e[oe];j({...Z,[i]:{mode:ai.Edit}})}})(t)}}))}if(o?.deleteAction&&!0===o?.deleteAction?.isEnabled){let e=!0;o?.deleteAction?.isActionVisibleForRecord&&(e=o?.deleteAction?.isActionVisibleForRecord(t));let d=!1;o?.deleteAction?.isActionDisabledForRecord&&(d=o?.deleteAction?.isActionDisabledForRecord(t)),ne&&e&&a.push(i(ii,{disabled:d,icon:i(g,{title:r("DELETE_BTN_LABEL"),children:i(se,{icon:"trash",style:{color:d?"gray":void 0}})}),showInMenu:o?.deleteAction?.gridActionProps?.showInMenu||!1,label:r("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(ne&&!d){if(o?.deleteAction?.preActionValidation&&!o.deleteAction.preActionValidation(t))return;z(t),pe(!0)}}}))}}}if(t[o?.keyColumnName||"id"]&&t[o?.keyColumnName||"id"]>0&&o?.attachment&&a?.push(i(ii,{icon:i(g,{title:"Attachments",children:i(se,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{l(t),p(!o?.attachment?.enableAttachFn||o.attachment.enableAttachFn(t)),u(!0)}})),t[o?.keyColumnName||"id"]&&t[o?.keyColumnName||"id"]>0&&o?.workFlowDocumentCode&&a?.push(i(ii,{icon:i(g,{title:"Approvals",children:i(se,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{l(t),A(!0)}})),t[o?.keyColumnName||"id"]&&t[o?.keyColumnName||"id"]>0&&o?.rowActions)for(const e of o.rowActions)e?.gridActionProps?.multiRecord&&!0===e?.gridActionProps?.multiRecord||a.push(i(Qa,{...e,record:t,reloadData:async()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)}}));return a}};let he=[];(void 0===o?.disableDefaultAction||!o.disableDefaultAction||o?.rowActions&&o?.rowActions.length>0)&&he.push(ye),he=[...he,..._];ee(()=>{void 0!==o?.autoLoad&&!0!==o.autoLoad||o.apiActions.reloadData(o?.gridLoadParametersValues),$()},[]),ee(()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},[V.UserInfo?.currentOrganization]),ee(()=>{$()},[L,o.formElements]);const Re=X.useMemo(()=>{const e=he.map(e=>({...e,width:b[e.field]||e.width}));if(P.length){const i=new Map(e.map(e=>[e.field,e]));return P.map(e=>i.get(e)).filter(Boolean)}return e},[P,b,he]);return e(t,{children:[i(le,{}),"modal"===o?.editMode?.editMode?i(Oe,{children:o?.editMode?.specs?.formComponent?i(o.editMode.specs.formComponent,{recordIdToEdit:H?H[oe]:void 0,formCloseCallBk:()=>{Ne(!1),o.apiActions.reloadData(o?.gridLoadParametersValues)}}):i(ar,{keyColumnName:o.keyColumnName,attachment:o.attachment,formLoadCallBk:o.formLoadCallBk,recordIdToEdit:H?H[oe]:void 0,formCloseCallBk:()=>{Ne(!1),o.apiActions.reloadData(o?.gridLoadParametersValues)},elements:o.formElements,apiActions:o.apiActions,editAuthorityKey:o?.editAction?.authority,formSavedSuccessfullyCallBk:o?.editAction?.postActionCallBack,preSaveValidation:o?.editAction?.preActionValidation,actions:o?.rowActions})}):i(t,{}),void 0!==o?.hideInfoBar||o?.hideInfoBar?i(t,{}):e(f,{sx:{display:"flex"},children:[void 0!==o?.hideBackButton||o?.hideBackButton?i(t,{}):i(N,{onClick:()=>{q(-1,{replace:!0})},children:i(se,{icon:"arrow-left"})}),e(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[o?.girdIcon?i(se,{icon:o.girdIcon,style:{marginRight:5,marginLeft:5}}):i(t,{}),i(O,{variant:"h5",children:o?.gridTitle?Ua(r(o?.gridTitle)):""})]})]}),o?.gridLoadParameters&&o?.gridLoadParameters.length>0&&o?.gridLoadParametersValues&&o?.setGridLoadParametersValues?e(F,{defaultExpanded:!0,sx:{width:"100%"},children:[i(B,{expandIcon:i(ti,{}),children:e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[i(se,{style:{marginLeft:5,marginRight:5},icon:"search"}),i(O,{component:"span",children:"Filters"})]})}),i(k,{children:i(f,{children:i(ar,{saveButtonSpecs:{label:r("SEARCH_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:r("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{null!=e?o.setGridLoadParametersValues(e):o.setGridLoadParametersValues({}),o.apiActions.reloadData(e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:o.gridLoadParameters})})})]}):i(t,{}),o?.attachment?i(m,{children:i(Ga,{attachmentCode:o.attachment.attachmentCode,refKey:n[o?.keyColumnName||"id"],enableAttachment:s})}):i(t,{}),o?.workFlowDocumentCode?i(T,{children:i(or,{workFlowDocumentCode:o.workFlowDocumentCode,refDocumentId:n[o?.keyColumnName||"id"],postActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)},cancelActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)}})}):i(t,{}),i(oi,{...o?.muiProps,slots:{toolbar:Ha},slotProps:{toolbar:{templateProps:{...o,rowSelectionModel:ie,data:o?.data},handleCreateNewRecord:()=>{if("form"===o?.editMode?.editMode)q(o.editMode.specs.formRoute);else if("modal"===o?.editMode?.editMode)Q(null),Ne(!0);else if("row"===o?.editMode?.editMode){Za-=1;const e={};e[oe]=Za,e.isNew=!0;for(const i of _)"actions"!=i?.type&&i?.field!=oe&&i?.field&&(e[i.field]=null);ae(i=>[e,...i]),j(e=>({...e,[Za]:{mode:ai.Edit}}))}},clearGridState:()=>{o?.gridStateKey&&localStorage.removeItem(o.gridStateKey),D({}),M([]),S({}),w([]),Y({left:[..."ltr"===L?Xa:[]],right:[..."rtl"===L?Xa:[]]})}}},getRowId:e=>e[oe],showToolbar:!0,rows:o?.data,columns:Re,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,i)=>{"rowFocusOut"===e.reason&&(i.defaultMuiPrevented=!0)},rowModesModel:"row"==o.editMode.editMode?Z:void 0,onRowModesModelChange:"row"==o.editMode.editMode?e=>{j(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async a=>{if("row"===o.editMode.editMode){let r=null;const d=(e=>{try{re.parse(e)}catch(e){console.log("validateRecord err",e);let i=null;return i=e instanceof Ce.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",i}})(a);if(d){const o=d.split(",");throw me.error(i("div",{style:{},children:o.map(o=>e(t,{children:[i("div",{children:o}),i(v,{})]}))})),new Error(d)}if(o?.editAction?.preActionValidation&&!o.editAction.preActionValidation(a))throw new Error("error on the configured presave validation");const n={...a};if(a[oe]&&ga(a[oe])&&Number(a[oe])<0&&(n[oe]=null),r=await o.apiActions.saveRecord(n),null==r)throw new Error("Failed to process your request, contact your administrator");return o?.editAction?.postActionCallBack&&await o.editAction.postActionCallBack(a),!0===a?.isNew&&ae(e=>{const i=e.filter(e=>e[oe]!==a[oe]);return[r,...i]}),!0===o?.editMode?.reloadAfterSave&&o?.apiActions?.reloadData&&o?.apiActions?.reloadData(o?.gridLoadParametersValues),r}},rowSelectionModel:ie,onRowSelectionModelChange:e=>{te(e)},columnVisibilityModel:C,onColumnVisibilityModelChange:e=>{D(e),o?.gridStateKey&&$a(o.gridStateKey,{columnVisibilityModel:e})},onColumnOrderChange:e=>{const{column:i,targetIndex:t}=e;M(e=>{const a=e.length?[...e]:he.map(e=>e.field),r=a.indexOf(i.field);return-1===r||(a.splice(r,1),a.splice(t,0,i.field),o?.gridStateKey&&$a(o.gridStateKey,{columnOrder:a})),a})},onColumnWidthChange:e=>{const i={...b,[e.colDef.field]:e.width};S(i),o?.gridStateKey&&$a(o.gridStateKey,{columnWidths:i})},rowGroupingModel:U,onRowGroupingModelChange:e=>{(e=>{w(e),o?.gridStateKey&&$a(o.gridStateKey,{columnGroupingModel:e})})(e)},sx:{width:"100%"}})]})},er=e=>{if(0===e.length)return[];const i=[];for(const t of Object.keys(e[0])){const e={type:"field",mode:"props",props:{fieldLabel:t,fieldName:t,fieldType:"text"}};i.push(e)}return i},ir=e=>{const[t,o]=J([]);return ee(()=>{const i=e.reportData.map((e,i)=>({...e,report_record_data_key:i}));o(i)},[e.reportData]),i(Ja,{data:t,disableDefaultAction:!0,setData:e.setReportData,formElements:er(e.reportData),gridLoadParameters:e.gridLoadParameters,gridLoadParametersValues:e.gridLoadParametersValues,setGridLoadParametersValues:e.setGridLoadParametersValues,editMode:{editMode:"none"},girdIcon:"file-excel",gridTitle:"Report",autoLoad:!0,keyColumnName:"report_record_data_key",hideInfoBar:!0,apiActions:{deleteRecordById:async()=>!0,loadRecordById:async()=>{},reloadData:async()=>{e.reloadReport()},saveRecord:async()=>{}}})},tr=o=>{const[a,r]=J(null),[d,n]=J(null),[l,s]=J([]),[p,c]=J("WAITING_REPORT_CODE"),{handleGetRequest:m,handlePostRequest:u,HandleDownloadHTTPPostPDF:T}=Hi(),[A,_]=J(null),[I,E]=J({...o?.reportParametersValues}),[y,h]=J([]),{t:R}=_e(),L=e=>{const i=[];for(const t of e){const e={type:"field",mode:"props",props:{fieldLabel:t?.parameterLabel,fieldName:t?.parameterCode,fieldType:t?.parameterType,hidden:t?.hidden,formProps:{fieldSize:{lg:4,md:6,sm:12}},required:t?.mandatory,defaultValue:I[t?.parameterCode]||t?.defaultValue}};i.push(e)}return i},C=async(e,i)=>{c("WAITING_RESULT"),"Excel"===e?.reportType?await u({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:o.reportCode,parameters:i,resultMode:o.resultMode,jasperOutPutFileType:o.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT"),s(e.data)}}):e?.reportType&&await T({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:o.reportCode,parameters:i,resultMode:o.resultMode,jasperOutPutFileType:o.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT");const i=e.headers["content-disposition"];let t="downloaded_file";if(i&&-1!==i.indexOf("filename=")){const e=i.match(/filename="?([^"]+)"?/);e&&e[1]&&(t=e[1])}if(t.includes("pdf")){const i=new Blob([e.data],{type:"application/pdf"}),t=URL.createObjectURL(i);r(t)}else{const i=new Blob([e.data],{type:e.headers["content-type"]}),o=window.URL.createObjectURL(i),a=document.createElement("a");a.href=o,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(o)}},failureCallBkFn:e=>{n("Failed To run report ... contact your administrator"),c("ERROR")}})};return ee(()=>{o?.reportCode&&(async()=>{c("LOADING_METADATA"),await m({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:o.reportCode},successCallBkFn:e=>{_(e.data),h(L(e.data.reportParameters)),!0===o?.byPassParameterEntry||0==e.data.reportParameters.length?(C(e.data,I),c("WAITING_RESULT")):c("WAITING_PARAMETER_INPUT")},failureCallBkFn:e=>{n("Failed loading report metadata ... contact your administrator"),c("ERROR")}})})()},[o.reportCode,o.byPassParameterEntry,o.reportParametersValues,o.jasperOutPutFileType,o.resultMode]),e(t,{children:[e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[e(f,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[i(se,{icon:"Excel"===A?.reportType?"file-excel":"file-pdf",color:"Excel"===A?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),A?.reportName]}),"Excel"!=A?.reportType&&"SHOWING_RESULT"===p?e(t,{children:[!0===o?.byPassParameterEntry?i(t,{}):y.length>0?i(N,{onClick:()=>{h(L(A.reportParameters)),c("WAITING_PARAMETER_INPUT")},children:i(se,{icon:"filter"})}):i(t,{}),i(N,{children:i(se,{icon:"refresh",onClick:()=>{C(A,I)}})})]}):i(t,{})]}),i(f,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===p&&"Excel"!=A?.reportType?e(F,{defaultExpanded:!0,sx:{width:"100%"},expanded:!0,children:[i(B,{children:e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[i(se,{style:{marginLeft:5,marginRight:5},icon:"search"}),i(O,{component:"span",children:"Filters"})]})}),i(k,{children:i(f,{children:i(ar,{saveButtonSpecs:{label:R("SHOW_REPORT_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success",hidden:!0},cancelButtonSpecs:{label:R("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{E(null!=e?e:{}),C(A,e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:y})})})]}):"SHOWING_RESULT"===p||("WAITING_PARAMETER_INPUT"===p||"WAITING_RESULT"===p)&&"Excel"===A?.reportType?"Excel"===A?.reportType?i(ir,{reportData:l,setReportData:s,reloadReport:async()=>{C(A,I)},gridLoadParameters:y,gridLoadParametersValues:I,setGridLoadParametersValues:E}):i("iframe",{src:a,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===p?e(f,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[i(se,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),d]}):i(t,{})})]})},or=o=>{const r=Ee(),d=a(e=>e.AppLayout),{isUserAuthorized:n,UserInfo:l}=Zi(),{handleGetRequest:s,handlePostRequest:p}=Hi(),[c,m]=J(null),[u,T]=J([]),{t:_}=_e(),[I,E]=J(null),[O,h]=J({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:R,setWindowState:L}=ji({windowTitle:"ltr"===d.appDirection?O?.workflowDocument&&O?.referencedDocument?`${O?.workflowDocument?.documentEnName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`:"Document":O?.workflowDocument&&O?.referencedDocument?`${O?.workflowDocument?.documentArName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),C=async()=>{await s({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:o.workFlowDocumentCode,refDocumentId:o.refDocumentId},successCallBkFn:e=>{h(e.data)},failureCallBkFn:()=>{h({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},D=async()=>{await p({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:O?.workflowDocument?.id,refDocumentId:o.refDocumentId,actionId:c.id,refDocumentStatus:O?.workflowDocumentStatus?.documentStatusCode,actionComment:I},successCallBkFn:async e=>{c?.post_action_endpoint?await p({endPointURI:c.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:o.refDocumentId,actionId:c.id},successCallBkFn:()=>{C(),o?.postActionCallBk&&o.postActionCallBk()}}):C()}})};return ee(()=>{o.refDocumentId&&o.workFlowDocumentCode&&C()},[o.refDocumentId,o.workFlowDocumentCode]),ee(()=>{T(O?.nextActions&&O?.nextActions?.length>0?O.nextActions.filter(e=>{if(!O?.workflowDocumentStatus?.nextActionTakersAuthority&&!O?.nextActionTakers)return!0;if(O?.workflowDocumentStatus?.nextActionTakersAuthority&&n(O.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(O?.nextActionTakers)for(const e of O.nextActionTakers)if(l?.username===e?.username||l?.username===e?.USERNAME)return!0;return!1}):[])},[O.nextActions,O.nextActionTakers]),e(t,{children:[O?.workflowDocumentReport?.id?i(R,{children:i(tr,{reportCode:O?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:o.refDocumentId+""}})}):i(t,{}),O?.workflowDocument?e(f,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[i(N,{onClick:()=>{r(-1,{replace:!0})},children:i(se,{icon:"arrow-left"})}),i(f,{sx:{flex:1}}),i(se,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===d.appDirection?`${O?.workflowDocument?.documentEnName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`:`${O?.workflowDocument?.documentArName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`,O?.workflowDocumentStatus?"ltr"===d.appDirection?` ( ${O?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${O?.workflowDocumentStatus?.documentStatusArName} )`:"",i(f,{sx:{flex:1}}),O?.workflowDocumentReport?.id?i(A,{onClick:()=>{L(!0)},variant:"outlined",startIcon:i(se,{icon:"eye"}),children:_("VIEW_LABEL")}):i(t,{})]}):i(t,{}),e(f,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[u?.length>0?e(y,{sx:{padding:2,display:"flex",flex:1,margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[i(nt,{sx:{marginBottom:2,width:400},label:_("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===d.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:c?.id,options:u,onChangeCallBack:(e,i)=>{m(i)}}),i(tt,{sx:{width:400},rows:3,value:I,onChange:e=>{E(e.target.value)},multiline:!0,label:_("WF_COMMENT_LABEL")}),e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[i(A,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=c&&null!=c?.id?!0!==c.require_comment&&1!==c.require_comment&&"true"!==c.require_comment||null!==I&&""!==I?c?.pre_action_endpoint?await p({endPointURI:c.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:o.refDocumentId,actionId:c.id},successCallBkFn:()=>{D()}}):D():me.error("You must enter comment for the action to be processed"):me.error("You must select action to process")},children:_("WF_TAKE_ACTION_BTN_LABEL")}),o?.cancelActionCallBk?i(A,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{o?.cancelActionCallBk&&o.cancelActionCallBk()},children:_("WF_CANCEL_BTN_LABEL")}):i(t,{})]}),O?.nextActionTakers&&O.nextActionTakers.length>0?e(t,{children:[i(v,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:e(f,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[i(se,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",_("WF_WAITING_FOR_LABEL")]})}),i(f,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:O.nextActionTakers.map(o=>e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[i(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:o?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),e(f,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[i("div",{children:"ltr"===d.appDirection?o?.employee_en_name:o?.employee_ar_name}),i("div",{children:o?.email?e(t,{children:[i(se,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),o?.email]}):i(t,{})}),i("div",{children:o?.mobile_number?e(t,{children:[i(se,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),o?.mobile_number]}):i(t,{})})]})]}))})]}):i(t,{})]}):i(t,{}),O?.actionsHistory.length>0?i(Ya,{actionHistory:O.actionsHistory}):e(y,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[e(f,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[i(se,{icon:"history",style:{marginRight:10,marginLeft:10}}),_("WF_ACTION_HISTORY_LABEL")]}),i(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},ar=o=>{const{Window:a,setWindowState:r}=ji({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),{Window:d,setWindowState:n}=ji({windowTitle:"Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[l,s]=J(!0),{t:p}=_e(),c=yt(o.elements),m=[];for(const e of c)e?.hidden&&m.push(e.fieldName);const[u,T]=J(m),_={};for(const e of o.elements)"field"===e?.type&&"props"===e?.mode&&e?.props?.defaultValue&&(_[e.props.fieldName]=e.props.defaultValue);const[f,I]=J([]),E=Le.object(Rt(c)),O=Ie({resolver:Re(E),defaultValues:_}),y=O.watch(),h=Oe(),L=o?.formRouteRecordIdParamName,C=async()=>{let e=null;if(o?.recordIdToEdit?e=o.recordIdToEdit:L&&h[L]&&(e=h[L]),e){const i=await o.apiActions.loadRecordById(e);if(i){O.reset({...i}),o?.formLoadCallBk&&o?.formLoadCallBk(D,O,i);for(const e of c)"combobox"===e?.fieldType&&i[e.fieldName]&&O.setValue(e.fieldName,i[e.fieldName]+"")}}else O.reset({})},D={setFieldValue:(e,i)=>{O.setValue(e,i)},hideField:e=>{T(i=>[...i,e])},showField:e=>{T(i=>i.filter(i=>i!==e))},disableField:e=>{I(i=>[...i,e])},enableField:e=>{I(i=>i.filter(i=>i!==e))}};return ee(()=>{C()},[o?.recordIdToEdit]),ee(()=>{s(!o?.attachment||!o?.attachment?.enableAttachFn||o.attachment.enableAttachFn(y))},[y]),e(t,{children:[o?.attachment?i(a,{children:i(Ga,{attachmentCode:o.attachment.attachmentCode,refKey:y[o?.keyColumnName||"id"],enableAttachment:l})}):i(t,{}),o?.workFlowDocumentCode?i(d,{children:i(or,{workFlowDocumentCode:o.workFlowDocumentCode,refDocumentId:y[o?.keyColumnName||"id"],postActionCallBk:()=>{n(!1),C()},cancelActionCallBk:()=>{n(!1)}})}):i(t,{}),i(Ma,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:i(R,{sx:{width:"100%"},container:!0,children:o.elements.map((e,t)=>"group"===e.type?i(Ba,{...e.props,formManager:O,formValues:y,formActions:D,hiddenFields:u,disabledFields:f},t):"field"===e.type&&"props"===e.mode?i(xa,{fieldInfo:e.props,formManager:O,formValues:y,formActions:D,hiddenFields:u,disabledFields:f},t):"field"===e.type&&"node"===e.mode?i(R,{size:e?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:i(e.node,{formManager:O,formValues:y})},t):void 0)})}),e(Ma,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[y[o?.keyColumnName||"id"]&&o?.attachment?i(g,{title:"Attachments",children:i(N,{onClick:()=>{r(!0)},children:i(se,{icon:"paperclip"})})}):null,y[o?.keyColumnName||"id"]&&o?.workFlowDocumentCode?i(g,{title:"Approvals",children:i(N,{onClick:()=>{n(!0)},children:i(se,{icon:"stamp"})})}):null,o?.actions&&y[o?.keyColumnName||"id"]?o.actions.map(e=>!0===e?.formActionProps?.enabled?i(Fa,{...e,record:y}):i(t,{})):i(t,{}),i("div",{style:{flex:1}}),i(A,{variant:o?.saveButtonSpecs?.actionButtonVariant?o.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:o?.saveButtonSpecs?.icon?i(se,{icon:o.saveButtonSpecs.icon}):null,color:o?.saveButtonSpecs?.actionButtonColor?o.saveButtonSpecs.actionButtonColor:"primary",onClick:O.handleSubmit(e=>{(async e=>{if((!o?.preSaveValidation||o.preSaveValidation(e))&&e){const i=await o.apiActions.saveRecord(e);i&&(O.reset({...i}),o?.formSavedSuccessfullyCallBk&&o.formSavedSuccessfullyCallBk(i),o?.formCloseCallBk&&o.formCloseCallBk())}})(e)},e=>{me.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:p(o?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),i(A,{variant:o?.cancelButtonSpecs?.actionButtonVariant?o.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:o?.cancelButtonSpecs?.icon?i(se,{icon:o.cancelButtonSpecs.icon}):null,color:o?.cancelButtonSpecs?.actionButtonColor?o.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{o?.formCloseCallBk&&o.formCloseCallBk(),O.reset(_)},children:p(o?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},rr=()=>{const{workflowDocumentCode:e,refDocumentId:t}=Oe();return i(or,{workFlowDocumentCode:e,refDocumentId:t})},dr=e=>i(ri,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),nr=t=>e(y,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[i(f,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:i("div",{children:t.record[t.valueField]})}),i(O,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]})]}),lr=o=>e(t,{children:[i(O,{sx:{fontSize:16,fontWeight:"bold"},children:o.record[o.labelField]}),i(di,{width:200,height:200,value:o.record[o.valueField],valueMax:o.total})]}),sr=e=>i(ni,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function pr(t){return e(si,{sx:{display:"flex",alignItems:"center"},children:[i(si,{sx:{width:"100%",mr:1},children:i(li,{variant:"determinate",...t})}),i(si,{sx:{minWidth:35},children:i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(t.value)}%`})})]})}const cr=t=>e(si,{sx:{width:"100%"},children:[i(Ve,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]}),i(pr,{value:t.record[t.valueField]/t.total*100})]}),mr=e=>{const t=e.data.map((i,t)=>({id:t,value:i[e.valueField],label:i[e.labelField]+""}));return i(pi,{series:[{data:t}]})},ur=o=>{const[a,r]=J(!0),[d,n]=J([]),{handleGetRequest:l}=Hi();ee(()=>{(async()=>{r(!0),await l({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:o.dataQueryId,...o.parameterValues},successCallBkFn:e=>{r(!1),n(e.data)},failureCallBkFn:()=>{r(!1),n(null)}})})()},[o.parameterValues]);let s=0;if(1==d.length&&(s=100),"CircularProgress"===o.widgetType||"LinearProgress"===o.widgetType)for(const e of d)s+=e[o.verticalAxisField];return e(t,{children:["LineChart"===o.widgetType||"PieChart"===o.widgetType||"ColumnChart"===o.widgetType?e(f,{children:[i(se,{style:{marginRight:10,marginLeft:10},icon:o?.icon||"chart-pie"}),o?.title]}):i(t,{}),i(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:a?e(t,{children:[i(se,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),i("div",{children:"Loading"})]}):"ColumnChart"===o.widgetType?i(dr,{data:d,widgetTitle:o.title,labelField:o.verticalAxisField,valueField:o.horizontalAxisField,valueLabel:o.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===o.widgetType?i(sr,{data:d,widgetTitle:o.title,labelField:o.verticalAxisField,valueField:o.horizontalAxisField,valueLabel:o.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===o.widgetType?i(mr,{data:d,widgetTitle:o.title,labelField:o.horizontalAxisField,valueField:o.verticalAxisField,widgetType:"Line"}):e(R,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[i(R,{size:{xs:12},sx:{textAlign:"center"},children:o.title}),d.map((e,t)=>"Card"===o.widgetType?i(R,{size:{md:3,xs:12},children:i(nr,{widgetTitle:"",record:e,labelField:o.verticalAxisField,valueField:o.horizontalAxisField},t)}):"CircularProgress"===o.widgetType?i(R,{size:{md:3,xs:12},children:i(lr,{widgetTitle:"",record:e,labelField:o.horizontalAxisField,valueField:o.verticalAxisField,total:s},t)}):"LinearProgress"===o.widgetType?i(R,{size:{md:3,xs:12},children:i(cr,{widgetTitle:"",record:e,labelField:o.horizontalAxisField,valueField:o.verticalAxisField,total:s},t)}):void 0)]})})]})},Tr=o=>{const[a,r]=J({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),[d,n]=J(o?.parameters||{}),l=Ee(),{handleGetRequest:s,handlePostRequest:p}=Hi();return ee(()=>{o.dashboardCode&&(async()=>{await s({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:o.dashboardCode},successCallBkFn:e=>{r(e.data)},failureCallBkFn:()=>{r(null)}})})()},[o.dashboardCode,o.parameters]),i(t,{children:a?e(t,{children:[e(f,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[i(N,{onClick:()=>{l(-1,{replace:!0})},children:i(se,{icon:"arrow-left"})}),i(f,{sx:{flex:1}}),i(se,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),i(f,{children:a?.dashboardTitle}),i(f,{sx:{flex:1}})]}),i(R,{container:!0,spacing:1,sx:{flexGrow:1,overflowY:"auto",padding:1},children:a?.widgets.map((e,t)=>i(R,{sx:{alignItems:"center",justifyContent:"center",padding:1,display:"flex",overflow:"auto",flexDirection:"Card"!=e.widgetType?"column":void 0,height:e?.height||300},size:{md:e?.width,sm:12},children:i(ur,{...e})},t))})]}):i(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},Ar=()=>{const{dashboardCode:e}=Oe();return i(Tr,{dashboardCode:e})},_r=t=>{const{UserSession:r}=Zi(),d=a(e=>e.AppLayout),n=o(),{handlePostRequest:l}=Hi(),[s,p]=J(r.value.currentOrganization.id);return e(f,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[i(nt,{sx:{width:"100%"},displayField:"ltr"===d.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:r.value.userOrganizations,value:s,onChangeCallBack:e=>{p(e)}}),i(A,{sx:{m:1},variant:"contained",disabled:null==s||s===r.value.currentOrganization.id,onClick:async()=>{await l({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:r.value.username,orgId:s},data:{},successCallBkFn:e=>{const i={...e.data,isAuthenticated:!0};n(Ki.setAuthenticated(i)),t.successChangeCallBackFn&&t.successChangeCallBackFn()}})},children:"Change Organization"})]})},fr=pe({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,i)=>{e.isOpened=i.payload}}}),{toggleSideBarState:Ir,setSideBarState:Er}=fr.actions;var Or=fr.reducer;function Nr(e,i){const t=te(e);ee(()=>{t.current=e},[e]),ee(()=>{const e=setInterval(()=>t.current?.(),i);return()=>clearInterval(e)},[i])}const yr=W`
|
|
31
|
+
function(e,i){const t=bi(e,i);return"production"!==process.env.NODE_ENV?(...i)=>{const o=`"${e}"`;return 0===i.length?console.error([`MUI: Seems like you called \`styled(${o})()\` without a \`style\` argument.`,'You must provide a `styles` argument: `styled("div")(styleYouForgotToPass)`.'].join("\n")):i.some(e=>void 0===e)&&console.error(`MUI: the styled(${o})(...args) API requires all its args to be defined.`),t(...i)}:t}("div",{shouldForwardProp:e=>"theme"!==e&&"sx"!==e&&"as"!==e})(Ea),n=$.forwardRef(function(e,n){const l=function(e=ya){return Na(e)}(o),{className:s,component:p="div",...c}=ha(e);return i(d,{as:p,ref:n,className:Da(s,r?r(a):a),theme:t&&l[t]||l,...c})});return n}({defaultClassName:function(e,i,t="Mui"){const o={};return i.forEach(i=>{o[i]=function(e,i,t="Mui"){const o=Pa[i];return o?`${t}-${o}`:`${La.generate(e)}-${i}`}(e,i,t)}),o}("MuiBox",["root"]).root,generateClassName:La.generate});function ba(e){return/^\d+$/.test(e)}function ga(e){return"number"==typeof e&&!isNaN(e)}function Sa(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function Ua(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function va(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function wa(e,i){const t=new Date(e),o=new Date,a=Math.floor((t-o)/1e3),r="rtl"===i?"ar":"en",d=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=[{unit:"year",seconds:31536e3},{unit:"month",seconds:2592e3},{unit:"week",seconds:604800},{unit:"day",seconds:86400},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(const{unit:e,seconds:i}of n){const t=Math.floor(a/i);if(Math.abs(t)>1)return d.format(t,e)}return"ar"===r?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(Ma.propTypes={children:to.node,component:to.elementType,sx:to.oneOfType([to.arrayOf(to.oneOfType([to.func,to.object,to.bool])),to.func,to.object])});const xa=e=>{if(e?.fieldInfo){const o=e.fieldInfo,a=e?.formManager||null,r=e?.formActions||null,d=e?.formValues||null,n=e?.fieldInfo?.fieldName||null,l=e?.fieldInfo?.fieldType||null;return o&&a&&d&&n&&l?e.hiddenFields.includes(n)?i(t,{}):i(R,{size:o?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===l||"number"===l?i(tt,{...o.muiTextFieldProps,fullWidth:!0,type:l,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),label:o?.fieldLabel,value:d[n],onChange:e=>{let i=null;""!=e.target.value&&(i="number"===l&&Sa(e.target.value)?Number(e.target.value):e.target.value),a.setValue(n,i),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(i,a,r)},sx:{"& .MuiInputBase-root":{height:`${o?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...o?.formProps?.style},error:null!=a.formState.errors[n],helperText:a?.formState?.errors[n]?.message?.toString()}):"date"===o?.fieldType?i(Tt,{format:o?.dateFormat||lt,sx:o?.formProps?.style||{width:"100%"},disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),label:o?.fieldLabel,onChangeCallBack:e=>{a.setValue(n,e),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(e,a,r)},value:d[n],error:null!=a.formState.errors[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):"datetime"===o?.fieldType?i(At,{format:o?.dateFormat||st,sx:o?.formProps?.style||{width:"100%"},disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),label:o?.fieldLabel,onChangeCallBack:e=>{a.setValue(n,e),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(e,a,r)},hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),value:d[n],error:null!=a.formState.errors[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):"checkbox"===o?.fieldType?i(dt,{label:o?.fieldLabel,onChangeCallBack:e=>{a.setValue(n,e),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(e,a,r)},hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),value:d[n],checkedValue:o?.checkedValue||!0,unCheckedValue:o?.unCheckedValue||!1,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),sx:o?.formProps?.style}):"combobox"===o?.fieldType?i(nt,{sx:o?.formProps?.style||{width:"100%"},label:o?.fieldLabel,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),onChangeCallBack:(e,i)=>{let t=null;e&&(t=e),a.setValue(n,t),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(t,a,r,i)},options:o?.options||[],displayField:o?.optionDisplayField||"",valueField:o?.optionValueField||"",value:d[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):"lookup"===o?.fieldType?i(_t,{sx:o?.formProps?.style||{width:"100%"},label:o?.fieldLabel,disabled:!(!o?.disabled&&!e.disabledFields.includes(n)),hidden:!(!o?.hidden&&!e.hiddenFields.includes(n)),onChangeCallBack:(e,i)=>{let t=null;e&&(t=e),a.setValue(n,t),o?.formProps?.onValueChangeCallBack&&o?.formProps?.onValueChangeCallBack(t,a,r,i)},lookupType:o.lookupType,value:d[n],errorMessage:a?.formState?.errors[n]?.message?.toString()}):null}):i(t,{})}return i(t,{})},Fa=o=>{const a=Zi(),{ConfirmationWindow:r,setOpen:d}=Qi({body:o?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{o?.actionFn(o?.record)}});return null==o?.authority||a.isUserAuthorized(o.authority)?e(t,{children:[i(r,{}),e(A,{variant:o?.formActionProps?.actionButtonVariant,color:o?.formActionProps?.actionButtonColor,onClick:()=>{if(o?.actionFn){if(o?.preActionValidation&&!o.preActionValidation(o.record))return;!0===o?.isConfirmationRequired?d(!0):o?.actionFn(o.record)}},children:[o?.icon?i(se,{icon:o.icon,style:{marginRight:5,marginLeft:5}}):i(t,{}),i("div",{children:o?.label})]})]}):i(t,{})},Ba=o=>{const{t:a}=_e();return i(t,{children:e(R,{container:!0,sx:o?.style,alignItems:"flex-start",children:[o?.label?i(R,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:o?.icon?e(t,{children:[i(se,{icon:o.icon,style:{marginRight:5,marginLeft:5}}),i("div",{children:a(o.label)})]}):i(t,{children:a(o.label)})}):i(t,{}),o?.elements?o.elements.map(e=>"group"===e.type?i(Ba,{...e.props,formManager:o.formManager,formValues:o.formValues,formActions:o.formActions,hiddenFields:o.hiddenFields,disabledFields:o.disabledFields}):"field"===e.type&&"props"===e.mode?i(xa,{fieldInfo:e.props,formManager:o.formManager,formValues:o.formValues,formActions:o.formActions,hiddenFields:o.hiddenFields,disabledFields:o.disabledFields}):"field"===e.type&&"node"===e.mode?i(R,{size:e?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:i(e.node,{formManager:o.formManager,formValues:o.formValues,formActions:o.formActions})}):void 0):null,o?.actions?i(R,{size:{sm:12},sx:{padding:1},children:o.actions.map(e=>i(Fa,{...e,record:o.formValues}))}):i(t,{})]})})},ka=e=>{const t=a(e=>e.AppInfo.value.apiBaseUrl),[o,r]=J(null);return ee(()=>{(()=>{let i=t+"/api/v1/attachment/";e?.attachmentId?i+="download?attachmentId="+e.attachmentId:(i+=`downloadImage?attachmentCode=${e.attachmentCode}&refKey=${e.refKey}`,e?.category&&(i+=`&category=${e.category}`)),r(i)})()},[e]),e?.showAsAvatar?i(b,{sx:e.style,onError:()=>{r(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:o}):i("img",{src:o,loading:"lazy",alt:"image",onError:()=>{r(e?.onErrorImage?e.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Wa=o=>{const{handleGetRequest:a,handleDeleteRequest:r}=Hi(),{isUserAuthorized:d}=Zi();let n=!0;o?.downloadAuthorityKey&&(n=d(o.downloadAuthorityKey));const{ConfirmationWindow:l,setOpen:s}=Qi({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await r({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:o.attachmentCode,refKey:o.refKey,attachmentId:o.id},successCallBkFn:e=>{o.setAttachmentConfig(e.data)},showMask:!0})})()}});return e(t,{children:[i(l,{}),e(Pe,{sx:{width:300,border:"0.5px solid gray"},children:[i(Ye,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:o?.docType.toLocaleLowerCase().includes("image")?i(ka,{attachmentId:o.id}):i(se,{icon:"file",size:"3x"})}),e(Ge,{children:[i(Ve,{gutterBottom:!0,variant:"h6",component:"div",children:o.fileName}),i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${o?.attachmentSize||"unknown"} kb`}),i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${o?.category||"NA"}`}),i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:o.remark})]}),e(We,{children:[o?.allowDelete?i(N,{size:"small",onClick:()=>{s(!0)},children:i(g,{title:"Delete Attachment",children:i(se,{icon:"trash"})})}):i(t,{}),i("div",{style:{flex:1}}),n?i(N,{size:"small",onClick:async()=>{await a({endPointURI:"api/v1/attachment/download",parameters:{attachmentId:o.id},showMask:!0,responseType:"blob",successCallBkFn:e=>{const i=window.URL.createObjectURL(new Blob([e.data])),t=document.createElement("a");t.href=i,t.setAttribute("download",o.fileName),document.body.appendChild(t),t.click(),t.remove()}})},children:i(g,{title:"Download Attachment",children:i(se,{icon:"download"})})}):i(t,{})]})]})]})},Ga=o=>{const{handleUploadRequest:a,handleGetRequest:r}=Hi(),[d,n]=J(null),[l,s]=J([]),[p,c]=J(null),[m,u]=J(null),[T,_]=J([]),[f,I]=J(null),{isUserAuthorized:E}=Zi(),O=e=>e.split(".").pop()?.toLowerCase()||"";ee(()=>{(async()=>{await r({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:o.attachmentCode,refKey:o.refKey},successCallBkFn:e=>{I(e.data)}})})()},[o.refKey,o.attachmentCode]),ee(()=>{if(_(f?.allowedFileTypes?f.allowedFileTypes.split(","):[]),f?.attachmentCategories){const e=[];for(const i of f.attachmentCategories.split(","))e.push({value:i});s(e)}else s([])},[f]);let N=!0;f?.downloadAuthorityKey&&!E(f?.downloadAuthorityKey)&&(N=!1);let h=!0;return!1===o?.enableAttachment&&(h=!1),f?.uploadAuthorityKey&&!E(f.uploadAuthorityKey)&&(h=!1),e(y,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[i(t,h?{children:null==f?.maxAllowedNumberOfFiles||f?.maxAllowedNumberOfFiles>f.refKeyAttachments.length?e(t,{children:[e("h3",{children:[i(se,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),i("input",{type:"file",style:{margin:20},accept:f?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const i of e.target.files){const e=O(i.name);if(T.length>0&&!T.includes(e))return void me.error(e+" is not allowed")}n(e.target.files)}}),l.length>0?i(nt,{label:"Attachment Type",sx:{width:300,m:1},options:l,displayField:"value",valueField:"value",value:m,onChangeCallBack:e=>{u(e)}}):i(t,{}),i(tt,{label:"Remark",value:p,onChange:e=>c(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),i(A,{sx:{m:1},variant:"contained",onClick:async()=>{let e=f?.refKeyAttachments.length||0;if(f?.maxAllowedNumberOfFiles&&d.length+e>f.maxAllowedNumberOfFiles)me.error("Maximum number of attachments is "+f.maxAllowedNumberOfFiles);else if(!0===f?.isCategoryRequired&&l.length>0&&(null==m||void 0===m||""===m))me.error("You must selected document type to process your request");else if(d){for(const e of d)if(e.type.startsWith("image/")){const i=600,t=1024*i;if(e.size>t)return void me.error(`File ${e.name} is too large. Max allowed is ${i}KB.`)}await a({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:o.refKey,attachmentCode:o.attachmentCode,remark:p,category:m},files:d,successCallBkFn:e=>{I(e.data),n(null),u(null),c(null),me.success("Your request has been process successfully")}})}else me.error("You must add files to upload")},children:"Upload"})]}):i(t,{})}:{}),N&&f?.refKeyAttachments?.length>0?e(t,{children:[e("h3",{children:[i(se,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),i(R,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:f?.refKeyAttachments.map(e=>i(R,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:i(Wa,{...e,attachmentCode:o.attachmentCode,setAttachmentConfig:I,downloadAuthorityKey:f.downloadAuthorityKey,allowDelete:h})}))})]}):i(t,{})]})},Ya=o=>{const r=a(e=>e.AppLayout),{t:d}=_e();return e(y,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[e(f,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[i(se,{icon:"history",style:{marginRight:10,marginLeft:10}}),d("WF_ACTION_HISTORY_LABEL")]}),i(f,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:o.actionHistory.map((a,d)=>i(t,{children:e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[e(f,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[i(f,{sx:{marginBottom:.2},children:a.actionTime}),e(Ve,{children:["via ",a.actionMethod]})]}),e(f,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[i(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:a?.personId+""||"0",style:{m:1,width:70,height:70}}),d!==o.actionHistory.length-1?i(f,{sx:{marginTop:11,position:"absolute"},children:"|"}):i(t,{})]}),e(f,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[e(f,{sx:{width:"100%"},children:["ltr"===r.appDirection?`${a?.documentActionEnName}`:`${a?.documentActionArName}`,a?.actionComment?" - "+a.actionComment:""]}),i(f,{sx:{width:"100%"},children:"ltr"===r.appDirection?`${a?.employeeEnName}`:`${a?.employeeArName}`})]})]})}))})]})},Va=o=>{const{t:a}=_e(),r=Zi(),{ConfirmationWindow:d,setOpen:n}=Qi({body:a(o?.confirmationMessage||"ACTION_CONFIRMATION"),title:a("CONFIRMATION"),onConfirmationCallBk:async()=>{await(o?.actionFn(o.recordsToProcessActionOn,o.recordIdsToProcessActionOn)),o?.reloadData&&o.reloadData()}});let l=!0;if(o.authority&&(l=r.isUserAuthorized(o.authority)),l)return e(t,{children:[i(d,{}),e(A,{onClick:async()=>{if(o?.recordsToProcessActionOn&&o?.recordsToProcessActionOn.length>0){if(o?.preActionValidation)for(const e of o.recordsToProcessActionOn)if(!o.preActionValidation(e))return;!0===o?.isConfirmationRequired?n(!0):(await o.actionFn(o.recordsToProcessActionOn,o.recordIdsToProcessActionOn),o?.reloadData&&o.reloadData())}else me.error(a("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"))},variant:o?.label?"outlined":o?.formActionProps?.actionButtonVariant?o.formActionProps.actionButtonVariant:"text",size:"small",color:o?.formActionProps?.actionButtonColor||"primary",children:[o?.icon?i(se,{style:{marginRight:5,marginLeft:5},icon:o.icon}):i(t,{}),o?.label?a(o.label):i(t,{})]})]})},qa=S(qe)({display:"grid",alignItems:"center"}),Ka=S(Ke)(({theme:e,ownerState:i})=>({gridArea:"1 / 1",width:"min-content",height:"min-content",zIndex:1,opacity:i.expanded?0:1,pointerEvents:i.expanded?"none":"auto",transition:e.transitions.create(["opacity"])})),za=S(h)(({theme:e,ownerState:i})=>({gridArea:"1 / 1",overflowX:"clip",width:i.expanded?260:"var(--trigger-width)",opacity:i.expanded?1:0,transition:e.transitions.create(["width","opacity"])})),Ha=o=>{const{t:a}=_e(),r=Zi(),d=!o?.templateProps?.editAction?.authority||r.isUserAuthorized(o.templateProps.editAction.authority),n=Lt(o?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},o?.templateProps?.data||[],o?.templateProps?.keyColumnName||"id");return e(ze,{children:[d&&"none"!=o?.templateProps?.editMode?.editMode?e(A,{onClick:o?.handleCreateNewRecord,children:[i(se,{icon:"add",style:{marginRight:5,marginLeft:5}}),a("ADD_BTN_LABEL")]}):i(t,{}),o?.templateProps?.rowActions?o.templateProps.rowActions.map((e,i)=>!0===e?.gridActionProps?.multiRecord?ie(Va,{...e,key:i,reloadData:async()=>{o.templateProps.apiActions.reloadData(o?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:n.selectedRecordIds,recordsToProcessActionOn:n.selectedRecords}):null):i(t,{}),i(f,{sx:{flex:1,mx:.5},children:o?.templateProps?.tBar}),i(g,{title:"Columns",children:i(He,{render:i(Ke,{}),children:i(Qe,{fontSize:"small"})})}),i(g,{title:"Filters",children:i(Ze,{render:(e,t)=>i(Ke,{...e,color:"default",children:i(U,{badgeContent:t.filterCount,color:"primary",variant:"dot",children:i(je,{fontSize:"small"})})})})}),o?.templateProps?.gridStateKey?i(g,{title:a("RESET_GRID_STATE"),children:i(N,{onClick:o?.clearGridState,children:i(se,{icon:"eraser"})})}):i(t,{}),i(v,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),i(g,{title:a("EXPORT_EXECL_LABEL"),children:i($e,{render:i(w,{}),children:i(se,{icon:"file-excel",color:"green"})})}),e(qa,{children:[i(Xe,{render:(e,t)=>i(g,{title:a("SEARCH_BTN_LABEL"),enterDelay:0,children:i(Ka,{...e,ownerState:{expanded:t.expanded},color:"default","aria-disabled":t.expanded,children:i(se,{icon:"search"})})})}),i(Je,{render:({ref:e,...t},o)=>i(za,{...t,ownerState:{expanded:o.expanded},inputRef:e,"aria-label":"Search",placeholder:`${a("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:i(x,{position:"start",children:i(se,{icon:"search"})}),endAdornment:o.value?i(x,{position:"end",children:i(ei,{edge:"end",size:"small","aria-label":"Clear search",children:i(se,{icon:"xmark"})})}):null,...t.slotProps?.input},...t.slotProps}})})]}),i(N,{onClick:()=>{o.templateProps.apiActions.reloadData(o?.templateProps?.gridLoadParametersValues)},children:i(se,{icon:"refresh"})})]})},Qa=o=>{const{t:a}=_e(),r=Zi(),{ConfirmationWindow:d,setOpen:n}=Qi({body:a(o?.confirmationMessage||"ACTION_CONFIRMATION"),title:a("CONFIRMATION"),onConfirmationCallBk:async()=>{await(o?.actionFn(o.record)),o?.reloadData&&o.reloadData()}});let l=!0;o.authority&&(l=r.isUserAuthorized(o.authority));let s={};o?.getActionIconStyleForRecord&&(s=o.getActionIconStyleForRecord(o.record));let p=!0;o?.isActionVisibleForRecord&&(p=o?.isActionVisibleForRecord(o.record));let c=!1;if(o?.isActionDisabledForRecord&&(c=o.isActionDisabledForRecord(o.record)),l&&p)return e(t,{children:[i(d,{}),i(ii,{disabled:c,icon:i(g,{title:o?.label?a(o.label):"",children:i(se,{icon:o.icon,style:{...s,color:c?"gray":null!=s?.color?s.color:void 0}})}),showInMenu:o?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!c){if(o?.preActionValidation&&!o.preActionValidation(o.record))return;!0===o?.isConfirmationRequired?n(!0):(await o.actionFn(o.record),!0===o?.gridActionProps?.reloadGridAfterAction&&o?.reloadData&&o.reloadData())}}})]})};let Za=-1;const ja=e=>{try{const i=localStorage.getItem(e);return i?JSON.parse(i):{}}catch(e){return console.error("Failed to load grid state",e),{}}},$a=(e,i)=>{const t=ja(e);localStorage.setItem(e,JSON.stringify({...t,...i}))},Xa=["__check__","actions"],Ja=o=>{const{t:r}=_e(),d=a(e=>e.AppLayout),[n,l]=J({}),[s,p]=J(!0),{getLookupOptions:c}=(()=>{const{handleGetRequest:e}=Hi(),i=a(e=>e.AppLayout),t=async i=>{let t=[];return await e({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:i},successCallBkFn:e=>{t=e.data}}),t};return{generateLookupGridColumn:async e=>{let o=await t(e.lookupType);return{...e,options:o,displayField:"ltr"===i.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:t}})(),{Window:m,setWindowState:u}=ji({windowTitle:r(o.gridTitle)+" Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"50%",onCloseCallBack:()=>{o?.apiActions?.reloadData(o.gridLoadParametersValues)}}),{Window:T,setWindowState:A}=ji({windowTitle:r(o.gridTitle)+" Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"80%",onCloseCallBack:()=>{o?.apiActions?.reloadData(o.gridLoadParametersValues)}}),[_,I]=J([]),E=yt(o.formElements),y=[],h=X.useMemo(()=>o?.gridStateKey?ja(o.gridStateKey):{},[]);for(const e of E)!0===e?.gridProps?.hidden&&y.push(e.fieldName);let R={};if(h?.columnVisibilityModel){R=h.columnVisibilityModel;const e=Object.keys(R);for(const i of y)e.includes(i)||(R[i]=!1)}else for(const e of y)R[e]=!1;const L=a(e=>e.AppLayout.appDirection),[C,D]=X.useState(R),[P,M]=X.useState(h.columnOrder||[]),[b,S]=X.useState(h.columnWidths||{}),[U,w]=J(h.columnGroupingModel||[]);let x=h?.pinnedColumns?.left||[];x=x.filter(e=>!Xa.includes(e));let W=h?.pinnedColumns?.right||[]||[];W=W.filter(e=>!Xa.includes(e));const[G,Y]=J({left:[..."ltr"===L?Xa:[],...x],right:[..."rtl"===L?Xa:[],...W]}),V=Zi(),q=Ee(),[K,z]=J(null),[H,Q]=J(null),[Z,j]=J({}),$=async()=>{let e=ht(E,"row"===o?.editMode?.editMode||!1,r);for(let i of e)i?.lookupType&&(i.displayField="ltr"===d.appDirection?"lookupEnDisplay":"lookupArDisplay",i.options=await c(i.lookupType),i.valueField="lookupValue");I(e)},[ie,te]=J({ids:new Set,type:"include"});let oe="id";o?.keyColumnName&&(oe=o?.keyColumnName);const ae=o.setData,re=Ce.object(Rt(E));let de=!0;o?.editAction?.authority&&(de=V.isUserAuthorized(o.editAction.authority));let ne=!0;o?.deleteAction?.authority&&(ne=V.isUserAuthorized(o.deleteAction.authority));const{ConfirmationWindow:le,setOpen:pe}=Qi({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let e=!0;K&&!0===K?.isNew||(e=await o.apiActions.deleteRecordById(K[oe])),e&&(o?.deleteAction?.postActionCallBack&&await o.deleteAction.postActionCallBack(K),ae(e=>e.filter(e=>e[oe]!=K[oe])))}});let ce,ue,Te,Ae,fe,Ie;"modal"===o?.editMode?.editMode&&(ce=o?.editMode?.specs?.modalHeight||"fit-content",ue=o?.editMode?.specs?.modalWidth||"300",Te=o?.editMode?.specs?.modalMinHeight,Ae=o?.editMode?.specs?.modalMinWidth,fe=o?.editMode?.specs?.modalIcon||"window",Ie=o?.editMode?.specs?.modalTitle||"Record Form");const{Window:Oe,setWindowState:Ne}=ji({height:ce,minHeight:Te,minWidth:Ae,onCloseCallBack:()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},width:ue,windowIcon:fe,windowTitle:Ie}),ye={type:"actions",field:"actions",headerName:"",headerAlign:"center",width:(o?.rowActions?30*o.rowActions.length:0)+(o?.editAction&&o?.editAction?.isEnabled?30:0)+(o?.deleteAction&&o?.deleteAction?.isEnabled?30:0)+(o?.attachment?30:0)+(o?.workFlowDocumentCode?30:0),getActions:e=>{const t=e.row,a=[];if("none"!=o?.editMode?.editMode&&(void 0===o?.disableDefaultAction||!o.disableDefaultAction)){const e=Z[t[oe]]?.mode===ai.Edit;if("row"===o.editMode.editMode&&e)de&&(a.push(i(ii,{icon:i(se,{icon:"save"}),label:r("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const i=e[oe];j({...Z,[i]:{mode:ai.View}})})(t)}})),a.push(i(ii,{icon:i(se,{icon:"cancel"}),label:r("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const i=e[oe];i&&ga(i)&&i<0?(j({...Z,[i]:{mode:ai.View,ignoreModifications:!0}}),ae(e=>{const t=e.filter(e=>e[oe]!=i);return t})):j({...Z,[i]:{mode:ai.View,ignoreModifications:!0}})})(t)},color:"inherit"})));else{if(o?.editAction&&!0===o?.editAction?.isEnabled){let e=!0;o?.editAction?.isActionVisibleForRecord&&(e=o?.editAction?.isActionVisibleForRecord(t));let d=!1;o?.editAction?.isActionDisabledForRecord&&(d=o?.editAction?.isActionDisabledForRecord(t)),de&&e&&a.push(i(ii,{disabled:d,icon:i(g,{title:r("EDIT_BTN_LABEL"),children:i(se,{icon:"edit",style:{color:d?"gray":void 0}})}),showInMenu:o?.editAction?.gridActionProps?.showInMenu||!1,label:r("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{de&&!d&&(async e=>{if(e)if(Q(e),"form"===o.editMode.editMode)q(o.editMode.specs.formRoute+"/"+e[oe]);else if("modal"===o.editMode.editMode)Ne(!0);else if("row"===o?.editMode?.editMode){const i=e[oe];j({...Z,[i]:{mode:ai.Edit}})}})(t)}}))}if(o?.deleteAction&&!0===o?.deleteAction?.isEnabled){let e=!0;o?.deleteAction?.isActionVisibleForRecord&&(e=o?.deleteAction?.isActionVisibleForRecord(t));let d=!1;o?.deleteAction?.isActionDisabledForRecord&&(d=o?.deleteAction?.isActionDisabledForRecord(t)),ne&&e&&a.push(i(ii,{disabled:d,icon:i(g,{title:r("DELETE_BTN_LABEL"),children:i(se,{icon:"trash",style:{color:d?"gray":void 0}})}),showInMenu:o?.deleteAction?.gridActionProps?.showInMenu||!1,label:r("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(ne&&!d){if(o?.deleteAction?.preActionValidation&&!o.deleteAction.preActionValidation(t))return;z(t),pe(!0)}}}))}}}if(t[o?.keyColumnName||"id"]&&t[o?.keyColumnName||"id"]>0&&o?.attachment&&a?.push(i(ii,{icon:i(g,{title:"Attachments",children:i(se,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{l(t),p(!o?.attachment?.enableAttachFn||o.attachment.enableAttachFn(t)),u(!0)}})),t[o?.keyColumnName||"id"]&&t[o?.keyColumnName||"id"]>0&&o?.workFlowDocumentCode&&a?.push(i(ii,{icon:i(g,{title:"Approvals",children:i(se,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{l(t),A(!0)}})),t[o?.keyColumnName||"id"]&&t[o?.keyColumnName||"id"]>0&&o?.rowActions)for(const e of o.rowActions)e?.gridActionProps?.multiRecord&&!0===e?.gridActionProps?.multiRecord||a.push(i(Qa,{...e,record:t,reloadData:async()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)}}));return a}};let he=[];(void 0===o?.disableDefaultAction||!o.disableDefaultAction||o?.rowActions&&o?.rowActions.length>0)&&he.push(ye),he=[...he,..._];ee(()=>{void 0!==o?.autoLoad&&!0!==o.autoLoad||o.apiActions.reloadData(o?.gridLoadParametersValues),$()},[]),ee(()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},[V.UserInfo?.currentOrganization]),ee(()=>{$()},[L,o.formElements]);const Re=X.useMemo(()=>{const e=he.map(e=>({...e,width:b[e.field]||e.width}));if(P.length){const i=new Map(e.map(e=>[e.field,e]));return P.map(e=>i.get(e)).filter(Boolean)}return e},[P,b,he]);return e(t,{children:[i(le,{}),"modal"===o?.editMode?.editMode?i(Oe,{children:o?.editMode?.specs?.formComponent?i(o.editMode.specs.formComponent,{recordIdToEdit:H?H[oe]:void 0,formCloseCallBk:()=>{Ne(!1),o.apiActions.reloadData(o?.gridLoadParametersValues)}}):i(ar,{keyColumnName:o.keyColumnName,attachment:o.attachment,formLoadCallBk:o.formLoadCallBk,recordIdToEdit:H?H[oe]:void 0,formCloseCallBk:()=>{Ne(!1),o.apiActions.reloadData(o?.gridLoadParametersValues)},elements:o.formElements,apiActions:o.apiActions,editAuthorityKey:o?.editAction?.authority,formSavedSuccessfullyCallBk:o?.editAction?.postActionCallBack,preSaveValidation:o?.editAction?.preActionValidation,actions:o?.rowActions})}):i(t,{}),void 0!==o?.hideInfoBar||o?.hideInfoBar?i(t,{}):e(f,{sx:{display:"flex"},children:[void 0!==o?.hideBackButton||o?.hideBackButton?i(t,{}):i(N,{onClick:()=>{q(-1,{replace:!0})},children:i(se,{icon:"arrow-left"})}),e(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[o?.girdIcon?i(se,{icon:o.girdIcon,style:{marginRight:5,marginLeft:5}}):i(t,{}),i(O,{variant:"h5",children:o?.gridTitle?Ua(r(o?.gridTitle)):""})]})]}),o?.gridLoadParameters&&o?.gridLoadParameters.length>0&&o?.gridLoadParametersValues&&o?.setGridLoadParametersValues?e(F,{defaultExpanded:!0,sx:{width:"100%"},children:[i(B,{expandIcon:i(ti,{}),children:e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[i(se,{style:{marginLeft:5,marginRight:5},icon:"search"}),i(O,{component:"span",children:"Filters"})]})}),i(k,{children:i(f,{children:i(ar,{saveButtonSpecs:{label:r("SEARCH_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:r("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{null!=e?o.setGridLoadParametersValues(e):o.setGridLoadParametersValues({}),o.apiActions.reloadData(e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:o.gridLoadParameters})})})]}):i(t,{}),o?.attachment?i(m,{children:i(Ga,{attachmentCode:o.attachment.attachmentCode,refKey:n[o?.keyColumnName||"id"],enableAttachment:s})}):i(t,{}),o?.workFlowDocumentCode?i(T,{children:i(or,{workFlowDocumentCode:o.workFlowDocumentCode,refDocumentId:n[o?.keyColumnName||"id"],postActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)},cancelActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)}})}):i(t,{}),i(oi,{...o?.muiProps,slots:{toolbar:Ha},slotProps:{toolbar:{templateProps:{...o,rowSelectionModel:ie,data:o?.data},handleCreateNewRecord:()=>{if("form"===o?.editMode?.editMode)q(o.editMode.specs.formRoute);else if("modal"===o?.editMode?.editMode)Q(null),Ne(!0);else if("row"===o?.editMode?.editMode){Za-=1;const e={};e[oe]=Za,e.isNew=!0;for(const i of _)"actions"!=i?.type&&i?.field!=oe&&i?.field&&(e[i.field]=null);ae(i=>[e,...i]),j(e=>({...e,[Za]:{mode:ai.Edit}}))}},clearGridState:()=>{o?.gridStateKey&&localStorage.removeItem(o.gridStateKey),D({}),M([]),S({}),w([]),Y({left:[..."ltr"===L?Xa:[]],right:[..."rtl"===L?Xa:[]]})}}},getRowId:e=>e[oe],showToolbar:!0,rows:o?.data,columns:Re,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,i)=>{"rowFocusOut"===e.reason&&(i.defaultMuiPrevented=!0)},rowModesModel:"row"==o.editMode.editMode?Z:void 0,onRowModesModelChange:"row"==o.editMode.editMode?e=>{j(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async a=>{if("row"===o.editMode.editMode){let r=null;const d=(e=>{try{re.parse(e)}catch(e){console.log("validateRecord err",e);let i=null;return i=e instanceof Ce.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",i}})(a);if(d){const o=d.split(",");throw me.error(i("div",{style:{},children:o.map(o=>e(t,{children:[i("div",{children:o}),i(v,{})]}))})),new Error(d)}if(o?.editAction?.preActionValidation&&!o.editAction.preActionValidation(a))throw new Error("error on the configured presave validation");const n={...a};if(a[oe]&&ga(a[oe])&&Number(a[oe])<0&&(n[oe]=null),r=await o.apiActions.saveRecord(n),null==r)throw new Error("Failed to process your request, contact your administrator");return o?.editAction?.postActionCallBack&&await o.editAction.postActionCallBack(a),!0===a?.isNew&&ae(e=>{const i=e.filter(e=>e[oe]!==a[oe]);return[r,...i]}),!0===o?.editMode?.reloadAfterSave&&o?.apiActions?.reloadData&&o?.apiActions?.reloadData(o?.gridLoadParametersValues),r}},rowSelectionModel:ie,onRowSelectionModelChange:e=>{te(e)},columnVisibilityModel:C,onColumnVisibilityModelChange:e=>{D(e),o?.gridStateKey&&$a(o.gridStateKey,{columnVisibilityModel:e})},onColumnOrderChange:e=>{const{column:i,targetIndex:t}=e;M(e=>{const a=e.length?[...e]:he.map(e=>e.field),r=a.indexOf(i.field);return-1===r||(a.splice(r,1),a.splice(t,0,i.field),o?.gridStateKey&&$a(o.gridStateKey,{columnOrder:a})),a})},onColumnWidthChange:e=>{const i={...b,[e.colDef.field]:e.width};S(i),o?.gridStateKey&&$a(o.gridStateKey,{columnWidths:i})},rowGroupingModel:U,onRowGroupingModelChange:e=>{(e=>{w(e),o?.gridStateKey&&$a(o.gridStateKey,{columnGroupingModel:e})})(e)},sx:{width:"100%"}})]})},er=e=>{if(0===e.length)return[];const i=[];for(const t of Object.keys(e[0])){const e={type:"field",mode:"props",props:{fieldLabel:t,fieldName:t,fieldType:"text"}};i.push(e)}return i},ir=e=>{const[t,o]=J([]);return ee(()=>{const i=e.reportData.map((e,i)=>({...e,report_record_data_key:i}));o(i)},[e.reportData]),i(Ja,{data:t,disableDefaultAction:!0,setData:e.setReportData,formElements:er(e.reportData),gridLoadParameters:e.gridLoadParameters,gridLoadParametersValues:e.gridLoadParametersValues,setGridLoadParametersValues:e.setGridLoadParametersValues,editMode:{editMode:"none"},girdIcon:"file-excel",gridTitle:"Report",autoLoad:!0,keyColumnName:"report_record_data_key",hideInfoBar:!0,apiActions:{deleteRecordById:async()=>!0,loadRecordById:async()=>{},reloadData:async()=>{e.reloadReport()},saveRecord:async()=>{}}})},tr=o=>{const[a,r]=J(null),[d,n]=J(null),[l,s]=J([]),[p,c]=J("WAITING_REPORT_CODE"),{handleGetRequest:m,handlePostRequest:u,HandleDownloadHTTPPostPDF:T}=Hi(),[A,_]=J(null),[I,E]=J({...o?.reportParametersValues}),[y,h]=J([]),{t:R}=_e(),L=e=>{const i=[];for(const t of e){const e={type:"field",mode:"props",props:{fieldLabel:t?.parameterLabel,fieldName:t?.parameterCode,fieldType:t?.parameterType,hidden:t?.hidden,formProps:{fieldSize:{lg:4,md:6,sm:12}},required:t?.mandatory,defaultValue:I[t?.parameterCode]||t?.defaultValue}};i.push(e)}return i},C=async(e,i)=>{c("WAITING_RESULT"),"Excel"===e?.reportType?await u({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:o.reportCode,parameters:i,resultMode:o.resultMode,jasperOutPutFileType:o.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT"),s(e.data)}}):e?.reportType&&await T({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:o.reportCode,parameters:i,resultMode:o.resultMode,jasperOutPutFileType:o.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT");const i=e.headers["content-disposition"];let t="downloaded_file";if(i&&-1!==i.indexOf("filename=")){const e=i.match(/filename="?([^"]+)"?/);e&&e[1]&&(t=e[1])}if(t.includes("pdf")){const i=new Blob([e.data],{type:"application/pdf"}),t=URL.createObjectURL(i);r(t)}else{const i=new Blob([e.data],{type:e.headers["content-type"]}),o=window.URL.createObjectURL(i),a=document.createElement("a");a.href=o,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(o)}},failureCallBkFn:e=>{n("Failed To run report ... contact your administrator"),c("ERROR")}})};return ee(()=>{o?.reportCode&&(async()=>{c("LOADING_METADATA"),await m({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:o.reportCode},successCallBkFn:e=>{_(e.data),h(L(e.data.reportParameters)),!0===o?.byPassParameterEntry||0==e.data.reportParameters.length?(C(e.data,I),c("WAITING_RESULT")):c("WAITING_PARAMETER_INPUT")},failureCallBkFn:e=>{n("Failed loading report metadata ... contact your administrator"),c("ERROR")}})})()},[o.reportCode,o.byPassParameterEntry,o.reportParametersValues,o.jasperOutPutFileType,o.resultMode]),e(t,{children:[e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[e(f,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[i(se,{icon:"Excel"===A?.reportType?"file-excel":"file-pdf",color:"Excel"===A?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),A?.reportName]}),"Excel"!=A?.reportType&&"SHOWING_RESULT"===p?e(t,{children:[!0===o?.byPassParameterEntry?i(t,{}):y.length>0?i(N,{onClick:()=>{h(L(A.reportParameters)),c("WAITING_PARAMETER_INPUT")},children:i(se,{icon:"filter"})}):i(t,{}),i(N,{children:i(se,{icon:"refresh",onClick:()=>{C(A,I)}})})]}):i(t,{})]}),i(f,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===p&&"Excel"!=A?.reportType?e(F,{defaultExpanded:!0,sx:{width:"100%"},expanded:!0,children:[i(B,{children:e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[i(se,{style:{marginLeft:5,marginRight:5},icon:"search"}),i(O,{component:"span",children:"Filters"})]})}),i(k,{children:i(f,{children:i(ar,{saveButtonSpecs:{label:R("SHOW_REPORT_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success",hidden:!0},cancelButtonSpecs:{label:R("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{E(null!=e?e:{}),C(A,e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:y})})})]}):"SHOWING_RESULT"===p||("WAITING_PARAMETER_INPUT"===p||"WAITING_RESULT"===p)&&"Excel"===A?.reportType?"Excel"===A?.reportType?i(ir,{reportData:l,setReportData:s,reloadReport:async()=>{C(A,I)},gridLoadParameters:y,gridLoadParametersValues:I,setGridLoadParametersValues:E}):i("iframe",{src:a,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===p?e(f,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[i(se,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),d]}):i(t,{})})]})},or=o=>{const r=Ee(),d=a(e=>e.AppLayout),{isUserAuthorized:n,UserInfo:l}=Zi(),{handleGetRequest:s,handlePostRequest:p}=Hi(),[c,m]=J(null),[u,T]=J([]),{t:_}=_e(),[I,E]=J(null),[O,h]=J({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:R,setWindowState:L}=ji({windowTitle:"ltr"===d.appDirection?O?.workflowDocument&&O?.referencedDocument?`${O?.workflowDocument?.documentEnName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`:"Document":O?.workflowDocument&&O?.referencedDocument?`${O?.workflowDocument?.documentArName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),C=async()=>{await s({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:o.workFlowDocumentCode,refDocumentId:o.refDocumentId},successCallBkFn:e=>{h(e.data)},failureCallBkFn:()=>{h({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},D=async()=>{await p({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:O?.workflowDocument?.id,refDocumentId:o.refDocumentId,actionId:c.id,refDocumentStatus:O?.workflowDocumentStatus?.documentStatusCode,actionComment:I},successCallBkFn:async e=>{c?.post_action_endpoint?await p({endPointURI:c.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:o.refDocumentId,actionId:c.id},successCallBkFn:()=>{C(),o?.postActionCallBk&&o.postActionCallBk()}}):C()}})};return ee(()=>{o.refDocumentId&&o.workFlowDocumentCode&&C()},[o.refDocumentId,o.workFlowDocumentCode]),ee(()=>{T(O?.nextActions&&O?.nextActions?.length>0?O.nextActions.filter(e=>{if(!O?.workflowDocumentStatus?.nextActionTakersAuthority&&!O?.nextActionTakers)return!0;if(O?.workflowDocumentStatus?.nextActionTakersAuthority&&n(O.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(O?.nextActionTakers)for(const e of O.nextActionTakers)if(l?.username===e?.username||l?.username===e?.USERNAME)return!0;return!1}):[])},[O.nextActions,O.nextActionTakers]),e(t,{children:[O?.workflowDocumentReport?.id?i(R,{children:i(tr,{reportCode:O?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:o.refDocumentId+""}})}):i(t,{}),O?.workflowDocument?e(f,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[i(N,{onClick:()=>{r(-1,{replace:!0})},children:i(se,{icon:"arrow-left"})}),i(f,{sx:{flex:1}}),i(se,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===d.appDirection?`${O?.workflowDocument?.documentEnName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`:`${O?.workflowDocument?.documentArName} # ${O?.referencedDocument[O?.workflowDocument?.documentNumberField]}`,O?.workflowDocumentStatus?"ltr"===d.appDirection?` ( ${O?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${O?.workflowDocumentStatus?.documentStatusArName} )`:"",i(f,{sx:{flex:1}}),O?.workflowDocumentReport?.id?i(A,{onClick:()=>{L(!0)},variant:"outlined",startIcon:i(se,{icon:"eye"}),children:_("VIEW_LABEL")}):i(t,{})]}):i(t,{}),e(f,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[u?.length>0?e(y,{sx:{padding:2,display:"flex",flex:1,margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[i(nt,{sx:{marginBottom:2,width:400},label:_("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===d.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:c?.id,options:u,onChangeCallBack:(e,i)=>{m(i)}}),i(tt,{sx:{width:400},rows:3,value:I,onChange:e=>{E(e.target.value)},multiline:!0,label:_("WF_COMMENT_LABEL")}),e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[i(A,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=c&&null!=c?.id?!0!==c.require_comment&&1!==c.require_comment&&"true"!==c.require_comment||null!==I&&""!==I?c?.pre_action_endpoint?await p({endPointURI:c.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:o.refDocumentId,actionId:c.id},successCallBkFn:()=>{D()}}):D():me.error("You must enter comment for the action to be processed"):me.error("You must select action to process")},children:_("WF_TAKE_ACTION_BTN_LABEL")}),o?.cancelActionCallBk?i(A,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{o?.cancelActionCallBk&&o.cancelActionCallBk()},children:_("WF_CANCEL_BTN_LABEL")}):i(t,{})]}),O?.nextActionTakers&&O.nextActionTakers.length>0?e(t,{children:[i(v,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:e(f,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[i(se,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",_("WF_WAITING_FOR_LABEL")]})}),i(f,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:O.nextActionTakers.map(o=>e(f,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[i(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:o?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),e(f,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[i("div",{children:"ltr"===d.appDirection?o?.employee_en_name:o?.employee_ar_name}),i("div",{children:o?.email?e(t,{children:[i(se,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),o?.email]}):i(t,{})}),i("div",{children:o?.mobile_number?e(t,{children:[i(se,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),o?.mobile_number]}):i(t,{})})]})]}))})]}):i(t,{})]}):i(t,{}),O?.actionsHistory.length>0?i(Ya,{actionHistory:O.actionsHistory}):e(y,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[e(f,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[i(se,{icon:"history",style:{marginRight:10,marginLeft:10}}),_("WF_ACTION_HISTORY_LABEL")]}),i(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},ar=o=>{const{Window:a,setWindowState:r}=ji({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),{Window:d,setWindowState:n}=ji({windowTitle:"Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[l,s]=J(!0),{t:p}=_e(),c=yt(o.elements),m=[];for(const e of c)e?.hidden&&m.push(e.fieldName);const[u,T]=J(m),_={};for(const e of o.elements)"field"===e?.type&&"props"===e?.mode&&e?.props?.defaultValue&&(_[e.props.fieldName]=e.props.defaultValue);const[f,I]=J([]),E=Le.object(Rt(c)),O=Ie({resolver:Re(E),defaultValues:_}),y=O.watch(),h=Oe(),L=o?.formRouteRecordIdParamName,C=async()=>{let e=null;if(o?.recordIdToEdit?e=o.recordIdToEdit:L&&h[L]&&(e=h[L]),e){const i=await o.apiActions.loadRecordById(e);if(i){O.reset({...i}),o?.formLoadCallBk&&o?.formLoadCallBk(D,O,i);for(const e of c)"combobox"===e?.fieldType&&i[e.fieldName]&&O.setValue(e.fieldName,i[e.fieldName]+"")}}else O.reset({})},D={setFieldValue:(e,i)=>{O.setValue(e,i)},hideField:e=>{T(i=>[...i,e])},showField:e=>{T(i=>i.filter(i=>i!==e))},disableField:e=>{I(i=>[...i,e])},enableField:e=>{I(i=>i.filter(i=>i!==e))}};return ee(()=>{C()},[o?.recordIdToEdit]),ee(()=>{s(!o?.attachment||!o?.attachment?.enableAttachFn||o.attachment.enableAttachFn(y))},[y]),e(t,{children:[o?.attachment?i(a,{children:i(Ga,{attachmentCode:o.attachment.attachmentCode,refKey:y[o?.keyColumnName||"id"],enableAttachment:l})}):i(t,{}),o?.workFlowDocumentCode?i(d,{children:i(or,{workFlowDocumentCode:o.workFlowDocumentCode,refDocumentId:y[o?.keyColumnName||"id"],postActionCallBk:()=>{n(!1),C()},cancelActionCallBk:()=>{n(!1)}})}):i(t,{}),i(Ma,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:i(R,{sx:{width:"100%"},container:!0,children:o.elements.map((e,t)=>"group"===e.type?i(Ba,{...e.props,formManager:O,formValues:y,formActions:D,hiddenFields:u,disabledFields:f},t):"field"===e.type&&"props"===e.mode?i(xa,{fieldInfo:e.props,formManager:O,formValues:y,formActions:D,hiddenFields:u,disabledFields:f},t):"field"===e.type&&"node"===e.mode?i(R,{size:e?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:i(e.node,{formManager:O,formValues:y})},t):void 0)})}),e(Ma,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[y[o?.keyColumnName||"id"]&&o?.attachment?i(g,{title:"Attachments",children:i(N,{onClick:()=>{r(!0)},children:i(se,{icon:"paperclip"})})}):null,y[o?.keyColumnName||"id"]&&o?.workFlowDocumentCode?i(g,{title:"Approvals",children:i(N,{onClick:()=>{n(!0)},children:i(se,{icon:"stamp"})})}):null,o?.actions&&y[o?.keyColumnName||"id"]?o.actions.map(e=>!0===e?.formActionProps?.enabled?i(Fa,{...e,record:y}):i(t,{})):i(t,{}),i("div",{style:{flex:1}}),i(A,{variant:o?.saveButtonSpecs?.actionButtonVariant?o.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:o?.saveButtonSpecs?.icon?i(se,{icon:o.saveButtonSpecs.icon}):null,color:o?.saveButtonSpecs?.actionButtonColor?o.saveButtonSpecs.actionButtonColor:"primary",onClick:O.handleSubmit(e=>{(async e=>{if((!o?.preSaveValidation||o.preSaveValidation(e))&&e){const i=await o.apiActions.saveRecord(e);i&&(O.reset({...i}),o?.formSavedSuccessfullyCallBk&&o.formSavedSuccessfullyCallBk(i),o?.formCloseCallBk&&o.formCloseCallBk())}})(e)},e=>{me.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:p(o?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),i(A,{variant:o?.cancelButtonSpecs?.actionButtonVariant?o.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:o?.cancelButtonSpecs?.icon?i(se,{icon:o.cancelButtonSpecs.icon}):null,color:o?.cancelButtonSpecs?.actionButtonColor?o.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{o?.formCloseCallBk&&o.formCloseCallBk(),O.reset(_)},children:p(o?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},rr=()=>{const{workflowDocumentCode:e,refDocumentId:t}=Oe();return i(or,{workFlowDocumentCode:e,refDocumentId:t})},dr=e=>i(ri,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),nr=t=>e(y,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[i(f,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:i("div",{children:t.record[t.valueField]})}),i(O,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]})]}),lr=o=>e(t,{children:[i(O,{sx:{fontSize:16,fontWeight:"bold"},children:o.record[o.labelField]}),i(di,{width:200,height:200,value:o.record[o.valueField],valueMax:o.total})]}),sr=e=>i(ni,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function pr(t){return e(si,{sx:{display:"flex",alignItems:"center"},children:[i(si,{sx:{width:"100%",mr:1},children:i(li,{variant:"determinate",...t})}),i(si,{sx:{minWidth:35},children:i(Ve,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(t.value)}%`})})]})}const cr=t=>e(si,{sx:{width:"100%"},children:[i(Ve,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]}),i(pr,{value:t.record[t.valueField]/t.total*100})]}),mr=e=>{const t=e.data.map((i,t)=>({id:t,value:i[e.valueField],label:i[e.labelField]+""}));return i(pi,{series:[{data:t}]})},ur=o=>{const[a,r]=J(!0),[d,n]=J([]),{handleGetRequest:l}=Hi();ee(()=>{(async()=>{r(!0),await l({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:o.dataQueryId,...o.parameterValues},successCallBkFn:e=>{r(!1),n(e.data)},failureCallBkFn:()=>{r(!1),n(null)}})})()},[o.parameterValues]);let s=0;if(1==d.length&&(s=100),"CircularProgress"===o.widgetType||"LinearProgress"===o.widgetType)for(const e of d)s+=e[o.verticalAxisField];return e(t,{children:["LineChart"===o.widgetType||"PieChart"===o.widgetType||"ColumnChart"===o.widgetType?e(f,{children:[i(se,{style:{marginRight:10,marginLeft:10},icon:o?.icon||"chart-pie"}),o?.title]}):i(t,{}),i(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:a?e(t,{children:[i(se,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),i("div",{children:"Loading"})]}):"ColumnChart"===o.widgetType?i(dr,{data:d,widgetTitle:o.title,labelField:o.verticalAxisField,valueField:o.horizontalAxisField,valueLabel:o.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===o.widgetType?i(sr,{data:d,widgetTitle:o.title,labelField:o.verticalAxisField,valueField:o.horizontalAxisField,valueLabel:o.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===o.widgetType?i(mr,{data:d,widgetTitle:o.title,labelField:o.horizontalAxisField,valueField:o.verticalAxisField,widgetType:"Line"}):e(R,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[i(R,{size:{xs:12},sx:{textAlign:"center"},children:o.title}),d.map((e,t)=>"Card"===o.widgetType?i(R,{size:{md:3,xs:12},children:i(nr,{widgetTitle:"",record:e,labelField:o.verticalAxisField,valueField:o.horizontalAxisField},t)}):"CircularProgress"===o.widgetType?i(R,{size:{md:3,xs:12},children:i(lr,{widgetTitle:"",record:e,labelField:o.horizontalAxisField,valueField:o.verticalAxisField,total:s},t)}):"LinearProgress"===o.widgetType?i(R,{size:{md:3,xs:12},children:i(cr,{widgetTitle:"",record:e,labelField:o.horizontalAxisField,valueField:o.verticalAxisField,total:s},t)}):void 0)]})})]})},Tr=o=>{const[a,r]=J({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),[d,n]=J(o?.parameters||{}),l=Ee(),{handleGetRequest:s,handlePostRequest:p}=Hi();return ee(()=>{o.dashboardCode&&(async()=>{await s({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:o.dashboardCode},successCallBkFn:e=>{r(e.data)},failureCallBkFn:()=>{r(null)}})})()},[o.dashboardCode,o.parameters]),i(t,{children:a?e(t,{children:[e(f,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[i(N,{onClick:()=>{l(-1,{replace:!0})},children:i(se,{icon:"arrow-left"})}),i(f,{sx:{flex:1}}),i(se,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),i(f,{children:a?.dashboardTitle}),i(f,{sx:{flex:1}})]}),i(R,{container:!0,spacing:1,sx:{flexGrow:1,overflowY:"auto",padding:1},children:a?.widgets.map((e,t)=>i(R,{sx:{alignItems:"center",justifyContent:"center",padding:1,display:"flex",overflow:"auto",flexDirection:"Card"!=e.widgetType?"column":void 0,height:e?.height||300},size:{md:e?.width,sm:12},children:i(ur,{...e})},t))})]}):i(f,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},Ar=()=>{const{dashboardCode:e}=Oe();return i(Tr,{dashboardCode:e})},_r=t=>{const{UserSession:r}=Zi(),d=a(e=>e.AppLayout),n=o(),{handlePostRequest:l}=Hi(),[s,p]=J(r.value.currentOrganization.id);return e(f,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[i(nt,{sx:{width:"100%"},displayField:"ltr"===d.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:r.value.userOrganizations,value:s,onChangeCallBack:e=>{p(e)}}),i(A,{sx:{m:1},variant:"contained",disabled:null==s||s===r.value.currentOrganization.id,onClick:async()=>{await l({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:r.value.username,orgId:s},data:{},successCallBkFn:e=>{const i={...e.data,isAuthenticated:!0};n(Ki.setAuthenticated(i)),t.successChangeCallBackFn&&t.successChangeCallBackFn()}})},children:"Change Organization"})]})},fr=pe({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,i)=>{e.isOpened=i.payload}}}),{toggleSideBarState:Ir,setSideBarState:Er}=fr.actions;var Or=fr.reducer;function Nr(e,i){const t=te(e);ee(()=>{t.current=e},[e]),ee(()=>{const e=setInterval(()=>t.current?.(),i);return()=>clearInterval(e)},[i])}const yr=W`
|
|
32
32
|
0% { transform: scale(1); opacity: 1; }
|
|
33
33
|
25% { transform: scale(1); opacity: 0.6; }
|
|
34
34
|
50% { transform: scale(1); opacity: 1; }
|