1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/avatarHealth-CH6NeMcj.js","assets/index-CBfKlGil.js","assets/vendor-BlB_7aU1.js","assets/vendor-BTrKGrB8.css","assets/index-BSWn8LCt.css"])))=>i.map(i=>d[i]); 2import{_ as d}from"./vendor-BlB_7aU1.js";import{P as i,X as n,bx as _}from"./index-CBfKlGil.js";import{c as y,A as g}from"./avatarCompression-Dv1BltQR.js";import{p as w}from"./usePatientData-BbPf1ho0.js";import"./imageCompression-DyMrhjXP.js";function p(a){if(a)try{_.invalidateQueries({queryKey:["profile",a]})}catch{}}function l(){try{_.invalidateQueries({queryKey:w.all})}catch{}}async function A(a,r){const{error:t}=await i.rpc("bump_profile_avatar",{p_user_id:a,p_avatar_url:r});if(t){n.warn("[syncAvatar] Failed to bump_profile_avatar:",t.message);return}p(a)}async function b(a,r){const{data:t,error:e}=await i.from("patients").select("id").eq("user_id",a).maybeSingle();if(e){n.warn("[syncAvatar] Failed to lookup patient by user_id:",e.message);return}if(!(t!=null&&t.id))return;const{error:o}=await i.rpc("bump_patient_avatar",{p_patient_id:t.id,p_avatar_url:r});if(o){n.warn("[syncAvatar] Failed to bump_patient_avatar:",o.message);return}l()}async function P(a,r){const{error:t}=await i.rpc("bump_patient_avatar",{p_patient_id:a,p_avatar_url:r});if(t)throw n.error("[syncAvatar] Failed to bump_patient_avatar:",t.message),t;l();const{data:e}=await i.from("patients").select("user_id").eq("id",a).maybeSingle();e!=null&&e.user_id&&(await A(e.user_id,r),p(e.user_id))}async function E(a,r){const{error:t}=await i.rpc("bump_profile_avatar",{p_user_id:a,p_avatar_url:r});if(t)throw n.error("[syncAvatar] Failed to bump_profile_avatar:",t.message),t;p(a),await b(a,r)}const c="avatars",h=10*1024*1024,C="31536000";function T(a){if(!a.type||!a.type.startsWith("image/"))throw new Error("invalid_image_type");if(a.size>h)throw new Error("image_too_large")}function F(a){return a.kind==="profile"?`${a.userId}/avatar.jpg`:`patients/${a.patientId}/avatar.jpg`}async function G(a,r){T(a);const t=await y(a),e=F(r),{error:o}=await i.storage.from(c).upload(e,t,{upsert:!0,contentType:g,cacheControl:C});if(o)throw n.warn("[uploadAvatar] storage.upload failed:",o.message),o;const{safeGetAvatarPublicUrl:m}=await d(async()=>{const{safeGetAvatarPublicUrl:v}=await import("./avatarHealth-CH6NeMcj.js");return{safeGetAvatarPublicUrl:v}},__vite__mapDeps([0,1,2,3,4])),{publicUrl:u,ok:f}=m(c,e);if(!f||!u)throw new Error("public_url_unavailable");const s=u;return r.kind==="profile"?await E(r.userId,s):await P(r.patientId,s),{publicUrl:s,storagePath:e}}function K(a){const r=a instanceof Error?a.message:String(a);return r==="invalid_image_type"?"Selecione um arquivo de imagem (PNG, JPG ou WEBP).":r==="image_too_large"?"A imagem deve ter no máximo 10MB.":"Não foi possÃvel atualizar a foto. Tente novamente."}export{G as uploadAvatar,K as uploadAvatarErrorMessage};
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.