@asaleh37/ui-base 25.9.26 → 25.9.30

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 CHANGED
@@ -278,6 +278,10 @@ type TemplateGridColDef = GridColDef & {
278
278
  options?: Array<object>;
279
279
  displayField?: string;
280
280
  valueField?: string;
281
+ commonStoreKey?: string;
282
+ dataQueryId?: number;
283
+ storeUrl?: string;
284
+ storeLoadParam?: any;
281
285
  };
282
286
  type TemplateGridAttachmentProps = {
283
287
  attachmentCode: string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var e=require("@mui/x-data-grid-premium"),t=require("react/jsx-runtime"),i=require("react-redux"),o=require("@fortawesome/fontawesome-svg-core"),r=require("@fortawesome/free-brands-svg-icons"),n=require("@fortawesome/free-regular-svg-icons"),a=require("@fortawesome/free-solid-svg-icons");require("react-toastify/dist/ReactToastify.css");var s=require("@mui/material"),l=require("@emotion/react"),d=require("react"),c=require("@mui/material/styles"),u=require("@mui/material/CssBaseline"),p=require("@mui/material/AppBar"),h=require("@mui/material/Toolbar"),m=require("@fortawesome/react-fontawesome"),f=require("@reduxjs/toolkit"),g=require("react-toastify"),T=require("axios"),A=require("i18next"),y=require("react-i18next"),I=require("react-hook-form"),_=require("react-router-dom"),E=require("@hookform/resolvers/zod"),O=require("zod"),C=require("@mui/material/List"),N=require("@mui/material/Card"),R=require("@mui/material/CardHeader"),b=require("@mui/material/ListItemText"),w=require("@mui/material/ListItemIcon"),S=require("@mui/material/Checkbox"),P=require("@mui/material/Button"),v=require("@mui/material/Divider"),L=require("@mui/x-date-pickers"),M=require("@mui/x-date-pickers/AdapterMoment"),x=require("moment"),D=require("@mui/material/CardActions"),k=require("@mui/material/CardContent"),U=require("@mui/material/CardMedia"),F=require("@mui/material/Typography"),B=require("@mui/lab"),q=require("@mui/x-tree-view/models"),j=require("@mui/x-charts"),G=require("@mui/material/LinearProgress"),W=require("@mui/material/Box"),H=require("@mui/x-charts/PieChart"),Y=require("@mui/material/IconButton"),K=require("@mui/material/Drawer"),V=require("@react-spring/web"),z=require("@mui/material/Collapse"),Q=require("@mui/x-tree-view/RichTreeView"),$=require("@mui/x-tree-view/TreeItem"),Z=require("@mui/x-tree-view/useTreeItem2"),J=require("@mui/x-tree-view/TreeItem2"),X=require("@mui/x-tree-view/TreeItem2Icon"),ee=require("@mui/x-tree-view/TreeItem2Provider"),te=require("@mui/x-tree-view/TreeItem2DragAndDropOverlay"),ie=require("stylis-plugin-rtl"),oe=require("stylis"),re=require("@emotion/cache"),ne=require("@emotion/styled"),ae=require("@mui/material/colors"),se=require("@mui/material/SwipeableDrawer"),le=require("@mui/x-license");function de(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var o=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,o.get?o:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var ce=de(d),ue=de(O);!function(e,t){void 0===t&&(t={});var i=t.insertAt;if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===i&&o.firstChild?o.insertBefore(r,o.firstChild):o.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.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 pe=(e=768)=>{const[t,i]=d.useState(window.innerWidth<e);return d.useEffect(()=>{const t=()=>i(window.innerWidth<e);return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[e]),t},he=350,me={themeMode:localStorage.getItem("themeMode")||"light",appDirection:"ar"==localStorage.getItem("language")?"rtl":"ltr"},fe=f.createSlice({name:"AppLayout",initialState:me,reducers:{setThemeMode:(e,t)=>{e.themeMode=t.payload},setAppDirection:(e,t)=>{e.appDirection=t.payload}}}),ge=fe.actions;var Te=fe.reducer;const Ae=f.createSlice({name:"loadingMask",initialState:{value:{isOpened:!1,message:null}},reducers:{showLoadingMask:(e,t)=>{e.value.isOpened=!0,e.value.message=t.payload},hideLoadingMask:e=>{e.value.isOpened=!1,e.value.message=null}}}),{showLoadingMask:ye,hideLoadingMask:Ie}=Ae.actions;var _e=Ae.reducer;const Ee=()=>{const e=i.useDispatch();return{show:t=>{e(ye(t))},hide:()=>{e(Ie())}}},Oe=f.createSlice({name:"UserSession",initialState:{value:{isAuthenticated:null,authorities:[]}},reducers:{setAuthenticated:(e,t)=>{e.value=t.payload},setUnAuthenticated:e=>{e.value={isAuthenticated:!1,authorities:[]}}}}),Ce=Oe.actions;var Ne=Oe.reducer;const Re=()=>{const e=Ee(),t=i.useDispatch(),o=i.useSelector(e=>e.AppInfo.value.apiBaseUrl),r=T.create({baseURL:o,timeout:6e5,withCredentials:!0});r.defaults.withCredentials=!0,r.interceptors.request.use(e=>{const t=localStorage.getItem("TOKEN");return t&&(e.headers.Authorization=`Bearer ${t}`),e},e=>Promise.reject(e)),r.interceptors.response.use(e=>e,e=>{if(e&&(e.response&&(e.response.status&&401===e.response.status)))t(Ce.setUnAuthenticated()),localStorage.removeItem("TOKEN"),g.toast.error("your session is now expired, you need to login again",{autoClose:!1});else if(e&&(e.response&&(e.response.status&&402===e.response.status)))t(Ce.setUnAuthenticated()),g.toast.error("Your license is missing or has expired,Please reach out to your vendor for assistance.");else if(e&&(e.response&&(e.response.status&&403===e.response.status)))g.toast.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=>{g.toast.error(e)})}else g.toast.error(e.response.data);else g.toast.error("failed to communicate with the server ... try again later");return"ERROR"});return{handleGetRequest:async t=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);const i=await r.get(t.endPointURI,{params:{...t.parameters},withCredentials:!0,headers:t.headers,responseType:t?.responseType});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},handlePostRequest:async t=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);let i=await r.post(t.endPointURI,t.data,{params:t.parameters,responseType:t?.responseType,headers:t?.headers});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},handleDeleteRequest:async t=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);let i=await r.delete(t.endPointURI,{params:{...t.parameters},responseType:t?.responseType,headers:t?.headers});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},HandleDownloadHTTPPostPDF:async(t={endPointURI:"",parameters:{},data:{}})=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);const i=await r.post(t.endPointURI,t.data,{responseType:"blob"});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},handleUploadRequest:async t=>{if(null===t.files||0===t.files.length)return g.toast.error("You must add files to upload"),"ERROR";const i=new FormData;for(const e of t.files)i.append("files",e);void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);let o=await r.post(t.endPointURI,i,{params:t?.parameters,headers:{"Content-Type":"multipart/form-data"}});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==o?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(o),o):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(o),"ERROR")}}},be=e=>{const[i,o]=d.useState(!1),{t:r}=y.useTranslation();return{ConfirmationWindow:()=>t.jsxs(s.Dialog,{open:i,children:[t.jsx(s.DialogTitle,{children:e.title}),t.jsx(s.DialogContent,{children:t.jsx(s.DialogContentText,{children:e.body})}),t.jsxs(s.DialogActions,{children:[t.jsx(s.Button,{variant:"contained",sx:{marginRight:2,marginLeft:2},color:"primary",onClick:()=>{o(!1)},children:r("NO_LABEL")}),t.jsx(s.Button,{variant:"contained",sx:{marginRight:2,marginLeft:2},color:"error",onClick:()=>{e.onConfirmationCallBk(),o(!1)},autoFocus:!0,children:r("YES_LABEL")})]})]}),open:i,setOpen:o}},we=()=>{const e=i.useSelector(e=>e.UserSession),t=e.value;return{UserSession:e,isUserAuthorized:t=>{if(e?.value?.authorities)for(let i of e.value.authorities){if("DEVELOPMENT_ADMIN"===t&&("DEVELOPMENT_ADMIN"===i?.authority||"ORGANIZATION_ADMIN"===i?.authority))return!0;if("ORGANIZATION_ADMIN"===t&&"ORGANIZATION_ADMIN"===i?.authority)return!0;if("DEVELOPMENT_ADMIN"!==t&&"ORGANIZATION_ADMIN"!==t&&("ORGANIZATION_ADMIN"===i?.authority||"DEVELOPMENT_ADMIN"===i?.authority||"SYSTEM_ADMIN"===i?.authority||i?.authority===t))return!0}return!1},isCurrentOrganizationAuthorizedToModule:e=>{if(t?.currentOrganization?.systemApplicationModules)for(const i of t.currentOrganization.systemApplicationModules)if(i.toLowerCase()==e.toLowerCase())return!0;return!1},UserInfo:t}},Se=e=>{const[o,r]=d.useState(!1),n=i.useSelector(e=>e.AppLayout.appDirection);return{windowState:o,setWindowState:r,Window:i=>t.jsx(s.Modal,{open:o,sx:{zIndex:e=>e.zIndex.drawer},onClose:()=>{!o&&e?.onCloseCallBack&&e.onCloseCallBack()},children:t.jsxs(s.Box,{dir:n,sx:{position:"absolute",top:"50%",left:"50%",maxHeight:"90%",transform:"translate(-50%, -50%)",height:e?.height||"80%",width:e?.width||"90%",minWidth:e.minWidth||400,minHeight:e.minHeight||200,overflow:"hidden",bgcolor:"modalBackground.main",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:[t.jsx(s.AppBar,{position:"static",children:t.jsxs(s.Toolbar,{variant:"dense",children:[t.jsx(m.FontAwesomeIcon,{icon:e?.windowIcon||"window-maximize",style:{marginRight:5}}),t.jsx(s.Typography,{variant:"h6",color:"inherit",component:"div",children:e?.windowTitle||"window"}),t.jsx("div",{style:{flexGrow:1}}),t.jsx(s.IconButton,{onClick:()=>{r(!1),null!=e.onCloseCallBack&&null!=e.onCloseCallBack&&e.onCloseCallBack()},color:"secondary",children:t.jsx(m.FontAwesomeIcon,{icon:"xmark-square"})})]})}),t.jsx(s.Paper,{sx:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",height:"100%",padding:1,overflow:"hidden"},children:i?.children})]})})}},Pe=f.createSlice({name:"commonStores",initialState:{stores:{},storeKeys:[]},reducers:{setStoresMetaData:(e,t)=>{e.stores=t.payload,e.storeKeys=Object.keys(t.payload)},setStoreData:(e,t)=>{e.stores[t.payload.storeKey].data=t.payload.data}}}),{setStoreData:ve,setStoresMetaData:Le}=Pe.actions;var Me=Pe.reducer;const xe=e=>{const t=i.useSelector(e=>e.commonStores.stores),o=i.useDispatch(),r=we(),{handleGetRequest:n,handlePostRequest:a,handleDeleteRequest:s}=Re();return{reloadData:async i=>{if(e?.commonStoreKey){const i=Object.keys(t);for(const a of i)if(a===e.commonStoreKey&&(void 0===t[a]?.authority||null===t[a]?.authority||r.isUserAuthorized(t[a]?.authority))&&""!=t[a]?.url){await n({endPointURI:t[a].url,showMask:!1,successCallBkFn:t=>{o(ve({storeKey:a,data:t.data})),e.setData(t.data)},failureCallBkFn:()=>{o(ve({storeKey:a,data:[]})),e.setData([])}});break}}else e?.findAll&&await n({endPointURI:e.findAll,showMask:!0,parameters:i||{},successCallBkFn:t=>{e.setData(t.data)}})},loadRecordById:async t=>{let i=null;if(e?.findById){const o={};o[e?.findByIdParamName||"id"]=t,await n({endPointURI:e.findById,showMask:!0,parameters:o,successCallBkFn:e=>{i=e.data}})}return i},saveRecord:async t=>{let i=null;return e?.save&&await a({endPointURI:e.save,data:t,showMask:!0,successCallBkFn:e=>{i=e.data}}),i},deleteRecordById:async t=>{let i=!0;if(e?.deleteById){const o={};o[e?.deleteByIdParamName||"id"]=t,await s({endPointURI:e.deleteById,showMask:!0,parameters:o,successCallBkFn:()=>{i=!0},failureCallBkFn:()=>{i=!1}})}return i}}},De=e=>{const{t:i}=y.useTranslation();return t.jsx(s.TextField,{...e,hidden:!0,slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:t.jsx(t.Fragment,{children:e?.label?i(e.label):""}),error:e?.error,helperText:e?.helperText?i(e.helperText):void 0})};function ke(e,t){return e.filter(e=>-1===t.indexOf(e))}function Ue(e,t){return e.filter(e=>-1!==t.indexOf(e))}const Fe=({valueField:e="id",displayField:i="name",options:o=[],selectedOptions:r=[],setSelection:n})=>{const[a,l]=ce.useState([]),[d,c]=ce.useState([]),[u,p]=ce.useState([]),[h,m]=ce.useState(""),[f,g]=ce.useState(""),T=Ue(a,d),A=Ue(a,u);ce.useEffect(()=>{o&&c([...o])},[o]),ce.useEffect(()=>{r&&p([...r])},[r]);const y=e=>()=>{const t=a.indexOf(e),i=[...a];-1===t?i.push(e):i.splice(t,1),l(i)},I=e=>Ue(a,e).length,_=e=>()=>{var t,i;I(e)===e.length?l(ke(a,e)):l((t=a,i=e,[...t,...ke(i,t)]))},E=(o,r,n)=>{const l=r.filter(e=>{if(e[i]){const t=e[i];if("left"===n&&t.toLocaleLowerCase().includes(h.toLocaleLowerCase()))return!0;if("right"===n&&t.toLocaleLowerCase().includes(f.toLocaleLowerCase()))return!0}return!1});return t.jsxs(N,{sx:{height:"100%"},children:[t.jsx(R,{sx:{px:2,py:1},avatar:t.jsx(S,{onClick:_(l),checked:I(l)===l.length&&0!==l.length,indeterminate:I(l)!==l.length&&0!==I(l),disabled:0===l.length,inputProps:{"aria-label":"all items selected"}}),title:o,subheader:`${I(r)} / ${r.length} Selected`}),t.jsx(s.Box,{sx:{width:"100%",padding:1},children:t.jsx(De,{fullWidth:!0,label:"search",value:"left"===n?h:f,onChange:e=>{"left"===n?m(e.target.value):g(e.target.value)}})}),t.jsx(v,{}),t.jsx(C,{sx:{width:"100%",height:"80%",bgcolor:"secondary",overflow:"auto"},dense:!0,component:"div",role:"list",children:l.map(o=>(o[e],t.jsxs(s.ListItemButton,{role:"listitem",onClick:y(o),sx:{cursor:"pointer"},children:[t.jsx(w,{children:t.jsx(S,{checked:-1!==a.indexOf(o),tabIndex:-1,disableRipple:!0})}),t.jsx(b,{id:o[e],primary:o[i]})]},o[e])))})]})};return t.jsxs(s.Grid2,{container:!0,spacing:2,sx:{flexGrow:1,overflow:"auto",margin:1,display:"flex",width:"100%"},justifyContent:"center",alignItems:"center",children:[t.jsx(s.Grid2,{sx:{height:"100%",flex:1},children:E("Available Items",d,"left")}),t.jsx(s.Grid2,{children:t.jsxs(s.Grid2,{container:!0,direction:"column",alignItems:"center",children:[t.jsx(P,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{p(e=>{let t=u.concat(T);return n(t),t}),c(ke(d,T)),l(ke(a,T))},disabled:0===T.length,"aria-label":"move selected right",children:">"}),t.jsx(P,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{c(d.concat(A)),p(e=>{let t=ke(u,A);return n(t),t}),l(ke(a,A))},disabled:0===A.length,"aria-label":"move selected left",children:"<"})]})}),t.jsx(s.Grid2,{sx:{height:"100%",flex:1},children:E("Currently Selected",u,"right")})]})},Be=e=>{const{t:i}=y.useTranslation();return t.jsx(s.FormControlLabel,{sx:e.sx,hidden:e?.hidden||!1,disabled:e.disabled||!1,required:e.required||!1,control:t.jsx(s.Checkbox,{checked:e?.checkedValue==e.value||"true"===e.value||"1"==e.value,onChange:t=>{void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&(t.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:i(e.label)})},qe=e=>{const o=i.useSelector(e=>e.AppLayout),[r,n]=d.useState(e?.options||[]),a=i.useSelector(t=>t?.commonStores?.stores[e?.commonStoreKey]?.data),{handleGetRequest:l}=Re();d.useEffect(()=>{e?.commonStoreKey?n(a):(async()=>{e?.storeUrl?await l({endPointURI:e.storeUrl,showMask:!1,parameters:e?.storeLoadParam,successCallBkFn:e=>{n(e.data)},failureCallBkFn:()=>{n([])}}):e?.dataQueryId?await l({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e?.storeLoadParam},successCallBkFn:e=>{n(e.data)},failureCallBkFn:()=>{n([])}}):e?.options&&n(e.options)})()},[e?.storeUrl,e?.storeLoadParam,e?.dataQueryId,e?.commonStoreKey,e?.options,a]);const{t:c}=y.useTranslation();return t.jsx(s.Autocomplete,{sx:e.sx,value:(t=>{for(let i of r)if(i[e.valueField]==t)return i;return null})(e.value),options:r,disabled:e.disabled,hidden:e?.hidden||!1,onChange:(t,i)=>{if(void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack)if(null!=i){let t=i[e.valueField];e.onChangeCallBack(t,i)}else e.onChangeCallBack(null,null)},clearOnBlur:!0,handleHomeEndKeys:!0,getOptionLabel:t=>null!=t?c(t[e.displayField]):"",renderOption:(i,o)=>t.jsx("li",{...i,children:null!=o?c(o[e.displayField]):""}),slots:{popper:e=>t.jsx(s.Popper,{...e,style:{...e.style,direction:o.appDirection}})},renderInput:i=>t.jsx(s.TextField,{...i,required:e.required||!1,variant:"outlined",slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:c(e.label),error:null!=e.errorMessage&&void 0!==e.errorMessage,helperText:null!=e.errorMessage&&void 0!==e.errorMessage?c(e.errorMessage):""})})},je="YYYY-MM-DD",Ge="YYYY-MM-DD HH:mm:ss",We="#37505C",He="#ff6d00",Ye="#ea690e",Ke="#74776B",Ve=e=>{const{t:i}=y.useTranslation();return e?.hidden?t.jsx(t.Fragment,{}):t.jsx(L.LocalizationProvider,{dateAdapter:M.AdapterMoment,children:t.jsx(L.DatePicker,{value:null!=e.value&&void 0!==e.value&&""!==e.value?x(e.value,e?.format||je):null,sx:{...e.sx,display:e?.hidden?"none":void 0},label:i(e.label),format:e?.format||je,disabled:e.disabled,onChange:t=>{let i=null;null!=t&&t.isValid()&&(i=t.format(e?.format||je)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(i)},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?t.jsx(t.Fragment,{children:i(e.errorMessage)}):t.jsx(t.Fragment,{})}}})})},ze=e=>{const{t:i}=y.useTranslation();return e?.hidden?t.jsx(t.Fragment,{}):t.jsx(L.LocalizationProvider,{dateAdapter:M.AdapterMoment,children:t.jsx(L.DateTimePicker,{value:null!=e.value&&void 0!==e.value&&""!==e.value?x(e.value,e?.format||Ge):null,label:i(e.label),sx:{...e.sx,display:e?.hidden?"none":void 0},format:e?.format||Ge,disabled:e.disabled,onChange:t=>{let i=null;null!=t&&t.isValid()&&(i=t.format(e?.format||Ge)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(i)},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?t.jsx(t.Fragment,{children:i(e.errorMessage)}):t.jsx(t.Fragment,{})}}})})},Qe=e=>{const o=i.useSelector(e=>e.AppLayout),r=we(),[n,a]=d.useState([]),{handleGetRequest:s}=Re();return d.useEffect(()=>{e.lookupType&&(async()=>{await s({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:e.lookupType},successCallBkFn:e=>{a(e.data)},failureCallBkFn:()=>{a([])}})})()},[e.lookupType,r.UserSession]),t.jsx(qe,{...e,options:n,displayField:"ltr"===o.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"})},$e=e=>({...e,type:"string",renderEditCell:e=>t.jsx(Ve,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:t=>{e.api.setEditCellValue({id:e.id,field:e.field,value:t})}}),valueParser:(e,t,i)=>{let o=null;return null!==e&&(o=x(e).format(je)),o},valueFormatter:(e,t,i)=>t[i.field]}),Ze=e=>({...e,type:"string",renderEditCell:e=>t.jsx(ze,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:t=>{e.api.setEditCellValue({id:e.id,field:e.field,value:t})}}),valueParser:(e,t,i)=>{let o=null;return null!==e&&(o=x(e).format(Ge)),o},valueFormatter:(e,t,i)=>t[i.field]}),Je=e=>({...e,type:"custom",valueGetter:e=>e||e,renderCell:e=>{let i=null;try{i=e.colDef.options.find(t=>t[e.colDef.valueField]==e.value)}catch(e){}return t.jsx("div",{children:null!=i?i[e.colDef.displayField]:e.value})},renderEditCell:e=>t.jsx(qe,{...e,sx:{width:"100%"},options:e?.colDef?.options,commonStoreKey:e?.colDef?.commonStoreKey,dataQueryId:e?.colDef?.dataQueryId,storeUrl:e?.colDef?.storeUrl,storeLoadParam:e?.colDef?.storeLoadParam,valueField:e?.colDef?.valueField,displayField:e?.colDef?.displayField,onChangeCallBack:(t,i)=>{null===t&&e.api.setEditCellValue({id:e.id,field:e.field,value:null}),e.api.setEditCellValue({id:e.id,field:e.field,value:t})}})}),Xe=e=>({...e,type:"custom",valueGetter:e=>null==e||null==e?null:e,renderCell:i=>{const o=i?.value;return o===e.checkedValue||"true"===o||1===o||!0===o?t.jsx(m.FontAwesomeIcon,{icon:"check",color:"green"}):t.jsx(m.FontAwesomeIcon,{icon:"xmark",color:"red"})},renderEditCell:i=>t.jsx(Be,{...i,checkedValue:e?.checkedValue||!0,unCheckedValue:e?.unCheckedValue||!1,onChangeCallBack:e=>{i.api.setEditCellValue({id:i.id,field:i.field,value:e})}})}),et=e=>{const t=[];if("field"===e.type&&"props"===e.mode&&e?.props)t.push(e.props);else if("group"===e.type&&e?.props&&e?.props?.elements)for(const i of e.props.elements)t.push(...et(i));return t},tt=e=>{const t=[];for(const i of e)t.push(...et(i));return t},it=(e,t,i)=>{const o=[];for(const r of e)if("text"===r?.fieldType||"number"===r?.fieldType){const e={...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,type:"number"==r?.fieldType?"number":"string",field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200};o.push(e)}else if("date"===r?.fieldType){const e=$e({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else if("datetime"===r?.fieldType){const e=Ze({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else if("checkbox"===r?.fieldType){const e=Xe({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,checkedValue:r?.checkedValue,unCheckedValue:r?.unCheckedValue,width:150});o.push(e)}else if("combobox"===r?.fieldType){const e=Je({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,valueField:r?.optionValueField||"value",displayField:r?.optionDisplayField||"display",options:r?.options||[],flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else if("lookup"===r?.fieldType){const e=Je({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,lookupType:r?.lookupType,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,valueField:r?.optionValueField||"value",displayField:r?.optionDisplayField||"display",options:r?.options||[],flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else{const e={field:r.fieldName,...r?.gridProps?.muiProps};o.push(e)}return o},ot=e=>{const t={};for(const i of e)if(i?.fieldName){const e=i.fieldName;"number"===i.fieldType?t[e]=!0===i?.required?ue.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):ue.number().optional().nullable():"checkbox"===i.fieldType?t[e]=!0===i?.required?ue.boolean({required_error:"This field is required"}):ue.boolean().optional().nullable():"combobox"===i.fieldType?i?.comboboxValueDataType?"number"===i?.comboboxValueDataType?t[e]=!0===i?.required?ue.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):ue.number().optional().nullable():"string"===i?.comboboxValueDataType&&(t[e]=!0===i?.required?ue.string({message:"This field is required"}).min(1,"This field is required"):ue.string().optional().nullable()):t[e]=!0===i?.required?ue.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):ue.number().optional().nullable():t[e]=!0===i?.required?ue.string({message:"This field is required"}).min(1,"This field is required"):ue.string().optional().nullable()}return t},rt=(e,t,i)=>{const o=[],r=[];if("exclude"===e.type&&0===e.ids.size)for(const e of t)o.push(e),r.push(e[i]);else if(e?.ids)for(const n of e.ids){const e=t.find(e=>e[i]===n);o.push(e),r.push(n)}return{selectedRecords:o,selectedRecordIds:r}};function nt(e,...t){const i=new URL(`https://mui.com/production-error/?code=${e}`);return t.forEach(e=>i.searchParams.append("args[]",e)),`Minified MUI error #${e}; visit ${i} for the full message.`}function at(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var st,lt={exports:{}},dt={exports:{}},ct={};var ut,pt,ht,mt,ft,gt,Tt,At,yt,It,_t,Et,Ot,Ct,Nt,Rt={};
1
+ "use strict";var e=require("@mui/x-data-grid-premium"),t=require("react/jsx-runtime"),i=require("react-redux"),o=require("@fortawesome/fontawesome-svg-core"),r=require("@fortawesome/free-brands-svg-icons"),n=require("@fortawesome/free-regular-svg-icons"),a=require("@fortawesome/free-solid-svg-icons");require("react-toastify/dist/ReactToastify.css");var s=require("@mui/material"),l=require("@emotion/react"),d=require("react"),c=require("@mui/material/styles"),u=require("@mui/material/CssBaseline"),p=require("@mui/material/AppBar"),h=require("@mui/material/Toolbar"),m=require("@fortawesome/react-fontawesome"),f=require("@reduxjs/toolkit"),g=require("react-toastify"),T=require("axios"),A=require("i18next"),y=require("react-i18next"),I=require("react-hook-form"),_=require("react-router-dom"),E=require("@hookform/resolvers/zod"),O=require("zod"),C=require("@mui/material/List"),N=require("@mui/material/Card"),R=require("@mui/material/CardHeader"),b=require("@mui/material/ListItemText"),w=require("@mui/material/ListItemIcon"),S=require("@mui/material/Checkbox"),P=require("@mui/material/Button"),v=require("@mui/material/Divider"),L=require("@mui/x-date-pickers"),M=require("@mui/x-date-pickers/AdapterMoment"),x=require("moment"),D=require("@mui/material/CardActions"),k=require("@mui/material/CardContent"),U=require("@mui/material/CardMedia"),F=require("@mui/material/Typography"),B=require("@mui/lab"),q=require("@mui/x-tree-view/models"),j=require("@mui/x-charts"),G=require("@mui/material/LinearProgress"),W=require("@mui/material/Box"),H=require("@mui/x-charts/PieChart"),Y=require("@mui/material/IconButton"),K=require("@mui/material/Drawer"),V=require("@react-spring/web"),z=require("@mui/material/Collapse"),Q=require("@mui/x-tree-view/RichTreeView"),$=require("@mui/x-tree-view/TreeItem"),Z=require("@mui/x-tree-view/useTreeItem2"),J=require("@mui/x-tree-view/TreeItem2"),X=require("@mui/x-tree-view/TreeItem2Icon"),ee=require("@mui/x-tree-view/TreeItem2Provider"),te=require("@mui/x-tree-view/TreeItem2DragAndDropOverlay"),ie=require("stylis-plugin-rtl"),oe=require("stylis"),re=require("@emotion/cache"),ne=require("@emotion/styled"),ae=require("@mui/material/colors"),se=require("@mui/material/SwipeableDrawer"),le=require("@mui/x-license");function de(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var o=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,o.get?o:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var ce=de(d),ue=de(O);!function(e,t){void 0===t&&(t={});var i=t.insertAt;if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===i&&o.firstChild?o.insertBefore(r,o.firstChild):o.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.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 pe=(e=768)=>{const[t,i]=d.useState(window.innerWidth<e);return d.useEffect(()=>{const t=()=>i(window.innerWidth<e);return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[e]),t},he=350,me={themeMode:localStorage.getItem("themeMode")||"light",appDirection:"ar"==localStorage.getItem("language")?"rtl":"ltr"},fe=f.createSlice({name:"AppLayout",initialState:me,reducers:{setThemeMode:(e,t)=>{e.themeMode=t.payload},setAppDirection:(e,t)=>{e.appDirection=t.payload}}}),ge=fe.actions;var Te=fe.reducer;const Ae=f.createSlice({name:"loadingMask",initialState:{value:{isOpened:!1,message:null}},reducers:{showLoadingMask:(e,t)=>{e.value.isOpened=!0,e.value.message=t.payload},hideLoadingMask:e=>{e.value.isOpened=!1,e.value.message=null}}}),{showLoadingMask:ye,hideLoadingMask:Ie}=Ae.actions;var _e=Ae.reducer;const Ee=()=>{const e=i.useDispatch();return{show:t=>{e(ye(t))},hide:()=>{e(Ie())}}},Oe=f.createSlice({name:"UserSession",initialState:{value:{isAuthenticated:null,authorities:[]}},reducers:{setAuthenticated:(e,t)=>{e.value=t.payload},setUnAuthenticated:e=>{e.value={isAuthenticated:!1,authorities:[]}}}}),Ce=Oe.actions;var Ne=Oe.reducer;const Re=()=>{const e=Ee(),t=i.useDispatch(),o=i.useSelector(e=>e.AppInfo.value.apiBaseUrl),r=T.create({baseURL:o,timeout:6e5,withCredentials:!0});r.defaults.withCredentials=!0,r.interceptors.request.use(e=>{const t=localStorage.getItem("TOKEN");return t&&(e.headers.Authorization=`Bearer ${t}`),e},e=>Promise.reject(e)),r.interceptors.response.use(e=>e,e=>{if(e&&(e.response&&(e.response.status&&401===e.response.status)))t(Ce.setUnAuthenticated()),localStorage.removeItem("TOKEN"),g.toast.error("your session is now expired, you need to login again",{autoClose:!1});else if(e&&(e.response&&(e.response.status&&402===e.response.status)))t(Ce.setUnAuthenticated()),g.toast.error("Your license is missing or has expired,Please reach out to your vendor for assistance.");else if(e&&(e.response&&(e.response.status&&403===e.response.status)))g.toast.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=>{g.toast.error(e)})}else g.toast.error(e.response.data);else g.toast.error("failed to communicate with the server ... try again later");return"ERROR"});return{handleGetRequest:async t=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);const i=await r.get(t.endPointURI,{params:{...t.parameters},withCredentials:!0,headers:t.headers,responseType:t?.responseType});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},handlePostRequest:async t=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);let i=await r.post(t.endPointURI,t.data,{params:t.parameters,responseType:t?.responseType,headers:t?.headers});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},handleDeleteRequest:async t=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);let i=await r.delete(t.endPointURI,{params:{...t.parameters},responseType:t?.responseType,headers:t?.headers});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},HandleDownloadHTTPPostPDF:async(t={endPointURI:"",parameters:{},data:{}})=>{void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);const i=await r.post(t.endPointURI,t.data,{responseType:"blob"});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==i?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(i),i):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(i),"ERROR")},handleUploadRequest:async t=>{if(null===t.files||0===t.files.length)return g.toast.error("You must add files to upload"),"ERROR";const i=new FormData;for(const e of t.files)i.append("files",e);void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.show(t.loadingMessage);let o=await r.post(t.endPointURI,i,{params:t?.parameters,headers:{"Content-Type":"multipart/form-data"}});return void 0!==t.showMask&&null!=t.showMask&&!0===t.showMask&&e.hide(),"ERROR"!==o?(void 0!==t.successCallBkFn&&null!=t.successCallBkFn&&t.successCallBkFn(o),o):(void 0!==t.failureCallBkFn&&null!=t.failureCallBkFn&&t.failureCallBkFn(o),"ERROR")}}},be=e=>{const[i,o]=d.useState(!1),{t:r}=y.useTranslation();return{ConfirmationWindow:()=>t.jsxs(s.Dialog,{open:i,children:[t.jsx(s.DialogTitle,{children:e.title}),t.jsx(s.DialogContent,{children:t.jsx(s.DialogContentText,{children:e.body})}),t.jsxs(s.DialogActions,{children:[t.jsx(s.Button,{variant:"contained",sx:{marginRight:2,marginLeft:2},color:"primary",onClick:()=>{o(!1)},children:r("NO_LABEL")}),t.jsx(s.Button,{variant:"contained",sx:{marginRight:2,marginLeft:2},color:"error",onClick:()=>{e.onConfirmationCallBk(),o(!1)},autoFocus:!0,children:r("YES_LABEL")})]})]}),open:i,setOpen:o}},we=()=>{const e=i.useSelector(e=>e.UserSession),t=e.value;return{UserSession:e,isUserAuthorized:t=>{if(e?.value?.authorities)for(let i of e.value.authorities){if("DEVELOPMENT_ADMIN"===t&&("DEVELOPMENT_ADMIN"===i?.authority||"ORGANIZATION_ADMIN"===i?.authority))return!0;if("ORGANIZATION_ADMIN"===t&&"ORGANIZATION_ADMIN"===i?.authority)return!0;if("DEVELOPMENT_ADMIN"!==t&&"ORGANIZATION_ADMIN"!==t&&("ORGANIZATION_ADMIN"===i?.authority||"DEVELOPMENT_ADMIN"===i?.authority||"SYSTEM_ADMIN"===i?.authority||i?.authority===t))return!0}return!1},isCurrentOrganizationAuthorizedToModule:e=>{if(t?.currentOrganization?.systemApplicationModules)for(const i of t.currentOrganization.systemApplicationModules)if(i.toLowerCase()==e.toLowerCase())return!0;return!1},UserInfo:t}},Se=e=>{const[o,r]=d.useState(!1),n=i.useSelector(e=>e.AppLayout.appDirection);return{windowState:o,setWindowState:r,Window:i=>t.jsx(s.Modal,{open:o,sx:{zIndex:e=>e.zIndex.drawer},onClose:()=>{!o&&e?.onCloseCallBack&&e.onCloseCallBack()},children:t.jsxs(s.Box,{dir:n,sx:{position:"absolute",top:"50%",left:"50%",maxHeight:"90%",transform:"translate(-50%, -50%)",height:e?.height||"80%",width:e?.width||"90%",minWidth:e.minWidth||400,minHeight:e.minHeight||200,overflow:"hidden",bgcolor:"modalBackground.main",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:[t.jsx(s.AppBar,{position:"static",children:t.jsxs(s.Toolbar,{variant:"dense",children:[t.jsx(m.FontAwesomeIcon,{icon:e?.windowIcon||"window-maximize",style:{marginRight:5}}),t.jsx(s.Typography,{variant:"h6",color:"inherit",component:"div",children:e?.windowTitle||"window"}),t.jsx("div",{style:{flexGrow:1}}),t.jsx(s.IconButton,{onClick:()=>{r(!1),null!=e.onCloseCallBack&&null!=e.onCloseCallBack&&e.onCloseCallBack()},color:"secondary",children:t.jsx(m.FontAwesomeIcon,{icon:"xmark-square"})})]})}),t.jsx(s.Paper,{sx:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%",height:"100%",padding:1,overflow:"hidden"},children:i?.children})]})})}},Pe=f.createSlice({name:"commonStores",initialState:{stores:{},storeKeys:[]},reducers:{setStoresMetaData:(e,t)=>{e.stores=t.payload,e.storeKeys=Object.keys(t.payload)},setStoreData:(e,t)=>{e.stores[t.payload.storeKey].data=t.payload.data}}}),{setStoreData:ve,setStoresMetaData:Le}=Pe.actions;var Me=Pe.reducer;const xe=e=>{const t=i.useSelector(e=>e.commonStores.stores),o=i.useDispatch(),r=we(),{handleGetRequest:n,handlePostRequest:a,handleDeleteRequest:s}=Re();return{reloadData:async i=>{if(e?.commonStoreKey){const i=Object.keys(t);for(const a of i)if(a===e.commonStoreKey&&(void 0===t[a]?.authority||null===t[a]?.authority||r.isUserAuthorized(t[a]?.authority))&&""!=t[a]?.url){await n({endPointURI:t[a].url,showMask:!1,successCallBkFn:t=>{o(ve({storeKey:a,data:t.data})),e.setData(t.data)},failureCallBkFn:()=>{o(ve({storeKey:a,data:[]})),e.setData([])}});break}}else e?.findAll&&await n({endPointURI:e.findAll,showMask:!0,parameters:i||{},successCallBkFn:t=>{e.setData(t.data)}})},loadRecordById:async t=>{let i=null;if(e?.findById){const o={};o[e?.findByIdParamName||"id"]=t,await n({endPointURI:e.findById,showMask:!0,parameters:o,successCallBkFn:e=>{i=e.data}})}return i},saveRecord:async t=>{let i=null;return e?.save&&await a({endPointURI:e.save,data:t,showMask:!0,successCallBkFn:e=>{i=e.data}}),i},deleteRecordById:async t=>{let i=!0;if(e?.deleteById){const o={};o[e?.deleteByIdParamName||"id"]=t,await s({endPointURI:e.deleteById,showMask:!0,parameters:o,successCallBkFn:()=>{i=!0},failureCallBkFn:()=>{i=!1}})}return i}}},De=e=>{const{t:i}=y.useTranslation();return t.jsx(s.TextField,{...e,hidden:!0,slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:t.jsx(t.Fragment,{children:e?.label?i(e.label):""}),error:e?.error,helperText:e?.helperText?i(e.helperText):void 0})};function ke(e,t){return e.filter(e=>-1===t.indexOf(e))}function Ue(e,t){return e.filter(e=>-1!==t.indexOf(e))}const Fe=({valueField:e="id",displayField:i="name",options:o=[],selectedOptions:r=[],setSelection:n})=>{const[a,l]=ce.useState([]),[d,c]=ce.useState([]),[u,p]=ce.useState([]),[h,m]=ce.useState(""),[f,g]=ce.useState(""),T=Ue(a,d),A=Ue(a,u);ce.useEffect(()=>{o&&c([...o])},[o]),ce.useEffect(()=>{r&&p([...r])},[r]);const y=e=>()=>{const t=a.indexOf(e),i=[...a];-1===t?i.push(e):i.splice(t,1),l(i)},I=e=>Ue(a,e).length,_=e=>()=>{var t,i;I(e)===e.length?l(ke(a,e)):l((t=a,i=e,[...t,...ke(i,t)]))},E=(o,r,n)=>{const l=r.filter(e=>{if(e[i]){const t=e[i];if("left"===n&&t.toLocaleLowerCase().includes(h.toLocaleLowerCase()))return!0;if("right"===n&&t.toLocaleLowerCase().includes(f.toLocaleLowerCase()))return!0}return!1});return t.jsxs(N,{sx:{height:"100%"},children:[t.jsx(R,{sx:{px:2,py:1},avatar:t.jsx(S,{onClick:_(l),checked:I(l)===l.length&&0!==l.length,indeterminate:I(l)!==l.length&&0!==I(l),disabled:0===l.length,inputProps:{"aria-label":"all items selected"}}),title:o,subheader:`${I(r)} / ${r.length} Selected`}),t.jsx(s.Box,{sx:{width:"100%",padding:1},children:t.jsx(De,{fullWidth:!0,label:"search",value:"left"===n?h:f,onChange:e=>{"left"===n?m(e.target.value):g(e.target.value)}})}),t.jsx(v,{}),t.jsx(C,{sx:{width:"100%",height:"80%",bgcolor:"secondary",overflow:"auto"},dense:!0,component:"div",role:"list",children:l.map(o=>(o[e],t.jsxs(s.ListItemButton,{role:"listitem",onClick:y(o),sx:{cursor:"pointer"},children:[t.jsx(w,{children:t.jsx(S,{checked:-1!==a.indexOf(o),tabIndex:-1,disableRipple:!0})}),t.jsx(b,{id:o[e],primary:o[i]})]},o[e])))})]})};return t.jsxs(s.Grid2,{container:!0,spacing:2,sx:{flexGrow:1,overflow:"auto",margin:1,display:"flex",width:"100%"},justifyContent:"center",alignItems:"center",children:[t.jsx(s.Grid2,{sx:{height:"100%",flex:1},children:E("Available Items",d,"left")}),t.jsx(s.Grid2,{children:t.jsxs(s.Grid2,{container:!0,direction:"column",alignItems:"center",children:[t.jsx(P,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{p(e=>{let t=u.concat(T);return n(t),t}),c(ke(d,T)),l(ke(a,T))},disabled:0===T.length,"aria-label":"move selected right",children:">"}),t.jsx(P,{sx:{my:.5},variant:"outlined",size:"small",onClick:()=>{c(d.concat(A)),p(e=>{let t=ke(u,A);return n(t),t}),l(ke(a,A))},disabled:0===A.length,"aria-label":"move selected left",children:"<"})]})}),t.jsx(s.Grid2,{sx:{height:"100%",flex:1},children:E("Currently Selected",u,"right")})]})},Be=e=>{const{t:i}=y.useTranslation();return t.jsx(s.FormControlLabel,{sx:e.sx,hidden:e?.hidden||!1,disabled:e.disabled||!1,required:e.required||!1,control:t.jsx(s.Checkbox,{checked:e?.checkedValue==e.value||"true"===e.value||"1"==e.value,onChange:t=>{void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&(t.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:i(e.label)})},qe=e=>{const o=i.useSelector(e=>e.AppLayout),[r,n]=d.useState(e?.options||[]),a=i.useSelector(t=>t?.commonStores?.stores[e?.commonStoreKey]?.data),{handleGetRequest:l}=Re();d.useEffect(()=>{e?.commonStoreKey?n(a):(async()=>{e?.storeUrl?await l({endPointURI:e.storeUrl,showMask:!1,parameters:e?.storeLoadParam,successCallBkFn:e=>{n(e.data)},failureCallBkFn:()=>{n([])}}):e?.dataQueryId?await l({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e?.storeLoadParam},successCallBkFn:e=>{n(e.data)},failureCallBkFn:()=>{n([])}}):e?.options&&n(e.options)})()},[e?.storeUrl,e?.storeLoadParam,e?.dataQueryId,e?.commonStoreKey,e?.options,a]);const{t:c}=y.useTranslation();return t.jsx(s.Autocomplete,{sx:e.sx,value:(t=>{for(let i of r)if(i[e.valueField]==t)return i;return null})(e.value),options:r,disabled:e.disabled,hidden:e?.hidden||!1,onChange:(t,i)=>{if(void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack)if(null!=i){let t=i[e.valueField];e.onChangeCallBack(t,i)}else e.onChangeCallBack(null,null)},clearOnBlur:!0,handleHomeEndKeys:!0,getOptionLabel:t=>null!=t?c(t[e.displayField]):"",renderOption:(i,o)=>t.jsx("li",{...i,children:null!=o?c(o[e.displayField]):""}),slots:{popper:e=>t.jsx(s.Popper,{...e,style:{...e.style,direction:o.appDirection}})},renderInput:i=>t.jsx(s.TextField,{...i,required:e.required||!1,variant:"outlined",slotProps:{inputLabel:{shrink:!0,sx:{fontWeight:"bold"}}},label:c(e.label),error:null!=e.errorMessage&&void 0!==e.errorMessage,helperText:null!=e.errorMessage&&void 0!==e.errorMessage?c(e.errorMessage):""})})},je="YYYY-MM-DD",Ge="YYYY-MM-DD HH:mm:ss",We="#37505C",He="#ff6d00",Ye="#ea690e",Ke="#74776B",Ve=e=>{const{t:i}=y.useTranslation();return e?.hidden?t.jsx(t.Fragment,{}):t.jsx(L.LocalizationProvider,{dateAdapter:M.AdapterMoment,children:t.jsx(L.DatePicker,{value:null!=e.value&&void 0!==e.value&&""!==e.value?x(e.value,e?.format||je):null,sx:{...e.sx,display:e?.hidden?"none":void 0},label:i(e.label),format:e?.format||je,disabled:e.disabled,onChange:t=>{let i=null;null!=t&&t.isValid()&&(i=t.format(e?.format||je)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(i)},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?t.jsx(t.Fragment,{children:i(e.errorMessage)}):t.jsx(t.Fragment,{})}}})})},ze=e=>{const{t:i}=y.useTranslation();return e?.hidden?t.jsx(t.Fragment,{}):t.jsx(L.LocalizationProvider,{dateAdapter:M.AdapterMoment,children:t.jsx(L.DateTimePicker,{value:null!=e.value&&void 0!==e.value&&""!==e.value?x(e.value,e?.format||Ge):null,label:i(e.label),sx:{...e.sx,display:e?.hidden?"none":void 0},format:e?.format||Ge,disabled:e.disabled,onChange:t=>{let i=null;null!=t&&t.isValid()&&(i=t.format(e?.format||Ge)),void 0!==e.onChangeCallBack&&null!=e.onChangeCallBack&&e.onChangeCallBack(i)},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?t.jsx(t.Fragment,{children:i(e.errorMessage)}):t.jsx(t.Fragment,{})}}})})},Qe=e=>{const o=i.useSelector(e=>e.AppLayout),r=we(),[n,a]=d.useState([]),{handleGetRequest:s}=Re();return d.useEffect(()=>{e.lookupType&&(async()=>{await s({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:e.lookupType},successCallBkFn:e=>{a(e.data)},failureCallBkFn:()=>{a([])}})})()},[e.lookupType,r.UserSession]),t.jsx(qe,{...e,options:n,displayField:"ltr"===o.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"})},$e=e=>({...e,type:"string",renderEditCell:e=>t.jsx(Ve,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:t=>{e.api.setEditCellValue({id:e.id,field:e.field,value:t})}}),valueParser:(e,t,i)=>{let o=null;return null!==e&&(o=x(e).format(je)),o},valueFormatter:(e,t,i)=>t[i.field]}),Ze=e=>({...e,type:"string",renderEditCell:e=>t.jsx(ze,{sx:{width:"100%"},label:"",value:e.value,onChangeCallBack:t=>{e.api.setEditCellValue({id:e.id,field:e.field,value:t})}}),valueParser:(e,t,i)=>{let o=null;return null!==e&&(o=x(e).format(Ge)),o},valueFormatter:(e,t,i)=>t[i.field]}),Je=e=>({...e,type:"custom",valueGetter:e=>e||e,renderEditCell:e=>t.jsx(qe,{...e,sx:{width:"100%"},options:e?.colDef?.options,commonStoreKey:e?.colDef?.commonStoreKey,dataQueryId:e?.colDef?.dataQueryId,storeUrl:e?.colDef?.storeUrl,storeLoadParam:e?.colDef?.storeLoadParam,valueField:e?.colDef?.valueField,displayField:e?.colDef?.displayField,onChangeCallBack:(t,i)=>{null===t&&e.api.setEditCellValue({id:e.id,field:e.field,value:null}),e.api.setEditCellValue({id:e.id,field:e.field,value:t})}})}),Xe=e=>({...e,type:"custom",valueGetter:e=>null==e||null==e?null:e,renderCell:i=>{const o=i?.value;return o===e.checkedValue||"true"===o||1===o||!0===o?t.jsx(m.FontAwesomeIcon,{icon:"check",color:"green"}):t.jsx(m.FontAwesomeIcon,{icon:"xmark",color:"red"})},renderEditCell:i=>t.jsx(Be,{...i,checkedValue:e?.checkedValue||!0,unCheckedValue:e?.unCheckedValue||!1,onChangeCallBack:e=>{i.api.setEditCellValue({id:i.id,field:i.field,value:e})}})}),et=e=>{const t=[];if("field"===e.type&&"props"===e.mode&&e?.props)t.push(e.props);else if("group"===e.type&&e?.props&&e?.props?.elements)for(const i of e.props.elements)t.push(...et(i));return t},tt=e=>{const t=[];for(const i of e)t.push(...et(i));return t},it=(e,t,i)=>{const o=[];for(const r of e)if("text"===r?.fieldType||"number"===r?.fieldType){const e={...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,type:"number"==r?.fieldType?"number":"string",field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200};o.push(e)}else if("date"===r?.fieldType){const e=$e({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else if("datetime"===r?.fieldType){const e=Ze({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else if("checkbox"===r?.fieldType){const e=Xe({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,checkedValue:r?.checkedValue,unCheckedValue:r?.unCheckedValue,width:150});o.push(e)}else if("combobox"===r?.fieldType){const e=Je({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",hidden:r?.hidden,searchable:r?.gridProps?.searchable,valueField:r?.optionValueField||"value",displayField:r?.optionDisplayField||"display",options:r?.options||[],flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else if("lookup"===r?.fieldType){const e=Je({...r?.gridProps?.muiProps,editable:null!=r?.gridProps?.muiProps?.editable?r?.gridProps?.muiProps?.editable:t,lookupType:r?.lookupType,field:r?.fieldName,headerName:i(r?.fieldLabel||r?.fieldName),headerAlign:"center",align:"center",commonStoreKey:r?.commonStoreKey,dataQueryId:r?.dataQueryId,storeUrl:r?.storeUrl,storeLoadParam:r?.storeLoadParam,hidden:r?.hidden,searchable:r?.gridProps?.searchable,valueField:r?.optionValueField||"value",displayField:r?.optionDisplayField||"display",options:r?.options||[],flex:r?.gridProps?.muiProps?.flex||1,minWidth:r?.gridProps?.muiProps?.width?r?.gridProps?.muiProps?.width:200});o.push(e)}else{const e={field:r.fieldName,...r?.gridProps?.muiProps};o.push(e)}return o},ot=e=>{const t={};for(const i of e)if(i?.fieldName){const e=i.fieldName;"number"===i.fieldType?t[e]=!0===i?.required?ue.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):ue.number().optional().nullable():"checkbox"===i.fieldType?t[e]=!0===i?.required?ue.boolean({required_error:"This field is required"}):ue.boolean().optional().nullable():"combobox"===i.fieldType?i?.comboboxValueDataType?"number"===i?.comboboxValueDataType?t[e]=!0===i?.required?ue.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):ue.number().optional().nullable():"string"===i?.comboboxValueDataType&&(t[e]=!0===i?.required?ue.string({message:"This field is required"}).min(1,"This field is required"):ue.string().optional().nullable()):t[e]=!0===i?.required?ue.number({required_error:"This field is required",invalid_type_error:"This field must be a number"}):ue.number().optional().nullable():t[e]=!0===i?.required?ue.string({message:"This field is required"}).min(1,"This field is required"):ue.string().optional().nullable()}return t},rt=(e,t,i)=>{const o=[],r=[];if("exclude"===e.type&&0===e.ids.size)for(const e of t)o.push(e),r.push(e[i]);else if(e?.ids)for(const n of e.ids){const e=t.find(e=>e[i]===n);o.push(e),r.push(n)}return{selectedRecords:o,selectedRecordIds:r}};function nt(e,...t){const i=new URL(`https://mui.com/production-error/?code=${e}`);return t.forEach(e=>i.searchParams.append("args[]",e)),`Minified MUI error #${e}; visit ${i} for the full message.`}function at(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var st,lt={exports:{}},dt={exports:{}},ct={};var ut,pt,ht,mt,ft,gt,Tt,At,yt,It,_t,Et,Ot,Ct,Nt,Rt={};
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,t){const i=ne(e,t);return"production"!==process.env.NODE_ENV?(...t)=>{const o=`"${e}"`;return 0===t.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")):t.some(e=>void 0===e)&&console.error(`MUI: the styled(${o})(...args) API requires all its args to be defined.`),i(...t)}:i}("div",{shouldForwardProp:e=>"theme"!==e&&"sx"!==e&&"as"!==e})(Zi),s=ce.forwardRef(function(e,s){const l=function(e=eo){return Xi(e)}(o),{className:d,component:c="div",...u}=to(e);return t.jsx(a,{as:c,ref:s,className:no(d,n?n(r):r),theme:i&&l[i]||l,...u})});return s}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=ao[t];return o?`${i}-${o}`:`${oo.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:oo.generate});function lo(e){return"number"==typeof e&&!isNaN(e)}function co(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function uo(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function po(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function ho(e,t){const i=new Date(e),o=new Date,r=Math.floor((i-o)/1e3),n="rtl"===t?"ar":"en",a=new Intl.RelativeTimeFormat(n,{numeric:"auto"}),s=[{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:t}of s){const i=Math.floor(r/t);if(Math.abs(i)>1)return a.format(i,e)}return"ar"===n?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(so.propTypes={children:Dt.node,component:Dt.elementType,sx:Dt.oneOfType([Dt.arrayOf(Dt.oneOfType([Dt.func,Dt.object,Dt.bool])),Dt.func,Dt.object])});const mo=e=>{if(e?.fieldInfo){const i=e.fieldInfo,o=e?.formManager||null,r=e?.formActions||null,n=e?.formValues||null,a=e?.fieldInfo?.fieldName||null,l=e?.fieldInfo?.fieldType||null;if(!(i&&o&&n&&a&&l))return t.jsx(t.Fragment,{});const d=()=>e?.fieldInfo?.formProps?.fieldLabelFn?e.fieldInfo.formProps.fieldLabelFn(n):e?.fieldInfo?.fieldLabel?e?.fieldInfo?.fieldLabel:void 0;return e.hiddenFields.includes(a)?t.jsx(t.Fragment,{}):t.jsx(s.Grid2,{size:i?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===l||"number"===l?t.jsx(De,{...i.muiTextFieldProps,fullWidth:!0,type:l,disabled:e.disabledFields.includes(a),label:d(),value:n[a],onChange:t=>{let i=null;""!=t.target.value&&(i="number"===l&&co(t.target.value)?Number(t.target.value):t.target.value),o.setValue(a,i),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,i)},sx:{"& .MuiInputBase-root":{height:`${i?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...i?.formProps?.style,display:e.hiddenFields.includes(a)?"none":void 0},error:null!=o.formState.errors[a],helperText:o?.formState?.errors[a]?.message?.toString()}):"date"===i?.fieldType?t.jsx(Ve,{format:i?.dateFormat||je,sx:i?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),label:d(),onChangeCallBack:t=>{o.setValue(a,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t)},value:n[a],error:null!=o.formState.errors[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):"datetime"===i?.fieldType?t.jsx(ze,{format:i?.dateFormat||Ge,sx:i?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),label:d(),onChangeCallBack:t=>{o.setValue(a,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t)},value:n[a],error:null!=o.formState.errors[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):"checkbox"===i?.fieldType?t.jsx(Be,{label:d(),onChangeCallBack:t=>{o.setValue(a,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t)},value:n[a],checkedValue:i?.checkedValue||!0,unCheckedValue:i?.unCheckedValue||!1,disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),sx:i?.formProps?.style}):"combobox"===i?.fieldType?t.jsx(qe,{sx:i?.formProps?.style||{width:"100%"},label:d(),commonStoreKey:i?.commonStoreKey,dataQueryId:i?.dataQueryId,storeUrl:i?.storeUrl,storeLoadParam:i?.storeLoadParam,disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),onChangeCallBack:(t,i)=>{let s=null;t&&(s=t),o.setValue(a,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t,i)},options:i?.options||[],displayField:i?.optionDisplayField||"",valueField:i?.optionValueField||"",value:n[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):"lookup"===i?.fieldType?t.jsx(Qe,{sx:i?.formProps?.style||{width:"100%"},label:d(),disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),onChangeCallBack:(t,i)=>{let s=null;t&&(s=t),o.setValue(a,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t,i)},lookupType:i.lookupType,value:n[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):null})}return t.jsx(t.Fragment,{})},fo=e=>{const i=we(),{ConfirmationWindow:o,setOpen:r}=be({body:e?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{e?.actionFn(e?.record)}});return null==e?.authority||i.isUserAuthorized(e.authority)?t.jsxs(t.Fragment,{children:[t.jsx(o,{}),t.jsxs(s.Button,{variant:e?.formActionProps?.actionButtonVariant,color:e?.formActionProps?.actionButtonColor,onClick:()=>{if(e?.actionFn){if(e?.preActionValidation&&!e.preActionValidation(e.record))return;!0===e?.isConfirmationRequired?r(!0):e?.actionFn(e.record)}},children:[e?.icon?t.jsx(m.FontAwesomeIcon,{icon:e.icon,style:{marginRight:5,marginLeft:5}}):t.jsx(t.Fragment,{}),t.jsx("div",{children:e?.label})]})]}):t.jsx(t.Fragment,{})},go=e=>{const{t:i}=y.useTranslation();return t.jsx(t.Fragment,{children:t.jsxs(s.Grid2,{container:!0,sx:e?.style,alignItems:"flex-start",children:[e?.label?t.jsx(s.Grid2,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:e?.icon?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:e.icon,style:{marginRight:5,marginLeft:5}}),t.jsx("div",{children:i(e.label)})]}):t.jsx(t.Fragment,{children:i(e.label)})}):t.jsx(t.Fragment,{}),e?.elements?e.elements.map(i=>"group"===i.type?t.jsx(go,{...i.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===i.type&&"props"===i.mode?t.jsx(mo,{fieldInfo:i.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===i.type&&"node"===i.mode?t.jsx(s.Grid2,{size:i?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:t.jsx(i.node,{formManager:e.formManager,formValues:e.formValues,formActions:e.formActions})}):void 0):null,e?.actions?t.jsx(s.Grid2,{size:{sm:12},sx:{padding:1},children:e.actions.map(i=>t.jsx(fo,{...i,record:e.formValues}))}):t.jsx(t.Fragment,{})]})})},To=e=>{const o=i.useSelector(e=>e.AppInfo.value.apiBaseUrl),[r,n]=d.useState(null);return d.useEffect(()=>{e?.refKey&&(()=>{let t=o+"/api/v1/attachment/";e?.attachmentId?t+="download?attachmentId="+e.attachmentId:(t+=`downloadImage?attachmentCode=${e.attachmentCode}&refKey=${e.refKey}`,e?.category&&(t+=`&category=${e.category}`)),n(t)})()},[e.refKey]),e?.showAsAvatar?t.jsx(s.Avatar,{sx:e.style,onError:()=>{n(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:r}):t.jsx("img",{src:r,loading:"lazy",alt:"image",onError:()=>{n(e?.onErrorImage?e.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Ao=e=>{const{handleGetRequest:i,handleDeleteRequest:o}=Re(),{isUserAuthorized:r}=we();let n=!0;e?.downloadAuthorityKey&&(n=r(e.downloadAuthorityKey));const{ConfirmationWindow:a,setOpen:l}=be({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await o({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey,attachmentId:e.id},successCallBkFn:t=>{e.setAttachmentConfig(t.data)},showMask:!0})})()}});return t.jsxs(t.Fragment,{children:[t.jsx(a,{}),t.jsxs(N,{sx:{width:300,border:"0.5px solid gray"},children:[t.jsx(U,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:e?.docType.toLocaleLowerCase().includes("image")?t.jsx(To,{attachmentId:e.id}):t.jsx(m.FontAwesomeIcon,{icon:"file",size:"3x"})}),t.jsxs(k,{children:[t.jsx(F,{gutterBottom:!0,variant:"h6",component:"div",children:e.fileName}),t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${e?.attachmentSize||"unknown"} kb`}),t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${e?.category||"NA"}`}),t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:e.remark})]}),t.jsxs(D,{children:[e?.allowDelete?t.jsx(s.IconButton,{size:"small",onClick:()=>{l(!0)},children:t.jsx(s.Tooltip,{title:"Delete Attachment",children:t.jsx(m.FontAwesomeIcon,{icon:"trash"})})}):t.jsx(t.Fragment,{}),t.jsx("div",{style:{flex:1}}),n?t.jsx(s.IconButton,{size:"small",onClick:async()=>{await i({endPointURI:"api/v1/attachment/download",parameters:{attachmentId:e.id},showMask:!0,responseType:"blob",successCallBkFn:t=>{const i=window.URL.createObjectURL(new Blob([t.data])),o=document.createElement("a");o.href=i,o.setAttribute("download",e.fileName),document.body.appendChild(o),o.click(),o.remove()}})},children:t.jsx(s.Tooltip,{title:"Download Attachment",children:t.jsx(m.FontAwesomeIcon,{icon:"download"})})}):t.jsx(t.Fragment,{})]})]})]})},yo=e=>{const{handleUploadRequest:i,handleGetRequest:o}=Re(),[r,n]=d.useState(null),[a,l]=d.useState([]),[c,u]=d.useState(null),[p,h]=d.useState(null),[f,T]=d.useState([]),[A,y]=d.useState(null),{isUserAuthorized:I}=we(),_=e=>e.split(".").pop()?.toLowerCase()||"";d.useEffect(()=>{(async()=>{await o({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey},successCallBkFn:e=>{y(e.data)}})})()},[e.refKey,e.attachmentCode]),d.useEffect(()=>{if(T(A?.allowedFileTypes?A.allowedFileTypes.split(","):[]),A?.attachmentCategories){const e=[];for(const t of A.attachmentCategories.split(","))e.push({value:t});l(e)}else l([])},[A]);let E=!0;A?.downloadAuthorityKey&&!I(A?.downloadAuthorityKey)&&(E=!1);let O=!0;return!1===e?.enableAttachment&&(O=!1),A?.uploadAuthorityKey&&!I(A.uploadAuthorityKey)&&(O=!1),t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",width:"100%",minHeight:400,alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[O?t.jsx(t.Fragment,{children:null==A?.maxAllowedNumberOfFiles||A?.maxAllowedNumberOfFiles>A.refKeyAttachments.length?t.jsxs(t.Fragment,{children:[t.jsxs("h3",{children:[t.jsx(m.FontAwesomeIcon,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),t.jsx("input",{type:"file",style:{margin:20},accept:A?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=_(t.name);if(f.length>0&&!f.includes(e))return void g.toast.error(e+" is not allowed")}n(e.target.files)}}),a.length>0?t.jsx(qe,{label:"Attachment Type",sx:{width:300,m:1},options:a,displayField:"value",valueField:"value",value:p,onChangeCallBack:e=>{h(e)}}):t.jsx(t.Fragment,{}),t.jsx(De,{label:"Remark",value:c,onChange:e=>u(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),t.jsx(s.Button,{sx:{m:1},variant:"contained",onClick:async()=>{let t=A?.refKeyAttachments.length||0;if(A?.maxAllowedNumberOfFiles&&r.length+t>A.maxAllowedNumberOfFiles)g.toast.error("Maximum number of attachments is "+A.maxAllowedNumberOfFiles);else if(!0===A?.isCategoryRequired&&a.length>0&&(null==p||void 0===p||""===p))g.toast.error("You must selected document type to process your request");else if(r){for(const e of r)if(e.type.startsWith("image/")){const t=600,i=1024*t;if(e.size>i)return void g.toast.error(`File ${e.name} is too large. Max allowed is ${t}KB.`)}await i({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:e.refKey,attachmentCode:e.attachmentCode,remark:c,category:p},files:r,successCallBkFn:e=>{y(e.data),n(null),h(null),u(null),g.toast.success("Your request has been process successfully")}})}else g.toast.error("You must add files to upload")},children:"Upload"})]}):t.jsx(t.Fragment,{})}):t.jsx(t.Fragment,{}),E&&A?.refKeyAttachments?.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("h3",{children:[t.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),t.jsx(s.Grid2,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:A?.refKeyAttachments.map(i=>t.jsx(s.Grid2,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:t.jsx(Ao,{...i,attachmentCode:e.attachmentCode,setAttachmentConfig:y,downloadAuthorityKey:A.downloadAuthorityKey,allowDelete:O})}))})]}):t.jsx(t.Fragment,{})]})},Io=e=>{const o=i.useSelector(e=>e.AppLayout),{t:r}=y.useTranslation();return t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",width:600,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[t.jsxs(s.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[t.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),r("WF_ACTION_HISTORY_LABEL")]}),t.jsx(s.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:e.actionHistory.map((i,r)=>t.jsx(t.Fragment,{children:t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[t.jsxs(s.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[t.jsx(s.Box,{sx:{marginBottom:.2},children:i.actionTime}),t.jsxs(F,{children:["via ",i.actionMethod]})]}),t.jsxs(s.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[t.jsx(To,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:i?.personId?i?.personId+"":void 0,style:{m:1,width:70,height:70}}),r!==e.actionHistory.length-1?t.jsx(s.Box,{sx:{marginTop:11,position:"absolute"},children:"|"}):t.jsx(t.Fragment,{})]}),t.jsxs(s.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[t.jsxs(s.Box,{sx:{width:"100%"},children:["ltr"===o.appDirection?`${i?.documentActionEnName}`:`${i?.documentActionArName}`,i?.actionComment?" - "+i.actionComment:""]}),t.jsx(s.Box,{sx:{width:"100%"},children:"ltr"===o.appDirection?`${i?.employeeEnName}`:`${i?.employeeArName}`})]})]})}))})]})},_o=e=>{const{t:i}=y.useTranslation(),o=we(),{ConfirmationWindow:r,setOpen:n}=be({body:i(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:i("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn)),e?.reloadData&&e.reloadData()}});let a=!0;if(e.authority&&(a=o.isUserAuthorized(e.authority)),a)return t.jsxs(t.Fragment,{children:[t.jsx(r,{}),t.jsxs(s.Button,{onClick:async()=>{if(e?.recordsToProcessActionOn&&e?.recordsToProcessActionOn.length>0){if(e?.preActionValidation)for(const t of e.recordsToProcessActionOn)if(!e.preActionValidation(t))return;!0===e?.isConfirmationRequired?n(!0):(await e.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn),e?.reloadData&&e.reloadData())}else g.toast.error(i("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"))},variant:e?.label?"outlined":e?.formActionProps?.actionButtonVariant?e.formActionProps.actionButtonVariant:"text",size:"small",color:e?.formActionProps?.actionButtonColor||"primary",children:[e?.icon?t.jsx(m.FontAwesomeIcon,{style:{marginRight:5,marginLeft:5},icon:e.icon}):t.jsx(t.Fragment,{}),e?.label?i(e.label):t.jsx(t.Fragment,{})]})]})},Eo=s.styled(e.QuickFilter)({display:"grid",alignItems:"center"}),Oo=s.styled(e.ToolbarButton)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",width:"min-content",height:"min-content",zIndex:1,opacity:t.expanded?0:1,pointerEvents:t.expanded?"none":"auto",transition:e.transitions.create(["opacity"])})),Co=s.styled(s.TextField)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",overflowX:"clip",width:t.expanded?260:"var(--trigger-width)",opacity:t.expanded?1:0,transition:e.transitions.create(["width","opacity"])})),No=i=>{const{t:o}=y.useTranslation(),r=we(),n=!i?.templateProps?.editAction?.authority||r.isUserAuthorized(i.templateProps.editAction.authority),a=rt(i?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},i?.templateProps?.data||[],i?.templateProps?.keyColumnName||"id");return t.jsxs(e.Toolbar,{children:[n&&"none"!=i?.templateProps?.editMode?.editMode&&(void 0===i?.templateProps?.hideCreateBtn||!1===i?.templateProps?.hideCreateBtn)?t.jsxs(s.Button,{onClick:i?.handleCreateNewRecord,children:[t.jsx(m.FontAwesomeIcon,{icon:"add",style:{marginRight:5,marginLeft:5}}),o("ADD_BTN_LABEL")]}):t.jsx(t.Fragment,{}),i?.templateProps?.rowActions?i.templateProps.rowActions.map((e,t)=>!0===e?.gridActionProps?.multiRecord?d.createElement(_o,{...e,key:t,reloadData:async()=>{i.templateProps.apiActions.reloadData(i?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:a.selectedRecordIds,recordsToProcessActionOn:a.selectedRecords}):null):t.jsx(t.Fragment,{}),t.jsx(s.Box,{sx:{flex:1,mx:.5,my:.5,padding:1},children:i?.templateProps?.tBar}),t.jsx(s.Tooltip,{title:"Columns",children:t.jsx(e.ColumnsPanelTrigger,{render:t.jsx(e.ToolbarButton,{}),children:t.jsx(e.GridViewColumnIcon,{fontSize:"small"})})}),t.jsx(s.Tooltip,{title:"Filters",children:t.jsx(e.FilterPanelTrigger,{render:(i,o)=>t.jsx(e.ToolbarButton,{...i,color:"default",children:t.jsx(s.Badge,{badgeContent:o.filterCount,color:"primary",variant:"dot",children:t.jsx(e.GridFilterListIcon,{fontSize:"small"})})})})}),i?.templateProps?.gridStateKey?t.jsx(s.Tooltip,{title:o("RESET_GRID_STATE"),children:t.jsx(s.IconButton,{onClick:i?.clearGridState,children:t.jsx(m.FontAwesomeIcon,{icon:"eraser"})})}):t.jsx(t.Fragment,{}),t.jsx(s.Divider,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),t.jsx(s.Tooltip,{title:o("EXPORT_EXECL_LABEL"),children:t.jsx(e.ExportExcel,{render:t.jsx(s.MenuItem,{}),children:t.jsx(m.FontAwesomeIcon,{icon:"file-excel",color:"green"})})}),t.jsxs(Eo,{children:[t.jsx(e.QuickFilterTrigger,{render:(e,i)=>t.jsx(s.Tooltip,{title:o("SEARCH_BTN_LABEL"),enterDelay:0,children:t.jsx(Oo,{...e,ownerState:{expanded:i.expanded},color:"default","aria-disabled":i.expanded,children:t.jsx(m.FontAwesomeIcon,{icon:"search"})})})}),t.jsx(e.QuickFilterControl,{render:({ref:i,...r},n)=>t.jsx(Co,{...r,ownerState:{expanded:n.expanded},inputRef:i,"aria-label":"Search",placeholder:`${o("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:t.jsx(s.InputAdornment,{position:"start",children:t.jsx(m.FontAwesomeIcon,{icon:"search"})}),endAdornment:n.value?t.jsx(s.InputAdornment,{position:"end",children:t.jsx(e.QuickFilterClear,{edge:"end",size:"small","aria-label":"Clear search",children:t.jsx(m.FontAwesomeIcon,{icon:"xmark"})})}):null,...r.slotProps?.input},...r.slotProps}})})]}),t.jsx(s.IconButton,{onClick:()=>{i.templateProps.apiActions.reloadData(i?.templateProps?.gridLoadParametersValues)},children:t.jsx(m.FontAwesomeIcon,{icon:"refresh"})})]})},Ro=i=>{const{t:o}=y.useTranslation(),r=we(),{ConfirmationWindow:n,setOpen:a}=be({body:o(i?.confirmationMessage||"ACTION_CONFIRMATION"),title:o("CONFIRMATION"),onConfirmationCallBk:async()=>{await(i?.actionFn(i.record)),i?.reloadData&&i.reloadData()}});let l=!0;i.authority&&(l=r.isUserAuthorized(i.authority));let d={};i?.getActionIconStyleForRecord&&(d=i.getActionIconStyleForRecord(i.record));let c=!0;i?.isActionVisibleForRecord&&(c=i?.isActionVisibleForRecord(i.record));let u=!1;if(i?.isActionDisabledForRecord&&(u=i.isActionDisabledForRecord(i.record)),l&&c)return t.jsxs(t.Fragment,{children:[t.jsx(n,{}),t.jsx(e.GridActionsCellItem,{disabled:u,icon:t.jsx(s.Tooltip,{title:i?.label?o(i.label):"",children:t.jsx(m.FontAwesomeIcon,{icon:i.icon,style:{...d,color:u?"gray":null!=d?.color?d.color:void 0}})}),showInMenu:i?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!u){if(i?.preActionValidation&&!i.preActionValidation(i.record))return;!0===i?.isConfirmationRequired?a(!0):(await i.actionFn(i.record),!0===i?.gridActionProps?.reloadGridAfterAction&&i?.reloadData&&i.reloadData())}}})]})};let bo=-1;const wo=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},So=(e,t)=>{const i=wo(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},Po=["__check__","actions"],vo=o=>{const{t:r}=y.useTranslation(),n=i.useSelector(e=>e.AppLayout),[a,l]=d.useState({}),[c,u]=d.useState(!0),{getLookupOptions:p}=(()=>{const{handleGetRequest:e}=Re(),t=i.useSelector(e=>e.AppLayout),o=async t=>{let i=[];return await e({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:t},successCallBkFn:e=>{i=e.data}}),i};return{generateLookupGridColumn:async e=>{let i=await o(e.lookupType);return{...e,options:i,displayField:"ltr"===t.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:o}})(),{Window:h,setWindowState:f}=Se({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}=Se({windowTitle:r(o.gridTitle)+" Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:()=>{o?.apiActions?.reloadData(o.gridLoadParametersValues)}}),[I,E]=d.useState([]),C=tt(o.formElements),N=[],R=d.useMemo(()=>o?.gridStateKey?wo(o.gridStateKey):{},[]);for(const e of C)!0===e?.gridProps?.hidden&&N.push(e.fieldName);let b={};if(R?.columnVisibilityModel){b=R.columnVisibilityModel;const e=Object.keys(b);for(const t of N)e.includes(t)||(b[t]=!1)}else for(const e of N)b[e]=!1;const w=i.useSelector(e=>e.AppLayout.appDirection),[S,P]=d.useState(b),[v,L]=d.useState(R.columnOrder||[]),[M,x]=d.useState(R.columnWidths||{}),[D,k]=d.useState(R.columnGroupingModel||[]);let U=R?.pinnedColumns?.left||[];U=U.filter(e=>!Po.includes(e));let F=R?.pinnedColumns?.right||[]||[];F=F.filter(e=>!Po.includes(e));const[B,q]=d.useState({left:[..."ltr"===w?Po:[],...U],right:[..."rtl"===w?Po:[],...F]}),j=we(),G=_.useNavigate(),[W,H]=d.useState(null),[Y,K]=d.useState(null),[V,z]=d.useState({}),Q=async()=>{let e=it(C,"row"===o?.editMode?.editMode||!1,r);for(let t of e)t?.lookupType&&(t.displayField="ltr"===n.appDirection?"lookupEnDisplay":"lookupArDisplay",t.options=await p(t.lookupType),t.valueField="lookupValue");E(e)},[$,Z]=d.useState({ids:new Set,type:"include"});let J="id";o?.keyColumnName&&(J=o?.keyColumnName);const X=o.setData;let ee=null;ee=o?.validationSchema?o.validationSchema:O.z.object(ot(C));let te=!0;o?.editAction?.authority&&(te=j.isUserAuthorized(o.editAction.authority));let ie=!0;o?.deleteAction?.authority&&(ie=j.isUserAuthorized(o.deleteAction.authority));const{ConfirmationWindow:oe,setOpen:re}=be({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let e=!0;W&&!0===W?.isNew||(e=await o.apiActions.deleteRecordById(W[J])),e&&(o?.deleteAction?.postActionCallBack&&await o.deleteAction.postActionCallBack(W),X(e=>e.filter(e=>e[J]!=W[J])))}});let ne,ae,se,le,de,ce;"modal"===o?.editMode?.editMode&&(ne=o?.editMode?.specs?.modalHeight||"fit-content",ae=o?.editMode?.specs?.modalWidth||"300",se=o?.editMode?.specs?.modalMinHeight,le=o?.editMode?.specs?.modalMinWidth,de=o?.editMode?.specs?.modalIcon||"window",ce=o?.editMode?.specs?.modalTitle||"Record Form");const{Window:ue,setWindowState:pe}=Se({height:ne,minHeight:se,minWidth:le,onCloseCallBack:()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},width:ae,windowIcon:de,windowTitle:ce}),he={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:i=>{const n=i.row,a=[];if("none"!=o?.editMode?.editMode&&(void 0===o?.disableDefaultAction||!o.disableDefaultAction)){const i=V[n[J]]?.mode===e.GridRowModes.Edit;if("row"===o.editMode.editMode&&i)te&&(a.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(m.FontAwesomeIcon,{icon:"save"}),label:r("SAVE_BTN_LABEL"),onClick:()=>{(t=>{const i=t[J];z({...V,[i]:{mode:e.GridRowModes.View}})})(n)}})),a.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(m.FontAwesomeIcon,{icon:"cancel"}),label:r("CANCEL_BTN_LABEL"),onClick:()=>{(t=>{const i=t[J];i&&lo(i)&&i<0?(z({...V,[i]:{mode:e.GridRowModes.View,ignoreModifications:!0}}),X(e=>{const t=e.filter(e=>e[J]!=i);return t})):z({...V,[i]:{mode:e.GridRowModes.View,ignoreModifications:!0}})})(n)},color:"inherit"})));else{if(o?.editAction&&!0===o?.editAction?.isEnabled){let i=!0;o?.editAction?.isActionVisibleForRecord&&(i=o?.editAction?.isActionVisibleForRecord(n));let l=!1;o?.editAction?.isActionDisabledForRecord&&(l=o?.editAction?.isActionDisabledForRecord(n)),te&&i&&a.push(t.jsx(e.GridActionsCellItem,{disabled:l,icon:t.jsx(s.Tooltip,{title:r("EDIT_BTN_LABEL"),children:t.jsx(m.FontAwesomeIcon,{icon:"edit",style:{color:l?"gray":void 0}})}),showInMenu:o?.editAction?.gridActionProps?.showInMenu||!1,label:r("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{te&&!l&&(async t=>{if(t)if(K(t),"form"===o.editMode.editMode)G(o.editMode.specs.formRoute+"/"+t[J]);else if("modal"===o.editMode.editMode)pe(!0);else if("row"===o?.editMode?.editMode){const i=t[J];z({...V,[i]:{mode:e.GridRowModes.Edit}})}})(n)}}))}if(o?.deleteAction&&!0===o?.deleteAction?.isEnabled){let i=!0;o?.deleteAction?.isActionVisibleForRecord&&(i=o?.deleteAction?.isActionVisibleForRecord(n));let l=!1;o?.deleteAction?.isActionDisabledForRecord&&(l=o?.deleteAction?.isActionDisabledForRecord(n)),ie&&i&&a.push(t.jsx(e.GridActionsCellItem,{disabled:l,icon:t.jsx(s.Tooltip,{title:r("DELETE_BTN_LABEL"),children:t.jsx(m.FontAwesomeIcon,{icon:"trash",style:{color:l?"gray":void 0}})}),showInMenu:o?.deleteAction?.gridActionProps?.showInMenu||!1,label:r("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(ie&&!l){if(o?.deleteAction?.preActionValidation&&!o.deleteAction.preActionValidation(n))return;H(n),re(!0)}}}))}}}if(n[o?.keyColumnName||"id"]&&n[o?.keyColumnName||"id"]>0&&o?.attachment&&a?.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(s.Tooltip,{title:"Attachments",children:t.jsx(m.FontAwesomeIcon,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{l(n),u(!o?.attachment?.enableAttachFn||o.attachment.enableAttachFn(n)),f(!0)}})),n[o?.keyColumnName||"id"]&&n[o?.keyColumnName||"id"]>0&&o?.workFlowDocumentCode&&a?.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(s.Tooltip,{title:"Approvals",children:t.jsx(m.FontAwesomeIcon,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{l(n),A(!0)}})),n[o?.keyColumnName||"id"]&&n[o?.keyColumnName||"id"]>0&&o?.rowActions)for(const e of o.rowActions)e?.gridActionProps?.multiRecord&&!0===e?.gridActionProps?.multiRecord||a.push(t.jsx(Ro,{...e,record:n,reloadData:async()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)}}));return a}};let me=[];(void 0===o?.disableDefaultAction||!o.disableDefaultAction||o?.rowActions&&o?.rowActions.length>0)&&me.push(he),me=[...me,...I];d.useEffect(()=>{void 0!==o?.autoLoad&&!0!==o.autoLoad||o.apiActions.reloadData(o?.gridLoadParametersValues),Q()},[]),d.useEffect(()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},[j.UserInfo?.currentOrganization]),d.useEffect(()=>{Q()},[w,o.formElements]);const fe=d.useMemo(()=>{const e=me.map(e=>({...e}));if(v.length){const t=new Map(e.map(e=>[e.field,e]));return v.map(e=>t.get(e)).filter(Boolean)}return e},[v,M,me]);return t.jsxs(t.Fragment,{children:[t.jsx(oe,{}),"modal"===o?.editMode?.editMode?t.jsx(ue,{children:o?.editMode?.specs?.formComponent?t.jsx(o.editMode.specs.formComponent,{recordIdToEdit:Y?Y[J]:void 0,formCloseCallBk:()=>{pe(!1),o.apiActions.reloadData(o?.gridLoadParametersValues)}}):t.jsx(Uo,{keyColumnName:o.keyColumnName,attachment:o.attachment,formValuesChangeCallBk:o?.formProps?.formValuesChangeCallBk,recordIdToEdit:Y?Y[J]:void 0,formCloseCallBk:()=>{pe(!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})}):t.jsx(t.Fragment,{}),void 0!==o?.hideInfoBar||o?.hideInfoBar?t.jsx(t.Fragment,{}):t.jsxs(s.Box,{sx:{display:"flex"},children:[void 0!==o?.hideBackButton||o?.hideBackButton?t.jsx(t.Fragment,{}):t.jsx(s.IconButton,{onClick:()=>{G(-1,{replace:!0})},children:t.jsx(m.FontAwesomeIcon,{icon:"ltr"===w?"arrow-left":"arrow-right"})}),t.jsxs(s.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[o?.girdIcon?t.jsx(m.FontAwesomeIcon,{icon:o.girdIcon,style:{marginRight:5,marginLeft:5}}):t.jsx(t.Fragment,{}),t.jsx(s.Typography,{variant:"h5",children:o?.gridTitle?uo(r(o?.gridTitle)):""})]})]}),o?.gridLoadParameters&&o?.gridLoadParameters.length>0&&o?.gridLoadParametersValues&&o?.setGridLoadParametersValues?t.jsxs(s.Accordion,{defaultExpanded:!0,sx:{width:"100%"},children:[t.jsx(s.AccordionSummary,{expandIcon:t.jsx(e.GridExpandMoreIcon,{}),children:t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),t.jsx(s.Typography,{component:"span",children:"Filters"})]})}),t.jsx(s.AccordionDetails,{children:t.jsx(s.Box,{children:t.jsx(Uo,{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})})})]}):t.jsx(t.Fragment,{}),o?.attachment?t.jsx(h,{children:t.jsx(yo,{attachmentCode:o.attachment.attachmentCode,refKey:a[o?.keyColumnName||"id"],enableAttachment:c})}):t.jsx(t.Fragment,{}),o?.workFlowDocumentCode?t.jsx(T,{children:t.jsx(ko,{workFlowDocumentCode:o.workFlowDocumentCode,refDocumentId:a[o?.keyColumnName||"id"],postActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)},cancelActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)}})}):t.jsx(t.Fragment,{}),t.jsx(e.DataGridPremium,{...o?.muiProps,slots:{toolbar:No},slotProps:{toolbar:{templateProps:{...o,rowSelectionModel:$,data:o?.data},handleCreateNewRecord:()=>{if("form"===o?.editMode?.editMode)G(o.editMode.specs.formRoute);else if("modal"===o?.editMode?.editMode)K(null),pe(!0);else if("row"===o?.editMode?.editMode){bo-=1;const t={};t[J]=bo,t.isNew=!0;for(const e of I)"actions"!=e?.type&&e?.field!=J&&e?.field&&(t[e.field]=null);X(e=>[t,...e]),z(t=>({...t,[bo]:{mode:e.GridRowModes.Edit}}))}},clearGridState:()=>{o?.gridStateKey&&localStorage.removeItem(o.gridStateKey),P({}),L([]),x({}),k([]),q({left:[..."ltr"===w?Po:[]],right:[..."rtl"===w?Po:[]]})}}},getRowId:e=>e[J],showToolbar:!0,rows:o?.data,columns:fe,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==o.editMode.editMode?V:void 0,onRowModesModelChange:"row"==o.editMode.editMode?e=>{z(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async e=>{if("row"===o.editMode.editMode){let i=null;const r=(e=>{try{ee.parse(e)}catch(e){console.log("validateRecord err",e);let t=null;return t=e instanceof O.z.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",t}})(e);if(r){const e=r.split(",");throw g.toast.error(t.jsx("div",{style:{},children:e.map(e=>t.jsxs(t.Fragment,{children:[t.jsx("div",{children:e}),t.jsx(s.Divider,{})]}))})),new Error(r)}if(o?.editAction?.preActionValidation&&!o.editAction.preActionValidation(e))throw new Error("error on the configured presave validation");const n={...e};if(e[J]&&lo(e[J])&&Number(e[J])<0&&(n[J]=null),i=await o.apiActions.saveRecord(n),null==i)throw new Error("Failed to process your request, contact your administrator");return o?.editAction?.postActionCallBack&&await o.editAction.postActionCallBack(e),!0===e?.isNew&&X(t=>{const o=t.filter(t=>t[J]!==e[J]);return[i,...o]}),!0===o?.editMode?.reloadAfterSave&&o?.apiActions?.reloadData&&o?.apiActions?.reloadData(o?.gridLoadParametersValues),i}},rowSelectionModel:$,onRowSelectionModelChange:e=>{Z(e)},columnVisibilityModel:S,onColumnVisibilityModelChange:e=>{P(e),o?.gridStateKey&&So(o.gridStateKey,{columnVisibilityModel:e})},onColumnOrderChange:e=>{const{column:t,targetIndex:i}=e;L(e=>{const r=e.length?[...e]:me.map(e=>e.field),n=r.indexOf(t.field);return-1===n||(r.splice(n,1),r.splice(i,0,t.field),o?.gridStateKey&&So(o.gridStateKey,{columnOrder:r})),r})},rowGroupingModel:D,onRowGroupingModelChange:e=>{(e=>{k(e),o?.gridStateKey&&So(o.gridStateKey,{columnGroupingModel:e})})(e)},sx:{width:"100%"}})]})},Lo=e=>{if(0===e.length)return[];const t=[];for(const i of Object.keys(e[0])){const e={type:"field",mode:"props",props:{fieldLabel:i,fieldName:i,fieldType:"text"}};t.push(e)}return t},Mo=e=>{const[i,o]=d.useState([]);return d.useEffect(()=>{const t=e.reportData.map((e,t)=>({...e,report_record_data_key:t}));o(t)},[e.reportData]),t.jsx(vo,{data:i,disableDefaultAction:!0,setData:e.setReportData,formElements:Lo(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()=>{}}})},xo=e=>{const[i,o]=d.useState({...e?.initialParameterValues}),r=((e,t)=>{const i=[];for(const o of e){const e={type:"field",mode:"props",props:{fieldLabel:o?.parameterLabel,fieldName:o?.parameterCode,fieldType:o?.parameterType,hidden:o?.hidden,formProps:{fieldSize:{lg:4,md:6,sm:12}},required:o?.mandatory,defaultValue:t[o?.parameterCode]||o?.defaultValue}};i.push(e)}return i})(e.parameters,i);return{ParameterPanel:({searchBtnClickCallBk:e})=>{const{t:i}=y.useTranslation();return t.jsxs(s.Accordion,{defaultExpanded:!0,sx:{width:"100%"},children:[t.jsx(s.AccordionSummary,{expandIcon:t.jsx(m.FontAwesomeIcon,{icon:{prefix:"far",iconName:"square-caret-down"}}),children:t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),t.jsx(s.Typography,{component:"span",children:"Filters"})]})}),t.jsx(s.AccordionDetails,{children:t.jsx(s.Box,{children:t.jsx(Uo,{saveButtonSpecs:{label:i("Filter"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:i("RESET_BTN_LABEL"),icon:"eraser",hidden:!0,actionButtonVariant:"outlined",actionButtonColor:"error"},actions:[{label:i("RESET_BTN_LABEL"),icon:"eraser",isIdRequired:!1,formActionProps:{enabled:!0},actionFn:async(e,t)=>{o({})}}],apiActions:{deleteRecordById:async()=>!0,saveRecord:async t=>{o(null!=t?t:{}),e&&await e(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:r})})})]})},parametersValues:i,setParametersValues:o,panelElements:r}},Do=e=>{const[i,o]=d.useState(null),[r,n]=d.useState(null),[a,l]=d.useState([]),[c,u]=d.useState("WAITING_REPORT_CODE"),{handleGetRequest:p,handlePostRequest:h,HandleDownloadHTTPPostPDF:f}=Re(),[g,T]=d.useState(null),{ParameterPanel:A,parametersValues:y,panelElements:I,setParametersValues:_}=xo({parameters:g?.reportParameters||[],initialParameterValues:{...e?.reportParametersValues}});d.useEffect(()=>{g&&(!0===e?.byPassParameterEntry||0==g.reportParameters.length?(E(y),u("WAITING_RESULT")):u("WAITING_PARAMETER_INPUT"))},[g]);const E=async t=>{u("WAITING_RESULT"),"Excel"===g?.reportType?await h({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{u("SHOWING_RESULT"),l(e.data)}}):g?.reportType&&await f({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{u("SHOWING_RESULT");const t=e.headers["content-disposition"];let i="downloaded_file";if(t&&-1!==t.indexOf("filename=")){const e=t.match(/filename="?([^"]+)"?/);e&&e[1]&&(i=e[1])}if(i.includes("pdf")){const t=new Blob([e.data],{type:"application/pdf"}),i=URL.createObjectURL(t);o(i)}else{const t=new Blob([e.data],{type:e.headers["content-type"]}),o=window.URL.createObjectURL(t),r=document.createElement("a");r.href=o,r.download=i,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(o)}},failureCallBkFn:e=>{n("Failed To run report ... contact your administrator"),u("ERROR")}})};return d.useEffect(()=>{e?.reportCode&&(async()=>{u("LOADING_METADATA"),await p({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:e.reportCode},successCallBkFn:e=>{T(e.data)},failureCallBkFn:e=>{n("Failed loading report metadata ... contact your administrator"),u("ERROR")}})})()},[e.reportCode,e.byPassParameterEntry,e.reportParametersValues,e.jasperOutPutFileType,e.resultMode]),t.jsxs(t.Fragment,{children:[t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[t.jsxs(s.Box,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[t.jsx(m.FontAwesomeIcon,{icon:"Excel"===g?.reportType?"file-excel":"file-pdf",color:"Excel"===g?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),g?.reportName]}),"Excel"!=g?.reportType&&"SHOWING_RESULT"===c?t.jsxs(t.Fragment,{children:[!0===e?.byPassParameterEntry?t.jsx(t.Fragment,{}):g?.reportParameters.length>0?t.jsx(s.IconButton,{onClick:()=>{u("WAITING_PARAMETER_INPUT")},children:t.jsx(m.FontAwesomeIcon,{icon:"filter"})}):t.jsx(t.Fragment,{}),t.jsx(s.IconButton,{children:t.jsx(m.FontAwesomeIcon,{icon:"refresh",onClick:()=>{E(y)}})})]}):t.jsx(t.Fragment,{})]}),t.jsx(s.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===c&&"Excel"!=g?.reportType?t.jsx(A,{searchBtnClickCallBk:E}):"SHOWING_RESULT"===c||("WAITING_PARAMETER_INPUT"===c||"WAITING_RESULT"===c)&&"Excel"===g?.reportType?"Excel"===g?.reportType?t.jsx(Mo,{reportData:a,setReportData:l,reloadReport:async()=>{E(y)},gridLoadParameters:I,gridLoadParametersValues:y,setGridLoadParametersValues:_}):t.jsx("iframe",{src:i,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===c?t.jsxs(s.Box,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[t.jsx(m.FontAwesomeIcon,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),r]}):t.jsx(t.Fragment,{})})]})},ko=e=>{const o=_.useNavigate(),r=i.useSelector(e=>e.AppLayout),{isUserAuthorized:n,UserInfo:a}=we(),{handleGetRequest:l,handlePostRequest:c}=Re(),[u,p]=d.useState(null),[h,f]=d.useState([]),{t:T}=y.useTranslation(),[A,I]=d.useState(null),[E,O]=d.useState({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:C,setWindowState:N}=Se({windowTitle:"ltr"===r.appDirection?E?.workflowDocument&&E?.referencedDocument?`${E?.workflowDocument?.documentEnName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`:"Document":E?.workflowDocument&&E?.referencedDocument?`${E?.workflowDocument?.documentArName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),R=async()=>{await l({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:e.workFlowDocumentCode,refDocumentId:e.refDocumentId},successCallBkFn:e=>{O(structuredClone(e.data))},failureCallBkFn:()=>{O({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},b=async()=>{await c({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:E?.workflowDocument?.id,refDocumentId:e.refDocumentId,actionId:u.id,refDocumentStatus:E?.workflowDocumentStatus?.documentStatusCode,actionComment:A},successCallBkFn:async t=>{u?.post_action_endpoint?await c({endPointURI:u.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:u.id},successCallBkFn:()=>{R(),e?.postActionCallBk&&e.postActionCallBk()}}):R()}})};return d.useEffect(()=>{e.refDocumentId&&e.workFlowDocumentCode&&R()},[e.refDocumentId,e.workFlowDocumentCode]),d.useEffect(()=>{f(E?.nextActions&&E?.nextActions?.length>0?E.nextActions.filter(e=>{if(!E?.workflowDocumentStatus?.nextActionTakersAuthority&&!E?.nextActionTakers)return!0;if(E?.workflowDocumentStatus?.nextActionTakersAuthority&&n(E.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(E?.nextActionTakers)for(const e of E.nextActionTakers)if(a?.username===e?.username||a?.username===e?.USERNAME)return!0;return!1}):[])},[E.nextActions,E.nextActionTakers]),t.jsxs(t.Fragment,{children:[E?.workflowDocumentReport?.id?t.jsx(C,{children:t.jsx(Do,{reportCode:E?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:e.refDocumentId+""}})}):t.jsx(t.Fragment,{}),E?.workflowDocument?t.jsxs(s.Box,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(s.IconButton,{onClick:()=>{o(-1,{replace:!0})},children:t.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),t.jsx(s.Box,{sx:{flex:1}}),t.jsx(m.FontAwesomeIcon,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===r.appDirection?`${E?.workflowDocument?.documentEnName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`:`${E?.workflowDocument?.documentArName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`,E?.workflowDocumentStatus?"ltr"===r.appDirection?` ( ${E?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${E?.workflowDocumentStatus?.documentStatusArName} )`:"",t.jsx(s.Box,{sx:{flex:1}}),E?.workflowDocumentReport?.id?t.jsx(s.Button,{onClick:()=>{N(!0)},variant:"outlined",startIcon:t.jsx(m.FontAwesomeIcon,{icon:"eye"}),children:T("VIEW_LABEL")}):t.jsx(t.Fragment,{})]}):t.jsx(t.Fragment,{}),t.jsxs(s.Box,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[h?.length>0?t.jsxs(s.Paper,{sx:{padding:2,display:"flex",margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[t.jsx(qe,{sx:{marginBottom:2,width:400},label:T("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===r.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:u?.id,options:h,onChangeCallBack:(e,t)=>{p(t)}}),t.jsx(De,{sx:{width:400},rows:3,value:A,onChange:e=>{I(e.target.value)},multiline:!0,label:T("WF_COMMENT_LABEL")}),t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(s.Button,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=u&&null!=u?.id?!0!==u.require_comment&&1!==u.require_comment&&"true"!==u.require_comment||null!==A&&""!==A?u?.pre_action_endpoint?await c({endPointURI:u.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:u.id},successCallBkFn:()=>{b()}}):b():g.toast.error("You must enter comment for the action to be processed"):g.toast.error("You must select action to process")},children:T("WF_TAKE_ACTION_BTN_LABEL")}),e?.cancelActionCallBk?t.jsx(s.Button,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{e?.cancelActionCallBk&&e.cancelActionCallBk()},children:T("WF_CANCEL_BTN_LABEL")}):t.jsx(t.Fragment,{})]}),E?.nextActionTakers&&E.nextActionTakers.length>0?t.jsxs(t.Fragment,{children:[t.jsx(s.Divider,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:t.jsxs(s.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[t.jsx(m.FontAwesomeIcon,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",T("WF_WAITING_FOR_LABEL")]})}),t.jsx(s.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:E.nextActionTakers.map(e=>t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[t.jsx(To,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:e?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),t.jsxs(s.Box,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[t.jsx("div",{children:"ltr"===r.appDirection?e?.employee_en_name:e?.employee_ar_name}),t.jsx("div",{children:e?.email?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),e?.email]}):t.jsx(t.Fragment,{})}),t.jsx("div",{children:e?.mobile_number?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),e?.mobile_number]}):t.jsx(t.Fragment,{})})]})]}))})]}):t.jsx(t.Fragment,{})]}):t.jsx(t.Fragment,{}),E?.actionsHistory.length>0?t.jsx(Io,{actionHistory:E.actionsHistory}):t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",width:600,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[t.jsxs(s.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[t.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),T("WF_ACTION_HISTORY_LABEL")]}),t.jsx(s.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},Uo=e=>{const{Window:i,setWindowState:o}=Se({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[r,n]=d.useState(!0),{t:a}=y.useTranslation(),l=tt(e.elements),[c,u]=d.useState([]),[p,h]=d.useState([]),f={};for(const t of e.elements)"field"===t?.type&&"props"===t?.mode&&t?.props?.defaultValue&&(f[t.props.fieldName]=t.props.defaultValue);let T=null;T=e?.validationSchema?e.validationSchema:ue.object(ot(l));const A=I.useForm({resolver:E.zodResolver(T),defaultValues:f}),O=A.watch(),C=_.useParams(),N=e?.formRouteRecordIdParamName,R=async()=>{let t=null;if(e?.recordIdToEdit?t=e.recordIdToEdit:N&&C[N]&&(t=C[N]),t){const i=await e.apiActions.loadRecordById(t);if(i){A.reset({...i}),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk({...i},S,A);for(const e of l)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?A.setValue(e.fieldName,i[e.fieldName]+""):A.setValue(e.fieldName,i[e.fieldName]))}}else A.reset({})},{Window:b,setWindowState:w}=Se({windowTitle:"Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:async()=>{await R()}}),S={setFieldValue:(e,t)=>{A.setValue(e,t)},hideField:e=>{h(t=>[...t,e])},showField:e=>{h(t=>t.filter(t=>t!==e))},disableField:e=>{u(t=>[...t,e])},enableField:e=>{u(t=>t.filter(t=>t!==e))}};return d.useEffect(()=>{const e=[],t=[];for(const i of l)i?.hidden&&e.push(i.fieldName),i?.disabled&&t.push(i.fieldName);h(e),u(t)},[e.elements]),d.useEffect(()=>{R()},[e?.recordIdToEdit]),d.useEffect(()=>{n(!e?.attachment||!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(O))},[O]),t.jsxs(t.Fragment,{children:[e?.attachment?t.jsx(i,{children:t.jsx(yo,{attachmentCode:e.attachment.attachmentCode,refKey:O[e?.keyColumnName||"id"],enableAttachment:r})}):t.jsx(t.Fragment,{}),e?.workFlowDocumentCode?t.jsx(b,{children:t.jsx(ko,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:O[e?.keyColumnName||"id"],postActionCallBk:()=>{w(!1),R()},cancelActionCallBk:()=>{w(!1),R()}})}):t.jsx(t.Fragment,{}),t.jsx(so,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:t.jsx(s.Grid2,{sx:{width:"100%"},container:!0,children:e.elements.map((i,o)=>"group"===i.type?t.jsx(go,{...i.props,formManager:A,formValues:O,formActions:S,hiddenFields:p,disabledFields:c,formValuesChangeCallBk:e.formValuesChangeCallBk},o):"field"===i.type&&"props"===i.mode?t.jsx(mo,{fieldInfo:i.props,formManager:A,formValues:O,formActions:S,hiddenFields:p,disabledFields:c,formValuesChangeCallBk:e.formValuesChangeCallBk},o):"field"===i.type&&"node"===i.mode?t.jsx(s.Grid2,{size:i?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:t.jsx(i.node,{formManager:A,formValues:O})},o):void 0)})}),t.jsxs(so,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[O[e?.keyColumnName||"id"]&&e?.attachment?t.jsx(s.Tooltip,{title:"Attachments",children:t.jsx(s.IconButton,{onClick:()=>{o(!0)},children:t.jsx(m.FontAwesomeIcon,{icon:"paperclip"})})}):null,O[e?.keyColumnName||"id"]&&e?.workFlowDocumentCode?t.jsx(s.Tooltip,{title:"Approvals",children:t.jsx(s.IconButton,{onClick:()=>{w(!0)},children:t.jsx(m.FontAwesomeIcon,{icon:"stamp"})})}):null,e?.actions?e.actions.map(i=>!1===i?.isIdRequired?t.jsx(fo,{...i,record:O}):O[e?.keyColumnName||"id"]?!0===i?.formActionProps?.enabled?t.jsx(fo,{...i,record:O}):t.jsx(t.Fragment,{}):void 0):t.jsx(t.Fragment,{}),t.jsx("div",{style:{flex:1}}),e?.saveButtonSpecs?.hidden?t.jsx(t.Fragment,{}):t.jsx(s.Button,{variant:e?.saveButtonSpecs?.actionButtonVariant?e.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:e?.saveButtonSpecs?.icon?t.jsx(m.FontAwesomeIcon,{icon:e.saveButtonSpecs.icon}):null,color:e?.saveButtonSpecs?.actionButtonColor?e.saveButtonSpecs.actionButtonColor:"primary",onClick:A.handleSubmit(t=>{(async t=>{if((!e?.preSaveValidation||e.preSaveValidation(t))&&t){const i=await e.apiActions.saveRecord(t);i&&(A.reset({...i}),e?.formSavedSuccessfullyCallBk&&e.formSavedSuccessfullyCallBk(i),e?.formCloseCallBk&&e.formCloseCallBk())}})(t)},e=>{g.toast.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:a(e?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),e?.cancelButtonSpecs?.hidden?t.jsx(t.Fragment,{}):t.jsx(s.Button,{variant:e?.cancelButtonSpecs?.actionButtonVariant?e.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:e?.cancelButtonSpecs?.icon?t.jsx(m.FontAwesomeIcon,{icon:e.cancelButtonSpecs.icon}):null,color:e?.cancelButtonSpecs?.actionButtonColor?e.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{e?.formCloseCallBk&&e.formCloseCallBk(),A.reset(f)},children:a(e?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},Fo=()=>{const{workflowDocumentCode:e,refDocumentId:i}=_.useParams();return t.jsx(ko,{workFlowDocumentCode:e,refDocumentId:i})},Bo=e=>t.jsx(j.BarChart,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),qo=e=>t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[t.jsx(s.Box,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:t.jsx("div",{children:e.record[e.valueField]})}),t.jsx(s.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]})]}),jo=e=>t.jsxs(t.Fragment,{children:[t.jsx(s.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),t.jsx(j.Gauge,{width:200,height:200,value:e.record[e.valueField],valueMax:e.total})]}),Go=e=>t.jsx(j.LineChart,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function Wo(e){return t.jsxs(W,{sx:{display:"flex",alignItems:"center"},children:[t.jsx(W,{sx:{width:"100%",mr:1},children:t.jsx(G,{variant:"determinate",...e})}),t.jsx(W,{sx:{minWidth:35},children:t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(e.value)}%`})})]})}const Ho=e=>t.jsxs(W,{sx:{width:"100%"},children:[t.jsx(F,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),t.jsx(Wo,{value:e.record[e.valueField]/e.total*100})]}),Yo=e=>{const i=e.data.map((t,i)=>({id:i,value:t[e.valueField],label:t[e.labelField]+""}));return t.jsx(H.PieChart,{series:[{data:i}]})},Ko=e=>{const[i,o]=d.useState(!0),[r,n]=d.useState([]),{handleGetRequest:a}=Re();d.useEffect(()=>{e.loadWidget?(async()=>{o(!0),await a({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e.parameterValues},successCallBkFn:e=>{o(!1),n(e.data)},failureCallBkFn:()=>{o(!1),n([])}})})():o(!1)},[e.loadWidget,e.loadCounter]);let l=0;if(1==r.length)l=100;else if("CircularProgress"===e.widgetType||"LinearProgress"===e.widgetType)for(const t of r)l+=t[e.verticalAxisField];return t.jsxs(t.Fragment,{children:["LineChart"===e.widgetType||"PieChart"===e.widgetType||"ColumnChart"===e.widgetType?t.jsxs(s.Box,{children:[t.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:e?.icon||"chart-pie"}),e?.title]}):t.jsx(t.Fragment,{}),t.jsx(s.Box,{sx:{flex:1,padding:1,height:"90%",display:"flex",alignItems:"center",justifyContent:"center",width:"90%"},children:i?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),t.jsx("div",{children:"Loading"})]}):"ColumnChart"===e.widgetType?t.jsx(Bo,{data:r,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===e.widgetType?t.jsx(Go,{data:r,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===e.widgetType?t.jsx(Yo,{data:r,widgetTitle:e.title,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,widgetType:"Pie"}):t.jsxs(s.Grid2,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[t.jsx(s.Grid2,{size:{xs:12},sx:{textAlign:"center"},children:e.title}),r.map((i,o)=>"Card"===e.widgetType?t.jsx(s.Grid2,{size:{md:3,xs:12},children:t.jsx(qo,{widgetTitle:"",record:i,labelField:e.horizontalAxisField,valueField:e.verticalAxisField},o)}):"CircularProgress"===e.widgetType?t.jsx(s.Grid2,{size:{md:3,xs:12},children:t.jsx(jo,{widgetTitle:"",record:i,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:l},o)}):"LinearProgress"===e.widgetType?t.jsx(s.Grid2,{size:{md:3,xs:12},children:t.jsx(Ho,{widgetTitle:"",record:i,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:l},o)}):void 0)]})})]})},Vo=e=>{const[i,o]=d.useState({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),{ParameterPanel:r,parametersValues:n}=xo({parameters:i?.dashboardParameters||[],initialParameterValues:{}}),[a,l]=d.useState(0),[c,u]=d.useState(!1);d.useEffect(()=>{if(null!=i.dashboardCode&&null!=i.dashboardCode&&""!=i.dashboardCode){u(!1);let e=!0;if(i?.dashboardParameters.length>0)for(const t of i?.dashboardParameters)if(!0===t?.mandatory&&(void 0===n[t.parameterCode]||null===n[t.parameterCode]||""===n[t.parameterCode])){e=!1;break}e&&u(e),l(a+1)}},[i?.dashboardParameters,n]);const p=_.useNavigate(),{handleGetRequest:h,handlePostRequest:f}=Re();return d.useEffect(()=>{e.dashboardCode&&(async()=>{await h({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:e.dashboardCode},successCallBkFn:e=>{o(e.data)},failureCallBkFn:()=>{o(null)}})})()},[e.dashboardCode,e.parameters]),t.jsx(t.Fragment,{children:i?t.jsxs(t.Fragment,{children:[t.jsxs(s.Box,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(s.IconButton,{onClick:()=>{p(-1,{replace:!0})},children:t.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),t.jsx(s.Box,{sx:{flex:1}}),t.jsx(m.FontAwesomeIcon,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),t.jsx(s.Box,{children:i?.dashboardTitle}),t.jsx(s.Box,{sx:{flex:1}})]}),i?.dashboardParameters.length>0?t.jsx(r,{searchBtnClickCallBk:async e=>{l(a+1)}}):t.jsx(t.Fragment,{}),t.jsx(s.Grid2,{container:!0,spacing:1,sx:{height:"fit-content",overflowY:"auto",padding:1},children:i?.widgets.map((e,i)=>t.jsx(s.Grid2,{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:t.jsx(Ko,{...e,parameterValues:n,loadWidget:c})},i))})]}):t.jsx(s.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},zo=()=>{const{dashboardCode:e}=_.useParams();return t.jsx(Vo,{dashboardCode:e})},Qo=e=>{const{UserSession:o}=we(),r=i.useSelector(e=>e.AppLayout),n=i.useDispatch(),{handlePostRequest:a}=Re(),[l,c]=d.useState(o.value.currentOrganization.id);return t.jsxs(s.Box,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[t.jsx(qe,{sx:{width:"100%"},displayField:"ltr"===r.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:o.value.userOrganizations,value:l,onChangeCallBack:e=>{c(e)}}),t.jsx(s.Button,{sx:{m:1},variant:"contained",disabled:null==l||l===o.value.currentOrganization.id,onClick:async()=>{await a({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:o.value.username,orgId:l},data:{},successCallBkFn:t=>{const i={...t.data,isAuthenticated:!0};n(Ce.setAuthenticated(i)),e.successChangeCallBackFn&&e.successChangeCallBackFn()}})},children:"Change Organization"})]})},$o=f.createSlice({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Zo,setSideBarState:Jo}=$o.actions;var Xo=$o.reducer;function er(e,t){const i=d.useRef(e);d.useEffect(()=>{i.current=e},[e]),d.useEffect(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const tr=s.keyframes`
31
+ function(e,t){const i=ne(e,t);return"production"!==process.env.NODE_ENV?(...t)=>{const o=`"${e}"`;return 0===t.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")):t.some(e=>void 0===e)&&console.error(`MUI: the styled(${o})(...args) API requires all its args to be defined.`),i(...t)}:i}("div",{shouldForwardProp:e=>"theme"!==e&&"sx"!==e&&"as"!==e})(Zi),s=ce.forwardRef(function(e,s){const l=function(e=eo){return Xi(e)}(o),{className:d,component:c="div",...u}=to(e);return t.jsx(a,{as:c,ref:s,className:no(d,n?n(r):r),theme:i&&l[i]||l,...u})});return s}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=ao[t];return o?`${i}-${o}`:`${oo.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:oo.generate});function lo(e){return"number"==typeof e&&!isNaN(e)}function co(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function uo(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function po(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function ho(e,t){const i=new Date(e),o=new Date,r=Math.floor((i-o)/1e3),n="rtl"===t?"ar":"en",a=new Intl.RelativeTimeFormat(n,{numeric:"auto"}),s=[{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:t}of s){const i=Math.floor(r/t);if(Math.abs(i)>1)return a.format(i,e)}return"ar"===n?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(so.propTypes={children:Dt.node,component:Dt.elementType,sx:Dt.oneOfType([Dt.arrayOf(Dt.oneOfType([Dt.func,Dt.object,Dt.bool])),Dt.func,Dt.object])});const mo=e=>{if(e?.fieldInfo){const i=e.fieldInfo,o=e?.formManager||null,r=e?.formActions||null,n=e?.formValues||null,a=e?.fieldInfo?.fieldName||null,l=e?.fieldInfo?.fieldType||null;if(!(i&&o&&n&&a&&l))return t.jsx(t.Fragment,{});const d=()=>e?.fieldInfo?.formProps?.fieldLabelFn?e.fieldInfo.formProps.fieldLabelFn(n):e?.fieldInfo?.fieldLabel?e?.fieldInfo?.fieldLabel:void 0;return e.hiddenFields.includes(a)?t.jsx(t.Fragment,{}):t.jsx(s.Grid2,{size:i?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===l||"number"===l?t.jsx(De,{...i.muiTextFieldProps,fullWidth:!0,type:l,disabled:e.disabledFields.includes(a),label:d(),value:n[a],onChange:t=>{let i=null;""!=t.target.value&&(i="number"===l&&co(t.target.value)?Number(t.target.value):t.target.value),o.setValue(a,i),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,i)},sx:{"& .MuiInputBase-root":{height:`${i?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...i?.formProps?.style,display:e.hiddenFields.includes(a)?"none":void 0},error:null!=o.formState.errors[a],helperText:o?.formState?.errors[a]?.message?.toString()}):"date"===i?.fieldType?t.jsx(Ve,{format:i?.dateFormat||je,sx:i?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),label:d(),onChangeCallBack:t=>{o.setValue(a,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t)},value:n[a],error:null!=o.formState.errors[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):"datetime"===i?.fieldType?t.jsx(ze,{format:i?.dateFormat||Ge,sx:i?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),label:d(),onChangeCallBack:t=>{o.setValue(a,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t)},value:n[a],error:null!=o.formState.errors[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):"checkbox"===i?.fieldType?t.jsx(Be,{label:d(),onChangeCallBack:t=>{o.setValue(a,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t)},value:n[a],checkedValue:i?.checkedValue||!0,unCheckedValue:i?.unCheckedValue||!1,disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),sx:i?.formProps?.style}):"combobox"===i?.fieldType?t.jsx(qe,{sx:i?.formProps?.style||{width:"100%"},label:d(),commonStoreKey:i?.commonStoreKey,dataQueryId:i?.dataQueryId,storeUrl:i?.storeUrl,storeLoadParam:i?.storeLoadParam,disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),onChangeCallBack:(t,i)=>{let s=null;t&&(s=t),o.setValue(a,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t,i)},options:i?.options||[],displayField:i?.optionDisplayField||"",valueField:i?.optionValueField||"",value:n[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):"lookup"===i?.fieldType?t.jsx(Qe,{sx:i?.formProps?.style||{width:"100%"},label:d(),disabled:e.disabledFields.includes(a),hidden:e.hiddenFields.includes(a),onChangeCallBack:(t,i)=>{let s=null;t&&(s=t),o.setValue(a,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(n,r,o,a,t,i)},lookupType:i.lookupType,value:n[a],errorMessage:o?.formState?.errors[a]?.message?.toString()}):null})}return t.jsx(t.Fragment,{})},fo=e=>{const i=we(),{ConfirmationWindow:o,setOpen:r}=be({body:e?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{e?.actionFn(e?.record)}});return null==e?.authority||i.isUserAuthorized(e.authority)?t.jsxs(t.Fragment,{children:[t.jsx(o,{}),t.jsxs(s.Button,{variant:e?.formActionProps?.actionButtonVariant,color:e?.formActionProps?.actionButtonColor,onClick:()=>{if(e?.actionFn){if(e?.preActionValidation&&!e.preActionValidation(e.record))return;!0===e?.isConfirmationRequired?r(!0):e?.actionFn(e.record)}},children:[e?.icon?t.jsx(m.FontAwesomeIcon,{icon:e.icon,style:{marginRight:5,marginLeft:5}}):t.jsx(t.Fragment,{}),t.jsx("div",{children:e?.label})]})]}):t.jsx(t.Fragment,{})},go=e=>{const{t:i}=y.useTranslation();return t.jsx(t.Fragment,{children:t.jsxs(s.Grid2,{container:!0,sx:e?.style,alignItems:"flex-start",children:[e?.label?t.jsx(s.Grid2,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:e?.icon?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:e.icon,style:{marginRight:5,marginLeft:5}}),t.jsx("div",{children:i(e.label)})]}):t.jsx(t.Fragment,{children:i(e.label)})}):t.jsx(t.Fragment,{}),e?.elements?e.elements.map(i=>"group"===i.type?t.jsx(go,{...i.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===i.type&&"props"===i.mode?t.jsx(mo,{fieldInfo:i.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===i.type&&"node"===i.mode?t.jsx(s.Grid2,{size:i?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:t.jsx(i.node,{formManager:e.formManager,formValues:e.formValues,formActions:e.formActions})}):void 0):null,e?.actions?t.jsx(s.Grid2,{size:{sm:12},sx:{padding:1},children:e.actions.map(i=>t.jsx(fo,{...i,record:e.formValues}))}):t.jsx(t.Fragment,{})]})})},To=e=>{const o=i.useSelector(e=>e.AppInfo.value.apiBaseUrl),[r,n]=d.useState(null);return d.useEffect(()=>{e?.refKey&&(()=>{let t=o+"/api/v1/attachment/";e?.attachmentId?t+="download?attachmentId="+e.attachmentId:(t+=`downloadImage?attachmentCode=${e.attachmentCode}&refKey=${e.refKey}`,e?.category&&(t+=`&category=${e.category}`)),n(t)})()},[e.refKey]),e?.showAsAvatar?t.jsx(s.Avatar,{sx:e.style,onError:()=>{n(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:r}):t.jsx("img",{src:r,loading:"lazy",alt:"image",onError:()=>{n(e?.onErrorImage?e.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Ao=e=>{const{handleGetRequest:i,handleDeleteRequest:o}=Re(),{isUserAuthorized:r}=we();let n=!0;e?.downloadAuthorityKey&&(n=r(e.downloadAuthorityKey));const{ConfirmationWindow:a,setOpen:l}=be({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await o({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey,attachmentId:e.id},successCallBkFn:t=>{e.setAttachmentConfig(t.data)},showMask:!0})})()}});return t.jsxs(t.Fragment,{children:[t.jsx(a,{}),t.jsxs(N,{sx:{width:300,border:"0.5px solid gray"},children:[t.jsx(U,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:e?.docType.toLocaleLowerCase().includes("image")?t.jsx(To,{attachmentId:e.id}):t.jsx(m.FontAwesomeIcon,{icon:"file",size:"3x"})}),t.jsxs(k,{children:[t.jsx(F,{gutterBottom:!0,variant:"h6",component:"div",children:e.fileName}),t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${e?.attachmentSize||"unknown"} kb`}),t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${e?.category||"NA"}`}),t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:e.remark})]}),t.jsxs(D,{children:[e?.allowDelete?t.jsx(s.IconButton,{size:"small",onClick:()=>{l(!0)},children:t.jsx(s.Tooltip,{title:"Delete Attachment",children:t.jsx(m.FontAwesomeIcon,{icon:"trash"})})}):t.jsx(t.Fragment,{}),t.jsx("div",{style:{flex:1}}),n?t.jsx(s.IconButton,{size:"small",onClick:async()=>{await i({endPointURI:"api/v1/attachment/download",parameters:{attachmentId:e.id},showMask:!0,responseType:"blob",successCallBkFn:t=>{const i=window.URL.createObjectURL(new Blob([t.data])),o=document.createElement("a");o.href=i,o.setAttribute("download",e.fileName),document.body.appendChild(o),o.click(),o.remove()}})},children:t.jsx(s.Tooltip,{title:"Download Attachment",children:t.jsx(m.FontAwesomeIcon,{icon:"download"})})}):t.jsx(t.Fragment,{})]})]})]})},yo=e=>{const{handleUploadRequest:i,handleGetRequest:o}=Re(),[r,n]=d.useState(null),[a,l]=d.useState([]),[c,u]=d.useState(null),[p,h]=d.useState(null),[f,T]=d.useState([]),[A,y]=d.useState(null),{isUserAuthorized:I}=we(),_=e=>e.split(".").pop()?.toLowerCase()||"";d.useEffect(()=>{(async()=>{await o({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey},successCallBkFn:e=>{y(e.data)}})})()},[e.refKey,e.attachmentCode]),d.useEffect(()=>{if(T(A?.allowedFileTypes?A.allowedFileTypes.split(","):[]),A?.attachmentCategories){const e=[];for(const t of A.attachmentCategories.split(","))e.push({value:t});l(e)}else l([])},[A]);let E=!0;A?.downloadAuthorityKey&&!I(A?.downloadAuthorityKey)&&(E=!1);let O=!0;return!1===e?.enableAttachment&&(O=!1),A?.uploadAuthorityKey&&!I(A.uploadAuthorityKey)&&(O=!1),t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",width:"100%",minHeight:400,alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[O?t.jsx(t.Fragment,{children:null==A?.maxAllowedNumberOfFiles||A?.maxAllowedNumberOfFiles>A.refKeyAttachments.length?t.jsxs(t.Fragment,{children:[t.jsxs("h3",{children:[t.jsx(m.FontAwesomeIcon,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),t.jsx("input",{type:"file",style:{margin:20},accept:A?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=_(t.name);if(f.length>0&&!f.includes(e))return void g.toast.error(e+" is not allowed")}n(e.target.files)}}),a.length>0?t.jsx(qe,{label:"Attachment Type",sx:{width:300,m:1},options:a,displayField:"value",valueField:"value",value:p,onChangeCallBack:e=>{h(e)}}):t.jsx(t.Fragment,{}),t.jsx(De,{label:"Remark",value:c,onChange:e=>u(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),t.jsx(s.Button,{sx:{m:1},variant:"contained",onClick:async()=>{let t=A?.refKeyAttachments.length||0;if(A?.maxAllowedNumberOfFiles&&r.length+t>A.maxAllowedNumberOfFiles)g.toast.error("Maximum number of attachments is "+A.maxAllowedNumberOfFiles);else if(!0===A?.isCategoryRequired&&a.length>0&&(null==p||void 0===p||""===p))g.toast.error("You must selected document type to process your request");else if(r){for(const e of r)if(e.type.startsWith("image/")){const t=600,i=1024*t;if(e.size>i)return void g.toast.error(`File ${e.name} is too large. Max allowed is ${t}KB.`)}await i({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:e.refKey,attachmentCode:e.attachmentCode,remark:c,category:p},files:r,successCallBkFn:e=>{y(e.data),n(null),h(null),u(null),g.toast.success("Your request has been process successfully")}})}else g.toast.error("You must add files to upload")},children:"Upload"})]}):t.jsx(t.Fragment,{})}):t.jsx(t.Fragment,{}),E&&A?.refKeyAttachments?.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("h3",{children:[t.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),t.jsx(s.Grid2,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:A?.refKeyAttachments.map(i=>t.jsx(s.Grid2,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:t.jsx(Ao,{...i,attachmentCode:e.attachmentCode,setAttachmentConfig:y,downloadAuthorityKey:A.downloadAuthorityKey,allowDelete:O})}))})]}):t.jsx(t.Fragment,{})]})},Io=e=>{const o=i.useSelector(e=>e.AppLayout),{t:r}=y.useTranslation();return t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",width:600,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[t.jsxs(s.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[t.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),r("WF_ACTION_HISTORY_LABEL")]}),t.jsx(s.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:e.actionHistory.map((i,r)=>t.jsx(t.Fragment,{children:t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[t.jsxs(s.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[t.jsx(s.Box,{sx:{marginBottom:.2},children:i.actionTime}),t.jsxs(F,{children:["via ",i.actionMethod]})]}),t.jsxs(s.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[t.jsx(To,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:i?.personId?i?.personId+"":void 0,style:{m:1,width:70,height:70}}),r!==e.actionHistory.length-1?t.jsx(s.Box,{sx:{marginTop:11,position:"absolute"},children:"|"}):t.jsx(t.Fragment,{})]}),t.jsxs(s.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[t.jsxs(s.Box,{sx:{width:"100%"},children:["ltr"===o.appDirection?`${i?.documentActionEnName}`:`${i?.documentActionArName}`,i?.actionComment?" - "+i.actionComment:""]}),t.jsx(s.Box,{sx:{width:"100%"},children:"ltr"===o.appDirection?`${i?.employeeEnName}`:`${i?.employeeArName}`})]})]})}))})]})},_o=e=>{const{t:i}=y.useTranslation(),o=we(),{ConfirmationWindow:r,setOpen:n}=be({body:i(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:i("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn)),e?.reloadData&&e.reloadData()}});let a=!0;if(e.authority&&(a=o.isUserAuthorized(e.authority)),a)return t.jsxs(t.Fragment,{children:[t.jsx(r,{}),t.jsxs(s.Button,{onClick:async()=>{if(e?.recordsToProcessActionOn&&e?.recordsToProcessActionOn.length>0){if(e?.preActionValidation)for(const t of e.recordsToProcessActionOn)if(!e.preActionValidation(t))return;!0===e?.isConfirmationRequired?n(!0):(await e.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn),e?.reloadData&&e.reloadData())}else g.toast.error(i("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"))},variant:e?.label?"outlined":e?.formActionProps?.actionButtonVariant?e.formActionProps.actionButtonVariant:"text",size:"small",color:e?.formActionProps?.actionButtonColor||"primary",children:[e?.icon?t.jsx(m.FontAwesomeIcon,{style:{marginRight:5,marginLeft:5},icon:e.icon}):t.jsx(t.Fragment,{}),e?.label?i(e.label):t.jsx(t.Fragment,{})]})]})},Eo=s.styled(e.QuickFilter)({display:"grid",alignItems:"center"}),Oo=s.styled(e.ToolbarButton)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",width:"min-content",height:"min-content",zIndex:1,opacity:t.expanded?0:1,pointerEvents:t.expanded?"none":"auto",transition:e.transitions.create(["opacity"])})),Co=s.styled(s.TextField)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",overflowX:"clip",width:t.expanded?260:"var(--trigger-width)",opacity:t.expanded?1:0,transition:e.transitions.create(["width","opacity"])})),No=i=>{const{t:o}=y.useTranslation(),r=we(),n=!i?.templateProps?.editAction?.authority||r.isUserAuthorized(i.templateProps.editAction.authority),a=rt(i?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},i?.templateProps?.data||[],i?.templateProps?.keyColumnName||"id");return t.jsxs(e.Toolbar,{children:[n&&"none"!=i?.templateProps?.editMode?.editMode&&(void 0===i?.templateProps?.hideCreateBtn||!1===i?.templateProps?.hideCreateBtn)?t.jsxs(s.Button,{onClick:i?.handleCreateNewRecord,children:[t.jsx(m.FontAwesomeIcon,{icon:"add",style:{marginRight:5,marginLeft:5}}),o("ADD_BTN_LABEL")]}):t.jsx(t.Fragment,{}),i?.templateProps?.rowActions?i.templateProps.rowActions.map((e,t)=>!0===e?.gridActionProps?.multiRecord?d.createElement(_o,{...e,key:t,reloadData:async()=>{i.templateProps.apiActions.reloadData(i?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:a.selectedRecordIds,recordsToProcessActionOn:a.selectedRecords}):null):t.jsx(t.Fragment,{}),t.jsx(s.Box,{sx:{flex:1,mx:.5,my:.5,padding:1},children:i?.templateProps?.tBar}),t.jsx(s.Tooltip,{title:"Columns",children:t.jsx(e.ColumnsPanelTrigger,{render:t.jsx(e.ToolbarButton,{}),children:t.jsx(e.GridViewColumnIcon,{fontSize:"small"})})}),t.jsx(s.Tooltip,{title:"Filters",children:t.jsx(e.FilterPanelTrigger,{render:(i,o)=>t.jsx(e.ToolbarButton,{...i,color:"default",children:t.jsx(s.Badge,{badgeContent:o.filterCount,color:"primary",variant:"dot",children:t.jsx(e.GridFilterListIcon,{fontSize:"small"})})})})}),i?.templateProps?.gridStateKey?t.jsx(s.Tooltip,{title:o("RESET_GRID_STATE"),children:t.jsx(s.IconButton,{onClick:i?.clearGridState,children:t.jsx(m.FontAwesomeIcon,{icon:"eraser"})})}):t.jsx(t.Fragment,{}),t.jsx(s.Divider,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),t.jsx(s.Tooltip,{title:o("EXPORT_EXECL_LABEL"),children:t.jsx(e.ExportExcel,{render:t.jsx(s.MenuItem,{}),children:t.jsx(m.FontAwesomeIcon,{icon:"file-excel",color:"green"})})}),t.jsxs(Eo,{children:[t.jsx(e.QuickFilterTrigger,{render:(e,i)=>t.jsx(s.Tooltip,{title:o("SEARCH_BTN_LABEL"),enterDelay:0,children:t.jsx(Oo,{...e,ownerState:{expanded:i.expanded},color:"default","aria-disabled":i.expanded,children:t.jsx(m.FontAwesomeIcon,{icon:"search"})})})}),t.jsx(e.QuickFilterControl,{render:({ref:i,...r},n)=>t.jsx(Co,{...r,ownerState:{expanded:n.expanded},inputRef:i,"aria-label":"Search",placeholder:`${o("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:t.jsx(s.InputAdornment,{position:"start",children:t.jsx(m.FontAwesomeIcon,{icon:"search"})}),endAdornment:n.value?t.jsx(s.InputAdornment,{position:"end",children:t.jsx(e.QuickFilterClear,{edge:"end",size:"small","aria-label":"Clear search",children:t.jsx(m.FontAwesomeIcon,{icon:"xmark"})})}):null,...r.slotProps?.input},...r.slotProps}})})]}),t.jsx(s.IconButton,{onClick:()=>{i.templateProps.apiActions.reloadData(i?.templateProps?.gridLoadParametersValues)},children:t.jsx(m.FontAwesomeIcon,{icon:"refresh"})})]})},Ro=i=>{const{t:o}=y.useTranslation(),r=we(),{ConfirmationWindow:n,setOpen:a}=be({body:o(i?.confirmationMessage||"ACTION_CONFIRMATION"),title:o("CONFIRMATION"),onConfirmationCallBk:async()=>{await(i?.actionFn(i.record)),i?.reloadData&&i.reloadData()}});let l=!0;i.authority&&(l=r.isUserAuthorized(i.authority));let d={};i?.getActionIconStyleForRecord&&(d=i.getActionIconStyleForRecord(i.record));let c=!0;i?.isActionVisibleForRecord&&(c=i?.isActionVisibleForRecord(i.record));let u=!1;if(i?.isActionDisabledForRecord&&(u=i.isActionDisabledForRecord(i.record)),l&&c)return t.jsxs(t.Fragment,{children:[t.jsx(n,{}),t.jsx(e.GridActionsCellItem,{disabled:u,icon:t.jsx(s.Tooltip,{title:i?.label?o(i.label):"",children:t.jsx(m.FontAwesomeIcon,{icon:i.icon,style:{...d,color:u?"gray":null!=d?.color?d.color:void 0}})}),showInMenu:i?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!u){if(i?.preActionValidation&&!i.preActionValidation(i.record))return;!0===i?.isConfirmationRequired?a(!0):(await i.actionFn(i.record),!0===i?.gridActionProps?.reloadGridAfterAction&&i?.reloadData&&i.reloadData())}}})]})};let bo=-1;const wo=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},So=(e,t)=>{const i=wo(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},Po=["__check__","actions"],vo=o=>{const{t:r}=y.useTranslation(),n=i.useSelector(e=>e.AppLayout),[a,l]=d.useState({}),[c,u]=d.useState(!0),{getLookupOptions:p}=(()=>{const{handleGetRequest:e}=Re(),t=i.useSelector(e=>e.AppLayout),o=async t=>{let i=[];return await e({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:t},successCallBkFn:e=>{i=e.data}}),i};return{generateLookupGridColumn:async e=>{let i=await o(e.lookupType);return{...e,options:i,displayField:"ltr"===t.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:o}})(),{Window:h,setWindowState:f}=Se({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}=Se({windowTitle:r(o.gridTitle)+" Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:()=>{o?.apiActions?.reloadData(o.gridLoadParametersValues)}}),[I,E]=d.useState([]),C=tt(o.formElements),N=[],R=d.useMemo(()=>o?.gridStateKey?wo(o.gridStateKey):{},[]);for(const e of C)!0===e?.gridProps?.hidden&&N.push(e.fieldName);let b={};if(R?.columnVisibilityModel){b=R.columnVisibilityModel;const e=Object.keys(b);for(const t of N)e.includes(t)||(b[t]=!1)}else for(const e of N)b[e]=!1;const w=i.useSelector(e=>e.AppLayout.appDirection),[S,P]=d.useState(b),[v,L]=d.useState(R.columnOrder||[]),[M,x]=d.useState(R.columnWidths||{}),[D,k]=d.useState(R.columnGroupingModel||[]);let U=R?.pinnedColumns?.left||[];U=U.filter(e=>!Po.includes(e));let F=R?.pinnedColumns?.right||[]||[];F=F.filter(e=>!Po.includes(e));const[B,q]=d.useState({left:[..."ltr"===w?Po:[],...U],right:[..."rtl"===w?Po:[],...F]}),j=we(),G=_.useNavigate(),[W,H]=d.useState(null),[Y,K]=d.useState(null),[V,z]=d.useState({}),Q=async()=>{let e=it(C,"row"===o?.editMode?.editMode||!1,r);for(let t of e)t?.lookupType&&(t.displayField="ltr"===n.appDirection?"lookupEnDisplay":"lookupArDisplay",t.options=await p(t.lookupType),t.valueField="lookupValue");E(e)},[$,Z]=d.useState({ids:new Set,type:"include"});let J="id";o?.keyColumnName&&(J=o?.keyColumnName);const X=o.setData;let ee=null;ee=o?.validationSchema?o.validationSchema:O.z.object(ot(C));let te=!0;o?.editAction?.authority&&(te=j.isUserAuthorized(o.editAction.authority));let ie=!0;o?.deleteAction?.authority&&(ie=j.isUserAuthorized(o.deleteAction.authority));const{ConfirmationWindow:oe,setOpen:re}=be({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let e=!0;W&&!0===W?.isNew||(e=await o.apiActions.deleteRecordById(W[J])),e&&(o?.deleteAction?.postActionCallBack&&await o.deleteAction.postActionCallBack(W),X(e=>e.filter(e=>e[J]!=W[J])))}});let ne,ae,se,le,de,ce;"modal"===o?.editMode?.editMode&&(ne=o?.editMode?.specs?.modalHeight||"fit-content",ae=o?.editMode?.specs?.modalWidth||"300",se=o?.editMode?.specs?.modalMinHeight,le=o?.editMode?.specs?.modalMinWidth,de=o?.editMode?.specs?.modalIcon||"window",ce=o?.editMode?.specs?.modalTitle||"Record Form");const{Window:ue,setWindowState:pe}=Se({height:ne,minHeight:se,minWidth:le,onCloseCallBack:()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},width:ae,windowIcon:de,windowTitle:ce}),he={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:i=>{const n=i.row,a=[];if("none"!=o?.editMode?.editMode&&(void 0===o?.disableDefaultAction||!o.disableDefaultAction)){const i=V[n[J]]?.mode===e.GridRowModes.Edit;if("row"===o.editMode.editMode&&i)te&&(a.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(m.FontAwesomeIcon,{icon:"save"}),label:r("SAVE_BTN_LABEL"),onClick:()=>{(t=>{const i=t[J];z({...V,[i]:{mode:e.GridRowModes.View}})})(n)}})),a.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(m.FontAwesomeIcon,{icon:"cancel"}),label:r("CANCEL_BTN_LABEL"),onClick:()=>{(t=>{const i=t[J];i&&lo(i)&&i<0?(z({...V,[i]:{mode:e.GridRowModes.View,ignoreModifications:!0}}),X(e=>{const t=e.filter(e=>e[J]!=i);return t})):z({...V,[i]:{mode:e.GridRowModes.View,ignoreModifications:!0}})})(n)},color:"inherit"})));else{if(o?.editAction&&!0===o?.editAction?.isEnabled){let i=!0;o?.editAction?.isActionVisibleForRecord&&(i=o?.editAction?.isActionVisibleForRecord(n));let l=!1;o?.editAction?.isActionDisabledForRecord&&(l=o?.editAction?.isActionDisabledForRecord(n)),te&&i&&a.push(t.jsx(e.GridActionsCellItem,{disabled:l,icon:t.jsx(s.Tooltip,{title:r("EDIT_BTN_LABEL"),children:t.jsx(m.FontAwesomeIcon,{icon:"edit",style:{color:l?"gray":void 0}})}),showInMenu:o?.editAction?.gridActionProps?.showInMenu||!1,label:r("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{te&&!l&&(async t=>{if(t)if(K(t),"form"===o.editMode.editMode)G(o.editMode.specs.formRoute+"/"+t[J]);else if("modal"===o.editMode.editMode)pe(!0);else if("row"===o?.editMode?.editMode){const i=t[J];z({...V,[i]:{mode:e.GridRowModes.Edit}})}})(n)}}))}if(o?.deleteAction&&!0===o?.deleteAction?.isEnabled){let i=!0;o?.deleteAction?.isActionVisibleForRecord&&(i=o?.deleteAction?.isActionVisibleForRecord(n));let l=!1;o?.deleteAction?.isActionDisabledForRecord&&(l=o?.deleteAction?.isActionDisabledForRecord(n)),ie&&i&&a.push(t.jsx(e.GridActionsCellItem,{disabled:l,icon:t.jsx(s.Tooltip,{title:r("DELETE_BTN_LABEL"),children:t.jsx(m.FontAwesomeIcon,{icon:"trash",style:{color:l?"gray":void 0}})}),showInMenu:o?.deleteAction?.gridActionProps?.showInMenu||!1,label:r("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(ie&&!l){if(o?.deleteAction?.preActionValidation&&!o.deleteAction.preActionValidation(n))return;H(n),re(!0)}}}))}}}if(n[o?.keyColumnName||"id"]&&n[o?.keyColumnName||"id"]>0&&o?.attachment&&a?.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(s.Tooltip,{title:"Attachments",children:t.jsx(m.FontAwesomeIcon,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{l(n),u(!o?.attachment?.enableAttachFn||o.attachment.enableAttachFn(n)),f(!0)}})),n[o?.keyColumnName||"id"]&&n[o?.keyColumnName||"id"]>0&&o?.workFlowDocumentCode&&a?.push(t.jsx(e.GridActionsCellItem,{icon:t.jsx(s.Tooltip,{title:"Approvals",children:t.jsx(m.FontAwesomeIcon,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{l(n),A(!0)}})),n[o?.keyColumnName||"id"]&&n[o?.keyColumnName||"id"]>0&&o?.rowActions)for(const e of o.rowActions)e?.gridActionProps?.multiRecord&&!0===e?.gridActionProps?.multiRecord||a.push(t.jsx(Ro,{...e,record:n,reloadData:async()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)}}));return a}};let me=[];(void 0===o?.disableDefaultAction||!o.disableDefaultAction||o?.rowActions&&o?.rowActions.length>0)&&me.push(he),me=[...me,...I];d.useEffect(()=>{void 0!==o?.autoLoad&&!0!==o.autoLoad||o.apiActions.reloadData(o?.gridLoadParametersValues),Q()},[]),d.useEffect(()=>{o.apiActions.reloadData(o?.gridLoadParametersValues)},[j.UserInfo?.currentOrganization]),d.useEffect(()=>{Q()},[w,o.formElements]);const fe=d.useMemo(()=>{const e=me.map(e=>({...e}));if(v.length){const t=new Map(e.map(e=>[e.field,e]));return v.map(e=>t.get(e)).filter(Boolean)}return e},[v,M,me]);return t.jsxs(t.Fragment,{children:[t.jsx(oe,{}),"modal"===o?.editMode?.editMode?t.jsx(ue,{children:o?.editMode?.specs?.formComponent?t.jsx(o.editMode.specs.formComponent,{recordIdToEdit:Y?Y[J]:void 0,formCloseCallBk:()=>{pe(!1),o.apiActions.reloadData(o?.gridLoadParametersValues)}}):t.jsx(Uo,{keyColumnName:o.keyColumnName,attachment:o.attachment,formValuesChangeCallBk:o?.formProps?.formValuesChangeCallBk,recordIdToEdit:Y?Y[J]:void 0,formCloseCallBk:()=>{pe(!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})}):t.jsx(t.Fragment,{}),void 0!==o?.hideInfoBar||o?.hideInfoBar?t.jsx(t.Fragment,{}):t.jsxs(s.Box,{sx:{display:"flex"},children:[void 0!==o?.hideBackButton||o?.hideBackButton?t.jsx(t.Fragment,{}):t.jsx(s.IconButton,{onClick:()=>{G(-1,{replace:!0})},children:t.jsx(m.FontAwesomeIcon,{icon:"ltr"===w?"arrow-left":"arrow-right"})}),t.jsxs(s.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[o?.girdIcon?t.jsx(m.FontAwesomeIcon,{icon:o.girdIcon,style:{marginRight:5,marginLeft:5}}):t.jsx(t.Fragment,{}),t.jsx(s.Typography,{variant:"h5",children:o?.gridTitle?uo(r(o?.gridTitle)):""})]})]}),o?.gridLoadParameters&&o?.gridLoadParameters.length>0&&o?.gridLoadParametersValues&&o?.setGridLoadParametersValues?t.jsxs(s.Accordion,{defaultExpanded:!0,sx:{width:"100%"},children:[t.jsx(s.AccordionSummary,{expandIcon:t.jsx(e.GridExpandMoreIcon,{}),children:t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),t.jsx(s.Typography,{component:"span",children:"Filters"})]})}),t.jsx(s.AccordionDetails,{children:t.jsx(s.Box,{children:t.jsx(Uo,{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})})})]}):t.jsx(t.Fragment,{}),o?.attachment?t.jsx(h,{children:t.jsx(yo,{attachmentCode:o.attachment.attachmentCode,refKey:a[o?.keyColumnName||"id"],enableAttachment:c})}):t.jsx(t.Fragment,{}),o?.workFlowDocumentCode?t.jsx(T,{children:t.jsx(ko,{workFlowDocumentCode:o.workFlowDocumentCode,refDocumentId:a[o?.keyColumnName||"id"],postActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)},cancelActionCallBk:()=>{A(!1),o.apiActions.reloadData(o.gridLoadParametersValues)}})}):t.jsx(t.Fragment,{}),t.jsx(e.DataGridPremium,{...o?.muiProps,slots:{toolbar:No},slotProps:{toolbar:{templateProps:{...o,rowSelectionModel:$,data:o?.data},handleCreateNewRecord:()=>{if("form"===o?.editMode?.editMode)G(o.editMode.specs.formRoute);else if("modal"===o?.editMode?.editMode)K(null),pe(!0);else if("row"===o?.editMode?.editMode){bo-=1;const t={};t[J]=bo,t.isNew=!0;for(const e of I)"actions"!=e?.type&&e?.field!=J&&e?.field&&(t[e.field]=null);X(e=>[t,...e]),z(t=>({...t,[bo]:{mode:e.GridRowModes.Edit}}))}},clearGridState:()=>{o?.gridStateKey&&localStorage.removeItem(o.gridStateKey),P({}),L([]),x({}),k([]),q({left:[..."ltr"===w?Po:[]],right:[..."rtl"===w?Po:[]]})}}},getRowId:e=>e[J],showToolbar:!0,rows:o?.data,columns:fe,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==o.editMode.editMode?V:void 0,onRowModesModelChange:"row"==o.editMode.editMode?e=>{z(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async e=>{if("row"===o.editMode.editMode){let i=null;const r=(e=>{try{ee.parse(e)}catch(e){console.log("validateRecord err",e);let t=null;return t=e instanceof O.z.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",t}})(e);if(r){const e=r.split(",");throw g.toast.error(t.jsx("div",{style:{},children:e.map(e=>t.jsxs(t.Fragment,{children:[t.jsx("div",{children:e}),t.jsx(s.Divider,{})]}))})),new Error(r)}if(o?.editAction?.preActionValidation&&!o.editAction.preActionValidation(e))throw new Error("error on the configured presave validation");const n={...e};if(e[J]&&lo(e[J])&&Number(e[J])<0&&(n[J]=null),i=await o.apiActions.saveRecord(n),null==i)throw new Error("Failed to process your request, contact your administrator");return o?.editAction?.postActionCallBack&&await o.editAction.postActionCallBack(e),!0===e?.isNew&&X(t=>{const o=t.filter(t=>t[J]!==e[J]);return[i,...o]}),!0===o?.editMode?.reloadAfterSave&&o?.apiActions?.reloadData&&o?.apiActions?.reloadData(o?.gridLoadParametersValues),i}},rowSelectionModel:$,onRowSelectionModelChange:e=>{Z(e)},columnVisibilityModel:S,onColumnVisibilityModelChange:e=>{P(e),o?.gridStateKey&&So(o.gridStateKey,{columnVisibilityModel:e})},onColumnOrderChange:e=>{const{column:t,targetIndex:i}=e;L(e=>{const r=e.length?[...e]:me.map(e=>e.field),n=r.indexOf(t.field);return-1===n||(r.splice(n,1),r.splice(i,0,t.field),o?.gridStateKey&&So(o.gridStateKey,{columnOrder:r})),r})},rowGroupingModel:D,onRowGroupingModelChange:e=>{(e=>{k(e),o?.gridStateKey&&So(o.gridStateKey,{columnGroupingModel:e})})(e)},sx:{width:"100%"}})]})},Lo=e=>{if(0===e.length)return[];const t=[];for(const i of Object.keys(e[0])){const e={type:"field",mode:"props",props:{fieldLabel:i,fieldName:i,fieldType:"text"}};t.push(e)}return t},Mo=e=>{const[i,o]=d.useState([]);return d.useEffect(()=>{const t=e.reportData.map((e,t)=>({...e,report_record_data_key:t}));o(t)},[e.reportData]),t.jsx(vo,{data:i,disableDefaultAction:!0,setData:e.setReportData,formElements:Lo(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()=>{}}})},xo=e=>{const[i,o]=d.useState({...e?.initialParameterValues}),r=((e,t)=>{const i=[];for(const o of e){const e={type:"field",mode:"props",props:{fieldLabel:o?.parameterLabel,fieldName:o?.parameterCode,fieldType:o?.parameterType,hidden:o?.hidden,formProps:{fieldSize:{lg:4,md:6,sm:12}},required:o?.mandatory,defaultValue:t[o?.parameterCode]||o?.defaultValue}};i.push(e)}return i})(e.parameters,i);return{ParameterPanel:({searchBtnClickCallBk:e})=>{const{t:i}=y.useTranslation();return t.jsxs(s.Accordion,{defaultExpanded:!0,sx:{width:"100%"},children:[t.jsx(s.AccordionSummary,{expandIcon:t.jsx(m.FontAwesomeIcon,{icon:{prefix:"far",iconName:"square-caret-down"}}),children:t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),t.jsx(s.Typography,{component:"span",children:"Filters"})]})}),t.jsx(s.AccordionDetails,{children:t.jsx(s.Box,{children:t.jsx(Uo,{saveButtonSpecs:{label:i("Filter"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:i("RESET_BTN_LABEL"),icon:"eraser",hidden:!0,actionButtonVariant:"outlined",actionButtonColor:"error"},actions:[{label:i("RESET_BTN_LABEL"),icon:"eraser",isIdRequired:!1,formActionProps:{enabled:!0},actionFn:async(e,t)=>{o({})}}],apiActions:{deleteRecordById:async()=>!0,saveRecord:async t=>{o(null!=t?t:{}),e&&await e(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:r})})})]})},parametersValues:i,setParametersValues:o,panelElements:r}},Do=e=>{const[i,o]=d.useState(null),[r,n]=d.useState(null),[a,l]=d.useState([]),[c,u]=d.useState("WAITING_REPORT_CODE"),{handleGetRequest:p,handlePostRequest:h,HandleDownloadHTTPPostPDF:f}=Re(),[g,T]=d.useState(null),{ParameterPanel:A,parametersValues:y,panelElements:I,setParametersValues:_}=xo({parameters:g?.reportParameters||[],initialParameterValues:{...e?.reportParametersValues}});d.useEffect(()=>{g&&(!0===e?.byPassParameterEntry||0==g.reportParameters.length?(E(y),u("WAITING_RESULT")):u("WAITING_PARAMETER_INPUT"))},[g]);const E=async t=>{u("WAITING_RESULT"),"Excel"===g?.reportType?await h({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{u("SHOWING_RESULT"),l(e.data)}}):g?.reportType&&await f({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{u("SHOWING_RESULT");const t=e.headers["content-disposition"];let i="downloaded_file";if(t&&-1!==t.indexOf("filename=")){const e=t.match(/filename="?([^"]+)"?/);e&&e[1]&&(i=e[1])}if(i.includes("pdf")){const t=new Blob([e.data],{type:"application/pdf"}),i=URL.createObjectURL(t);o(i)}else{const t=new Blob([e.data],{type:e.headers["content-type"]}),o=window.URL.createObjectURL(t),r=document.createElement("a");r.href=o,r.download=i,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(o)}},failureCallBkFn:e=>{n("Failed To run report ... contact your administrator"),u("ERROR")}})};return d.useEffect(()=>{e?.reportCode&&(async()=>{u("LOADING_METADATA"),await p({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:e.reportCode},successCallBkFn:e=>{T(e.data)},failureCallBkFn:e=>{n("Failed loading report metadata ... contact your administrator"),u("ERROR")}})})()},[e.reportCode,e.byPassParameterEntry,e.reportParametersValues,e.jasperOutPutFileType,e.resultMode]),t.jsxs(t.Fragment,{children:[t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[t.jsxs(s.Box,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[t.jsx(m.FontAwesomeIcon,{icon:"Excel"===g?.reportType?"file-excel":"file-pdf",color:"Excel"===g?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),g?.reportName]}),"Excel"!=g?.reportType&&"SHOWING_RESULT"===c?t.jsxs(t.Fragment,{children:[!0===e?.byPassParameterEntry?t.jsx(t.Fragment,{}):g?.reportParameters.length>0?t.jsx(s.IconButton,{onClick:()=>{u("WAITING_PARAMETER_INPUT")},children:t.jsx(m.FontAwesomeIcon,{icon:"filter"})}):t.jsx(t.Fragment,{}),t.jsx(s.IconButton,{children:t.jsx(m.FontAwesomeIcon,{icon:"refresh",onClick:()=>{E(y)}})})]}):t.jsx(t.Fragment,{})]}),t.jsx(s.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===c&&"Excel"!=g?.reportType?t.jsx(A,{searchBtnClickCallBk:E}):"SHOWING_RESULT"===c||("WAITING_PARAMETER_INPUT"===c||"WAITING_RESULT"===c)&&"Excel"===g?.reportType?"Excel"===g?.reportType?t.jsx(Mo,{reportData:a,setReportData:l,reloadReport:async()=>{E(y)},gridLoadParameters:I,gridLoadParametersValues:y,setGridLoadParametersValues:_}):t.jsx("iframe",{src:i,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===c?t.jsxs(s.Box,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[t.jsx(m.FontAwesomeIcon,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),r]}):t.jsx(t.Fragment,{})})]})},ko=e=>{const o=_.useNavigate(),r=i.useSelector(e=>e.AppLayout),{isUserAuthorized:n,UserInfo:a}=we(),{handleGetRequest:l,handlePostRequest:c}=Re(),[u,p]=d.useState(null),[h,f]=d.useState([]),{t:T}=y.useTranslation(),[A,I]=d.useState(null),[E,O]=d.useState({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:C,setWindowState:N}=Se({windowTitle:"ltr"===r.appDirection?E?.workflowDocument&&E?.referencedDocument?`${E?.workflowDocument?.documentEnName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`:"Document":E?.workflowDocument&&E?.referencedDocument?`${E?.workflowDocument?.documentArName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),R=async()=>{await l({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:e.workFlowDocumentCode,refDocumentId:e.refDocumentId},successCallBkFn:e=>{O(structuredClone(e.data))},failureCallBkFn:()=>{O({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},b=async()=>{await c({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:E?.workflowDocument?.id,refDocumentId:e.refDocumentId,actionId:u.id,refDocumentStatus:E?.workflowDocumentStatus?.documentStatusCode,actionComment:A},successCallBkFn:async t=>{u?.post_action_endpoint?await c({endPointURI:u.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:u.id},successCallBkFn:()=>{R(),e?.postActionCallBk&&e.postActionCallBk()}}):R()}})};return d.useEffect(()=>{e.refDocumentId&&e.workFlowDocumentCode&&R()},[e.refDocumentId,e.workFlowDocumentCode]),d.useEffect(()=>{f(E?.nextActions&&E?.nextActions?.length>0?E.nextActions.filter(e=>{if(!E?.workflowDocumentStatus?.nextActionTakersAuthority&&!E?.nextActionTakers)return!0;if(E?.workflowDocumentStatus?.nextActionTakersAuthority&&n(E.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(E?.nextActionTakers)for(const e of E.nextActionTakers)if(a?.username===e?.username||a?.username===e?.USERNAME)return!0;return!1}):[])},[E.nextActions,E.nextActionTakers]),t.jsxs(t.Fragment,{children:[E?.workflowDocumentReport?.id?t.jsx(C,{children:t.jsx(Do,{reportCode:E?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:e.refDocumentId+""}})}):t.jsx(t.Fragment,{}),E?.workflowDocument?t.jsxs(s.Box,{sx:{width:"100%",maxWidth:600,textAlign:"center",fontSize:16,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(s.IconButton,{onClick:()=>{o(-1,{replace:!0})},children:t.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),t.jsx(s.Box,{sx:{flex:1}}),t.jsx(m.FontAwesomeIcon,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===r.appDirection?`${E?.workflowDocument?.documentEnName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`:`${E?.workflowDocument?.documentArName} # ${E?.referencedDocument[E?.workflowDocument?.documentNumberField]}`,E?.workflowDocumentStatus?"ltr"===r.appDirection?` ( ${E?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${E?.workflowDocumentStatus?.documentStatusArName} )`:"",t.jsx(s.Box,{sx:{flex:1}}),E?.workflowDocumentReport?.id?t.jsx(s.Button,{onClick:()=>{N(!0)},variant:"outlined",startIcon:t.jsx(m.FontAwesomeIcon,{icon:"eye"}),children:T("VIEW_LABEL")}):t.jsx(t.Fragment,{})]}):t.jsx(t.Fragment,{}),t.jsxs(s.Box,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[h?.length>0?t.jsxs(s.Paper,{sx:{padding:2,display:"flex",margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[t.jsx(qe,{sx:{marginBottom:2,width:400},label:T("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===r.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:u?.id,options:h,onChangeCallBack:(e,t)=>{p(t)}}),t.jsx(De,{sx:{width:400},rows:3,value:A,onChange:e=>{I(e.target.value)},multiline:!0,label:T("WF_COMMENT_LABEL")}),t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(s.Button,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=u&&null!=u?.id?!0!==u.require_comment&&1!==u.require_comment&&"true"!==u.require_comment||null!==A&&""!==A?u?.pre_action_endpoint?await c({endPointURI:u.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:u.id},successCallBkFn:()=>{b()}}):b():g.toast.error("You must enter comment for the action to be processed"):g.toast.error("You must select action to process")},children:T("WF_TAKE_ACTION_BTN_LABEL")}),e?.cancelActionCallBk?t.jsx(s.Button,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{e?.cancelActionCallBk&&e.cancelActionCallBk()},children:T("WF_CANCEL_BTN_LABEL")}):t.jsx(t.Fragment,{})]}),E?.nextActionTakers&&E.nextActionTakers.length>0?t.jsxs(t.Fragment,{children:[t.jsx(s.Divider,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:t.jsxs(s.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[t.jsx(m.FontAwesomeIcon,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",T("WF_WAITING_FOR_LABEL")]})}),t.jsx(s.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:E.nextActionTakers.map(e=>t.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[t.jsx(To,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:e?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),t.jsxs(s.Box,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[t.jsx("div",{children:"ltr"===r.appDirection?e?.employee_en_name:e?.employee_ar_name}),t.jsx("div",{children:e?.email?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),e?.email]}):t.jsx(t.Fragment,{})}),t.jsx("div",{children:e?.mobile_number?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),e?.mobile_number]}):t.jsx(t.Fragment,{})})]})]}))})]}):t.jsx(t.Fragment,{})]}):t.jsx(t.Fragment,{}),E?.actionsHistory.length>0?t.jsx(Io,{actionHistory:E.actionsHistory}):t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",width:600,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[t.jsxs(s.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[t.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),T("WF_ACTION_HISTORY_LABEL")]}),t.jsx(s.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},Uo=e=>{const{Window:i,setWindowState:o}=Se({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[r,n]=d.useState(!0),{t:a}=y.useTranslation(),l=tt(e.elements),[c,u]=d.useState([]),[p,h]=d.useState([]),f={};for(const t of e.elements)"field"===t?.type&&"props"===t?.mode&&t?.props?.defaultValue&&(f[t.props.fieldName]=t.props.defaultValue);let T=null;T=e?.validationSchema?e.validationSchema:ue.object(ot(l));const A=I.useForm({resolver:E.zodResolver(T),defaultValues:f}),O=A.watch(),C=_.useParams(),N=e?.formRouteRecordIdParamName,R=async()=>{let t=null;if(e?.recordIdToEdit?t=e.recordIdToEdit:N&&C[N]&&(t=C[N]),t){const i=await e.apiActions.loadRecordById(t);if(i){A.reset({...i}),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk({...i},S,A);for(const e of l)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?A.setValue(e.fieldName,i[e.fieldName]+""):A.setValue(e.fieldName,i[e.fieldName]))}}else A.reset({}),e.formValuesChangeCallBk(O,S,A)},{Window:b,setWindowState:w}=Se({windowTitle:"Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:async()=>{await R()}}),S={setFieldValue:(e,t)=>{A.setValue(e,t)},hideField:e=>{h(t=>[...t,e])},showField:e=>{h(t=>t.filter(t=>t!==e))},disableField:e=>{u(t=>[...t,e])},enableField:e=>{u(t=>t.filter(t=>t!==e))}};return d.useEffect(()=>{const e=[],t=[];for(const i of l)i?.hidden&&e.push(i.fieldName),i?.disabled&&t.push(i.fieldName);h(e),u(t)},[e.elements]),d.useEffect(()=>{R()},[e?.recordIdToEdit]),d.useEffect(()=>{n(!e?.attachment||!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(O))},[O]),t.jsxs(t.Fragment,{children:[e?.attachment?t.jsx(i,{children:t.jsx(yo,{attachmentCode:e.attachment.attachmentCode,refKey:O[e?.keyColumnName||"id"],enableAttachment:r})}):t.jsx(t.Fragment,{}),e?.workFlowDocumentCode?t.jsx(b,{children:t.jsx(ko,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:O[e?.keyColumnName||"id"],postActionCallBk:()=>{w(!1),R()},cancelActionCallBk:()=>{w(!1),R()}})}):t.jsx(t.Fragment,{}),t.jsx(so,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:t.jsx(s.Grid2,{sx:{width:"100%"},container:!0,children:e.elements.map((i,o)=>"group"===i.type?t.jsx(go,{...i.props,formManager:A,formValues:O,formActions:S,hiddenFields:p,disabledFields:c,formValuesChangeCallBk:e.formValuesChangeCallBk},o):"field"===i.type&&"props"===i.mode?t.jsx(mo,{fieldInfo:i.props,formManager:A,formValues:O,formActions:S,hiddenFields:p,disabledFields:c,formValuesChangeCallBk:e.formValuesChangeCallBk},o):"field"===i.type&&"node"===i.mode?t.jsx(s.Grid2,{size:i?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:t.jsx(i.node,{formManager:A,formValues:O})},o):void 0)})}),t.jsxs(so,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[O[e?.keyColumnName||"id"]&&e?.attachment?t.jsx(s.Tooltip,{title:"Attachments",children:t.jsx(s.IconButton,{onClick:()=>{o(!0)},children:t.jsx(m.FontAwesomeIcon,{icon:"paperclip"})})}):null,O[e?.keyColumnName||"id"]&&e?.workFlowDocumentCode?t.jsx(s.Tooltip,{title:"Approvals",children:t.jsx(s.IconButton,{onClick:()=>{w(!0)},children:t.jsx(m.FontAwesomeIcon,{icon:"stamp"})})}):null,e?.actions?e.actions.map(i=>!1===i?.isIdRequired?t.jsx(fo,{...i,record:O}):O[e?.keyColumnName||"id"]?!0===i?.formActionProps?.enabled?t.jsx(fo,{...i,record:O}):t.jsx(t.Fragment,{}):void 0):t.jsx(t.Fragment,{}),t.jsx("div",{style:{flex:1}}),e?.saveButtonSpecs?.hidden?t.jsx(t.Fragment,{}):t.jsx(s.Button,{variant:e?.saveButtonSpecs?.actionButtonVariant?e.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:e?.saveButtonSpecs?.icon?t.jsx(m.FontAwesomeIcon,{icon:e.saveButtonSpecs.icon}):null,color:e?.saveButtonSpecs?.actionButtonColor?e.saveButtonSpecs.actionButtonColor:"primary",onClick:A.handleSubmit(t=>{(async t=>{if((!e?.preSaveValidation||e.preSaveValidation(t))&&t){const i=await e.apiActions.saveRecord(t);i&&(A.reset({...i}),e?.formSavedSuccessfullyCallBk&&e.formSavedSuccessfullyCallBk(i),e?.formCloseCallBk&&e.formCloseCallBk())}})(t)},e=>{g.toast.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:a(e?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),e?.cancelButtonSpecs?.hidden?t.jsx(t.Fragment,{}):t.jsx(s.Button,{variant:e?.cancelButtonSpecs?.actionButtonVariant?e.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:e?.cancelButtonSpecs?.icon?t.jsx(m.FontAwesomeIcon,{icon:e.cancelButtonSpecs.icon}):null,color:e?.cancelButtonSpecs?.actionButtonColor?e.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{e?.formCloseCallBk&&e.formCloseCallBk(),A.reset(f)},children:a(e?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},Fo=()=>{const{workflowDocumentCode:e,refDocumentId:i}=_.useParams();return t.jsx(ko,{workFlowDocumentCode:e,refDocumentId:i})},Bo=e=>t.jsx(j.BarChart,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),qo=e=>t.jsxs(s.Paper,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[t.jsx(s.Box,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:t.jsx("div",{children:e.record[e.valueField]})}),t.jsx(s.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]})]}),jo=e=>t.jsxs(t.Fragment,{children:[t.jsx(s.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),t.jsx(j.Gauge,{width:200,height:200,value:e.record[e.valueField],valueMax:e.total})]}),Go=e=>t.jsx(j.LineChart,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function Wo(e){return t.jsxs(W,{sx:{display:"flex",alignItems:"center"},children:[t.jsx(W,{sx:{width:"100%",mr:1},children:t.jsx(G,{variant:"determinate",...e})}),t.jsx(W,{sx:{minWidth:35},children:t.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(e.value)}%`})})]})}const Ho=e=>t.jsxs(W,{sx:{width:"100%"},children:[t.jsx(F,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),t.jsx(Wo,{value:e.record[e.valueField]/e.total*100})]}),Yo=e=>{const i=e.data.map((t,i)=>({id:i,value:t[e.valueField],label:t[e.labelField]+""}));return t.jsx(H.PieChart,{series:[{data:i}]})},Ko=e=>{const[i,o]=d.useState(!0),[r,n]=d.useState([]),{handleGetRequest:a}=Re();d.useEffect(()=>{e.loadWidget?(async()=>{o(!0),await a({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e.parameterValues},successCallBkFn:e=>{o(!1),n(e.data)},failureCallBkFn:()=>{o(!1),n([])}})})():o(!1)},[e.loadWidget,e.loadCounter]);let l=0;if(1==r.length)l=100;else if("CircularProgress"===e.widgetType||"LinearProgress"===e.widgetType)for(const t of r)l+=t[e.verticalAxisField];return t.jsxs(t.Fragment,{children:["LineChart"===e.widgetType||"PieChart"===e.widgetType||"ColumnChart"===e.widgetType?t.jsxs(s.Box,{children:[t.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:e?.icon||"chart-pie"}),e?.title]}):t.jsx(t.Fragment,{}),t.jsx(s.Box,{sx:{flex:1,padding:1,height:"90%",display:"flex",alignItems:"center",justifyContent:"center",width:"90%"},children:i?t.jsxs(t.Fragment,{children:[t.jsx(m.FontAwesomeIcon,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),t.jsx("div",{children:"Loading"})]}):"ColumnChart"===e.widgetType?t.jsx(Bo,{data:r,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===e.widgetType?t.jsx(Go,{data:r,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===e.widgetType?t.jsx(Yo,{data:r,widgetTitle:e.title,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,widgetType:"Pie"}):t.jsxs(s.Grid2,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[t.jsx(s.Grid2,{size:{xs:12},sx:{textAlign:"center"},children:e.title}),r.map((i,o)=>"Card"===e.widgetType?t.jsx(s.Grid2,{size:{md:3,xs:12},children:t.jsx(qo,{widgetTitle:"",record:i,labelField:e.horizontalAxisField,valueField:e.verticalAxisField},o)}):"CircularProgress"===e.widgetType?t.jsx(s.Grid2,{size:{md:3,xs:12},children:t.jsx(jo,{widgetTitle:"",record:i,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:l},o)}):"LinearProgress"===e.widgetType?t.jsx(s.Grid2,{size:{md:3,xs:12},children:t.jsx(Ho,{widgetTitle:"",record:i,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:l},o)}):void 0)]})})]})},Vo=e=>{const[i,o]=d.useState({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),{ParameterPanel:r,parametersValues:n}=xo({parameters:i?.dashboardParameters||[],initialParameterValues:{}}),[a,l]=d.useState(0),[c,u]=d.useState(!1);d.useEffect(()=>{if(null!=i.dashboardCode&&null!=i.dashboardCode&&""!=i.dashboardCode){u(!1);let e=!0;if(i?.dashboardParameters.length>0)for(const t of i?.dashboardParameters)if(!0===t?.mandatory&&(void 0===n[t.parameterCode]||null===n[t.parameterCode]||""===n[t.parameterCode])){e=!1;break}e&&u(e),l(a+1)}},[i?.dashboardParameters,n]);const p=_.useNavigate(),{handleGetRequest:h,handlePostRequest:f}=Re();return d.useEffect(()=>{e.dashboardCode&&(async()=>{await h({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:e.dashboardCode},successCallBkFn:e=>{o(e.data)},failureCallBkFn:()=>{o(null)}})})()},[e.dashboardCode,e.parameters]),t.jsx(t.Fragment,{children:i?t.jsxs(t.Fragment,{children:[t.jsxs(s.Box,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx(s.IconButton,{onClick:()=>{p(-1,{replace:!0})},children:t.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),t.jsx(s.Box,{sx:{flex:1}}),t.jsx(m.FontAwesomeIcon,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),t.jsx(s.Box,{children:i?.dashboardTitle}),t.jsx(s.Box,{sx:{flex:1}})]}),i?.dashboardParameters.length>0?t.jsx(r,{searchBtnClickCallBk:async e=>{l(a+1)}}):t.jsx(t.Fragment,{}),t.jsx(s.Grid2,{container:!0,spacing:1,sx:{height:"fit-content",overflowY:"auto",padding:1},children:i?.widgets.map((e,i)=>t.jsx(s.Grid2,{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:t.jsx(Ko,{...e,parameterValues:n,loadWidget:c})},i))})]}):t.jsx(s.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},zo=()=>{const{dashboardCode:e}=_.useParams();return t.jsx(Vo,{dashboardCode:e})},Qo=e=>{const{UserSession:o}=we(),r=i.useSelector(e=>e.AppLayout),n=i.useDispatch(),{handlePostRequest:a}=Re(),[l,c]=d.useState(o.value.currentOrganization.id);return t.jsxs(s.Box,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[t.jsx(qe,{sx:{width:"100%"},displayField:"ltr"===r.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:o.value.userOrganizations,value:l,onChangeCallBack:e=>{c(e)}}),t.jsx(s.Button,{sx:{m:1},variant:"contained",disabled:null==l||l===o.value.currentOrganization.id,onClick:async()=>{await a({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:o.value.username,orgId:l},data:{},successCallBkFn:t=>{const i={...t.data,isAuthenticated:!0};n(Ce.setAuthenticated(i)),e.successChangeCallBackFn&&e.successChangeCallBackFn()}})},children:"Change Organization"})]})},$o=f.createSlice({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Zo,setSideBarState:Jo}=$o.actions;var Xo=$o.reducer;function er(e,t){const i=d.useRef(e);d.useEffect(()=>{i.current=e},[e]),d.useEffect(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const tr=s.keyframes`
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; }