1import{j as e}from"./three-DQYxx-K5.js";import{r as l}from"./react-5m16uN2r.js";import{u as Y,b as Z,m as U,e as y,G as ee,a as I}from"./index-B9IHGE4x.js";import{B as ae}from"./Breadcrumb-C_cD3hKk.js";import{U as se}from"./upload-B1Ee7sgq.js";import"./house-9dJN880N.js";import"./chevron-right-Db0MWDvj.js";const te=[{code:"en",name:"English",flag:"ðºð¸"},{code:"fr",name:"Français",flag:"ð«ð·"},{code:"de",name:"Deutsch",flag:"ð©ðª"},{code:"zh",name:"䏿",flag:"ð¨ð³"}],m="https://api.dicebear.com/7.x",N=[{id:"pilot",name:"Pilot",path:`${m}/adventurer/svg?seed=AeroPilot&backgroundColor=b6e3f4`},{id:"copilot",name:"Co-Pilot",path:`${m}/adventurer/svg?seed=CoPilotAce&backgroundColor=c0aede`},{id:"engineer",name:"Engineer",path:`${m}/adventurer/svg?seed=FlightEngineer&backgroundColor=d1f4d1`},{id:"mechanic",name:"Mechanic",path:`${m}/adventurer/svg?seed=AeroMechanic&backgroundColor=ffd5dc`},{id:"designer",name:"Designer",path:`${m}/adventurer/svg?seed=AircraftDesigner&backgroundColor=ffdfbf`},{id:"astronaut",name:"Astronaut",path:`${m}/adventurer/svg?seed=SpaceAstronaut&backgroundColor=c9e8ff`}];function ue({onBack:F,onProfileUpdate:d}){const{t:s,i18n:b}=Y(),{getAccessTokenSilently:S,user:i}=Z(),[n,A]=l.useState(null),[C,M]=l.useState(null),[H,E]=l.useState(!0),[D,o]=l.useState(null),[p,k]=l.useState(null),[$,z]=l.useState(!1),[T,_]=l.useState(!1),[w,j]=l.useState(!1),[L,f]=l.useState(null),R=l.useRef(null),V=async()=>{try{const a=await S(),t=await fetch("/api/user/profile",{headers:{Authorization:`Bearer ${a}`}});if(!t.ok)throw new Error(`Failed to fetch profile: ${t.statusText}`);const r=await t.json();A(r);const u=N.find(c=>{var h;return(h=r.picture)==null?void 0:h.includes(c.id)});u&&k(u.id)}catch(a){console.error("Failed to fetch profile:",a),o(a instanceof Error?a.message:"Failed to fetch profile")}},W=async()=>{try{const a=await S(),t=await fetch("/api/user/stats",{headers:{Authorization:`Bearer ${a}`}});if(!t.ok)throw new Error(`Failed to fetch stats: ${t.statusText}`);const r=await t.json();M(r)}catch(a){console.error("Failed to fetch stats:",a)}};l.useEffect(()=>{(async()=>{E(!0),await Promise.all([V(),W()]),E(!1)})()},[S]);const q=a=>{k(a),f(null);const t=N.find(r=>r.id===a);t&&f(t.path)},J=async a=>{var r,u,c,h;const t=(r=a.target.files)==null?void 0:r[0];if(t){if(!t.type.startsWith("image/")){o(s("profile.errors.selectImage"));return}if(t.size>5*1024*1024){o(s("profile.errors.imageTooLarge"));return}z(!0),o(null),k(null);try{const g=new FileReader;g.onload=x=>{var G;f((G=x.target)==null?void 0:G.result)},g.readAsDataURL(t);const B=new FormData;B.append("file",t);const v=await I.put("/api/user/profile/upload",B,{headers:{"Content-Type":"multipart/form-data"}});(u=v.data)!=null&&u.picture_url&&(f(v.data.picture_url),A(x=>x&&{...x,picture:v.data.picture_url}),d==null||d(v.data.picture_url),j(!0),setTimeout(()=>j(!1),3e3))}catch(g){console.error("Failed to upload photo:",g),o(((h=(c=g.response)==null?void 0:c.data)==null?void 0:h.detail)||"Failed to upload photo"),f(null)}finally{z(!1)}}},K=async()=>{var a,t;if(p){_(!0),o(null);try{const r=N.find(c=>c.id===p);if(!r)return;(await I.put("/api/user/profile",{picture_url:r.path})).data&&(A(c=>c&&{...c,picture:r.path}),d==null||d(r.path),j(!0),setTimeout(()=>j(!1),3e3))}catch(r){console.error("Failed to save profile:",r),o(((t=(a=r.response)==null?void 0:a.data)==null?void 0:t.detail)||"Failed to save profile")}finally{_(!1)}}},O=a=>{b.changeLanguage(a),localStorage.setItem("aereo-language",a)},Q=a=>a?new Date(a).toLocaleDateString("en-US",{month:"long",year:"numeric"}):"Unknown",P=()=>L||(n!=null&&n.picture?n.picture:i!=null&&i.picture?i.picture:null),X=()=>{const a=(n==null?void 0:n.name)||(i==null?void 0:i.name)||(n==null?void 0:n.email)||(i==null?void 0:i.email);return a?a.charAt(0).toUpperCase():"?"};return H?e.jsx("div",{className:"profile-page",children:e.jsxs("div",{className:"profile-loading",children:[e.jsx("div",{className:"loading-spinner"}),e.jsx("p",{children:s("profile.loading")})]})}):e.jsx("div",{className:"profile-page",children:e.jsxs("div",{className:"profile-container",children:[e.jsx(ae,{items:[{label:s("common.home"),onClick:F},{label:s("profile.title")}]}),e.jsx("div",{className:"profile-header",children:e.jsxs("div",{className:"profile-title-section",children:[e.jsx("div",{className:"profile-title-left",children:e.jsx("h1",{children:s("profile.title")})}),e.jsxs("button",{className:"btn-back",onClick:F,children:[e.jsx(U,{size:16}),s("common.back")]})]})}),D&&e.jsxs("div",{className:"profile-error-banner",children:[e.jsx("span",{children:D}),e.jsx("button",{onClick:()=>o(null),children:s("common.dismiss")})]}),e.jsxs("div",{className:"profile-content",children:[e.jsxs("div",{className:"profile-info-card",children:[e.jsx("div",{className:"profile-avatar-section",children:e.jsx("div",{className:"current-avatar",children:P()?e.jsx("img",{src:P(),alt:"Profile"}):e.jsx("div",{className:"avatar-placeholder",children:X()})})}),e.jsxs("div",{className:"profile-details",children:[e.jsx("h2",{className:"profile-name",children:(n==null?void 0:n.name)||(i==null?void 0:i.name)||s("common.user")}),e.jsx("p",{className:"profile-email",children:(n==null?void 0:n.email)||(i==null?void 0:i.email)||s("common.noEmail")}),e.jsx("p",{className:"profile-member-since",children:s("profile.memberSince",{date:Q((n==null?void 0:n.created_at)??null)})}),e.jsx("p",{className:"profile-designs-count",children:s("profile.designsCreated",{count:(C==null?void 0:C.total_jobs)||0})})]})]}),e.jsxs("div",{className:"profile-picture-section",children:[e.jsx("h3",{className:"section-title",children:s("profile.changeProfilePicture")}),e.jsxs("div",{className:"upload-section",children:[e.jsx("input",{type:"file",ref:R,onChange:J,accept:"image/*",style:{display:"none"}}),e.jsx("button",{className:"upload-btn",onClick:()=>{var a;return(a=R.current)==null?void 0:a.click()},disabled:$,children:$?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"btn-spinner"}),s("profile.uploading")]}):e.jsxs(e.Fragment,{children:[e.jsx(se,{size:18}),s("profile.uploadPhoto")]})}),e.jsx("span",{className:"upload-hint",children:s("profile.uploadHint")})]}),e.jsx("div",{className:"avatar-divider",children:e.jsx("span",{children:s("profile.orChooseAvatar")})}),e.jsx("div",{className:"avatar-grid",children:N.map(a=>e.jsxs("button",{className:`avatar-option ${p===a.id?"selected":""}`,onClick:()=>q(a.id),title:a.name,children:[e.jsxs("div",{className:"avatar-preview",children:[e.jsx("img",{src:a.path,alt:a.name,className:"avatar-image"}),e.jsx("span",{className:"avatar-name",children:a.name})]}),p===a.id&&e.jsx("div",{className:"avatar-check",children:e.jsx(y,{size:14})})]},a.id))})]}),e.jsxs("div",{className:"profile-language-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx(ee,{size:18}),s("profile.languagePreference")]}),e.jsx("p",{className:"section-description",children:s("profile.languageDescription")}),e.jsx("div",{className:"language-grid",children:te.map(a=>e.jsxs("button",{className:`language-option ${a.code===b.language?"selected":""}`,onClick:()=>O(a.code),children:[e.jsx("span",{className:"language-flag",children:a.flag}),e.jsx("span",{className:"language-name",children:a.name}),a.code===b.language&&e.jsx("span",{className:"language-check",children:e.jsx(y,{size:14})})]},a.code))})]}),e.jsx("div",{className:"profile-actions",children:e.jsx("button",{className:`save-btn ${w?"success":""}`,onClick:K,disabled:!p||T||w,children:T?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"btn-spinner"}),s("profile.saving")]}):w?e.jsxs(e.Fragment,{children:[e.jsx(y,{size:18}),s("profile.saved")]}):s("common.save")})})]})]})})}export{ue 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.