1import{u as L,r as i,j as e,C as f,i as u,k as j,dQ as D,G as h,bj as X,bX as _,m as v,b9 as z,ba as T,cv as E,bb as B,dR as V,w as N,E as r,I as c,dN as $,v as P,J as k,M as q,V as G,c_ as H,z as J}from"./index-D7Px3Jip.js";const Q=()=>{const{user:a,setUser:p}=L(),[t,o]=i.useState(!1),[w,b]=i.useState(!1),g=i.useRef(null),[d,y]=i.useState((a==null?void 0:a.avatar)||null),[C,S]=i.useState(null),[n,l]=i.useState({name:(a==null?void 0:a.name)||"",email:(a==null?void 0:a.email)||"",phone:(a==null?void 0:a.phone)||"",address:(a==null?void 0:a.address)||"",department:(a==null?void 0:a.department)||"",avatar:(a==null?void 0:a.avatar)||"",specialization:(a==null?void 0:a.specialization)||""}),M=async()=>{try{b(!0);let s=a==null?void 0:a.avatar;if(C){const F=new FormData;F.append("file",C),s=(await P.post("/api/uploads/upload",F,{headers:{"Content-Type":"multipart/form-data"}})).data.url}const m={...a,...n,avatar:s},{data:x}=await P.post("/api/user/updateUser",{updatedUser:m});p(x.user),k.success("Profile updated successfully"),o(!1)}catch(s){console.error("Update failed:",s),k.error("Failed to update profile")}finally{b(!1)}},A=()=>{l({name:(a==null?void 0:a.name)||"",email:(a==null?void 0:a.email)||"",phone:(a==null?void 0:a.phone)||"",address:(a==null?void 0:a.address)||"",department:(a==null?void 0:a.department)||"",avatar:(a==null?void 0:a.avatar)||"",specialization:(a==null?void 0:a.specialization)||""}),y((a==null?void 0:a.avatar)||null),S(null),o(!1)},I=()=>{t&&g.current&&g.current.click()},R=s=>{if(s.target.files&&s.target.files[0]){const m=s.target.files[0];S(m);const x=new FileReader;x.onloadend=()=>{y(x.result)},x.readAsDataURL(m)}},U=s=>({owner:"bg-purple-500",admin:"bg-blue-500",sales_manager:"bg-green-500",team_lead:"bg-yellow-500",agent:"bg-orange-500",site_incharge:"bg-red-500",contractor:"bg-gray-500",accountant:"bg-indigo-500",customer_purchased:"bg-pink-500",customer_prospect:"bg-cyan-500"})[s]||"bg-gray-500";return a?e.jsx("div",{className:"max-w-4xl mx-auto space-y-6",children:e.jsxs(f,{children:[e.jsx(u,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs(j,{className:"flex items-center gap-2 text-lg sm:text-xl",children:[e.jsx(D,{className:"h-5 w-5"}),"Profile Information"]}),e.jsxs(h,{variant:t?"destructive":"outline",size:"sm",onClick:t?A:()=>o(!0),className:"self-start sm:self-auto",children:[t?e.jsx(X,{className:"h-4 w-4 mr-2"}):e.jsx(_,{className:"h-4 w-4 mr-2"}),t?"Cancel":"Edit"]})]})}),e.jsx(v,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row items-start gap-6 ",children:[e.jsxs("div",{className:`relative ${t?"cursor-pointer hover:opacity-80":"cursor-default"} border border-1 border-gray-200 rounded-full`,onClick:I,children:[e.jsxs(z,{className:"h-20 w-20 sm:h-24 sm:w-24",children:[e.jsx(T,{src:d!=null&&d.startsWith("data:")?d:E(d)}),e.jsx(B,{className:"text-lg sm:text-xl",children:a.name.split(" ").map(s=>s[0]).join("")})]}),t&&e.jsx("div",{className:"absolute bottom-0 right-0 bg-black bg-opacity-50 rounded-full p-1",children:e.jsx(V,{className:"text-white h-4 w-4"})}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",ref:g,onChange:R})]}),e.jsxs("div",{className:"flex-1 space-y-4 w-full",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-semibold font-sans break-words",children:n.name}),e.jsx(N,{className:`${U(a.role)} text-white font-sans w-fit`,children:a.role.replace("_"," ").toUpperCase()})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"name",children:"Full Name"}),e.jsx(c,{id:"name",value:n.name,onChange:s=>l({...n,name:s.target.value}),disabled:!t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email",children:"Email"}),e.jsx(c,{id:"email",type:"email",value:n.email,onChange:s=>l({...n,email:s.target.value}),disabled:!t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"phone",children:"Phone Number"}),e.jsx(c,{id:"phone",value:n.phone,onChange:s=>l({...n,phone:s.target.value}),disabled:!t,placeholder:"+91 XXXXX XXXXX"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"department",children:"Department"}),e.jsx(c,{id:"department",value:n.department,onChange:s=>l({...n,department:s.target.value}),disabled:!t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"address",children:"Address"}),e.jsx(c,{id:"address",value:n.address,onChange:s=>l({...n,address:s.target.value}),disabled:!t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"specialization",children:"Specialization"}),e.jsx(c,{id:"specialization",value:n.specialization,onChange:s=>l({...n,specialization:s.target.value}),disabled:!t})]})]}),t&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(h,{onClick:M,className:"w-full sm:w-auto",disabled:w,children:[e.jsx($,{className:"h-4 w-4 mr-2"}),w?"Saving...":"Save Changes"]}),e.jsx(h,{variant:"outline",onClick:A,className:"w-full sm:w-auto",children:"Cancel"})]})]})]})})]})}):null},O=()=>{const{user:a}=L(),p=()=>({owner:["Full System Access","User Management","Financial Reports","System Settings"],admin:["User Management","Content Management","System Configuration","Reports"],sales_manager:["Team Management","Sales Reports","Enquiry Management","Lead Assignment"],team_lead:["Team Coordination","Task Assignment","Performance Review","Site Visits"],agent:["Lead Management","Client Communication","Site Visits"],site_incharge:["Site Monitoring","Quality Control","Contractor Management","Progress Reports"],contractor:["Task Management","Material Requests","Invoice Creation","Progress Updates"],accountant:["Financial Management","Tax Documents","Invoice Processing"],customer_purchased:["Property Access","Payment History","Document Access","Support"],customer_prospect:["Property Browsing","Site Visits","Application Tracking","Support"]})[a==null?void 0:a.role]||[];return e.jsx(q,{children:e.jsxs("div",{className:"space-y-6 p-0 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-md font-vidaloka",children:"Profile"}),e.jsxs("div",{className:"flex items-center gap-2 text-sm sm:text-base",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),a&&a.updatedAt&&e.jsxs("span",{className:"text-muted-foreground",children:["Last updated:"," ",new Date(a.updatedAt).toLocaleDateString("en-GB")]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-2 space-y-6",children:e.jsx(Q,{})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(f,{children:[e.jsx(u,{children:e.jsxs(j,{className:"flex items-center gap-2 font-sans text-base sm:text-lg",children:[e.jsx(H,{className:"h-5 w-5"}),"Permissions"]})}),e.jsx(v,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:p().map((t,o)=>e.jsx(N,{variant:"secondary",className:"whitespace-nowrap",children:t},o))})})]}),e.jsxs(f,{children:[e.jsx(u,{children:e.jsxs(j,{className:"flex items-center gap-2 font-sans text-base sm:text-lg",children:[e.jsx(J,{className:"h-5 w-5"}),"Account Information"]})}),e.jsxs(v,{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between text-sm gap-1 sm:gap-0",children:[e.jsx("span",{className:"text-muted-foreground font-sans",children:"Member Since:"}),e.jsx("span",{children:a&&a.createdAt&&new Date(a.createdAt).toLocaleStr
1ing("en-IN",{month:"long",year:"numeric"})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between text-sm gap-1 sm:gap-0",children:[e.jsx("span",{className:"text-muted-foreground font-sans",children:"Account Status:"}),e.jsx(N,{variant:"default",className:"bg-green-500 w-fit",children:"Active"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between text-sm gap-1 sm:gap-0",children:[e.jsx("span",{className:"text-muted-foreground font-sans",children:"Last Login:"}),e.jsx("span",{children:a&&a.lastLogin&&new Date(a.lastLogin).toLocaleTimeString("en-IN",{day:"2-digit",month:"long",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})})]})]})]})]})]})]})})};export{O 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.