1import{f as W,D as O,H as G,u as J,g as K,r as u,h as Q,c as i,a as t,i as _,j as o,b as V,w as F,t as h,l as M,m,v,J as S,e as X,o as d,d as A}from"#entry";import{u as Y}from"./Dy9pVEbO.js";import"./DKLWY9DJ.js";const Z={class:"min-h-screen bg-gray-50 py-8"},ee={class:"max-w-3xl mx-auto px-4 sm:px-6 lg:px-8"},te={key:0,class:"text-center py-12"},oe={key:1},re={class:"mb-8"},se={class:"text-3xl font-bold text-gray-900 mt-4"},le={class:"bg-white rounded-lg shadow-md p-6"},ae={class:"mb-6"},ne={class:"flex items-center space-x-6"},ie={class:"shrink-0"},de=["src","alt"],ue={key:1,class:"h-32 w-32 bg-gray-200 rounded-lg flex items-center justify-center border-2 border-gray-300"},ge={class:"cursor-pointer"},ce={key:0,class:"text-red-600 text-sm mt-2"},me={class:"mb-6"},be={class:"mb-6"},pe={class:"mb-6"},fe={class:"mb-6"},he={class:"flex space-x-4"},ve={class:"flex items-center"},ye={class:"flex items-center"},xe={class:"mb-6"},we={class:"mb-6"},_e={class:"mb-6"},ke={key:0,class:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg"},Pe={class:"text-red-800"},De={key:1,class:"mb-6 p-4 bg-green-50 border border-green-200 rounded-lg"},Ee={class:"flex justify-between"},Ue={class:"flex space-x-4"},Ce=["disabled"],Ne={key:0},Ve={key:1},Fe={key:2,class:"bg-red-50 border border-red-200 rounded-lg p-6"},Me={class:"text-red-600"},Se={class:"text-xl font-semibold text-gray-900 mb-4"},Ae={class:"flex justify-end space-x-4"},Re=W({__name:"edit",setup(Ie){const I=O(),P=G(),p=J(),g=K();Y({title:"Edit Dog Profile",description:"Update your dogâs profile on DogHealthy â breed, weight, microchip and notes for UK pet health tracking.",index:!1});const s=u(null),y=u(!0),f=u(!1),c=u(""),D=u(!1),x=u(!1),l=u({name:"",breed:"",birthDate:"",gender:"",weight:null,microchipNumber:"",notes:""}),b=u(null),k=u(null),w=u(""),E=u(!1),j=u(null),B=async()=>{try{y.value=!0,c.value="";const r=I.params.id;if(console.log("[Edit Page] Fetching dog:",r),console.log("[Edit Page] User ID:",g.userId),!g.userId){console.error("[Edit Page] No user ID available"),c.value="Please log in to edit dogs",y.value=!1;return}const{data:e,error:n}=await p.from("doghealthy_dogs").select("*").eq("id",r).eq("user_id",g.userId).single();if(n){console.error("[Edit Page] Fetch error:",n),c.value="Dog not found or you do not have permission to edit it",y.value=!1;return}console.log("[Edit Page] Dog loaded:",e),s.value=e,l.value={name:e.name,breed:e.breed||"",birthDate:e.birth_date||"",gender:e.gender||"",weight:e.weight_kg,microchipNumber:e.microchip_number||"",notes:e.notes||""},console.log("[Edit Page] Form populated:",l.value)}catch(r){console.error("[Edit Page] Exception:",r),c.value=r.message||"Failed to load dog details"}finally{y.value=!1}},$=r=>{const n=r.target.files?.[0];if(w.value="",!n)return;if(!n.type.startsWith("image/")){w.value="Please select an image file";return}if(n.size>5*1024*1024){w.value="File size must be less than 5MB";return}b.value=n,E.value=!1;const a=new FileReader;a.onload=N=>{k.value=N.target?.result},a.readAsDataURL(n)},R=()=>{E.value=!0,b.value=null,k.value=null},q=async r=>{if(!b.value)return null;try{const e=b.value.name.split(".").pop(),a=`dogs/${`${r}_${Date.now()}.${e}`}`,{data:N,error:C}=await p.storage.from("doghealthy").upload(a,b.value,{cacheControl:"3600",upsert:!1});if(C)throw console.error("Upload error:",C),C;const{data:{publicUrl:H}}=p.storage.from("doghealthy").getPublicUrl(a);return H}catch(e){throw console.error("Error uploading photo:",e),e}},U=async r=>{try{const n=new URL(r).pathname.split("/"),a=n.slice(n.indexOf("dogs")).join("/");await p.storage.from("doghealthy").remove([a])}catch(e){console.error("Error deleting old photo:",e)}},T=async()=>{if(s.value){c.value="",D.value=!1,f.value=!0;try{let r=s.value.photo_url;b.value?(s.value.photo_url&&await U(s.value.photo_url),r=await q(s.value.id)):E.value&&s.value.photo_url&&(await U(s.value.photo_url),r=null);const e={name:l.value.name,breed:l.value.breed||null,birth_date:l.value.birthDate||null,gender:l.value.gender||null,weight_kg:l.value.weight||null,microchip_number:l.value.microchipNumber||null,notes:l.value.notes||null,photo_url:r},{error:n}=await p.from("doghealthy_dogs").update(e).eq("id",s.value.id).eq("user_id",g.userId);if(n)throw console.error("Update error:",n),n;D.value=!0,s.value={...s.value,...e},setTimeout(()=>{P.push(`/dogs/${s.value?.id}`)},1500)}catch(r){console.error("Error updating dog:",r),c.value=r.message||"Failed to update dog. Please try again."}finally{f.value=!1}}},L=()=>{x.value=!0},z=async()=>
1{if(s.value)try{f.value=!0,s.value.photo_url&&await U(s.value.photo_url);const{error:r}=await p.from("doghealthy_dogs").delete().eq("id",s.value.id).eq("user_id",g.userId);if(r)throw console.error("Delete error:",r),r;P.push("/dogs")}catch(r){console.error("Error deleting dog:",r),c.value=r.message||"Failed to delete dog",x.value=!1,f.value=!1}};return Q(async()=>{if(console.log("[Edit Page] Component mounted"),console.log("[Edit Page] Auth loading:",g.loading),console.log("[Edit Page] Authenticated:",g.isAuthenticated),console.log("[Edit Page] User:",g.user),g.loading&&(console.log("[Edit Page] Waiting for auth to initialize..."),await new Promise(r=>setTimeout(r,1e3))),console.log("[Edit Page] After wait - Authenticated:",g.isAuthenticated),!g.isAuthenticated){console.log("[Edit Page] Not authenticated, redirecting to login"),P.push("/auth/login");return}console.log("[Edit Page] Starting fetchDog"),await B()}),(r,e)=>{const n=X;return d(),i("div",Z,[t("div",ee,[o(y)&&!o(s)?(d(),i("div",te,[...e[11]||(e[11]=[t("div",{class:"inline-block animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"},null,-1),t("p",{class:"mt-4 text-gray-600"},"Loading...",-1)])])):o(s)?(d(),i("div",oe,[t("div",re,[V(n,{to:`/dogs/${o(s).id}`,class:"text-blue-600 hover:text-blue-700 font-medium mb-4 inline-flex items-center"},{default:F(()=>[e[12]||(e[12]=t("svg",{class:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 19l-7-7m0 0l7-7m-7 7h18"})],-1)),A(" Back to "+h(o(s).name),1)]),_:1},8,["to"]),t("h1",se,"Edit "+h(o(s).name),1),e[13]||(e[13]=t("p",{class:"text-gray-600 mt-2"},"Update your dog's information",-1))]),t("div",le,[t("form",{onSubmit:M(T,["prevent"])},[t("div",ae,[e[16]||(e[16]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Dog Photo ",-1)),t("div",ne,[t("div",ie,[o(k)||o(s).photo_url?(d(),i("img",{key:0,src:o(k)||o(s).photo_url,alt:o(s).name,class:"h-32 w-32 object-cover rounded-lg border-2 border-gray-300"},null,8,de)):(d(),i("div",ue,[...e[14]||(e[14]=[t("svg",{class:"h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})],-1)])]))]),t("div",null,[t("label",ge,[e[15]||(e[15]=t("span",{class:"bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition-colors inline-block"}," Change Photo ",-1)),t("input",{type:"file",ref_key:"fileInput",ref:j,accept:"image/*",onChange:$,class:"hidden"},null,544)]),o(s).photo_url&&!o(b)?(d(),i("button",{key:0,onClick:R,type:"button",class:"ml-2 text-red-600 hover:text-red-700 text-sm"}," Remove Photo ")):_("",!0)])]),o(w)?(d(),i("p",ce,h(o(w)),1)):_("",!0)]),t("div",me,[e[17]||(e[17]=t("label",{for:"name",class:"block text-sm font-medium text-gray-700 mb-2"}," Dog Name * ",-1)),m(t("input",{id:"name","onUpdate:modelValue":e[0]||(e[0]=a=>o(l).name=a),type:"text",required:"",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[v,o(l).name]])]),t("div",be,[e[18]||(e[18]=t("label",{for:"breed",class:"block text-sm font-medium text-gray-700 mb-2"}," Breed ",-1)),m(t("input",{id:"breed","onUpdate:modelValue":e[1]||(e[1]=a=>o(l).breed=a),type:"text",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[v,o(l).breed]])]),t("div",pe,[e[19]||(e[19]=t("label",{for:"birthDate",class:"block text-sm font-medium text-gray-700 mb-2"}," Date of Birth ",-1)),m(t("input",{id:"birthDate","onUpdate:modelValue":e[2]||(e[2]=a=>o(l).birthDate=a),type:"date",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[v,o(l).birthDate]])]),t("div",fe,[e[22]||(e[22]=t("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Gender ",-1)),t("div",he,[t("label",ve,[m(t("input",{"onUpdate:modelValue":e[3]||(e[3]=a=>o(l).gender=a),type:"radio",value:"male",class:"mr-2 text-blue-600 focus:ring-blue-500"},null,512),[[S,o(l).gender]]),e[20]||(e[20]=t("span",{class:"text-gray-700"},"Male",-1))]),t("label",ye,[m(t("input",{"onUpdate:modelValue":e[4]||(e[4]=a=>
1o(l).gender=a),type:"radio",value:"female",class:"mr-2 text-blue-600 focus:ring-blue-500"},null,512),[[S,o(l).gender]]),e[21]||(e[21]=t("span",{class:"text-gray-700"},"Female",-1))])])]),t("div",xe,[e[23]||(e[23]=t("label",{for:"weight",class:"block text-sm font-medium text-gray-700 mb-2"}," Weight (kg) ",-1)),m(t("input",{id:"weight","onUpdate:modelValue":e[5]||(e[5]=a=>o(l).weight=a),type:"number",step:"0.1",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[v,o(l).weight,void 0,{number:!0}]])]),t("div",we,[e[24]||(e[24]=t("label",{for:"microchipNumber",class:"block text-sm font-medium text-gray-700 mb-2"}," Microchip Number ",-1)),m(t("input",{id:"microchipNumber","onUpdate:modelValue":e[6]||(e[6]=a=>o(l).microchipNumber=a),type:"text",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[v,o(l).microchipNumber]])]),t("div",_e,[e[25]||(e[25]=t("label",{for:"notes",class:"block text-sm font-medium text-gray-700 mb-2"}," Notes ",-1)),m(t("textarea",{id:"notes","onUpdate:modelValue":e[7]||(e[7]=a=>o(l).notes=a),rows:"4",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[v,o(l).notes]])]),o(c)?(d(),i("div",ke,[t("p",Pe,h(o(c)),1)])):_("",!0),o(D)?(d(),i("div",De,[...e[26]||(e[26]=[t("p",{class:"text-green-800"},"Changes saved successfully!",-1)])])):_("",!0),t("div",Ee,[t("button",{onClick:L,type:"button",class:"px-6 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors"}," Delete Dog "),t("div",Ue,[V(n,{to:`/dogs/${o(s).id}`,class:"px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"},{default:F(()=>[...e[27]||(e[27]=[A(" Cancel ",-1)])]),_:1},8,["to"]),t("button",{type:"submit",disabled:o(f),class:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[o(f)?(d(),i("span",Ne,"Saving...")):(d(),i("span",Ve,"Save Changes"))],8,Ce)])])],32)])])):(d(),i("div",Fe,[e[28]||(e[28]=t("h2",{class:"text-xl font-semibold text-red-800 mb-2"},"Error",-1)),t("p",Me,h(o(c)||"Failed to load dog details"),1)]))]),o(x)?(d(),i("div",{key:0,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e[10]||(e[10]=a=>x.value=!1)},[t("div",{class:"bg-white rounded-lg p-6 max-w-md mx-4",onClick:e[9]||(e[9]=M(()=>{},["stop"]))},[t("h3",Se,"Delete "+h(o(s)?.name)+"?",1),e[29]||(e[29]=t("p",{class:"text-gray-600 mb-6"}," Are you sure you want to delete this dog? This will also delete all associated health records, vaccinations, medications, and appointments. This action cannot be undone. ",-1)),t("div",Ae,[t("button",{onClick:e[8]||(e[8]=a=>x.value=!1),class:"px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50"}," Cancel "),t("button",{onClick:z,class:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700"}," Delete ")])])])):_("",!0)])}}});export{Re 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.