import{bz as R,bA as A,bB as B,bC as f,bD as k,bE as O,ai as x,bF as z,a as L,b as a,bG as P,a_ as Z,aZ as G,bH as $,bI as H,bJ as _,a$ as J,bK as K,bL as Q,bM as V,bN as q,r as m,bt as W,u as X,bO as Y,bP as U,j as b,$ as w,bf as S,V as ee,bQ as se,bR as te,bS as ae}from"./index-AbGWey75.js";const ne=async({setSaveType:t,currentEvent:e,dispatch:o,calendarsGroup:r,loadMaterials:d,id:n,date:l,setIsLoaderData:p,navigate:E,user:c})=>{if(Number(n)===R)return;t(e.resource.saveType||A.Save);const u=await o(B({id:Number(n),calendarsGroup:r,startDate:new Date(l),isAllDay:!1,isUtc:!0})),{payload:s}=u;if(!s){E("/");return}const{AccessType:v}=s||{};((s==null?void 0:s.OrganizerId)===(c==null?void 0:c.ContactId)||v!==f.FreeBusy&&v!==f.Read)&&(s!=null&&s.HasMaterials)&&await d(),p(!1)},oe=async({event:t,currentUser:e,dispatch:o,id:r})=>{const{accessType:d,ownerId:n,organizerId:l}=t.resource,p=n===(e==null?void 0:e.Id)||l===(e==null?void 0:e.ContactId);if(!((d===f.FreeBusy||d===f.Read)&&!p&&(n!==void 0||l!==void 0)))try{const{payload:c}=await o(k(Number(r)));if(t.resource.ownerId!==(e==null?void 0:e.Id))return;const u=O(c,e);if(x.isEmpty(u))return;const s=u.map(({id:v})=>v);await o(z(s))}catch{}},re=()=>{const t=L(),e=a(P),o=a(Z),r=a(G),d=a($),n=a(H),l=a(_),p=a(J),E=a(K),c=a(Q),u=a(V),s=a(q),[v,y]=m.useState(A.Save),[M,I]=m.useState(!0),h=W(),{isMobile:T}=X(),{id:i,date:g}=Y(),D=i!==void 0,C=()=>{t(te()),t(ae()),h("/")},j=m.useCallback(()=>{oe({event:e,currentUser:n,dispatch:t,id:Number(i)})},[e,t,n,i]);return m.useEffect(()=>{if(!(!i&&g)){const{pathname:F,search:N}=location;if(F==="/event/new_event"){t(U({search:N,calendarsGroup:o}));return}ne({setSaveType:y,currentEvent:e,dispatch:t,calendarsGroup:o,loadMaterials:j,id:Number(i),date:g,setIsLoaderData:I,navigate:h,user:n})}},[i,g]),x.isEmpty(r)?b.jsx(w,{w:"100%",h:"100vh",align:"center",justify:"center",children:b.jsx(S,{})}):D&&i!==(e==null?void 0:e.id)?b.jsx(w,{w:"100%",h:"100vh",align:"center",justify:"center",children:b.jsx(S,{})}):b.jsx(ee,{w:"100%",px:T?10:20,children:b.jsx(se,{edit:D,handleCloseCreateEventModal:C,calendarList:r,currentEvent:e,calendarsGroup:o,currentAddConfigStatus:d,currentUser:n,saveType:v,setSaveType:y,isLoaderData:M,currentEventStatus:l,timeZones:p,timeZone:E,submitEvent:c,calendarDisplayedDatesRange:u,openedDeletedRecurringActionModal:s})})};export{re as default};
