1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[638],{14707:(e,t,n)=>{"use strict";n.d(t,{A:()=>l});var r=n(37876),i=n(14232);function a(e){let{name:t,imageUrl:n}=e,[a,l]=(0,i.useState)(!1),s=(t||"?").trim()||"?",o=s.slice(0,1).toUpperCase(),c=!!n&&!a;return(0,r.jsx)("span",{className:"inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full border border-white bg-amber-200 text-[10px] font-bold text-amber-950 dark:border-amber-950 dark:bg-amber-800 dark:text-amber-100",style:{width:26,height:26},title:s,children:c?(0,r.jsx)("img",{src:n,alt:"",className:"h-full border-green-500 border-2 rounded-full animate-pulse w-full object-cover",onError:()=>l(!0)}):o})}function l(e){let{participants:t=[]}=e;if(!t.length)return null;let n=t.map(e=>e.isSelf?"You":(e.name||"Someone").trim()||"Someone").join(" \xb7 ");return(0,r.jsxs)("div",{className:"mb-2 flex max-w-full items-center gap-2 dark:text-amber-100",role:"status","aria-live":"polite",title:n,children:[(0,r.jsx)("span",{className:"flex shrink-0 -space-x-1.5","aria-hidden":!0,children:t.map((e,t)=>(0,r.jsx)(a,{name:e.name,imageUrl:e.imageUrl},"".concat(String(e.userId),"-").concat(t)))}),(0,r.jsx)("span",{className:"min-w-0 truncate font-medium",children:n})]})}},55967:(e,t,n)=>{"use strict";let r;n.d(t,{O:()=>h});var i=n(14232),a=n(29454),l=n(12692);function s(e){if(!e||!String(e).trim())return null;let t=String(e).trim().replace(/\/+$/,"");/^https?:\/\//i.test(t)||(t=("https:"===window.location.protocol?"https://":"http://")+t.replace(/^\/\//,""));try{return new URL(t).origin}catch(e){return null}}function o(e){return"localhost"===e||"127.0.0.1"===e||e.endsWith(".local")}function c(){let e=s("https://glacial-spire-76389-5c8e09b34750.herokuapp.com");if(e)return e;let t=s("https://glacial-spire-76389-5c8e09b34750.herokuapp.com");return!t||o(window.location.hostname)?null:t}function d(){let e=c();return e?e===window.location.origin:o(window.location.hostname)}async function u(){let e=c();if(e)return e;if(o(window.location.hostname))return null;if(void 0!==r)return r;try{let e=await fetch("/api/socket/origin",{credentials:"same-origin"}),t=await e.json().catch(()=>({})),n=(null==t?void 0:t.origin)!=null?String(t.origin):"";r=s(n)||null}catch(e){r=null}return r}let m=null;async function p(){if(d())return m||(m=fetch("/api/socket-init").then(()=>void 0).catch(e=>{throw m=null,e})),m}function h(e){let{roomPrefix:t,entityId:n,authToken:r,currentUser:s,enabled:o}=e;return function(e){let{roomKey:t,authToken:n,currentUser:r,enabled:s}=e,[o,c]=(0,i.useState)([]),m=(0,i.useMemo)(()=>{if(null==r?void 0:r._id)return String(r._id);let e=a.default.get("did");return e?String(e):null},[null==r?void 0:r._id]),h=(0,i.useMemo)(()=>{if(n&&String(n).trim())return String(n).trim();let e=a.default.get("tkn");return e?String(e).trim():null},[n]);(0,i.useEffect)(()=>{if(!s||!t||!h||!m)return void c([]);let e=!0,n=null;return(async()=>{try{d()&&await p()}catch(e){console.warn("[usePagePresence] bootstrap failed",e);return}if(!e)return;let i=await u(),a={path:"/api/socketio",withCredentials:!0,auth:{token:h}},s=i?(0,l.io)(i,a):(0,l.io)(a);if(n=s,!e){s.removeAllListeners(),s.disconnect(),n=null;return}let o=(null==r?void 0:r.name)&&String(r.name).trim()||"User",x=(null==r?void 0:r.imageUrl)||(null==r?void 0:r.profileImage)||null,g=()=>{n.emit("join-presence",{roomKey:t,user:{userId:m,name:o,imageUrl:x||null}})};n.on("connect",g),n.on("presence-peers",e=>{Array.isArray(e)&&c(e.filter(e=>e&&String(e.userId)!==String(m)))}),n.on("presence-user-joined",e=>{e&&String(e.userId)!==String(m)&&c(t=>{let n=t.filter(t=>String(t.userId)!==String(e.userId));return n.push({userId:String(e.userId),name:e.name||"Someone",imageUrl:e.imageUrl||null}),n})}),n.on("presence-user-left",e=>{let t=null==e?void 0:e.userId;null!=t&&c(e=>e.filter(e=>String(e.userId)!==String(t)))}),n.connected&&g()})(),()=>{e=!1;let t=n;if(n=null,t){try{t.emit("leave-presence")}catch(e){}t.removeAllListeners(),t.disconnect()}}},[s,t,h,m,null==r?void 0:r.name,null==r?void 0:r.imageUrl,null==r?void 0:r.profileImage]);let x=(0,i.useMemo)(()=>s&&t&&h&&m?[{userId:m,name:(null==r?void 0:r.name)&&String(r.name).trim()||"User",imageUrl:(null==r?void 0:r.imageUrl)||(null==r?void 0:r.profileImage)||null,isSelf:!0},...o]:[],[s,t,h,m,null==r?void 0:r.name,null==r?void 0:r.imageUrl,null==r?void 0:r.profileImage,o]);return{peers:o,participants:x}}({roomKey:(0,i.useMemo)(()=>{let e=null==n||""===n?null:Array.isArray(n)?n[0]:n;if(null==e||""===e)return null;let r=String(t||"").trim();return r?"".concat(r,":").concat(String(e)):null},[t,n]),authToken:r,currentUser:s,enabled:o})}},93784:(e,t,n)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/dashboard/appointments/edit/[id]",function(){return n(96434)}])},96434:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>f});var r=n(37876),i=n(14232),a=n(89099),l=n(94246),s=n(35845),o=n(35588),c=n(70039),d=n(14707),u=n(55967),m=n(78769),p=n(31452),h=n(96668),x=n(78464),g=n(29454);function f(){let e=(0,a.useRouter)(),{id:t}=e.query,{user:n,loading:f,auth:b}=(0,l.A)(),{can:v}=(0,s.A)(),[j,y]=(0,i.useState)(null),[w,N]=(0,i.useState)([]),[k,S]=(0,i.useState)(!0),[A,U]=(0,i.useState)(!1),[_,I
1]=(0,i.useState)(null),[E,C]=(0,i.useState)(!1);v("canManageAppointments");let P=v("canCreateAppointments"),T=!!(e.isReady&&"string"==typeof t&&n&&!f&&j&&P&&!k),{participants:M}=(0,u.O)({roomPrefix:"appointment",entityId:"string"==typeof t?t:null,authToken:b||g.default.get("tkn"),currentUser:n,enabled:T}),O=(0,i.useCallback)(async()=>{try{S(!0),I(null);let e=await fetch("/api/appointments/".concat(t)),n=await e.json();if(!e.ok)return void(404===e.status?I("Appointment not found or you do not have permission to edit it."):I(n.error||"Failed to fetch appointment"));y(n.appointment||n)}catch(e){console.error("Error fetching appointment:",e),I("An error occurred while fetching the appointment. Please try again.")}finally{S(!1)}},[t]),R=async()=>{try{let e=await fetch("/api/users?limit=100"),t=await e.json();e.ok&&t.users&&N(t.users)}catch(e){console.error("Error fetching form data:",e)}};(0,i.useEffect)(()=>{!f&&n&&t&&(O(),R())},[f,n,t,O]);let B=async n=>{if(!P)return void I("You don't have permission to edit appointments");try{U(!0),I(null);let r=await fetch("/api/appointments/".concat(t),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),i=await r.json();if(!r.ok)throw Error(i.error||"Failed to update appointment");C(!0),setTimeout(()=>{e.push("/dashboard/appointments/view/".concat(t))},2e3)}catch(e){console.error("Error updating appointment:",e),I(e.message)}finally{U(!1)}},F=()=>{e.push("/dashboard/appointments/view/".concat(t))};return f?(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,r.jsx)("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-blue-600"})})}):n?P?k?(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,r.jsx)("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-blue-600"})})}):_?(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"py-6",children:(0,r.jsxs)("div",{className:"max-w-2xl mx-auto",children:[(0,r.jsx)(m.F,{variant:"danger",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"font-medium",children:"Error"}),(0,r.jsx)("p",{className:"text-sm",children:_})]})}),(0,r.jsx)("div",{className:"mt-6 text-center",children:(0,r.jsx)("button",{onClick:()=>e.push("/dashboard/appointments"),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700",children:"Back to Appointments"})})]})})}):j?E?(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"py-6",children:(0,r.jsx)("div",{className:"max-w-2xl mx-auto",children:(0,r.jsxs)("div",{className:"text-center py-12",children:[(0,r.jsx)(h.A,{className:"h-16 w-16 mx-auto mb-4 text-green-600"}),(0,r.jsx)("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Appointment Updated Successfully!"}),(0,r.jsx)("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"Your changes have been saved. Redirecting to appointment details..."}),(0,r.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto"})]})})})}):(0,r.jsx)(o.A,{children:(0,r.jsxs)("div",{className:"py-6 space-y-4 sm:space-y-5",children:[(0,r.jsx)(d.A,{participants:M}),(0,r.jsxs)("button",{type:"button",onClick:F,className:"inline-flex items-center gap-2 rounded-xl px-2 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-white",children:[(0,r.jsx)(x.A,{className:"h-4 w-4"}),"Back to appointment"]}),(0,r.jsx)(c.A,{appointment:j,onSubmit:B,onCancel:F,isSubmitting:A,error:_,users:w})]})}):(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"py-6",children:(0,r.jsxs)("div",{className:"max-w-2xl mx-auto text-center",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Appointment Not Found"}),(0,r.jsx)("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"The appointment you're looking for doesn't exist or has been deleted."}),(0,r.jsx)("button",{onClick:()=>e.push("/dashboard/appointments"),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700",children:"Back to Appointments"})]})})}):(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"space-y-6 mt-2 mb-2",children:(0,r.jsx)(p.A,{title:"Access Denied",message:"You don't have permission to edit appointments.",requiredRoles:"Admin, Manager, Project Manager, or Operative",redirectPath:"/dashboard/appointments",redirectText:"Back to Appointments"})})}):(0,r.jsx)(o.A,{children:(0,r.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold mb-2 text-gray-900 dark:text-white",children:"Authentication Required"}),(0,r.jsx)("p",{className:"mb-6 text-gray-600 dark:text-gray-400",children:"Please login to view this page."}),(0,r.jsx)("button",{onClick:()=>
1e.push("/auth/login"),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700",children:"Go to Login"})]})})})}}},e=>{e.O(0,[7725,4429,6989,4925,5885,5588,8720,7025,9990,2111,39,636,6593,8792],()=>e(e.s=93784)),_N_E=e.O()}]);
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.