@asaleh37/ui-base 25.8.23-1 → 25.8.23-2

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.js 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=oe(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})($i),d=pe.forwardRef(function(t,d){const l=function(e=eo){return Ji(e)}(o),{className:s,component:p="div",...c}=to(t);return e.jsx(n,{as:p,ref:d,className:ro(s,r?r(a):a),theme:i&&l[i]||l,...c})});return d}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=no[t];return o?`${i}-${o}`:`${oo.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:oo.generate});function so(e){return"number"==typeof e&&!isNaN(e)}function po(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function co(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function uo(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function mo(e,t){const i=new Date(e),o=new Date,a=Math.floor((i-o)/1e3),r="rtl"===t?"ar":"en",n=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),d=[{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 d){const i=Math.floor(a/t);if(Math.abs(i)>1)return n.format(i,e)}return"ar"===r?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(lo.propTypes={children:wt.node,component:wt.elementType,sx:wt.oneOfType([wt.arrayOf(wt.oneOfType([wt.func,wt.object,wt.bool])),wt.func,wt.object])});const To=t=>{if(t?.fieldInfo){const i=t.fieldInfo,o=t?.formManager||null,a=t?.formActions||null,r=t?.formValues||null,d=t?.fieldInfo?.fieldName||null,l=t?.fieldInfo?.fieldType||null;return i&&o&&r&&d&&l?t.hiddenFields.includes(d)?e.jsx(e.Fragment,{}):e.jsx(n.Grid2,{size:i?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===l||"number"===l?e.jsx(we,{...i.muiTextFieldProps,fullWidth:!0,type:l,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),label:i?.fieldLabel,value:r[d],onChange:e=>{let t=null;""!=e.target.value&&(t="number"===l&&po(e.target.value)?Number(e.target.value):e.target.value),o.setValue(d,t),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(t,o,a)},sx:{"& .MuiInputBase-root":{height:`${i?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...i?.formProps?.style},error:null!=o.formState.errors[d],helperText:o?.formState?.errors[d]?.message?.toString()}):"date"===i?.fieldType?e.jsx(ze,{format:i?.dateFormat||Ge,sx:i?.formProps?.style||{width:"100%"},disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),label:i?.fieldLabel,onChangeCallBack:e=>{o.setValue(d,e),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(e,o,a)},value:r[d],error:null!=o.formState.errors[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):"datetime"===i?.fieldType?e.jsx(He,{format:i?.dateFormat||We,sx:i?.formProps?.style||{width:"100%"},disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),label:i?.fieldLabel,onChangeCallBack:e=>{o.setValue(d,e),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(e,o,a)},hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),value:r[d],error:null!=o.formState.errors[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):"checkbox"===i?.fieldType?e.jsx(ke,{label:i?.fieldLabel,onChangeCallBack:e=>{o.setValue(d,e),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(e,o,a)},hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),value:r[d],checkedValue:i?.checkedValue||!0,unCheckedValue:i?.unCheckedValue||!1,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),sx:i?.formProps?.style}):"combobox"===i?.fieldType?e.jsx(je,{sx:i?.formProps?.style||{width:"100%"},label:i?.fieldLabel,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),onChangeCallBack:(e,t)=>{let r=null;e&&(r=e),o.setValue(d,r),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(r,o,a,t)},options:i?.options||[],displayField:i?.optionDisplayField||"",valueField:i?.optionValueField||"",value:r[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):"lookup"===i?.fieldType?e.jsx(Qe,{sx:i?.formProps?.style||{width:"100%"},label:i?.fieldLabel,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),onChangeCallBack:(e,t)=>{let r=null;e&&(r=e),o.setValue(d,r),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(r,o,a,t)},lookupType:i.lookupType,value:r[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):null}):e.jsx(e.Fragment,{})}return e.jsx(e.Fragment,{})},Ao=t=>{const i=De(),{ConfirmationWindow:o,setOpen:a}=ge({body:t?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{t?.actionFn(t?.record)}});return null==t?.authority||i.isUserAuthorized(t.authority)?e.jsxs(e.Fragment,{children:[e.jsx(o,{}),e.jsxs(n.Button,{variant:t?.formActionProps?.actionButtonVariant,color:t?.formActionProps?.actionButtonColor,onClick:()=>{if(t?.actionFn){if(t?.preActionValidation&&!t.preActionValidation(t.record))return;!0===t?.isConfirmationRequired?a(!0):t?.actionFn(t.record)}},children:[t?.icon?e.jsx(m.FontAwesomeIcon,{icon:t.icon,style:{marginRight:5,marginLeft:5}}):e.jsx(e.Fragment,{}),e.jsx("div",{children:t?.label})]})]}):e.jsx(e.Fragment,{})},_o=t=>{const{t:i}=I.useTranslation();return e.jsx(e.Fragment,{children:e.jsxs(n.Grid2,{container:!0,sx:t?.style,alignItems:"flex-start",children:[t?.label?e.jsx(n.Grid2,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:t?.icon?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:t.icon,style:{marginRight:5,marginLeft:5}}),e.jsx("div",{children:i(t.label)})]}):e.jsx(e.Fragment,{children:i(t.label)})}):e.jsx(e.Fragment,{}),t?.elements?t.elements.map(i=>"group"===i.type?e.jsx(_o,{...i.props,formManager:t.formManager,formValues:t.formValues,formActions:t.formActions,hiddenFields:t.hiddenFields,disabledFields:t.disabledFields}):"field"===i.type&&"props"===i.mode?e.jsx(To,{fieldInfo:i.props,formManager:t.formManager,formValues:t.formValues,formActions:t.formActions,hiddenFields:t.hiddenFields,disabledFields:t.disabledFields}):"field"===i.type&&"node"===i.mode?e.jsx(n.Grid2,{size:i?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:e.jsx(i.node,{formManager:t.formManager,formValues:t.formValues,formActions:t.formActions})}):void 0):null,t?.actions?e.jsx(n.Grid2,{size:{sm:12},sx:{padding:1},children:t.actions.map(i=>e.jsx(Ao,{...i,record:t.formValues}))}):e.jsx(e.Fragment,{})]})})},fo=i=>{const o=t.useSelector(e=>e.AppInfo.value.apiBaseUrl),[a,r]=l.useState(null);return l.useEffect(()=>{(()=>{let e=o+"/api/v1/attachment/";i?.attachmentId?e+="download?attachmentId="+i.attachmentId:(e+=`downloadImage?attachmentCode=${i.attachmentCode}&refKey=${i.refKey}`,i?.category&&(e+=`&category=${i.category}`)),r(e)})()},[i]),i?.showAsAvatar?e.jsx(n.Avatar,{sx:i.style,onError:()=>{r(i?.onErrorImage?i.onErrorImage:"/no_image.png")},src:a}):e.jsx("img",{src:a,loading:"lazy",alt:"image",onError:()=>{r(i?.onErrorImage?i.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Io=t=>{const{handleGetRequest:i,handleDeleteRequest:o}=Ce(),{isUserAuthorized:a}=De();let r=!0;t?.downloadAuthorityKey&&(r=a(t.downloadAuthorityKey));const{ConfirmationWindow:d,setOpen:l}=ge({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await o({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:t.attachmentCode,refKey:t.refKey,attachmentId:t.id},successCallBkFn:e=>{t.setAttachmentConfig(e.data)},showMask:!0})})()}});return e.jsxs(e.Fragment,{children:[e.jsx(d,{}),e.jsxs(R,{sx:{width:300,border:"0.5px solid gray"},children:[e.jsx(v,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:t?.docType.toLocaleLowerCase().includes("image")?e.jsx(fo,{attachmentId:t.id}):e.jsx(m.FontAwesomeIcon,{icon:"file",size:"3x"})}),e.jsxs(w,{children:[e.jsx(F,{gutterBottom:!0,variant:"h6",component:"div",children:t.fileName}),e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${t?.attachmentSize||"unknown"} kb`}),e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${t?.category||"NA"}`}),e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:t.remark})]}),e.jsxs(U,{children:[t?.allowDelete?e.jsx(n.IconButton,{size:"small",onClick:()=>{l(!0)},children:e.jsx(n.Tooltip,{title:"Delete Attachment",children:e.jsx(m.FontAwesomeIcon,{icon:"trash"})})}):e.jsx(e.Fragment,{}),e.jsx("div",{style:{flex:1}}),r?e.jsx(n.IconButton,{size:"small",onClick:async()=>{await i({endPointURI:"api/v1/attachment/download",parameters:{attachmentId:t.id},showMask:!0,responseType:"blob",successCallBkFn:e=>{const i=window.URL.createObjectURL(new Blob([e.data])),o=document.createElement("a");o.href=i,o.setAttribute("download",t.fileName),document.body.appendChild(o),o.click(),o.remove()}})},children:e.jsx(n.Tooltip,{title:"Download Attachment",children:e.jsx(m.FontAwesomeIcon,{icon:"download"})})}):e.jsx(e.Fragment,{})]})]})]})},Eo=t=>{const{handleUploadRequest:i,handleGetRequest:o}=Ce(),[a,r]=l.useState(null),[d,s]=l.useState([]),[p,c]=l.useState(null),[u,T]=l.useState(null),[_,f]=l.useState([]),[I,E]=l.useState(null),{isUserAuthorized:O}=De(),N=e=>e.split(".").pop()?.toLowerCase()||"";l.useEffect(()=>{(async()=>{await o({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:t.attachmentCode,refKey:t.refKey},successCallBkFn:e=>{E(e.data)}})})()},[t.refKey,t.attachmentCode]),l.useEffect(()=>{if(f(I?.allowedFileTypes?I.allowedFileTypes.split(","):[]),I?.attachmentCategories){const e=[];for(const t of I.attachmentCategories.split(","))e.push({value:t});s(e)}else s([])},[I]);let y=!0;I?.downloadAuthorityKey&&!O(I?.downloadAuthorityKey)&&(y=!1);let h=!0;return!1===t?.enableAttachment&&(h=!1),I?.uploadAuthorityKey&&!O(I.uploadAuthorityKey)&&(h=!1),e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[h?e.jsx(e.Fragment,{children:null==I?.maxAllowedNumberOfFiles||I?.maxAllowedNumberOfFiles>I.refKeyAttachments.length?e.jsxs(e.Fragment,{children:[e.jsxs("h3",{children:[e.jsx(m.FontAwesomeIcon,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),e.jsx("input",{type:"file",style:{margin:20},accept:I?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=N(t.name);if(_.length>0&&!_.includes(e))return void A.toast.error(e+" is not allowed")}r(e.target.files)}}),d.length>0?e.jsx(je,{label:"Attachment Type",sx:{width:300,m:1},options:d,displayField:"value",valueField:"value",value:u,onChangeCallBack:e=>{T(e)}}):e.jsx(e.Fragment,{}),e.jsx(we,{label:"Remark",value:p,onChange:e=>c(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),e.jsx(n.Button,{sx:{m:1},variant:"contained",onClick:async()=>{let e=I?.refKeyAttachments.length||0;if(I?.maxAllowedNumberOfFiles&&a.length+e>I.maxAllowedNumberOfFiles)A.toast.error("Maximum number of attachments is "+I.maxAllowedNumberOfFiles);else if(!0===I?.isCategoryRequired&&d.length>0&&(null==u||void 0===u||""===u))A.toast.error("You must selected document type to process your request");else if(a){for(const e of a)if(e.type.startsWith("image/")){const t=600,i=1024*t;if(e.size>i)return void A.toast.error(`File ${e.name} is too large. Max allowed is ${t}KB.`)}await i({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:t.refKey,attachmentCode:t.attachmentCode,remark:p,category:u},files:a,successCallBkFn:e=>{E(e.data),r(null),T(null),c(null),A.toast.success("Your request has been process successfully")}})}else A.toast.error("You must add files to upload")},children:"Upload"})]}):e.jsx(e.Fragment,{})}):e.jsx(e.Fragment,{}),y&&I?.refKeyAttachments?.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("h3",{children:[e.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),e.jsx(n.Grid2,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:I?.refKeyAttachments.map(i=>e.jsx(n.Grid2,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:e.jsx(Io,{...i,attachmentCode:t.attachmentCode,setAttachmentConfig:E,downloadAuthorityKey:I.downloadAuthorityKey,allowDelete:h})}))})]}):e.jsx(e.Fragment,{})]})},Oo=i=>{const o=t.useSelector(e=>e.AppLayout),{t:a}=I.useTranslation();return e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[e.jsxs(n.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[e.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),a("WF_ACTION_HISTORY_LABEL")]}),e.jsx(n.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:i.actionHistory.map((t,a)=>e.jsx(e.Fragment,{children:e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[e.jsxs(n.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[e.jsx(n.Box,{sx:{marginBottom:.2},children:t.actionTime}),e.jsxs(F,{children:["via ",t.actionMethod]})]}),e.jsxs(n.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[e.jsx(fo,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:t?.personId+""||"0",style:{m:1,width:70,height:70}}),a!==i.actionHistory.length-1?e.jsx(n.Box,{sx:{marginTop:11,position:"absolute"},children:"|"}):e.jsx(e.Fragment,{})]}),e.jsxs(n.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[e.jsxs(n.Box,{sx:{width:"100%"},children:["ltr"===o.appDirection?`${t?.documentActionEnName}`:`${t?.documentActionArName}`,t?.actionComment?" - "+t.actionComment:""]}),e.jsx(n.Box,{sx:{width:"100%"},children:"ltr"===o.appDirection?`${t?.employeeEnName}`:`${t?.employeeArName}`})]})]})}))})]})},No=t=>{const{t:i}=I.useTranslation(),o=De(),{ConfirmationWindow:a,setOpen:r}=ge({body:i(t?.confirmationMessage||"ACTION_CONFIRMATION"),title:i("CONFIRMATION"),onConfirmationCallBk:async()=>{await(t?.actionFn(t.recordsToProcessActionOn,t.recordIdsToProcessActionOn)),t?.reloadData&&t.reloadData()}});let d=!0;if(t.authority&&(d=o.isUserAuthorized(t.authority)),d)return e.jsxs(e.Fragment,{children:[e.jsx(a,{}),e.jsxs(n.Button,{onClick:async()=>{if(t?.recordsToProcessActionOn&&t?.recordsToProcessActionOn.length>0){if(t?.preActionValidation)for(const e of t.recordsToProcessActionOn)if(!t.preActionValidation(e))return;!0===t?.isConfirmationRequired?r(!0):(await t.actionFn(t.recordsToProcessActionOn,t.recordIdsToProcessActionOn),t?.reloadData&&t.reloadData())}else A.toast.error(i("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"))},variant:t?.label?"outlined":t?.formActionProps?.actionButtonVariant?t.formActionProps.actionButtonVariant:"text",size:"small",color:t?.formActionProps?.actionButtonColor||"primary",children:[t?.icon?e.jsx(m.FontAwesomeIcon,{style:{marginRight:5,marginLeft:5},icon:t.icon}):e.jsx(e.Fragment,{}),t?.label?i(t.label):e.jsx(e.Fragment,{})]})]})},yo=n.styled(B.QuickFilter)({display:"grid",alignItems:"center"}),ho=n.styled(B.ToolbarButton)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",width:"min-content",height:"min-content",zIndex:1,opacity:t.expanded?0:1,pointerEvents:t.expanded?"none":"auto",transition:e.transitions.create(["opacity"])})),Ro=n.styled(n.TextField)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",overflowX:"clip",width:t.expanded?260:"var(--trigger-width)",opacity:t.expanded?1:0,transition:e.transitions.create(["width","opacity"])})),Lo=t=>{const{t:i}=I.useTranslation(),o=De(),a=!t?.templateProps?.editAction?.authority||o.isUserAuthorized(t.templateProps.editAction.authority),r=at(t?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},t?.templateProps?.data||[],t?.templateProps?.keyColumnName||"id");return e.jsxs(B.Toolbar,{children:[a&&"none"!=t?.templateProps?.editMode?.editMode?e.jsxs(n.Button,{onClick:t?.handleCreateNewRecord,children:[e.jsx(m.FontAwesomeIcon,{icon:"add",style:{marginRight:5,marginLeft:5}}),i("ADD_BTN_LABEL")]}):e.jsx(e.Fragment,{}),t?.templateProps?.rowActions?t.templateProps.rowActions.map((e,i)=>!0===e?.gridActionProps?.multiRecord?l.createElement(No,{...e,key:i,reloadData:async()=>{t.templateProps.apiActions.reloadData(t?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:r.selectedRecordIds,recordsToProcessActionOn:r.selectedRecords}):null):e.jsx(e.Fragment,{}),e.jsx(n.Box,{sx:{flex:1,mx:.5},children:t?.templateProps?.tBar}),e.jsx(n.Tooltip,{title:"Columns",children:e.jsx(B.ColumnsPanelTrigger,{render:e.jsx(B.ToolbarButton,{}),children:e.jsx(B.GridViewColumnIcon,{fontSize:"small"})})}),e.jsx(n.Tooltip,{title:"Filters",children:e.jsx(B.FilterPanelTrigger,{render:(t,i)=>e.jsx(B.ToolbarButton,{...t,color:"default",children:e.jsx(n.Badge,{badgeContent:i.filterCount,color:"primary",variant:"dot",children:e.jsx(B.GridFilterListIcon,{fontSize:"small"})})})})}),t?.templateProps?.gridStateKey?e.jsx(n.Tooltip,{title:i("RESET_GRID_STATE"),children:e.jsx(n.IconButton,{onClick:t?.clearGridState,children:e.jsx(m.FontAwesomeIcon,{icon:"eraser"})})}):e.jsx(e.Fragment,{}),e.jsx(n.Divider,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),e.jsx(n.Tooltip,{title:i("EXPORT_EXECL_LABEL"),children:e.jsx(B.ExportExcel,{render:e.jsx(n.MenuItem,{}),children:e.jsx(m.FontAwesomeIcon,{icon:"file-excel",color:"green"})})}),e.jsxs(yo,{children:[e.jsx(B.QuickFilterTrigger,{render:(t,o)=>e.jsx(n.Tooltip,{title:i("SEARCH_BTN_LABEL"),enterDelay:0,children:e.jsx(ho,{...t,ownerState:{expanded:o.expanded},color:"default","aria-disabled":o.expanded,children:e.jsx(m.FontAwesomeIcon,{icon:"search"})})})}),e.jsx(B.QuickFilterControl,{render:({ref:t,...o},a)=>e.jsx(Ro,{...o,ownerState:{expanded:a.expanded},inputRef:t,"aria-label":"Search",placeholder:`${i("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:e.jsx(n.InputAdornment,{position:"start",children:e.jsx(m.FontAwesomeIcon,{icon:"search"})}),endAdornment:a.value?e.jsx(n.InputAdornment,{position:"end",children:e.jsx(B.QuickFilterClear,{edge:"end",size:"small","aria-label":"Clear search",children:e.jsx(m.FontAwesomeIcon,{icon:"xmark"})})}):null,...o.slotProps?.input},...o.slotProps}})})]}),e.jsx(n.IconButton,{onClick:()=>{t.templateProps.apiActions.reloadData(t?.templateProps?.gridLoadParametersValues)},children:e.jsx(m.FontAwesomeIcon,{icon:"refresh"})})]})},Co=t=>{const{t:i}=I.useTranslation(),o=De(),{ConfirmationWindow:a,setOpen:r}=ge({body:i(t?.confirmationMessage||"ACTION_CONFIRMATION"),title:i("CONFIRMATION"),onConfirmationCallBk:async()=>{await(t?.actionFn(t.record)),t?.reloadData&&t.reloadData()}});let d=!0;t.authority&&(d=o.isUserAuthorized(t.authority));let l={};t?.getActionIconStyleForRecord&&(l=t.getActionIconStyleForRecord(t.record));let s=!0;t?.isActionVisibleForRecord&&(s=t?.isActionVisibleForRecord(t.record));let p=!1;if(t?.isActionDisabledForRecord&&(p=t.isActionDisabledForRecord(t.record)),d&&s)return e.jsxs(e.Fragment,{children:[e.jsx(a,{}),e.jsx(B.GridActionsCellItem,{disabled:p,icon:e.jsx(n.Tooltip,{title:t?.label?i(t.label):"",children:e.jsx(m.FontAwesomeIcon,{icon:t.icon,style:{...l,color:p?"gray":null!=l?.color?l.color:void 0}})}),showInMenu:t?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!p){if(t?.preActionValidation&&!t.preActionValidation(t.record))return;!0===t?.isConfirmationRequired?r(!0):(await t.actionFn(t.record),!0===t?.gridActionProps?.reloadGridAfterAction&&t?.reloadData&&t.reloadData())}}})]})};let go=-1;const Do=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},Po=(e,t)=>{const i=Do(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},Mo=["__check__","actions"],xo=i=>{const{t:o}=I.useTranslation(),a=t.useSelector(e=>e.AppLayout),[r,d]=l.useState({}),[s,p]=l.useState(!0),{getLookupOptions:c}=(()=>{const{handleGetRequest:e}=Ce(),i=t.useSelector(e=>e.AppLayout),o=async t=>{let i=[];return await e({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:t},successCallBkFn:e=>{i=e.data}}),i};return{generateLookupGridColumn:async e=>{let t=await o(e.lookupType);return{...e,options:t,displayField:"ltr"===i.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:o}})(),{Window:u,setWindowState:T}=Pe({windowTitle:o(i.gridTitle)+" Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"50%",onCloseCallBack:()=>{i?.apiActions?.reloadData(i.gridLoadParametersValues)}}),{Window:_,setWindowState:f}=Pe({windowTitle:o(i.gridTitle)+" Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"80%",onCloseCallBack:()=>{i?.apiActions?.reloadData(i.gridLoadParametersValues)}}),[E,N]=l.useState([]),h=tt(i.formElements),R=[],L=l.useMemo(()=>i?.gridStateKey?Do(i.gridStateKey):{},[]);for(const e of h)!0===e?.gridProps?.hidden&&R.push(e.fieldName);let C={};if(L?.columnVisibilityModel){C=L.columnVisibilityModel;const e=Object.keys(C);for(const t of R)e.includes(t)||(C[t]=!1)}else for(const e of R)C[e]=!1;const g=t.useSelector(e=>e.AppLayout.appDirection),[D,P]=l.useState(C),[M,x]=l.useState(L.columnOrder||[]),[b,S]=l.useState(L.columnWidths||{}),[U,w]=l.useState(L.columnGroupingModel||[]);let v=L?.pinnedColumns?.left||[];v=v.filter(e=>!Mo.includes(e));let F=L?.pinnedColumns?.right||[]||[];F=F.filter(e=>!Mo.includes(e));const[k,j]=l.useState({left:[..."ltr"===g?Mo:[],...v],right:[..."rtl"===g?Mo:[],...F]}),G=De(),W=O.useNavigate(),[Y,V]=l.useState(null),[q,K]=l.useState(null),[z,H]=l.useState({}),Q=async()=>{let e=it(h,"row"===i?.editMode?.editMode||!1,o);for(let t of e)t?.lookupType&&(t.displayField="ltr"===a.appDirection?"lookupEnDisplay":"lookupArDisplay",t.options=await c(t.lookupType),t.valueField="lookupValue");N(e)},[Z,$]=l.useState({ids:new Set,type:"include"});let X="id";i?.keyColumnName&&(X=i?.keyColumnName);const J=i.setData,ee=y.z.object(ot(h));let te=!0;i?.editAction?.authority&&(te=G.isUserAuthorized(i.editAction.authority));let ie=!0;i?.deleteAction?.authority&&(ie=G.isUserAuthorized(i.deleteAction.authority));const{ConfirmationWindow:oe,setOpen:ae}=ge({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let e=!0;Y&&!0===Y?.isNew||(e=await i.apiActions.deleteRecordById(Y[X])),e&&(i?.deleteAction?.postActionCallBack&&await i.deleteAction.postActionCallBack(Y),J(e=>e.filter(e=>e[X]!=Y[X])))}});let re,ne,de,le,se,pe;"modal"===i?.editMode?.editMode&&(re=i?.editMode?.specs?.modalHeight||"fit-content",ne=i?.editMode?.specs?.modalWidth||"300",de=i?.editMode?.specs?.modalMinHeight,le=i?.editMode?.specs?.modalMinWidth,se=i?.editMode?.specs?.modalIcon||"window",pe=i?.editMode?.specs?.modalTitle||"Record Form");const{Window:ce,setWindowState:ue}=Pe({height:re,minHeight:de,minWidth:le,onCloseCallBack:()=>{i.apiActions.reloadData(i?.gridLoadParametersValues)},width:ne,windowIcon:se,windowTitle:pe}),me={type:"actions",field:"actions",headerName:"",headerAlign:"center",width:(i?.rowActions?30*i.rowActions.length:0)+(i?.editAction&&i?.editAction?.isEnabled?30:0)+(i?.deleteAction&&i?.deleteAction?.isEnabled?30:0)+(i?.attachment?30:0)+(i?.workFlowDocumentCode?30:0),getActions:t=>{const a=t.row,r=[];if("none"!=i?.editMode?.editMode&&(void 0===i?.disableDefaultAction||!i.disableDefaultAction)){const t=z[a[X]]?.mode===B.GridRowModes.Edit;if("row"===i.editMode.editMode&&t)te&&(r.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(m.FontAwesomeIcon,{icon:"save"}),label:o("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const t=e[X];H({...z,[t]:{mode:B.GridRowModes.View}})})(a)}})),r.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(m.FontAwesomeIcon,{icon:"cancel"}),label:o("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const t=e[X];t&&so(t)&&t<0?(H({...z,[t]:{mode:B.GridRowModes.View,ignoreModifications:!0}}),J(e=>{const i=e.filter(e=>e[X]!=t);return i})):H({...z,[t]:{mode:B.GridRowModes.View,ignoreModifications:!0}})})(a)},color:"inherit"})));else{if(i?.editAction&&!0===i?.editAction?.isEnabled){let t=!0;i?.editAction?.isActionVisibleForRecord&&(t=i?.editAction?.isActionVisibleForRecord(a));let d=!1;i?.editAction?.isActionDisabledForRecord&&(d=i?.editAction?.isActionDisabledForRecord(a)),te&&t&&r.push(e.jsx(B.GridActionsCellItem,{disabled:d,icon:e.jsx(n.Tooltip,{title:o("EDIT_BTN_LABEL"),children:e.jsx(m.FontAwesomeIcon,{icon:"edit",style:{color:d?"gray":void 0}})}),showInMenu:i?.editAction?.gridActionProps?.showInMenu||!1,label:o("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{te&&!d&&(async e=>{if(e)if(K(e),"form"===i.editMode.editMode)W(i.editMode.specs.formRoute+"/"+e[X]);else if("modal"===i.editMode.editMode)ue(!0);else if("row"===i?.editMode?.editMode){const t=e[X];H({...z,[t]:{mode:B.GridRowModes.Edit}})}})(a)}}))}if(i?.deleteAction&&!0===i?.deleteAction?.isEnabled){let t=!0;i?.deleteAction?.isActionVisibleForRecord&&(t=i?.deleteAction?.isActionVisibleForRecord(a));let d=!1;i?.deleteAction?.isActionDisabledForRecord&&(d=i?.deleteAction?.isActionDisabledForRecord(a)),ie&&t&&r.push(e.jsx(B.GridActionsCellItem,{disabled:d,icon:e.jsx(n.Tooltip,{title:o("DELETE_BTN_LABEL"),children:e.jsx(m.FontAwesomeIcon,{icon:"trash",style:{color:d?"gray":void 0}})}),showInMenu:i?.deleteAction?.gridActionProps?.showInMenu||!1,label:o("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(ie&&!d){if(i?.deleteAction?.preActionValidation&&!i.deleteAction.preActionValidation(a))return;V(a),ae(!0)}}}))}}}if(a[i?.keyColumnName||"id"]&&a[i?.keyColumnName||"id"]>0&&i?.attachment&&r?.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(n.Tooltip,{title:"Attachments",children:e.jsx(m.FontAwesomeIcon,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{d(a),p(!i?.attachment?.enableAttachFn||i.attachment.enableAttachFn(a)),T(!0)}})),a[i?.keyColumnName||"id"]&&a[i?.keyColumnName||"id"]>0&&i?.workFlowDocumentCode&&r?.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(n.Tooltip,{title:"Approvals",children:e.jsx(m.FontAwesomeIcon,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{d(a),f(!0)}})),a[i?.keyColumnName||"id"]&&a[i?.keyColumnName||"id"]>0&&i?.rowActions)for(const t of i.rowActions)t?.gridActionProps?.multiRecord&&!0===t?.gridActionProps?.multiRecord||r.push(e.jsx(Co,{...t,record:a,reloadData:async()=>{i.apiActions.reloadData(i?.gridLoadParametersValues)}}));return r}};let Te=[];(void 0===i?.disableDefaultAction||!i.disableDefaultAction||i?.rowActions&&i?.rowActions.length>0)&&Te.push(me),Te=[...Te,...E];l.useEffect(()=>{void 0!==i?.autoLoad&&!0!==i.autoLoad||i.apiActions.reloadData(i?.gridLoadParametersValues),Q()},[]),l.useEffect(()=>{i.apiActions.reloadData(i?.gridLoadParametersValues)},[G.UserInfo?.currentOrganization]),l.useEffect(()=>{Q()},[g,i.formElements]);const Ae=l.useMemo(()=>{const e=Te.map(e=>({...e,width:b[e.field]||e.width}));if(M.length){const t=new Map(e.map(e=>[e.field,e]));return M.map(e=>t.get(e)).filter(Boolean)}return e},[M,b,Te]);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{}),"modal"===i?.editMode?.editMode?e.jsx(ce,{children:i?.editMode?.specs?.formComponent?e.jsx(i.editMode.specs.formComponent,{recordIdToEdit:q?q[X]:void 0,formCloseCallBk:()=>{ue(!1),i.apiActions.reloadData(i?.gridLoadParametersValues)}}):e.jsx(vo,{keyColumnName:i.keyColumnName,attachment:i.attachment,formLoadCallBk:i.formLoadCallBk,recordIdToEdit:q?q[X]:void 0,formCloseCallBk:()=>{ue(!1),i.apiActions.reloadData(i?.gridLoadParametersValues)},elements:i.formElements,apiActions:i.apiActions,editAuthorityKey:i?.editAction?.authority,formSavedSuccessfullyCallBk:i?.editAction?.postActionCallBack,preSaveValidation:i?.editAction?.preActionValidation,actions:i?.rowActions})}):e.jsx(e.Fragment,{}),void 0!==i?.hideInfoBar||i?.hideInfoBar?e.jsx(e.Fragment,{}):e.jsxs(n.Box,{sx:{display:"flex"},children:[void 0!==i?.hideBackButton||i?.hideBackButton?e.jsx(e.Fragment,{}):e.jsx(n.IconButton,{onClick:()=>{W(-1,{replace:!0})},children:e.jsx(m.FontAwesomeIcon,{icon:"ltr"===g?"arrow-left":"arrow-right"})}),e.jsxs(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[i?.girdIcon?e.jsx(m.FontAwesomeIcon,{icon:i.girdIcon,style:{marginRight:5,marginLeft:5}}):e.jsx(e.Fragment,{}),e.jsx(n.Typography,{variant:"h5",children:i?.gridTitle?co(o(i?.gridTitle)):""})]})]}),i?.gridLoadParameters&&i?.gridLoadParameters.length>0&&i?.gridLoadParametersValues&&i?.setGridLoadParametersValues?e.jsxs(n.Accordion,{defaultExpanded:!0,sx:{width:"100%"},children:[e.jsx(n.AccordionSummary,{expandIcon:e.jsx(B.GridExpandMoreIcon,{}),children:e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),e.jsx(n.Typography,{component:"span",children:"Filters"})]})}),e.jsx(n.AccordionDetails,{children:e.jsx(n.Box,{children:e.jsx(vo,{saveButtonSpecs:{label:o("SEARCH_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:o("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{null!=e?i.setGridLoadParametersValues(e):i.setGridLoadParametersValues({}),i.apiActions.reloadData(e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:i.gridLoadParameters})})})]}):e.jsx(e.Fragment,{}),i?.attachment?e.jsx(u,{children:e.jsx(Eo,{attachmentCode:i.attachment.attachmentCode,refKey:r[i?.keyColumnName||"id"],enableAttachment:s})}):e.jsx(e.Fragment,{}),i?.workFlowDocumentCode?e.jsx(_,{children:e.jsx(wo,{workFlowDocumentCode:i.workFlowDocumentCode,refDocumentId:r[i?.keyColumnName||"id"],postActionCallBk:()=>{f(!1),i.apiActions.reloadData(i.gridLoadParametersValues)},cancelActionCallBk:()=>{f(!1),i.apiActions.reloadData(i.gridLoadParametersValues)}})}):e.jsx(e.Fragment,{}),e.jsx(B.DataGridPremium,{...i?.muiProps,slots:{toolbar:Lo},slotProps:{toolbar:{templateProps:{...i,rowSelectionModel:Z,data:i?.data},handleCreateNewRecord:()=>{if("form"===i?.editMode?.editMode)W(i.editMode.specs.formRoute);else if("modal"===i?.editMode?.editMode)K(null),ue(!0);else if("row"===i?.editMode?.editMode){go-=1;const e={};e[X]=go,e.isNew=!0;for(const t of E)"actions"!=t?.type&&t?.field!=X&&t?.field&&(e[t.field]=null);J(t=>[e,...t]),H(e=>({...e,[go]:{mode:B.GridRowModes.Edit}}))}},clearGridState:()=>{i?.gridStateKey&&localStorage.removeItem(i.gridStateKey),P({}),x([]),S({}),w([]),j({left:[..."ltr"===g?Mo:[]],right:[..."rtl"===g?Mo:[]]})}}},getRowId:e=>e[X],showToolbar:!0,rows:i?.data,columns:Ae,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==i.editMode.editMode?z:void 0,onRowModesModelChange:"row"==i.editMode.editMode?e=>{H(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async t=>{if("row"===i.editMode.editMode){let o=null;const a=(e=>{try{ee.parse(e)}catch(e){console.log("validateRecord err",e);let t=null;return t=e instanceof y.z.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",t}})(t);if(a){const t=a.split(",");throw A.toast.error(e.jsx("div",{style:{},children:t.map(t=>e.jsxs(e.Fragment,{children:[e.jsx("div",{children:t}),e.jsx(n.Divider,{})]}))})),new Error(a)}if(i?.editAction?.preActionValidation&&!i.editAction.preActionValidation(t))throw new Error("error on the configured presave validation");const r={...t};if(t[X]&&so(t[X])&&Number(t[X])<0&&(r[X]=null),o=await i.apiActions.saveRecord(r),null==o)throw new Error("Failed to process your request, contact your administrator");return i?.editAction?.postActionCallBack&&await i.editAction.postActionCallBack(t),!0===t?.isNew&&J(e=>{const i=e.filter(e=>e[X]!==t[X]);return[o,...i]}),!0===i?.editMode?.reloadAfterSave&&i?.apiActions?.reloadData&&i?.apiActions?.reloadData(i?.gridLoadParametersValues),o}},rowSelectionModel:Z,onRowSelectionModelChange:e=>{$(e)},columnVisibilityModel:D,onColumnVisibilityModelChange:e=>{P(e),i?.gridStateKey&&Po(i.gridStateKey,{columnVisibilityModel:e})},onColumnOrderChange:e=>{const{column:t,targetIndex:o}=e;x(e=>{const a=e.length?[...e]:Te.map(e=>e.field),r=a.indexOf(t.field);return-1===r||(a.splice(r,1),a.splice(o,0,t.field),i?.gridStateKey&&Po(i.gridStateKey,{columnOrder:a})),a})},onColumnWidthChange:e=>{const t={...b,[e.colDef.field]:e.width};S(t),i?.gridStateKey&&Po(i.gridStateKey,{columnWidths:t})},rowGroupingModel:U,onRowGroupingModelChange:e=>{(e=>{w(e),i?.gridStateKey&&Po(i.gridStateKey,{columnGroupingModel:e})})(e)},sx:{width:"100%"}})]})},bo=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},So=t=>{const[i,o]=l.useState([]);return l.useEffect(()=>{const e=t.reportData.map((e,t)=>({...e,report_record_data_key:t}));o(e)},[t.reportData]),e.jsx(xo,{data:i,disableDefaultAction:!0,setData:t.setReportData,formElements:bo(t.reportData),gridLoadParameters:t.gridLoadParameters,gridLoadParametersValues:t.gridLoadParametersValues,setGridLoadParametersValues:t.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()=>{t.reloadReport()},saveRecord:async()=>{}}})},Uo=t=>{const[i,o]=l.useState(null),[a,r]=l.useState(null),[d,s]=l.useState([]),[p,c]=l.useState("WAITING_REPORT_CODE"),{handleGetRequest:u,handlePostRequest:T,HandleDownloadHTTPPostPDF:A}=Ce(),[_,f]=l.useState(null),[E,O]=l.useState({...t?.reportParametersValues}),[N,y]=l.useState([]),{t:h}=I.useTranslation(),R=e=>{const t=[];for(const i of e){const e={type:"field",mode:"props",props:{fieldLabel:i?.parameterLabel,fieldName:i?.parameterCode,fieldType:i?.parameterType,hidden:i?.hidden,formProps:{fieldSize:{lg:4,md:6,sm:12}},required:i?.mandatory,defaultValue:E[i?.parameterCode]||i?.defaultValue}};t.push(e)}return t},L=async(e,i)=>{c("WAITING_RESULT"),"Excel"===e?.reportType?await T({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:t.reportCode,parameters:i,resultMode:t.resultMode,jasperOutPutFileType:t.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT"),s(e.data)}}):e?.reportType&&await A({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:t.reportCode,parameters:i,resultMode:t.resultMode,jasperOutPutFileType:t.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT");const t=e.headers["content-disposition"];let i="downloaded_file";if(t&&-1!==t.indexOf("filename=")){const e=t.match(/filename="?([^"]+)"?/);e&&e[1]&&(i=e[1])}if(i.includes("pdf")){const t=new Blob([e.data],{type:"application/pdf"}),i=URL.createObjectURL(t);o(i)}else{const t=new Blob([e.data],{type:e.headers["content-type"]}),o=window.URL.createObjectURL(t),a=document.createElement("a");a.href=o,a.download=i,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(o)}},failureCallBkFn:e=>{r("Failed To run report ... contact your administrator"),c("ERROR")}})};return l.useEffect(()=>{t?.reportCode&&(async()=>{c("LOADING_METADATA"),await u({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:t.reportCode},successCallBkFn:e=>{f(e.data),y(R(e.data.reportParameters)),!0===t?.byPassParameterEntry||0==e.data.reportParameters.length?(L(e.data,E),c("WAITING_RESULT")):c("WAITING_PARAMETER_INPUT")},failureCallBkFn:e=>{r("Failed loading report metadata ... contact your administrator"),c("ERROR")}})})()},[t.reportCode,t.byPassParameterEntry,t.reportParametersValues,t.jasperOutPutFileType,t.resultMode]),e.jsxs(e.Fragment,{children:[e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[e.jsxs(n.Box,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[e.jsx(m.FontAwesomeIcon,{icon:"Excel"===_?.reportType?"file-excel":"file-pdf",color:"Excel"===_?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),_?.reportName]}),"Excel"!=_?.reportType&&"SHOWING_RESULT"===p?e.jsxs(e.Fragment,{children:[!0===t?.byPassParameterEntry?e.jsx(e.Fragment,{}):N.length>0?e.jsx(n.IconButton,{onClick:()=>{y(R(_.reportParameters)),c("WAITING_PARAMETER_INPUT")},children:e.jsx(m.FontAwesomeIcon,{icon:"filter"})}):e.jsx(e.Fragment,{}),e.jsx(n.IconButton,{children:e.jsx(m.FontAwesomeIcon,{icon:"refresh",onClick:()=>{L(_,E)}})})]}):e.jsx(e.Fragment,{})]}),e.jsx(n.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===p&&"Excel"!=_?.reportType?e.jsxs(n.Accordion,{defaultExpanded:!0,sx:{width:"100%"},expanded:!0,children:[e.jsx(n.AccordionSummary,{children:e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),e.jsx(n.Typography,{component:"span",children:"Filters"})]})}),e.jsx(n.AccordionDetails,{children:e.jsx(n.Box,{children:e.jsx(vo,{saveButtonSpecs:{label:h("SHOW_REPORT_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success",hidden:!0},cancelButtonSpecs:{label:h("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{O(null!=e?e:{}),L(_,e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:N})})})]}):"SHOWING_RESULT"===p||("WAITING_PARAMETER_INPUT"===p||"WAITING_RESULT"===p)&&"Excel"===_?.reportType?"Excel"===_?.reportType?e.jsx(So,{reportData:d,setReportData:s,reloadReport:async()=>{L(_,E)},gridLoadParameters:N,gridLoadParametersValues:E,setGridLoadParametersValues:O}):e.jsx("iframe",{src:i,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===p?e.jsxs(n.Box,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[e.jsx(m.FontAwesomeIcon,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),a]}):e.jsx(e.Fragment,{})})]})},wo=i=>{const o=O.useNavigate(),a=t.useSelector(e=>e.AppLayout),{isUserAuthorized:r,UserInfo:d}=De(),{handleGetRequest:s,handlePostRequest:p}=Ce(),[c,u]=l.useState(null),[T,_]=l.useState([]),{t:f}=I.useTranslation(),[E,N]=l.useState(null),[y,h]=l.useState({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:R,setWindowState:L}=Pe({windowTitle:"ltr"===a.appDirection?y?.workflowDocument&&y?.referencedDocument?`${y?.workflowDocument?.documentEnName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`:"Document":y?.workflowDocument&&y?.referencedDocument?`${y?.workflowDocument?.documentArName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),C=async()=>{await s({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:i.workFlowDocumentCode,refDocumentId:i.refDocumentId},successCallBkFn:e=>{h(e.data)},failureCallBkFn:()=>{h({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},g=async()=>{await p({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:y?.workflowDocument?.id,refDocumentId:i.refDocumentId,actionId:c.id,refDocumentStatus:y?.workflowDocumentStatus?.documentStatusCode,actionComment:E},successCallBkFn:async e=>{c?.post_action_endpoint?await p({endPointURI:c.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:i.refDocumentId,actionId:c.id},successCallBkFn:()=>{C(),i?.postActionCallBk&&i.postActionCallBk()}}):C()}})};return l.useEffect(()=>{i.refDocumentId&&i.workFlowDocumentCode&&C()},[i.refDocumentId,i.workFlowDocumentCode]),l.useEffect(()=>{_(y?.nextActions&&y?.nextActions?.length>0?y.nextActions.filter(e=>{if(!y?.workflowDocumentStatus?.nextActionTakersAuthority&&!y?.nextActionTakers)return!0;if(y?.workflowDocumentStatus?.nextActionTakersAuthority&&r(y.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(y?.nextActionTakers)for(const e of y.nextActionTakers)if(d?.username===e?.username||d?.username===e?.USERNAME)return!0;return!1}):[])},[y.nextActions,y.nextActionTakers]),e.jsxs(e.Fragment,{children:[y?.workflowDocumentReport?.id?e.jsx(R,{children:e.jsx(Uo,{reportCode:y?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:i.refDocumentId+""}})}):e.jsx(e.Fragment,{}),y?.workflowDocument?e.jsxs(n.Box,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(n.IconButton,{onClick:()=>{o(-1,{replace:!0})},children:e.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),e.jsx(n.Box,{sx:{flex:1}}),e.jsx(m.FontAwesomeIcon,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===a.appDirection?`${y?.workflowDocument?.documentEnName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`:`${y?.workflowDocument?.documentArName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`,y?.workflowDocumentStatus?"ltr"===a.appDirection?` ( ${y?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${y?.workflowDocumentStatus?.documentStatusArName} )`:"",e.jsx(n.Box,{sx:{flex:1}}),y?.workflowDocumentReport?.id?e.jsx(n.Button,{onClick:()=>{L(!0)},variant:"outlined",startIcon:e.jsx(m.FontAwesomeIcon,{icon:"eye"}),children:f("VIEW_LABEL")}):e.jsx(e.Fragment,{})]}):e.jsx(e.Fragment,{}),e.jsxs(n.Box,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[T?.length>0?e.jsxs(n.Paper,{sx:{padding:2,display:"flex",flex:1,margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[e.jsx(je,{sx:{marginBottom:2,width:400},label:f("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===a.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:c?.id,options:T,onChangeCallBack:(e,t)=>{u(t)}}),e.jsx(we,{sx:{width:400},rows:3,value:E,onChange:e=>{N(e.target.value)},multiline:!0,label:f("WF_COMMENT_LABEL")}),e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(n.Button,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=c&&null!=c?.id?!0!==c.require_comment&&1!==c.require_comment&&"true"!==c.require_comment||null!==E&&""!==E?c?.pre_action_endpoint?await p({endPointURI:c.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:i.refDocumentId,actionId:c.id},successCallBkFn:()=>{g()}}):g():A.toast.error("You must enter comment for the action to be processed"):A.toast.error("You must select action to process")},children:f("WF_TAKE_ACTION_BTN_LABEL")}),i?.cancelActionCallBk?e.jsx(n.Button,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{i?.cancelActionCallBk&&i.cancelActionCallBk()},children:f("WF_CANCEL_BTN_LABEL")}):e.jsx(e.Fragment,{})]}),y?.nextActionTakers&&y.nextActionTakers.length>0?e.jsxs(e.Fragment,{children:[e.jsx(n.Divider,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:e.jsxs(n.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[e.jsx(m.FontAwesomeIcon,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",f("WF_WAITING_FOR_LABEL")]})}),e.jsx(n.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:y.nextActionTakers.map(t=>e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[e.jsx(fo,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:t?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),e.jsxs(n.Box,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[e.jsx("div",{children:"ltr"===a.appDirection?t?.employee_en_name:t?.employee_ar_name}),e.jsx("div",{children:t?.email?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),t?.email]}):e.jsx(e.Fragment,{})}),e.jsx("div",{children:t?.mobile_number?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),t?.mobile_number]}):e.jsx(e.Fragment,{})})]})]}))})]}):e.jsx(e.Fragment,{})]}):e.jsx(e.Fragment,{}),y?.actionsHistory.length>0?e.jsx(Oo,{actionHistory:y.actionsHistory}):e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[e.jsxs(n.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[e.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),f("WF_ACTION_HISTORY_LABEL")]}),e.jsx(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},vo=t=>{const{Window:i,setWindowState:o}=Pe({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),{Window:a,setWindowState:r}=Pe({windowTitle:"Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[d,s]=l.useState(!0),{t:p}=I.useTranslation(),c=tt(t.elements),u=[];for(const e of c)e?.hidden&&u.push(e.fieldName);const[T,_]=l.useState(u),f={};for(const e of t.elements)"field"===e?.type&&"props"===e?.mode&&e?.props?.defaultValue&&(f[e.props.fieldName]=e.props.defaultValue);const[y,h]=l.useState([]),R=ce.object(ot(c)),L=E.useForm({resolver:N.zodResolver(R),defaultValues:f}),C=L.watch(),g=O.useParams(),D=t?.formRouteRecordIdParamName,P=async()=>{let e=null;if(t?.recordIdToEdit?e=t.recordIdToEdit:D&&g[D]&&(e=g[D]),e){const i=await t.apiActions.loadRecordById(e);if(i){L.reset({...i}),t?.formLoadCallBk&&t?.formLoadCallBk(M,L,i);for(const e of c)"combobox"===e?.fieldType&&i[e.fieldName]&&L.setValue(e.fieldName,i[e.fieldName]+"")}}else L.reset({})},M={setFieldValue:(e,t)=>{L.setValue(e,t)},hideField:e=>{_(t=>[...t,e])},showField:e=>{_(t=>t.filter(t=>t!==e))},disableField:e=>{h(t=>[...t,e])},enableField:e=>{h(t=>t.filter(t=>t!==e))}};return l.useEffect(()=>{P()},[t?.recordIdToEdit]),l.useEffect(()=>{s(!t?.attachment||!t?.attachment?.enableAttachFn||t.attachment.enableAttachFn(C))},[C]),e.jsxs(e.Fragment,{children:[t?.attachment?e.jsx(i,{children:e.jsx(Eo,{attachmentCode:t.attachment.attachmentCode,refKey:C[t?.keyColumnName||"id"],enableAttachment:d})}):e.jsx(e.Fragment,{}),t?.workFlowDocumentCode?e.jsx(a,{children:e.jsx(wo,{workFlowDocumentCode:t.workFlowDocumentCode,refDocumentId:C[t?.keyColumnName||"id"],postActionCallBk:()=>{r(!1),P()},cancelActionCallBk:()=>{r(!1)}})}):e.jsx(e.Fragment,{}),e.jsx(lo,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:e.jsx(n.Grid2,{sx:{width:"100%"},container:!0,children:t.elements.map((t,i)=>"group"===t.type?e.jsx(_o,{...t.props,formManager:L,formValues:C,formActions:M,hiddenFields:T,disabledFields:y},i):"field"===t.type&&"props"===t.mode?e.jsx(To,{fieldInfo:t.props,formManager:L,formValues:C,formActions:M,hiddenFields:T,disabledFields:y},i):"field"===t.type&&"node"===t.mode?e.jsx(n.Grid2,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:e.jsx(t.node,{formManager:L,formValues:C})},i):void 0)})}),e.jsxs(lo,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[C[t?.keyColumnName||"id"]&&t?.attachment?e.jsx(n.Tooltip,{title:"Attachments",children:e.jsx(n.IconButton,{onClick:()=>{o(!0)},children:e.jsx(m.FontAwesomeIcon,{icon:"paperclip"})})}):null,C[t?.keyColumnName||"id"]&&t?.workFlowDocumentCode?e.jsx(n.Tooltip,{title:"Approvals",children:e.jsx(n.IconButton,{onClick:()=>{r(!0)},children:e.jsx(m.FontAwesomeIcon,{icon:"stamp"})})}):null,t?.actions&&C[t?.keyColumnName||"id"]?t.actions.map(t=>!0===t?.formActionProps?.enabled?e.jsx(Ao,{...t,record:C}):e.jsx(e.Fragment,{})):e.jsx(e.Fragment,{}),e.jsx("div",{style:{flex:1}}),e.jsx(n.Button,{variant:t?.saveButtonSpecs?.actionButtonVariant?t.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:t?.saveButtonSpecs?.icon?e.jsx(m.FontAwesomeIcon,{icon:t.saveButtonSpecs.icon}):null,color:t?.saveButtonSpecs?.actionButtonColor?t.saveButtonSpecs.actionButtonColor:"primary",onClick:L.handleSubmit(e=>{(async e=>{if((!t?.preSaveValidation||t.preSaveValidation(e))&&e){const i=await t.apiActions.saveRecord(e);i&&(L.reset({...i}),t?.formSavedSuccessfullyCallBk&&t.formSavedSuccessfullyCallBk(i),t?.formCloseCallBk&&t.formCloseCallBk())}})(e)},e=>{A.toast.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:p(t?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),e.jsx(n.Button,{variant:t?.cancelButtonSpecs?.actionButtonVariant?t.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:t?.cancelButtonSpecs?.icon?e.jsx(m.FontAwesomeIcon,{icon:t.cancelButtonSpecs.icon}):null,color:t?.cancelButtonSpecs?.actionButtonColor?t.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{t?.formCloseCallBk&&t.formCloseCallBk(),L.reset(f)},children:p(t?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},Fo=()=>{const{workflowDocumentCode:t,refDocumentId:i}=O.useParams();return e.jsx(wo,{workFlowDocumentCode:t,refDocumentId:i})},Bo=t=>e.jsx(k.BarChart,{dataset:t.data,xAxis:[{dataKey:t.valueField,scaleType:"band",label:t.valueLabel}],series:t.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),ko=t=>e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[e.jsx(n.Box,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:e.jsx("div",{children:t.record[t.valueField]})}),e.jsx(n.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]})]}),jo=t=>e.jsxs(e.Fragment,{children:[e.jsx(n.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]}),e.jsx(k.Gauge,{width:200,height:200,value:t.record[t.valueField],valueMax:t.total})]}),Go=t=>e.jsx(k.LineChart,{dataset:t.data,xAxis:[{dataKey:t.valueField,scaleType:"band",label:t.valueLabel}],series:t.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function Wo(t){return e.jsxs(G,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(G,{sx:{width:"100%",mr:1},children:e.jsx(j,{variant:"determinate",...t})}),e.jsx(G,{sx:{minWidth:35},children:e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(t.value)}%`})})]})}const Yo=t=>e.jsxs(G,{sx:{width:"100%"},children:[e.jsx(F,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]}),e.jsx(Wo,{value:t.record[t.valueField]/t.total*100})]}),Vo=t=>{const i=t.data.map((e,i)=>({id:i,value:e[t.valueField],label:e[t.labelField]+""}));return e.jsx(W.PieChart,{series:[{data:i}]})},qo=t=>{const[i,o]=l.useState(!0),[a,r]=l.useState([]),{handleGetRequest:d}=Ce();l.useEffect(()=>{(async()=>{o(!0),await d({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:t.dataQueryId,...t.parameterValues},successCallBkFn:e=>{o(!1),r(e.data)},failureCallBkFn:()=>{o(!1),r(null)}})})()},[t.parameterValues]);let s=0;if(1==a.length&&(s=100),"CircularProgress"===t.widgetType||"LinearProgress"===t.widgetType)for(const e of a)s+=e[t.verticalAxisField];return e.jsxs(e.Fragment,{children:["LineChart"===t.widgetType||"PieChart"===t.widgetType||"ColumnChart"===t.widgetType?e.jsxs(n.Box,{children:[e.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:t?.icon||"chart-pie"}),t?.title]}):e.jsx(e.Fragment,{}),e.jsx(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:i?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),e.jsx("div",{children:"Loading"})]}):"ColumnChart"===t.widgetType?e.jsx(Bo,{data:a,widgetTitle:t.title,labelField:t.verticalAxisField,valueField:t.horizontalAxisField,valueLabel:t.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===t.widgetType?e.jsx(Go,{data:a,widgetTitle:t.title,labelField:t.verticalAxisField,valueField:t.horizontalAxisField,valueLabel:t.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===t.widgetType?e.jsx(Vo,{data:a,widgetTitle:t.title,labelField:t.horizontalAxisField,valueField:t.verticalAxisField,widgetType:"Line"}):e.jsxs(n.Grid2,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[e.jsx(n.Grid2,{size:{xs:12},sx:{textAlign:"center"},children:t.title}),a.map((i,o)=>"Card"===t.widgetType?e.jsx(n.Grid2,{size:{md:3,xs:12},children:e.jsx(ko,{widgetTitle:"",record:i,labelField:t.verticalAxisField,valueField:t.horizontalAxisField},o)}):"CircularProgress"===t.widgetType?e.jsx(n.Grid2,{size:{md:3,xs:12},children:e.jsx(jo,{widgetTitle:"",record:i,labelField:t.horizontalAxisField,valueField:t.verticalAxisField,total:s},o)}):"LinearProgress"===t.widgetType?e.jsx(n.Grid2,{size:{md:3,xs:12},children:e.jsx(Yo,{widgetTitle:"",record:i,labelField:t.horizontalAxisField,valueField:t.verticalAxisField,total:s},o)}):void 0)]})})]})},Ko=t=>{const[i,o]=l.useState({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),[a,r]=l.useState(t?.parameters||{}),d=O.useNavigate(),{handleGetRequest:s,handlePostRequest:p}=Ce();return l.useEffect(()=>{t.dashboardCode&&(async()=>{await s({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:t.dashboardCode},successCallBkFn:e=>{o(e.data)},failureCallBkFn:()=>{o(null)}})})()},[t.dashboardCode,t.parameters]),e.jsx(e.Fragment,{children:i?e.jsxs(e.Fragment,{children:[e.jsxs(n.Box,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(n.IconButton,{onClick:()=>{d(-1,{replace:!0})},children:e.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),e.jsx(n.Box,{sx:{flex:1}}),e.jsx(m.FontAwesomeIcon,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),e.jsx(n.Box,{children:i?.dashboardTitle}),e.jsx(n.Box,{sx:{flex:1}})]}),e.jsx(n.Grid2,{container:!0,spacing:1,sx:{flexGrow:1,overflowY:"auto",padding:1},children:i?.widgets.map((t,i)=>e.jsx(n.Grid2,{sx:{alignItems:"center",justifyContent:"center",padding:1,display:"flex",overflow:"auto",flexDirection:"Card"!=t.widgetType?"column":void 0,height:t?.height||300},size:{md:t?.width,sm:12},children:e.jsx(qo,{...t})},i))})]}):e.jsx(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},zo=()=>{const{dashboardCode:t}=O.useParams();return e.jsx(Ko,{dashboardCode:t})},Ho=i=>{const{UserSession:o}=De(),a=t.useSelector(e=>e.AppLayout),r=t.useDispatch(),{handlePostRequest:d}=Ce(),[s,p]=l.useState(o.value.currentOrganization.id);return e.jsxs(n.Box,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[e.jsx(je,{sx:{width:"100%"},displayField:"ltr"===a.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:o.value.userOrganizations,value:s,onChangeCallBack:e=>{p(e)}}),e.jsx(n.Button,{sx:{m:1},variant:"contained",disabled:null==s||s===o.value.currentOrganization.id,onClick:async()=>{await d({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:o.value.username,orgId:s},data:{},successCallBkFn:e=>{const t={...e.data,isAuthenticated:!0};r(Re.setAuthenticated(t)),i.successChangeCallBackFn&&i.successChangeCallBackFn()}})},children:"Change Organization"})]})},Qo=T.createSlice({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Zo,setSideBarState:$o}=Qo.actions;var Xo=Qo.reducer;function Jo(e,t){const i=l.useRef(e);l.useEffect(()=>{i.current=e},[e]),l.useEffect(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const ea=n.keyframes`
31
+ function(e,t){const i=oe(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})($i),d=pe.forwardRef(function(t,d){const l=function(e=eo){return Ji(e)}(o),{className:s,component:p="div",...c}=to(t);return e.jsx(n,{as:p,ref:d,className:ro(s,r?r(a):a),theme:i&&l[i]||l,...c})});return d}({defaultClassName:function(e,t,i="Mui"){const o={};return t.forEach(t=>{o[t]=function(e,t,i="Mui"){const o=no[t];return o?`${i}-${o}`:`${oo.generate(e)}-${t}`}(e,t,i)}),o}("MuiBox",["root"]).root,generateClassName:oo.generate});function so(e){return"number"==typeof e&&!isNaN(e)}function po(e){return"string"==typeof e&&""!==e.trim()&&!isNaN(Number(e))}function co(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function uo(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function mo(e,t){const i=new Date(e),o=new Date,a=Math.floor((i-o)/1e3),r="rtl"===t?"ar":"en",n=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),d=[{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 d){const i=Math.floor(a/t);if(Math.abs(i)>1)return n.format(i,e)}return"ar"===r?"الآن":"just now"}"production"!==process.env.NODE_ENV&&(lo.propTypes={children:wt.node,component:wt.elementType,sx:wt.oneOfType([wt.arrayOf(wt.oneOfType([wt.func,wt.object,wt.bool])),wt.func,wt.object])});const To=t=>{if(t?.fieldInfo){const i=t.fieldInfo,o=t?.formManager||null,a=t?.formActions||null,r=t?.formValues||null,d=t?.fieldInfo?.fieldName||null,l=t?.fieldInfo?.fieldType||null;return i&&o&&r&&d&&l?t.hiddenFields.includes(d)?e.jsx(e.Fragment,{}):e.jsx(n.Grid2,{size:i?.formProps?.fieldSize||{lg:12,md:12,sm:12},sx:{padding:1,width:"100%"},children:"text"===l||"number"===l?e.jsx(we,{...i.muiTextFieldProps,fullWidth:!0,type:l,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),label:i?.fieldLabel,value:r[d],onChange:e=>{let t=null;""!=e.target.value&&(t="number"===l&&po(e.target.value)?Number(e.target.value):e.target.value),o.setValue(d,t),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(t,o,a)},sx:{"& .MuiInputBase-root":{height:`${i?.formProps?.fieldHeight}px`||void 0},"& .MuiInputBase-input":{height:"100% !important"},...i?.formProps?.style},error:null!=o.formState.errors[d],helperText:o?.formState?.errors[d]?.message?.toString()}):"date"===i?.fieldType?e.jsx(ze,{format:i?.dateFormat||Ge,sx:i?.formProps?.style||{width:"100%"},disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),label:i?.fieldLabel,onChangeCallBack:e=>{o.setValue(d,e),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(e,o,a)},value:r[d],error:null!=o.formState.errors[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):"datetime"===i?.fieldType?e.jsx(He,{format:i?.dateFormat||We,sx:i?.formProps?.style||{width:"100%"},disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),label:i?.fieldLabel,onChangeCallBack:e=>{o.setValue(d,e),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(e,o,a)},hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),value:r[d],error:null!=o.formState.errors[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):"checkbox"===i?.fieldType?e.jsx(ke,{label:i?.fieldLabel,onChangeCallBack:e=>{o.setValue(d,e),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(e,o,a)},hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),value:r[d],checkedValue:i?.checkedValue||!0,unCheckedValue:i?.unCheckedValue||!1,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),sx:i?.formProps?.style}):"combobox"===i?.fieldType?e.jsx(je,{sx:i?.formProps?.style||{width:"100%"},label:i?.fieldLabel,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),onChangeCallBack:(e,t)=>{let r=null;e&&(r=e),o.setValue(d,r),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(r,o,a,t)},options:i?.options||[],displayField:i?.optionDisplayField||"",valueField:i?.optionValueField||"",value:r[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):"lookup"===i?.fieldType?e.jsx(Qe,{sx:i?.formProps?.style||{width:"100%"},label:i?.fieldLabel,disabled:!(!i?.disabled&&!t.disabledFields.includes(d)),hidden:!(!i?.hidden&&!t.hiddenFields.includes(d)),onChangeCallBack:(e,t)=>{let r=null;e&&(r=e),o.setValue(d,r),i?.formProps?.onValueChangeCallBack&&i?.formProps?.onValueChangeCallBack(r,o,a,t)},lookupType:i.lookupType,value:r[d],errorMessage:o?.formState?.errors[d]?.message?.toString()}):null}):e.jsx(e.Fragment,{})}return e.jsx(e.Fragment,{})},Ao=t=>{const i=De(),{ConfirmationWindow:o,setOpen:a}=ge({body:t?.confirmationMessage||"",title:"Confirmation",onConfirmationCallBk:()=>{t?.actionFn(t?.record)}});return null==t?.authority||i.isUserAuthorized(t.authority)?e.jsxs(e.Fragment,{children:[e.jsx(o,{}),e.jsxs(n.Button,{variant:t?.formActionProps?.actionButtonVariant,color:t?.formActionProps?.actionButtonColor,onClick:()=>{if(t?.actionFn){if(t?.preActionValidation&&!t.preActionValidation(t.record))return;!0===t?.isConfirmationRequired?a(!0):t?.actionFn(t.record)}},children:[t?.icon?e.jsx(m.FontAwesomeIcon,{icon:t.icon,style:{marginRight:5,marginLeft:5}}):e.jsx(e.Fragment,{}),e.jsx("div",{children:t?.label})]})]}):e.jsx(e.Fragment,{})},_o=t=>{const{t:i}=I.useTranslation();return e.jsx(e.Fragment,{children:e.jsxs(n.Grid2,{container:!0,sx:t?.style,alignItems:"flex-start",children:[t?.label?e.jsx(n.Grid2,{size:12,sx:{padding:1,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"flex-start"},children:t?.icon?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:t.icon,style:{marginRight:5,marginLeft:5}}),e.jsx("div",{children:i(t.label)})]}):e.jsx(e.Fragment,{children:i(t.label)})}):e.jsx(e.Fragment,{}),t?.elements?t.elements.map(i=>"group"===i.type?e.jsx(_o,{...i.props,formManager:t.formManager,formValues:t.formValues,formActions:t.formActions,hiddenFields:t.hiddenFields,disabledFields:t.disabledFields}):"field"===i.type&&"props"===i.mode?e.jsx(To,{fieldInfo:i.props,formManager:t.formManager,formValues:t.formValues,formActions:t.formActions,hiddenFields:t.hiddenFields,disabledFields:t.disabledFields}):"field"===i.type&&"node"===i.mode?e.jsx(n.Grid2,{size:i?.props?.formProps?.fieldSize||{lg:3,md:6,sm:12},sx:{padding:1,width:"100%"},children:e.jsx(i.node,{formManager:t.formManager,formValues:t.formValues,formActions:t.formActions})}):void 0):null,t?.actions?e.jsx(n.Grid2,{size:{sm:12},sx:{padding:1},children:t.actions.map(i=>e.jsx(Ao,{...i,record:t.formValues}))}):e.jsx(e.Fragment,{})]})})},fo=i=>{const o=t.useSelector(e=>e.AppInfo.value.apiBaseUrl),[a,r]=l.useState(null);return l.useEffect(()=>{(()=>{let e=o+"/api/v1/attachment/";i?.attachmentId?e+="download?attachmentId="+i.attachmentId:(e+=`downloadImage?attachmentCode=${i.attachmentCode}&refKey=${i.refKey}`,i?.category&&(e+=`&category=${i.category}`)),r(e)})()},[i]),i?.showAsAvatar?e.jsx(n.Avatar,{sx:i.style,onError:()=>{r(i?.onErrorImage?i.onErrorImage:"/no_image.png")},src:a}):e.jsx("img",{src:a,loading:"lazy",alt:"image",onError:()=>{r(i?.onErrorImage?i.onErrorImage:"/no_image.png")},style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},Io=t=>{const{handleGetRequest:i,handleDeleteRequest:o}=Ce(),{isUserAuthorized:a}=De();let r=!0;t?.downloadAuthorityKey&&(r=a(t.downloadAuthorityKey));const{ConfirmationWindow:d,setOpen:l}=ge({title:"Confirmation",body:"Are you sure you want to delete this attachment?",onConfirmationCallBk:()=>{(async()=>{await o({endPointURI:"api/v1/attachment/archive",parameters:{attachmentCode:t.attachmentCode,refKey:t.refKey,attachmentId:t.id},successCallBkFn:e=>{t.setAttachmentConfig(e.data)},showMask:!0})})()}});return e.jsxs(e.Fragment,{children:[e.jsx(d,{}),e.jsxs(R,{sx:{width:300,border:"0.5px solid gray"},children:[e.jsx(v,{sx:{height:140,width:300,display:"flex",alignItems:"center",justifyContent:"center"},children:t?.docType.toLocaleLowerCase().includes("image")?e.jsx(fo,{attachmentId:t.id}):e.jsx(m.FontAwesomeIcon,{icon:"file",size:"3x"})}),e.jsxs(w,{children:[e.jsx(F,{gutterBottom:!0,variant:"h6",component:"div",children:t.fileName}),e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Size: ${t?.attachmentSize||"unknown"} kb`}),e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`File Type: ${t?.category||"NA"}`}),e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:t.remark})]}),e.jsxs(U,{children:[t?.allowDelete?e.jsx(n.IconButton,{size:"small",onClick:()=>{l(!0)},children:e.jsx(n.Tooltip,{title:"Delete Attachment",children:e.jsx(m.FontAwesomeIcon,{icon:"trash"})})}):e.jsx(e.Fragment,{}),e.jsx("div",{style:{flex:1}}),r?e.jsx(n.IconButton,{size:"small",onClick:async()=>{await i({endPointURI:"api/v1/attachment/download",parameters:{attachmentId:t.id},showMask:!0,responseType:"blob",successCallBkFn:e=>{const i=window.URL.createObjectURL(new Blob([e.data])),o=document.createElement("a");o.href=i,o.setAttribute("download",t.fileName),document.body.appendChild(o),o.click(),o.remove()}})},children:e.jsx(n.Tooltip,{title:"Download Attachment",children:e.jsx(m.FontAwesomeIcon,{icon:"download"})})}):e.jsx(e.Fragment,{})]})]})]})},Eo=t=>{const{handleUploadRequest:i,handleGetRequest:o}=Ce(),[a,r]=l.useState(null),[d,s]=l.useState([]),[p,c]=l.useState(null),[u,T]=l.useState(null),[_,f]=l.useState([]),[I,E]=l.useState(null),{isUserAuthorized:O}=De(),N=e=>e.split(".").pop()?.toLowerCase()||"";l.useEffect(()=>{(async()=>{await o({endPointURI:"api/v1/attachment/info",showMask:!0,parameters:{attachmentCode:t.attachmentCode,refKey:t.refKey},successCallBkFn:e=>{E(e.data)}})})()},[t.refKey,t.attachmentCode]),l.useEffect(()=>{if(f(I?.allowedFileTypes?I.allowedFileTypes.split(","):[]),I?.attachmentCategories){const e=[];for(const t of I.attachmentCategories.split(","))e.push({value:t});s(e)}else s([])},[I]);let y=!0;I?.downloadAuthorityKey&&!O(I?.downloadAuthorityKey)&&(y=!1);let h=!0;return!1===t?.enableAttachment&&(h=!1),I?.uploadAuthorityKey&&!O(I.uploadAuthorityKey)&&(h=!1),e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"flex-start",overflow:"hidden",flexGrow:1},children:[h?e.jsx(e.Fragment,{children:null==I?.maxAllowedNumberOfFiles||I?.maxAllowedNumberOfFiles>I.refKeyAttachments.length?e.jsxs(e.Fragment,{children:[e.jsxs("h3",{children:[e.jsx(m.FontAwesomeIcon,{icon:"paperclip",style:{marginRight:10,marginLeft:10}}),"Attachment Uploader"]}),e.jsx("input",{type:"file",style:{margin:20},accept:I?.allowedFileTypes,multiple:!0,onChange:e=>{if(e.target.files)for(const t of e.target.files){const e=N(t.name);if(_.length>0&&!_.includes(e))return void A.toast.error(e+" is not allowed")}r(e.target.files)}}),d.length>0?e.jsx(je,{label:"Attachment Type",sx:{width:300,m:1},options:d,displayField:"value",valueField:"value",value:u,onChangeCallBack:e=>{T(e)}}):e.jsx(e.Fragment,{}),e.jsx(we,{label:"Remark",value:p,onChange:e=>c(e.target.value),multiline:!0,sx:{width:300,m:1},rows:3}),e.jsx(n.Button,{sx:{m:1},variant:"contained",onClick:async()=>{let e=I?.refKeyAttachments.length||0;if(I?.maxAllowedNumberOfFiles&&a.length+e>I.maxAllowedNumberOfFiles)A.toast.error("Maximum number of attachments is "+I.maxAllowedNumberOfFiles);else if(!0===I?.isCategoryRequired&&d.length>0&&(null==u||void 0===u||""===u))A.toast.error("You must selected document type to process your request");else if(a){for(const e of a)if(e.type.startsWith("image/")){const t=600,i=1024*t;if(e.size>i)return void A.toast.error(`File ${e.name} is too large. Max allowed is ${t}KB.`)}await i({endPointURI:"api/v1/attachment/upload",showMask:!0,loadingMessage:"Uploading files ... please wait",parameters:{refKey:t.refKey,attachmentCode:t.attachmentCode,remark:p,category:u},files:a,successCallBkFn:e=>{E(e.data),r(null),T(null),c(null),A.toast.success("Your request has been process successfully")}})}else A.toast.error("You must add files to upload")},children:"Upload"})]}):e.jsx(e.Fragment,{})}):e.jsx(e.Fragment,{}),y&&I?.refKeyAttachments?.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("h3",{children:[e.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:"paperclip"}),"Attachments"]}),e.jsx(n.Grid2,{container:!0,spacing:2,sx:{overflow:"auto",padding:1,justifyContent:"center"},children:I?.refKeyAttachments.map(i=>e.jsx(n.Grid2,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:e.jsx(Io,{...i,attachmentCode:t.attachmentCode,setAttachmentConfig:E,downloadAuthorityKey:I.downloadAuthorityKey,allowDelete:h})}))})]}):e.jsx(e.Fragment,{})]})},Oo=i=>{const o=t.useSelector(e=>e.AppLayout),{t:a}=I.useTranslation();return e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:1,margin:1,alignItems:"center",justifyContent:"center"},children:[e.jsxs(n.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[e.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),a("WF_ACTION_HISTORY_LABEL")]}),e.jsx(n.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",overflowY:"auto",alignItems:"center",justifyContent:"flex-start"},children:i.actionHistory.map((t,a)=>e.jsx(e.Fragment,{children:e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",marginBottom:2},children:[e.jsxs(n.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-end",justifyContent:"center"},children:[e.jsx(n.Box,{sx:{marginBottom:.2},children:t.actionTime}),e.jsxs(F,{children:["via ",t.actionMethod]})]}),e.jsxs(n.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",marginRight:2,marginLeft:2},children:[e.jsx(fo,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:t?.personId+""||"0",style:{m:1,width:70,height:70}}),a!==i.actionHistory.length-1?e.jsx(n.Box,{sx:{marginTop:11,position:"absolute"},children:"|"}):e.jsx(e.Fragment,{})]}),e.jsxs(n.Box,{sx:{display:"flex",flex:1,flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[e.jsxs(n.Box,{sx:{width:"100%"},children:["ltr"===o.appDirection?`${t?.documentActionEnName}`:`${t?.documentActionArName}`,t?.actionComment?" - "+t.actionComment:""]}),e.jsx(n.Box,{sx:{width:"100%"},children:"ltr"===o.appDirection?`${t?.employeeEnName}`:`${t?.employeeArName}`})]})]})}))})]})},No=t=>{const{t:i}=I.useTranslation(),o=De(),{ConfirmationWindow:a,setOpen:r}=ge({body:i(t?.confirmationMessage||"ACTION_CONFIRMATION"),title:i("CONFIRMATION"),onConfirmationCallBk:async()=>{await(t?.actionFn(t.recordsToProcessActionOn,t.recordIdsToProcessActionOn)),t?.reloadData&&t.reloadData()}});let d=!0;if(t.authority&&(d=o.isUserAuthorized(t.authority)),d)return e.jsxs(e.Fragment,{children:[e.jsx(a,{}),e.jsxs(n.Button,{onClick:async()=>{if(t?.recordsToProcessActionOn&&t?.recordsToProcessActionOn.length>0){if(t?.preActionValidation)for(const e of t.recordsToProcessActionOn)if(!t.preActionValidation(e))return;!0===t?.isConfirmationRequired?r(!0):(await t.actionFn(t.recordsToProcessActionOn,t.recordIdsToProcessActionOn),t?.reloadData&&t.reloadData())}else A.toast.error(i("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"))},variant:t?.label?"outlined":t?.formActionProps?.actionButtonVariant?t.formActionProps.actionButtonVariant:"text",size:"small",color:t?.formActionProps?.actionButtonColor||"primary",children:[t?.icon?e.jsx(m.FontAwesomeIcon,{style:{marginRight:5,marginLeft:5},icon:t.icon}):e.jsx(e.Fragment,{}),t?.label?i(t.label):e.jsx(e.Fragment,{})]})]})},yo=n.styled(B.QuickFilter)({display:"grid",alignItems:"center"}),ho=n.styled(B.ToolbarButton)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",width:"min-content",height:"min-content",zIndex:1,opacity:t.expanded?0:1,pointerEvents:t.expanded?"none":"auto",transition:e.transitions.create(["opacity"])})),Ro=n.styled(n.TextField)(({theme:e,ownerState:t})=>({gridArea:"1 / 1",overflowX:"clip",width:t.expanded?260:"var(--trigger-width)",opacity:t.expanded?1:0,transition:e.transitions.create(["width","opacity"])})),Lo=t=>{const{t:i}=I.useTranslation(),o=De(),a=!t?.templateProps?.editAction?.authority||o.isUserAuthorized(t.templateProps.editAction.authority),r=at(t?.templateProps?.rowSelectionModel||{ids:new Set,type:"include"},t?.templateProps?.data||[],t?.templateProps?.keyColumnName||"id");return e.jsxs(B.Toolbar,{children:[a&&"none"!=t?.templateProps?.editMode?.editMode?e.jsxs(n.Button,{onClick:t?.handleCreateNewRecord,children:[e.jsx(m.FontAwesomeIcon,{icon:"add",style:{marginRight:5,marginLeft:5}}),i("ADD_BTN_LABEL")]}):e.jsx(e.Fragment,{}),t?.templateProps?.rowActions?t.templateProps.rowActions.map((e,i)=>!0===e?.gridActionProps?.multiRecord?l.createElement(No,{...e,key:i,reloadData:async()=>{t.templateProps.apiActions.reloadData(t?.templateProps?.gridLoadParametersValues)},recordIdsToProcessActionOn:r.selectedRecordIds,recordsToProcessActionOn:r.selectedRecords}):null):e.jsx(e.Fragment,{}),e.jsx(n.Box,{sx:{flex:1,mx:.5},children:t?.templateProps?.tBar}),e.jsx(n.Tooltip,{title:"Columns",children:e.jsx(B.ColumnsPanelTrigger,{render:e.jsx(B.ToolbarButton,{}),children:e.jsx(B.GridViewColumnIcon,{fontSize:"small"})})}),e.jsx(n.Tooltip,{title:"Filters",children:e.jsx(B.FilterPanelTrigger,{render:(t,i)=>e.jsx(B.ToolbarButton,{...t,color:"default",children:e.jsx(n.Badge,{badgeContent:i.filterCount,color:"primary",variant:"dot",children:e.jsx(B.GridFilterListIcon,{fontSize:"small"})})})})}),t?.templateProps?.gridStateKey?e.jsx(n.Tooltip,{title:i("RESET_GRID_STATE"),children:e.jsx(n.IconButton,{onClick:t?.clearGridState,children:e.jsx(m.FontAwesomeIcon,{icon:"eraser"})})}):e.jsx(e.Fragment,{}),e.jsx(n.Divider,{orientation:"vertical",variant:"middle",flexItem:!0,sx:{mx:.5}}),e.jsx(n.Tooltip,{title:i("EXPORT_EXECL_LABEL"),children:e.jsx(B.ExportExcel,{render:e.jsx(n.MenuItem,{}),children:e.jsx(m.FontAwesomeIcon,{icon:"file-excel",color:"green"})})}),e.jsxs(yo,{children:[e.jsx(B.QuickFilterTrigger,{render:(t,o)=>e.jsx(n.Tooltip,{title:i("SEARCH_BTN_LABEL"),enterDelay:0,children:e.jsx(ho,{...t,ownerState:{expanded:o.expanded},color:"default","aria-disabled":o.expanded,children:e.jsx(m.FontAwesomeIcon,{icon:"search"})})})}),e.jsx(B.QuickFilterControl,{render:({ref:t,...o},a)=>e.jsx(Ro,{...o,ownerState:{expanded:a.expanded},inputRef:t,"aria-label":"Search",placeholder:`${i("SEARCH_BTN_LABEL")}...`,size:"small",slotProps:{input:{startAdornment:e.jsx(n.InputAdornment,{position:"start",children:e.jsx(m.FontAwesomeIcon,{icon:"search"})}),endAdornment:a.value?e.jsx(n.InputAdornment,{position:"end",children:e.jsx(B.QuickFilterClear,{edge:"end",size:"small","aria-label":"Clear search",children:e.jsx(m.FontAwesomeIcon,{icon:"xmark"})})}):null,...o.slotProps?.input},...o.slotProps}})})]}),e.jsx(n.IconButton,{onClick:()=>{t.templateProps.apiActions.reloadData(t?.templateProps?.gridLoadParametersValues)},children:e.jsx(m.FontAwesomeIcon,{icon:"refresh"})})]})},Co=t=>{const{t:i}=I.useTranslation(),o=De(),{ConfirmationWindow:a,setOpen:r}=ge({body:i(t?.confirmationMessage||"ACTION_CONFIRMATION"),title:i("CONFIRMATION"),onConfirmationCallBk:async()=>{await(t?.actionFn(t.record)),t?.reloadData&&t.reloadData()}});let d=!0;t.authority&&(d=o.isUserAuthorized(t.authority));let l={};t?.getActionIconStyleForRecord&&(l=t.getActionIconStyleForRecord(t.record));let s=!0;t?.isActionVisibleForRecord&&(s=t?.isActionVisibleForRecord(t.record));let p=!1;if(t?.isActionDisabledForRecord&&(p=t.isActionDisabledForRecord(t.record)),d&&s)return e.jsxs(e.Fragment,{children:[e.jsx(a,{}),e.jsx(B.GridActionsCellItem,{disabled:p,icon:e.jsx(n.Tooltip,{title:t?.label?i(t.label):"",children:e.jsx(m.FontAwesomeIcon,{icon:t.icon,style:{...l,color:p?"gray":null!=l?.color?l.color:void 0}})}),showInMenu:t?.gridActionProps?.showInMenu||!1,label:"",className:"textPrimary",color:"inherit",onClick:async()=>{if(!p){if(t?.preActionValidation&&!t.preActionValidation(t.record))return;!0===t?.isConfirmationRequired?r(!0):(await t.actionFn(t.record),!0===t?.gridActionProps?.reloadGridAfterAction&&t?.reloadData&&t.reloadData())}}})]})};let go=-1;const Do=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t):{}}catch(e){return console.error("Failed to load grid state",e),{}}},Po=(e,t)=>{const i=Do(e);localStorage.setItem(e,JSON.stringify({...i,...t}))},Mo=["__check__","actions"],xo=i=>{const{t:o}=I.useTranslation(),a=t.useSelector(e=>e.AppLayout),[r,d]=l.useState({}),[s,p]=l.useState(!0),{getLookupOptions:c}=(()=>{const{handleGetRequest:e}=Ce(),i=t.useSelector(e=>e.AppLayout),o=async t=>{let i=[];return await e({endPointURI:"api/v1/public/system/lookup",showMask:!0,parameters:{lookupType:t},successCallBkFn:e=>{i=e.data}}),i};return{generateLookupGridColumn:async e=>{let t=await o(e.lookupType);return{...e,options:t,displayField:"ltr"===i.appDirection?"lookupEnDisplay":"lookupArDisplay",valueField:"lookupValue"}},getLookupOptions:o}})(),{Window:u,setWindowState:T}=Pe({windowTitle:o(i.gridTitle)+" Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"50%",onCloseCallBack:()=>{i?.apiActions?.reloadData(i.gridLoadParametersValues)}}),{Window:_,setWindowState:f}=Pe({windowTitle:o(i.gridTitle)+" Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:"80%",onCloseCallBack:()=>{i?.apiActions?.reloadData(i.gridLoadParametersValues)}}),[E,N]=l.useState([]),h=tt(i.formElements),R=[],L=l.useMemo(()=>i?.gridStateKey?Do(i.gridStateKey):{},[]);for(const e of h)!0===e?.gridProps?.hidden&&R.push(e.fieldName);let C={};if(L?.columnVisibilityModel){C=L.columnVisibilityModel;const e=Object.keys(C);for(const t of R)e.includes(t)||(C[t]=!1)}else for(const e of R)C[e]=!1;const g=t.useSelector(e=>e.AppLayout.appDirection),[D,P]=l.useState(C),[M,x]=l.useState(L.columnOrder||[]),[b,S]=l.useState(L.columnWidths||{}),[U,w]=l.useState(L.columnGroupingModel||[]);let v=L?.pinnedColumns?.left||[];v=v.filter(e=>!Mo.includes(e));let F=L?.pinnedColumns?.right||[]||[];F=F.filter(e=>!Mo.includes(e));const[k,j]=l.useState({left:[..."ltr"===g?Mo:[],...v],right:[..."rtl"===g?Mo:[],...F]}),G=De(),W=O.useNavigate(),[Y,V]=l.useState(null),[q,K]=l.useState(null),[z,H]=l.useState({}),Q=async()=>{let e=it(h,"row"===i?.editMode?.editMode||!1,o);for(let t of e)t?.lookupType&&(t.displayField="ltr"===a.appDirection?"lookupEnDisplay":"lookupArDisplay",t.options=await c(t.lookupType),t.valueField="lookupValue");N(e)},[Z,$]=l.useState({ids:new Set,type:"include"});let X="id";i?.keyColumnName&&(X=i?.keyColumnName);const J=i.setData,ee=y.z.object(ot(h));let te=!0;i?.editAction?.authority&&(te=G.isUserAuthorized(i.editAction.authority));let ie=!0;i?.deleteAction?.authority&&(ie=G.isUserAuthorized(i.deleteAction.authority));const{ConfirmationWindow:oe,setOpen:ae}=ge({title:"Confirmation",body:"Are you sure you want to delete this record ?",onConfirmationCallBk:async()=>{let e=!0;Y&&!0===Y?.isNew||(e=await i.apiActions.deleteRecordById(Y[X])),e&&(i?.deleteAction?.postActionCallBack&&await i.deleteAction.postActionCallBack(Y),J(e=>e.filter(e=>e[X]!=Y[X])))}});let re,ne,de,le,se,pe;"modal"===i?.editMode?.editMode&&(re=i?.editMode?.specs?.modalHeight||"fit-content",ne=i?.editMode?.specs?.modalWidth||"300",de=i?.editMode?.specs?.modalMinHeight,le=i?.editMode?.specs?.modalMinWidth,se=i?.editMode?.specs?.modalIcon||"window",pe=i?.editMode?.specs?.modalTitle||"Record Form");const{Window:ce,setWindowState:ue}=Pe({height:re,minHeight:de,minWidth:le,onCloseCallBack:()=>{i.apiActions.reloadData(i?.gridLoadParametersValues)},width:ne,windowIcon:se,windowTitle:pe}),me={type:"actions",field:"actions",headerName:"",headerAlign:"center",width:(i?.rowActions?30*i.rowActions.length:0)+(i?.editAction&&i?.editAction?.isEnabled?30:0)+(i?.deleteAction&&i?.deleteAction?.isEnabled?30:0)+(i?.attachment?30:0)+(i?.workFlowDocumentCode?30:0),getActions:t=>{const a=t.row,r=[];if("none"!=i?.editMode?.editMode&&(void 0===i?.disableDefaultAction||!i.disableDefaultAction)){const t=z[a[X]]?.mode===B.GridRowModes.Edit;if("row"===i.editMode.editMode&&t)te&&(r.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(m.FontAwesomeIcon,{icon:"save"}),label:o("SAVE_BTN_LABEL"),onClick:()=>{(e=>{const t=e[X];H({...z,[t]:{mode:B.GridRowModes.View}})})(a)}})),r.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(m.FontAwesomeIcon,{icon:"cancel"}),label:o("CANCEL_BTN_LABEL"),onClick:()=>{(e=>{const t=e[X];t&&so(t)&&t<0?(H({...z,[t]:{mode:B.GridRowModes.View,ignoreModifications:!0}}),J(e=>{const i=e.filter(e=>e[X]!=t);return i})):H({...z,[t]:{mode:B.GridRowModes.View,ignoreModifications:!0}})})(a)},color:"inherit"})));else{if(i?.editAction&&!0===i?.editAction?.isEnabled){let t=!0;i?.editAction?.isActionVisibleForRecord&&(t=i?.editAction?.isActionVisibleForRecord(a));let d=!1;i?.editAction?.isActionDisabledForRecord&&(d=i?.editAction?.isActionDisabledForRecord(a)),te&&t&&r.push(e.jsx(B.GridActionsCellItem,{disabled:d,icon:e.jsx(n.Tooltip,{title:o("EDIT_BTN_LABEL"),children:e.jsx(m.FontAwesomeIcon,{icon:"edit",style:{color:d?"gray":void 0}})}),showInMenu:i?.editAction?.gridActionProps?.showInMenu||!1,label:o("EDIT_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{te&&!d&&(async e=>{if(e)if(K(e),"form"===i.editMode.editMode)W(i.editMode.specs.formRoute+"/"+e[X]);else if("modal"===i.editMode.editMode)ue(!0);else if("row"===i?.editMode?.editMode){const t=e[X];H({...z,[t]:{mode:B.GridRowModes.Edit}})}})(a)}}))}if(i?.deleteAction&&!0===i?.deleteAction?.isEnabled){let t=!0;i?.deleteAction?.isActionVisibleForRecord&&(t=i?.deleteAction?.isActionVisibleForRecord(a));let d=!1;i?.deleteAction?.isActionDisabledForRecord&&(d=i?.deleteAction?.isActionDisabledForRecord(a)),ie&&t&&r.push(e.jsx(B.GridActionsCellItem,{disabled:d,icon:e.jsx(n.Tooltip,{title:o("DELETE_BTN_LABEL"),children:e.jsx(m.FontAwesomeIcon,{icon:"trash",style:{color:d?"gray":void 0}})}),showInMenu:i?.deleteAction?.gridActionProps?.showInMenu||!1,label:o("DELETE_BTN_LABEL"),className:"textPrimary",color:"inherit",onClick:()=>{if(ie&&!d){if(i?.deleteAction?.preActionValidation&&!i.deleteAction.preActionValidation(a))return;V(a),ae(!0)}}}))}}}if(a[i?.keyColumnName||"id"]&&a[i?.keyColumnName||"id"]>0&&i?.attachment&&r?.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(n.Tooltip,{title:"Attachments",children:e.jsx(m.FontAwesomeIcon,{icon:"paperclip"})}),label:"Attachments",className:"textPrimary",color:"inherit",onClick:()=>{d(a),p(!i?.attachment?.enableAttachFn||i.attachment.enableAttachFn(a)),T(!0)}})),a[i?.keyColumnName||"id"]&&a[i?.keyColumnName||"id"]>0&&i?.workFlowDocumentCode&&r?.push(e.jsx(B.GridActionsCellItem,{icon:e.jsx(n.Tooltip,{title:"Approvals",children:e.jsx(m.FontAwesomeIcon,{icon:"stamp"})}),label:"Approvals",className:"textPrimary",color:"inherit",onClick:()=>{d(a),f(!0)}})),a[i?.keyColumnName||"id"]&&a[i?.keyColumnName||"id"]>0&&i?.rowActions)for(const t of i.rowActions)t?.gridActionProps?.multiRecord&&!0===t?.gridActionProps?.multiRecord||r.push(e.jsx(Co,{...t,record:a,reloadData:async()=>{i.apiActions.reloadData(i?.gridLoadParametersValues)}}));return r}};let Te=[];(void 0===i?.disableDefaultAction||!i.disableDefaultAction||i?.rowActions&&i?.rowActions.length>0)&&Te.push(me),Te=[...Te,...E];l.useEffect(()=>{void 0!==i?.autoLoad&&!0!==i.autoLoad||i.apiActions.reloadData(i?.gridLoadParametersValues),Q()},[]),l.useEffect(()=>{i.apiActions.reloadData(i?.gridLoadParametersValues)},[G.UserInfo?.currentOrganization]),l.useEffect(()=>{Q()},[g,i.formElements]);const Ae=l.useMemo(()=>{const e=Te.map(e=>({...e,width:b[e.field]||e.width}));if(M.length){const t=new Map(e.map(e=>[e.field,e]));return M.map(e=>t.get(e)).filter(Boolean)}return e},[M,b,Te]);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{}),"modal"===i?.editMode?.editMode?e.jsx(ce,{children:i?.editMode?.specs?.formComponent?e.jsx(i.editMode.specs.formComponent,{recordIdToEdit:q?q[X]:void 0,formCloseCallBk:()=>{ue(!1),i.apiActions.reloadData(i?.gridLoadParametersValues)}}):e.jsx(vo,{keyColumnName:i.keyColumnName,attachment:i.attachment,formLoadCallBk:i.formLoadCallBk,recordIdToEdit:q?q[X]:void 0,formCloseCallBk:()=>{ue(!1),i.apiActions.reloadData(i?.gridLoadParametersValues)},elements:i.formElements,apiActions:i.apiActions,editAuthorityKey:i?.editAction?.authority,formSavedSuccessfullyCallBk:i?.editAction?.postActionCallBack,preSaveValidation:i?.editAction?.preActionValidation,actions:i?.rowActions})}):e.jsx(e.Fragment,{}),void 0!==i?.hideInfoBar||i?.hideInfoBar?e.jsx(e.Fragment,{}):e.jsxs(n.Box,{sx:{display:"flex"},children:[void 0!==i?.hideBackButton||i?.hideBackButton?e.jsx(e.Fragment,{}):e.jsx(n.IconButton,{onClick:()=>{W(-1,{replace:!0})},children:e.jsx(m.FontAwesomeIcon,{icon:"ltr"===g?"arrow-left":"arrow-right"})}),e.jsxs(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:[i?.girdIcon?e.jsx(m.FontAwesomeIcon,{icon:i.girdIcon,style:{marginRight:5,marginLeft:5}}):e.jsx(e.Fragment,{}),e.jsx(n.Typography,{variant:"h5",children:i?.gridTitle?co(o(i?.gridTitle)):""})]})]}),i?.gridLoadParameters&&i?.gridLoadParameters.length>0&&i?.gridLoadParametersValues&&i?.setGridLoadParametersValues?e.jsxs(n.Accordion,{defaultExpanded:!0,sx:{width:"100%"},children:[e.jsx(n.AccordionSummary,{expandIcon:e.jsx(B.GridExpandMoreIcon,{}),children:e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),e.jsx(n.Typography,{component:"span",children:"Filters"})]})}),e.jsx(n.AccordionDetails,{children:e.jsx(n.Box,{children:e.jsx(vo,{saveButtonSpecs:{label:o("SEARCH_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success"},cancelButtonSpecs:{label:o("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{null!=e?i.setGridLoadParametersValues(e):i.setGridLoadParametersValues({}),i.apiActions.reloadData(e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:i.gridLoadParameters})})})]}):e.jsx(e.Fragment,{}),i?.attachment?e.jsx(u,{children:e.jsx(Eo,{attachmentCode:i.attachment.attachmentCode,refKey:r[i?.keyColumnName||"id"],enableAttachment:s})}):e.jsx(e.Fragment,{}),i?.workFlowDocumentCode?e.jsx(_,{children:e.jsx(wo,{workFlowDocumentCode:i.workFlowDocumentCode,refDocumentId:r[i?.keyColumnName||"id"],postActionCallBk:()=>{f(!1),i.apiActions.reloadData(i.gridLoadParametersValues)},cancelActionCallBk:()=>{f(!1),i.apiActions.reloadData(i.gridLoadParametersValues)}})}):e.jsx(e.Fragment,{}),e.jsx(B.DataGridPremium,{...i?.muiProps,slots:{toolbar:Lo},slotProps:{toolbar:{templateProps:{...i,rowSelectionModel:Z,data:i?.data},handleCreateNewRecord:()=>{if("form"===i?.editMode?.editMode)W(i.editMode.specs.formRoute);else if("modal"===i?.editMode?.editMode)K(null),ue(!0);else if("row"===i?.editMode?.editMode){go-=1;const e={};e[X]=go,e.isNew=!0;for(const t of E)"actions"!=t?.type&&t?.field!=X&&t?.field&&(e[t.field]=null);J(t=>[e,...t]),H(e=>({...e,[go]:{mode:B.GridRowModes.Edit}}))}},clearGridState:()=>{i?.gridStateKey&&localStorage.removeItem(i.gridStateKey),P({}),x([]),S({}),w([]),j({left:[..."ltr"===g?Mo:[]],right:[..."rtl"===g?Mo:[]]})}}},getRowId:e=>e[X],showToolbar:!0,rows:i?.data,columns:Ae,checkboxSelection:!0,editMode:"row",onRowEditStop:(e,t)=>{"rowFocusOut"===e.reason&&(t.defaultMuiPrevented=!0)},rowModesModel:"row"==i.editMode.editMode?z:void 0,onRowModesModelChange:"row"==i.editMode.editMode?e=>{H(e)}:void 0,rowGroupingColumnMode:"multiple",processRowUpdate:async t=>{if("row"===i.editMode.editMode){let o=null;const a=(e=>{try{ee.parse(e)}catch(e){console.log("validateRecord err",e);let t=null;return t=e instanceof y.z.ZodError?e.errors.map(e=>"Error in field ("+e.path+") : "+e.message).join(","):"invalid record data",t}})(t);if(a){const t=a.split(",");throw A.toast.error(e.jsx("div",{style:{},children:t.map(t=>e.jsxs(e.Fragment,{children:[e.jsx("div",{children:t}),e.jsx(n.Divider,{})]}))})),new Error(a)}if(i?.editAction?.preActionValidation&&!i.editAction.preActionValidation(t))throw new Error("error on the configured presave validation");const r={...t};if(t[X]&&so(t[X])&&Number(t[X])<0&&(r[X]=null),o=await i.apiActions.saveRecord(r),null==o)throw new Error("Failed to process your request, contact your administrator");return i?.editAction?.postActionCallBack&&await i.editAction.postActionCallBack(t),!0===t?.isNew&&J(e=>{const i=e.filter(e=>e[X]!==t[X]);return[o,...i]}),!0===i?.editMode?.reloadAfterSave&&i?.apiActions?.reloadData&&i?.apiActions?.reloadData(i?.gridLoadParametersValues),o}},rowSelectionModel:Z,onRowSelectionModelChange:e=>{$(e)},columnVisibilityModel:D,onColumnVisibilityModelChange:e=>{P(e),i?.gridStateKey&&Po(i.gridStateKey,{columnVisibilityModel:e})},onColumnOrderChange:e=>{const{column:t,targetIndex:o}=e;x(e=>{const a=e.length?[...e]:Te.map(e=>e.field),r=a.indexOf(t.field);return-1===r||(a.splice(r,1),a.splice(o,0,t.field),i?.gridStateKey&&Po(i.gridStateKey,{columnOrder:a})),a})},onColumnWidthChange:e=>{const t={...b,[e.colDef.field]:e.width};S(t),i?.gridStateKey&&Po(i.gridStateKey,{columnWidths:t})},rowGroupingModel:U,onRowGroupingModelChange:e=>{(e=>{w(e),i?.gridStateKey&&Po(i.gridStateKey,{columnGroupingModel:e})})(e)},sx:{width:"100%"}})]})},bo=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},So=t=>{const[i,o]=l.useState([]);return l.useEffect(()=>{const e=t.reportData.map((e,t)=>({...e,report_record_data_key:t}));o(e)},[t.reportData]),e.jsx(xo,{data:i,disableDefaultAction:!0,setData:t.setReportData,formElements:bo(t.reportData),gridLoadParameters:t.gridLoadParameters,gridLoadParametersValues:t.gridLoadParametersValues,setGridLoadParametersValues:t.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()=>{t.reloadReport()},saveRecord:async()=>{}}})},Uo=t=>{const[i,o]=l.useState(null),[a,r]=l.useState(null),[d,s]=l.useState([]),[p,c]=l.useState("WAITING_REPORT_CODE"),{handleGetRequest:u,handlePostRequest:T,HandleDownloadHTTPPostPDF:A}=Ce(),[_,f]=l.useState(null),[E,O]=l.useState({...t?.reportParametersValues}),[N,y]=l.useState([]),{t:h}=I.useTranslation(),R=e=>{const t=[];for(const i of e){const e={type:"field",mode:"props",props:{fieldLabel:i?.parameterLabel,fieldName:i?.parameterCode,fieldType:i?.parameterType,hidden:i?.hidden,formProps:{fieldSize:{lg:4,md:6,sm:12}},required:i?.mandatory,defaultValue:E[i?.parameterCode]||i?.defaultValue}};t.push(e)}return t},L=async(e,i)=>{c("WAITING_RESULT"),"Excel"===e?.reportType?await T({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:t.reportCode,parameters:i,resultMode:t.resultMode,jasperOutPutFileType:t.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT"),s(e.data)}}):e?.reportType&&await A({endPointURI:"api/v1/public/report/run",showMask:!0,data:{reportCode:t.reportCode,parameters:i,resultMode:t.resultMode,jasperOutPutFileType:t.jasperOutPutFileType},successCallBkFn:e=>{c("SHOWING_RESULT");const t=e.headers["content-disposition"];let i="downloaded_file";if(t&&-1!==t.indexOf("filename=")){const e=t.match(/filename="?([^"]+)"?/);e&&e[1]&&(i=e[1])}if(i.includes("pdf")){const t=new Blob([e.data],{type:"application/pdf"}),i=URL.createObjectURL(t);o(i)}else{const t=new Blob([e.data],{type:e.headers["content-type"]}),o=window.URL.createObjectURL(t),a=document.createElement("a");a.href=o,a.download=i,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(o)}},failureCallBkFn:e=>{r("Failed To run report ... contact your administrator"),c("ERROR")}})};return l.useEffect(()=>{t?.reportCode&&(async()=>{c("LOADING_METADATA"),await u({endPointURI:"api/v1/public/report/metadata",showMask:!0,parameters:{reportCode:t.reportCode},successCallBkFn:e=>{f(e.data),y(R(e.data.reportParameters)),!0===t?.byPassParameterEntry||0==e.data.reportParameters.length?(L(e.data,E),c("WAITING_RESULT")):c("WAITING_PARAMETER_INPUT")},failureCallBkFn:e=>{r("Failed loading report metadata ... contact your administrator"),c("ERROR")}})})()},[t.reportCode,t.byPassParameterEntry,t.reportParametersValues,t.jasperOutPutFileType,t.resultMode]),e.jsxs(e.Fragment,{children:[e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:[e.jsxs(n.Box,{sx:{flex:1,textAlign:"center",marginBottom:1},children:[e.jsx(m.FontAwesomeIcon,{icon:"Excel"===_?.reportType?"file-excel":"file-pdf",color:"Excel"===_?.reportType?"darkgreen":"darkred",style:{marginRight:10,marginLeft:10}}),_?.reportName]}),"Excel"!=_?.reportType&&"SHOWING_RESULT"===p?e.jsxs(e.Fragment,{children:[!0===t?.byPassParameterEntry?e.jsx(e.Fragment,{}):N.length>0?e.jsx(n.IconButton,{onClick:()=>{y(R(_.reportParameters)),c("WAITING_PARAMETER_INPUT")},children:e.jsx(m.FontAwesomeIcon,{icon:"filter"})}):e.jsx(e.Fragment,{}),e.jsx(n.IconButton,{children:e.jsx(m.FontAwesomeIcon,{icon:"refresh",onClick:()=>{L(_,E)}})})]}):e.jsx(e.Fragment,{})]}),e.jsx(n.Box,{sx:{flexGrow:1,width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start"},children:"WAITING_PARAMETER_INPUT"===p&&"Excel"!=_?.reportType?e.jsxs(n.Accordion,{defaultExpanded:!0,sx:{width:"100%"},expanded:!0,children:[e.jsx(n.AccordionSummary,{children:e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(m.FontAwesomeIcon,{style:{marginLeft:5,marginRight:5},icon:"search"}),e.jsx(n.Typography,{component:"span",children:"Filters"})]})}),e.jsx(n.AccordionDetails,{children:e.jsx(n.Box,{children:e.jsx(vo,{saveButtonSpecs:{label:h("SHOW_REPORT_BTN_LABEL"),icon:"search",actionButtonVariant:"outlined",actionButtonColor:"success",hidden:!0},cancelButtonSpecs:{label:h("RESET_BTN_LABEL"),icon:"eraser",actionButtonVariant:"outlined",actionButtonColor:"error"},apiActions:{deleteRecordById:async()=>!0,saveRecord:async e=>{O(null!=e?e:{}),L(_,e)},reloadData:async()=>{},loadRecordById:async()=>{}},elements:N})})})]}):"SHOWING_RESULT"===p||("WAITING_PARAMETER_INPUT"===p||"WAITING_RESULT"===p)&&"Excel"===_?.reportType?"Excel"===_?.reportType?e.jsx(So,{reportData:d,setReportData:s,reloadReport:async()=>{L(_,E)},gridLoadParameters:N,gridLoadParametersValues:E,setGridLoadParametersValues:O}):e.jsx("iframe",{src:i,width:"100%",height:"100%",title:"PDF Preview",style:{border:"1px solid #ccc",marginTop:"20px"}}):"ERROR"===p?e.jsxs(n.Box,{sx:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[e.jsx(m.FontAwesomeIcon,{icon:"circle-exclamation",color:"darkred",style:{marginRight:10,marginLeft:10}}),a]}):e.jsx(e.Fragment,{})})]})},wo=i=>{const o=O.useNavigate(),a=t.useSelector(e=>e.AppLayout),{isUserAuthorized:r,UserInfo:d}=De(),{handleGetRequest:s,handlePostRequest:p}=Ce(),[c,u]=l.useState(null),[T,_]=l.useState([]),{t:f}=I.useTranslation(),[E,N]=l.useState(null),[y,h]=l.useState({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActionTakers:null,nextActions:[]}),{Window:R,setWindowState:L}=Pe({windowTitle:"ltr"===a.appDirection?y?.workflowDocument&&y?.referencedDocument?`${y?.workflowDocument?.documentEnName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`:"Document":y?.workflowDocument&&y?.referencedDocument?`${y?.workflowDocument?.documentArName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`:"وثيقة",windowIcon:"eye",width:"80%"}),C=async()=>{await s({endPointURI:"api/v1/public/workflow/doc/info",showMask:!0,parameters:{workflowDocumentCode:i.workFlowDocumentCode,refDocumentId:i.refDocumentId},successCallBkFn:e=>{h(e.data)},failureCallBkFn:()=>{h({referencedDocument:null,workflowDocumentReport:null,workflowDocument:null,workflowDocumentStatus:null,actionsHistory:[],nextActions:[],nextActionTakers:null})}})},g=async()=>{await p({endPointURI:"api/v1/public/workflow/doc/action",showMask:!0,data:{workflowDocumentId:y?.workflowDocument?.id,refDocumentId:i.refDocumentId,actionId:c.id,refDocumentStatus:y?.workflowDocumentStatus?.documentStatusCode,actionComment:E},successCallBkFn:async e=>{c?.post_action_endpoint?await p({endPointURI:c.post_action_endpoint,showMask:!0,loadingMessage:"Processing post action process ... please wait",parameters:{refDocumentId:i.refDocumentId,actionId:c.id},successCallBkFn:()=>{C(),i?.postActionCallBk&&i.postActionCallBk()}}):C()}})};return l.useEffect(()=>{i.refDocumentId&&i.workFlowDocumentCode&&C()},[i.refDocumentId,i.workFlowDocumentCode]),l.useEffect(()=>{_(y?.nextActions&&y?.nextActions?.length>0?y.nextActions.filter(e=>{if(!y?.workflowDocumentStatus?.nextActionTakersAuthority&&!y?.nextActionTakers)return!0;if(y?.workflowDocumentStatus?.nextActionTakersAuthority&&r(y.workflowDocumentStatus.nextActionTakersAuthority))return!0;if(y?.nextActionTakers)for(const e of y.nextActionTakers)if(d?.username===e?.username||d?.username===e?.USERNAME)return!0;return!1}):[])},[y.nextActions,y.nextActionTakers]),e.jsxs(e.Fragment,{children:[y?.workflowDocumentReport?.id?e.jsx(R,{children:e.jsx(Uo,{reportCode:y?.workflowDocumentReport?.reportCode,resultMode:"App",byPassParameterEntry:!0,reportParametersValues:{doc_id:i.refDocumentId+""}})}):e.jsx(e.Fragment,{}),y?.workflowDocument?e.jsxs(n.Box,{sx:{width:"100%",textAlign:"center",fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(n.IconButton,{onClick:()=>{o(-1,{replace:!0})},children:e.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),e.jsx(n.Box,{sx:{flex:1}}),e.jsx(m.FontAwesomeIcon,{icon:"file",style:{marginRight:10,marginLeft:10}}),"ltr"===a.appDirection?`${y?.workflowDocument?.documentEnName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`:`${y?.workflowDocument?.documentArName} # ${y?.referencedDocument[y?.workflowDocument?.documentNumberField]}`,y?.workflowDocumentStatus?"ltr"===a.appDirection?` ( ${y?.workflowDocumentStatus?.documentStatusEnName} )`:` ( ${y?.workflowDocumentStatus?.documentStatusArName} )`:"",e.jsx(n.Box,{sx:{flex:1}}),y?.workflowDocumentReport?.id?e.jsx(n.Button,{onClick:()=>{L(!0)},variant:"outlined",startIcon:e.jsx(m.FontAwesomeIcon,{icon:"eye"}),children:f("VIEW_LABEL")}):e.jsx(e.Fragment,{})]}):e.jsx(e.Fragment,{}),e.jsxs(n.Box,{sx:{flex:1,width:"100%",overflow:"hidden",display:"flex"},children:[T?.length>0?e.jsxs(n.Paper,{sx:{padding:2,display:"flex",flex:1,margin:1,flexDirection:"column",alignItems:"center",justifyContent:"flex-start",overflow:"hidden"},children:[e.jsx(je,{sx:{marginBottom:2,width:400},label:f("WE_AVAILABLE_ACTIONS_LABEL"),displayField:"ltr"===a.appDirection?"document_action_en_name":"document_action_ar_name",valueField:"id",value:c?.id,options:T,onChangeCallBack:(e,t)=>{u(t)}}),e.jsx(we,{sx:{width:400},rows:3,value:E,onChange:e=>{N(e.target.value)},multiline:!0,label:f("WF_COMMENT_LABEL")}),e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(n.Button,{color:"success",variant:"contained",sx:{width:200,m:1},onClick:async()=>{null!=c&&null!=c?.id?!0!==c.require_comment&&1!==c.require_comment&&"true"!==c.require_comment||null!==E&&""!==E?c?.pre_action_endpoint?await p({endPointURI:c.pre_action_endpoint,showMask:!0,loadingMessage:"Processing pre action validation ... please wait",parameters:{refDocumentId:i.refDocumentId,actionId:c.id},successCallBkFn:()=>{g()}}):g():A.toast.error("You must enter comment for the action to be processed"):A.toast.error("You must select action to process")},children:f("WF_TAKE_ACTION_BTN_LABEL")}),i?.cancelActionCallBk?e.jsx(n.Button,{variant:"contained",sx:{width:200,m:1},color:"error",onClick:()=>{i?.cancelActionCallBk&&i.cancelActionCallBk()},children:f("WF_CANCEL_BTN_LABEL")}):e.jsx(e.Fragment,{})]}),y?.nextActionTakers&&y.nextActionTakers.length>0?e.jsxs(e.Fragment,{children:[e.jsx(n.Divider,{variant:"fullWidth",flexItem:!0,sx:{marginTop:1,marginBottom:1},children:e.jsxs(n.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[e.jsx(m.FontAwesomeIcon,{icon:"users",style:{marginRight:10,marginLeft:10}})," ",f("WF_WAITING_FOR_LABEL")]})}),e.jsx(n.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",overflow:"auto",padding:1,width:"100%"},children:y.nextActionTakers.map(t=>e.jsxs(n.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",border:"1px dotted black",width:400,marginBottom:2,padding:2},children:[e.jsx(fo,{showAsAvatar:!0,attachmentCode:"EMPLOYEE_PHOTOS",refKey:t?.id||"0",style:{marginRight:2,marginLeft:2,width:60,height:60}}),e.jsxs(n.Box,{sx:{flex:2,display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center"},children:[e.jsx("div",{children:"ltr"===a.appDirection?t?.employee_en_name:t?.employee_ar_name}),e.jsx("div",{children:t?.email?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:"envelope",style:{marginRight:10,marginLeft:10}}),t?.email]}):e.jsx(e.Fragment,{})}),e.jsx("div",{children:t?.mobile_number?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:"mobile",style:{marginRight:10,marginLeft:10}}),t?.mobile_number]}):e.jsx(e.Fragment,{})})]})]}))})]}):e.jsx(e.Fragment,{})]}):e.jsx(e.Fragment,{}),y?.actionsHistory.length>0?e.jsx(Oo,{actionHistory:y.actionsHistory}):e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",flexGrow:1,padding:2,margin:1,alignItems:"center",justifyContent:"center"},children:[e.jsxs(n.Box,{sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:"bold"},children:[e.jsx(m.FontAwesomeIcon,{icon:"history",style:{marginRight:10,marginLeft:10}}),f("WF_ACTION_HISTORY_LABEL")]}),e.jsx(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:"No Action Log available"})]})]})]})},vo=t=>{const{Window:i,setWindowState:o}=Pe({windowTitle:"Attachments",windowIcon:"paperclip",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),{Window:a,setWindowState:r}=Pe({windowTitle:"Approvals",windowIcon:"stamp",width:"fit-content",height:"fit-content",minHeight:500,minWidth:400}),[d,s]=l.useState(!0),{t:p}=I.useTranslation(),c=tt(t.elements),u=[];for(const e of c)e?.hidden&&u.push(e.fieldName);const[T,_]=l.useState(u),f={};for(const e of t.elements)"field"===e?.type&&"props"===e?.mode&&e?.props?.defaultValue&&(f[e.props.fieldName]=e.props.defaultValue);const[y,h]=l.useState([]),R=ce.object(ot(c)),L=E.useForm({resolver:N.zodResolver(R),defaultValues:f}),C=L.watch(),g=O.useParams(),D=t?.formRouteRecordIdParamName,P=async()=>{let e=null;if(t?.recordIdToEdit?e=t.recordIdToEdit:D&&g[D]&&(e=g[D]),e){const i=await t.apiActions.loadRecordById(e);if(i){L.reset({...i}),t?.formLoadCallBk&&t?.formLoadCallBk(M,L,i);for(const e of c)"combobox"===e?.fieldType&&i[e.fieldName]&&(e?.comboboxValueDataType&&"string"===e?.comboboxValueDataType?L.setValue(e.fieldName,i[e.fieldName]+""):L.setValue(e.fieldName,i[e.fieldName]))}}else L.reset({})},M={setFieldValue:(e,t)=>{L.setValue(e,t)},hideField:e=>{_(t=>[...t,e])},showField:e=>{_(t=>t.filter(t=>t!==e))},disableField:e=>{h(t=>[...t,e])},enableField:e=>{h(t=>t.filter(t=>t!==e))}};return l.useEffect(()=>{P()},[t?.recordIdToEdit]),l.useEffect(()=>{s(!t?.attachment||!t?.attachment?.enableAttachFn||t.attachment.enableAttachFn(C))},[C]),e.jsxs(e.Fragment,{children:[t?.attachment?e.jsx(i,{children:e.jsx(Eo,{attachmentCode:t.attachment.attachmentCode,refKey:C[t?.keyColumnName||"id"],enableAttachment:d})}):e.jsx(e.Fragment,{}),t?.workFlowDocumentCode?e.jsx(a,{children:e.jsx(wo,{workFlowDocumentCode:t.workFlowDocumentCode,refDocumentId:C[t?.keyColumnName||"id"],postActionCallBk:()=>{r(!1),P()},cancelActionCallBk:()=>{r(!1)}})}):e.jsx(e.Fragment,{}),e.jsx(lo,{sx:{display:"flex",flex:1,width:"100%",height:"fit-content",flexDirection:"column",alignItems:"center",overflow:"auto"},children:e.jsx(n.Grid2,{sx:{width:"100%"},container:!0,children:t.elements.map((t,i)=>"group"===t.type?e.jsx(_o,{...t.props,formManager:L,formValues:C,formActions:M,hiddenFields:T,disabledFields:y},i):"field"===t.type&&"props"===t.mode?e.jsx(To,{fieldInfo:t.props,formManager:L,formValues:C,formActions:M,hiddenFields:T,disabledFields:y},i):"field"===t.type&&"node"===t.mode?e.jsx(n.Grid2,{size:t?.props?.formProps?.fieldSize||{lg:3,md:6,xs:12},sx:{padding:1,width:"100%"},children:e.jsx(t.node,{formManager:L,formValues:C})},i):void 0)})}),e.jsxs(lo,{sx:{display:"flex",width:"100%",alignItems:"center",justifyContent:"flex-start"},children:[C[t?.keyColumnName||"id"]&&t?.attachment?e.jsx(n.Tooltip,{title:"Attachments",children:e.jsx(n.IconButton,{onClick:()=>{o(!0)},children:e.jsx(m.FontAwesomeIcon,{icon:"paperclip"})})}):null,C[t?.keyColumnName||"id"]&&t?.workFlowDocumentCode?e.jsx(n.Tooltip,{title:"Approvals",children:e.jsx(n.IconButton,{onClick:()=>{r(!0)},children:e.jsx(m.FontAwesomeIcon,{icon:"stamp"})})}):null,t?.actions&&C[t?.keyColumnName||"id"]?t.actions.map(t=>!0===t?.formActionProps?.enabled?e.jsx(Ao,{...t,record:C}):e.jsx(e.Fragment,{})):e.jsx(e.Fragment,{}),e.jsx("div",{style:{flex:1}}),e.jsx(n.Button,{variant:t?.saveButtonSpecs?.actionButtonVariant?t.saveButtonSpecs.actionButtonVariant:"contained",sx:{m:1},startIcon:t?.saveButtonSpecs?.icon?e.jsx(m.FontAwesomeIcon,{icon:t.saveButtonSpecs.icon}):null,color:t?.saveButtonSpecs?.actionButtonColor?t.saveButtonSpecs.actionButtonColor:"primary",onClick:L.handleSubmit(e=>{(async e=>{if((!t?.preSaveValidation||t.preSaveValidation(e))&&e){const i=await t.apiActions.saveRecord(e);i&&(L.reset({...i}),t?.formSavedSuccessfullyCallBk&&t.formSavedSuccessfullyCallBk(i),t?.formCloseCallBk&&t.formCloseCallBk())}})(e)},e=>{A.toast.error("Form Data is not valid, make sure you have all field with valid data"),console.log("form validation error",e)}),children:p(t?.saveButtonSpecs?.label||"SAVE_BTN_LABEL")}),e.jsx(n.Button,{variant:t?.cancelButtonSpecs?.actionButtonVariant?t.cancelButtonSpecs.actionButtonVariant:"contained",startIcon:t?.cancelButtonSpecs?.icon?e.jsx(m.FontAwesomeIcon,{icon:t.cancelButtonSpecs.icon}):null,color:t?.cancelButtonSpecs?.actionButtonColor?t.cancelButtonSpecs.actionButtonColor:"error",sx:{m:1},onClick:()=>{t?.formCloseCallBk&&t.formCloseCallBk(),L.reset(f)},children:p(t?.cancelButtonSpecs?.label||"CANCEL_BTN_LABEL")})]})]})},Fo=()=>{const{workflowDocumentCode:t,refDocumentId:i}=O.useParams();return e.jsx(wo,{workFlowDocumentCode:t,refDocumentId:i})},Bo=t=>e.jsx(k.BarChart,{dataset:t.data,xAxis:[{dataKey:t.valueField,scaleType:"band",label:t.valueLabel}],series:t.labelField?.split(",").map(e=>({dataKey:e,label:e}))}),ko=t=>e.jsxs(n.Paper,{sx:{display:"flex",flexDirection:"column",height:150,padding:1,flexGrow:1,justifyContent:"center",alignItems:"center"},children:[e.jsx(n.Box,{sx:{display:"flex",width:"100%",justifyContent:"space-evenly",alignItems:"center"},children:e.jsx("div",{children:t.record[t.valueField]})}),e.jsx(n.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]})]}),jo=t=>e.jsxs(e.Fragment,{children:[e.jsx(n.Typography,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]}),e.jsx(k.Gauge,{width:200,height:200,value:t.record[t.valueField],valueMax:t.total})]}),Go=t=>e.jsx(k.LineChart,{dataset:t.data,xAxis:[{dataKey:t.valueField,scaleType:"band",label:t.valueLabel}],series:t.labelField?.split(",").map(e=>({dataKey:e,label:e}))});function Wo(t){return e.jsxs(G,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(G,{sx:{width:"100%",mr:1},children:e.jsx(j,{variant:"determinate",...t})}),e.jsx(G,{sx:{minWidth:35},children:e.jsx(F,{variant:"body2",sx:{color:"text.secondary"},children:`${Math.round(t.value)}%`})})]})}const Yo=t=>e.jsxs(G,{sx:{width:"100%"},children:[e.jsx(F,{sx:{fontSize:16,fontWeight:"bold"},children:t.record[t.labelField]}),e.jsx(Wo,{value:t.record[t.valueField]/t.total*100})]}),Vo=t=>{const i=t.data.map((e,i)=>({id:i,value:e[t.valueField],label:e[t.labelField]+""}));return e.jsx(W.PieChart,{series:[{data:i}]})},qo=t=>{const[i,o]=l.useState(!0),[a,r]=l.useState([]),{handleGetRequest:d}=Ce();l.useEffect(()=>{(async()=>{o(!0),await d({endPointURI:"api/v1/dev/query/result",showMask:!1,parameters:{queryId:t.dataQueryId,...t.parameterValues},successCallBkFn:e=>{o(!1),r(e.data)},failureCallBkFn:()=>{o(!1),r(null)}})})()},[t.parameterValues]);let s=0;if(1==a.length&&(s=100),"CircularProgress"===t.widgetType||"LinearProgress"===t.widgetType)for(const e of a)s+=e[t.verticalAxisField];return e.jsxs(e.Fragment,{children:["LineChart"===t.widgetType||"PieChart"===t.widgetType||"ColumnChart"===t.widgetType?e.jsxs(n.Box,{children:[e.jsx(m.FontAwesomeIcon,{style:{marginRight:10,marginLeft:10},icon:t?.icon||"chart-pie"}),t?.title]}):e.jsx(e.Fragment,{}),e.jsx(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",width:"100%"},children:i?e.jsxs(e.Fragment,{children:[e.jsx(m.FontAwesomeIcon,{icon:{prefix:"fas",iconName:"arrows-spin"},style:{marginRight:10,marginLeft:10},spin:!0,size:"2x"}),e.jsx("div",{children:"Loading"})]}):"ColumnChart"===t.widgetType?e.jsx(Bo,{data:a,widgetTitle:t.title,labelField:t.verticalAxisField,valueField:t.horizontalAxisField,valueLabel:t.horizontalAxisLabel,widgetType:"Line"}):"LineChart"===t.widgetType?e.jsx(Go,{data:a,widgetTitle:t.title,labelField:t.verticalAxisField,valueField:t.horizontalAxisField,valueLabel:t.horizontalAxisLabel,widgetType:"Line"}):"PieChart"===t.widgetType?e.jsx(Vo,{data:a,widgetTitle:t.title,labelField:t.horizontalAxisField,valueField:t.verticalAxisField,widgetType:"Line"}):e.jsxs(n.Grid2,{container:!0,sx:{width:"100%",alignItems:"flex-start",justifyContent:"flex-start"},spacing:2,size:{xs:12},children:[e.jsx(n.Grid2,{size:{xs:12},sx:{textAlign:"center"},children:t.title}),a.map((i,o)=>"Card"===t.widgetType?e.jsx(n.Grid2,{size:{md:3,xs:12},children:e.jsx(ko,{widgetTitle:"",record:i,labelField:t.verticalAxisField,valueField:t.horizontalAxisField},o)}):"CircularProgress"===t.widgetType?e.jsx(n.Grid2,{size:{md:3,xs:12},children:e.jsx(jo,{widgetTitle:"",record:i,labelField:t.horizontalAxisField,valueField:t.verticalAxisField,total:s},o)}):"LinearProgress"===t.widgetType?e.jsx(n.Grid2,{size:{md:3,xs:12},children:e.jsx(Yo,{widgetTitle:"",record:i,labelField:t.horizontalAxisField,valueField:t.verticalAxisField,total:s},o)}):void 0)]})})]})},Ko=t=>{const[i,o]=l.useState({dashboardCode:"",dashboardName:"",dashboardTitle:"",dashboardParameters:[],widgets:[]}),[a,r]=l.useState(t?.parameters||{}),d=O.useNavigate(),{handleGetRequest:s,handlePostRequest:p}=Ce();return l.useEffect(()=>{t.dashboardCode&&(async()=>{await s({endPointURI:"api/v1/dev/dashboard/metadata",showMask:!0,parameters:{dashboardCode:t.dashboardCode},successCallBkFn:e=>{o(e.data)},failureCallBkFn:()=>{o(null)}})})()},[t.dashboardCode,t.parameters]),e.jsx(e.Fragment,{children:i?e.jsxs(e.Fragment,{children:[e.jsxs(n.Box,{sx:{fontSize:20,fontWeight:"bold",display:"flex",alignItems:"center",justifyContent:"center"},children:[e.jsx(n.IconButton,{onClick:()=>{d(-1,{replace:!0})},children:e.jsx(m.FontAwesomeIcon,{icon:"arrow-left"})}),e.jsx(n.Box,{sx:{flex:1}}),e.jsx(m.FontAwesomeIcon,{style:{marginLeft:10,marginRight:10},icon:"square-poll-vertical"}),e.jsx(n.Box,{children:i?.dashboardTitle}),e.jsx(n.Box,{sx:{flex:1}})]}),e.jsx(n.Grid2,{container:!0,spacing:1,sx:{flexGrow:1,overflowY:"auto",padding:1},children:i?.widgets.map((t,i)=>e.jsx(n.Grid2,{sx:{alignItems:"center",justifyContent:"center",padding:1,display:"flex",overflow:"auto",flexDirection:"Card"!=t.widgetType?"column":void 0,height:t?.height||300},size:{md:t?.width,sm:12},children:e.jsx(qo,{...t})},i))})]}):e.jsx(n.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,fontWeight:"bold"},children:"No Dashboard Found"})})},zo=()=>{const{dashboardCode:t}=O.useParams();return e.jsx(Ko,{dashboardCode:t})},Ho=i=>{const{UserSession:o}=De(),a=t.useSelector(e=>e.AppLayout),r=t.useDispatch(),{handlePostRequest:d}=Ce(),[s,p]=l.useState(o.value.currentOrganization.id);return e.jsxs(n.Box,{sx:{display:"flex",flexDirection:"column",width:"100%",alignItems:"center",justifyContent:"center",padding:1},children:[e.jsx(je,{sx:{width:"100%"},displayField:"ltr"===a.appDirection?"organizationEnName":"organizationArName",valueField:"id",label:"",options:o.value.userOrganizations,value:s,onChangeCallBack:e=>{p(e)}}),e.jsx(n.Button,{sx:{m:1},variant:"contained",disabled:null==s||s===o.value.currentOrganization.id,onClick:async()=>{await d({endPointURI:"api/auth/changeCurrentOrg",showMask:!0,parameters:{username:o.value.username,orgId:s},data:{},successCallBkFn:e=>{const t={...e.data,isAuthenticated:!0};r(Re.setAuthenticated(t)),i.successChangeCallBackFn&&i.successChangeCallBackFn()}})},children:"Change Organization"})]})},Qo=T.createSlice({name:"SideBar",initialState:{isOpened:!1},reducers:{toggleSideBarState:e=>{e.isOpened=!e.isOpened},setSideBarState:(e,t)=>{e.isOpened=t.payload}}}),{toggleSideBarState:Zo,setSideBarState:$o}=Qo.actions;var Xo=Qo.reducer;function Jo(e,t){const i=l.useRef(e);l.useEffect(()=>{i.current=e},[e]),l.useEffect(()=>{const e=setInterval(()=>i.current?.(),t);return()=>clearInterval(e)},[t])}const ea=n.keyframes`
32
32
  0% { transform: scale(1); opacity: 1; }
33
33
  25% { transform: scale(1); opacity: 0.6; }
34
34
  50% { transform: scale(1); opacity: 1; }