@asaleh37/ui-base 25.12.171 → 25.12.173

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.mjs CHANGED
@@ -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=St(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})(Er),a=ue.forwardRef(function(e,a){const s=function(e=Nr){return Cr(e)}(i),{className:l,component:d="div",...c}=Rr(e);return g(n,{as:d,ref:a,className:vr(l,r?r(o):o),theme:t&&s[t]||s,...c})});return a}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=Lr[t];return o?`${i}-${o}`:`${wr.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:wr.generate});function Mr(e){return/^\d+$/.test(e)}function Dr(e){return"number"==typeof e&&!isNaN(e)}function kr(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function Ur(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function xr(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function Fr(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&&(Sr.propTypes={children:no.node,component:no.elementType,sx:no.oneOfType([no.arrayOf(no.oneOfType([no.func,no.object,no.bool])),no.func,no.object])});const Br=(e,t)=>t?it(e).format(t):it(e).format(pi),qr=(e,t)=>t?it(e,t).toDate():it(e,pi).toDate(),Wr=e=>{if(e?.fieldInfo){const t=e.fieldInfo,i=e?.formManager||null,o=e?.formActions||null,r=e?.formValues||null,n=e?.fieldInfo?.fieldName||null,a=e?.fieldInfo?.fieldType||null;if(!(t&&i&&r&&n&&a))return g(T,{});const s=()=>e?.fieldInfo?.formProps?.fieldLabelFn?e.fieldInfo.formProps.fieldLabelFn(r):e?.fieldInfo?.fieldLabel?e?.fieldInfo?.fieldLabel:void 0;return e.hiddenFields.includes(n)?g(T,{}):g(B,{size:t?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===a||"number"===a?g(ni,{...t.muiTextFieldProps,fullWidth:!0,type:a,disabled:e.disabledFields.includes(n),label:s(),value:r[n],onChange:t=>{let s=null;""!=t.target.value&&(s="number"===a&&kr(t.target.value)?Number(t.target.value):t.target.value),i.setValue(n,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,s)},sx:{"& .MuiInputBase-root":{height:`${t?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...t?.formProps?.style,display:e.hiddenFields.includes(n)?"none":void 0},error:null!=i.formState.errors[n],helperText:i?.formState?.errors[n]?.message?.toString()}):"date"===t?.fieldType?g(Ti,{format:t?.dateFormat||pi,sx:t?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),label:s(),onChangeCallBack:t=>{i.setValue(n,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t)},value:r[n],error:null!=i.formState.errors[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):"datetime"===t?.fieldType?g(yi,{format:t?.dateFormat||ui,sx:t?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),label:s(),onChangeCallBack:t=>{i.setValue(n,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t)},value:r[n],error:null!=i.formState.errors[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):"checkbox"===t?.fieldType?g(di,{label:s(),onChangeCallBack:t=>{i.setValue(n,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t)},value:r[n],checkedValue:t?.checkedValue||!0,unCheckedValue:t?.unCheckedValue||!1,disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),sx:t?.formProps?.style}):"combobox"===t?.fieldType?g(ci,{sx:t?.formProps?.style||{width:"100%"},label:s(),commonStoreKey:t?.commonStoreKey,dataQueryId:t?.dataQueryId,storeUrl:t?.storeUrl,storeLoadParam:t?.storeLoadParam,disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),onChangeCallBack:(t,a)=>{let s=null;t&&(s=t),i.setValue(n,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t,a)},options:t?.options||[],displayField:t?.optionDisplayField||"",valueField:t?.optionValueField||"",value:r[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):"lookup"===t?.fieldType?g(Ai,{sx:t?.formProps?.style||{width:"100%"},label:s(),disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),onChangeCallBack:(t,a)=>{let s=null;t&&(s=t),i.setValue(n,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t,a)},lookupType:t.lookupType,value:r[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):null})}return g(T,{})},Gr=e=>{const t=Zt(),{ConfirmationWindow:i,setOpen:o}=jt({body:e?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{e?.actionFn(e?.record)}});return null==e?.authority||t.isUserAuthorized(e.authority)?f(T,{children:[g(i,{}),f(v,{variant:e?.formActionProps?.actionButtonVariant,color:e?.formActionProps?.actionButtonColor,onClick:()=>{if(e?.actionFn){if(e?.preActionValidation&&!e.preActionValidation(e.record))return;!0===e?.isConfirmationRequired?o(!0):e?.actionFn(e.record)}},children:[e?.icon?g(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}):g(T,{}),g("div",{children:e?.label})]})]}):g(T,{})},Hr=e=>{const{t:t}=Me();return g(T,{children:f(B,{container:!0,sx:e?.style,alignItems:"flex-start",children:[e?.label?g(B,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:e?.icon?f(T,{children:[g(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}),g("div",{children:t(e.label)})]}):g(T,{children:t(e.label)})}):g(T,{}),e?.elements?e.elements.map(t=>"group"===t.type?g(Hr,{...t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===t.type&&"props"===t.mode?g(Wr,{fieldInfo:t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===t.type&&"node"===t.mode?g(B,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:g(t.node,{formManager:e.formManager,formValues:e.formValues,formActions:e.formActions})}):void 0):null,e?.actions?g(B,{size:{sm:12},sx:{padding:1},children:e.actions.map(t=>g(Gr,{...t,record:e.formValues}))}):g(T,{})]})})},Yr=e=>{const t=A(e=>e.AppInfo.value.apiBaseUrl),[i,o]=me(null);return fe(()=>{e?.refKey&&(()=>{let i=t+"/api/v1/attachment/";e?.attachmentId?i+="download?attachmentId="+e.attachmentId:(i+=`downloadImage?attachmentCode=${e.attachmentCode}&refKey=${e.refKey}`,e?.category&&(i+=`&category=${e.category}`)),o(i)})()},[e.refKey]),e?.showAsAvatar?g(K,{sx:e.style,onError:()=>{o(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:i}):g("img",{src:i,loading:"lazy",alt:"image",onError:()=>{o(e?.onErrorImage?e.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Kr=e=>{const{handleGetRequest:t,handleDeleteRequest:i}=$t(),{isUserAuthorized:o}=Zt();let r=!0;e?.downloadAuthorityKey&&(r=o(e.downloadAuthorityKey));const{ConfirmationWindow:n,setOpen:a}=jt({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await i({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey,attachmentId:e.id},successCallBkFn:t=>{e.setAttachmentConfig(t.data)},showMask:!0})})()}});return f(T,{children:[g(n,{}),f(Ke,{sx:{width:300,border:"0.5px solid gray"},children:[g(nt,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:e?.docType.toLocaleLowerCase().includes("image")?g(Yr,{attachmentId:e.id}):g(Re,{icon:"file",size:"3x"})}),f(rt,{children:[g(at,{gutterBottom:!0,variant:"h6",component:"div",children:e.fileName}),g(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${e?.attachmentSize||"unknown"} kb`}),g(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${e?.category||"NA"}`}),g(at,{variant:"body2",sx:{color:"text.secondary"},children:e.remark})]}),f(ot,{children:[e?.allowDelete?g(U,{size:"small",onClick:()=>{a(!0)},children:g(V,{title:"Delete Attachment",children:g(Re,{icon:"trash"})})}):g(T,{}),g("div",{style:{flex:1}}),r?g(U,{size:"small",onClick:async()=>{await t({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:g(V,{title:"Download Attachment",children:g(Re,{icon:"download"})})}):g(T,{})]})]})]})},Vr=e=>{const{handleUploadRequest:t,handleGetRequest:i}=$t(),[o,r]=me(null),[n,a]=me([]),[s,l]=me(null),[d,c]=me(null),[p,u]=me([]),[h,m]=me(null),{isUserAuthorized:y}=Zt(),A=e=>e.split(".").pop()?.toLowerCase()||"";fe(()=>{(async()=>{await i({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey},successCallBkFn:e=>{m(e.data)}})})()},[e.refKey,e.attachmentCode]),fe(()=>{if(u(h?.allowedFileTypes?h.allowedFileTypes.split(","):[]),h?.attachmentCategories){const e=[];for(const t of h.attachmentCategories.split(","))e.push({value:t});a(e)}else a([])},[h]);let I=!0;h?.downloadAuthorityKey&&!y(h?.downloadAuthorityKey)&&(I=!1);let _=!0;return!1===e?.enableAttachment&&(_=!1),h?.uploadAuthorityKey&&!y(h.uploadAuthorityKey)&&(_=!1),f(x,{sx:{display:"flex",flexDirection:"column",width:"100%",minHeight:400,alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[g(T,_?{children:null==h?.maxAllowedNumberOfFiles||h?.maxAllowedNumberOfFiles>h.refKeyAttachments.length?f(T,{children:[f("h3",{children:[g(Re,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),g("input",{type:"file",style:{margin:20},accept:h?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=A(t.name);if(p.length>0&&!p.includes(e))return void Pe.error(e+" is not allowed")}r(e.target.files)}}),n.length>0?g(ci,{label:"Attachment Type",sx:{width:300,m:1},options:n,displayField:"value",valueField:"value",value:d,onChangeCallBack:e=>{c(e)}}):g(T,{}),g(ni,{label:"Remark",value:s,onChange:e=>l(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),g(v,{sx:{m:1},variant:"contained",onClick:async()=>{let i=h?.refKeyAttachments.length||0;if(h?.maxAllowedNumberOfFiles&&o.length+i>h.maxAllowedNumberOfFiles)Pe.error("Maximum number of attachments is "+h.maxAllowedNumberOfFiles);else if(!0===h?.isCategoryRequired&&n.length>0&&(null==d||void 0===d||""===d))Pe.error("You must selected document type to process your request");else if(o){for(const e of o)if(e.type.startsWith("image/")){const t=600,i=1024*t;if(e.size>i)return void Pe.error(`File ${e.name} is too large. Max allowed is ${t}KB.`)}await t({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:e.refKey,attachmentCode:e.attachmentCode,remark:s,category:d},files:o,successCallBkFn:e=>{m(e.data),r(null),c(null),l(null),Pe.success("Your request has been process successfully")}})}else Pe.error("You must add files to upload")},children:"Upload"})]}):g(T,{})}:{}),I&&h?.refKeyAttachments?.length>0?f(T,{children:[f("h3",{children:[g(Re,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),g(B,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:h?.refKeyAttachments.map(t=>g(B,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:g(Kr,{...t,attachmentCode:e.attachmentCode,setAttachmentConfig:m,downloadAuthorityKey:h.downloadAuthorityKey,allowDelete:_})}))})]}):g(T,{})]})},zr=e=>{const t=A(e=>e.AppLayout),{t:i}=Me();return f(x,{sx:{display:"flex",flexDirection:"column",width:600,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[f(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[g(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),i("WF_ACTION_HISTORY_LABEL")]}),g(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:e.actionHistory.map((i,o)=>g(T,{children:f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[f(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[g(S,{sx:{marginBottom:.2},children:i.actionTime}),f(at,{children:["via ",i.actionMethod]})]}),f(S,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[g(Yr,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:i?.personId?i?.personId+"":void 0,style:{m:1,width:70,height:70}}),o!==e.actionHistory.length-1?g(S,{sx:{marginTop:11,position:"absolute"},children:"|"}):g(T,{})]}),f(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[f(S,{sx:{width:"100%"},children:["ltr"===t.appDirection?`${i?.documentActionEnName}`:`${i?.documentActionArName}`,i?.actionComment?" - "+i.actionComment:""]}),g(S,{sx:{width:"100%"},children:"ltr"===t.appDirection?`${i?.employeeEnName}`:`${i?.employeeArName}`})]})]})}))})]})},Qr=e=>{const{t:t}=Me(),i=Zt(),{ConfirmationWindow:o,setOpen:r}=jt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn)),e?.reloadData&&e.reloadData()}});let n=!0;if(e.authority&&(n=i.isUserAuthorized(e.authority)),n)return f(T,{children:[g(o,{}),f(v,{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?r(!0):(await e.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn),e?.reloadData&&e.reloadData())}else Pe.error(t("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?g(Re,{style:{marginRight:5,marginLeft:5},icon:e.icon}):g(T,{}),e?.label?t(e.label):g(T,{})]})]})},$r=z(e)({display:"grid",alignItems:"center"}),jr=z(t)(({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"])})),Zr=z(F)(({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"])})),Jr=e=>{const{t:p}=Me(),u=Zt(),h=!e?.templateProps?.editAction?.authority||u.isUserAuthorized(e.templateProps.editAction.authority),m=wi(e?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},e?.templateProps?.data||[],e?.templateProps?.keyColumnName||"id");return f(i,{children:[h&&"none"!=e?.templateProps?.editMode?.editMode&&(void 0===e?.templateProps?.hideCreateBtn||!1===e?.templateProps?.hideCreateBtn)?f(v,{onClick:e?.handleCreateNewRecord,children:[g(Re,{icon:"add",style:{marginRight:5,marginLeft:5}}),p("ADD_BTN_LABEL")]}):g(T,{}),e?.templateProps?.rowActions?e.templateProps.rowActions.map((t,i)=>!0===t?.gridActionProps?.multiRecord?ge(Qr,{...t,key:i,reloadData:async()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:m.selectedRecordIds,recordsToProcessActionOn:m.selectedRecords}):null):g(T,{}),g(S,{sx:{flex:1,mx:.5,my:.5,padding:1},children:e?.templateProps?.tBar}),g(V,{title:"Columns",children:g(o,{render:g(t,{}),children:g(r,{fontSize:"small"})})}),g(V,{title:"Filters",children:g(n,{render:(e,i)=>g(t,{...e,color:"default",children:g(Q,{badgeContent:i.filterCount,color:"primary",variant:"dot",children:g(a,{fontSize:"small"})})})})}),e?.templateProps?.gridStateKey?g(V,{title:p("RESET_GRID_STATE"),children:g(U,{onClick:e?.clearGridState,children:g(Re,{icon:"eraser"})})}):g(T,{}),g($,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),g(V,{title:p("EXPORT_EXECL_LABEL"),children:g(s,{render:g(j,{}),children:g(Re,{icon:"file-excel",color:"green"})})}),f($r,{children:[g(l,{render:(e,t)=>g(V,{title:p("SEARCH_BTN_LABEL"),enterDelay:0,children:g(jr,{...e,ownerState:{expanded:t.expanded},color:"default","aria-disabled":t.expanded,children:g(Re,{icon:"search"})})})}),g(d,{render:({ref:e,...t},i)=>g(Zr,{...t,ownerState:{expanded:i.expanded},inputRef:e,"aria-label":"Search",placeholder:`${p("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:g(Z,{position:"start",children:g(Re,{icon:"search"})}),endAdornment:i.value?g(Z,{position:"end",children:g(c,{edge:"end",size:"small","aria-label":"Clear search",children:g(Re,{icon:"xmark"})})}):null,...t.slotProps?.input},...t.slotProps}})})]}),g(U,{onClick:()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},children:g(Re,{icon:"refresh"})})]})},Xr=e=>{const{t:t}=Me(),i=Zt(),{ConfirmationWindow:o,setOpen:r}=jt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.record)),e?.reloadData&&e.reloadData()}});let n=!0;e.authority&&(n=i.isUserAuthorized(e.authority));let a={};e?.getActionIconStyleForRecord&&(a=e.getActionIconStyleForRecord(e.record));let s=!0;e?.isActionVisibleForRecord&&(s=e?.isActionVisibleForRecord(e.record));let l=!1;if(e?.isActionDisabledForRecord&&(l=e.isActionDisabledForRecord(e.record)),n&&s)return f(T,{children:[g(o,{}),g(p,{disabled:l,icon:g(V,{title:e?.label?t(e.label):"",children:g(Re,{icon:e.icon,style:{...a,color:l?"gray":null!=a?.color?a.color:void 0}})}),showInMenu:e?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!l){if(e?.preActionValidation&&!e.preActionValidation(e.record))return;!0===e?.isConfirmationRequired?r(!0):(await e.actionFn(e.record),!0===e?.gridActionProps?.reloadGridAfterAction&&e?.reloadData&&e.reloadData())}}})]})};let en=-1;const tn=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},on=(e,t)=>{const i=tn(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},rn=["__check__","actions"],nn=e=>{const{t:t}=Me(),{handleGetRequest:i}=$t(),o=A(e=>e.commonStores.stores),r=A(e=>e.AppLayout),[n,a]=me({}),[s,l]=me(!0),{getLookupOptions:d}=(()=>{const{handleGetRequest:e}=$t(),t=A(e=>e.AppLayout),i=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 o=await i(e.lookupType);return{...e,options:o,displayField:"ltr"===t.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:i}})(),{Window:c,setWindowState:y}=Jt({windowTitle:t(e.gridTitle)+" Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"50%",onCloseCallBack:()=>{e?.apiActions?.reloadData(e.gridLoadParametersValues)}}),{Window:I,setWindowState:_}=Jt({windowTitle:t(e.gridTitle)+" Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:()=>{e?.apiActions?.reloadData(e.gridLoadParametersValues)}}),[E,O]=me([]),C=Ni(e.formElements),N=[],R=he.useMemo(()=>e?.gridStateKey?tn(e.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=A(e=>e.AppLayout.appDirection),[P,v]=he.useState(b),[L,M]=he.useState(R.columnOrder||[]),[D,x]=he.useState(R.columnWidths||{}),[F,B]=me(R.columnGroupingModel||[]);let q=R?.pinnedColumns?.left||[];q=q.filter(e=>!rn.includes(e));let W=R?.pinnedColumns?.right||[]||[];W=W.filter(e=>!rn.includes(e));const[G,H]=me({left:[..."ltr"===w?rn:[],...q],right:[..."rtl"===w?rn:[],...W]}),Y=Zt(),K=Ue(),[z,Q]=me(null),[j,Z]=me(null),[te,ie]=me({}),oe=async(e,t,o)=>{let r=[];return e?await i({endPointURI:e,showMask:!1,parameters:t,successCallBkFn:e=>{r=e.data}}):o&&await i({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:o,...t},successCallBkFn:e=>{r=e.data}}),r},re=async()=>{let i=Ri(C,"row"===e?.editMode?.editMode||!1,t);for(let e of i)if(e?.lookupType&&(e.displayField="ltr"===r.appDirection?"lookupEnDisplay":"lookupArDisplay",e.options=await d(e.lookupType),e.valueField="lookupValue"),"custom"===e.type){if(e?.options)continue;e.options=e?.commonStoreKey?o[e.commonStoreKey]?.data||[]:await oe(e?.storeUrl,e?.storeLoadParam,e?.dataQueryId)}O(i)},[ne,ae]=me({ids:new Set,type:"include"});let se="id";e?.keyColumnName&&(se=e?.keyColumnName);const le=e.setData;let de=null;de=e?.validationSchema?e.validationSchema:He.object(bi(C));let ce=!0;e?.editAction?.authority&&(ce=Y.isUserAuthorized(e.editAction.authority));let pe=!0;e?.deleteAction?.authority&&(pe=Y.isUserAuthorized(e.deleteAction.authority));const{ConfirmationWindow:ue,setOpen:ge}=jt({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let t=!0;z&&!0===z?.isNew||(t=await e.apiActions.deleteRecordById(z[se])),t&&(e?.deleteAction?.postActionCallBack&&await e.deleteAction.postActionCallBack(z),le(e=>e.filter(e=>e[se]!=z[se])))}});let Te,ye,Ae,Ie,_e,Ee;"modal"===e?.editMode?.editMode&&(Te=e?.editMode?.specs?.modalHeight||"fit-content",ye=e?.editMode?.specs?.modalWidth||"300",Ae=e?.editMode?.specs?.modalMinHeight,Ie=e?.editMode?.specs?.modalMinWidth,_e=e?.editMode?.specs?.modalIcon||"window",Ee=e?.editMode?.specs?.modalTitle||"Record Form");const{Window:Oe,setWindowState:Ce}=Jt({height:Te,minHeight:Ae,minWidth:Ie,onCloseCallBack:()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},width:ye,windowIcon:_e,windowTitle:Ee}),Ne={type:"actions",field:"actions",headerName:"",headerAlign:"center",width:(e?.rowActions?30*e.rowActions.length:0)+(e?.editAction&&e?.editAction?.isEnabled?30:0)+(e?.deleteAction&&e?.deleteAction?.isEnabled?30:0)+(e?.attachment?30:0)+(e?.workFlowDocumentCode?30:0),getActions:i=>{const o=i.row,r=[];if("none"!=e?.editMode?.editMode&&(void 0===e?.disableDefaultAction||!e.disableDefaultAction)){const i=te[o[se]]?.mode===m.Edit;if("row"===e.editMode.editMode&&i)ce&&(r.push(g(p,{icon:g(Re,{icon:"save"}),label:t("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const t=e[se];ie({...te,[t]:{mode:m.View}})})(o)}})),r.push(g(p,{icon:g(Re,{icon:"cancel"}),label:t("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const t=e[se];t&&Dr(t)&&t<0?(ie({...te,[t]:{mode:m.View,ignoreModifications:!0}}),le(e=>{const i=e.filter(e=>e[se]!=t);return i})):ie({...te,[t]:{mode:m.View,ignoreModifications:!0}})})(o)},color:"inherit"})));else{if(e?.editAction&&!0===e?.editAction?.isEnabled){let i=!0;e?.editAction?.isActionVisibleForRecord&&(i=e?.editAction?.isActionVisibleForRecord(o));let n=!1;e?.editAction?.isActionDisabledForRecord&&(n=e?.editAction?.isActionDisabledForRecord(o)),ce&&i&&r.push(g(p,{disabled:n,icon:g(V,{title:t("EDIT_BTN_LABEL"),children:g(Re,{icon:"edit",style:{color:n?"gray":void 0}})}),showInMenu:e?.editAction?.gridActionProps?.showInMenu||!1,label:t("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{ce&&!n&&(async t=>{if(t)if(Z(t),"form"===e.editMode.editMode)K(e.editMode.specs.formRoute+"/"+t[se]);else if("modal"===e.editMode.editMode)Ce(!0);else if("row"===e?.editMode?.editMode){const e=t[se];ie({...te,[e]:{mode:m.Edit}})}})(o)}}))}if(e?.deleteAction&&!0===e?.deleteAction?.isEnabled){let i=!0;e?.deleteAction?.isActionVisibleForRecord&&(i=e?.deleteAction?.isActionVisibleForRecord(o));let n=!1;e?.deleteAction?.isActionDisabledForRecord&&(n=e?.deleteAction?.isActionDisabledForRecord(o)),pe&&i&&r.push(g(p,{disabled:n,icon:g(V,{title:t("DELETE_BTN_LABEL"),children:g(Re,{icon:"trash",style:{color:n?"gray":void 0}})}),showInMenu:e?.deleteAction?.gridActionProps?.showInMenu||!1,label:t("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(pe&&!n){if(e?.deleteAction?.preActionValidation&&!e.deleteAction.preActionValidation(o))return;Q(o),ge(!0)}}}))}}}if(o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.attachment&&r?.push(g(p,{icon:g(V,{title:"Attachments",children:g(Re,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{a(o),l(!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(o)),y(!0)}})),o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.workFlowDocumentCode&&r?.push(g(p,{icon:g(V,{title:"Approvals",children:g(Re,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{a(o),_(!0)}})),o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.rowActions)for(const t of e.rowActions)t?.gridActionProps?.multiRecord&&!0===t?.gridActionProps?.multiRecord||r.push(g(Xr,{...t,record:o,reloadData:async()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)}}));return r}};let be=[];(void 0===e?.disableDefaultAction||!e.disableDefaultAction||e?.rowActions&&e?.rowActions.length>0)&&be.push(Ne),be=[...be,...E];fe(()=>{void 0!==e?.autoLoad&&!0!==e.autoLoad||e.apiActions.reloadData(e?.gridLoadParametersValues),re()},[]),fe(()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},[Y.UserInfo?.currentOrganization]),fe(()=>{re()},[w,e.formElements]);const we=he.useMemo(()=>{const e=be.map(e=>({...e}));if(L.length){const t=new Map(e.map(e=>[e.field,e]));return L.map(e=>t.get(e)).filter(Boolean)}return e},[L,D,be]);return f(T,{children:[g(ue,{}),"modal"===e?.editMode?.editMode?g(Oe,{children:e?.editMode?.specs?.formComponent?g(e.editMode.specs.formComponent,{recordIdToEdit:j?j[se]:void 0,formCloseCallBk:()=>{Ce(!1),e.apiActions.reloadData(e?.gridLoadParametersValues)}}):g(pn,{keyColumnName:e.keyColumnName,attachment:e.attachment,formValuesChangeCallBk:e?.formProps?.formValuesChangeCallBk,recordIdToEdit:j?j[se]:void 0,formCloseCallBk:()=>{Ce(!1),e.apiActions.reloadData(e?.gridLoadParametersValues)},elements:e.formElements,apiActions:e.apiActions,editAuthorityKey:e?.editAction?.authority,formSavedSuccessfullyCallBk:e?.editAction?.postActionCallBack,preSaveValidation:e?.editAction?.preActionValidation,actions:e?.rowActions})}):g(T,{}),void 0!==e?.hideInfoBar||e?.hideInfoBar?g(T,{}):f(S,{sx:{display:"flex"},children:[void 0!==e?.hideBackButton||e?.hideBackButton?g(T,{}):g(U,{onClick:()=>{K(-1,{replace:!0})},children:g(Re,{icon:"ltr"===w?"arrow-left":"arrow-right"})}),f(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[e?.girdIcon?g(Re,{icon:e.girdIcon,style:{marginRight:5,marginLeft:5}}):g(T,{}),g(k,{variant:"h5",children:e?.gridTitle?Ur(t(e?.gridTitle)):""})]})]}),e?.gridLoadParameters&&e?.gridLoadParameters.length>0&&e?.gridLoadParametersValues&&e?.setGridLoadParametersValues?f(J,{defaultExpanded:!0,sx:{width:"100%"},children:[g(X,{expandIcon:g(u,{}),children:f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[g(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),g(k,{component:"span",children:"Filters"})]})}),g(ee,{children:g(S,{children:g(pn,{saveButtonSpecs:{label:t("SEARCH_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:t("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async t=>{null!=t?e.setGridLoadParametersValues(t):e.setGridLoadParametersValues({}),e.apiActions.reloadData(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:e.gridLoadParameters})})})]}):g(T,{}),e?.attachment?g(c,{children:g(Vr,{attachmentCode:e.attachment.attachmentCode,refKey:n[e?.keyColumnName||"id"],enableAttachment:s})}):g(T,{}),e?.workFlowDocumentCode?g(I,{children:g(cn,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:n[e?.keyColumnName||"id"],postActionCallBk:()=>{_(!1),e.apiActions.reloadData(e.gridLoadParametersValues)},cancelActionCallBk:()=>{_(!1),e.apiActions.reloadData(e.gridLoadParametersValues)}})}):g(T,{}),g(h,{...e?.muiProps,slots:{toolbar:Jr},slotProps:{toolbar:{templateProps:{...e,rowSelectionModel:ne,data:e?.data},handleCreateNewRecord:()=>{if("form"===e?.editMode?.editMode)K(e.editMode.specs.formRoute);else if("modal"===e?.editMode?.editMode)Z(null),Ce(!0);else if("row"===e?.editMode?.editMode){en-=1;const e={};e[se]=en,e.isNew=!0;for(const t of E)"actions"!=t?.type&&t?.field!=se&&t?.field&&(e[t.field]=null);le(t=>[e,...t]),ie(e=>({...e,[en]:{mode:m.Edit}}))}},clearGridState:()=>{e?.gridStateKey&&localStorage.removeItem(e.gridStateKey),v({}),M([]),x({}),B([]),H({left:[..."ltr"===w?rn:[]],right:[..."rtl"===w?rn:[]]})}}},getRowId:e=>e[se],showToolbar:!0,rows:e?.data,columns:we,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==e.editMode.editMode?te:void 0,onRowModesModelChange:"row"==e.editMode.editMode?e=>{ie(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async t=>{if("row"===e.editMode.editMode){let i=null;const o=(e=>{try{de.parse(e)}catch(e){console.log("validateRecord err",e);let t=null;return t=e instanceof He.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",t}})(t);if(o){const e=o.split(",");throw Pe.error(g("div",{style:{},children:e.map(e=>f(T,{children:[g("div",{children:e}),g($,{})]}))})),new Error(o)}if(e?.editAction?.preActionValidation&&!e.editAction.preActionValidation(t))throw new Error("error on the configured presave validation");const r={...t};if(t[se]&&Dr(t[se])&&Number(t[se])<0&&(r[se]=null),i=await e.apiActions.saveRecord(r),null==i)throw new Error("Failed to process your request, contact your administrator");return e?.editAction?.postActionCallBack&&await e.editAction.postActionCallBack(t),!0===t?.isNew&&le(e=>{const o=e.filter(e=>e[se]!==t[se]);return[i,...o]}),!0===e?.editMode?.reloadAfterSave&&e?.apiActions?.reloadData&&e?.apiActions?.reloadData(e?.gridLoadParametersValues),i}},rowSelectionModel:ne,onRowSelectionModelChange:e=>{ae(e)},columnVisibilityModel:P,onColumnVisibilityModelChange:t=>{v(t),e?.gridStateKey&&on(e.gridStateKey,{columnVisibilityModel:t})},onColumnOrderChange:t=>{const{column:i,targetIndex:o}=t;M(t=>{const r=t.length?[...t]:be.map(e=>e.field),n=r.indexOf(i.field);return-1===n||(r.splice(n,1),r.splice(o,0,i.field),e?.gridStateKey&&on(e.gridStateKey,{columnOrder:r})),r})},rowGroupingModel:F,onRowGroupingModelChange:t=>{(t=>{B(t),e?.gridStateKey&&on(e.gridStateKey,{columnGroupingModel:t})})(t)},sx:{width:"100%"}})]})},an=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},sn=e=>{const[t,i]=me([]);return fe(()=>{const t=e.reportData.map((e,t)=>({...e,report_record_data_key:t}));i(t)},[e.reportData]),g(nn,{data:t,disableDefaultAction:!0,setData:e.setReportData,formElements:an(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()=>{}}})},ln=e=>{const[t,i]=me({...e?.initialParameterValues}),o=((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,t);return{ParameterPanel:({searchBtnClickCallBk:e})=>{const{t:t}=Me();return f(J,{defaultExpanded:!0,sx:{width:"100%"},children:[g(X,{expandIcon:g(Re,{icon:{prefix:"far",iconName:"square-caret-down"}}),children:f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[g(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),g(k,{component:"span",children:"Filters"})]})}),g(ee,{children:g(S,{children:g(pn,{saveButtonSpecs:{label:t("Filter"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:t("RESET_BTN_LABEL"),icon:"eraser",hidden:!0,actionButtonVariant:"outlined",actionButtonColor:"error"},actions:[{label:t("RESET_BTN_LABEL"),icon:"eraser",isIdRequired:!1,formActionProps:{enabled:!0},actionFn:async(e,t)=>{i({})}}],apiActions:{deleteRecordById:async()=>!0,saveRecord:async t=>{i(null!=t?t:{}),e&&await e(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:o})})})]})},parametersValues:t,setParametersValues:i,panelElements:o}},dn=e=>{const[t,i]=me(null),[o,r]=me(null),[n,a]=me([]),[s,l]=me("WAITING_REPORT_CODE"),{handleGetRequest:d,handlePostRequest:c,HandleDownloadHTTPPostPDF:p}=$t(),[u,h]=me(null),{ParameterPanel:m,parametersValues:y,panelElements:A,setParametersValues:I}=ln({parameters:u?.reportParameters||[],initialParameterValues:{...e?.reportParametersValues}});fe(()=>{u&&(!0===e?.byPassParameterEntry||0==u.reportParameters.length?(_(y),l("WAITING_RESULT")):l("WAITING_PARAMETER_INPUT"))},[u]);const _=async t=>{l("WAITING_RESULT"),"Excel"===u?.reportType?await c({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{l("SHOWING_RESULT"),a(e.data)}}):u?.reportType&&await p({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{l("SHOWING_RESULT");const t=e.headers["content-disposition"];let o="downloaded_file";if(t&&-1!==t.indexOf("filename=")){const e=t.match(/filename="?([^"]+)"?/);e&&e[1]&&(o=e[1])}if(o.includes("pdf")){const t=new Blob([e.data],{type:"application/pdf"}),o=URL.createObjectURL(t);i(o)}else{const t=new Blob([e.data],{type:e.headers["content-type"]}),i=window.URL.createObjectURL(t),r=document.createElement("a");r.href=i,r.download=o,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(i)}},failureCallBkFn:e=>{r("Failed To run report ... contact your administrator"),l("ERROR")}})};return fe(()=>{e?.reportCode&&(async()=>{l("LOADING_METADATA"),await d({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:e.reportCode},successCallBkFn:e=>{h(e.data)},failureCallBkFn:e=>{r("Failed loading report metadata ... contact your administrator"),l("ERROR")}})})()},[e.reportCode,e.byPassParameterEntry,e.reportParametersValues,e.jasperOutPutFileType,e.resultMode]),f(T,{children:[f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[f(S,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[g(Re,{icon:"Excel"===u?.reportType?"file-excel":"file-pdf",color:"Excel"===u?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),u?.reportName]}),"Excel"!=u?.reportType&&"SHOWING_RESULT"===s?f(T,{children:[!0===e?.byPassParameterEntry?g(T,{}):u?.reportParameters.length>0?g(U,{onClick:()=>{l("WAITING_PARAMETER_INPUT")},children:g(Re,{icon:"filter"})}):g(T,{}),g(U,{children:g(Re,{icon:"refresh",onClick:()=>{_(y)}})})]}):g(T,{})]}),g(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===s&&"Excel"!=u?.reportType?g(m,{searchBtnClickCallBk:_}):"SHOWING_RESULT"===s||("WAITING_PARAMETER_INPUT"===s||"WAITING_RESULT"===s)&&"Excel"===u?.reportType?"Excel"===u?.reportType?g(sn,{reportData:n,setReportData:a,reloadReport:async()=>{_(y)},gridLoadParameters:A,gridLoadParametersValues:y,setGridLoadParametersValues:I}):g("iframe",{src:t,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===s?f(S,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[g(Re,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),o]}):g(T,{})})]})},cn=e=>{const t=Ue(),i=A(e=>e.AppLayout),{isUserAuthorized:o,UserInfo:r}=Zt(),{handleGetRequest:n,handlePostRequest:a}=$t(),[s,l]=me(null),[d,c]=me([]),{t:p}=Me(),[u,h]=me(null),[m,y]=me({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:I,setWindowState:_}=Jt({windowTitle:"ltr"===i.appDirection?m?.workflowDocument&&m?.referencedDocument?`${m?.workflowDocument?.documentEnName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`:"Document":m?.workflowDocument&&m?.referencedDocument?`${m?.workflowDocument?.documentArName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),E=async()=>{await n({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:e.workFlowDocumentCode,refDocumentId:e.refDocumentId},successCallBkFn:e=>{y(structuredClone(e.data))},failureCallBkFn:()=>{y({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},O=async()=>{await a({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:m?.workflowDocument?.id,refDocumentId:e.refDocumentId,actionId:s.id,refDocumentStatus:m?.workflowDocumentStatus?.documentStatusCode,actionComment:u},successCallBkFn:async t=>{s?.post_action_endpoint?await a({endPointURI:s.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:s.id},successCallBkFn:()=>{E(),e?.postActionCallBk&&e.postActionCallBk()}}):E()}})};return fe(()=>{e.refDocumentId&&e.workFlowDocumentCode&&E()},[e.refDocumentId,e.workFlowDocumentCode]),fe(()=>{c(m?.nextActions&&m?.nextActions?.length>0?m.nextActions.filter(e=>{if(!m?.workflowDocumentStatus?.nextActionTakersAuthority&&!m?.nextActionTakers)return!0;if(m?.workflowDocumentStatus?.nextActionTakersAuthority&&o(m.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(m?.nextActionTakers)for(const e of m.nextActionTakers)if(r?.username==e?.username||r?.username==e?.USERNAME||r?.email==e?.email||r?.email==e?.EMAIL||r?.employeeNumber==e?.employeeNumber||r?.employeeNumber==e?.EMPLOYEE_NUMBER)return!0;return!1}):[])},[m.nextActions,m.nextActionTakers]),f(T,{children:[m?.workflowDocumentReport?.id?g(I,{children:g(dn,{reportCode:m?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:e.refDocumentId+""}})}):g(T,{}),m?.workflowDocument?f(S,{sx:{width:"100%",maxWidth:600,textAlign:"center",fontSize:16,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[g(U,{onClick:()=>{t(-1,{replace:!0})},children:g(Re,{icon:"arrow-left"})}),g(S,{sx:{flex:1}}),g(Re,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===i.appDirection?`${m?.workflowDocument?.documentEnName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`:`${m?.workflowDocument?.documentArName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`,m?.workflowDocumentStatus?"ltr"===i.appDirection?` ( ${m?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${m?.workflowDocumentStatus?.documentStatusArName} )`:"",g(S,{sx:{flex:1}}),m?.workflowDocumentReport?.id?g(v,{onClick:()=>{_(!0)},variant:"outlined",startIcon:g(Re,{icon:"eye"}),children:p("VIEW_LABEL")}):g(T,{})]}):g(T,{}),f(S,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[d?.length>0?f(x,{sx:{padding:2,display:"flex",margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[g(ci,{sx:{marginBottom:2,width:400},label:p("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===i.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:s?.id,options:d,onChangeCallBack:(e,t)=>{l(t)}}),g(ni,{sx:{width:400},rows:3,value:u,onChange:e=>{h(e.target.value)},multiline:!0,label:p("WF_COMMENT_LABEL")}),f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[g(v,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=s&&null!=s?.id?!0!==s.require_comment&&1!==s.require_comment&&"true"!==s.require_comment||null!==u&&""!==u?s?.pre_action_endpoint?await a({endPointURI:s.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:s.id},successCallBkFn:()=>{O()}}):O():Pe.error("You must enter comment for the action to be processed"):Pe.error("You must select action to process")},children:p("WF_TAKE_ACTION_BTN_LABEL")}),e?.cancelActionCallBk?g(v,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{e?.cancelActionCallBk&&e.cancelActionCallBk()},children:p("WF_CANCEL_BTN_LABEL")}):g(T,{})]}),m?.nextActionTakers&&m.nextActionTakers.length>0?f(T,{children:[g($,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:f(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[g(Re,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",p("WF_WAITING_FOR_LABEL")]})}),g(S,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:m.nextActionTakers.map(e=>f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[g(Yr,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:e?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),f(S,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[g("div",{children:"ltr"===i.appDirection?e?.employee_en_name:e?.employee_ar_name}),g("div",{children:e?.email?f(T,{children:[g(Re,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),e?.email]}):g(T,{})}),g("div",{children:e?.mobile_number?f(T,{children:[g(Re,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),e?.mobile_number]}):g(T,{})})]})]}))})]}):g(T,{})]}):g(T,{}),m?.actionsHistory.length>0?g(zr,{actionHistory:m.actionsHistory}):f(x,{sx:{display:"flex",flexDirection:"column",width:600,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[f(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[g(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),p("WF_ACTION_HISTORY_LABEL")]}),g(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},pn=e=>{const{Window:t,setWindowState:i}=Jt({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[o,r]=me(!0),{t:n}=Me(),a=Ni(e.elements),[s,l]=me([]),[d,c]=me([]),p={};for(const t of e.elements)"field"===t?.type&&"props"===t?.mode&&t?.props?.defaultValue&&(p[t.props.fieldName]=t.props.defaultValue);let u=null;u=e?.validationSchema?e.validationSchema:Ge.object(bi(a));const h=ke({resolver:We(u),defaultValues:p}),m=h.watch(),y=xe(),A=e?.formRouteRecordIdParamName,I=async()=>{let t=null;if(e?.recordIdToEdit?t=e.recordIdToEdit:A&&y[A]&&(t=y[A]),t){const i=await e.apiActions.loadRecordById(t);if(i){h.reset({...i});for(const e of a)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?h.setValue(e.fieldName,i[e.fieldName]+""):h.setValue(e.fieldName,i[e.fieldName]));e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(m,O,h)}}else h.reset({}),e.formValuesChangeCallBk(m,O,h)},{Window:_,setWindowState:E}=Jt({windowTitle:"Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:async()=>{await I()}}),O={setFieldValue:(e,t)=>{h.setValue(e,t)},hideField:e=>{c(t=>[...t,e])},showField:e=>{c(t=>t.filter(t=>t!==e))},disableField:e=>{l(t=>[...t,e])},enableField:e=>{l(t=>t.filter(t=>t!==e))}};return fe(()=>{const e=[],t=[];for(const i of a)i?.hidden&&e.push(i.fieldName),i?.disabled&&t.push(i.fieldName);c(e),l(t)},[e.elements]),fe(()=>{I()},[e?.recordIdToEdit]),fe(()=>{r(!e?.attachment||!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(m))},[m]),f(T,{children:[e?.attachment?g(t,{children:g(Vr,{attachmentCode:e.attachment.attachmentCode,refKey:m[e?.keyColumnName||"id"],enableAttachment:o})}):g(T,{}),e?.workFlowDocumentCode?g(_,{children:g(cn,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:m[e?.keyColumnName||"id"],postActionCallBk:()=>{E(!1),I()},cancelActionCallBk:()=>{E(!1),I()}})}):g(T,{}),g(Sr,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:g(B,{sx:{width:"100%"},container:!0,children:e.elements.map((t,i)=>"group"===t.type?g(Hr,{...t.props,formManager:h,formValues:m,formActions:O,hiddenFields:d,disabledFields:s,formValuesChangeCallBk:e.formValuesChangeCallBk},i):"field"===t.type&&"props"===t.mode?g(Wr,{fieldInfo:t.props,formManager:h,formValues:m,formActions:O,hiddenFields:d,disabledFields:s,formValuesChangeCallBk:e.formValuesChangeCallBk},i):"field"===t.type&&"node"===t.mode?g(B,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:g(t.node,{formManager:h,formValues:m})},i):void 0)})}),f(Sr,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[m[e?.keyColumnName||"id"]&&e?.attachment?g(V,{title:"Attachments",children:g(U,{onClick:()=>{i(!0)},children:g(Re,{icon:"paperclip"})})}):null,m[e?.keyColumnName||"id"]&&e?.workFlowDocumentCode?g(V,{title:"Approvals",children:g(U,{onClick:()=>{E(!0)},children:g(Re,{icon:"stamp"})})}):null,e?.actions?e.actions.map(t=>!1===t?.isIdRequired?g(Gr,{...t,record:m}):m[e?.keyColumnName||"id"]?!0===t?.formActionProps?.enabled?g(Gr,{...t,record:m}):g(T,{}):void 0):g(T,{}),g("div",{style:{flex:1}}),e?.saveButtonSpecs?.hidden?g(T,{}):g(v,{variant:e?.saveButtonSpecs?.actionButtonVariant?e.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:e?.saveButtonSpecs?.icon?g(Re,{icon:e.saveButtonSpecs.icon}):null,color:e?.saveButtonSpecs?.actionButtonColor?e.saveButtonSpecs.actionButtonColor:"primary",onClick:h.handleSubmit(t=>{(async t=>{if((!e?.preSaveValidation||e.preSaveValidation(t))&&t){const i=await e.apiActions.saveRecord(t);i&&(h.reset({...i}),e?.formSavedSuccessfullyCallBk&&e.formSavedSuccessfullyCallBk(i),e?.formCloseCallBk&&e.formCloseCallBk())}})(t)},e=>{Pe.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:n(e?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),e?.cancelButtonSpecs?.hidden?g(T,{}):g(v,{variant:e?.cancelButtonSpecs?.actionButtonVariant?e.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:e?.cancelButtonSpecs?.icon?g(Re,{icon:e.cancelButtonSpecs.icon}):null,color:e?.cancelButtonSpecs?.actionButtonColor?e.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{e?.formCloseCallBk&&e.formCloseCallBk(),h.reset(p)},children:n(e?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},un=()=>{const{workflowDocumentCode:e,refDocumentId:t}=xe();return g(cn,{workFlowDocumentCode:e,refDocumentId:t})},hn=e=>g(st,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),mn=e=>f(x,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[g(S,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:g("div",{children:e.record[e.valueField]})}),g(k,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]})]}),fn=e=>f(T,{children:[g(k,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),g(lt,{width:200,height:200,value:e.record[e.valueField],valueMax:e.total})]}),gn=e=>g(dt,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function Tn(e){return f(pt,{sx:{display:"flex",alignItems:"center"},children:[g(pt,{sx:{width:"100%",mr:1},children:g(ct,{variant:"determinate",...e})}),g(pt,{sx:{minWidth:35},children:g(at,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(e.value)}%`})})]})}const yn=e=>f(pt,{sx:{width:"100%"},children:[g(at,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),g(Tn,{value:e.record[e.valueField]/e.total*100})]}),An=e=>{const t=e.data.map((t,i)=>({id:i,value:t[e.valueField],label:t[e.labelField]+""}));return g(ut,{series:[{data:t}]})},In=e=>{const[t,i]=me(!0),[o,r]=me([]),{handleGetRequest:n}=$t();fe(()=>{e.loadWidget?(async()=>{i(!0),await n({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e.parameterValues},successCallBkFn:e=>{i(!1),r(e.data)},failureCallBkFn:()=>{i(!1),r([])}})})():i(!1)},[e.loadWidget,e.loadCounter]);let a=0;if(1==o.length)a=100;else if("CircularProgress"===e.widgetType||"LinearProgress"===e.widgetType)for(const t of o)a+=t[e.verticalAxisField];return f(T,{children:["LineChart"===e.widgetType||"PieChart"===e.widgetType||"ColumnChart"===e.widgetType?f(S,{children:[g(Re,{style:{marginRight:10,marginLeft:10},icon:e?.icon||"chart-pie"}),e?.title]}):g(T,{}),g(S,{sx:{flex:1,padding:1,height:"90%",display:"flex",alignItems:"center",justifyContent:"center",width:"90%"},children:t?f(T,{children:[g(Re,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),g("div",{children:"Loading"})]}):"ColumnChart"===e.widgetType?g(hn,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===e.widgetType?g(gn,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===e.widgetType?g(An,{data:o,widgetTitle:e.title,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,widgetType:"Pie"}):f(B,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[g(B,{size:{xs:12},sx:{textAlign:"center"},children:e.title}),o.map((t,i)=>"Card"===e.widgetType?g(B,{size:{md:3,xs:12},children:g(mn,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField},i)}):"CircularProgress"===e.widgetType?g(B,{size:{md:3,xs:12},children:g(fn,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:a},i)}):"LinearProgress"===e.widgetType?g(B,{size:{md:3,xs:12},children:g(yn,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:a},i)}):void 0)]})})]})},_n=e=>{const[t,i]=me({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),{ParameterPanel:o,parametersValues:r}=ln({parameters:t?.dashboardParameters||[],initialParameterValues:{}}),[n,a]=me(0),[s,l]=me(!1);fe(()=>{if(null!=t.dashboardCode&&null!=t.dashboardCode&&""!=t.dashboardCode){l(!1);let e=!0;if(t?.dashboardParameters.length>0)for(const i of t?.dashboardParameters)if(!0===i?.mandatory&&(void 0===r[i.parameterCode]||null===r[i.parameterCode]||""===r[i.parameterCode])){e=!1;break}e&&l(e),a(n+1)}},[t?.dashboardParameters,r]);const d=Ue(),{handleGetRequest:c,handlePostRequest:p}=$t();return fe(()=>{e.dashboardCode&&(async()=>{await c({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:e.dashboardCode},successCallBkFn:e=>{i(e.data)},failureCallBkFn:()=>{i(null)}})})()},[e.dashboardCode,e.parameters]),g(T,{children:t?f(T,{children:[f(S,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[g(U,{onClick:()=>{d(-1,{replace:!0})},children:g(Re,{icon:"arrow-left"})}),g(S,{sx:{flex:1}}),g(Re,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),g(S,{children:t?.dashboardTitle}),g(S,{sx:{flex:1}})]}),t?.dashboardParameters.length>0?g(o,{searchBtnClickCallBk:async e=>{a(n+1)}}):g(T,{}),g(B,{container:!0,spacing:1,sx:{height:"fit-content",overflowY:"auto",padding:1},children:t?.widgets.map((e,t)=>g(B,{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:g(In,{...e,parameterValues:r,loadWidget:s})},t))})]}):g(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},En=()=>{const{dashboardCode:e}=xe();return g(_n,{dashboardCode:e})},On=e=>{const{UserSession:t}=Zt(),i=A(e=>e.AppLayout),o=y(),{handlePostRequest:r}=$t(),[n,a]=me(t.value.currentOrganization.id);return f(S,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[g(ci,{sx:{width:"100%"},displayField:"ltr"===i.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:t.value.userOrganizations,value:n,onChangeCallBack:e=>{a(e)}}),g(v,{sx:{m:1},variant:"contained",disabled:null==n||n===t.value.currentOrganization.id,onClick:async()=>{await r({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:t.value.username,orgId:n},data:{},successCallBkFn:t=>{const i={...t.data,isAuthenticated:!0};t?.data?.token&&localStorage.setItem("TOKEN",t.data.token),i.token=null,o(zt.setAuthenticated(i)),e.successChangeCallBackFn&&e.successChangeCallBackFn()}})},children:"Change Organization"})]})},Cn=be({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Nn,setSideBarState:Rn}=Cn.actions;var bn=Cn.reducer;function wn(e,t){const i=Te(e);fe(()=>{i.current=e},[e]),fe(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const Pn=te`
31
+ function(e,t){const i=St(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})(Er),a=ue.forwardRef(function(e,a){const s=function(e=Nr){return Cr(e)}(i),{className:l,component:d="div",...c}=Rr(e);return g(n,{as:d,ref:a,className:vr(l,r?r(o):o),theme:t&&s[t]||s,...c})});return a}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=Lr[t];return o?`${i}-${o}`:`${wr.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:wr.generate});function Mr(e){return/^\d+$/.test(e)}function Dr(e){return"number"==typeof e&&!isNaN(e)}function kr(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function Ur(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function xr(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function Fr(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&&(Sr.propTypes={children:no.node,component:no.elementType,sx:no.oneOfType([no.arrayOf(no.oneOfType([no.func,no.object,no.bool])),no.func,no.object])});const Br=(e,t)=>t?it(e).format(t):it(e).format(pi),qr=(e,t)=>t?it(e,t).toDate():it(e,pi).toDate(),Wr=e=>{if(e?.fieldInfo){const t=e.fieldInfo,i=e?.formManager||null,o=e?.formActions||null,r=e?.formValues||null,n=e?.fieldInfo?.fieldName||null,a=e?.fieldInfo?.fieldType||null;if(!(t&&i&&r&&n&&a))return g(T,{});const s=()=>e?.fieldInfo?.formProps?.fieldLabelFn?e.fieldInfo.formProps.fieldLabelFn(r):e?.fieldInfo?.fieldLabel?e?.fieldInfo?.fieldLabel:void 0;return e.hiddenFields.includes(n)?g(T,{}):g(B,{size:t?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===a||"number"===a?g(ni,{...t.muiTextFieldProps,fullWidth:!0,type:a,disabled:e.disabledFields.includes(n),label:s(),value:r[n],onChange:t=>{let s=null;""!=t.target.value&&(s="number"===a&&kr(t.target.value)?Number(t.target.value):t.target.value),i.setValue(n,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,s)},sx:{"& .MuiInputBase-root":{height:`${t?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...t?.formProps?.style,display:e.hiddenFields.includes(n)?"none":void 0},error:null!=i.formState.errors[n],helperText:i?.formState?.errors[n]?.message?.toString()}):"date"===t?.fieldType?g(Ti,{format:t?.dateFormat||pi,sx:t?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),label:s(),onChangeCallBack:t=>{i.setValue(n,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t)},value:r[n],error:null!=i.formState.errors[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):"datetime"===t?.fieldType?g(yi,{format:t?.dateFormat||ui,sx:t?.formProps?.style||{width:"100%"},disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),label:s(),onChangeCallBack:t=>{i.setValue(n,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t)},value:r[n],error:null!=i.formState.errors[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):"checkbox"===t?.fieldType?g(di,{label:s(),onChangeCallBack:t=>{i.setValue(n,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t)},value:r[n],checkedValue:t?.checkedValue||!0,unCheckedValue:t?.unCheckedValue||!1,disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),sx:t?.formProps?.style}):"combobox"===t?.fieldType?g(ci,{sx:t?.formProps?.style||{width:"100%"},label:s(),commonStoreKey:t?.commonStoreKey,dataQueryId:t?.dataQueryId,storeUrl:t?.storeUrl,storeLoadParam:t?.storeLoadParam,disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),onChangeCallBack:(t,a)=>{let s=null;t&&(s=t),i.setValue(n,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t,a)},options:t?.options||[],displayField:t?.optionDisplayField||"",valueField:t?.optionValueField||"",value:r[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):"lookup"===t?.fieldType?g(Ai,{sx:t?.formProps?.style||{width:"100%"},label:s(),disabled:e.disabledFields.includes(n),hidden:e.hiddenFields.includes(n),onChangeCallBack:(t,a)=>{let s=null;t&&(s=t),i.setValue(n,s),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(r,o,i,n,t,a)},lookupType:t.lookupType,value:r[n],errorMessage:i?.formState?.errors[n]?.message?.toString()}):null})}return g(T,{})},Gr=e=>{const t=Zt(),{ConfirmationWindow:i,setOpen:o}=jt({body:e?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{e?.actionFn(e?.record)}});return null==e?.authority||t.isUserAuthorized(e.authority)?f(T,{children:[g(i,{}),f(v,{variant:e?.formActionProps?.actionButtonVariant,color:e?.formActionProps?.actionButtonColor,onClick:()=>{if(e?.actionFn){if(e?.preActionValidation&&!e.preActionValidation(e.record))return;!0===e?.isConfirmationRequired?o(!0):e?.actionFn(e.record)}},children:[e?.icon?g(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}):g(T,{}),g("div",{children:e?.label})]})]}):g(T,{})},Hr=e=>{const{t:t}=Me();return g(T,{children:f(B,{container:!0,sx:e?.style,alignItems:"flex-start",children:[e?.label?g(B,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:e?.icon?f(T,{children:[g(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}),g("div",{children:t(e.label)})]}):g(T,{children:t(e.label)})}):g(T,{}),e?.elements?e.elements.map(t=>"group"===t.type?g(Hr,{...t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===t.type&&"props"===t.mode?g(Wr,{fieldInfo:t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields,formValuesChangeCallBk:e?.formValuesChangeCallBk}):"field"===t.type&&"node"===t.mode?g(B,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:g(t.node,{formManager:e.formManager,formValues:e.formValues,formActions:e.formActions})}):void 0):null,e?.actions?g(B,{size:{sm:12},sx:{padding:1},children:e.actions.map(t=>g(Gr,{...t,record:e.formValues}))}):g(T,{})]})})},Yr=e=>{const t=A(e=>e.AppInfo.value.apiBaseUrl),[i,o]=me(null);return fe(()=>{(e?.refKey||e?.attachmentId)&&(()=>{let i=t+"/api/v1/attachment/";e?.attachmentId?i+="download?attachmentId="+e.attachmentId:(i+=`downloadImage?attachmentCode=${e.attachmentCode}&refKey=${e.refKey}`,e?.category&&(i+=`&category=${e.category}`)),o(i)})()},[e.refKey,e?.attachmentId]),e?.showAsAvatar?g(K,{sx:e.style,onError:()=>{o(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:i}):g("img",{src:i,loading:"lazy",alt:"image",onError:()=>{o(e?.onErrorImage?e.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Kr=e=>{const{handleGetRequest:t,handleDeleteRequest:i}=$t(),{isUserAuthorized:o}=Zt();let r=!0;e?.downloadAuthorityKey&&(r=o(e.downloadAuthorityKey));const{ConfirmationWindow:n,setOpen:a}=jt({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await i({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey,attachmentId:e.id},successCallBkFn:t=>{e.setAttachmentConfig(t.data)},showMask:!0})})()}});return f(T,{children:[g(n,{}),f(Ke,{sx:{width:300,border:"0.5px solid gray"},children:[g(nt,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:e?.docType.toLocaleLowerCase().includes("image")?g(Yr,{attachmentId:e.id}):g(Re,{icon:"file",size:"3x"})}),f(rt,{children:[g(at,{gutterBottom:!0,variant:"h6",component:"div",children:e.fileName}),g(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${e?.attachmentSize||"unknown"} kb`}),g(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${e?.category||"NA"}`}),g(at,{variant:"body2",sx:{color:"text.secondary"},children:e.remark})]}),f(ot,{children:[e?.allowDelete?g(U,{size:"small",onClick:()=>{a(!0)},children:g(V,{title:"Delete Attachment",children:g(Re,{icon:"trash"})})}):g(T,{}),g("div",{style:{flex:1}}),r?g(U,{size:"small",onClick:async()=>{await t({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:g(V,{title:"Download Attachment",children:g(Re,{icon:"download"})})}):g(T,{})]})]})]})},Vr=e=>{const{handleUploadRequest:t,handleGetRequest:i}=$t(),[o,r]=me(null),[n,a]=me([]),[s,l]=me(null),[d,c]=me(null),[p,u]=me([]),[h,m]=me(null),{isUserAuthorized:y}=Zt(),A=e=>e.split(".").pop()?.toLowerCase()||"";fe(()=>{(async()=>{await i({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey},successCallBkFn:e=>{m(e.data)}})})()},[e.refKey,e.attachmentCode]),fe(()=>{if(u(h?.allowedFileTypes?h.allowedFileTypes.split(","):[]),h?.attachmentCategories){const e=[];for(const t of h.attachmentCategories.split(","))e.push({value:t});a(e)}else a([])},[h]);let I=!0;h?.downloadAuthorityKey&&!y(h?.downloadAuthorityKey)&&(I=!1);let _=!0;return!1===e?.enableAttachment&&(_=!1),h?.uploadAuthorityKey&&!y(h.uploadAuthorityKey)&&(_=!1),f(x,{sx:{display:"flex",flexDirection:"column",width:"100%",minHeight:400,alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[g(T,_?{children:null==h?.maxAllowedNumberOfFiles||h?.maxAllowedNumberOfFiles>h.refKeyAttachments.length?f(T,{children:[f("h3",{children:[g(Re,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),g("input",{type:"file",style:{margin:20},accept:h?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=A(t.name);if(p.length>0&&!p.includes(e))return void Pe.error(e+" is not allowed")}r(e.target.files)}}),n.length>0?g(ci,{label:"Attachment Type",sx:{width:300,m:1},options:n,displayField:"value",valueField:"value",value:d,onChangeCallBack:e=>{c(e)}}):g(T,{}),g(ni,{label:"Remark",value:s,onChange:e=>l(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),g(v,{sx:{m:1},variant:"contained",onClick:async()=>{let i=h?.refKeyAttachments.length||0;if(h?.maxAllowedNumberOfFiles&&o.length+i>h.maxAllowedNumberOfFiles)Pe.error("Maximum number of attachments is "+h.maxAllowedNumberOfFiles);else if(!0===h?.isCategoryRequired&&n.length>0&&(null==d||void 0===d||""===d))Pe.error("You must selected document type to process your request");else if(o){for(const e of o)if(e.type.startsWith("image/")){const t=600,i=1024*t;if(e.size>i)return void Pe.error(`File ${e.name} is too large. Max allowed is ${t}KB.`)}await t({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:e.refKey,attachmentCode:e.attachmentCode,remark:s,category:d},files:o,successCallBkFn:e=>{m(e.data),r(null),c(null),l(null),Pe.success("Your request has been process successfully")}})}else Pe.error("You must add files to upload")},children:"Upload"})]}):g(T,{})}:{}),I&&h?.refKeyAttachments?.length>0?f(T,{children:[f("h3",{children:[g(Re,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),g(B,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:h?.refKeyAttachments.map(t=>g(B,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:g(Kr,{...t,attachmentCode:e.attachmentCode,setAttachmentConfig:m,downloadAuthorityKey:h.downloadAuthorityKey,allowDelete:_})}))})]}):g(T,{})]})},zr=e=>{const t=A(e=>e.AppLayout),{t:i}=Me();return f(x,{sx:{display:"flex",flexDirection:"column",width:600,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[f(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[g(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),i("WF_ACTION_HISTORY_LABEL")]}),g(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:e.actionHistory.map((i,o)=>g(T,{children:f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[f(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[g(S,{sx:{marginBottom:.2},children:i.actionTime}),f(at,{children:["via ",i.actionMethod]})]}),f(S,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[g(Yr,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:i?.personId?i?.personId+"":void 0,style:{m:1,width:70,height:70}}),o!==e.actionHistory.length-1?g(S,{sx:{marginTop:11,position:"absolute"},children:"|"}):g(T,{})]}),f(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[f(S,{sx:{width:"100%"},children:["ltr"===t.appDirection?`${i?.documentActionEnName}`:`${i?.documentActionArName}`,i?.actionComment?" - "+i.actionComment:""]}),g(S,{sx:{width:"100%"},children:"ltr"===t.appDirection?`${i?.employeeEnName}`:`${i?.employeeArName}`})]})]})}))})]})},Qr=e=>{const{t:t}=Me(),i=Zt(),{ConfirmationWindow:o,setOpen:r}=jt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn)),e?.reloadData&&e.reloadData()}});let n=!0;if(e.authority&&(n=i.isUserAuthorized(e.authority)),n)return f(T,{children:[g(o,{}),f(v,{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?r(!0):(await e.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn),e?.reloadData&&e.reloadData())}else Pe.error(t("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?g(Re,{style:{marginRight:5,marginLeft:5},icon:e.icon}):g(T,{}),e?.label?t(e.label):g(T,{})]})]})},$r=z(e)({display:"grid",alignItems:"center"}),jr=z(t)(({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"])})),Zr=z(F)(({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"])})),Jr=e=>{const{t:p}=Me(),u=Zt(),h=!e?.templateProps?.editAction?.authority||u.isUserAuthorized(e.templateProps.editAction.authority),m=wi(e?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},e?.templateProps?.data||[],e?.templateProps?.keyColumnName||"id");return f(i,{children:[h&&"none"!=e?.templateProps?.editMode?.editMode&&(void 0===e?.templateProps?.hideCreateBtn||!1===e?.templateProps?.hideCreateBtn)?f(v,{onClick:e?.handleCreateNewRecord,children:[g(Re,{icon:"add",style:{marginRight:5,marginLeft:5}}),p("ADD_BTN_LABEL")]}):g(T,{}),e?.templateProps?.rowActions?e.templateProps.rowActions.map((t,i)=>!0===t?.gridActionProps?.multiRecord?ge(Qr,{...t,key:i,reloadData:async()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:m.selectedRecordIds,recordsToProcessActionOn:m.selectedRecords}):null):g(T,{}),g(S,{sx:{flex:1,mx:.5,my:.5,padding:1},children:e?.templateProps?.tBar}),g(V,{title:"Columns",children:g(o,{render:g(t,{}),children:g(r,{fontSize:"small"})})}),g(V,{title:"Filters",children:g(n,{render:(e,i)=>g(t,{...e,color:"default",children:g(Q,{badgeContent:i.filterCount,color:"primary",variant:"dot",children:g(a,{fontSize:"small"})})})})}),e?.templateProps?.gridStateKey?g(V,{title:p("RESET_GRID_STATE"),children:g(U,{onClick:e?.clearGridState,children:g(Re,{icon:"eraser"})})}):g(T,{}),g($,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),g(V,{title:p("EXPORT_EXECL_LABEL"),children:g(s,{render:g(j,{}),children:g(Re,{icon:"file-excel",color:"green"})})}),f($r,{children:[g(l,{render:(e,t)=>g(V,{title:p("SEARCH_BTN_LABEL"),enterDelay:0,children:g(jr,{...e,ownerState:{expanded:t.expanded},color:"default","aria-disabled":t.expanded,children:g(Re,{icon:"search"})})})}),g(d,{render:({ref:e,...t},i)=>g(Zr,{...t,ownerState:{expanded:i.expanded},inputRef:e,"aria-label":"Search",placeholder:`${p("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:g(Z,{position:"start",children:g(Re,{icon:"search"})}),endAdornment:i.value?g(Z,{position:"end",children:g(c,{edge:"end",size:"small","aria-label":"Clear search",children:g(Re,{icon:"xmark"})})}):null,...t.slotProps?.input},...t.slotProps}})})]}),g(U,{onClick:()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},children:g(Re,{icon:"refresh"})})]})},Xr=e=>{const{t:t}=Me(),i=Zt(),{ConfirmationWindow:o,setOpen:r}=jt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.record)),e?.reloadData&&e.reloadData()}});let n=!0;e.authority&&(n=i.isUserAuthorized(e.authority));let a={};e?.getActionIconStyleForRecord&&(a=e.getActionIconStyleForRecord(e.record));let s=!0;e?.isActionVisibleForRecord&&(s=e?.isActionVisibleForRecord(e.record));let l=!1;if(e?.isActionDisabledForRecord&&(l=e.isActionDisabledForRecord(e.record)),n&&s)return f(T,{children:[g(o,{}),g(p,{disabled:l,icon:g(V,{title:e?.label?t(e.label):"",children:g(Re,{icon:e.icon,style:{...a,color:l?"gray":null!=a?.color?a.color:void 0}})}),showInMenu:e?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!l){if(e?.preActionValidation&&!e.preActionValidation(e.record))return;!0===e?.isConfirmationRequired?r(!0):(await e.actionFn(e.record),!0===e?.gridActionProps?.reloadGridAfterAction&&e?.reloadData&&e.reloadData())}}})]})};let en=-1;const tn=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},on=(e,t)=>{const i=tn(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},rn=["__check__","actions"],nn=e=>{const{t:t}=Me(),{handleGetRequest:i}=$t(),o=A(e=>e.commonStores.stores),r=A(e=>e.AppLayout),[n,a]=me({}),[s,l]=me(!0),{getLookupOptions:d}=(()=>{const{handleGetRequest:e}=$t(),t=A(e=>e.AppLayout),i=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 o=await i(e.lookupType);return{...e,options:o,displayField:"ltr"===t.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:i}})(),{Window:c,setWindowState:y}=Jt({windowTitle:t(e.gridTitle)+" Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"50%",onCloseCallBack:()=>{e?.apiActions?.reloadData(e.gridLoadParametersValues)}}),{Window:I,setWindowState:_}=Jt({windowTitle:t(e.gridTitle)+" Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:()=>{e?.apiActions?.reloadData(e.gridLoadParametersValues)}}),[E,O]=me([]),C=Ni(e.formElements),N=[],R=he.useMemo(()=>e?.gridStateKey?tn(e.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=A(e=>e.AppLayout.appDirection),[P,v]=he.useState(b),[L,M]=he.useState(R.columnOrder||[]),[D,x]=he.useState(R.columnWidths||{}),[F,B]=me(R.columnGroupingModel||[]);let q=R?.pinnedColumns?.left||[];q=q.filter(e=>!rn.includes(e));let W=R?.pinnedColumns?.right||[]||[];W=W.filter(e=>!rn.includes(e));const[G,H]=me({left:[..."ltr"===w?rn:[],...q],right:[..."rtl"===w?rn:[],...W]}),Y=Zt(),K=Ue(),[z,Q]=me(null),[j,Z]=me(null),[te,ie]=me({}),oe=async(e,t,o)=>{let r=[];return e?await i({endPointURI:e,showMask:!1,parameters:t,successCallBkFn:e=>{r=e.data}}):o&&await i({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:o,...t},successCallBkFn:e=>{r=e.data}}),r},re=async()=>{let i=Ri(C,"row"===e?.editMode?.editMode||!1,t);for(let e of i)if(e?.lookupType&&(e.displayField="ltr"===r.appDirection?"lookupEnDisplay":"lookupArDisplay",e.options=await d(e.lookupType),e.valueField="lookupValue"),"custom"===e.type){if(e?.options)continue;e.options=e?.commonStoreKey?o[e.commonStoreKey]?.data||[]:await oe(e?.storeUrl,e?.storeLoadParam,e?.dataQueryId)}O(i)},[ne,ae]=me({ids:new Set,type:"include"});let se="id";e?.keyColumnName&&(se=e?.keyColumnName);const le=e.setData;let de=null;de=e?.validationSchema?e.validationSchema:He.object(bi(C));let ce=!0;e?.editAction?.authority&&(ce=Y.isUserAuthorized(e.editAction.authority));let pe=!0;e?.deleteAction?.authority&&(pe=Y.isUserAuthorized(e.deleteAction.authority));const{ConfirmationWindow:ue,setOpen:ge}=jt({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let t=!0;z&&!0===z?.isNew||(t=await e.apiActions.deleteRecordById(z[se])),t&&(e?.deleteAction?.postActionCallBack&&await e.deleteAction.postActionCallBack(z),le(e=>e.filter(e=>e[se]!=z[se])))}});let Te,ye,Ae,Ie,_e,Ee;"modal"===e?.editMode?.editMode&&(Te=e?.editMode?.specs?.modalHeight||"fit-content",ye=e?.editMode?.specs?.modalWidth||"300",Ae=e?.editMode?.specs?.modalMinHeight,Ie=e?.editMode?.specs?.modalMinWidth,_e=e?.editMode?.specs?.modalIcon||"window",Ee=e?.editMode?.specs?.modalTitle||"Record Form");const{Window:Oe,setWindowState:Ce}=Jt({height:Te,minHeight:Ae,minWidth:Ie,onCloseCallBack:()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},width:ye,windowIcon:_e,windowTitle:Ee}),Ne={type:"actions",field:"actions",headerName:"",headerAlign:"center",width:(e?.rowActions?30*e.rowActions.length:0)+(e?.editAction&&e?.editAction?.isEnabled?30:0)+(e?.deleteAction&&e?.deleteAction?.isEnabled?30:0)+(e?.attachment?30:0)+(e?.workFlowDocumentCode?30:0),getActions:i=>{const o=i.row,r=[];if("none"!=e?.editMode?.editMode&&(void 0===e?.disableDefaultAction||!e.disableDefaultAction)){const i=te[o[se]]?.mode===m.Edit;if("row"===e.editMode.editMode&&i)ce&&(r.push(g(p,{icon:g(Re,{icon:"save"}),label:t("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const t=e[se];ie({...te,[t]:{mode:m.View}})})(o)}})),r.push(g(p,{icon:g(Re,{icon:"cancel"}),label:t("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const t=e[se];t&&Dr(t)&&t<0?(ie({...te,[t]:{mode:m.View,ignoreModifications:!0}}),le(e=>{const i=e.filter(e=>e[se]!=t);return i})):ie({...te,[t]:{mode:m.View,ignoreModifications:!0}})})(o)},color:"inherit"})));else{if(e?.editAction&&!0===e?.editAction?.isEnabled){let i=!0;e?.editAction?.isActionVisibleForRecord&&(i=e?.editAction?.isActionVisibleForRecord(o));let n=!1;e?.editAction?.isActionDisabledForRecord&&(n=e?.editAction?.isActionDisabledForRecord(o)),ce&&i&&r.push(g(p,{disabled:n,icon:g(V,{title:t("EDIT_BTN_LABEL"),children:g(Re,{icon:"edit",style:{color:n?"gray":void 0}})}),showInMenu:e?.editAction?.gridActionProps?.showInMenu||!1,label:t("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{ce&&!n&&(async t=>{if(t)if(Z(t),"form"===e.editMode.editMode)K(e.editMode.specs.formRoute+"/"+t[se]);else if("modal"===e.editMode.editMode)Ce(!0);else if("row"===e?.editMode?.editMode){const e=t[se];ie({...te,[e]:{mode:m.Edit}})}})(o)}}))}if(e?.deleteAction&&!0===e?.deleteAction?.isEnabled){let i=!0;e?.deleteAction?.isActionVisibleForRecord&&(i=e?.deleteAction?.isActionVisibleForRecord(o));let n=!1;e?.deleteAction?.isActionDisabledForRecord&&(n=e?.deleteAction?.isActionDisabledForRecord(o)),pe&&i&&r.push(g(p,{disabled:n,icon:g(V,{title:t("DELETE_BTN_LABEL"),children:g(Re,{icon:"trash",style:{color:n?"gray":void 0}})}),showInMenu:e?.deleteAction?.gridActionProps?.showInMenu||!1,label:t("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(pe&&!n){if(e?.deleteAction?.preActionValidation&&!e.deleteAction.preActionValidation(o))return;Q(o),ge(!0)}}}))}}}if((o[e?.keyColumnName]||o.id&&o.id>0)&&e?.attachment&&r?.push(g(p,{icon:g(V,{title:"Attachments",children:g(Re,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{a(o),l(!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(o)),y(!0)}})),(o[e?.keyColumnName]||o.id&&o.id>0)&&e?.workFlowDocumentCode&&r?.push(g(p,{icon:g(V,{title:"Approvals",children:g(Re,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{a(o),_(!0)}})),o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.rowActions)for(const t of e.rowActions)t?.gridActionProps?.multiRecord&&!0===t?.gridActionProps?.multiRecord||r.push(g(Xr,{...t,record:o,reloadData:async()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)}}));return r}};let be=[];(void 0===e?.disableDefaultAction||!e.disableDefaultAction||e?.rowActions&&e?.rowActions.length>0)&&be.push(Ne),be=[...be,...E];fe(()=>{void 0!==e?.autoLoad&&!0!==e.autoLoad||e.apiActions.reloadData(e?.gridLoadParametersValues),re()},[]),fe(()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},[Y.UserInfo?.currentOrganization]),fe(()=>{re()},[w,e.formElements]);const we=he.useMemo(()=>{const e=be.map(e=>({...e}));if(L.length){const t=new Map(e.map(e=>[e.field,e]));return L.map(e=>t.get(e)).filter(Boolean)}return e},[L,D,be]);return f(T,{children:[g(ue,{}),"modal"===e?.editMode?.editMode?g(Oe,{children:e?.editMode?.specs?.formComponent?g(e.editMode.specs.formComponent,{recordIdToEdit:j?j[se]:void 0,formCloseCallBk:()=>{Ce(!1),e.apiActions.reloadData(e?.gridLoadParametersValues)}}):g(pn,{keyColumnName:e.keyColumnName,attachment:e.attachment,formValuesChangeCallBk:e?.formProps?.formValuesChangeCallBk,recordIdToEdit:j?j[se]:void 0,formCloseCallBk:()=>{Ce(!1),e.apiActions.reloadData(e?.gridLoadParametersValues)},elements:e.formElements,apiActions:e.apiActions,editAuthorityKey:e?.editAction?.authority,formSavedSuccessfullyCallBk:e?.editAction?.postActionCallBack,preSaveValidation:e?.editAction?.preActionValidation,actions:e?.rowActions})}):g(T,{}),void 0!==e?.hideInfoBar||e?.hideInfoBar?g(T,{}):f(S,{sx:{display:"flex"},children:[void 0!==e?.hideBackButton||e?.hideBackButton?g(T,{}):g(U,{onClick:()=>{K(-1,{replace:!0})},children:g(Re,{icon:"ltr"===w?"arrow-left":"arrow-right"})}),f(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[e?.girdIcon?g(Re,{icon:e.girdIcon,style:{marginRight:5,marginLeft:5}}):g(T,{}),g(k,{variant:"h5",children:e?.gridTitle?Ur(t(e?.gridTitle)):""})]})]}),e?.gridLoadParameters&&e?.gridLoadParameters.length>0&&e?.gridLoadParametersValues&&e?.setGridLoadParametersValues?f(J,{defaultExpanded:!0,sx:{width:"100%"},children:[g(X,{expandIcon:g(u,{}),children:f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[g(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),g(k,{component:"span",children:"Filters"})]})}),g(ee,{children:g(S,{children:g(pn,{saveButtonSpecs:{label:t("SEARCH_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:t("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async t=>{null!=t?e.setGridLoadParametersValues(t):e.setGridLoadParametersValues({}),e.apiActions.reloadData(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:e.gridLoadParameters})})})]}):g(T,{}),e?.attachment?g(c,{children:g(Vr,{attachmentCode:e.attachment.attachmentCode,refKey:n[e?.keyColumnName||"id"],enableAttachment:s})}):g(T,{}),e?.workFlowDocumentCode?g(I,{children:g(cn,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:n[e?.keyColumnName||"id"],postActionCallBk:()=>{_(!1),e.apiActions.reloadData(e.gridLoadParametersValues)},cancelActionCallBk:()=>{_(!1),e.apiActions.reloadData(e.gridLoadParametersValues)}})}):g(T,{}),g(h,{...e?.muiProps,slots:{toolbar:Jr},slotProps:{toolbar:{templateProps:{...e,rowSelectionModel:ne,data:e?.data},handleCreateNewRecord:()=>{if("form"===e?.editMode?.editMode)K(e.editMode.specs.formRoute);else if("modal"===e?.editMode?.editMode)Z(null),Ce(!0);else if("row"===e?.editMode?.editMode){en-=1;const e={};e[se]=en,e.isNew=!0;for(const t of E)"actions"!=t?.type&&t?.field!=se&&t?.field&&(e[t.field]=null);le(t=>[e,...t]),ie(e=>({...e,[en]:{mode:m.Edit}}))}},clearGridState:()=>{e?.gridStateKey&&localStorage.removeItem(e.gridStateKey),v({}),M([]),x({}),B([]),H({left:[..."ltr"===w?rn:[]],right:[..."rtl"===w?rn:[]]})}}},getRowId:e=>e[se],showToolbar:!0,rows:e?.data,columns:we,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==e.editMode.editMode?te:void 0,onRowModesModelChange:"row"==e.editMode.editMode?e=>{ie(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async t=>{if("row"===e.editMode.editMode){let i=null;const o=(e=>{try{de.parse(e)}catch(e){console.log("validateRecord err",e);let t=null;return t=e instanceof He.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",t}})(t);if(o){const e=o.split(",");throw Pe.error(g("div",{style:{},children:e.map(e=>f(T,{children:[g("div",{children:e}),g($,{})]}))})),new Error(o)}if(e?.editAction?.preActionValidation&&!e.editAction.preActionValidation(t))throw new Error("error on the configured presave validation");const r={...t};if(t[se]&&Dr(t[se])&&Number(t[se])<0&&(r[se]=null),i=await e.apiActions.saveRecord(r),null==i)throw new Error("Failed to process your request, contact your administrator");return e?.editAction?.postActionCallBack&&await e.editAction.postActionCallBack(t),!0===t?.isNew&&le(e=>{const o=e.filter(e=>e[se]!==t[se]);return[i,...o]}),!0===e?.editMode?.reloadAfterSave&&e?.apiActions?.reloadData&&e?.apiActions?.reloadData(e?.gridLoadParametersValues),i}},rowSelectionModel:ne,onRowSelectionModelChange:e=>{ae(e)},columnVisibilityModel:P,onColumnVisibilityModelChange:t=>{v(t),e?.gridStateKey&&on(e.gridStateKey,{columnVisibilityModel:t})},onColumnOrderChange:t=>{const{column:i,targetIndex:o}=t;M(t=>{const r=t.length?[...t]:be.map(e=>e.field),n=r.indexOf(i.field);return-1===n||(r.splice(n,1),r.splice(o,0,i.field),e?.gridStateKey&&on(e.gridStateKey,{columnOrder:r})),r})},rowGroupingModel:F,onRowGroupingModelChange:t=>{(t=>{B(t),e?.gridStateKey&&on(e.gridStateKey,{columnGroupingModel:t})})(t)},sx:{width:"100%"}})]})},an=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},sn=e=>{const[t,i]=me([]);return fe(()=>{const t=e.reportData.map((e,t)=>({...e,report_record_data_key:t}));i(t)},[e.reportData]),g(nn,{data:t,disableDefaultAction:!0,setData:e.setReportData,formElements:an(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()=>{}}})},ln=e=>{const[t,i]=me({...e?.initialParameterValues}),o=((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,t);return{ParameterPanel:({searchBtnClickCallBk:e})=>{const{t:t}=Me();return f(J,{defaultExpanded:!0,sx:{width:"100%"},children:[g(X,{expandIcon:g(Re,{icon:{prefix:"far",iconName:"square-caret-down"}}),children:f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[g(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),g(k,{component:"span",children:"Filters"})]})}),g(ee,{children:g(S,{children:g(pn,{saveButtonSpecs:{label:t("Filter"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:t("RESET_BTN_LABEL"),icon:"eraser",hidden:!0,actionButtonVariant:"outlined",actionButtonColor:"error"},actions:[{label:t("RESET_BTN_LABEL"),icon:"eraser",isIdRequired:!1,formActionProps:{enabled:!0},actionFn:async(e,t)=>{i({})}}],apiActions:{deleteRecordById:async()=>!0,saveRecord:async t=>{i(null!=t?t:{}),e&&await e(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:o})})})]})},parametersValues:t,setParametersValues:i,panelElements:o}},dn=e=>{const[t,i]=me(null),[o,r]=me(null),[n,a]=me([]),[s,l]=me("WAITING_REPORT_CODE"),{handleGetRequest:d,handlePostRequest:c,HandleDownloadHTTPPostPDF:p}=$t(),[u,h]=me(null),{ParameterPanel:m,parametersValues:y,panelElements:A,setParametersValues:I}=ln({parameters:u?.reportParameters||[],initialParameterValues:{...e?.reportParametersValues}});fe(()=>{u&&(!0===e?.byPassParameterEntry||0==u.reportParameters.length?(_(y),l("WAITING_RESULT")):l("WAITING_PARAMETER_INPUT"))},[u]);const _=async t=>{l("WAITING_RESULT"),"Excel"===u?.reportType?await c({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{l("SHOWING_RESULT"),a(e.data)}}):u?.reportType&&await p({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:e.reportCode,parameters:t,resultMode:e.resultMode,jasperOutPutFileType:e.jasperOutPutFileType},successCallBkFn:e=>{l("SHOWING_RESULT");const t=e.headers["content-disposition"];let o="downloaded_file";if(t&&-1!==t.indexOf("filename=")){const e=t.match(/filename="?([^"]+)"?/);e&&e[1]&&(o=e[1])}if(o.includes("pdf")){const t=new Blob([e.data],{type:"application/pdf"}),o=URL.createObjectURL(t);i(o)}else{const t=new Blob([e.data],{type:e.headers["content-type"]}),i=window.URL.createObjectURL(t),r=document.createElement("a");r.href=i,r.download=o,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(i)}},failureCallBkFn:e=>{r("Failed To run report ... contact your administrator"),l("ERROR")}})};return fe(()=>{e?.reportCode&&(async()=>{l("LOADING_METADATA"),await d({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:e.reportCode},successCallBkFn:e=>{h(e.data)},failureCallBkFn:e=>{r("Failed loading report metadata ... contact your administrator"),l("ERROR")}})})()},[e.reportCode,e.byPassParameterEntry,e.reportParametersValues,e.jasperOutPutFileType,e.resultMode]),f(T,{children:[f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[f(S,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[g(Re,{icon:"Excel"===u?.reportType?"file-excel":"file-pdf",color:"Excel"===u?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),u?.reportName]}),"Excel"!=u?.reportType&&"SHOWING_RESULT"===s?f(T,{children:[!0===e?.byPassParameterEntry?g(T,{}):u?.reportParameters.length>0?g(U,{onClick:()=>{l("WAITING_PARAMETER_INPUT")},children:g(Re,{icon:"filter"})}):g(T,{}),g(U,{children:g(Re,{icon:"refresh",onClick:()=>{_(y)}})})]}):g(T,{})]}),g(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===s&&"Excel"!=u?.reportType?g(m,{searchBtnClickCallBk:_}):"SHOWING_RESULT"===s||("WAITING_PARAMETER_INPUT"===s||"WAITING_RESULT"===s)&&"Excel"===u?.reportType?"Excel"===u?.reportType?g(sn,{reportData:n,setReportData:a,reloadReport:async()=>{_(y)},gridLoadParameters:A,gridLoadParametersValues:y,setGridLoadParametersValues:I}):g("iframe",{src:t,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===s?f(S,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[g(Re,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),o]}):g(T,{})})]})},cn=e=>{const t=Ue(),i=A(e=>e.AppLayout),{isUserAuthorized:o,UserInfo:r}=Zt(),{handleGetRequest:n,handlePostRequest:a}=$t(),[s,l]=me(null),[d,c]=me([]),{t:p}=Me(),[u,h]=me(null),[m,y]=me({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:I,setWindowState:_}=Jt({windowTitle:"ltr"===i.appDirection?m?.workflowDocument&&m?.referencedDocument?`${m?.workflowDocument?.documentEnName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`:"Document":m?.workflowDocument&&m?.referencedDocument?`${m?.workflowDocument?.documentArName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),E=async()=>{await n({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:e.workFlowDocumentCode,refDocumentId:e.refDocumentId},successCallBkFn:e=>{y(structuredClone(e.data))},failureCallBkFn:()=>{y({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},O=async()=>{await a({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:m?.workflowDocument?.id,refDocumentId:e.refDocumentId,actionId:s.id,refDocumentStatus:m?.workflowDocumentStatus?.documentStatusCode,actionComment:u},successCallBkFn:async t=>{s?.post_action_endpoint?await a({endPointURI:s.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:s.id},successCallBkFn:()=>{E(),e?.postActionCallBk&&e.postActionCallBk()}}):E()}})};return fe(()=>{e.refDocumentId&&e.workFlowDocumentCode&&E()},[e.refDocumentId,e.workFlowDocumentCode]),fe(()=>{c(m?.nextActions&&m?.nextActions?.length>0?m.nextActions.filter(e=>{if(!m?.workflowDocumentStatus?.nextActionTakersAuthority&&!m?.nextActionTakers)return!0;if(m?.workflowDocumentStatus?.nextActionTakersAuthority&&o(m.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(m?.nextActionTakers)for(const e of m.nextActionTakers)if(r?.username==e?.username||r?.username==e?.USERNAME||r?.email==e?.email||r?.email==e?.EMAIL||r?.employeeNumber==e?.employeeNumber||r?.employeeNumber==e?.EMPLOYEE_NUMBER)return!0;return!1}):[])},[m.nextActions,m.nextActionTakers]),f(T,{children:[m?.workflowDocumentReport?.id?g(I,{children:g(dn,{reportCode:m?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:e.refDocumentId+""}})}):g(T,{}),m?.workflowDocument?f(S,{sx:{width:"100%",maxWidth:600,textAlign:"center",fontSize:16,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[g(U,{onClick:()=>{t(-1,{replace:!0})},children:g(Re,{icon:"arrow-left"})}),g(S,{sx:{flex:1}}),g(Re,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===i.appDirection?`${m?.workflowDocument?.documentEnName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`:`${m?.workflowDocument?.documentArName} # ${m?.referencedDocument[m?.workflowDocument?.documentNumberField]}`,m?.workflowDocumentStatus?"ltr"===i.appDirection?` ( ${m?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${m?.workflowDocumentStatus?.documentStatusArName} )`:"",g(S,{sx:{flex:1}}),m?.workflowDocumentReport?.id?g(v,{onClick:()=>{_(!0)},variant:"outlined",startIcon:g(Re,{icon:"eye"}),children:p("VIEW_LABEL")}):g(T,{})]}):g(T,{}),f(S,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[d?.length>0?f(x,{sx:{padding:2,display:"flex",margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[g(ci,{sx:{marginBottom:2,width:400},label:p("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===i.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:s?.id,options:d,onChangeCallBack:(e,t)=>{l(t)}}),g(ni,{sx:{width:400},rows:3,value:u,onChange:e=>{h(e.target.value)},multiline:!0,label:p("WF_COMMENT_LABEL")}),f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[g(v,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=s&&null!=s?.id?!0!==s.require_comment&&1!==s.require_comment&&"true"!==s.require_comment||null!==u&&""!==u?s?.pre_action_endpoint?await a({endPointURI:s.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:s.id},successCallBkFn:()=>{O()}}):O():Pe.error("You must enter comment for the action to be processed"):Pe.error("You must select action to process")},children:p("WF_TAKE_ACTION_BTN_LABEL")}),e?.cancelActionCallBk?g(v,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{e?.cancelActionCallBk&&e.cancelActionCallBk()},children:p("WF_CANCEL_BTN_LABEL")}):g(T,{})]}),m?.nextActionTakers&&m.nextActionTakers.length>0?f(T,{children:[g($,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:f(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[g(Re,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",p("WF_WAITING_FOR_LABEL")]})}),g(S,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:m.nextActionTakers.map(e=>f(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[g(Yr,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:e?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),f(S,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[g("div",{children:"ltr"===i.appDirection?e?.employee_en_name:e?.employee_ar_name}),g("div",{children:e?.email?f(T,{children:[g(Re,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),e?.email]}):g(T,{})}),g("div",{children:e?.mobile_number?f(T,{children:[g(Re,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),e?.mobile_number]}):g(T,{})})]})]}))})]}):g(T,{})]}):g(T,{}),m?.actionsHistory.length>0?g(zr,{actionHistory:m.actionsHistory}):f(x,{sx:{display:"flex",flexDirection:"column",width:600,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[f(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[g(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),p("WF_ACTION_HISTORY_LABEL")]}),g(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},pn=e=>{const{Window:t,setWindowState:i}=Jt({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[o,r]=me(!0),{t:n}=Me(),a=Ni(e.elements),[s,l]=me([]),[d,c]=me([]),p={};for(const t of e.elements)"field"===t?.type&&"props"===t?.mode&&t?.props?.defaultValue&&(p[t.props.fieldName]=t.props.defaultValue);let u=null;u=e?.validationSchema?e.validationSchema:Ge.object(bi(a));const h=ke({resolver:We(u),defaultValues:p}),m=h.watch(),y=xe(),A=e?.formRouteRecordIdParamName,I=async()=>{let t=null;if(e?.recordIdToEdit?t=e.recordIdToEdit:A&&y[A]&&(t=y[A]),t){const i=await e.apiActions.loadRecordById(t);if(i){h.reset({...i});for(const e of a)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?h.setValue(e.fieldName,i[e.fieldName]+""):h.setValue(e.fieldName,i[e.fieldName]));e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(m,O,h)}}else h.reset({}),e.formValuesChangeCallBk(m,O,h)},{Window:_,setWindowState:E}=Jt({windowTitle:"Approvals",windowIcon:"stamp",height:"fit-content",minHeight:500,width:"fit-content",onCloseCallBack:async()=>{await I()}}),O={setFieldValue:(e,t)=>{h.setValue(e,t)},hideField:e=>{c(t=>[...t,e])},showField:e=>{c(t=>t.filter(t=>t!==e))},disableField:e=>{l(t=>[...t,e])},enableField:e=>{l(t=>t.filter(t=>t!==e))}};return fe(()=>{const e=[],t=[];for(const i of a)i?.hidden&&e.push(i.fieldName),i?.disabled&&t.push(i.fieldName);c(e),l(t)},[e.elements]),fe(()=>{I()},[e?.recordIdToEdit]),fe(()=>{r(!e?.attachment||!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(m))},[m]),f(T,{children:[e?.attachment?g(t,{children:g(Vr,{attachmentCode:e.attachment.attachmentCode,refKey:m[e?.keyColumnName||"id"],enableAttachment:o})}):g(T,{}),e?.workFlowDocumentCode?g(_,{children:g(cn,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:m[e?.keyColumnName||"id"],postActionCallBk:()=>{E(!1),I()},cancelActionCallBk:()=>{E(!1),I()}})}):g(T,{}),g(Sr,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:g(B,{sx:{width:"100%"},container:!0,children:e.elements.map((t,i)=>"group"===t.type?g(Hr,{...t.props,formManager:h,formValues:m,formActions:O,hiddenFields:d,disabledFields:s,formValuesChangeCallBk:e.formValuesChangeCallBk},i):"field"===t.type&&"props"===t.mode?g(Wr,{fieldInfo:t.props,formManager:h,formValues:m,formActions:O,hiddenFields:d,disabledFields:s,formValuesChangeCallBk:e.formValuesChangeCallBk},i):"field"===t.type&&"node"===t.mode?g(B,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:g(t.node,{formManager:h,formValues:m})},i):void 0)})}),f(Sr,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[m[e?.keyColumnName||"id"]&&e?.attachment?g(V,{title:"Attachments",children:g(U,{onClick:()=>{i(!0)},children:g(Re,{icon:"paperclip"})})}):null,m[e?.keyColumnName||"id"]&&e?.workFlowDocumentCode?g(V,{title:"Approvals",children:g(U,{onClick:()=>{E(!0)},children:g(Re,{icon:"stamp"})})}):null,e?.actions?e.actions.map(t=>!1===t?.isIdRequired?g(Gr,{...t,record:m}):m[e?.keyColumnName||"id"]?!0===t?.formActionProps?.enabled?g(Gr,{...t,record:m}):g(T,{}):void 0):g(T,{}),g("div",{style:{flex:1}}),e?.saveButtonSpecs?.hidden?g(T,{}):g(v,{variant:e?.saveButtonSpecs?.actionButtonVariant?e.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:e?.saveButtonSpecs?.icon?g(Re,{icon:e.saveButtonSpecs.icon}):null,color:e?.saveButtonSpecs?.actionButtonColor?e.saveButtonSpecs.actionButtonColor:"primary",onClick:h.handleSubmit(t=>{(async t=>{if((!e?.preSaveValidation||e.preSaveValidation(t))&&t){const i=await e.apiActions.saveRecord(t);i&&(h.reset({...i}),e?.formSavedSuccessfullyCallBk&&e.formSavedSuccessfullyCallBk(i),e?.formCloseCallBk&&e.formCloseCallBk())}})(t)},e=>{Pe.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:n(e?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),e?.cancelButtonSpecs?.hidden?g(T,{}):g(v,{variant:e?.cancelButtonSpecs?.actionButtonVariant?e.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:e?.cancelButtonSpecs?.icon?g(Re,{icon:e.cancelButtonSpecs.icon}):null,color:e?.cancelButtonSpecs?.actionButtonColor?e.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{e?.formCloseCallBk&&e.formCloseCallBk(),h.reset(p)},children:n(e?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},un=()=>{const{workflowDocumentCode:e,refDocumentId:t}=xe();return g(cn,{workFlowDocumentCode:e,refDocumentId:t})},hn=e=>g(st,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),mn=e=>f(x,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[g(S,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:g("div",{children:e.record[e.valueField]})}),g(k,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]})]}),fn=e=>f(T,{children:[g(k,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),g(lt,{width:200,height:200,value:e.record[e.valueField],valueMax:e.total})]}),gn=e=>g(dt,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function Tn(e){return f(pt,{sx:{display:"flex",alignItems:"center"},children:[g(pt,{sx:{width:"100%",mr:1},children:g(ct,{variant:"determinate",...e})}),g(pt,{sx:{minWidth:35},children:g(at,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(e.value)}%`})})]})}const yn=e=>f(pt,{sx:{width:"100%"},children:[g(at,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),g(Tn,{value:e.record[e.valueField]/e.total*100})]}),An=e=>{const t=e.data.map((t,i)=>({id:i,value:t[e.valueField],label:t[e.labelField]+""}));return g(ut,{series:[{data:t}]})},In=e=>{const[t,i]=me(!0),[o,r]=me([]),{handleGetRequest:n}=$t();fe(()=>{e.loadWidget?(async()=>{i(!0),await n({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e.parameterValues},successCallBkFn:e=>{i(!1),r(e.data)},failureCallBkFn:()=>{i(!1),r([])}})})():i(!1)},[e.loadWidget,e.loadCounter]);let a=0;if(1==o.length)a=100;else if("CircularProgress"===e.widgetType||"LinearProgress"===e.widgetType)for(const t of o)a+=t[e.verticalAxisField];return f(T,{children:["LineChart"===e.widgetType||"PieChart"===e.widgetType||"ColumnChart"===e.widgetType?f(S,{children:[g(Re,{style:{marginRight:10,marginLeft:10},icon:e?.icon||"chart-pie"}),e?.title]}):g(T,{}),g(S,{sx:{flex:1,padding:1,height:"90%",display:"flex",alignItems:"center",justifyContent:"center",width:"90%"},children:t?f(T,{children:[g(Re,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),g("div",{children:"Loading"})]}):"ColumnChart"===e.widgetType?g(hn,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===e.widgetType?g(gn,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===e.widgetType?g(An,{data:o,widgetTitle:e.title,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,widgetType:"Pie"}):f(B,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[g(B,{size:{xs:12},sx:{textAlign:"center"},children:e.title}),o.map((t,i)=>"Card"===e.widgetType?g(B,{size:{md:3,xs:12},children:g(mn,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField},i)}):"CircularProgress"===e.widgetType?g(B,{size:{md:3,xs:12},children:g(fn,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:a},i)}):"LinearProgress"===e.widgetType?g(B,{size:{md:3,xs:12},children:g(yn,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:a},i)}):void 0)]})})]})},_n=e=>{const[t,i]=me({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),{ParameterPanel:o,parametersValues:r}=ln({parameters:t?.dashboardParameters||[],initialParameterValues:{}}),[n,a]=me(0),[s,l]=me(!1);fe(()=>{if(null!=t.dashboardCode&&null!=t.dashboardCode&&""!=t.dashboardCode){l(!1);let e=!0;if(t?.dashboardParameters.length>0)for(const i of t?.dashboardParameters)if(!0===i?.mandatory&&(void 0===r[i.parameterCode]||null===r[i.parameterCode]||""===r[i.parameterCode])){e=!1;break}e&&l(e),a(n+1)}},[t?.dashboardParameters,r]);const d=Ue(),{handleGetRequest:c,handlePostRequest:p}=$t();return fe(()=>{e.dashboardCode&&(async()=>{await c({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:e.dashboardCode},successCallBkFn:e=>{i(e.data)},failureCallBkFn:()=>{i(null)}})})()},[e.dashboardCode,e.parameters]),g(T,{children:t?f(T,{children:[f(S,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[g(U,{onClick:()=>{d(-1,{replace:!0})},children:g(Re,{icon:"arrow-left"})}),g(S,{sx:{flex:1}}),g(Re,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),g(S,{children:t?.dashboardTitle}),g(S,{sx:{flex:1}})]}),t?.dashboardParameters.length>0?g(o,{searchBtnClickCallBk:async e=>{a(n+1)}}):g(T,{}),g(B,{container:!0,spacing:1,sx:{height:"fit-content",overflowY:"auto",padding:1},children:t?.widgets.map((e,t)=>g(B,{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:g(In,{...e,parameterValues:r,loadWidget:s})},t))})]}):g(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},En=()=>{const{dashboardCode:e}=xe();return g(_n,{dashboardCode:e})},On=e=>{const{UserSession:t}=Zt(),i=A(e=>e.AppLayout),o=y(),{handlePostRequest:r}=$t(),[n,a]=me(t.value.currentOrganization.id);return f(S,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[g(ci,{sx:{width:"100%"},displayField:"ltr"===i.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:t.value.userOrganizations,value:n,onChangeCallBack:e=>{a(e)}}),g(v,{sx:{m:1},variant:"contained",disabled:null==n||n===t.value.currentOrganization.id,onClick:async()=>{await r({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:t.value.username,orgId:n},data:{},successCallBkFn:t=>{const i={...t.data,isAuthenticated:!0};t?.data?.token&&localStorage.setItem("TOKEN",t.data.token),i.token=null,o(zt.setAuthenticated(i)),e.successChangeCallBackFn&&e.successChangeCallBackFn()}})},children:"Change Organization"})]})},Cn=be({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Nn,setSideBarState:Rn}=Cn.actions;var bn=Cn.reducer;function wn(e,t){const i=Te(e);fe(()=>{i.current=e},[e]),fe(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const Pn=te`
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; }