@asaleh37/ui-base 25.8.30 → 25.8.31

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=Mt(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})(Ea),d=me.forwardRef(function(e,d){const n=function(e=ya){return Oa(e)}(i),{className:l,component:s="div",...p}=ha(e);return _(r,{as:s,ref:d,className:Da(l,a?a(o):o),theme:t&&n[t]||n,...p})});return d}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=Pa[t];return o?`${i}-${o}`:`${La.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:La.generate});function Ma(e){return/^\d+$/.test(e)}function ba(e){return"number"==typeof e&&!isNaN(e)}function Sa(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function Ua(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function va(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function wa(e,t){const i=new Date(e),o=new Date,a=Math.floor((i-o)/1e3),r="rtl"===t?"ar":"en",d=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=[{unit:"year",seconds:31536e3},{unit:"month",seconds:2592e3},{unit:"week",seconds:604800},{unit:"day",seconds:86400},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(const{unit:e,seconds:t}of n){const i=Math.floor(a/t);if(Math.abs(i)>1)return d.format(i,e)}return"ar"===r?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(ga.propTypes={children:io.node,component:io.elementType,sx:io.oneOfType([io.arrayOf(io.oneOfType([io.func,io.object,io.bool])),io.func,io.object])});const xa=e=>{if(e?.fieldInfo){const t=e.fieldInfo,i=e?.formManager||null,o=e?.formActions||null,a=e?.formValues||null,r=e?.fieldInfo?.fieldName||null,d=e?.fieldInfo?.fieldType||null;if(!(t&&i&&a&&r&&d))return _(f,{});const n=()=>e?.fieldInfo?.formProps?.fieldLabelFn?e.fieldInfo.formProps.fieldLabelFn(a):e?.fieldInfo?.fieldLabel?e?.fieldInfo?.fieldLabel:void 0;return e.hiddenFields.includes(r)?_(f,{}):_(k,{size:t?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===d||"number"===d?_(ii,{...t.muiTextFieldProps,fullWidth:!0,type:d,disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),label:n(),value:a[r],onChange:t=>{let n=null;""!=t.target.value&&(n="number"===d&&Sa(t.target.value)?Number(t.target.value):t.target.value),i.setValue(r,n),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,n)},sx:{"& .MuiInputBase-root":{height:`${t?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...t?.formProps?.style},error:null!=i.formState.errors[r],helperText:i?.formState?.errors[r]?.message?.toString()}):"date"===t?.fieldType?_(Ti,{format:t?.dateFormat||li,sx:t?.formProps?.style||{width:"100%"},disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),label:n(),onChangeCallBack:t=>{i.setValue(r,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t)},value:a[r],error:null!=i.formState.errors[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):"datetime"===t?.fieldType?_(Ai,{format:t?.dateFormat||si,sx:t?.formProps?.style||{width:"100%"},disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),label:n(),onChangeCallBack:t=>{i.setValue(r,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t)},value:a[r],error:null!=i.formState.errors[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):"checkbox"===t?.fieldType?_(di,{label:n(),onChangeCallBack:t=>{i.setValue(r,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t)},value:a[r],checkedValue:t?.checkedValue||!0,unCheckedValue:t?.unCheckedValue||!1,disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),sx:t?.formProps?.style}):"combobox"===t?.fieldType?_(ni,{sx:t?.formProps?.style||{width:"100%"},label:n(),disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),onChangeCallBack:(t,d)=>{let n=null;t&&(n=t),i.setValue(r,n),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t,d)},options:t?.options||[],displayField:t?.optionDisplayField||"",valueField:t?.optionValueField||"",value:a[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):"lookup"===t?.fieldType?_(_i,{sx:t?.formProps?.style||{width:"100%"},label:n(),disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),onChangeCallBack:(t,d)=>{let n=null;t&&(n=t),i.setValue(r,n),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t,d)},lookupType:t.lookupType,value:a[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):null})}return _(f,{})},Fa=e=>{const t=Zt(),{ConfirmationWindow:i,setOpen:o}=Qt({body:e?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{e?.actionFn(e?.record)}});return null==e?.authority||t.isUserAuthorized(e.authority)?A(f,{children:[_(i,{}),A(M,{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?_(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}):_(f,{}),_("div",{children:e?.label})]})]}):_(f,{})},Ba=e=>{const{t:t}=be();return _(f,{children:A(k,{container:!0,sx:e?.style,alignItems:"flex-start",children:[e?.label?_(k,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:e?.icon?A(f,{children:[_(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}),_("div",{children:t(e.label)})]}):_(f,{children:t(e.label)})}):_(f,{}),e?.elements?e.elements.map(t=>"group"===t.type?_(Ba,{...t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields}):"field"===t.type&&"props"===t.mode?_(xa,{fieldInfo:t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields}):"field"===t.type&&"node"===t.mode?_(k,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:_(t.node,{formManager:e.formManager,formValues:e.formValues,formActions:e.formActions})}):void 0):null,e?.actions?_(k,{size:{sm:12},sx:{padding:1},children:e.actions.map(t=>_(Fa,{...t,record:e.formValues}))}):_(f,{})]})})},ka=e=>{const t=E(e=>e.AppInfo.value.apiBaseUrl),[i,o]=Te(null);return Ae(()=>{(()=>{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]),e?.showAsAvatar?_(K,{sx:e.style,onError:()=>{o(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:i}):_("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"}})},Wa=e=>{const{handleGetRequest:t,handleDeleteRequest:i}=Ht(),{isUserAuthorized:o}=Zt();let a=!0;e?.downloadAuthorityKey&&(a=o(e.downloadAuthorityKey));const{ConfirmationWindow:r,setOpen:d}=Qt({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 A(f,{children:[_(r,{}),A(Ve,{sx:{width:300,border:"0.5px solid gray"},children:[_(ot,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:e?.docType.toLocaleLowerCase().includes("image")?_(ka,{attachmentId:e.id}):_(Re,{icon:"file",size:"3x"})}),A(it,{children:[_(at,{gutterBottom:!0,variant:"h6",component:"div",children:e.fileName}),_(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${e?.attachmentSize||"unknown"} kb`}),_(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${e?.category||"NA"}`}),_(at,{variant:"body2",sx:{color:"text.secondary"},children:e.remark})]}),A(tt,{children:[e?.allowDelete?_(x,{size:"small",onClick:()=>{d(!0)},children:_(z,{title:"Delete Attachment",children:_(Re,{icon:"trash"})})}):_(f,{}),_("div",{style:{flex:1}}),a?_(x,{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:_(z,{title:"Download Attachment",children:_(Re,{icon:"download"})})}):_(f,{})]})]})]})},Ga=e=>{const{handleUploadRequest:t,handleGetRequest:i}=Ht(),[o,a]=Te(null),[r,d]=Te([]),[n,l]=Te(null),[s,p]=Te(null),[c,m]=Te([]),[u,T]=Te(null),{isUserAuthorized:I}=Zt(),E=e=>e.split(".").pop()?.toLowerCase()||"";Ae(()=>{(async()=>{await i({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey},successCallBkFn:e=>{T(e.data)}})})()},[e.refKey,e.attachmentCode]),Ae(()=>{if(m(u?.allowedFileTypes?u.allowedFileTypes.split(","):[]),u?.attachmentCategories){const e=[];for(const t of u.attachmentCategories.split(","))e.push({value:t});d(e)}else d([])},[u]);let N=!0;u?.downloadAuthorityKey&&!I(u?.downloadAuthorityKey)&&(N=!1);let O=!0;return!1===e?.enableAttachment&&(O=!1),u?.uploadAuthorityKey&&!I(u.uploadAuthorityKey)&&(O=!1),A(F,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[_(f,O?{children:null==u?.maxAllowedNumberOfFiles||u?.maxAllowedNumberOfFiles>u.refKeyAttachments.length?A(f,{children:[A("h3",{children:[_(Re,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),_("input",{type:"file",style:{margin:20},accept:u?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=E(t.name);if(c.length>0&&!c.includes(e))return void De.error(e+" is not allowed")}a(e.target.files)}}),r.length>0?_(ni,{label:"Attachment Type",sx:{width:300,m:1},options:r,displayField:"value",valueField:"value",value:s,onChangeCallBack:e=>{p(e)}}):_(f,{}),_(ii,{label:"Remark",value:n,onChange:e=>l(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),_(M,{sx:{m:1},variant:"contained",onClick:async()=>{let i=u?.refKeyAttachments.length||0;if(u?.maxAllowedNumberOfFiles&&o.length+i>u.maxAllowedNumberOfFiles)De.error("Maximum number of attachments is "+u.maxAllowedNumberOfFiles);else if(!0===u?.isCategoryRequired&&r.length>0&&(null==s||void 0===s||""===s))De.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 De.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:n,category:s},files:o,successCallBkFn:e=>{T(e.data),a(null),p(null),l(null),De.success("Your request has been process successfully")}})}else De.error("You must add files to upload")},children:"Upload"})]}):_(f,{})}:{}),N&&u?.refKeyAttachments?.length>0?A(f,{children:[A("h3",{children:[_(Re,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),_(k,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:u?.refKeyAttachments.map(t=>_(k,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:_(Wa,{...t,attachmentCode:e.attachmentCode,setAttachmentConfig:T,downloadAuthorityKey:u.downloadAuthorityKey,allowDelete:O})}))})]}):_(f,{})]})},Ya=e=>{const t=E(e=>e.AppLayout),{t:i}=be();return A(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[A(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[_(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),i("WF_ACTION_HISTORY_LABEL")]}),_(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:e.actionHistory.map((i,o)=>_(f,{children:A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[A(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[_(S,{sx:{marginBottom:.2},children:i.actionTime}),A(at,{children:["via ",i.actionMethod]})]}),A(S,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[_(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:i?.personId+""||"0",style:{m:1,width:70,height:70}}),o!==e.actionHistory.length-1?_(S,{sx:{marginTop:11,position:"absolute"},children:"|"}):_(f,{})]}),A(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[A(S,{sx:{width:"100%"},children:["ltr"===t.appDirection?`${i?.documentActionEnName}`:`${i?.documentActionArName}`,i?.actionComment?" - "+i.actionComment:""]}),_(S,{sx:{width:"100%"},children:"ltr"===t.appDirection?`${i?.employeeEnName}`:`${i?.employeeArName}`})]})]})}))})]})},Va=e=>{const{t:t}=be(),i=Zt(),{ConfirmationWindow:o,setOpen:a}=Qt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn)),e?.reloadData&&e.reloadData()}});let r=!0;if(e.authority&&(r=i.isUserAuthorized(e.authority)),r)return A(f,{children:[_(o,{}),A(M,{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?a(!0):(await e.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn),e?.reloadData&&e.reloadData())}else De.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?_(Re,{style:{marginRight:5,marginLeft:5},icon:e.icon}):_(f,{}),e?.label?t(e.label):_(f,{})]})]})},qa=H(e)({display:"grid",alignItems:"center"}),Ka=H(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"])})),za=H(B)(({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"])})),Ha=e=>{const{t:c}=be(),m=Zt(),u=!e?.templateProps?.editAction?.authority||m.isUserAuthorized(e.templateProps.editAction.authority),T=Li(e?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},e?.templateProps?.data||[],e?.templateProps?.keyColumnName||"id");return A(i,{children:[u&&"none"!=e?.templateProps?.editMode?.editMode?A(M,{onClick:e?.handleCreateNewRecord,children:[_(Re,{icon:"add",style:{marginRight:5,marginLeft:5}}),c("ADD_BTN_LABEL")]}):_(f,{}),e?.templateProps?.rowActions?e.templateProps.rowActions.map((t,i)=>!0===t?.gridActionProps?.multiRecord?_e(Va,{...t,key:i,reloadData:async()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:T.selectedRecordIds,recordsToProcessActionOn:T.selectedRecords}):null):_(f,{}),_(S,{sx:{flex:1,mx:.5},children:e?.templateProps?.tBar}),_(z,{title:"Columns",children:_(o,{render:_(t,{}),children:_(a,{fontSize:"small"})})}),_(z,{title:"Filters",children:_(r,{render:(e,i)=>_(t,{...e,color:"default",children:_(Q,{badgeContent:i.filterCount,color:"primary",variant:"dot",children:_(d,{fontSize:"small"})})})})}),e?.templateProps?.gridStateKey?_(z,{title:c("RESET_GRID_STATE"),children:_(x,{onClick:e?.clearGridState,children:_(Re,{icon:"eraser"})})}):_(f,{}),_(Z,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),_(z,{title:c("EXPORT_EXECL_LABEL"),children:_(n,{render:_(j,{}),children:_(Re,{icon:"file-excel",color:"green"})})}),A(qa,{children:[_(l,{render:(e,t)=>_(z,{title:c("SEARCH_BTN_LABEL"),enterDelay:0,children:_(Ka,{...e,ownerState:{expanded:t.expanded},color:"default","aria-disabled":t.expanded,children:_(Re,{icon:"search"})})})}),_(s,{render:({ref:e,...t},i)=>_(za,{...t,ownerState:{expanded:i.expanded},inputRef:e,"aria-label":"Search",placeholder:`${c("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:_($,{position:"start",children:_(Re,{icon:"search"})}),endAdornment:i.value?_($,{position:"end",children:_(p,{edge:"end",size:"small","aria-label":"Clear search",children:_(Re,{icon:"xmark"})})}):null,...t.slotProps?.input},...t.slotProps}})})]}),_(x,{onClick:()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},children:_(Re,{icon:"refresh"})})]})},Qa=e=>{const{t:t}=be(),i=Zt(),{ConfirmationWindow:o,setOpen:a}=Qt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.record)),e?.reloadData&&e.reloadData()}});let r=!0;e.authority&&(r=i.isUserAuthorized(e.authority));let d={};e?.getActionIconStyleForRecord&&(d=e.getActionIconStyleForRecord(e.record));let n=!0;e?.isActionVisibleForRecord&&(n=e?.isActionVisibleForRecord(e.record));let l=!1;if(e?.isActionDisabledForRecord&&(l=e.isActionDisabledForRecord(e.record)),r&&n)return A(f,{children:[_(o,{}),_(c,{disabled:l,icon:_(z,{title:e?.label?t(e.label):"",children:_(Re,{icon:e.icon,style:{...d,color:l?"gray":null!=d?.color?d.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?a(!0):(await e.actionFn(e.record),!0===e?.gridActionProps?.reloadGridAfterAction&&e?.reloadData&&e.reloadData())}}})]})};let Za=-1;const ja=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},$a=(e,t)=>{const i=ja(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},Xa=["__check__","actions"],Ja=e=>{const{t:t}=be(),i=E(e=>e.AppLayout),[o,a]=Te({}),[r,d]=Te(!0),{getLookupOptions:n}=(()=>{const{handleGetRequest:e}=Ht(),t=E(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:l,setWindowState:s}=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:p,setWindowState:I}=jt({windowTitle:t(e.gridTitle)+" Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"80%",onCloseCallBack:()=>{e?.apiActions?.reloadData(e.gridLoadParametersValues)}}),[N,O]=Te([]),y=yi(e.formElements),h=[],R=ue.useMemo(()=>e?.gridStateKey?ja(e.gridStateKey):{},[]);for(const e of y)!0===e?.gridProps?.hidden&&h.push(e.fieldName);let L={};if(R?.columnVisibilityModel){L=R.columnVisibilityModel;const e=Object.keys(L);for(const t of h)e.includes(t)||(L[t]=!1)}else for(const e of h)L[e]=!1;const C=E(e=>e.AppLayout.appDirection),[D,P]=ue.useState(L),[g,M]=ue.useState(R.columnOrder||[]),[b,U]=ue.useState(R.columnWidths||{}),[v,F]=Te(R.columnGroupingModel||[]);let B=R?.pinnedColumns?.left||[];B=B.filter(e=>!Xa.includes(e));let k=R?.pinnedColumns?.right||[]||[];k=k.filter(e=>!Xa.includes(e));const[W,G]=Te({left:[..."ltr"===C?Xa:[],...B],right:[..."rtl"===C?Xa:[],...k]}),Y=Zt(),V=ve(),[q,K]=Te(null),[H,Q]=Te(null),[j,$]=Te({}),te=async()=>{let o=hi(y,"row"===e?.editMode?.editMode||!1,t);for(let e of o)e?.lookupType&&(e.displayField="ltr"===i.appDirection?"lookupEnDisplay":"lookupArDisplay",e.options=await n(e.lookupType),e.valueField="lookupValue");O(o)},[ie,oe]=Te({ids:new Set,type:"include"});let ae="id";e?.keyColumnName&&(ae=e?.keyColumnName);const re=e.setData;let de=null;de=e?.validationSchema?e.validationSchema:Ge.object(Ri(y));let ne=!0;e?.editAction?.authority&&(ne=Y.isUserAuthorized(e.editAction.authority));let le=!0;e?.deleteAction?.authority&&(le=Y.isUserAuthorized(e.deleteAction.authority));const{ConfirmationWindow:se,setOpen:pe}=Qt({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let t=!0;q&&!0===q?.isNew||(t=await e.apiActions.deleteRecordById(q[ae])),t&&(e?.deleteAction?.postActionCallBack&&await e.deleteAction.postActionCallBack(q),re(e=>e.filter(e=>e[ae]!=q[ae])))}});let ce,me,_e,fe,Ie,Ee;"modal"===e?.editMode?.editMode&&(ce=e?.editMode?.specs?.modalHeight||"fit-content",me=e?.editMode?.specs?.modalWidth||"300",_e=e?.editMode?.specs?.modalMinHeight,fe=e?.editMode?.specs?.modalMinWidth,Ie=e?.editMode?.specs?.modalIcon||"window",Ee=e?.editMode?.specs?.modalTitle||"Record Form");const{Window:Ne,setWindowState:Oe}=jt({height:ce,minHeight:_e,minWidth:fe,onCloseCallBack:()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},width:me,windowIcon:Ie,windowTitle:Ee}),ye={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=j[o[ae]]?.mode===T.Edit;if("row"===e.editMode.editMode&&i)ne&&(r.push(_(c,{icon:_(Re,{icon:"save"}),label:t("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const t=e[ae];$({...j,[t]:{mode:T.View}})})(o)}})),r.push(_(c,{icon:_(Re,{icon:"cancel"}),label:t("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const t=e[ae];t&&ba(t)&&t<0?($({...j,[t]:{mode:T.View,ignoreModifications:!0}}),re(e=>{const i=e.filter(e=>e[ae]!=t);return i})):$({...j,[t]:{mode:T.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 a=!1;e?.editAction?.isActionDisabledForRecord&&(a=e?.editAction?.isActionDisabledForRecord(o)),ne&&i&&r.push(_(c,{disabled:a,icon:_(z,{title:t("EDIT_BTN_LABEL"),children:_(Re,{icon:"edit",style:{color:a?"gray":void 0}})}),showInMenu:e?.editAction?.gridActionProps?.showInMenu||!1,label:t("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{ne&&!a&&(async t=>{if(t)if(Q(t),"form"===e.editMode.editMode)V(e.editMode.specs.formRoute+"/"+t[ae]);else if("modal"===e.editMode.editMode)Oe(!0);else if("row"===e?.editMode?.editMode){const e=t[ae];$({...j,[e]:{mode:T.Edit}})}})(o)}}))}if(e?.deleteAction&&!0===e?.deleteAction?.isEnabled){let i=!0;e?.deleteAction?.isActionVisibleForRecord&&(i=e?.deleteAction?.isActionVisibleForRecord(o));let a=!1;e?.deleteAction?.isActionDisabledForRecord&&(a=e?.deleteAction?.isActionDisabledForRecord(o)),le&&i&&r.push(_(c,{disabled:a,icon:_(z,{title:t("DELETE_BTN_LABEL"),children:_(Re,{icon:"trash",style:{color:a?"gray":void 0}})}),showInMenu:e?.deleteAction?.gridActionProps?.showInMenu||!1,label:t("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(le&&!a){if(e?.deleteAction?.preActionValidation&&!e.deleteAction.preActionValidation(o))return;K(o),pe(!0)}}}))}}}if(o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.attachment&&r?.push(_(c,{icon:_(z,{title:"Attachments",children:_(Re,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{a(o),d(!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(o)),s(!0)}})),o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.workFlowDocumentCode&&r?.push(_(c,{icon:_(z,{title:"Approvals",children:_(Re,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{a(o),I(!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(_(Qa,{...t,record:o,reloadData:async()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)}}));return r}};let he=[];(void 0===e?.disableDefaultAction||!e.disableDefaultAction||e?.rowActions&&e?.rowActions.length>0)&&he.push(ye),he=[...he,...N];Ae(()=>{void 0!==e?.autoLoad&&!0!==e.autoLoad||e.apiActions.reloadData(e?.gridLoadParametersValues),te()},[]),Ae(()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},[Y.UserInfo?.currentOrganization]),Ae(()=>{te()},[C,e.formElements]);const Le=ue.useMemo(()=>{const e=he.map(e=>({...e}));if(g.length){const t=new Map(e.map(e=>[e.field,e]));return g.map(e=>t.get(e)).filter(Boolean)}return e},[g,b,he]);return A(f,{children:[_(se,{}),"modal"===e?.editMode?.editMode?_(Ne,{children:e?.editMode?.specs?.formComponent?_(e.editMode.specs.formComponent,{recordIdToEdit:H?H[ae]:void 0,formCloseCallBk:()=>{Oe(!1),e.apiActions.reloadData(e?.gridLoadParametersValues)}}):_(rr,{keyColumnName:e.keyColumnName,attachment:e.attachment,formValuesChangeCallBk:e?.formProps?.formValuesChangeCallBk,recordIdToEdit:H?H[ae]:void 0,formCloseCallBk:()=>{Oe(!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})}):_(f,{}),void 0!==e?.hideInfoBar||e?.hideInfoBar?_(f,{}):A(S,{sx:{display:"flex"},children:[void 0!==e?.hideBackButton||e?.hideBackButton?_(f,{}):_(x,{onClick:()=>{V(-1,{replace:!0})},children:_(Re,{icon:"ltr"===C?"arrow-left":"arrow-right"})}),A(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[e?.girdIcon?_(Re,{icon:e.girdIcon,style:{marginRight:5,marginLeft:5}}):_(f,{}),_(w,{variant:"h5",children:e?.gridTitle?Ua(t(e?.gridTitle)):""})]})]}),e?.gridLoadParameters&&e?.gridLoadParameters.length>0&&e?.gridLoadParametersValues&&e?.setGridLoadParametersValues?A(X,{defaultExpanded:!0,sx:{width:"100%"},children:[_(J,{expandIcon:_(m,{}),children:A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[_(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),_(w,{component:"span",children:"Filters"})]})}),_(ee,{children:_(S,{children:_(rr,{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})})})]}):_(f,{}),e?.attachment?_(l,{children:_(Ga,{attachmentCode:e.attachment.attachmentCode,refKey:o[e?.keyColumnName||"id"],enableAttachment:r})}):_(f,{}),e?.workFlowDocumentCode?_(p,{children:_(ar,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:o[e?.keyColumnName||"id"],postActionCallBk:()=>{I(!1),e.apiActions.reloadData(e.gridLoadParametersValues)},cancelActionCallBk:()=>{I(!1),e.apiActions.reloadData(e.gridLoadParametersValues)}})}):_(f,{}),_(u,{...e?.muiProps,slots:{toolbar:Ha},slotProps:{toolbar:{templateProps:{...e,rowSelectionModel:ie,data:e?.data},handleCreateNewRecord:()=>{if("form"===e?.editMode?.editMode)V(e.editMode.specs.formRoute);else if("modal"===e?.editMode?.editMode)Q(null),Oe(!0);else if("row"===e?.editMode?.editMode){Za-=1;const e={};e[ae]=Za,e.isNew=!0;for(const t of N)"actions"!=t?.type&&t?.field!=ae&&t?.field&&(e[t.field]=null);re(t=>[e,...t]),$(e=>({...e,[Za]:{mode:T.Edit}}))}},clearGridState:()=>{e?.gridStateKey&&localStorage.removeItem(e.gridStateKey),P({}),M([]),U({}),F([]),G({left:[..."ltr"===C?Xa:[]],right:[..."rtl"===C?Xa:[]]})}}},getRowId:e=>e[ae],showToolbar:!0,rows:e?.data,columns:Le,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==e.editMode.editMode?j:void 0,onRowModesModelChange:"row"==e.editMode.editMode?e=>{$(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 Ge.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 De.error(_("div",{style:{},children:e.map(e=>A(f,{children:[_("div",{children:e}),_(Z,{})]}))})),new Error(o)}if(e?.editAction?.preActionValidation&&!e.editAction.preActionValidation(t))throw new Error("error on the configured presave validation");const a={...t};if(t[ae]&&ba(t[ae])&&Number(t[ae])<0&&(a[ae]=null),i=await e.apiActions.saveRecord(a),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&&re(e=>{const o=e.filter(e=>e[ae]!==t[ae]);return[i,...o]}),!0===e?.editMode?.reloadAfterSave&&e?.apiActions?.reloadData&&e?.apiActions?.reloadData(e?.gridLoadParametersValues),i}},rowSelectionModel:ie,onRowSelectionModelChange:e=>{oe(e)},columnVisibilityModel:D,onColumnVisibilityModelChange:t=>{P(t),e?.gridStateKey&&$a(e.gridStateKey,{columnVisibilityModel:t})},onColumnOrderChange:t=>{const{column:i,targetIndex:o}=t;M(t=>{const a=t.length?[...t]:he.map(e=>e.field),r=a.indexOf(i.field);return-1===r||(a.splice(r,1),a.splice(o,0,i.field),e?.gridStateKey&&$a(e.gridStateKey,{columnOrder:a})),a})},rowGroupingModel:v,onRowGroupingModelChange:t=>{(t=>{F(t),e?.gridStateKey&&$a(e.gridStateKey,{columnGroupingModel:t})})(t)},sx:{width:"100%"}})]})},er=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},tr=e=>{const[t,i]=Te([]);return Ae(()=>{const t=e.reportData.map((e,t)=>({...e,report_record_data_key:t}));i(t)},[e.reportData]),_(Ja,{data:t,disableDefaultAction:!0,setData:e.setReportData,formElements:er(e.reportData),gridLoadParameters:e.gridLoadParameters,gridLoadParametersValues:e.gridLoadParametersValues,setGridLoadParametersValues:e.setGridLoadParametersValues,editMode:{editMode:"none"},girdIcon:"file-excel",gridTitle:"Report",autoLoad:!0,keyColumnName:"report_record_data_key",hideInfoBar:!0,apiActions:{deleteRecordById:async()=>!0,loadRecordById:async()=>{},reloadData:async()=>{e.reloadReport()},saveRecord:async()=>{}}})},ir=e=>{console.log("useParameterPanel","useParameterPanel called");const[t,i]=Te({...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:a}=be();return A(X,{defaultExpanded:!0,sx:{width:"100%"},children:[_(J,{expandIcon:_(Re,{icon:{prefix:"far",iconName:"square-caret-down"}}),children:A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[_(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),_(w,{component:"span",children:"Filters"})]})}),_(ee,{children:_(S,{children:_(rr,{saveButtonSpecs:{label:a("Filter"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:a("RESET_BTN_LABEL"),icon:"eraser",hidden:!0,actionButtonVariant:"outlined",actionButtonColor:"error"},actions:[{label:a("RESET_BTN_LABEL"),icon:"eraser",isIdRequired:!1,formActionProps:{enabled:!0},actionFn:async(e,t)=>{i({})}}],apiActions:{deleteRecordById:async()=>!0,saveRecord:async o=>{i(null!=o?o:{}),e&&await e(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:o})})})]})},parametersValues:t,setParametersValues:i,panelElements:o}},or=e=>{const[t,i]=Te(null),[o,a]=Te(null),[r,d]=Te([]),[n,l]=Te("WAITING_REPORT_CODE"),{handleGetRequest:s,handlePostRequest:p,HandleDownloadHTTPPostPDF:c}=Ht(),[m,u]=Te(null),{ParameterPanel:T,parametersValues:I,panelElements:E,setParametersValues:N}=ir({parameters:m?.reportParameters||[],initialParameterValues:{...e?.reportParametersValues}}),O=async t=>{l("WAITING_RESULT"),"Excel"===m?.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"),d(e.data)}}):m?.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");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),a=document.createElement("a");a.href=i,a.download=o,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(i)}},failureCallBkFn:e=>{a("Failed To run report ... contact your administrator"),l("ERROR")}})};return Ae(()=>{e?.reportCode&&(async()=>{l("LOADING_METADATA"),await s({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:e.reportCode},successCallBkFn:t=>{u(t.data),!0===e?.byPassParameterEntry||0==t.data.reportParameters.length?(O(I),l("WAITING_RESULT")):l("WAITING_PARAMETER_INPUT")},failureCallBkFn:e=>{a("Failed loading report metadata ... contact your administrator"),l("ERROR")}})})()},[e.reportCode,e.byPassParameterEntry,e.reportParametersValues,e.jasperOutPutFileType,e.resultMode]),A(f,{children:[A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[A(S,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[_(Re,{icon:"Excel"===m?.reportType?"file-excel":"file-pdf",color:"Excel"===m?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),m?.reportName]}),"Excel"!=m?.reportType&&"SHOWING_RESULT"===n?A(f,{children:[!0===e?.byPassParameterEntry?_(f,{}):m?.reportParameters.length>0?_(x,{onClick:()=>{l("WAITING_PARAMETER_INPUT")},children:_(Re,{icon:"filter"})}):_(f,{}),_(x,{children:_(Re,{icon:"refresh",onClick:()=>{O(I)}})})]}):_(f,{})]}),_(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===n&&"Excel"!=m?.reportType?_(T,{searchBtnClickCallBk:O}):"SHOWING_RESULT"===n||("WAITING_PARAMETER_INPUT"===n||"WAITING_RESULT"===n)&&"Excel"===m?.reportType?"Excel"===m?.reportType?_(tr,{reportData:r,setReportData:d,reloadReport:async()=>{O(I)},gridLoadParameters:E,gridLoadParametersValues:I,setGridLoadParametersValues:N}):_("iframe",{src:t,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===n?A(S,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[_(Re,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),o]}):_(f,{})})]})},ar=e=>{const t=ve(),i=E(e=>e.AppLayout),{isUserAuthorized:o,UserInfo:a}=Zt(),{handleGetRequest:r,handlePostRequest:d}=Ht(),[n,l]=Te(null),[s,p]=Te([]),{t:c}=be(),[m,u]=Te(null),[T,I]=Te({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:N,setWindowState:O}=jt({windowTitle:"ltr"===i.appDirection?T?.workflowDocument&&T?.referencedDocument?`${T?.workflowDocument?.documentEnName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`:"Document":T?.workflowDocument&&T?.referencedDocument?`${T?.workflowDocument?.documentArName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),y=async()=>{await r({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:e.workFlowDocumentCode,refDocumentId:e.refDocumentId},successCallBkFn:e=>{I(e.data)},failureCallBkFn:()=>{I({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},h=async()=>{await d({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:T?.workflowDocument?.id,refDocumentId:e.refDocumentId,actionId:n.id,refDocumentStatus:T?.workflowDocumentStatus?.documentStatusCode,actionComment:m},successCallBkFn:async t=>{n?.post_action_endpoint?await d({endPointURI:n.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:n.id},successCallBkFn:()=>{y(),e?.postActionCallBk&&e.postActionCallBk()}}):y()}})};return Ae(()=>{e.refDocumentId&&e.workFlowDocumentCode&&y()},[e.refDocumentId,e.workFlowDocumentCode]),Ae(()=>{p(T?.nextActions&&T?.nextActions?.length>0?T.nextActions.filter(e=>{if(!T?.workflowDocumentStatus?.nextActionTakersAuthority&&!T?.nextActionTakers)return!0;if(T?.workflowDocumentStatus?.nextActionTakersAuthority&&o(T.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(T?.nextActionTakers)for(const e of T.nextActionTakers)if(a?.username===e?.username||a?.username===e?.USERNAME)return!0;return!1}):[])},[T.nextActions,T.nextActionTakers]),A(f,{children:[T?.workflowDocumentReport?.id?_(N,{children:_(or,{reportCode:T?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:e.refDocumentId+""}})}):_(f,{}),T?.workflowDocument?A(S,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[_(x,{onClick:()=>{t(-1,{replace:!0})},children:_(Re,{icon:"arrow-left"})}),_(S,{sx:{flex:1}}),_(Re,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===i.appDirection?`${T?.workflowDocument?.documentEnName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`:`${T?.workflowDocument?.documentArName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`,T?.workflowDocumentStatus?"ltr"===i.appDirection?` ( ${T?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${T?.workflowDocumentStatus?.documentStatusArName} )`:"",_(S,{sx:{flex:1}}),T?.workflowDocumentReport?.id?_(M,{onClick:()=>{O(!0)},variant:"outlined",startIcon:_(Re,{icon:"eye"}),children:c("VIEW_LABEL")}):_(f,{})]}):_(f,{}),A(S,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[s?.length>0?A(F,{sx:{padding:2,display:"flex",flex:1,margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[_(ni,{sx:{marginBottom:2,width:400},label:c("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===i.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:n?.id,options:s,onChangeCallBack:(e,t)=>{l(t)}}),_(ii,{sx:{width:400},rows:3,value:m,onChange:e=>{u(e.target.value)},multiline:!0,label:c("WF_COMMENT_LABEL")}),A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[_(M,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=n&&null!=n?.id?!0!==n.require_comment&&1!==n.require_comment&&"true"!==n.require_comment||null!==m&&""!==m?n?.pre_action_endpoint?await d({endPointURI:n.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:n.id},successCallBkFn:()=>{h()}}):h():De.error("You must enter comment for the action to be processed"):De.error("You must select action to process")},children:c("WF_TAKE_ACTION_BTN_LABEL")}),e?.cancelActionCallBk?_(M,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{e?.cancelActionCallBk&&e.cancelActionCallBk()},children:c("WF_CANCEL_BTN_LABEL")}):_(f,{})]}),T?.nextActionTakers&&T.nextActionTakers.length>0?A(f,{children:[_(Z,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:A(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[_(Re,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",c("WF_WAITING_FOR_LABEL")]})}),_(S,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:T.nextActionTakers.map(e=>A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[_(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:e?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),A(S,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[_("div",{children:"ltr"===i.appDirection?e?.employee_en_name:e?.employee_ar_name}),_("div",{children:e?.email?A(f,{children:[_(Re,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),e?.email]}):_(f,{})}),_("div",{children:e?.mobile_number?A(f,{children:[_(Re,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),e?.mobile_number]}):_(f,{})})]})]}))})]}):_(f,{})]}):_(f,{}),T?.actionsHistory.length>0?_(Ya,{actionHistory:T.actionsHistory}):A(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[A(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[_(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),c("WF_ACTION_HISTORY_LABEL")]}),_(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},rr=e=>{const{Window:t,setWindowState:i}=jt({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),{Window:o,setWindowState:a}=jt({windowTitle:"Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[r,d]=Te(!0),{t:n}=be(),l=yi(e.elements),s=[];for(const e of l)e?.hidden&&s.push(e.fieldName);const[p,c]=Te(s),m={};for(const t of e.elements)"field"===t?.type&&"props"===t?.mode&&t?.props?.defaultValue&&(m[t.props.fieldName]=t.props.defaultValue);const[u,T]=Te([]);let I=null;I=e?.validationSchema?e.validationSchema:We.object(Ri(l));const E=Ue({resolver:ke(I),defaultValues:m}),N=E.watch(),O=we(),y=e?.formRouteRecordIdParamName,h=async()=>{let t=null;if(e?.recordIdToEdit?t=e.recordIdToEdit:y&&O[y]&&(t=O[y]),t){const i=await e.apiActions.loadRecordById(t);if(i){E.reset({...i}),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk({...i},R,E);for(const e of l)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?E.setValue(e.fieldName,i[e.fieldName]+""):E.setValue(e.fieldName,i[e.fieldName]))}}else E.reset({})},R={setFieldValue:(e,t)=>{E.setValue(e,t)},hideField:e=>{c(t=>[...t,e])},showField:e=>{c(t=>t.filter(t=>t!==e))},disableField:e=>{T(t=>[...t,e])},enableField:e=>{T(t=>t.filter(t=>t!==e))}};return Ae(()=>{h()},[e?.recordIdToEdit]),Ae(()=>{d(!e?.attachment||!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(N))},[N]),A(f,{children:[e?.attachment?_(t,{children:_(Ga,{attachmentCode:e.attachment.attachmentCode,refKey:N[e?.keyColumnName||"id"],enableAttachment:r})}):_(f,{}),e?.workFlowDocumentCode?_(o,{children:_(ar,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:N[e?.keyColumnName||"id"],postActionCallBk:()=>{a(!1),h()},cancelActionCallBk:()=>{a(!1)}})}):_(f,{}),_(ga,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:_(k,{sx:{width:"100%"},container:!0,children:e.elements.map((t,i)=>"group"===t.type?_(Ba,{...t.props,formManager:E,formValues:N,formActions:R,hiddenFields:p,disabledFields:u},i):"field"===t.type&&"props"===t.mode?_(xa,{fieldInfo:t.props,formManager:E,formValues:N,formActions:R,hiddenFields:p,disabledFields:u,formValuesChangeCallBk:e.formValuesChangeCallBk},i):"field"===t.type&&"node"===t.mode?_(k,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:_(t.node,{formManager:E,formValues:N})},i):void 0)})}),A(ga,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[N[e?.keyColumnName||"id"]&&e?.attachment?_(z,{title:"Attachments",children:_(x,{onClick:()=>{i(!0)},children:_(Re,{icon:"paperclip"})})}):null,N[e?.keyColumnName||"id"]&&e?.workFlowDocumentCode?_(z,{title:"Approvals",children:_(x,{onClick:()=>{a(!0)},children:_(Re,{icon:"stamp"})})}):null,e?.actions?e.actions.map(t=>!1===t?.isIdRequired?_(Fa,{...t,record:N}):N[e?.keyColumnName||"id"]?!0===t?.formActionProps?.enabled?_(Fa,{...t,record:N}):_(f,{}):void 0):_(f,{}),_("div",{style:{flex:1}}),e?.saveButtonSpecs?.hidden?_(f,{}):_(M,{variant:e?.saveButtonSpecs?.actionButtonVariant?e.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:e?.saveButtonSpecs?.icon?_(Re,{icon:e.saveButtonSpecs.icon}):null,color:e?.saveButtonSpecs?.actionButtonColor?e.saveButtonSpecs.actionButtonColor:"primary",onClick:E.handleSubmit(t=>{(async t=>{if((!e?.preSaveValidation||e.preSaveValidation(t))&&t){const i=await e.apiActions.saveRecord(t);i&&(E.reset({...i}),e?.formSavedSuccessfullyCallBk&&e.formSavedSuccessfullyCallBk(i),e?.formCloseCallBk&&e.formCloseCallBk())}})(t)},e=>{De.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?_(f,{}):_(M,{variant:e?.cancelButtonSpecs?.actionButtonVariant?e.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:e?.cancelButtonSpecs?.icon?_(Re,{icon:e.cancelButtonSpecs.icon}):null,color:e?.cancelButtonSpecs?.actionButtonColor?e.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{e?.formCloseCallBk&&e.formCloseCallBk(),E.reset(m)},children:n(e?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},dr=()=>{const{workflowDocumentCode:e,refDocumentId:t}=we();return _(ar,{workFlowDocumentCode:e,refDocumentId:t})},nr=e=>_(rt,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),lr=e=>A(F,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[_(S,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:_("div",{children:e.record[e.valueField]})}),_(w,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]})]}),sr=e=>A(f,{children:[_(w,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),_(dt,{width:200,height:200,value:e.record[e.valueField],valueMax:e.total})]}),pr=e=>_(nt,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function cr(e){return A(st,{sx:{display:"flex",alignItems:"center"},children:[_(st,{sx:{width:"100%",mr:1},children:_(lt,{variant:"determinate",...e})}),_(st,{sx:{minWidth:35},children:_(at,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(e.value)}%`})})]})}const mr=e=>A(st,{sx:{width:"100%"},children:[_(at,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),_(cr,{value:e.record[e.valueField]/e.total*100})]}),ur=e=>{const t=e.data.map((t,i)=>({id:i,value:t[e.valueField],label:t[e.labelField]+""}));return _(pt,{series:[{data:t}]})},Tr=e=>{const[t,i]=Te(!0),[o,a]=Te([]),{handleGetRequest:r}=Ht();Ae(()=>{e.loadWidget?(async()=>{i(!0),await r({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e.parameterValues},successCallBkFn:e=>{i(!1),a(e.data)},failureCallBkFn:()=>{i(!1),a([])}})})():i(!1)},[e.loadWidget,e.loadCounter]);let d=0;if(1==o.length)d=100;else if("CircularProgress"===e.widgetType||"LinearProgress"===e.widgetType)for(const t of o)d+=t[e.verticalAxisField];return A(f,{children:["LineChart"===e.widgetType||"PieChart"===e.widgetType||"ColumnChart"===e.widgetType?A(S,{children:[_(Re,{style:{marginRight:10,marginLeft:10},icon:e?.icon||"chart-pie"}),e?.title]}):_(f,{}),_(S,{sx:{flex:1,padding:1,height:"90%",display:"flex",alignItems:"center",justifyContent:"center",width:"90%"},children:t?A(f,{children:[_(Re,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),_("div",{children:"Loading"})]}):"ColumnChart"===e.widgetType?_(nr,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===e.widgetType?_(pr,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===e.widgetType?_(ur,{data:o,widgetTitle:e.title,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,widgetType:"Pie"}):A(k,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[_(k,{size:{xs:12},sx:{textAlign:"center"},children:e.title}),o.map((t,i)=>"Card"===e.widgetType?_(k,{size:{md:3,xs:12},children:_(lr,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField},i)}):"CircularProgress"===e.widgetType?_(k,{size:{md:3,xs:12},children:_(sr,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:d},i)}):"LinearProgress"===e.widgetType?_(k,{size:{md:3,xs:12},children:_(mr,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:d},i)}):void 0)]})})]})},Ar=e=>{const[t,i]=Te({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),{ParameterPanel:o,parametersValues:a}=ir({parameters:t?.dashboardParameters||[],initialParameterValues:{}}),[r,d]=Te(0),[n,l]=Te(!1);Ae(()=>{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===a[i.parameterCode]||null===a[i.parameterCode]||""===a[i.parameterCode])){e=!1;break}e&&l(e),d(r+1)}},[t?.dashboardParameters,a]);const s=ve(),{handleGetRequest:p,handlePostRequest:c}=Ht();return Ae(()=>{e.dashboardCode&&(async()=>{await p({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:e.dashboardCode},successCallBkFn:e=>{i(e.data)},failureCallBkFn:()=>{i(null)}})})()},[e.dashboardCode,e.parameters]),_(f,{children:t?A(f,{children:[A(S,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[_(x,{onClick:()=>{s(-1,{replace:!0})},children:_(Re,{icon:"arrow-left"})}),_(S,{sx:{flex:1}}),_(Re,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),_(S,{children:t?.dashboardTitle}),_(S,{sx:{flex:1}})]}),t?.dashboardParameters.length>0?_(o,{searchBtnClickCallBk:async e=>{d(r+1)}}):_(f,{}),_(k,{container:!0,spacing:1,sx:{height:"fit-content",overflowY:"auto",padding:1},children:t?.widgets.map((e,t)=>_(k,{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:_(Tr,{...e,parameterValues:a,loadWidget:n})},t))})]}):_(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},_r=()=>{const{dashboardCode:e}=we();return _(Ar,{dashboardCode:e})},fr=e=>{const{UserSession:t}=Zt(),i=E(e=>e.AppLayout),o=I(),{handlePostRequest:a}=Ht(),[r,d]=Te(t.value.currentOrganization.id);return A(S,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[_(ni,{sx:{width:"100%"},displayField:"ltr"===i.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:t.value.userOrganizations,value:r,onChangeCallBack:e=>{d(e)}}),_(M,{sx:{m:1},variant:"contained",disabled:null==r||r===t.value.currentOrganization.id,onClick:async()=>{await a({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:t.value.username,orgId:r},data:{},successCallBkFn:t=>{const i={...t.data,isAuthenticated:!0};o(Kt.setAuthenticated(i)),e.successChangeCallBackFn&&e.successChangeCallBackFn()}})},children:"Change Organization"})]})},Ir=Le({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Er,setSideBarState:Nr}=Ir.actions;var Or=Ir.reducer;function yr(e,t){const i=fe(e);Ae(()=>{i.current=e},[e]),Ae(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const hr=te`
31
+ function(e,t){const i=Mt(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})(Ea),d=me.forwardRef(function(e,d){const n=function(e=ya){return Oa(e)}(i),{className:l,component:s="div",...p}=ha(e);return _(r,{as:s,ref:d,className:Da(l,a?a(o):o),theme:t&&n[t]||n,...p})});return d}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=Pa[t];return o?`${i}-${o}`:`${La.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:La.generate});function Ma(e){return/^\d+$/.test(e)}function ba(e){return"number"==typeof e&&!isNaN(e)}function Sa(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function Ua(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function va(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function wa(e,t){const i=new Date(e),o=new Date,a=Math.floor((i-o)/1e3),r="rtl"===t?"ar":"en",d=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=[{unit:"year",seconds:31536e3},{unit:"month",seconds:2592e3},{unit:"week",seconds:604800},{unit:"day",seconds:86400},{unit:"hour",seconds:3600},{unit:"minute",seconds:60},{unit:"second",seconds:1}];for(const{unit:e,seconds:t}of n){const i=Math.floor(a/t);if(Math.abs(i)>1)return d.format(i,e)}return"ar"===r?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(ga.propTypes={children:io.node,component:io.elementType,sx:io.oneOfType([io.arrayOf(io.oneOfType([io.func,io.object,io.bool])),io.func,io.object])});const xa=e=>{if(e?.fieldInfo){const t=e.fieldInfo,i=e?.formManager||null,o=e?.formActions||null,a=e?.formValues||null,r=e?.fieldInfo?.fieldName||null,d=e?.fieldInfo?.fieldType||null;if(!(t&&i&&a&&r&&d))return _(f,{});const n=()=>e?.fieldInfo?.formProps?.fieldLabelFn?e.fieldInfo.formProps.fieldLabelFn(a):e?.fieldInfo?.fieldLabel?e?.fieldInfo?.fieldLabel:void 0;return e.hiddenFields.includes(r)?_(f,{}):_(k,{size:t?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===d||"number"===d?_(ii,{...t.muiTextFieldProps,fullWidth:!0,type:d,disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),label:n(),value:a[r],onChange:t=>{let n=null;""!=t.target.value&&(n="number"===d&&Sa(t.target.value)?Number(t.target.value):t.target.value),i.setValue(r,n),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,n)},sx:{"& .MuiInputBase-root":{height:`${t?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...t?.formProps?.style},error:null!=i.formState.errors[r],helperText:i?.formState?.errors[r]?.message?.toString()}):"date"===t?.fieldType?_(Ti,{format:t?.dateFormat||li,sx:t?.formProps?.style||{width:"100%"},disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),label:n(),onChangeCallBack:t=>{i.setValue(r,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t)},value:a[r],error:null!=i.formState.errors[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):"datetime"===t?.fieldType?_(Ai,{format:t?.dateFormat||si,sx:t?.formProps?.style||{width:"100%"},disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),label:n(),onChangeCallBack:t=>{i.setValue(r,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t)},value:a[r],error:null!=i.formState.errors[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):"checkbox"===t?.fieldType?_(di,{label:n(),onChangeCallBack:t=>{i.setValue(r,t),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t)},value:a[r],checkedValue:t?.checkedValue||!0,unCheckedValue:t?.unCheckedValue||!1,disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),sx:t?.formProps?.style}):"combobox"===t?.fieldType?_(ni,{sx:t?.formProps?.style||{width:"100%"},label:n(),disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),onChangeCallBack:(t,d)=>{let n=null;t&&(n=t),i.setValue(r,n),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t,d)},options:t?.options||[],displayField:t?.optionDisplayField||"",valueField:t?.optionValueField||"",value:a[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):"lookup"===t?.fieldType?_(_i,{sx:t?.formProps?.style||{width:"100%"},label:n(),disabled:!(!t?.disabled&&!e.disabledFields.includes(r)),onChangeCallBack:(t,d)=>{let n=null;t&&(n=t),i.setValue(r,n),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk(a,o,i,r,t,d)},lookupType:t.lookupType,value:a[r],errorMessage:i?.formState?.errors[r]?.message?.toString()}):null})}return _(f,{})},Fa=e=>{const t=Zt(),{ConfirmationWindow:i,setOpen:o}=Qt({body:e?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{e?.actionFn(e?.record)}});return null==e?.authority||t.isUserAuthorized(e.authority)?A(f,{children:[_(i,{}),A(M,{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?_(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}):_(f,{}),_("div",{children:e?.label})]})]}):_(f,{})},Ba=e=>{const{t:t}=be();return _(f,{children:A(k,{container:!0,sx:e?.style,alignItems:"flex-start",children:[e?.label?_(k,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:e?.icon?A(f,{children:[_(Re,{icon:e.icon,style:{marginRight:5,marginLeft:5}}),_("div",{children:t(e.label)})]}):_(f,{children:t(e.label)})}):_(f,{}),e?.elements?e.elements.map(t=>"group"===t.type?_(Ba,{...t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields}):"field"===t.type&&"props"===t.mode?_(xa,{fieldInfo:t.props,formManager:e.formManager,formValues:e.formValues,formActions:e.formActions,hiddenFields:e.hiddenFields,disabledFields:e.disabledFields}):"field"===t.type&&"node"===t.mode?_(k,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:_(t.node,{formManager:e.formManager,formValues:e.formValues,formActions:e.formActions})}):void 0):null,e?.actions?_(k,{size:{sm:12},sx:{padding:1},children:e.actions.map(t=>_(Fa,{...t,record:e.formValues}))}):_(f,{})]})})},ka=e=>{const t=E(e=>e.AppInfo.value.apiBaseUrl),[i,o]=Te(null);return Ae(()=>{(()=>{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]),e?.showAsAvatar?_(K,{sx:e.style,onError:()=>{o(e?.onErrorImage?e.onErrorImage:"/no_image.png")},src:i}):_("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"}})},Wa=e=>{const{handleGetRequest:t,handleDeleteRequest:i}=Ht(),{isUserAuthorized:o}=Zt();let a=!0;e?.downloadAuthorityKey&&(a=o(e.downloadAuthorityKey));const{ConfirmationWindow:r,setOpen:d}=Qt({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 A(f,{children:[_(r,{}),A(Ve,{sx:{width:300,border:"0.5px solid gray"},children:[_(ot,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:e?.docType.toLocaleLowerCase().includes("image")?_(ka,{attachmentId:e.id}):_(Re,{icon:"file",size:"3x"})}),A(it,{children:[_(at,{gutterBottom:!0,variant:"h6",component:"div",children:e.fileName}),_(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${e?.attachmentSize||"unknown"} kb`}),_(at,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${e?.category||"NA"}`}),_(at,{variant:"body2",sx:{color:"text.secondary"},children:e.remark})]}),A(tt,{children:[e?.allowDelete?_(x,{size:"small",onClick:()=>{d(!0)},children:_(z,{title:"Delete Attachment",children:_(Re,{icon:"trash"})})}):_(f,{}),_("div",{style:{flex:1}}),a?_(x,{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:_(z,{title:"Download Attachment",children:_(Re,{icon:"download"})})}):_(f,{})]})]})]})},Ga=e=>{const{handleUploadRequest:t,handleGetRequest:i}=Ht(),[o,a]=Te(null),[r,d]=Te([]),[n,l]=Te(null),[s,p]=Te(null),[c,m]=Te([]),[u,T]=Te(null),{isUserAuthorized:I}=Zt(),E=e=>e.split(".").pop()?.toLowerCase()||"";Ae(()=>{(async()=>{await i({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:e.attachmentCode,refKey:e.refKey},successCallBkFn:e=>{T(e.data)}})})()},[e.refKey,e.attachmentCode]),Ae(()=>{if(m(u?.allowedFileTypes?u.allowedFileTypes.split(","):[]),u?.attachmentCategories){const e=[];for(const t of u.attachmentCategories.split(","))e.push({value:t});d(e)}else d([])},[u]);let N=!0;u?.downloadAuthorityKey&&!I(u?.downloadAuthorityKey)&&(N=!1);let O=!0;return!1===e?.enableAttachment&&(O=!1),u?.uploadAuthorityKey&&!I(u.uploadAuthorityKey)&&(O=!1),A(F,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[_(f,O?{children:null==u?.maxAllowedNumberOfFiles||u?.maxAllowedNumberOfFiles>u.refKeyAttachments.length?A(f,{children:[A("h3",{children:[_(Re,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),_("input",{type:"file",style:{margin:20},accept:u?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=E(t.name);if(c.length>0&&!c.includes(e))return void De.error(e+" is not allowed")}a(e.target.files)}}),r.length>0?_(ni,{label:"Attachment Type",sx:{width:300,m:1},options:r,displayField:"value",valueField:"value",value:s,onChangeCallBack:e=>{p(e)}}):_(f,{}),_(ii,{label:"Remark",value:n,onChange:e=>l(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),_(M,{sx:{m:1},variant:"contained",onClick:async()=>{let i=u?.refKeyAttachments.length||0;if(u?.maxAllowedNumberOfFiles&&o.length+i>u.maxAllowedNumberOfFiles)De.error("Maximum number of attachments is "+u.maxAllowedNumberOfFiles);else if(!0===u?.isCategoryRequired&&r.length>0&&(null==s||void 0===s||""===s))De.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 De.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:n,category:s},files:o,successCallBkFn:e=>{T(e.data),a(null),p(null),l(null),De.success("Your request has been process successfully")}})}else De.error("You must add files to upload")},children:"Upload"})]}):_(f,{})}:{}),N&&u?.refKeyAttachments?.length>0?A(f,{children:[A("h3",{children:[_(Re,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),_(k,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:u?.refKeyAttachments.map(t=>_(k,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:_(Wa,{...t,attachmentCode:e.attachmentCode,setAttachmentConfig:T,downloadAuthorityKey:u.downloadAuthorityKey,allowDelete:O})}))})]}):_(f,{})]})},Ya=e=>{const t=E(e=>e.AppLayout),{t:i}=be();return A(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[A(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[_(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),i("WF_ACTION_HISTORY_LABEL")]}),_(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:e.actionHistory.map((i,o)=>_(f,{children:A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[A(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[_(S,{sx:{marginBottom:.2},children:i.actionTime}),A(at,{children:["via ",i.actionMethod]})]}),A(S,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[_(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:i?.personId+""||"0",style:{m:1,width:70,height:70}}),o!==e.actionHistory.length-1?_(S,{sx:{marginTop:11,position:"absolute"},children:"|"}):_(f,{})]}),A(S,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[A(S,{sx:{width:"100%"},children:["ltr"===t.appDirection?`${i?.documentActionEnName}`:`${i?.documentActionArName}`,i?.actionComment?" - "+i.actionComment:""]}),_(S,{sx:{width:"100%"},children:"ltr"===t.appDirection?`${i?.employeeEnName}`:`${i?.employeeArName}`})]})]})}))})]})},Va=e=>{const{t:t}=be(),i=Zt(),{ConfirmationWindow:o,setOpen:a}=Qt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn)),e?.reloadData&&e.reloadData()}});let r=!0;if(e.authority&&(r=i.isUserAuthorized(e.authority)),r)return A(f,{children:[_(o,{}),A(M,{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?a(!0):(await e.actionFn(e.recordsToProcessActionOn,e.recordIdsToProcessActionOn),e?.reloadData&&e.reloadData())}else De.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?_(Re,{style:{marginRight:5,marginLeft:5},icon:e.icon}):_(f,{}),e?.label?t(e.label):_(f,{})]})]})},qa=H(e)({display:"grid",alignItems:"center"}),Ka=H(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"])})),za=H(B)(({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"])})),Ha=e=>{const{t:c}=be(),m=Zt(),u=!e?.templateProps?.editAction?.authority||m.isUserAuthorized(e.templateProps.editAction.authority),T=Li(e?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},e?.templateProps?.data||[],e?.templateProps?.keyColumnName||"id");return A(i,{children:[u&&"none"!=e?.templateProps?.editMode?.editMode?A(M,{onClick:e?.handleCreateNewRecord,children:[_(Re,{icon:"add",style:{marginRight:5,marginLeft:5}}),c("ADD_BTN_LABEL")]}):_(f,{}),e?.templateProps?.rowActions?e.templateProps.rowActions.map((t,i)=>!0===t?.gridActionProps?.multiRecord?_e(Va,{...t,key:i,reloadData:async()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:T.selectedRecordIds,recordsToProcessActionOn:T.selectedRecords}):null):_(f,{}),_(S,{sx:{flex:1,mx:.5,my:.5,padding:1},children:e?.templateProps?.tBar}),_(z,{title:"Columns",children:_(o,{render:_(t,{}),children:_(a,{fontSize:"small"})})}),_(z,{title:"Filters",children:_(r,{render:(e,i)=>_(t,{...e,color:"default",children:_(Q,{badgeContent:i.filterCount,color:"primary",variant:"dot",children:_(d,{fontSize:"small"})})})})}),e?.templateProps?.gridStateKey?_(z,{title:c("RESET_GRID_STATE"),children:_(x,{onClick:e?.clearGridState,children:_(Re,{icon:"eraser"})})}):_(f,{}),_(Z,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),_(z,{title:c("EXPORT_EXECL_LABEL"),children:_(n,{render:_(j,{}),children:_(Re,{icon:"file-excel",color:"green"})})}),A(qa,{children:[_(l,{render:(e,t)=>_(z,{title:c("SEARCH_BTN_LABEL"),enterDelay:0,children:_(Ka,{...e,ownerState:{expanded:t.expanded},color:"default","aria-disabled":t.expanded,children:_(Re,{icon:"search"})})})}),_(s,{render:({ref:e,...t},i)=>_(za,{...t,ownerState:{expanded:i.expanded},inputRef:e,"aria-label":"Search",placeholder:`${c("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:_($,{position:"start",children:_(Re,{icon:"search"})}),endAdornment:i.value?_($,{position:"end",children:_(p,{edge:"end",size:"small","aria-label":"Clear search",children:_(Re,{icon:"xmark"})})}):null,...t.slotProps?.input},...t.slotProps}})})]}),_(x,{onClick:()=>{e.templateProps.apiActions.reloadData(e?.templateProps?.gridLoadParametersValues)},children:_(Re,{icon:"refresh"})})]})},Qa=e=>{const{t:t}=be(),i=Zt(),{ConfirmationWindow:o,setOpen:a}=Qt({body:t(e?.confirmationMessage||"ACTION_CONFIRMATION"),title:t("CONFIRMATION"),onConfirmationCallBk:async()=>{await(e?.actionFn(e.record)),e?.reloadData&&e.reloadData()}});let r=!0;e.authority&&(r=i.isUserAuthorized(e.authority));let d={};e?.getActionIconStyleForRecord&&(d=e.getActionIconStyleForRecord(e.record));let n=!0;e?.isActionVisibleForRecord&&(n=e?.isActionVisibleForRecord(e.record));let l=!1;if(e?.isActionDisabledForRecord&&(l=e.isActionDisabledForRecord(e.record)),r&&n)return A(f,{children:[_(o,{}),_(c,{disabled:l,icon:_(z,{title:e?.label?t(e.label):"",children:_(Re,{icon:e.icon,style:{...d,color:l?"gray":null!=d?.color?d.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?a(!0):(await e.actionFn(e.record),!0===e?.gridActionProps?.reloadGridAfterAction&&e?.reloadData&&e.reloadData())}}})]})};let Za=-1;const ja=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},$a=(e,t)=>{const i=ja(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},Xa=["__check__","actions"],Ja=e=>{const{t:t}=be(),i=E(e=>e.AppLayout),[o,a]=Te({}),[r,d]=Te(!0),{getLookupOptions:n}=(()=>{const{handleGetRequest:e}=Ht(),t=E(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:l,setWindowState:s}=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:p,setWindowState:I}=jt({windowTitle:t(e.gridTitle)+" Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"80%",onCloseCallBack:()=>{e?.apiActions?.reloadData(e.gridLoadParametersValues)}}),[N,O]=Te([]),y=yi(e.formElements),h=[],R=ue.useMemo(()=>e?.gridStateKey?ja(e.gridStateKey):{},[]);for(const e of y)!0===e?.gridProps?.hidden&&h.push(e.fieldName);let L={};if(R?.columnVisibilityModel){L=R.columnVisibilityModel;const e=Object.keys(L);for(const t of h)e.includes(t)||(L[t]=!1)}else for(const e of h)L[e]=!1;const C=E(e=>e.AppLayout.appDirection),[D,P]=ue.useState(L),[g,M]=ue.useState(R.columnOrder||[]),[b,U]=ue.useState(R.columnWidths||{}),[v,F]=Te(R.columnGroupingModel||[]);let B=R?.pinnedColumns?.left||[];B=B.filter(e=>!Xa.includes(e));let k=R?.pinnedColumns?.right||[]||[];k=k.filter(e=>!Xa.includes(e));const[W,G]=Te({left:[..."ltr"===C?Xa:[],...B],right:[..."rtl"===C?Xa:[],...k]}),Y=Zt(),V=ve(),[q,K]=Te(null),[H,Q]=Te(null),[j,$]=Te({}),te=async()=>{let o=hi(y,"row"===e?.editMode?.editMode||!1,t);for(let e of o)e?.lookupType&&(e.displayField="ltr"===i.appDirection?"lookupEnDisplay":"lookupArDisplay",e.options=await n(e.lookupType),e.valueField="lookupValue");O(o)},[ie,oe]=Te({ids:new Set,type:"include"});let ae="id";e?.keyColumnName&&(ae=e?.keyColumnName);const re=e.setData;let de=null;de=e?.validationSchema?e.validationSchema:Ge.object(Ri(y));let ne=!0;e?.editAction?.authority&&(ne=Y.isUserAuthorized(e.editAction.authority));let le=!0;e?.deleteAction?.authority&&(le=Y.isUserAuthorized(e.deleteAction.authority));const{ConfirmationWindow:se,setOpen:pe}=Qt({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let t=!0;q&&!0===q?.isNew||(t=await e.apiActions.deleteRecordById(q[ae])),t&&(e?.deleteAction?.postActionCallBack&&await e.deleteAction.postActionCallBack(q),re(e=>e.filter(e=>e[ae]!=q[ae])))}});let ce,me,_e,fe,Ie,Ee;"modal"===e?.editMode?.editMode&&(ce=e?.editMode?.specs?.modalHeight||"fit-content",me=e?.editMode?.specs?.modalWidth||"300",_e=e?.editMode?.specs?.modalMinHeight,fe=e?.editMode?.specs?.modalMinWidth,Ie=e?.editMode?.specs?.modalIcon||"window",Ee=e?.editMode?.specs?.modalTitle||"Record Form");const{Window:Ne,setWindowState:Oe}=jt({height:ce,minHeight:_e,minWidth:fe,onCloseCallBack:()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},width:me,windowIcon:Ie,windowTitle:Ee}),ye={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=j[o[ae]]?.mode===T.Edit;if("row"===e.editMode.editMode&&i)ne&&(r.push(_(c,{icon:_(Re,{icon:"save"}),label:t("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const t=e[ae];$({...j,[t]:{mode:T.View}})})(o)}})),r.push(_(c,{icon:_(Re,{icon:"cancel"}),label:t("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const t=e[ae];t&&ba(t)&&t<0?($({...j,[t]:{mode:T.View,ignoreModifications:!0}}),re(e=>{const i=e.filter(e=>e[ae]!=t);return i})):$({...j,[t]:{mode:T.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 a=!1;e?.editAction?.isActionDisabledForRecord&&(a=e?.editAction?.isActionDisabledForRecord(o)),ne&&i&&r.push(_(c,{disabled:a,icon:_(z,{title:t("EDIT_BTN_LABEL"),children:_(Re,{icon:"edit",style:{color:a?"gray":void 0}})}),showInMenu:e?.editAction?.gridActionProps?.showInMenu||!1,label:t("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{ne&&!a&&(async t=>{if(t)if(Q(t),"form"===e.editMode.editMode)V(e.editMode.specs.formRoute+"/"+t[ae]);else if("modal"===e.editMode.editMode)Oe(!0);else if("row"===e?.editMode?.editMode){const e=t[ae];$({...j,[e]:{mode:T.Edit}})}})(o)}}))}if(e?.deleteAction&&!0===e?.deleteAction?.isEnabled){let i=!0;e?.deleteAction?.isActionVisibleForRecord&&(i=e?.deleteAction?.isActionVisibleForRecord(o));let a=!1;e?.deleteAction?.isActionDisabledForRecord&&(a=e?.deleteAction?.isActionDisabledForRecord(o)),le&&i&&r.push(_(c,{disabled:a,icon:_(z,{title:t("DELETE_BTN_LABEL"),children:_(Re,{icon:"trash",style:{color:a?"gray":void 0}})}),showInMenu:e?.deleteAction?.gridActionProps?.showInMenu||!1,label:t("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(le&&!a){if(e?.deleteAction?.preActionValidation&&!e.deleteAction.preActionValidation(o))return;K(o),pe(!0)}}}))}}}if(o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.attachment&&r?.push(_(c,{icon:_(z,{title:"Attachments",children:_(Re,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{a(o),d(!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(o)),s(!0)}})),o[e?.keyColumnName||"id"]&&o[e?.keyColumnName||"id"]>0&&e?.workFlowDocumentCode&&r?.push(_(c,{icon:_(z,{title:"Approvals",children:_(Re,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{a(o),I(!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(_(Qa,{...t,record:o,reloadData:async()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)}}));return r}};let he=[];(void 0===e?.disableDefaultAction||!e.disableDefaultAction||e?.rowActions&&e?.rowActions.length>0)&&he.push(ye),he=[...he,...N];Ae(()=>{void 0!==e?.autoLoad&&!0!==e.autoLoad||e.apiActions.reloadData(e?.gridLoadParametersValues),te()},[]),Ae(()=>{e.apiActions.reloadData(e?.gridLoadParametersValues)},[Y.UserInfo?.currentOrganization]),Ae(()=>{te()},[C,e.formElements]);const Le=ue.useMemo(()=>{const e=he.map(e=>({...e}));if(g.length){const t=new Map(e.map(e=>[e.field,e]));return g.map(e=>t.get(e)).filter(Boolean)}return e},[g,b,he]);return A(f,{children:[_(se,{}),"modal"===e?.editMode?.editMode?_(Ne,{children:e?.editMode?.specs?.formComponent?_(e.editMode.specs.formComponent,{recordIdToEdit:H?H[ae]:void 0,formCloseCallBk:()=>{Oe(!1),e.apiActions.reloadData(e?.gridLoadParametersValues)}}):_(rr,{keyColumnName:e.keyColumnName,attachment:e.attachment,formValuesChangeCallBk:e?.formProps?.formValuesChangeCallBk,recordIdToEdit:H?H[ae]:void 0,formCloseCallBk:()=>{Oe(!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})}):_(f,{}),void 0!==e?.hideInfoBar||e?.hideInfoBar?_(f,{}):A(S,{sx:{display:"flex"},children:[void 0!==e?.hideBackButton||e?.hideBackButton?_(f,{}):_(x,{onClick:()=>{V(-1,{replace:!0})},children:_(Re,{icon:"ltr"===C?"arrow-left":"arrow-right"})}),A(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[e?.girdIcon?_(Re,{icon:e.girdIcon,style:{marginRight:5,marginLeft:5}}):_(f,{}),_(w,{variant:"h5",children:e?.gridTitle?Ua(t(e?.gridTitle)):""})]})]}),e?.gridLoadParameters&&e?.gridLoadParameters.length>0&&e?.gridLoadParametersValues&&e?.setGridLoadParametersValues?A(X,{defaultExpanded:!0,sx:{width:"100%"},children:[_(J,{expandIcon:_(m,{}),children:A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[_(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),_(w,{component:"span",children:"Filters"})]})}),_(ee,{children:_(S,{children:_(rr,{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})})})]}):_(f,{}),e?.attachment?_(l,{children:_(Ga,{attachmentCode:e.attachment.attachmentCode,refKey:o[e?.keyColumnName||"id"],enableAttachment:r})}):_(f,{}),e?.workFlowDocumentCode?_(p,{children:_(ar,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:o[e?.keyColumnName||"id"],postActionCallBk:()=>{I(!1),e.apiActions.reloadData(e.gridLoadParametersValues)},cancelActionCallBk:()=>{I(!1),e.apiActions.reloadData(e.gridLoadParametersValues)}})}):_(f,{}),_(u,{...e?.muiProps,slots:{toolbar:Ha},slotProps:{toolbar:{templateProps:{...e,rowSelectionModel:ie,data:e?.data},handleCreateNewRecord:()=>{if("form"===e?.editMode?.editMode)V(e.editMode.specs.formRoute);else if("modal"===e?.editMode?.editMode)Q(null),Oe(!0);else if("row"===e?.editMode?.editMode){Za-=1;const e={};e[ae]=Za,e.isNew=!0;for(const t of N)"actions"!=t?.type&&t?.field!=ae&&t?.field&&(e[t.field]=null);re(t=>[e,...t]),$(e=>({...e,[Za]:{mode:T.Edit}}))}},clearGridState:()=>{e?.gridStateKey&&localStorage.removeItem(e.gridStateKey),P({}),M([]),U({}),F([]),G({left:[..."ltr"===C?Xa:[]],right:[..."rtl"===C?Xa:[]]})}}},getRowId:e=>e[ae],showToolbar:!0,rows:e?.data,columns:Le,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==e.editMode.editMode?j:void 0,onRowModesModelChange:"row"==e.editMode.editMode?e=>{$(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 Ge.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 De.error(_("div",{style:{},children:e.map(e=>A(f,{children:[_("div",{children:e}),_(Z,{})]}))})),new Error(o)}if(e?.editAction?.preActionValidation&&!e.editAction.preActionValidation(t))throw new Error("error on the configured presave validation");const a={...t};if(t[ae]&&ba(t[ae])&&Number(t[ae])<0&&(a[ae]=null),i=await e.apiActions.saveRecord(a),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&&re(e=>{const o=e.filter(e=>e[ae]!==t[ae]);return[i,...o]}),!0===e?.editMode?.reloadAfterSave&&e?.apiActions?.reloadData&&e?.apiActions?.reloadData(e?.gridLoadParametersValues),i}},rowSelectionModel:ie,onRowSelectionModelChange:e=>{oe(e)},columnVisibilityModel:D,onColumnVisibilityModelChange:t=>{P(t),e?.gridStateKey&&$a(e.gridStateKey,{columnVisibilityModel:t})},onColumnOrderChange:t=>{const{column:i,targetIndex:o}=t;M(t=>{const a=t.length?[...t]:he.map(e=>e.field),r=a.indexOf(i.field);return-1===r||(a.splice(r,1),a.splice(o,0,i.field),e?.gridStateKey&&$a(e.gridStateKey,{columnOrder:a})),a})},rowGroupingModel:v,onRowGroupingModelChange:t=>{(t=>{F(t),e?.gridStateKey&&$a(e.gridStateKey,{columnGroupingModel:t})})(t)},sx:{width:"100%"}})]})},er=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},tr=e=>{const[t,i]=Te([]);return Ae(()=>{const t=e.reportData.map((e,t)=>({...e,report_record_data_key:t}));i(t)},[e.reportData]),_(Ja,{data:t,disableDefaultAction:!0,setData:e.setReportData,formElements:er(e.reportData),gridLoadParameters:e.gridLoadParameters,gridLoadParametersValues:e.gridLoadParametersValues,setGridLoadParametersValues:e.setGridLoadParametersValues,editMode:{editMode:"none"},girdIcon:"file-excel",gridTitle:"Report",autoLoad:!0,keyColumnName:"report_record_data_key",hideInfoBar:!0,apiActions:{deleteRecordById:async()=>!0,loadRecordById:async()=>{},reloadData:async()=>{e.reloadReport()},saveRecord:async()=>{}}})},ir=e=>{console.log("useParameterPanel","useParameterPanel called");const[t,i]=Te({...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:a}=be();return A(X,{defaultExpanded:!0,sx:{width:"100%"},children:[_(J,{expandIcon:_(Re,{icon:{prefix:"far",iconName:"square-caret-down"}}),children:A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[_(Re,{style:{marginLeft:5,marginRight:5},icon:"search"}),_(w,{component:"span",children:"Filters"})]})}),_(ee,{children:_(S,{children:_(rr,{saveButtonSpecs:{label:a("Filter"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:a("RESET_BTN_LABEL"),icon:"eraser",hidden:!0,actionButtonVariant:"outlined",actionButtonColor:"error"},actions:[{label:a("RESET_BTN_LABEL"),icon:"eraser",isIdRequired:!1,formActionProps:{enabled:!0},actionFn:async(e,t)=>{i({})}}],apiActions:{deleteRecordById:async()=>!0,saveRecord:async o=>{i(null!=o?o:{}),e&&await e(t)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:o})})})]})},parametersValues:t,setParametersValues:i,panelElements:o}},or=e=>{const[t,i]=Te(null),[o,a]=Te(null),[r,d]=Te([]),[n,l]=Te("WAITING_REPORT_CODE"),{handleGetRequest:s,handlePostRequest:p,HandleDownloadHTTPPostPDF:c}=Ht(),[m,u]=Te(null),{ParameterPanel:T,parametersValues:I,panelElements:E,setParametersValues:N}=ir({parameters:m?.reportParameters||[],initialParameterValues:{...e?.reportParametersValues}}),O=async t=>{l("WAITING_RESULT"),"Excel"===m?.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"),d(e.data)}}):m?.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");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),a=document.createElement("a");a.href=i,a.download=o,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(i)}},failureCallBkFn:e=>{a("Failed To run report ... contact your administrator"),l("ERROR")}})};return Ae(()=>{e?.reportCode&&(async()=>{l("LOADING_METADATA"),await s({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:e.reportCode},successCallBkFn:t=>{u(t.data),!0===e?.byPassParameterEntry||0==t.data.reportParameters.length?(O(I),l("WAITING_RESULT")):l("WAITING_PARAMETER_INPUT")},failureCallBkFn:e=>{a("Failed loading report metadata ... contact your administrator"),l("ERROR")}})})()},[e.reportCode,e.byPassParameterEntry,e.reportParametersValues,e.jasperOutPutFileType,e.resultMode]),A(f,{children:[A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[A(S,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[_(Re,{icon:"Excel"===m?.reportType?"file-excel":"file-pdf",color:"Excel"===m?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),m?.reportName]}),"Excel"!=m?.reportType&&"SHOWING_RESULT"===n?A(f,{children:[!0===e?.byPassParameterEntry?_(f,{}):m?.reportParameters.length>0?_(x,{onClick:()=>{l("WAITING_PARAMETER_INPUT")},children:_(Re,{icon:"filter"})}):_(f,{}),_(x,{children:_(Re,{icon:"refresh",onClick:()=>{O(I)}})})]}):_(f,{})]}),_(S,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===n&&"Excel"!=m?.reportType?_(T,{searchBtnClickCallBk:O}):"SHOWING_RESULT"===n||("WAITING_PARAMETER_INPUT"===n||"WAITING_RESULT"===n)&&"Excel"===m?.reportType?"Excel"===m?.reportType?_(tr,{reportData:r,setReportData:d,reloadReport:async()=>{O(I)},gridLoadParameters:E,gridLoadParametersValues:I,setGridLoadParametersValues:N}):_("iframe",{src:t,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===n?A(S,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[_(Re,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),o]}):_(f,{})})]})},ar=e=>{const t=ve(),i=E(e=>e.AppLayout),{isUserAuthorized:o,UserInfo:a}=Zt(),{handleGetRequest:r,handlePostRequest:d}=Ht(),[n,l]=Te(null),[s,p]=Te([]),{t:c}=be(),[m,u]=Te(null),[T,I]=Te({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:N,setWindowState:O}=jt({windowTitle:"ltr"===i.appDirection?T?.workflowDocument&&T?.referencedDocument?`${T?.workflowDocument?.documentEnName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`:"Document":T?.workflowDocument&&T?.referencedDocument?`${T?.workflowDocument?.documentArName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),y=async()=>{await r({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:e.workFlowDocumentCode,refDocumentId:e.refDocumentId},successCallBkFn:e=>{I(e.data)},failureCallBkFn:()=>{I({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},h=async()=>{await d({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:T?.workflowDocument?.id,refDocumentId:e.refDocumentId,actionId:n.id,refDocumentStatus:T?.workflowDocumentStatus?.documentStatusCode,actionComment:m},successCallBkFn:async t=>{n?.post_action_endpoint?await d({endPointURI:n.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:n.id},successCallBkFn:()=>{y(),e?.postActionCallBk&&e.postActionCallBk()}}):y()}})};return Ae(()=>{e.refDocumentId&&e.workFlowDocumentCode&&y()},[e.refDocumentId,e.workFlowDocumentCode]),Ae(()=>{p(T?.nextActions&&T?.nextActions?.length>0?T.nextActions.filter(e=>{if(!T?.workflowDocumentStatus?.nextActionTakersAuthority&&!T?.nextActionTakers)return!0;if(T?.workflowDocumentStatus?.nextActionTakersAuthority&&o(T.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(T?.nextActionTakers)for(const e of T.nextActionTakers)if(a?.username===e?.username||a?.username===e?.USERNAME)return!0;return!1}):[])},[T.nextActions,T.nextActionTakers]),A(f,{children:[T?.workflowDocumentReport?.id?_(N,{children:_(or,{reportCode:T?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:e.refDocumentId+""}})}):_(f,{}),T?.workflowDocument?A(S,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[_(x,{onClick:()=>{t(-1,{replace:!0})},children:_(Re,{icon:"arrow-left"})}),_(S,{sx:{flex:1}}),_(Re,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===i.appDirection?`${T?.workflowDocument?.documentEnName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`:`${T?.workflowDocument?.documentArName} # ${T?.referencedDocument[T?.workflowDocument?.documentNumberField]}`,T?.workflowDocumentStatus?"ltr"===i.appDirection?` ( ${T?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${T?.workflowDocumentStatus?.documentStatusArName} )`:"",_(S,{sx:{flex:1}}),T?.workflowDocumentReport?.id?_(M,{onClick:()=>{O(!0)},variant:"outlined",startIcon:_(Re,{icon:"eye"}),children:c("VIEW_LABEL")}):_(f,{})]}):_(f,{}),A(S,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[s?.length>0?A(F,{sx:{padding:2,display:"flex",flex:1,margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[_(ni,{sx:{marginBottom:2,width:400},label:c("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===i.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:n?.id,options:s,onChangeCallBack:(e,t)=>{l(t)}}),_(ii,{sx:{width:400},rows:3,value:m,onChange:e=>{u(e.target.value)},multiline:!0,label:c("WF_COMMENT_LABEL")}),A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[_(M,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=n&&null!=n?.id?!0!==n.require_comment&&1!==n.require_comment&&"true"!==n.require_comment||null!==m&&""!==m?n?.pre_action_endpoint?await d({endPointURI:n.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:e.refDocumentId,actionId:n.id},successCallBkFn:()=>{h()}}):h():De.error("You must enter comment for the action to be processed"):De.error("You must select action to process")},children:c("WF_TAKE_ACTION_BTN_LABEL")}),e?.cancelActionCallBk?_(M,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{e?.cancelActionCallBk&&e.cancelActionCallBk()},children:c("WF_CANCEL_BTN_LABEL")}):_(f,{})]}),T?.nextActionTakers&&T.nextActionTakers.length>0?A(f,{children:[_(Z,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:A(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[_(Re,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",c("WF_WAITING_FOR_LABEL")]})}),_(S,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:T.nextActionTakers.map(e=>A(S,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[_(ka,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:e?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),A(S,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[_("div",{children:"ltr"===i.appDirection?e?.employee_en_name:e?.employee_ar_name}),_("div",{children:e?.email?A(f,{children:[_(Re,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),e?.email]}):_(f,{})}),_("div",{children:e?.mobile_number?A(f,{children:[_(Re,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),e?.mobile_number]}):_(f,{})})]})]}))})]}):_(f,{})]}):_(f,{}),T?.actionsHistory.length>0?_(Ya,{actionHistory:T.actionsHistory}):A(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[A(S,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[_(Re,{icon:"history",style:{marginRight:10,marginLeft:10}}),c("WF_ACTION_HISTORY_LABEL")]}),_(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},rr=e=>{const{Window:t,setWindowState:i}=jt({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),{Window:o,setWindowState:a}=jt({windowTitle:"Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[r,d]=Te(!0),{t:n}=be(),l=yi(e.elements),s=[];for(const e of l)e?.hidden&&s.push(e.fieldName);const[p,c]=Te(s),m={};for(const t of e.elements)"field"===t?.type&&"props"===t?.mode&&t?.props?.defaultValue&&(m[t.props.fieldName]=t.props.defaultValue);const[u,T]=Te([]);let I=null;I=e?.validationSchema?e.validationSchema:We.object(Ri(l));const E=Ue({resolver:ke(I),defaultValues:m}),N=E.watch(),O=we(),y=e?.formRouteRecordIdParamName,h=async()=>{let t=null;if(e?.recordIdToEdit?t=e.recordIdToEdit:y&&O[y]&&(t=O[y]),t){const i=await e.apiActions.loadRecordById(t);if(i){E.reset({...i}),e?.formValuesChangeCallBk&&e?.formValuesChangeCallBk({...i},R,E);for(const e of l)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?E.setValue(e.fieldName,i[e.fieldName]+""):E.setValue(e.fieldName,i[e.fieldName]))}}else E.reset({})},R={setFieldValue:(e,t)=>{E.setValue(e,t)},hideField:e=>{c(t=>[...t,e])},showField:e=>{c(t=>t.filter(t=>t!==e))},disableField:e=>{T(t=>[...t,e])},enableField:e=>{T(t=>t.filter(t=>t!==e))}};return Ae(()=>{h()},[e?.recordIdToEdit]),Ae(()=>{d(!e?.attachment||!e?.attachment?.enableAttachFn||e.attachment.enableAttachFn(N))},[N]),A(f,{children:[e?.attachment?_(t,{children:_(Ga,{attachmentCode:e.attachment.attachmentCode,refKey:N[e?.keyColumnName||"id"],enableAttachment:r})}):_(f,{}),e?.workFlowDocumentCode?_(o,{children:_(ar,{workFlowDocumentCode:e.workFlowDocumentCode,refDocumentId:N[e?.keyColumnName||"id"],postActionCallBk:()=>{a(!1),h()},cancelActionCallBk:()=>{a(!1)}})}):_(f,{}),_(ga,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:_(k,{sx:{width:"100%"},container:!0,children:e.elements.map((t,i)=>"group"===t.type?_(Ba,{...t.props,formManager:E,formValues:N,formActions:R,hiddenFields:p,disabledFields:u},i):"field"===t.type&&"props"===t.mode?_(xa,{fieldInfo:t.props,formManager:E,formValues:N,formActions:R,hiddenFields:p,disabledFields:u,formValuesChangeCallBk:e.formValuesChangeCallBk},i):"field"===t.type&&"node"===t.mode?_(k,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:_(t.node,{formManager:E,formValues:N})},i):void 0)})}),A(ga,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[N[e?.keyColumnName||"id"]&&e?.attachment?_(z,{title:"Attachments",children:_(x,{onClick:()=>{i(!0)},children:_(Re,{icon:"paperclip"})})}):null,N[e?.keyColumnName||"id"]&&e?.workFlowDocumentCode?_(z,{title:"Approvals",children:_(x,{onClick:()=>{a(!0)},children:_(Re,{icon:"stamp"})})}):null,e?.actions?e.actions.map(t=>!1===t?.isIdRequired?_(Fa,{...t,record:N}):N[e?.keyColumnName||"id"]?!0===t?.formActionProps?.enabled?_(Fa,{...t,record:N}):_(f,{}):void 0):_(f,{}),_("div",{style:{flex:1}}),e?.saveButtonSpecs?.hidden?_(f,{}):_(M,{variant:e?.saveButtonSpecs?.actionButtonVariant?e.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:e?.saveButtonSpecs?.icon?_(Re,{icon:e.saveButtonSpecs.icon}):null,color:e?.saveButtonSpecs?.actionButtonColor?e.saveButtonSpecs.actionButtonColor:"primary",onClick:E.handleSubmit(t=>{(async t=>{if((!e?.preSaveValidation||e.preSaveValidation(t))&&t){const i=await e.apiActions.saveRecord(t);i&&(E.reset({...i}),e?.formSavedSuccessfullyCallBk&&e.formSavedSuccessfullyCallBk(i),e?.formCloseCallBk&&e.formCloseCallBk())}})(t)},e=>{De.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?_(f,{}):_(M,{variant:e?.cancelButtonSpecs?.actionButtonVariant?e.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:e?.cancelButtonSpecs?.icon?_(Re,{icon:e.cancelButtonSpecs.icon}):null,color:e?.cancelButtonSpecs?.actionButtonColor?e.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{e?.formCloseCallBk&&e.formCloseCallBk(),E.reset(m)},children:n(e?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},dr=()=>{const{workflowDocumentCode:e,refDocumentId:t}=we();return _(ar,{workFlowDocumentCode:e,refDocumentId:t})},nr=e=>_(rt,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),lr=e=>A(F,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[_(S,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:_("div",{children:e.record[e.valueField]})}),_(w,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]})]}),sr=e=>A(f,{children:[_(w,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),_(dt,{width:200,height:200,value:e.record[e.valueField],valueMax:e.total})]}),pr=e=>_(nt,{dataset:e.data,xAxis:[{dataKey:e.valueField,scaleType:"band",label:e.valueLabel}],series:e.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function cr(e){return A(st,{sx:{display:"flex",alignItems:"center"},children:[_(st,{sx:{width:"100%",mr:1},children:_(lt,{variant:"determinate",...e})}),_(st,{sx:{minWidth:35},children:_(at,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(e.value)}%`})})]})}const mr=e=>A(st,{sx:{width:"100%"},children:[_(at,{sx:{fontSize:16,fontWeight:"bold"},children:e.record[e.labelField]}),_(cr,{value:e.record[e.valueField]/e.total*100})]}),ur=e=>{const t=e.data.map((t,i)=>({id:i,value:t[e.valueField],label:t[e.labelField]+""}));return _(pt,{series:[{data:t}]})},Tr=e=>{const[t,i]=Te(!0),[o,a]=Te([]),{handleGetRequest:r}=Ht();Ae(()=>{e.loadWidget?(async()=>{i(!0),await r({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:e.dataQueryId,...e.parameterValues},successCallBkFn:e=>{i(!1),a(e.data)},failureCallBkFn:()=>{i(!1),a([])}})})():i(!1)},[e.loadWidget,e.loadCounter]);let d=0;if(1==o.length)d=100;else if("CircularProgress"===e.widgetType||"LinearProgress"===e.widgetType)for(const t of o)d+=t[e.verticalAxisField];return A(f,{children:["LineChart"===e.widgetType||"PieChart"===e.widgetType||"ColumnChart"===e.widgetType?A(S,{children:[_(Re,{style:{marginRight:10,marginLeft:10},icon:e?.icon||"chart-pie"}),e?.title]}):_(f,{}),_(S,{sx:{flex:1,padding:1,height:"90%",display:"flex",alignItems:"center",justifyContent:"center",width:"90%"},children:t?A(f,{children:[_(Re,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),_("div",{children:"Loading"})]}):"ColumnChart"===e.widgetType?_(nr,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===e.widgetType?_(pr,{data:o,widgetTitle:e.title,labelField:e.verticalAxisField,valueField:e.horizontalAxisField,valueLabel:e.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===e.widgetType?_(ur,{data:o,widgetTitle:e.title,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,widgetType:"Pie"}):A(k,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[_(k,{size:{xs:12},sx:{textAlign:"center"},children:e.title}),o.map((t,i)=>"Card"===e.widgetType?_(k,{size:{md:3,xs:12},children:_(lr,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField},i)}):"CircularProgress"===e.widgetType?_(k,{size:{md:3,xs:12},children:_(sr,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:d},i)}):"LinearProgress"===e.widgetType?_(k,{size:{md:3,xs:12},children:_(mr,{widgetTitle:"",record:t,labelField:e.horizontalAxisField,valueField:e.verticalAxisField,total:d},i)}):void 0)]})})]})},Ar=e=>{const[t,i]=Te({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),{ParameterPanel:o,parametersValues:a}=ir({parameters:t?.dashboardParameters||[],initialParameterValues:{}}),[r,d]=Te(0),[n,l]=Te(!1);Ae(()=>{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===a[i.parameterCode]||null===a[i.parameterCode]||""===a[i.parameterCode])){e=!1;break}e&&l(e),d(r+1)}},[t?.dashboardParameters,a]);const s=ve(),{handleGetRequest:p,handlePostRequest:c}=Ht();return Ae(()=>{e.dashboardCode&&(async()=>{await p({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:e.dashboardCode},successCallBkFn:e=>{i(e.data)},failureCallBkFn:()=>{i(null)}})})()},[e.dashboardCode,e.parameters]),_(f,{children:t?A(f,{children:[A(S,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[_(x,{onClick:()=>{s(-1,{replace:!0})},children:_(Re,{icon:"arrow-left"})}),_(S,{sx:{flex:1}}),_(Re,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),_(S,{children:t?.dashboardTitle}),_(S,{sx:{flex:1}})]}),t?.dashboardParameters.length>0?_(o,{searchBtnClickCallBk:async e=>{d(r+1)}}):_(f,{}),_(k,{container:!0,spacing:1,sx:{height:"fit-content",overflowY:"auto",padding:1},children:t?.widgets.map((e,t)=>_(k,{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:_(Tr,{...e,parameterValues:a,loadWidget:n})},t))})]}):_(S,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},_r=()=>{const{dashboardCode:e}=we();return _(Ar,{dashboardCode:e})},fr=e=>{const{UserSession:t}=Zt(),i=E(e=>e.AppLayout),o=I(),{handlePostRequest:a}=Ht(),[r,d]=Te(t.value.currentOrganization.id);return A(S,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[_(ni,{sx:{width:"100%"},displayField:"ltr"===i.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:t.value.userOrganizations,value:r,onChangeCallBack:e=>{d(e)}}),_(M,{sx:{m:1},variant:"contained",disabled:null==r||r===t.value.currentOrganization.id,onClick:async()=>{await a({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:t.value.username,orgId:r},data:{},successCallBkFn:t=>{const i={...t.data,isAuthenticated:!0};o(Kt.setAuthenticated(i)),e.successChangeCallBackFn&&e.successChangeCallBackFn()}})},children:"Change Organization"})]})},Ir=Le({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Er,setSideBarState:Nr}=Ir.actions;var Or=Ir.reducer;function yr(e,t){const i=fe(e);Ae(()=>{i.current=e},[e]),Ae(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const hr=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; }