1import{a5 as ke,a6 as ze,r as d,_ as qe,a7 as st,a0 as Te,s as de,j as e,a8 as J,a1 as Me,a3 as Oe,a9 as at,aa as It,ab as ts,T as E,h as Ie,ac as ss,ad as xa,ae as ga,i as $,af as ha,ag as fa,ah as ya,ai as va,aj as Ca,u as ct,P as as,k as rs,m as jt,n as wt,o as Pe,p as M,B as _,x as te,I as V,q as St,t as ns,v as fe,ak as Le,al as rt,w as Be,am as nt,A as m,D as ba,an as dt,R as ot,E as We,ao as L,ap as ja,aq as yt,ar as wa,as as Sa,at as Ea,G as me,l as he,H as De,au as se,d as Z,c as ut,av as Ee,J as pe,C as Et,f as Tt,aw as Ta,M as ye,O as Re,Q as _e,V as ue,g as H,ax as Lt,y as B,z as Da,K as Ia,b as Fa,e as Pa,ay as Aa,F as Ra,az as _a,S as Bt,Y as qt,aA as Ut}from"./index-YZtdLjsh.js";import{u as ka,a as za,C as Gt}from"./CompactStatusBar-DjS598Tq.js";import{u as Ma,P as Oa}from"./useInfiniteStaff-D8aRVBpt.js";import{f as it}from"./format-price-Ct7XMMNY.js";import{E as Na}from"./ExpandLess-HO5O8AwK.js";import{E as $a}from"./ExpandMore-Bh227fr9.js";import{F as Dt,I as Wa}from"./Receipt-D4EAKbom.js";import{P as La}from"./Person-BYXNxMPQ.js";import{A as Ba,D as qa,a as Ua}from"./dashboard-filters-DJuiT9_C.js";import{P as Ga,e as Va}from"./pdf-export-BBK7EKJW.js";import{C as Ka}from"./Collapse-igxGYOdZ.js";import{P as lt,E as Ha}from"./PersonAdd-BvLw0LKE.js";import{u as le}from"./useMutation-BvRxzAdR.js";import{u as Vt}from"./useDebounce-BdHFOUvl.js";import{u as os}from"./useOrganizations-CAhBCEfT.js";import{u as Qa}from"./useDocumentReviewer-C9DW26Ya.js";import{D as ve,a as Ce,b as be}from"./DialogContent-BoUrvOZA.js";import{D as je}from"./DialogTitle-Cqy32sb-.js";import{A as ne}from"./Alert-Dj4_7nIo.js";import{T as re}from"./TextField-C0yGs4if.js";import{D as is}from"./Delete-BWlUKdHj.js";import{C as Ue}from"./Close-CxxIz5HN.js";import{C as Kt}from"./ContentCopy-DvORerLm.js";import{L as ls,A as cs,D as ds,a as Ya,b as Ja,f as Ht}from"./AdapterDateFns-sztmYhdp.js";import{S as Za}from"./fileTypes-CTcHNNi_.js";import{u as us,A as Qt}from"./Autocomplete-LMFmwNdJ.js";import{U as Xa}from"./Upload-DgWqNUn1.js";import{L as er}from"./ListItemText-BSIX_U8A.js";import{u as tr}from"./useAdminInvoices-Bfn6tuJD.js";import"./index-Chjiymov.js";import"./InputAdornment-BJhziIXN.js";function sr(t){const{badgeContent:s,invisible:r=!1,max:a=99,showZero:l=!1}=t,c=us({badgeContent:s,max:a});let g=r;r===!1&&s===0&&!l&&(g=!0);const{badgeContent:u,max:x=a}=g?c:t,v=u&&Number(u)>x?`${x}+`:u;return{badgeContent:u,invisible:g,max:x,displayValue:v}}function ar(t){return ze("MuiBadge",t)}const Se=ke("MuiBadge",["root","badge","dot","standard","anchorOriginTopRight","anchorOriginBottomRight","anchorOriginTopLeft","anchorOriginBottomLeft","invisible","colorError","colorInfo","colorPrimary","colorSecondary","colorSuccess","colorWarning","overlapRectangular","overlapCircular","anchorOriginTopLeftCircular","anchorOriginTopLeftRectangular","anchorOriginTopRightCircular","anchorOriginTopRightRectangular","anchorOriginBottomLeftCircular","anchorOriginBottomLeftRectangular","anchorOriginBottomRightCircular","anchorOriginBottomRightRectangular"]),vt=10,Ct=4,rr=t=>{const{color:s,anchorOrigin:r,invisible:a,overlap:l,variant:c,classes:g={}}=t,u={root:["root"],badge:["badge",c,a&&"invisible",`anchorOrigin${J(r.vertical)}${J(r.horizontal)}`,`anchorOrigin${J(r.vertical)}${J(r.horizontal)}${J(l)}`,`overlap${J(l)}`,s!=="default"&&`color${J(s)}`]};return Me(u,ar,g)},nr=de("span",{name:"MuiBadge",slot:"Root"})({position:"relative",display:"inline-flex",verticalAlign:"middle",flexShrink:0}),or=de("span",{name:"MuiBadge",slot:"Badge",overridesResolver:(t,s)=>{const{ownerState:r}=t;return[s.badge,s[r.variant],s[`anchorOrigin${J(r.anchorOrigin.vertical)}${J(r.anchorOrigin.horizontal)}${J(r.overlap)}`],r.color!=="default"&&s[`color${J(r.color)}`],r.invisible&&s.invisible]}})(Oe(({theme:t})=>({display:"flex",flexDirection:"row",flexWrap:"wrap",justifyContent:"center",alignContent:"center",alignItems:"center",position:"absolute",boxSizing:"border-box",fontFamily:t.typography.fontFamily,fontWeight:t.typography.fontWeightMedium,fontSize:t.typography.pxToRem(12),minWidth:vt*2,lineHeight:1,padding:"0 6px",height:vt*2,borderRadius:vt,zIndex:1,transition:t.transitions.create("transform",{easing:t.transitions.easing.easeInOut,duration:t.transitions.duration.enteringScreen}),variants:[...Object.entries(t.palette).filter(at(["contrastText"])).map(([s])=>({props:{color:s},style:{backgroundColor:(t.vars||t).palette[s].main,color:(t.vars||t).palette[s].contrastText}})),{props:{variant:"dot"},style:{borderRadius:Ct,height:Ct*2,minWidth:Ct*2,padding:0}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="top"&&s.anchorOrigin.horizontal==="right"&&s.overlap==="rectangular",style:{to
1p:0,right:0,transform:"scale(1) translate(50%, -50%)",transformOrigin:"100% 0%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(50%, -50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="bottom"&&s.anchorOrigin.horizontal==="right"&&s.overlap==="rectangular",style:{bottom:0,right:0,transform:"scale(1) translate(50%, 50%)",transformOrigin:"100% 100%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(50%, 50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="top"&&s.anchorOrigin.horizontal==="left"&&s.overlap==="rectangular",style:{top:0,left:0,transform:"scale(1) translate(-50%, -50%)",transformOrigin:"0% 0%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(-50%, -50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="bottom"&&s.anchorOrigin.horizontal==="left"&&s.overlap==="rectangular",style:{bottom:0,left:0,transform:"scale(1) translate(-50%, 50%)",transformOrigin:"0% 100%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(-50%, 50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="top"&&s.anchorOrigin.horizontal==="right"&&s.overlap==="circular",style:{top:"14%",right:"14%",transform:"scale(1) translate(50%, -50%)",transformOrigin:"100% 0%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(50%, -50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="bottom"&&s.anchorOrigin.horizontal==="right"&&s.overlap==="circular",style:{bottom:"14%",right:"14%",transform:"scale(1) translate(50%, 50%)",transformOrigin:"100% 100%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(50%, 50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="top"&&s.anchorOrigin.horizontal==="left"&&s.overlap==="circular",style:{top:"14%",left:"14%",transform:"scale(1) translate(-50%, -50%)",transformOrigin:"0% 0%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(-50%, -50%)"}}},{props:({ownerState:s})=>s.anchorOrigin.vertical==="bottom"&&s.anchorOrigin.horizontal==="left"&&s.overlap==="circular",style:{bottom:"14%",left:"14%",transform:"scale(1) translate(-50%, 50%)",transformOrigin:"0% 100%",[`&.${Se.invisible}`]:{transform:"scale(0) translate(-50%, 50%)"}}},{props:{invisible:!0},style:{transition:t.transitions.create("transform",{easing:t.transitions.easing.easeInOut,duration:t.transitions.duration.leavingScreen})}}]})));function Yt(t){return{vertical:t?.vertical??"top",horizontal:t?.horizontal??"right"}}const ir=d.forwardRef(function(s,r){const a=qe({props:s,name:"MuiBadge"}),{anchorOrigin:l,className:c,classes:g,component:u,components:x={},componentsProps:v={},children:j,overlap:p="rectangular",color:b="default",invisible:F=!1,max:I=99,badgeContent:y,slots:P,slotProps:k,showZero:A=!1,variant:R="standard",...S}=a,{badgeContent:T,invisible:z,max:f,displayValue:O}=sr({max:I,invisible:F,badgeContent:y,showZero:A}),D=us({anchorOrigin:Yt(l),color:b,overlap:p,variant:R,badgeContent:y}),o=z||T==null&&R!=="dot",{color:C=b,overlap:K=p,anchorOrigin:Q,variant:N=R}=o?D:a,h=Yt(Q),q=N!=="dot"?O:void 0,X={...a,badgeContent:T,invisible:o,max:f,displayValue:q,showZero:A,anchorOrigin:h,color:C,overlap:K,variant:N},ee=rr(X),we={slots:{root:P?.root??x.Root,badge:P?.badge??x.Badge},slotProps:{root:k?.root??v.root,badge:k?.badge??v.badge}},[ce,Fe]=st("root",{elementType:nr,externalForwardedProps:{...we,...S},ownerState:X,className:Te(ee.root,c),ref:r,additionalProps:{as:u}}),[oe,Ne]=st("badge",{elementType:or,externalForwardedProps:we,ownerState:X,className:ee.badge});return e.jsxs(ce,{...Fe,children:[j,e.jsx(oe,{...Ne,children:q})]})});function lr(t){return d.Children.toArray(t).filter(s=>d.isValidElement(s))}function cr(t){return ze("MuiFormControlLabel",t)}const Ke=ke("MuiFormControlLabel",["root","labelPlacementStart","labelPlacementTop","labelPlacementBottom","disabled","label","error","required","asterisk"]),dr=t=>{const{classes:s,disabled:r,labelPlacement:a,error:l,required:c}=t,g={root:["root",r&&"disabled",`labelPlacement${J(a)}`,l&&"error",c&&"required"],label:["label",r&&"disabled"],asterisk:["asterisk",l&&"error"]};return Me(g,cr,s)},ur=de("label",{name:"MuiFormControlLabel",slot:"Root",overridesResolver:(t,s)=>{const{ownerState:r}=t;return[{[`& .${Ke.label}`]:s.label},s.root,s[`labelPlacement${J(r.labelPlacement)}`]]}})(Oe(({theme:t})=>({display:"inline-flex",alignItems:"center",cursor:"pointer",verticalAlign:"middle",WebkitTapHighlightColor:"transparent",marginLeft:-11,marginRight:16,[`&.${Ke.disabled}`]:{cursor:"default"},[`& .${Ke.label}`]:{[`&.${Ke.disabled}`]:{color:(t.vars||t).palette.text.disabled}},variants:[{props:{labelPlacement:"start"},style:{flexDirection:"row-reverse",marginRight:-11}},{props:{labelPlacement:"top"},style:{flexDirection:"column-reverse"}},{props:{labelPlacement:"bottom"},style:{flexDirection:"column"}},{props:({labelPlacement:s})=>s==="start"||s==="top"||s==="bottom",style:{marginLeft:16}}]}
1))),pr=de("span",{name:"MuiFormControlLabel",slot:"Asterisk"})(Oe(({theme:t})=>({[`&.${Ke.error}`]:{color:(t.vars||t).palette.error.main}}))),bt=d.forwardRef(function(s,r){const a=qe({props:s,name:"MuiFormControlLabel"}),{checked:l,className:c,componentsProps:g={},control:u,disabled:x,disableTypography:v,inputRef:j,label:p,labelPlacement:b="end",name:F,onChange:I,required:y,slots:P={},slotProps:k={},value:A,...R}=a,S=It(),T=x??u.props.disabled??S?.disabled,z=y??u.props.required,f={disabled:T,required:z};["checked","name","onChange","value","inputRef"].forEach(h=>{typeof u.props[h]>"u"&&typeof a[h]<"u"&&(f[h]=a[h])});const O=ts({props:a,muiFormControl:S,states:["error"]}),D={...a,disabled:T,labelPlacement:b,required:z,error:O.error},o=dr(D),C={slots:P,slotProps:{...g,...k}},[K,Q]=st("typography",{elementType:E,externalForwardedProps:C,ownerState:D});let N=p;return N!=null&&N.type!==E&&!v&&(N=e.jsx(K,{component:"span",...Q,className:Te(o.label,Q?.className),children:N})),e.jsxs(ur,{className:Te(o.root,c),ownerState:D,ref:r,...R,children:[d.cloneElement(u,f),z?e.jsxs("div",{children:[N,e.jsxs(pr,{ownerState:D,"aria-hidden":!0,className:o.asterisk,children:["â","*"]})]}):N]})});function mr(t){return ze("MuiFormGroup",t)}ke("MuiFormGroup",["root","row","error"]);const xr=t=>{const{classes:s,row:r,error:a}=t;return Me({root:["root",r&&"row",a&&"error"]},mr,s)},gr=de("div",{name:"MuiFormGroup",slot:"Root",overridesResolver:(t,s)=>{const{ownerState:r}=t;return[s.root,r.row&&s.row]}})({display:"flex",flexDirection:"column",flexWrap:"wrap",variants:[{props:{row:!0},style:{flexDirection:"row"}}]}),hr=d.forwardRef(function(s,r){const a=qe({props:s,name:"MuiFormGroup"}),{className:l,row:c=!1,...g}=a,u=It(),x=ts({props:a,muiFormControl:u,states:["error"]}),v={...a,row:c,error:x.error},j=xr(v);return e.jsx(gr,{className:Te(j.root,l),ownerState:v,ref:r,...g})}),fr=Ie(e.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"})),yr=Ie(e.jsx("path",{d:"M8.465 8.465C9.37 7.56 10.62 7 12 7C14.76 7 17 9.24 17 12C17 13.38 16.44 14.63 15.535 15.535C14.63 16.44 13.38 17 12 17C9.24 17 7 14.76 7 12C7 10.62 7.56 9.37 8.465 8.465Z"})),vr=de("span",{name:"MuiRadioButtonIcon",shouldForwardProp:ss})({position:"relative",display:"flex"}),Cr=de(fr,{name:"MuiRadioButtonIcon"})({transform:"scale(1)"}),br=de(yr,{name:"MuiRadioButtonIcon"})(Oe(({theme:t})=>({left:0,position:"absolute",transform:"scale(0)",transition:t.transitions.create("transform",{easing:t.transitions.easing.easeIn,duration:t.transitions.duration.shortest}),variants:[{props:{checked:!0},style:{transform:"scale(1)",transition:t.transitions.create("transform",{easing:t.transitions.easing.easeOut,duration:t.transitions.duration.shortest})}}]})));function ps(t){const{checked:s=!1,classes:r={},fontSize:a}=t,l={...t,checked:s};return e.jsxs(vr,{className:r.root,ownerState:l,children:[e.jsx(Cr,{fontSize:a,className:r.background,ownerState:l}),e.jsx(br,{fontSize:a,className:r.dot,ownerState:l})]})}const ms=d.createContext(void 0);function jr(){return d.useContext(ms)}function wr(t){return ze("MuiRadio",t)}const Jt=ke("MuiRadio",["root","checked","disabled","colorPrimary","colorSecondary","sizeSmall"]),Sr=t=>{const{classes:s,color:r,size:a}=t,l={root:["root",`color${J(r)}`,a!=="medium"&&`size${J(a)}`]};return{...s,...Me(l,wr,s)}},Er=de(ga,{shouldForwardProp:t=>ss(t)||t==="classes",name:"MuiRadio",slot:"Root",overridesResolver:(t,s)=>{const{ownerState:r}=t;return[s.root,r.size!=="medium"&&s[`size${J(r.size)}`],s[`color${J(r.color)}`]]}})(Oe(({theme:t})=>({color:(t.vars||t).palette.text.secondary,[`&.${Jt.disabled}`]:{color:(t.vars||t).palette.action.disabled},variants:[{props:{color:"default",disabled:!1,disableRipple:!1},style:{"&:hover":{backgroundColor:t.vars?`rgba(${t.vars.palette.action.activeChannel} / ${t.vars.palette.action.hoverOpacity})`:$(t.palette.action.active,t.palette.action.hoverOpacity)}}},...Object.entries(t.palette).filter(at()).map(([s])=>({props:{color:s,disabled:!1,disableRipple:!1},style:{"&:hover":{backgroundColor:t.vars?`rgba(${t.vars.palette[s].mainChannel} / ${t.vars.palette.action.hoverOpacity})`:$(t.palette[s].main,t.palette.action.hoverOpacity)}}})),...Object.entries(t.palette).filter(at()).map(([s])=>({props:{color:s,disabled:!1},style:{[`&.${Jt.checked}`]:{color:(t.vars||t).palette[s].main}}})),{props:{disableRipple:!1},style:{"&:hover":{"@media (hover: none)":{backgroundColor:"transparent"}}}}]})));function Tr(t,s){return typeof s=="object"&&s!==null?t===s:String(t)===String(s)}const Dr=e.jsx(ps,{checked:!0}),Ir=e.jsx(ps,{}),Zt=d.forwardRef(function(s,r){const a=qe({props:s,name:"MuiRadio"}),{checked:l,checkedIcon:c=Dr,color:g="primary",icon:u=Ir,name:x,onChange:v,size:j="medium",className:p,disabled:b,disableRipple:F=!1,slots:I={},slotProps:y={},inputProps:P,...k}=a,A=It();let R=b;A&&typeof R>"u"&&(R=A.disabled),R??=!1;const S={...a,disabled:R,disableRipple:F,color:g,size:j},T=Sr(S),z=jr();let f=l;const O=xa(v,z&&z.onChange);let D=x;z&&(typeof f>"u"&&(f=Tr(z.value,a.value)),typeof D>"u"&&(D=z.name));const o=y.input??P,[C,K]=st("root",{ref:r,elementType:Er,className:Te(T.root,p),shouldForwardComponentProp:!0,externalForwardedProps:{slots:I,slotProps:y,...k},getSlotProps:Q=>({...Q,onChange:(N,...h)=>{Q.onChange?.(N,...h),O(N,...h)}}),ownerState:S,additionalProps:{type:"radio",icon:d.cloneElement(u,{fontSize:u.props.fontSize??j}),checkedIcon:d.cloneElement(c,{fontSize:c.props.fontSize??j}),disabled:R,name:D,checked:f,slots:I,slotProps:{input:typeof o=="function"?o(S):o}}});return e.jsx(C,{...K,classes:T})});function Fr(t){return ze("MuiRadioGroup",t)}ke("MuiRadioGroup",["root","row","error"]);const Pr=t=>{const{classes:s,row:r,error:a}=t;return Me({root:["root",r&&"row",a&&"error"]},Fr,s)},Ar=d.forwardRef(function(s,r){const{actions:a,children:l,className:c,defaultValue:g,name:u,onChange:x,value:v,...j}=s,p=d.useRef(null),b=Pr(s),[F,I]=ha({controlled:v,default:g,name:"RadioGroup"});d.useImperativeHandle(a,()=>({focus:()=>{let A=p.current.querySelector("input:not(:disabled):checked");A||(A=p.current.querySelector("input:not(:disabled)")),A&&A.focus()}}),[]);const y=fa(r,p),P=ya(u),k=d.useMemo(()=>({name:P,onChange(A){I(A.target.value),x&&x(A,A.target.value)},value:F}),[P,x,I,F]);return e.jsx(ms.Provider,{value:k,children:e.jsx(hr,{role:"radiogroup",ref:y,className:Te(b.root,c),...j,children:l})})});function Rr(t){return ze("MuiToggleButton",t)}const Ae=ke("MuiToggleButton",["root","disabled","selected","standard","primary","secondary","sizeSmall","sizeMedium","sizeLarge","fullWidth"]),xs=d.createContext({}),gs=d.createContext(void 0);function _r(t,s){return s===void 0||t===void 0?!1:Array.isArray(s)?s.includes(t):t===s}const kr=t=>{const{classes:s,fullWidth:r,selected:a,disabled:l,size:c,color:g}=t,u={root:["root",a&&"selected",l&&"disabled",r&&"fullWidth",`size${J(c)}`,g]};return Me(u,Rr,s)},zr=de(Ca,{name:"MuiToggleButton",slot:"Root",overridesResolver:(t,s)=>{const{ownerState:r}=t;return[s.root,s[`size${J(r.size)}`]]}})(Oe(({theme:t})=>({...t.typography.button,borderRadius:(t.vars||t).shape.borderRadius,padding:11,border:`1px solid ${(t.vars||t).palette.divider}`,color:(t.vars||t).palette.action.active,[`&.${Ae.disabled}`]:{color:(t.vars||t).palette.action.disabled,border:`1px solid ${(t.vars||t).palette.action.disabledBackgroun
1d}`},"&:hover":{textDecoration:"none",backgroundColor:t.vars?`rgba(${t.vars.palette.text.primaryChannel} / ${t.vars.palette.action.hoverOpacity})`:$(t.palette.text.primary,t.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:"transparent"}},variants:[{props:{color:"standard"},style:{[`&.${Ae.selected}`]:{color:(t.vars||t).palette.text.primary,backgroundColor:t.vars?`rgba(${t.vars.palette.text.primaryChannel} / ${t.vars.palette.action.selectedOpacity})`:$(t.palette.text.primary,t.palette.action.selectedOpacity),"&:hover":{backgroundColor:t.vars?`rgba(${t.vars.palette.text.primaryChannel} / calc(${t.vars.palette.action.selectedOpacity} + ${t.vars.palette.action.hoverOpacity}))`:$(t.palette.text.primary,t.palette.action.selectedOpacity+t.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:t.vars?`rgba(${t.vars.palette.text.primaryChannel} / ${t.vars.palette.action.selectedOpacity})`:$(t.palette.text.primary,t.palette.action.selectedOpacity)}}}}},...Object.entries(t.palette).filter(at()).map(([s])=>({props:{color:s},style:{[`&.${Ae.selected}`]:{color:(t.vars||t).palette[s].main,backgroundColor:t.vars?`rgba(${t.vars.palette[s].mainChannel} / ${t.vars.palette.action.selectedOpacity})`:$(t.palette[s].main,t.palette.action.selectedOpacity),"&:hover":{backgroundColor:t.vars?`rgba(${t.vars.palette[s].mainChannel} / calc(${t.vars.palette.action.selectedOpacity} + ${t.vars.palette.action.hoverOpacity}))`:$(t.palette[s].main,t.palette.action.selectedOpacity+t.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:t.vars?`rgba(${t.vars.palette[s].mainChannel} / ${t.vars.palette.action.selectedOpacity})`:$(t.palette[s].main,t.palette.action.selectedOpacity)}}}}})),{props:{fullWidth:!0},style:{width:"100%"}},{props:{size:"small"},style:{padding:7,fontSize:t.typography.pxToRem(13)}},{props:{size:"large"},style:{padding:15,fontSize:t.typography.pxToRem(15)}}]}))),Xt=d.forwardRef(function(s,r){const{value:a,...l}=d.useContext(xs),c=d.useContext(gs),g=va({...l,selected:_r(s.value,a)},s),u=qe({props:g,name:"MuiToggleButton"}),{children:x,className:v,color:j="standard",disabled:p=!1,disableFocusRipple:b=!1,fullWidth:F=!1,onChange:I,onClick:y,selected:P,size:k="medium",value:A,...R}=u,S={...u,color:j,disabled:p,disableFocusRipple:b,fullWidth:F,size:k},T=kr(S),z=O=>{y&&(y(O,A),O.defaultPrevented)||I&&I(O,A)},f=c||"";return e.jsx(zr,{className:Te(l.className,T.root,v,f),disabled:p,focusRipple:!b,ref:r,onClick:z,onChange:I,value:A,ownerState:S,"aria-pressed":P,...R,children:x})});function Mr(t){return ze("MuiToggleButtonGroup",t)}const G=ke("MuiToggleButtonGroup",["root","selected","horizontal","vertical","disabled","grouped","groupedHorizontal","groupedVertical","fullWidth","firstButton","lastButton","middleButton"]),Or=t=>{const{classes:s,orientation:r,fullWidth:a,disabled:l}=t,c={root:["root",r,a&&"fullWidth"],grouped:["grouped",`grouped${J(r)}`,l&&"disabled"],firstButton:["firstButton"],lastButton:["lastButton"],middleButton:["middleButton"]};return Me(c,Mr,s)},Nr=de("div",{name:"MuiToggleButtonGroup",slot:"Root",overridesResolver:(t,s)=>{const{ownerState:r}=t;return[{[`& .${G.grouped}`]:s.grouped},{[`& .${G.grouped}`]:s[`grouped${J(r.orientation)}`]},{[`& .${G.firstButton}`]:s.firstButton},{[`& .${G.lastButton}`]:s.lastButton},{[`& .${G.middleButton}`]:s.middleButton},s.root,r.orientation==="vertical"&&s.vertical,r.fullWidth&&s.fullWidth]}})(Oe(({theme:t})=>({display:"inline-flex",borderRadius:(t.vars||t).shape.borderRadius,variants:[{props:{orientation:"vertical"},style:{flexDirection:"column",[`& .${G.grouped}`]:{[`&.${G.selected} + .${G.grouped}.${G.selected}`]:{borderTop:0,marginTop:0}},[`& .${G.firstButton},& .${G.middleButton}`]:{borderBottomLeftRadius:0,borderBottomRightRadius:0},[`& .${G.lastButton},& .${G.middleButton}`]:{marginTop:-1,borderTop:"1px solid transparent",borderTopLeftRadius:0,borderTopRightRadius:0},[`& .${G.lastButton}.${Ae.disabled},& .${G.middleButton}.${Ae.disabled}`]:{borderTop:"1px solid transparent"}}},{props:{fullWidth:!0},style:{width:"100%"}},{props:{orientation:"horizontal"},style:{[`& .${G.grouped}`]:{[`&.${G.selected} + .${G.grouped}.${G.selected}`]:{borderLeft:0,marginLeft:0}},[`& .${G.firstButton},& .${G.middleButton}`]:{borderTopRightRadius:0,borderBottomRightRadius:0},[`& .${G.lastButton},& .${G.middleButton}`]:{marginLeft:-1,borderLeft:"1px solid transparent",borderTopLeftRadius:0,borderBottomLeftRadius:0},[`& .${G.lastButton}.${Ae.disabled},& .${G.middleButton}.${Ae.disabled}`]:{borderLeft:"1px solid transparent"}}}]}))),$r=d.forwardRef(function(s,r){const a=qe({props:s,name:"MuiToggleButtonGroup"}),{children:l,className:c,color:g="standard",disabled:u=!1,exclusive:x=!1,fullWidth:v=!1,onChange:j,orientation:p="horizontal",size:b="medium",value:F,...I}=a,y={...a,disabled:u,fullWidth:v,orientation:p,size:b},P=Or(y),k=d.useCallback((f,O)=>{if(!j)return;const D=F&&F.indexOf(O);let o;F&&D>=0?(o=F.slice(),o.splice(D,1)):o=F?F.concat(O):[O],j(f,o)},[j,F]),A=d.useCallback((f,O)=>{j&&j(f,F===O?null:O)},[j,F]),R=d.useMemo(()=>({className:P.grouped,onChange:x?A:k,value:F,size:b,fullWidth:v,color:g,disabled:u}),[P.grouped,x,A,k,F,b,v,g,u]),S=lr(l),T=S.length,z=f=>{const O=f===0,D=f===T-1;return O&&D?"":O?P.firstButton:D?P.lastButton:P.middleButton};return e.jsx(Nr,{role:"group",className:Te(P.root,c),ref:r,ownerState:y,...I,children:e.jsx(xs.Provider,{value:R,children:S.map((f,O)=>e.jsx(gs.Provider,{value:z(O),children:f},O))})})}),tt=Ie(e.jsx("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM8 9h8v10H8zm7.5-5-1-1h-5l-1 1H5v2h14V4z"})),Wr=Ie(e.jsx("path",{d:"M12.5 6.9c1.78 0 2.44.85 2.5 2.1h2.21c-.07-1.72-1.12-3.3-3.21-3.81V3h-3v2.16c-.53.12-1.03.3-1.48.54l1.47 1.47c.41-.17.91-.27 1.51-.27M5.33 4.06 4.06 5.33 7.5 8.77c0 2.08 1.56 3.21 3.91 3.91l3.51 3.51c-.34.48-1.05.91-2.42.91-2.06 0-2.87-.92-2.98-2.1h-2.2c.12 2.19 1.76 3.42 3.68 3.83V21h3v-2.15c.96-.18 1.82-.55 2.45-1.12l2.22 2.22 1.27-1.27z"})),es=Ie(e.jsx("path",{d:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"})),Lr=Ie(e.jsx("path",{d:"M7.41 18.59 8.83 20 12 16.83 15.17 20l1.41-1.41L12 14zm9.18-13.18L15.17 4 12 7.17 8.83 4 7.41 5.41 12 10z"})),Br=Ie(e.jsx("path",{d:"M12 5.83 15.17 9l1.41-1.41L12 3 7.41 7.59 8.83 9zm0 12.34L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15z"})),qr=Ie(e.jsx("path",{d:"M3 14h4v-4H3zm0 5h4v-4H3zM3 9h4V5H3zm5 5h13v-4H8zm0 5h13v-4H8zM8 5v4h13V5z"})),Ur=({folders:t,navigate:s,staff:r,onUpdateReviewer:a,onCancelDocument:l,onSetExtraFee:c,onCreateInvoice:g,onViewInvoice:u,onCompleteAllDocuments:x,onDeleteFolder:v,folderInvoices:j})=>{const p=ct(),[b,F]=d.useState(new Set(t.map(o=>o.id))),I=o=>{const C=new Set(b);C.has(o)?C.delete(o):C.add(o),F(C)},y=()=>{F(new Set(t.map(o=>o.id)))},P=()=>{F(new Set)};d.useEffect(()=>{const o=new Set(t.map(C=>C.id));F(C=>new Set([...C,...o]))},[t]);const k=o=>{switch(o){case"paid":return p.palette.success.main;
1case"pending":return p.palette.warning.main;case"failed":return p.palette.error.main;default:return p.palette.grey[500]}},A=(o,C)=>`${o.toUpperCase()} â ${C.toUpperCase()}`,R=o=>{if(!o||o==="")return"Pending to choose";switch(o){case We.HUMAN_AND_AI:return"Human + AI";case We.AI_ONLY:return"AI Only";default:return o}},S=o=>!!o.deletedAt,T=o=>!!o.filesDeletedAt,z=o=>o.documents.length>0&&o.documents.every(C=>C.status===m.COMPLETED),f=o=>j?.get(o),O=o=>{const C=[m.COMPLETED,m.CANCELLED,m.FAILED];return o.documents.some(K=>!C.includes(K.status))},D=o=>o.documents.length>0&&o.documents.every(C=>C.status===m.FAILED);return e.jsx(as,{elevation:0,sx:{borderRadius:2,border:`1px solid ${$(p.palette.grey[300],.3)}`,overflow:"hidden"},children:e.jsx(rs,{children:e.jsxs(jt,{children:[e.jsx(wt,{children:e.jsxs(Pe,{sx:{backgroundColor:p.palette.grey[100]},children:[e.jsx(M,{sx:{width:"50px",py:2,px:1},children:e.jsxs(_,{sx:{display:"flex",gap:.5},children:[e.jsx(te,{title:"Expand All",children:e.jsx(V,{size:"small",onClick:y,sx:{p:.5},children:e.jsx(Br,{sx:{fontSize:16}})})}),e.jsx(te,{title:"Collapse All",children:e.jsx(V,{size:"small",onClick:P,sx:{p:.5},children:e.jsx(Lr,{sx:{fontSize:16}})})})]})}),e.jsx(M,{sx:{fontWeight:600,color:p.palette.grey[600],fontSize:"0.875rem",py:2,px:3},children:"Project Name"}),e.jsx(M,{sx:{fontWeight:600,color:p.palette.grey[600],fontSize:"0.875rem",py:2,px:3},children:"User"}),e.jsx(M,{sx:{fontWeight:600,color:p.palette.grey[600],fontSize:"0.875rem",py:2,px:3},children:"Requested Deadline"}),e.jsx(M,{sx:{fontWeight:600,color:p.palette.grey[600],fontSize:"0.875rem",py:2,px:3},children:"Payment Status"}),e.jsx(M,{sx:{fontWeight:600,color:p.palette.grey[600],fontSize:"0.875rem",py:2,px:3},children:"Date"}),e.jsx(M,{sx:{fontWeight:600,color:p.palette.grey[600],fontSize:"0.875rem",py:2,px:3},children:"Actions"})]})}),e.jsx(St,{children:t.map(o=>e.jsxs(ns.Fragment,{children:[e.jsxs(Pe,{sx:{"&:last-child td":{borderBottom:0},cursor:"pointer",opacity:S(o)?.5:1,"&:hover":{backgroundColor:$(p.palette.primary.main,.04)}},onClick:()=>I(o.id),children:[e.jsx(M,{sx:{py:2,px:1},children:e.jsx(V,{size:"small",onClick:C=>{C.stopPropagation(),I(o.id)},children:b.has(o.id)?e.jsx(Na,{}):e.jsx($a,{})})}),e.jsx(M,{sx:{py:2.5,px:3},children:e.jsxs(_,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(Dt,{sx:{color:S(o)?p.palette.grey[400]:p.palette.grey[500],fontSize:20}}),e.jsx(E,{variant:"body2",fontWeight:500,sx:{color:S(o)?p.palette.grey[500]:"inherit",textDecoration:S(o)?"line-through":"none"},children:o.name}),S(o)&&e.jsx(fe,{icon:e.jsx(tt,{sx:{fontSize:14}}),label:"Deleted",size:"small",sx:{height:20,backgroundColor:$(p.palette.error.main,.1),color:p.palette.error.main,fontWeight:500,fontSize:"0.7rem","& .MuiChip-icon":{color:p.palette.error.main}}}),!S(o)&&T(o)&&e.jsx(fe,{icon:e.jsx(tt,{sx:{fontSize:14}}),label:"Files Deleted",size:"small",sx:{height:20,backgroundColor:$(p.palette.warning.main,.1),color:p.palette.warning.main,fontWeight:500,fontSize:"0.7rem","& .MuiChip-icon":{color:p.palette.warning.main}}})]})}),e.jsx(M,{sx:{py:2.5,px:3},children:e.jsxs(_,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(La,{sx:{color:p.palette.grey[500],fontSize:16}}),e.jsx(E,{variant:"body2",children:o.customer?.fullName||"Unknown User"})]})}),e.jsx(M,{sx:{py:2.5,px:3},children:e.jsx(E,{variant:"body2",children:o.requested_deadline?Le(new Date(o.requested_deadline)):"-"})}),e.jsx(M,{sx:{py:2.5,px:3},children:e.jsx(fe,{label:o.payment_status,size:"small",sx:{backgroundColor:$(k(o.payment_status),.1),color:k(o.payment_status),fontWeight:500}})}),e.jsx(M,{sx:{py:2.5,px:3},children:e.jsx(E,{variant:"body2",children:Le(o.created_at)})}),e.jsx(M,{sx:{py:2.5,px:3},children:e.jsxs(_,{sx:{display:"flex",gap:.5},children:[o.requested_deadline&&c&&!S(o)&&!f(o.id)&&e.jsx(te,{title:"Set Extra Fee",children:e.jsx(V,{size:"small",onClick:()=>{c(o.id,o.extra_fee_amount_cents||0)},sx:{p:.5},children:e.jsx(Ba,{sx:{fontSize:16}})})}),e.jsx(te,{title:S(o)?"View Deleted Folder Details":"View Folder Details",children:e.jsx(V,{size:"small",onClick:C=>{C.stopPropagation(),I(o.id)},sx:{p:.5},children:e.jsx(rt,{sx:{fontSize:16}})})}),x&&!S(o)&&O(o)&&e.jsx(te,{title:"Complete All Documents",children:e.jsx(V,{size:"small",onClick:C=>{C.stopPropagation(),x(o)},sx:{p:.5},color:"success",children:e.jsx(Be,{sx:{fontSize:16}})})}),z(o)&&!f(o.id)&&g&&e.jsx(te,{title:"Create Invoice",children:e.jsx(V,{size:"small",onClick:C=>{C.stopPropagation(),g(o)},sx:{p:.5},color:"secondary",children:e.jsx(Wa,{sx:{fontSize:16}})})}),f(o.id)&&u&&e.jsx(te,{title:"Export Invoice PDF",children:e.jsx(V,{size:"small",onClick:C=>{C.stopPropagation();const K=f(o.id);K&&u(K)},sx:{p:.5},color:"primary",children:e.jsx(Ga,{sx:{fontSize:16}})})}),v&&!S(o)&&D(o)&&e.jsx(te,{title:"Delete Project",children:e.jsx(V,{size:"small",onClick:C=>{C.stopPropagation(),v(o)},sx:{p:.5},color:"error",children:e.jsx(tt,{sx:{fontSize:16}})})})]})})]}),e.jsx(Pe,{children:e.jsx(M,{colSpan:7,sx:{py:0,px:0},children:e.jsx(Ka,{in:b.has(o.id),timeout:"auto",unmountOnExit:!0,children:e.jsx(_,{sx:{backgroundColor:$(p.palette.grey[50],.5),p:2},children:e.jsxs(jt,{size:"small",children:[e.jsx(wt,{children:e.jsxs(Pe,{children:[e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"25%"},children:"Document"}),e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"12%"},children:"Languages"}),e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"10%"},children:"Type"}),e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"12%"},children:"Status"}),e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"20%"},children:"Reviewer"}),e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"10%"},children:"Price"}),e.jsx(M,{sx:{fontWeight:600,fontSize:"0.75rem",py:1,px:2,width:"8%"},children:"Actions"})]})}),e.jsx(St,{children:o.documents.map(C=>{const K=nt(C.status,p),Q=C.status===m.REVIEW_PENDING||C.status===m.IN_REVIEW,N=C.status!==m.COMPLETED&&C.status!==m.CANCELLED&&C.status!==m.FAILED&&C.status!==m.COMPLETED_BY_STAFF,h=S(o)||T(o);
1return e.jsxs(Pe,{sx:{opacity:h?.6:1},children:[e.jsx(M,{sx:{py:1,px:2,width:"25%"},children:e.jsxs(_,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(ba,{sx:{color:p.palette.grey[500],fontSize:16}}),e.jsx(E,{variant:"body2",fontSize:"0.75rem",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"200px"},children:C.file_name})]})}),e.jsx(M,{sx:{py:1,px:2,width:"12%"},children:e.jsx(E,{variant:"body2",fontSize:"0.75rem",children:A(C.source_language,C.target_language)})}),e.jsx(M,{sx:{py:1,px:2,width:"10%"},children:e.jsx(E,{variant:"body2",fontSize:"0.75rem",children:R(C.translation_type)})}),e.jsx(M,{sx:{py:1,px:2,width:"12%"},children:e.jsx(fe,{label:K.title,size:"small",sx:{backgroundColor:$(K.backgroundColor,.1),color:K.iconColor,borderColor:K.iconColor,border:"1px solid",fontSize:"0.7rem",height:"20px"}})}),e.jsx(M,{sx:{py:1,px:2,width:"20%"},children:e.jsx(E,{variant:"body2",fontSize:"0.75rem",children:C.reviewer?.fullName||"Not Assigned"})}),e.jsx(M,{sx:{py:1,px:2,width:"10%"},children:e.jsx(E,{variant:"body2",fontSize:"0.75rem",children:it(C.payment_amount_cents)})}),e.jsx(M,{sx:{py:1,px:2,width:"8%"},children:e.jsxs(_,{sx:{display:"flex",gap:.5},children:[r&&a&&e.jsx(te,{title:h?"Document deleted":Q?"Assign Reviewer":"Document not in review status",children:e.jsx("span",{children:e.jsx(V,{size:"small",onClick:()=>{Q&&!h&&a(C.id,C.reviewer?.id||"")},disabled:!Q||h,sx:{p:1,backgroundColor:Q&&!h?$(p.palette.primary.main,.08):"transparent","&:hover":{backgroundColor:Q&&!h?$(p.palette.primary.main,.15):"transparent"}},children:e.jsx(lt,{sx:{fontSize:24}})})})}),l&&e.jsx(te,{title:h?"Document deleted":N?"Cancel Document":"Cannot cancel this document",children:e.jsx("span",{children:e.jsx(V,{size:"small",onClick:()=>{N&&!h&&l(C.id)},disabled:!N||h,sx:{p:1,backgroundColor:N&&!h?$(p.palette.error.main,.08):"transparent","&:hover":{backgroundColor:N&&!h?$(p.palette.error.main,.15):"transparent"}},children:e.jsx(dt,{sx:{fontSize:24}})})})}),e.jsx(te,{title:h?"View Deleted Document Metadata":C.status===m.CREATED?"Cannot view document in created status":"View Document",children:e.jsx("span",{children:e.jsx(V,{size:"small",onClick:()=>{C.status!==m.CREATED&&!h&&s(ot.DOCUMENT(C.id))},disabled:C.status===m.CREATED||h,sx:{p:1,backgroundColor:C.status!==m.CREATED&&!h?$(p.palette.info.main,.08):"transparent","&:hover":{backgroundColor:C.status!==m.CREATED&&!h?$(p.palette.info.main,.15):"transparent"}},children:e.jsx(rt,{sx:{fontSize:24}})})})})]})})]},C.id)})})]})})})})})]},o.id))})]})})})},Gr=t=>{const{statistics:s,documents:r,theme:a,navigate:l,staff:c,onUpdateReviewer:g,onCancelDocument:u}=t,x=(y,P)=>[{label:yt.actions.view,icon:rt,backgroundColor:P.palette.info.main,textColor:P.palette.common.white,hoverBackgroundColor:$(P.palette.info.main,.8),size:"small",onClick:()=>{l(ot.DOCUMENT(y.id))},disabled:y.status===m.CREATED}],v=["document","user","languages","type","status","reviewer","requested_deadline","deadline","date","price","actions"],j={document:{key:"document",header:"Document",type:"text",align:"left"},user:{key:"user",header:"User",type:"text",align:"left"},languages:{key:"languages",header:"Languages",type:"text",align:"left"},type:{key:"type",header:"Type",type:"text",align:"left"},status:{key:"status",header:"Status",type:"badge",align:"center"},reviewer:{key:"reviewer",header:"Reviewer",type:"text",align:"left"},requested_deadline:{key:"requested_deadline",header:"Requested Deadline",type:"text",align:"center"},deadline:{key:"deadline",header:"Deadline",type:"text",align:"center"},date:{key:"date",header:"Date",type:"date",align:"center"},price:{key:"price",header:"Price",type:"price",align:"right"},actions:{key:"actions",header:"Actions",type:"multiple-buttons",align:"center"}},p=v.map(y=>j[y]),b=[{key:m.AWAITING_TRANSLATION,value:s[m.AWAITING_TRANSLATION]||0,title:L[m.AWAITING_TRANSLATION].title,tooltip:L[m.AWAITING_TRANSLATION].description,icon:L[m.AWAITING_TRANSLATION].icon,iconColor:L[m.AWAITING_TRANSLATION].iconColor(a)},{key:m.COMPLETED,value:s[m.COMPLETED]||0,title:L[m.COMPLETED].title,tooltip:L[m.COMPLETED].description,icon:L[m.COMPLETED].icon,iconColor:L[m.COMPLETED].iconColor(a)},{key:m.COMPLETED_BY_STAFF,value:s[m.COMPLETED_BY_STAFF]||0,title:L[m.COMPLETED_BY_STAFF].title,tooltip:L[m.COMPLETED_BY_STAFF].description,icon:L[m.COMPLETED_BY_STAFF].icon,iconColor:L[m.COMPLETED_BY_STAFF].iconColor(a)},{key:m.FAILED,value:s[m.FAILED]||0,title:L[m.FAILED].title,tooltip:L[m.FAILED].description,icon:L[m.FAILED].icon,iconColor:L[m.FAILED].iconColor(a)},{key:m.REVIEW_PENDING,value:s[m.REVIEW_PENDING]||0,title:L[m.REVIEW_PENDING].title,tooltip:L[m.REVIEW_PENDING].description,icon:L[m.REVIEW_PENDING].icon,iconColor:L[m.REVIEW_PENDING].iconColor(a)}
1,{key:m.IN_REVIEW,value:s[m.IN_REVIEW]||0,title:L[m.IN_REVIEW].title,tooltip:L[m.IN_REVIEW].description,icon:L[m.IN_REVIEW].icon,iconColor:L[m.IN_REVIEW].iconColor(a)},{key:m.CREATED,value:s[m.CREATED]||0,title:L[m.CREATED].title,tooltip:L[m.CREATED].description,icon:L[m.CREATED].icon,iconColor:L[m.CREATED].iconColor(a)},{key:m.CANCELLED,value:s[m.CANCELLED]||0,title:L[m.CANCELLED].title,tooltip:L[m.CANCELLED].description,icon:L[m.CANCELLED].icon,iconColor:L[m.CANCELLED].iconColor(a)}],F=y=>{const P=nt(y.status,a),k=x(y,a);return{document:y.file_name,user:y.customer?.fullName,languages:Ea(y.source_language,y.target_language),type:Sa(y.translation_type),status:P.title,reviewer:y.reviewer?.fullName||yt.reviewer.notAssigned,requested_deadline:y.requested_deadline?Le(new Date(y.requested_deadline)):"-",deadline:wa(y.deadline_date),date:Le(new Date(y.created_at)),price:it(y.payment_amount_cents),actions:k.map(A=>A.label).join(", ")}},I=r.map(y=>{const P=nt(y.status,a),k=x(y,a),A=F(y),R={id:y.id};if(v.forEach(S=>{R[S]=String(A[S])}),v.includes("status")&&(R.badgeConfig={backgroundColor:P.backgroundColor,textColor:P.iconColor,borderColor:P.iconColor,size:"small",tooltip:P.tooltip}),v.includes("reviewer")&&(R.reviewer=y.reviewer?.email?ja(y.reviewer.email):yt.reviewer.notAssignedShort),v.includes("actions")){const S=[],T=y.status===m.REVIEW_PENDING||y.status===m.IN_REVIEW;if(c&&g){const f={label:"Assign Reviewer",backgroundColor:a.palette.primary.main,textColor:a.palette.common.white,hoverBackgroundColor:$(a.palette.primary.main,.8),size:"small",onClick:()=>{T&&g(y.id,y.reviewer?.id||"")},disabled:!T};S.push(f)}const z=y.status!==m.COMPLETED&&y.status!==m.CANCELLED&&y.status!==m.FAILED&&y.status!==m.COMPLETED_BY_STAFF;if(u&&z){const f={label:"Cancel",backgroundColor:a.palette.error.main,textColor:a.palette.common.white,hoverBackgroundColor:$(a.palette.error.main,.8),size:"small",onClick:()=>{u(y.id)},disabled:!1};S.push(f)}S.push(...k),R.multipleButtonsConfig=S,R.actions=""}return R});return{tableHeaders:p,statisticsCards:b,tableRows:I}},Vr=t=>{const s=me(),r=(c=1,g=25,u,x,v,j)=>De({queryKey:["getAdminFolders",c,g,u||"all",x||"all",v||"all",j?.dateFrom||"all",j?.dateTo||"all",j?.organizationIds||"all",t],queryFn:async()=>{if(!t)throw new Error("No authentication token");let p=`https://api.lingounlocked.ai/folders/search?page=${c}&limit=${g}`;u&&u!==""&&(p+=`&document_status=${encodeURIComponent(u)}`),x&&x!==""&&(p+=`&folder_name=${encodeURIComponent(x)}`),v&&v!==""&&(p+=`&user_email=${encodeURIComponent(v)}`),j?.dateFrom&&(p+=`&dateFrom=${encodeURIComponent(j.dateFrom)}`),j?.dateTo&&(p+=`&dateTo=${encodeURIComponent(j.dateTo)}`),j?.organizationIds&&(p+=`&organizationIds=${encodeURIComponent(j.organizationIds)}`);const b=await fetch(p,{method:"GET",headers:{authorization:`Bearer ${t}`}});if(!b.ok)throw new Error(`HTTP error! status: ${b.status}`);return await b.json()},enabled:!!t}),a=c=>De({queryKey:["getAdminFolder",c,t],queryFn:async()=>{if(!t)throw new Error("No authentication token");const g=await fetch(`https://api.lingounlocked.ai/folders/${c}`,{method:"GET",headers:{authorization:`Bearer ${t}`}});if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return await g.json()},enabled:!!t&&!!c}),l=le({mutationFn:async({folderId:c,data:g})=>{if(!t)throw new Error("No authentication token");const u=await fetch(`https://api.lingounlocked.ai/folders/${c}/extra-fee`,{method:"PATCH",headers:{"Content-Type":"application/json",authorization:`Bearer ${t}`},body:JSON.stringify(g)});if(!u.ok){const x=await u.json();throw new Error(x.message||`HTTP error! status: ${u.status}`)}return u.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["getAdminFolders"]}),s.invalidateQueries({queryKey:["getFolders"]})},onError:c=>{he.error("Error updating folder extra fee:",c)}});return{useAdminFolders:r,useAdminFolder:a,updateFolderExtraFeeMutation:l}},Kr=t=>{const s=me();return le({mutationFn:async({documentId:r,cancellation_reason:a})=>(await Z.cancelDocument(r,t)).queryFn({cancellation_reason:a}),onSuccess:()=>{s.invalidateQueries({queryKey:se.GET_DOCUMENTS}),s.invalidateQueries({queryKey:["getAdminFolders"]}),s.invalidateQueries({queryKey:["getFolders"]})}})},Hr=({open:t,onClose:s,onSubmit:r,isLoading:a})=>{const{getAccessToken:l}
1=ut(),[c,g]=d.useState(""),[u,x]=d.useState(""),[v,j]=d.useState(""),[p,b]=d.useState(""),{organizations:F,isOrganizationsLoading:I}=os(l()),{data:y,isLoading:P}=De({queryKey:[Ee(se.GET_PRICING_CONFIG),l()],queryFn:()=>Z.getPricingConfig(l()).queryFn(),enabled:t}),k=y?.data?.data||[],A=k.filter(f=>!f.organizationId),R=k.filter(f=>f.organizationId),S=async()=>{if(!c||u===""){b("Please fill in all fields");return}const f=parseFloat(u);if(isNaN(f)||f<0){b("Cost per word must be a non-negative number");return}b("");try{await r(c,f,v||null),T()}catch{b("Failed to update pricing configuration")}},T=()=>{g(""),x(""),j(""),b(""),s()},z=v?F.find(f=>f._id===v)?.name:null;return e.jsxs(ve,{open:t,onClose:T,maxWidth:"sm",fullWidth:!0,children:[e.jsx(je,{sx:{backgroundColor:"primary.main",color:"primary.contrastText","& .MuiTypography-root":{color:"primary.contrastText"}},children:"Update Pricing Configuration"}),e.jsx(Ce,{sx:{mt:2},children:e.jsxs(_,{sx:{mt:2},children:[p&&e.jsx(ne,{severity:"error",sx:{mb:2},children:p}),e.jsx(E,{variant:"h6",sx:{mb:2,fontWeight:600},children:"Current Pricing"}),P?e.jsx(_,{display:"flex",justifyContent:"center",py:2,children:e.jsx(pe,{size:24})}):k.length>0?e.jsxs(_,{sx:{mb:3},children:[A.length>0&&e.jsxs(_,{sx:{mb:3},children:[e.jsxs(_,{display:"flex",alignItems:"center",gap:1,mb:1,children:[e.jsx(E,{variant:"subtitle2",fontWeight:600,children:"Default Pricing"}),e.jsx(fe,{label:"All Organizations",size:"small",color:"primary"})]}),A.map(f=>e.jsx(Et,{sx:{mb:2},children:e.jsx(Tt,{children:e.jsxs(_,{display:"flex",justifyContent:"space-between",alignItems:"center",children:[e.jsxs(_,{children:[e.jsx(E,{variant:"subtitle1",fontWeight:600,children:f.translationType===We.AI_ONLY?"AI Only":"AI + Human Review"}),e.jsxs(E,{variant:"h6",color:"primary",fontWeight:700,children:[it(f.costPerWordCents,!1)," per word"]})]}),e.jsx(_,{textAlign:"right",children:e.jsxs(E,{variant:"caption",color:"text.secondary",children:["Last updated: ",Le(new Date(f.updatedAt))]})})]})})},f.id))]}),R.length>0&&e.jsxs(_,{children:[e.jsxs(_,{display:"flex",alignItems:"center",gap:1,mb:1,children:[e.jsx(E,{variant:"subtitle2",fontWeight:600,children:"Organization-Specific Pricing"}),e.jsx(fe,{label:`${R.length} Custom`,size:"small",color:"secondary"})]}),R.map(f=>e.jsx(Et,{sx:{mb:2,borderLeft:"4px solid",borderColor:"secondary.main"},children:e.jsx(Tt,{children:e.jsxs(_,{display:"flex",justifyContent:"space-between",alignItems:"center",children:[e.jsxs(_,{children:[e.jsxs(_,{display:"flex",alignItems:"center",gap:1,mb:.5,children:[e.jsx(E,{variant:"subtitle1",fontWeight:600,children:f.translationType===We.AI_ONLY?"AI Only":"AI + Human Review"}),e.jsx(fe,{label:f.organizationName||`Org ${f.organizationId}`,size:"small",variant:"outlined"})]}),e.jsxs(E,{variant:"h6",color:"secondary",fontWeight:700,children:[it(f.costPerWordCents,!1)," per word"]})]}),e.jsx(_,{textAlign:"right",children:e.jsxs(E,{variant:"caption",color:"text.secondary",children:["Last updated: ",Le(new Date(f.updatedAt))]})})]})})},f.id))]})]}):e.jsx(ne,{severity:"info",sx:{mb:2},children:"No pricing configurations found."}),e.jsx(Ta,{sx:{my:3}}),e.jsx(E,{variant:"h6",sx:{mb:2,fontWeight:600},children:"Update Pricing"}),e.jsxs(ye,{fullWidth:!0,sx:{mb:3},children:[e.jsx(Re,{children:"Organization"}),e.jsxs(_e,{value:v,onChange:f=>j(f.target.value),label:"Organization",disabled:I,children:[e.jsx(ue,{value:"",children:e.jsx("em",{children:"Default (All Organizations)"})}),F.map(f=>e.jsx(ue,{value:f._id,children:f.name},f._id))]})]}),e.jsxs(ye,{fullWidth:!0,sx:{mb:3},children:[e.jsx(Re,{children:"Translation Type"}),e.jsxs(_e,{value:c,onChange:f=>g(f.target.value),label:"Translation Type",children:[e.jsx(ue,{value:We.AI_ONLY,children:"AI Only"}),e.jsx(ue,{value:We.HUMAN_AND_AI,children:"AI + Human Review"})]})]}),e.jsx(re,{fullWidth:!0,label:"Cost per Word (cents)",type:"number",value:u,onChange:f=>x(f.target.value),placeholder:"e.g., 50 for $0.50 per word",sx:{mb:2}}),v&&z&&e.jsxs(ne,{severity:"info",sx:{mb:2},children:["Setting organization-specific pricing for ",e.jsx("strong",{children:z}),". This will only apply to users in this organization. Other organizations will use the default pricing."]}),e.jsx(E,{variant:"body2",color:"text.secondary",children:"Enter the cost in cents (e.g., 50 = $0.50 per word)"})]})}),e.jsxs(be,{sx:{p:2,backgroundColor:"background.default"},children:[e.jsx(H,{onClick:T,disabled:a,children:"Cancel"}),e.jsx(H,{onClick:S,variant:"contained",disabled:a||!c||!u,startIcon:a?e.jsx(pe,{size:16}):null,color:"secondary",children:a?"Updating...":"Update Pricing"})]})]})},Qr=t=>De({queryKey:Z.getEstimationTimeframes(t).queryKey,queryFn:async()=>(await Z.getEstimationTimeframes(t).queryFn()).data.data,enabled:!!t}),Yr=t=>{const s=me();return le({mutationFn:async r=>(await Z.createEstimationTimeframe(t).queryFn(r)).data.data,onSuccess:()=>{s.invalidateQueries({queryKey:[Ee(se.GET_ESTIMATION_TIMEFRAMES)]})}})},Jr=t=>{const s=me();return le({mutationFn:async({id:r,data:a})=>(await Z.updateEstimationTimeframe(r,t).queryFn(a)).data.data,onSuccess:()=>{s.invalidateQueries({queryKey:[Ee(se.GET_ESTIMATION_TIMEFRAMES)]})}})},Zr=t=>{const s=me();return le({mutationFn:r=>Z.deleteEstimationTimeframe(r,t).queryFn(),onSuccess:()=>{s.invalidateQueries({queryKey:[Ee(se.GET_ESTIMATION_TIMEFRAMES)]})}})},Xr=t=>{const s=me();return le({mutationFn:()=>Z.seedDefaultTimeframes(t).queryFn(),onSuccess:()=>{s.invalidateQueries({queryKey:[Ee(se.GET_ESTIMATION_TIMEFRAMES)]})}})},en=({open:t,onClose:s})=>{const{getAccessToken:r}=ut(),a=r(),{data:l,isLoading:c}=Qr(a),g=Yr(a),u=Jr(a),x=Zr(a),v=Xr(a),[j,p]=d.useState(""),[b,F]=d.useState(""),[I,y]=d.use
1State(null),[P,k]=d.useState(""),[A,R]=d.useState(""),[S,T]=d.useState(""),z=ns.useMemo(()=>!l||!Array.isArray(l)?[]:[...l].sort((h,q)=>h.max_words-q.max_words),[l]),f=async()=>{try{T(""),await v.mutateAsync(),B.success("Default timeframes seeded successfully!")}catch{const h="Failed to seed default timeframes";T(h),B.error(h)}},O=async()=>{T("");const h=parseInt(j,10),q=parseInt(b,10);if(!j||!b){T("Please fill in all fields");return}if(isNaN(h)||h<=0){T("Days must be a positive integer");return}if(isNaN(q)||q<=0){T("Max words must be a positive integer");return}if(z.some(X=>X.max_words===q)){T(`A timeframe with ${q} max words already exists`);return}try{await g.mutateAsync({days:h,max_words:q}),B.success("Timeframe added successfully!"),p(""),F("")}catch{const X="Failed to add timeframe";T(X),B.error(X)}},D=h=>{y(h.id),k(h.days.toString()),R(h.max_words.toString()),T("")},o=()=>{y(null),k(""),R(""),T("")},C=async h=>{T("");const q=parseInt(P,10),X=parseInt(A,10);if(!P||!A){T("Please fill in all fields");return}if(isNaN(q)||q<=0){T("Days must be a positive integer");return}if(isNaN(X)||X<=0){T("Max words must be a positive integer");return}if(z.some(ee=>ee.max_words===X&&ee.id!==h)){T(`A timeframe with ${X} max words already exists`);return}try{await u.mutateAsync({id:h,data:{days:q,max_words:X}}),B.success("Timeframe updated successfully!"),y(null),k(""),R("")}catch{const ee="Failed to update timeframe";T(ee),B.error(ee)}},K=async h=>{if(window.confirm("Are you sure you want to delete this timeframe?"))try{T(""),await x.mutateAsync(h),B.success("Timeframe deleted successfully!")}catch{const q="Failed to delete timeframe";T(q),B.error(q)}},Q=()=>{y(null),k(""),R(""),p(""),F(""),T(""),s()},N=g.isPending||u.isPending||x.isPending||v.isPending;return e.jsxs(ve,{open:t,onClose:Q,maxWidth:"md",fullWidth:!0,children:[e.jsx(je,{sx:{backgroundColor:"primary.main",color:"primary.contrastText","& .MuiTypography-root":{color:"primary.contrastText"}},children:"Manage Estimation Timeframes"}),e.jsx(Ce,{sx:{mt:2},children:e.jsxs(_,{sx:{mt:2},children:[S&&e.jsx(ne,{severity:"error",sx:{mb:2},children:S}),e.jsxs(_,{sx:{mb:3,display:"flex",justifyContent:"flex-start"},children:[e.jsx(H,{variant:"outlined",color:"primary",onClick:f,disabled:N||z.length>0,startIcon:v.isPending?e.jsx(pe,{size:16}):e.jsx(Lt,{}),children:v.isPending?"Seeding...":"Seed Default Values"}),z.length>0&&e.jsx(E,{variant:"caption",color:"text.secondary",sx:{ml:2,alignSelf:"center"},children:"Timeframes already configured"})]}),e.jsx(E,{variant:"h6",sx:{mb:2,fontWeight:600},children:"Current Timeframes"}),c?e.jsx(_,{display:"flex",justifyContent:"center",py:4,children:e.jsx(pe,{})}):z.length>0?e.jsx(rs,{component:as,elevation:0,sx:{mb:3,border:h=>`1px solid ${h.palette.divider}`,borderRadius:2},children:e.jsxs(jt,{children:[e.jsx(wt,{children:e.jsxs(Pe,{sx:{backgroundColor:h=>$(h.palette.primary.main,.08)},children:[e.jsx(M,{sx:{fontWeight:600},children:"Up to Words"}),e.jsx(M,{sx:{fontWeight:600},children:"Estimated Days"}),e.jsx(M,{align:"right",sx:{fontWeight:600},children:"Actions"})]})}),e.jsx(St,{children:z.map(h=>e.jsxs(Pe,{sx:{"&:hover":{backgroundColor:q=>$(q.palette.primary.main,.03)}},children:[e.jsx(M,{children:I===h.id?e.jsx(re,{size:"small",type:"number",value:A,onChange:q=>R(q.target.value),inputProps:{min:1},fullWidth:!0}):e.jsxs(E,{variant:"body2",children:[h.max_words.toLocaleString()," words"]})}),e.jsx(M,{children:I===h.id?e.jsx(re,{size:"small",type:"number",value:P,onChange:q=>k(q.target.value),inputProps:{min:1},fullWidth:!0}):e.jsxs(E,{variant:"body2",children:[h.days," day",h.days!==1?"s":""]})}),e.jsx(M,{align:"right",children:I===h.id?e.jsxs(_,{sx:{display:"flex",justifyContent:"flex-end",gap:1},children:[e.jsx(te,{title:"Save",children:e.jsx(V,{size:"small",color:"success",onClick:()=>C(h.id),disabled:N,children:e.jsx(Be,{fontSize:"small"})})}),e.jsx(te,{title:"Cancel",children:e.jsx(V,{size:"small",color:"error",onClick:o,disabled:N,children:e.jsx(dt,{fontSize:"small"})})})]}):e.jsxs(_,{sx:{display:"flex",justifyContent:"flex-end",gap:1},children:[e.jsx(te,{title:"Edit",children:e.jsx(V,{size:"small",color:"primary",onClick:()=>D(h),disabled:N,children:e.jsx(Ha,{fontSize:"small"})})}),e.jsx(te,{title:"Delete",children:e.jsx(V,{size:"small",color:"error",onClick:()=>K(h.id),disabled:N,children:e.jsx(is,{fontSize:"small"})})})]})})]}
1,h.id))})]})}):e.jsx(ne,{severity:"info",sx:{mb:3},children:'No timeframes configured. Click "Seed Default Values" to add default timeframes.'}),e.jsx(Et,{sx:{backgroundColor:h=>$(h.palette.secondary.main,.05),border:h=>`1px solid ${$(h.palette.secondary.main,.2)}`,borderRadius:2},children:e.jsxs(Tt,{children:[e.jsx(E,{variant:"h6",sx:{mb:2,fontWeight:600},children:"Add New Timeframe"}),e.jsxs(_,{sx:{display:"flex",gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"stretch",sm:"flex-start"}},children:[e.jsx(re,{label:"Estimated Days",type:"number",value:j,onChange:h=>p(h.target.value),placeholder:"e.g., 5",size:"small",inputProps:{min:1},sx:{flex:1}}),e.jsx(re,{label:"Max Words",type:"number",value:b,onChange:h=>F(h.target.value),placeholder:"e.g., 5000",size:"small",inputProps:{min:1},sx:{flex:1}}),e.jsx(H,{variant:"contained",color:"secondary",onClick:O,disabled:N||!j||!b,startIcon:g.isPending?e.jsx(pe,{size:16}):e.jsx(Lt,{}),sx:{minWidth:120},children:g.isPending?"Adding...":"Add"})]}),e.jsx(E,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:'Define how many business days to estimate based on word count. Documents with word counts up to the "Max Words" value will be estimated at the specified number of days.'})]})})]})}),e.jsx(be,{sx:{p:2,backgroundColor:"background.default"},children:e.jsx(H,{onClick:Q,disabled:N,children:"Close"})})]})},tn=({isOpen:t,onClose:s,onConfirm:r,documentName:a,isLoading:l,staff:c,currentReviewer:g,externalReviewLink:u,existingExternalName:x,existingDeadline:v})=>{const[j,p]=d.useState(x?"external":"internal"),[b,F]=d.useState(g?.id||""),[I,y]=d.useState(x||""),[P,k]=d.useState(v?new Date(v):null),[A,R]=d.useState(!!v),[S,T]=d.useState(!1);d.useEffect(()=>{t&&(p(x?"external":"internal"),y(x||""),v?(k(new Date(v)),R(!0)):(k(null),R(!1)),F(g?.id||""),T(!1))},[t,x,v,g]),d.useEffect(()=>{T(!!(x&&I&&I!==x))},[I,x]),d.useEffect(()=>{j==="internal"?x||y(""):F("")},[j,x]);const z=()=>{if(j==="internal"&&!b||j==="external"&&!I)return;let D;if(A&&P){const o=P.getFullYear(),C=String(P.getMonth()+1).padStart(2,"0"),K=String(P.getDate()).padStart(2,"0");D=`${o}-${C}-${K}`}r(b,D,j==="external"?I:void 0)},f=()=>{k(null),R(!1),y(""),p("internal"),s()},O=()=>{u&&(navigator.clipboard.writeText(u),B.success("Link copied to clipboard!"))};return e.jsxs(ve,{open:t,onClose:f,maxWidth:"sm",fullWidth:!0,sx:{borderRadius:3},children:[e.jsxs(je,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",pb:2,borderBottom:"1px solid",borderBottomColor:"divider"},children:[e.jsxs(_,{sx:{display:"flex",alignItems:"center",flex:1,mr:2},children:[e.jsx(lt,{sx:{color:"primary.main",mr:1,fontSize:28}}),e.jsx(E,{variant:"h6",children:"Assign Reviewer"})]}),e.jsx(V,{onClick:f,size:"small",disabled:l,children:e.jsx(Ue,{})})]}),e.jsxs(Ce,{sx:{p:3},children:[e.jsxs(E,{variant:"body1",sx:{mb:2},children:["Assign reviewer for document: ",e.jsx("strong",{children:a})]}),x&&u&&e.jsxs(ne,{severity:"info",sx:{mb:3},children:[e.jsx(E,{variant:"body2",fontWeight:600,sx:{mb:1.5},children:"Share this link with Reviewer"}),e.jsxs(_,{sx:{display:"flex",alignItems:"center",gap:1,p:1.5,bgcolor:"background.paper",borderRadius:1,border:"1px solid",borderColor:"divider"},children:[e.jsx(E,{variant:"caption",sx:{wordBreak:"break-all",display:"block",fontFamily:"monospace",flex:1},children:u}),e.jsx(V,{onClick:O,size:"small",color:"primary",children:e.jsx(Kt,{})})]})]}),S&&e.jsxs(ne,{severity:"warning",sx:{mb:3},children:[e.jsx(E,{variant:"body2",fontWeight:600,sx:{mb:.5},children:"Reviewer Change Detected"}),e.jsx(E,{variant:"caption",children:"Changing the external reviewer will generate a new access link and invalidate the previous one."})]}),u&&!x&&e.jsxs(ne,{severity:"success",sx:{mb:3},children:[e.jsx(E,{variant:"body2",fontWeight:600,sx:{mb:1},children:"External Review Link Generated!"}),e.jsxs(_,{sx:{display:"flex",alignItems:"center",gap:1,mt:1,p:1.5,bgcolor:"background.paper",borderRadius:1},children:[e.jsx(E,{variant:"caption",sx:{wordBreak:"break-all",display:"block",fontFamily:"monospace",flex:1},children:u}),e.jsx(V,{onClick:O,size:"small",color:"primary",children:e.jsx(Kt,{})})]})]}),e.jsxs(_,{sx:{mt:3},children:[e.jsxs(ye,{component:"fieldset",sx:{mb:3},children:[e.jsx(E,{variant:"subtitle2",sx:{mb:1},children:"Reviewer Type"}),e.jsxs(Ar,{row:!0,value:j,onChange:D=>p(D.target.value),children:[e.jsx(bt,{value:"internal",control:e.jsx(Zt,{}),label:"Internal Staff",disabled:l}),e.jsx(bt,{value:"external",control:e.jsx(Zt,{}),label:"External Reviewer",disabled:l})]})]}),j==="internal"?e.jsxs(ye,{fullWidth:!0,sx:{mb:3},children:[e.jsx(Re,{children:"Staff Reviewer"}),e.jsx(_e,{value:b,onChange:D=>F(D.target.value),disabled:l,label:"Staff Reviewer",children:c.map(D=>e.jsx(ue,{value:D.id,children:D.email},D.id))})]}):e.jsx(re,{fullWidth:!0,label:"External Reviewer Name",type:"text",value:I,onChange:D=>y(D.target.value),disabled:l,placeholder:"John Doe",helperText:"Name of external reviewer (non-authenticated)",sx:{mb:3}}),e.jsx(bt,{control:e.jsx(Da,{checked:A,onChange:D=>R(D.target.checked),disabled:l}),label:"Set deadline for review"}),A&&e.jsx(_,{sx:{mt:2},children:e.jsx(ls,{dateAdapter:cs,children:e.jsx(ds,{label:"Deadline Date",value:P,onChange:D=>k(D),minDate:new Date,disabled:l,slotProps:{textField:{fullWidth:!0,size:"medium"}}})})})]})]}),e.jsxs(be,{sx:{p:3,pt:1},children:[e.jsx(H,{onClick:f,disabled:l,children:"Cancel"}),e.jsx(H,{onClick:z,variant:"contained",color:"primary",disabled:l||j==="internal"&&!b||j==="external"&&!I||A&&!P,startIcon:l?e.jsx(pe,{size:20}):e.jsx(lt,{}),children:l?"Assigning...":"Assign"})]})]})},sn=({isOpen:t,onClose:s,onConfirm:r,documentName:a,isLoading:l})=>{const[c,g]=d.useState(""),u=()=>{r(c.trim()||void 0)},x=()=>{g(""),s()};return e.jsxs(ve,{open:t,onClose:x,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2}},children:[e.jsxs(je,{sx:{p:3,pb:1,fontWeight:600},children:[e.jsx(_,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:"Cancel Document"}),e.jsx(V,{onClick:x,size:"small",disabled:l,children:e.jsx(Ue,{})})]}),e.jsxs(Ce,{sx:{p:3},children:[e.jsxs(E,{variant:"body1",sx:{mb:2},children:["Are you sure you want to cancel the document:"," ",e.jsx("strong",{children:a}),"?"]}),e.jsx(E,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This action cannot be undone. The document will be marked as cancelled and the customer will be notified."}),e.jsx(re,{fullWidth:!0,label:"Cancellation Reason (Optional)",multiline:!0,rows:3,value:c,onChange:v=>g(v.target.value),disabled:l,placeholder:"Enter the reason for cancelling this document...",helperText:"This reason will be visible to the customer"})]}),e.jsxs(be,{sx:{p:3,pt:1},children:[e.jsx(H,{onClick:x,disabled:l,children:"Keep Document"}),e.jsx(H,{onClick:u,variant:"contained",color:"error",disabled:l,startIcon:l?e.jsx(pe,{size:20}):e.jsx(dt,{}),children:l?"Cancelling...":"Cancel Document"})]})]})},an=({open:t,onClose:s,onSubmit:r,folderName:a,currentExtraFee:l,isLoading:c=!1})=>{const[g,u]=d.useState(l?(l/100).toString():""),[x,v]=d.useState("");d.useEffect(()=>{u(l?(l/100).toString():"")},[l]);const j=()=>{const b=parseFloat(g);if(isNaN(b)||b<0){v("Please enter a valid amount (0 or greater)");return}const F=Math.round(b*100);r(F)},p=()=>{u(l?(l/100).toString():""),v(""),s()};return e.jsxs(ve,{open:t,onClose:p,maxWidth:"sm",fullWidth:!0,children:[e.jsxs(je,{sx:{fontWeight:600},children:["Set Extra Fee",e.jsxs(E,{variant:"body2",color:"text.secondary",sx:{mt:1},children:["Folder: ",a]})]}),e.jsx(Ce,{children:e.jsxs(_,{sx:{mt:2},children:[e.jsx(re,{fullWidth:!0,label:"Extra Fee Amount (USD)",type:"number",value:g,onChange:b=>{u(b.target.value),v("")}
1,placeholder:"0.00",inputProps:{min:0,step:.01},helperText:"Enter the extra fee amount in USD (e.g., 25.50 for $25.50)",error:!!x}),x&&e.jsx(ne,{severity:"error",sx:{mt:2},children:x})]})}),e.jsxs(be,{sx:{p:3,pt:2},children:[e.jsx(H,{onClick:p,disabled:c,children:"Cancel"}),e.jsx(H,{onClick:j,variant:"contained",disabled:c,sx:{minWidth:120},children:c?"Setting...":"Set Extra Fee"})]})]})},rn=({isOpen:t,onClose:s,onSuccess:r,onSubmit:a,isLoading:l=!1})=>{const c=ct(),{getAccessToken:g}=ut(),u=g(),[x,v]=d.useState(""),[j,p]=d.useState(""),[b,F]=d.useState(""),[I,y]=d.useState(""),[P,k]=d.useState(""),[A,R]=d.useState([]),[S,T]=d.useState([]),[z,f]=d.useState(null),[O,D]=d.useState(""),[o,C]=d.useState(!1),{data:K,isLoading:Q}=De({...Z.getOrganizations(u),enabled:!!u&&t}),{data:N}=De({...Z.getLanguages(u),enabled:!!u&&t}),h=K?.data||[],q=N?.data||[],ee=h.find(w=>(w._id||w.id)===x)?.departments||[],we=d.useCallback(w=>{T(U=>[...U,...w]),C(!1),D("")},[]),{getRootProps:ce,getInputProps:Fe}=ka({onDrop:we,accept:{"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[".docx"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":[".pptx"],"application/pdf":[".pdf"],"text/html":[".html"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"]},maxFiles:40,onDragEnter:()=>C(!0),onDragLeave:()=>C(!1)}),oe=w=>{T(U=>U.filter((xe,$e)=>$e!==w))},Ne=()=>{v(""),p(""),F(""),y(""),k(""),R([]),T([]),f(null),D("")},ie=()=>{Ne(),s()},pt=()=>{if(!x)return D("Please select an organization"),!1;if(!j)return D("Please select a department"),!1;if(!b||b.trim().length<3)return D("Requester name must be at least 3 characters"),!1;if(!I||I.trim().length<3)return D("Folder name must be at least 3 characters"),!1;if(!P)return D("Please select a source language"),!1;if(A.length===0)return D("Please select at least one target language"),!1;if(A.length>10)return D("Maximum 10 target languages allowed"),!1;if(S.length===0)return D("Please upload at least one file"),!1;if(S.length>40)return D("Maximum 40 files allowed"),!1;const w=S.length*A.length;return w>40?(D(`Total documents (${w}) exceeds limit of 40. Reduce files or target languages.`),!1):(D(""),!0)},He=async()=>{if(!pt())return;const w=new FormData;w.append("organization_id",x),w.append("department",j),w.append("requester_name",b),w.append("name",I),w.append("source_language",P),A.forEach(U=>{w.append("target_languages[]",U)}),z&&w.append("requested_deadline",z.toISOString()),S.forEach(U=>{w.append("files",U),w.append("file_names[]",U.name)});try{await a(w),Ne(),r()}catch(U){D(U instanceof Error?U.message:"Failed to create folder")}},mt=x&&j&&b.trim().length>=3&&I.trim().length>=3&&P&&A.length>0&&S.length>0;return e.jsxs(ve,{open:t,onClose:ie,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:2,maxHeight:"90vh"}},children:[e.jsx(je,{sx:{borderBottom:`1px solid ${c.palette.divider}`},children:e.jsxs(_,{display:"flex",alignItems:"center",justifyContent:"space-between",children:[e.jsx(E,{variant:"h6",fontWeight:600,children:"Create Project for Organization"}),e.jsx(V,{onClick:ie,size:"small",children:e.jsx(Ue,{})})]})}),e.jsxs(Ce,{sx:{mt:2},children:[O&&e.jsx(ne,{severity:"error",sx:{mb:2},onClose:()=>D(""),children:O}),e.jsx(Qt,{fullWidth:!0,value:h.find(w=>(w._id||w.id)===x)||null,onChange:(w,U)=>{const xe=U?._id||U?.id||"";v(xe),p("")},options:h,getOptionLabel:w=>w.name,isOptionEqualToValue:(w,U)=>(w._id||w.id)===(U._id||U.id),loading:Q,renderInput:w=>e.jsx(re,{...w,label:"Organization *",placeholder:"Select organization"}),sx:{mb:2}}),e.jsxs(ye,{fullWidth:!0,sx:{mb:2},disabled:!x,children:[e.jsx(Re,{children:"Department *"}),e.jsx(_e,{value:j,onChange:w=>p(w.target.value),label:"Department *",children:ee.map(w=>e.jsx(ue,{value:w,children:w},w))})]}),e.jsx(re,{fullWidth:!0,label:"Requester Name *",value:b,onChange:w=>F(w.target.value),placeholder:"e.g., John Smith - Marketing Director",helperText:"Name of the person requesting the translation",sx:{mb:2}}),e.jsx(re,{fullWidth:!0,label:"Project Name *",value:I,onChange:w=>y(w.target.value),placeholder:"e.g., Legal Documents Q1 2024",helperText:"Minimum 3 characters",sx:{mb:2}}),e.jsxs(ye,{fullWidth:!0,sx:{mb:2},children:[e.jsx(Re,{children:"Source Language *"}),e.jsx(_e,{value:P,onChange:w=>k(w.target.value),label:"Source Language *",children:q.map(w=>e.jsx(ue,{value:w.key,children:w.description},w.key))})]}),e.jsxs(ye,{fullWidth:!0,sx:{mb:2},children:[e.jsx(Qt,{multiple:!0,value:q.filter(w=>A.includes(w.key)),onChange:(w,U)=>{R(U.map(xe=>xe.key))},options:q.filter(w=>w.key!==P),getOptionLabel:w=>w.description,renderInput:w=>e.jsx(re,{...w,label:"Target Languages *",placeholder:"Select target languages"}),renderTags:(w,U)=>w.map((xe,$e)=>e.jsx(fe,{label:xe.description,...U({index:$e}),size:"small"}))}),e.jsx(E,{variant:"caption",color:"text.secondary",sx:{mt:.5},children:"Select 1-10 target languages"})]}),e.jsxs(_,{sx:{mb:2},children:[e.jsx(ir,{children:e.jsx(fe,{label:"Translation: Human + AI",icon:e.jsx(Be,{}),color:"success",sx:{fontWeight:500}})}),e.jsx(E,{variant:"caption",color:"text.secondary",sx:{ml:1},children:"Admin projects always use Human + AI translation"})]}),e.jsx(_,{sx:{mb:2},children:e.jsx(ls,{dateAdapter:cs,children:e.jsx(ds,{label:"Requested Deadline",value:z,onChange:w=>f(w),minDate:new Date,slotProps:{textField:{fullWidth:!0,size:"medium",helperText:"Optional â select a deadline for this project"}}})})}),e.jsxs(_,{sx:{mb:2},children:[e.jsx(E,{variant:"subtitle2",gutterBottom:!0,children:"Upload Files * (Max 40 files)"}),e.jsxs(_,{...ce(),sx:{border:`2px dashed ${o?c.palette.primary.main:c.palette.divider}`,borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:o?$(c.palette.primary.main,.05):"transparent",transition:"all 0.2s","&:hover":{bgcolor:$(c.palette.primary.main,.02),borderColor:c.palette.primary.main}},children:[e.jsx("input",{...Fe()}),e.jsx(Xa,{sx:{fontSize:48,color:c.palette.text.secondary,mb:1}}),e.jsx(E,{variant:"body1",gutterBottom:!0,children:o?"Drop files here...":"Drag & drop files here, or click to browse"}),e.jsxs(E,{variant:"caption",color:"text.secondary",children:["Supported: ",Za.join(", ")
1]})]})]}),S.length>0&&e.jsxs(_,{sx:{mb:2},children:[e.jsxs(E,{variant:"subtitle2",gutterBottom:!0,children:["Files (",S.length,")"]}),e.jsx(Ia,{dense:!0,sx:{maxHeight:200,overflow:"auto",bgcolor:c.palette.background.default,borderRadius:1},children:S.map((w,U)=>e.jsxs(Ya,{children:[e.jsx(er,{primary:w.name,secondary:`${(w.size/1024).toFixed(2)} KB`}),e.jsx(Ja,{children:e.jsx(V,{edge:"end",onClick:()=>oe(U),size:"small",children:e.jsx(is,{fontSize:"small"})})})]},U))})]}),S.length>0&&A.length>0&&e.jsxs(ne,{severity:"info",sx:{mb:2},children:["Total documents to create:"," ",e.jsx("strong",{children:S.length*A.length}),S.length*A.length>40&&e.jsx(E,{color:"error",variant:"body2",children:"â ï¸ Exceeds maximum of 40 documents"})]})]}),e.jsxs(be,{sx:{p:2,borderTop:`1px solid ${c.palette.divider}`},children:[e.jsx(H,{onClick:ie,disabled:l,children:"Cancel"}),e.jsx(H,{onClick:He,variant:"contained",disabled:!mt||l,startIcon:l?e.jsx(pe,{size:20}):e.jsx(Be,{}),children:l?"Creating...":"Create Project"})]})]})},nn=(t,s)=>{const r=me(),{data:a,isLoading:l,isError:c,refetch:g}=De({...Z.getFolderInvoices(t,s),enabled:!!t&&!!s}),u=a?.data||[],x=le({mutationFn:Z.createFolderInvoice(t).queryFn,onSuccess:()=>{B.success("Invoice created successfully!"),r.invalidateQueries({queryKey:[Ee(se.GET_FOLDER_INVOICES)]}),s&&r.invalidateQueries({queryKey:[Ee(se.GET_FOLDER_INVOICES),s]})},onError:b=>{B.error(b?.message||"Failed to create invoice")}}),v=le({mutationFn:b=>Z.deleteFolderInvoice(b,t).queryFn(),onSuccess:()=>{B.success("Invoice deleted successfully!"),r.invalidateQueries({queryKey:[Ee(se.GET_FOLDER_INVOICES)]})},onError:b=>{B.error(b?.message||"Failed to delete invoice")}});return{invoices:u,isLoading:l,isError:c,refetch:g,createInvoice:b=>x.mutateAsync(b),deleteInvoice:async b=>{await v.mutateAsync(b)},isCreating:x.isPending,isDeleting:v.isPending}},on=({open:t,onClose:s,onSubmit:r,folder:a,organizations:l,isLoading:c=!1})=>{const g=ct(),[u,x]=d.useState(""),[v,j]=d.useState("");d.useEffect(()=>{t&&(x(""),j(""))},[t]);const p=async()=>{if(a){if(!u){j("Please select an organization");return}try{await r({organization_id:u,folder_id:a.id,department:""})}catch(I){console.error("Error creating invoice:",I)}}},b=()=>{x(""),j(""),s()},F=I=>I._id||I.id||"";return a?e.jsxs(ve,{open:t,onClose:b,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2}},children:[e.jsxs(je,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",pb:2,fontWeight:600},children:["Create Invoice for Project",e.jsx(V,{onClick:b,size:"small",sx:{color:g.palette.grey[500],"&:hover":{backgroundColor:g.palette.grey[100]}},children:e.jsx(Ue,{})})]}),e.jsx(Ce,{sx:{pt:0},children:e.jsxs(_,{sx:{display:"flex",flexDirection:"column",gap:3},children:[e.jsxs(ne,{severity:"info",sx:{mb:1},children:["Create an invoice for the project ",e.jsxs("strong",{children:['"',a.name,'"']}),". This will generate an invoice based on the folder's documents and costs."]}),e.jsxs(_,{children:[e.jsx(E,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:"Project Details:"}),e.jsx(E,{variant:"body1",fontWeight:500,children:a.name}),e.jsxs(E,{variant:"body2",color:"text.secondary",children:[a.documents?.length||0," document(s)"]}),a.customer&&e.jsxs(E,{variant:"body2",color:"text.secondary",children:["Customer: ",a.customer.fullName]})]}),e.jsxs(ye,{fullWidth:!0,error:!!v,children:[e.jsx(Re,{children:"Select Organization"}),e.jsx(_e,{value:u,onChange:I=>{x(I.target.value),j("")},label:"Select Organization",disabled:c,children:l.length===0?e.jsx(ue,{disabled:!0,children:"No organizations available"}):l.map(I=>e.jsx(ue,{value:F(I),children:I.name},F(I)))}),v&&e.jsx(E,{variant:"caption",color:"error",sx:{mt:.5},children:v})]})]})}),e.jsxs(be,{sx:{p:3,pt:2},children:[e.jsx(H,{onClick:b,disabled:c,sx:{color:g.palette.grey[600],"&:hover":{backgroundColor:g.palette.grey[100]}},children:"Cancel"}),e.jsx(H,{onClick:p,variant:"contained",disabled:c||!u,sx:{backgroundColor:g.palette.primary.main,"&:hover":{backgroundColor:g.palette.primary.dark}},children:c?"Creating...":"Create Invoice"})]})]}):null},ln=({isOpen:t,onClose:s,onConfirm:r,folderName:a,documentCount:l,completableCount:c,isLoading:g})=>{const u=l-c;return e.jsxs(ve,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2}},children:[e.jsx(je,{sx:{p:3,pb:1,fontWeight:600},children:e.jsxs(_,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:["Complete All Documents",e.jsx(V,{onClick:s,size:"small",disabled:g,children:e.jsx(Ue,{})})]})}),e.jsxs(Ce,{sx:{p:3},children:[e.jsxs(E,{variant:"body1",sx:{mb:2},children:["Are you sure you want to complete all documents in the project:"," ",e.jsx("strong",{children:a}),"?"]}),e.jsx(ne,{severity:"info",sx:{mb:2},children:e.jsxs(E,{variant:"body2",children:[e.jsx("strong",{children:c})," document",c!==1?"s":""," will be marked as completed.",u>0&&e.jsxs(e.Fragment,{children:[" ",e.jsx("strong",{children:u})," document",u!==1?"s":""," will be skipped (already completed, cancelled, or failed)."]})]})}),e.jsx(E,{variant:"body2",color:"text.secondary",children:"The customer will be notified by email once all documents in this project are completed."})]}),e.jsxs(be,{sx:{p:3,pt:1},children:[e.jsx(H,{onClick:s,disabled:g,children:"Cancel"}),e.jsx(H,{onClick:r,variant:"contained",color:"success",disabled:g||c===0,startIcon:g?e.jsx(pe,{size:20}):e.jsx(Be,{}),children:g?"Completing...":"Complete All Documents"})]})]})},cn=({isOpen:t,onClose:s,onConfirm:r,folderName:a,documentCount:l,isLoading:c})=>e.jsxs(ve,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2}},children:[e.jsx(je,{sx:{p:3,pb:1,fontWeight:600},children:e.jsxs(_,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:["Delete Project",e.jsx(V,{onClick:s,size:"small",disabled:c,
1children:e.jsx(Ue,{})})]})}),e.jsxs(Ce,{sx:{p:3},children:[e.jsxs(E,{variant:"body1",sx:{mb:2},children:["Are you sure you want to delete the project:"," ",e.jsx("strong",{children:a}),"?"]}),e.jsx(ne,{severity:"warning",sx:{mb:2},children:e.jsxs(E,{variant:"body2",children:["This project contains ",e.jsx("strong",{children:l})," failed document",l!==1?"s":"",". The project will be marked as deleted and will no longer appear in active views."]})}),e.jsx(E,{variant:"body2",color:"text.secondary",children:"This action marks the project as deleted. The data will be retained for record-keeping purposes."})]}),e.jsxs(be,{sx:{p:3,pt:1},children:[e.jsx(H,{onClick:s,disabled:c,children:"Cancel"}),e.jsx(H,{onClick:r,variant:"contained",color:"error",disabled:c,startIcon:c?e.jsx(pe,{size:20}):e.jsx(tt,{}),children:c?"Deleting...":"Delete Project"})]})]}),dn=t=>{const s=me();return le({mutationFn:async({folderId:r})=>await(await Z.completeAllDocuments(r,t)).queryFn(),onSuccess:()=>{s.invalidateQueries({queryKey:se.GET_DOCUMENTS}),s.invalidateQueries({queryKey:["getAdminFolders"]}),s.invalidateQueries({queryKey:["getFolders"]}),s.invalidateQueries({queryKey:se.GET_DOCUMENT_SUMMARY}),s.invalidateQueries({queryKey:["getFolderSummary"]})}})},un=t=>{const s=me();return le({mutationFn:async({folderId:r})=>await(await Z.deleteFolder(r,t)).queryFn(),onSuccess:()=>{s.invalidateQueries({queryKey:["getAdminFolders"]}),s.invalidateQueries({queryKey:["getFolders"]}),s.invalidateQueries({queryKey:["getFolderSummary"]}),s.invalidateQueries({queryKey:se.GET_DOCUMENTS}),s.invalidateQueries({queryKey:se.GET_DOCUMENT_SUMMARY})}})};function qn(){const t=ct(),{getAccessToken:s}=ut(),r=Fa(),a=me(),[l,c]=Pa(),[g,u]=d.useState(!1),[x,v]=d.useState(!1),[j,p]=d.useState(!1),[b,F]=d.useState(!1),[I,y]=d.useState(!1),[P,k]=d.useState(!1),[A,R]=d.useState(null),[S,T]=d.useState(null),[z,f]=d.useState(null),[O,D]=d.useState(!1),[o,C]=d.useState(null),[K,Q]=d.useState(!1),[N,h]=d.useState(null),[q,X]=d.useState(!1),[ee,we]=d.useState(null),[ce,Fe]=d.useState({status:"",folderName:"",userEmail:""}),[oe,Ne]=d.useState(qa),[ie,pt]=d.useState("folders"),[He,mt]=d.useState("folders"),[w,U]=d.useState(""),[xe,$e]=d.useState(""),Qe=parseInt(l.get("page")||"1",10),Ft=parseInt(l.get("limit")||"5",10),xt=Vt(w,500),gt=Vt(xe,500),hs=[{value:"",label:"All Status"},{value:"awaiting_translation",label:"Awaiting Translation"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"},{value:"review_pending",label:"Review Pending"},{value:"in_review",label:"In Review"},{value:"created",label:"Created"},{value:"cancelled",label:"Cancelled"}],{organizations:ht,isOrganizationsLoading:fs}=os(s()),ys=d.useMemo(()=>({dateFrom:oe.dateFrom?Ht(oe.dateFrom,"yyyy-MM-dd"):void 0,dateTo:oe.dateTo?Ht(oe.dateTo,"yyyy-MM-dd"):void 0,organizationIds:oe.organizationIds.length>0?oe.organizationIds.join(","):void 0}),[oe]),{data:vs,isLoading:Cs,isError:bs}=De({...Z.getDocumentSummary(s())}),{data:ft,isLoading:js,isError:ws}=za(s()),{staff:Ye}=Ma(s()),{useAdminFolders:Ss,updateFolderExtraFeeMutation:Pt}=Vr(s()),At=Qa(s()),Rt=Kr(s()),_t=dn(s()),kt=un(s()),{invoices:zt}=tr(s(),{},1,1e4),Es=d.useMemo(()=>{const n=new Map;for(const i of zt)i.folder_id&&n.set(i.folder_id,i);return n},[zt]),{createInvoice:Ts,isCreating:Ds}=nn(s(),void 0),Je=n=>{let i=Xe?.find(W=>W.id===n);if(!i&&ae?.folders)for(const W of ae.folders){const Y=W.documents?.find(ge=>ge.id===n);if(Y){i=Y;break}}if(i){if(T({id:n,name:i.file_name,reviewer:i.reviewer,external_reviewer_name:i.external_reviewer_name,external_review_token:i.external_review_token,deadline_date:i.deadline_date}),i.external_review_token){const Y=`${window.location.origin}/external-review/${n}/${i.external_review_token}`;R(Y)}else R(null);F(!0)}},Is=async(n,i,W)=>{if(S)try{const Y=await At.mutateAsync({documentId:S.id,reviewerId:n,deadlineDate:i,externalName:W});if(Y&&typeof Y=="object"&&"data"in Y&&Y.data&&typeof Y.data=="object"&&"link"in Y.data){const ge=Y.data;R(ge.link),T({...S,external_reviewer_name:ge.external_reviewer_name,external_review_token:ge.token,deadline_date:i}
1),B.success("External reviewer assigned successfully! Link generated.")}else B.success("Reviewer assigned successfully!"),F(!1),T(null),R(null)}catch(Y){he.error("Error assigning reviewer:",Y),B.error("Failed to assign reviewer. Please try again.")}},Ze=n=>{const i=Xe?.find(W=>W.id===n);i&&(T({id:n,name:i.file_name,reviewer:i.reviewer}),y(!0))},Fs=(n,i)=>{const W=ae?.folders?.find(Y=>Y.id===n);W&&(f({id:W.id,name:W.name,extra_fee_amount_cents:i}),k(!0))},Ps=async n=>{if(z)try{await Pt.mutateAsync({folderId:z.id,data:{extra_fee_amount_cents:n}}),B.success("Extra fee updated successfully!"),k(!1),f(null)}catch(i){he.error("Error updating extra fee:",i);const W=i instanceof Error?i.message:"Failed to update extra fee. Please try again.";B.error(W)}},As=n=>{C(n),D(!0)},Rs=async n=>{try{const i=ht.find(W=>(W._id||W.id)===n.organization_id);await Va(n,{organizationName:i?.name||"Unknown",logoUrl:"/assets/Icon_Color.png"})}catch(i){he.error("Failed to export PDF:",i),B.error("Failed to export invoice PDF. Please try again.")}},_s=async n=>{try{await Ts(n),B.success("Invoice created successfully!"),D(!1),C(null),a.invalidateQueries({queryKey:["getAdminInvoices"]})}catch(i){he.error("Error creating invoice:",i),B.error("Failed to create invoice. Please try again.")}},ks=n=>{h(n),Q(!0)},zs=async()=>{if(N)try{const i=(await _t.mutateAsync({folderId:N.id}))?.data;if(i?.failed_count&&i.failed_count>0)B.warning(`Completed ${i.completed_count} documents. ${i.failed_count} failed. ${i.skipped_count} skipped.`);else{const W=i?.completed_count||0;B.success(`${W} document${W!==1?"s":""} completed successfully!`)}Q(!1),h(null)}catch(n){he.error("Error completing all documents:",n),B.error("Failed to complete documents. Please try again.")}},Ms=n=>{we(n),X(!0)},Os=async()=>{if(ee)try{await kt.mutateAsync({folderId:ee.id}),B.success("Project deleted successfully!"),X(!1),we(null)}catch(n){he.error("Error deleting folder:",n),B.error("Failed to delete project. Please try again.")}},Ns=async n=>{if(S)try{await Rt.mutateAsync({documentId:S.id,cancellation_reason:n}),B.success("Document cancelled successfully!"),y(!1),T(null)}catch(i){he.error("Error cancelling document:",i),B.error("Failed to cancel document. Please try again.")}},Mt=le({mutationFn:async n=>await Z.updatePricingConfig(s()).queryFn(n),onSuccess:()=>{B.success("Pricing configuration updated successfully!"),a.invalidateQueries({queryKey:[Z.getDocumentSummary(s()).queryKey]}),a.invalidateQueries({queryKey:[se.GET_PRICING_CONFIG]})},onError:()=>{B.error("Failed to update pricing configuration")}}),Ot=le({mutationFn:async n=>await Z.createFolderByAdmin(s()).queryFn(n),onSuccess:()=>{B.success("Project created successfully!"),p(!1),a.invalidateQueries({queryKey:["getAdminFolders"]}),a.invalidateQueries({queryKey:[se.GET_FOLDER_SUMMARY]})},onError:n=>{const i=n?.message||"Failed to create project";B.error(i),he.error("Failed to create folder by admin:",n)}}),$s=async n=>{await Ot.mutateAsync(n)},Ws=async(n,i,W)=>{await Mt.mutateAsync({translationType:n,costPerWordCents:i,organizationId:W})},{currentPage:Ls,totalPages:Bs,total:qs,limit:Us,canGoNext:Gs,canGoPrev:Vs,goToPage:Ge,goToNextPage:Ks,goToPrevPage:Hs,goToFirstPage:Qs,goToLastPage:Ys,setLimit:Js,data:Xe,isFetching:Zs}=Aa({initialPage:1,initialLimit:5,queryConfig:(n,i,W)=>Z.getDocuments(n,i,W,ce.status),queryArgs:[s()],dataKey:"documents",filters:ce}),{data:ae,isLoading:Xs,isError:ea}=Ss(Qe,Ft,ce.status,ce.folderName,ce.userEmail,ys),Nt=d.useCallback(()=>{Fe(n=>((n.folderName!==xt||n.userEmail!==gt)&&(Ge(1),c(W=>(W.set("page","1"),W))),{...n,folderName:xt,userEmail:gt}))},[xt,gt,Ge,c]);d.useEffect(()=>{Nt()},[Nt]);const ta=n=>{c(i=>(i.set("page",n.toString()),i))},sa=()=>{ae?.hasNext&&c(n=>(n.set("page",(Qe+1).toString()),n))},aa=()=>{ae?.hasPrev&&c(n=>(n.set("page",(Qe-1).toString()),n))},ra=()=>{c(n=>(n.set("page","1"),n))},na=()=>{ae?.totalPages&&c(n=>(n.set("page",ae.totalPages.toString()),n))},oa=n=>{c(i=>(i.set("limit",n.toString()),i.set("page","1"),i))},$t=()=>{if(!ae?.folders)return[];const n=[];return ae.folders.forEach(i=>
1{i.documents&&i.documents.length>0&&i.documents.forEach(W=>{n.push({...W,folder_name:i.name,folder_id:i.id})})}),n},ia={awaiting_translation:0,completed:0,completed_by_staff:0,failed:0,review_pending:0,in_review:0,created:0,cancelled:0},{tableHeaders:Wt,statisticsCards:la,tableRows:ca}=Gr({statistics:vs?.data||ia,documents:Xe,theme:t,navigate:r,staff:Ye,onUpdateReviewer:Je,onCancelDocument:Ze}),da=Wt.filter(n=>n.key!=="requested_deadline"&&n.key!=="date"),ua=()=>$t().map(i=>{const W=nt(i.status,t),Y=[],ge=i.status===m.REVIEW_PENDING||i.status===m.IN_REVIEW;Ye&&Je&&Y.push({icon:lt,backgroundColor:t.palette.primary.main,textColor:t.palette.common.white,hoverBackgroundColor:$(t.palette.primary.main,.8),size:"small",onClick:()=>{ge&&Je(i.id)},disabled:!ge,tooltip:ge?"Assign Reviewer":"Document not in review status"});const ma=i.status!==m.COMPLETED&&i.status!==m.CANCELLED&&i.status!==m.FAILED&&i.status!==m.COMPLETED_BY_STAFF;return Ze&&ma&&Y.push({icon:dt,backgroundColor:t.palette.error.main,textColor:t.palette.common.white,hoverBackgroundColor:$(t.palette.error.main,.8),size:"small",onClick:()=>{Ze(i.id)},disabled:!1,tooltip:"Cancel Document"}),Y.push({icon:rt,backgroundColor:t.palette.info.main,textColor:t.palette.common.white,hoverBackgroundColor:$(t.palette.info.main,.8),size:"small",onClick:()=>{const et=i.file_extension?.toLowerCase(),Ve=i.file_type?.toLowerCase();r(et===".html"||Ve==="text/html"||Ve==="html"?ot.ADMIN_HTML_EDITOR(i.id):et===".docx"||et===".xlsx"||et===".pptx"||Ve==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"||Ve==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"||Ve==="application/vnd.openxmlformats-officedocument.presentationml.presentation"?ot.ADMIN_DOCUMENT_EDIT(i.id):`/documents/${i.id}`)},disabled:i.status===m.CREATED,tooltip:i.status===m.CREATED?"Cannot view document in created status":"View Document"}),{id:i.id,document:i.file_name,user:i.customer?.fullName||"-",languages:`${i.source_language} â ${i.target_language}`,type:i.translation_type||"-",status:W.title,badgeConfig:{backgroundColor:W.backgroundColor,textColor:W.iconColor,size:"small"},reviewer:i.reviewer?.fullName||"Not Assigned",deadline:i.deadline_date?new Date(i.deadline_date).toLocaleDateString():"-",price:i.payment_amount_cents?`$${(i.payment_amount_cents/100).toFixed(2)}`:"-",folder_name:i.folder_name||"-",actions:"",multipleButtonsConfig:Y}}),pa=[{key:"paid",icon:Be,value:ft?.data?.paid||0,title:"Paid Folders",iconColor:t.palette.success.main,tooltip:"Number of folders paid by non-premium customers. Note: Some documents in these folders may have failed during the process."},{key:"pending_automatic",icon:Oa,value:ft?.data?.pending_automatic||0,title:"Pending",iconColor:t.palette.warning.main,tooltip:"Non-premium customers who have not yet paid to start the translation process."},{key:"refunded",icon:Wr,value:ft?.data?.refunded||0,title:"Refunded",iconColor:t.palette.error.main,tooltip:"The value of all folders has initiated the refund process."}];return Zs||Cs||js||ie==="folders"&&Xs?e.jsx(Ra,{}):bs||ws||ie==="folders"&&ea?e.jsx(_a,{}):e.jsxs("div",{children:[e.jsxs(_,{sx:{py:2},children:[e.jsx(E,{variant:"h6",sx:{fontWeight:600,color:t.palette.text.primary,mb:2,px:4},children:"Document Status Summary"}),e.jsx(Gt,{statusItems:la.map(n=>({key:n.key,icon:n.icon,value:n.value,title:n.title,iconColor:n.iconColor,tooltip:n.tooltip})),variant:"minimal"})]}),e.jsxs(_,{sx:{py:2},children:[e.jsx(E,{variant:"h6",sx:{fontWeight:600,color:t.palette.text.primary,mb:2,px:4},children:"Project Payment Summary"}),e.jsx(Gt,{statusItems:pa.map(n=>({key:n.key,icon:n.icon,value:n.value,title:n.title,iconColor:n.iconColor,tooltip:n.tooltip})),variant:"minimal"})]}),e.jsx(Ua,{filters:oe,onFiltersChange:Ne,organizations:ht,isOrganizationsLoading:fs}),e.jsx(_,{bgcolor:t.palette.background.paper,p:2,mx:4,mb:3,borderRadius:2,border:`1px solid ${t.palette.grey[200]}`,children:e.jsxs(Bt,{direction:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:2,children:[e.jsxs(Bt,{direction:"row",alignItems:"center",gap:2,flexWrap:"wrap",children:[e.jsxs($r,{value:ie==="folders"?He:ie,exclusive:!0,onChange:(n,i)=>{i!==null&&(ie==="folders"?mt(i):pt(i))},size:"small",children:[e.jsxs(Xt,{value:"folders",children:[e.jsx(Dt,{sx:{mr:1}}),"Projects"]}),e.jsxs(Xt,{value:"list",children:[e.jsx(qr,{sx:{mr:1}}),"List"]})]}),e.jsxs(ye,{size:"small",sx:{minWidth:200},children:[e.jsx(Re,{children:"Status"}),e.jsx(_e,{value:ce.status,onChange:n=>{Fe({...ce,status:n.target.value}),Ge(1),c(i=>(i.set("page","1"),i))},label:"Status",children:hs.map(n=>e.jsx(ue,{value:n.value,children:n.label},n.value))})]}),ie==="folders"&&e.jsx(re,{size:"small",label:"Project Name",value:w,onChange:n=>{U(n.target.value)},sx:{minWidth:200}}),ie==="folders"&&e.jsx(re,{size:"small",label:"User Email",value:xe,onChange:n=>{$e(n.target.value)},sx:{minWidth:200}}),e.jsx(H,{variant:"outlined",sx:{minWidth:140,height:40,borderColor:t.palette.primary.main,color:t.palette.primary.main,"&:hover":{backgroundColor:t.palette.primary.main,color:t.palette.primary.contrastText,borderColor:t.palette.primary.main}},onClick:()=>{Fe({status:"",folderName:"",userEmail:""}),U(""),$e(""),Ge(1),c(n=>(n.set("page","1"),n))},startIcon:e.jsx("span",{style:{fontWeight:700,fontSize:18},children:"Ã"}),children:"Clear Filters"})]}),e.jsx(H,{variant:"contained",startIcon:e.jsx(Dt,{}),onClick:()=>p(!0),color:"primary",sx:{minWidth:180,height:40},children:"Create Project"}),e.jsx(H,{variant:"contained",startIcon:e.jsx(es,{}),onClick:()=>u(!0),color:"secondary",sx:{minWidth:180,height:40},children:"Pricing Configuration"}),e.jsx(H,{variant:"contained",startIcon:e.jsx(es,{}),onClick:()=>v(!0),color:"secondary",sx:{minWidth:180,height:40},children:"Estimation Timeframes"})]})}),e.jsx(_,{sx:{p:4},children:ie==="folders"?He==="folders"?e.jsxs(e.Fragment,{children:[e.jsx(Ur,{folders:ae?.folders||[],navigate:r,staff:Ye,onUpdateReviewer:Je,onCancelDocument:Ze,onSetExtraFee:Fs,onCreateInvoice:As,onViewInvoice:Rs,onCompleteAllDocuments:ks,onDeleteFolder:Ms,folderInvoices:Es}),e.jsx(qt,{currentPage:Qe,totalPages:ae?.totalPages||1,total:ae?.total||0,limit:Ft,canGoNext:ae?.hasNext||!1,canGoPrev:ae?.hasPrev||!1,goToPage:ta,goToNextPage:sa,goToPrevPage:a
1a,goToFirstPage:ra,goToLastPage:na,setLimit:oa})]}):e.jsx(Ut,{title:`Project Documents (${$t().length})`,columns:da,data:ua()}):e.jsxs(e.Fragment,{children:[e.jsx(Ut,{title:`All Documents (${Xe.length})`,columns:Wt,data:ca}),e.jsx(qt,{currentPage:Ls,totalPages:Bs,total:qs,limit:Us,canGoNext:Gs,canGoPrev:Vs,goToPage:Ge,goToNextPage:Ks,goToPrevPage:Hs,goToFirstPage:Qs,goToLastPage:Ys,setLimit:Js})]})}),e.jsx(Hr,{open:g,onClose:()=>u(!1),onSubmit:Ws,isLoading:Mt.isPending}),e.jsx(en,{open:x,onClose:()=>v(!1)}),e.jsx(rn,{isOpen:j,onClose:()=>p(!1),onSuccess:()=>{p(!1)},onSubmit:$s,isLoading:Ot.isPending}),e.jsx(tn,{isOpen:b,onClose:()=>{F(!1),T(null),R(null)},onConfirm:Is,documentName:S?.name||"",isLoading:At.isPending,staff:Ye||[],currentReviewer:S?.reviewer,externalReviewLink:A,existingExternalName:S?.external_reviewer_name,existingDeadline:S?.deadline_date}),e.jsx(sn,{isOpen:I,onClose:()=>{y(!1),T(null)},onConfirm:Ns,documentName:S?.name||"",isLoading:Rt.isPending}),e.jsx(an,{open:P,onClose:()=>{k(!1),f(null)},onSubmit:Ps,folderName:z?.name||"",currentExtraFee:z?.extra_fee_amount_cents,isLoading:Pt.isPending}),e.jsx(on,{open:O,onClose:()=>{D(!1),C(null)},onSubmit:_s,folder:o,organizations:ht,isLoading:Ds}),e.jsx(ln,{isOpen:K,onClose:()=>{Q(!1),h(null)},onConfirm:zs,folderName:N?.name||"",documentCount:N?.documents?.length||0,completableCount:N?.documents?.filter(n=>n.status!==m.COMPLETED&&n.status!==m.CANCELLED&&n.status!==m.FAILED).length||0,isLoading:_t.isPending}),e.jsx(cn,{isOpen:q,onClose:()=>{X(!1),we(null)},onConfirm:Os,folderName:ee?.name||"",documentCount:ee?.documents?.length||0,isLoading:kt.isPending})]})}export{qn as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.