1import{j as e,bw as V,B as b,e as q,$ as z,a7 as k,g as Q,bj as v,bp as R,H as J,bv as K,bx as M,h as C,aN as Y,a as _,aM as G,r as X,aE as B,by as D,bz as Z,bA as ee,bB as se,C as h,b as u,c as p,aZ as te,d as g,aS as w}from"./index-DGo-vssZ.js";import{r as E}from"./vendor-Qgthw7N1.js";import{u as ae}from"./useMemberProfile-C1TnB_eM.js";import{M as re}from"./MobileActionSheet-8J59SiMq.js";import{M as S}from"./memberService-B-f_co3d.js";import{C as $}from"./camera-CX18FS0H.js";import{B as H}from"./building-wUoLfZZJ.js";import{C as O}from"./circle-x--5-vDMIU.js";const P="member-mobile-photo-upload";function j({label:s,value:r}){return e.jsxs("div",{className:"rounded-xl bg-gray-50 p-3 dark:bg-gray-900",children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-gray-900 dark:text-white",children:r})]})}function W({label:s,enabled:r}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl bg-gray-50 p-3 dark:bg-gray-900",children:[e.jsx("span",{className:"text-sm font-medium text-gray-800 dark:text-gray-200",children:s}),r?e.jsx(C,{className:"h-5 w-5 text-green-600"}):e.jsx(O,{className:"h-5 w-5 text-red-500"})]})}function ie(){return e.jsxs("div",{className:"space-y-4",children:[e.jsx(S,{title:"My Profile",subtitle:"Workspace account"}),e.jsxs("div",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-800",children:[e.jsx(M,{className:"h-20 w-20 rounded-full"}),e.jsx(M,{className:"mt-4 h-5 w-40 rounded"}),e.jsx(M,{className:"mt-2 h-4 w-56 rounded"})]})]})}function ne({profile:s,isLoading:r,isUploading:o,onPhotoUpload:d,onLogout:f,isVisitDetectionFeatureEnabled:i=!1,visitDetectionEnabled:n=!1,isUpdatingVisitDetection:m=!1,onVisitDetectionChange:y}){const[x,c]=E.useState(!1);if(r)return e.jsx(ie,{});if(!s)return e.jsxs(e.Fragment,{children:[e.jsx(S,{title:"My Profile",subtitle:"Workspace account"}),e.jsx("div",{className:"rounded-2xl border border-red-100 bg-red-50 py-12 text-center text-red-600 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300",children:"Failed to load profile"})]});const N=`${s.user.firstName} ${s.user.lastName}`.trim();return e.jsxs(e.Fragment,{children:[e.jsx(S,{title:"My Profile",subtitle:"Workspace account"}),e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-800",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(V,{user:s.user,size:"lg"}),e.jsx(b,{type:"button",size:"icon",className:"absolute -bottom-2 -right-2 h-9 w-9 rounded-full shadow-sm",disabled:o,asChild:!0,children:e.jsx("label",{htmlFor:P,"aria-label":"Upload profile photo",children:o?e.jsx("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent"}):e.jsx($,{className:"h-4 w-4"})})}),e.jsx("input",{id:P,type:"file",accept:"image/*",className:"hidden",onChange:d})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400",children:"Personal Information"}),e.jsx("h2",{className:"mt-1 truncate text-xl font-bold text-gray-900 dark:text-white",children:N||s.user.email}),e.jsx("p",{className:"mt-1 truncate text-sm text-gray-500 dark:text-gray-400",children:s.user.email}),e.jsx(q,{variant:"secondary",className:"mt-3 rounded-full",children:s.user.teamMemberRole})]})]}),e.jsx(b,{type:"button",variant:"outline",className:"mt-5 h-11 w-full rounded-xl",disabled:o,asChild:!0,children:e.jsxs("label",{htmlFor:P,children:[e.jsx(z,{className:"mr-2 h-4 w-4"}),o?"Uploading...":"Upload Photo"]})}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(j,{label:"Name",value:N||"Not provided"}),e.jsx(j,{label:"Member Since",value:k(new Date(s.user.createdAt),"MMMM d, yyyy")})]})]}),e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-800",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-base font-bold text-gray-900 dark:text-white",children:[e.jsx(Q,{className:"h-4 w-4 text-green-600"}),"Permissions"]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(W,{label:"Create Time Entries",enabled:s.permissions.canCreateTimeEntries}),e.jsx(W,{label:"View All Entries",enabled:s.permissions.canViewAllTimeEntries})]})]}),i&&e.jsx("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-800",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-base font-bold text-gray-900 dark:text-white",children:[e.jsx(v,{className:"h-4 w-4 text-green-600"}),"Visit Detection"]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:n?"Active - workspace property visits are being detected":"Off - no location data is collected"})]}),e.jsx(R,{checked:n,disabled:m,onCheckedChange:l=>y==null?void 0:y(l)})]})}),e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-800",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-base font-bold text-gray-900 dark:text-white",children:[e.jsx(H,{className:"h-4 w-4 text-green-600"}),"Workspace"]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx(j,{label:"Account Owner",value:`${s.workspace.accountOwner.firstName} ${s.workspace.accountOwner.lastName}`.trim()}),e.jsx(j,{label:"Owner Email",value:s.workspace.accountOwner.email}),e.jsx(j,{label:"Joined Workspace",value:k(new Date(s.workspace.memberSince),"MMMM d, yyyy")})]})]}),e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-800",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-base font-bold text-gray-900 dark:text-white",children:[e.jsx(v,{className:"h-4 w-4 text-green-600"}),"Workspace Properties"]}),s.assignedProperties.length>0?e.jsx("div",{className:"mt-4 space-y-2",children:s.assignedProperties.map(l=>e.jsxs("div",{className:"rounded-xl bg-gray-50 p-3 dark:bg-gray-900",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-white",children:[e.jsx(J,{className:"h-3.5 w-3.5 text-green-600"}),l.nickname]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:l.address})]},l.id))}):e.jsx("p",{className:"py-8 text-center text-sm text-gray-500 dark:text-gray-400",children:"No properties assigned yet"})]}),e.jsx("section",{className:"rounded-2xl border border-red-100 bg-white p-4 shadow-sm dark:border-red-900/60 dark:bg-gray-800",children:e.jsxs(b,{type:"button",variant:"outline",className:"h-11 w-full rounded-xl border-red-200 text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-900 dark:text-red-400 dark:hover:bg-red-950/40",onClick:()=>c(!0),children:[e.jsx(K,{className:"mr-2 h-4 w-4"}),"Log Out"]})}),e.jsx(re,{open:x,onOpenChange:c,title:"Log Out",message:"Are you sure you want to log out?",actions:[{label:"Log Out",destructive:!0,onClick:f}]})]})}function pe(){var T,F,I;const{data:s,isLoading:r}=ae(),o=Y(),[d,f]=E.useState(!1),{toast:i}
1=_(),n=G(),m=((T=s==null?void 0:s.features)==null?void 0:T.teamGeofenceVisitDetection)===!0,x=((I=(F=X({queryKey:["/api/user/preferences"],enabled:m,queryFn:async()=>{const t=await fetch("/api/user/preferences",{credentials:"include"});if(!t.ok)throw new Error("Failed to fetch preferences");return t.json()}}).data)==null?void 0:F.preferences)==null?void 0:I.locationTrackingEnabled)??!1,c=B({mutationFn:async t=>{const a=await fetch("/api/user/preferences",{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({locationTrackingEnabled:t})});if(!a.ok)throw new Error("Failed to update visit detection");try{localStorage.setItem("geofence_optin_cache",JSON.stringify(t))}catch{}return a.json()},onSuccess:(t,a)=>{n.invalidateQueries({queryKey:["/api/user/preferences"]}),a?D.start().catch(console.error):D.stop().catch(console.error),i({title:a?"Visit detection enabled":"Visit detection disabled",description:a?"Your visits to workspace properties can now be detected on this device.":"Location-based visit detection has been turned off on this device."})},onError:t=>{i({title:"Unable to update visit detection",description:t.message,variant:"destructive"})}}),N=E.useCallback(async()=>{try{await Z("/api/logout",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}})}catch{}await ee(n,{force:!0}),se("/logout-success")},[n]),l=B({mutationFn:async t=>{const a=await fetch("/api/user/profile",{method:"POST",body:t});if(!a.ok)throw new Error("Failed to update profile");return a.json()},onSuccess:()=>{i({title:"Success",description:"Profile photo updated successfully"}),n.invalidateQueries({queryKey:["member-profile"]}),n.invalidateQueries({queryKey:["/api/auth/user"]})},onError:t=>{i({title:"Error",description:t.message,variant:"destructive"})}}),A=async t=>{var U;const a=(U=t.target.files)==null?void 0:U[0];if(!a)return;if(!a.type.startsWith("image/")){i({title:"Error",description:"Please select an image file",variant:"destructive"});return}if(a.size>5*1024*1024){i({title:"Error",description:"Image must be less than 5MB",variant:"destructive"});return}const L=new FormData;L.append("profileImage",a),f(!0);try{await l.mutateAsync(L)}catch{}finally{f(!1),t.target.value=""}};return o?e.jsx(ne,{profile:s,isLoading:r,isUploading:d,onPhotoUpload:A,onLogout:N,isVisitDetectionFeatureEnabled:m,visitDetectionEnabled:x,isUpdatingVisitDetection:c.isPending,onVisitDetectionChange:t=>c.mutate(t)}):r?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading profile..."})}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"My Profile"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Your account information and workspace details"})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(h,{children:[e.jsx(u,{children:e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(te,{className:"w-5 h-5"}),"Personal Information"]})}),e.jsxs(g,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(V,{user:s.user,size:"lg"}),e.jsx(b,{size:"sm",className:"absolute -bottom-2 -right-2 rounded-full h-8 w-8",disabled:d,onClick:()=>{var t;return(t=document.getElementById("photo-upload"))==null?void 0:t.click()},children:d?e.jsx("div",{className:"animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full"}):e.jsx($,{className:"h-4 w-4"})}),e.jsx("input",{id:"photo-upload",type:"file",accept:"image/*",className:"hidden",onChange:A})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-lg font-medium",children:"Profile Photo"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:"Upload a new profile photo. Images should be square and under 5MB."}),e.jsxs(b,{variant:"outline",size:"sm",disabled:d,onClick:()=>{var t;return(t=document.getElementById("photo-upload"))==null?void 0:t.click()},children:[e.jsx(z,{className:"h-4 w-4 mr-2"}),d?"Uploading...":"Upload Photo"]})]})]}),e.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Name"}),e.jsxs("p",{className:"font-medium",children:[s.user.firstName," ",s.user.lastName]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Email"}),e.jsx("p",{className:"font-medium",children:s.user.email})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Role"}),e.jsx(q,{variant:"secondary",children:s.user.teamMemberRole})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Member Since"}),e.jsx("p",{className:"font-medium",children:k(new Date(s.user.createdAt),"MMMM d, yyyy")})]})]})]})]}),e.jsxs(h,{children:[e.jsxs(u,{children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"w-5 h-5"}),"Permissions"]}),e.jsx(w,{children:"Your access level within the workspace"})]}),e.jsxs(g,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Create Time Entries"}),s.permissions.canCreateTimeEntries?e.jsx(C,{className:"w-5 h-5 text-green-600"}):e.jsx(O,{className:"w-5 h-5 text-red-600"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"View All Entries"}),s.permissions.canViewAllTimeEntries?e.jsx(C,{className:"w-5 h-5 text-green-600"}):e.jsx(O,{className:"w-5 h-5 text-red-600"})]})]})]}),m&&e.jsxs(h,{children:[e.jsxs(u,{children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(v,{className:"w-5 h-5"}),"Visit Detection"]}),e.jsx(w,{children:"Automatically detect visits to workspace properties from this device"})]}),e.jsx(g,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Enable visit detection"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x?"Active - visits to workspace properties are being detected":"Off - no location data is collected"})]}),e.jsx(R,{checked:x,disabled:c.isPending,onCheckedChange:t=>c.mutate(t)})]})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(h,{children:[e.jsxs(u,{children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-5 h-5"}),"Workspace Information"]}),e.jsx(w,{children:"Details about your workspace and account owner"})]}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Account Owner"}),e.jsxs("p",{className:"font-medium",children:[s.workspace.accountOwner.firstName," ",s.workspace.accountOwner.lastName]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.workspace.accountOwner.email})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Joined Workspace"}),e.jsx("p",{className:"font-medium",children:k(new Date(s.workspace.memberSince),"MMMM d, yyyy")})]})]})]}),e.jsxs(h,{children:[e.jsxs(u,{children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(v,{className:"w-5 h-5"}),"Workspace Properties"]}),e.jsx(w,{children:"Properties you can log time entries for"})]}),e.jsx(g,{children:s.assignedProperties.length>0?e.jsx("div",{className:"space-y-3",children:s.assignedProperties.map(t=>e.jsxs("div",{className:"p-3 rounded-lg border hover:bg-accent transition-colors",children:[e.jsx("p",{className:"font-medium",children:t.nickname}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.address})]},t.id))}):e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No properties assigned yet"})})]})]})]})]}):e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-destructive",children:"Failed to load profile"})})}export{pe 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.