1import{b as e,r as s,j as a}from"./vendor-react-BH6F5oQJ.js";import{w as r,s as t,z as i,H as l,f as d,C as c,M as n,N as o,O as m,m as u,n as p,o as x,q as h,G as j,B as f}from"./index-dRqPaCFl.js";import{L as v}from"./label-RVODh2pd.js";import{S as g}from"./separator-KtQ1mSuG.js";import{c as w,v as N,w as y,x as b,k as P,y as S,b as C,z as E}from"./vendor-icons-CaI5__By.js";import"./vendor-ui-B4WC06Sp.js";import"./vendor-query-CC4VRGyP.js";import"./vendor-supabase-COwyE4EW.js";const _=()=>{const{toast:_}=r(),F=e(),[k,U]=s.useState(!0),[A,G]=s.useState(!1),[M,q]=s.useState(!1),[B,R]=s.useState(""),[z,I]=s.useState(""),[$,D]=s.useState(""),[T,V]=s.useState(""),[H,J]=s.useState(""),[L,O]=s.useState(!1),[W,K]=s.useState(""),[Q,X]=s.useState(""),[Y,Z]=s.useState("");s.useEffect(()=>{ee()},[]);const ee=async()=>{try{U(!0);const{data:{user:e},error:s}=await t.auth.getUser();if(s)throw s;if(!e)return void F("/admin/login");J(e.id),R(e.email||"");const{data:a,error:r}=await t.from("profiles").select("display_name, avatar_url").eq("id",e.id).single();r&&"PGRST116"!==r.code&&i("Profile error:",r),a&&(I(a.display_name||""),D(a.avatar_url||""));const{data:l,error:d}=await t.from("user_roles").select("role").eq("user_id",e.id).single();d&&"PGRST116"!==d.code&&i("Role error:",d),l&&V(l.role)}catch(e){_({title:"Error",description:"Failed to load user data",variant:"destructive"})}finally{U(!1)}};return k?a.jsx("div",{className:"min-h-screen flex items-center justify-center",children:a.jsx("div",{className:"h-12 w-12 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):a.jsxs(a.Fragment,{children:[a.jsxs(l,{children:[a.jsx("title",{children:"My Profile | Delphi Global Research Center"}),a.jsx("meta",{name:"robots",content:"noindex,nofollow"})]}),a.jsx("main",{className:"container mx-auto px-4 py-12 min-h-screen",children:a.jsxs("div",{className:"max-w-4xl mx-auto",children:[a.jsx("div",{className:"mb-8 flex items-center justify-between",children:a.jsxs("div",{children:[a.jsxs(d,{variant:"ghost",onClick:()=>F(-1),className:"mb-4 gap-2",children:[a.jsx(w,{className:"h-4 w-4"}),"Back"]}),a.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-primary to-primary/60 bg-clip-text text-transparent",children:"My Profile"}),a.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage your account settings and preferences"})]})}),a.jsxs("div",{className:"grid gap-6",children:[a.jsxs(c,{children:[a.jsxs(n,{children:[a.jsxs(o,{className:"flex items-center gap-2",children:[a.jsx(N,{className:"h-5 w-5 text-primary"}),"Account Information"]}),a.jsx(m,{children:"View your account details and role"})]}),a.jsxs(u,{className:"space-y-6",children:[a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs(p,{className:"h-24 w-24",children:[a.jsx(x,{src:$,alt:z||B}),a.jsx(h,{className:"text-2xl",children:(z||B).charAt(0).toUpperCase()})]}),a.jsxs("div",{className:"flex-1",children:[a.jsx(v,{htmlFor:"avatar",className:"cursor-pointer",children:a.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground mb-2",children:[a.jsx(y,{className:"h-4 w-4"}),"Profile Picture"]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs(d,{variant:"outline",size:"sm",disabled:L,onClick:()=>{var e;return null==(e=document.getElementById("avatar-upload"))?void 0:e.click()},className:"gap-2",children:[a.jsx(b,{className:"h-4 w-4"}),L?"Uploading...":"Upload New"]}),a.jsx(j,{id:"avatar-upload",type:"file",accept:"image/*",className:"hidden",onChange:async e=>{var s;try{const a=null==(s=e.target.files)?void 0:s[0];if(!a)return;if(!a.type.startsWith("image/"))return void _({title:"Error",description:"Please upload an image file",variant:"destructive"});if(a.size>2097152)return void _({title:"Error",description:"Image must be less than 2MB",variant:"destructive"});if(O(!0),$){const e=$.split("/").slice(-2).join("/");await t.storage.from("user-avatars").remove([e])}const r=a.name.split(".").pop(),i=`${H}/avatar.${r}`,{error:l}=await t.storage.from("user-avatars").upload(i,a,{upsert:!0});if(l)throw l;const{data:{publicUrl:d}}=t.storage.from("user-avatars").getPublicUrl(i),{error:c}=await t.from("profiles").update({avatar_url:d}).eq("id",H);if(c)throw c;D(d),_({title:"Success",description:"Avatar updated successfully"})}catch(a){_({title:"Error",description:"Failed to upload avatar",variant:"destructive"})}finally{O(!1)}},disabled:L})]}),a.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Max 2MB. JPG, PNG, or GIF"})]})]}),a.jsx(g,{}),a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsxs(v,{className:"flex items-center gap-2",children:[a.jsx(P,{className:"h-4 w-4 text-muted-foreground"}),"Email Address"]}),a.jsx(j,{value:B,disabled:!0,className:"bg-muted"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs(v,{className:"flex items-center gap-2",children:[a.jsx(S,{className:"h-4 w-4 text-muted-foreground"}),"Role"]}),a.jsx("div",{className:"flex items-center h-10",children:T?a.jsx(f,{variant:(se=T,"super_admin"===se?"default":"admin"===se?"secondary":"outline"),children:(e=>({super_admin:"Super Admin",admin:"Admin",editor:"Editor",author:"Author",viewer:"Viewer"}[e]||e))(T)}):a.jsx("span",{className:"text-sm text-muted-foreground",children:"No role assigned"})})]})]}),a.jsx(g,{}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(v,{htmlFor:"displayName",children:"Display Name"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(j,{id:"displayName",value:z,onChange:e=>I(e.target.value),placeholder:"Enter your display name"}),a.jsxs(d,{onClick:async()=>{try{G(!0);const{error:e}=await t.from("profiles").update({display_name:z}).eq("id",H);if(e)throw e;_({title:"Success",description:"Profile updated successfully"})}catch(e){_({title:"Error",description:"Failed to update profile",variant:"destructive"})}finally{G(!1)}},disabled:A,className:"gap-2",children:[a.jsx(C,{className:"h-4 w-4"}),A?"Saving...":"Save"]})]})]})]})]}),a.jsxs(c,{children:[a.jsxs(n,{children:[a.jsxs(o,{className:"flex items-center gap-2",children:[a.jsx(E,{className:"h-5 w-5 text-primary"}),"Change Password"]}),a.jsx(m,{children:"Update your password to keep your account secure"})]}),a.jsxs(u,{className:"space-y-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(v,{htmlFor:"newPassword",children:"New Password"}),a.jsx(j,{id:"newPassword",type:"password",value:Q,onChange:e=>X(e.target.value),placeholder:"Enter new password"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(v,{htmlFor:"confirmPassword",children:"Confirm New Password"}),a.jsx(j,{id:"confirmPassword",type:"password",value:Y,onChange:e=>Z(e.target.value),placeholder:"Confirm new password"})]}),a.jsxs(d,{onClick:async()=>{try{if(Q!==Y)return void _({title:"Error",description:"Passwords do not match",variant:"destructive"});if(Q.length<6)return void _({title:"Error",description:"Password must be at least 6 characters",variant:"destructive"});q(!0);const{error:e}=await t.auth.updateUser({password:Q});if(e)throw e;_({title:"Success",description:"Password changed successfully"}),K(""),X(""),Z("")}catch(e){_({title:"Error",description:e.message||"Failed to change password",variant:"destructive"})}finally{q(!1)}}
1,disabled:M||!Q||!Y,className:"gap-2",children:[a.jsx(E,{className:"h-4 w-4"}),M?"Changing...":"Change Password"]})]})]})]})]})})]});var se};export{_ 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.