1import{f as Q,D as W,u as X,g as ee,r as d,h as te,L as se,c as n,a as e,i as m,b as A,w as T,j as l,t as r,d as E,F as U,k as q,s as oe,l as le,m as v,v as f,I as ae,e as ne,o as i}from"#entry";import{p as re,D as I,t as ie,_ as de}from"./DO1Ijhay.js";import{u as ue}from"./Dy9pVEbO.js";import{u as N}from"./Z8EQgydt.js";import"./DKLWY9DJ.js";const ce={class:"min-h-screen bg-gray-50 py-8"},me={class:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"},ge={class:"mb-8 flex justify-between items-center"},ve={class:"text-gray-600 mt-2"},pe={key:0,class:"text-center py-12"},fe={key:1,class:"space-y-4"},be={class:"flex justify-between items-start"},xe={class:"flex-1"},ye={class:"flex items-start justify-between mb-4"},he={class:"text-xl font-semibold text-gray-900"},_e={class:"text-sm text-gray-500 mt-1"},we={class:"flex space-x-2 ml-4"},ke=["onClick"],Ce=["onClick"],De={class:"grid md:grid-cols-2 gap-4 mb-4"},Re={key:0},Me={class:"text-gray-900"},Se={key:1},Ve={class:"text-gray-900"},He={key:2},je={class:"text-gray-900"},Ae={key:3},Ee={class:"text-gray-900"},Ue={key:0,class:"mt-4 pt-4 border-t border-gray-200"},Ne={class:"text-gray-700 whitespace-pre-wrap"},Be={key:2,class:"bg-white rounded-lg shadow-md p-12 text-center"},Le={class:"text-gray-600 mb-6"},$e={key:0,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50"},Te={class:"bg-white rounded-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto"},qe={class:"p-6"},Ie={class:"flex justify-between items-center mb-6"},Pe={class:"text-2xl font-bold text-gray-900"},Fe={class:"space-y-4"},ze=["value"],Ge={class:"text-sm text-gray-500 mt-1"},Oe={key:0,class:"mt-4 p-4 bg-red-50 border border-red-200 rounded-lg"},Ye={class:"text-red-800"},Ze={class:"mt-6 flex justify-end space-x-4"},Je=["disabled"],Ke={key:1,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50"},Qe={class:"bg-white rounded-lg max-w-md w-full p-6"},We={class:"flex justify-end space-x-4"},Xe=["disabled"],nt=Q({__name:"health-records",setup(et){const P=W(),p=X(),B=ee(),b=P.params.id,c=d(""),g=d(1),x=d(0);ue(()=>({title:c.value?`Health Records â ${c.value}`:"Dog Health Records",description:c.value?`Store ${c.value}âs veterinary visits, diagnoses and treatments in DogHealthy.`:"Store dog health records, diagnoses and treatments in DogHealthy.",index:!1}));const y=d([]),L=d([]),C=d(!0),h=d(!1),D=d(!1),u=d(null),R=d(null),_=d(!1),M=d(!1),w=d(""),a=d({title:"",visit_date:"",diagnosis:"",treatment:"",vet_id:"",cost:null,notes:""}),F=async()=>{const{data:o}=await p.from("doghealthy_dogs").select("name").eq("id",b).single();o&&(c.value=o.name)},z=async()=>{const{data:o}=await p.from("doghealthy_vets").select("id, name, clinic_name").eq("user_id",B.userId).order("is_primary",{ascending:!1}).order("name");o&&(L.value=o)},S=async()=>{try{C.value=!0;const{from:o,to:t}=re(g.value,I),{data:k,error:V,count:s}=await p.from("doghealthy_health_records").select("*",{count:"exact"}).eq("dog_id",b).order("record_date",{ascending:!1}).range(o,t);if(V)throw V;x.value=s||0;const H=ie(x.value,I);if(g.value>H){g.value=H;return}y.value=(k||[]).map(K=>({...K,vet_name:null}))}catch(o){console.error("Error fetching health records:",o),y.value=[],x.value=0}finally{C.value=!1}},G=o=>new Date(o).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),O=o=>{u.value=o,a.value={title:o.title,visit_date:o.visit_date||o.record_date,diagnosis:o.diagnosis||"",treatment:o.treatment||"",vet_id:o.vet_id||"",cost:o.cost,notes:o.notes||""},h.value=!0},j=()=>{h.value=!1,u.value=null,a.value={title:"",visit_date:"",diagnosis:"",treatment:"",vet_id:"",cost:null,notes:""},w.value=""},$=async()=>{const{ensureCanCreate:o}=N();await o("health-records",y.value.length)&&(u.value=null,h.value=!0)},Y=async()=>{try{if(_.value=!0,w.value="",!u.value){const{ensureCanCreate:t}=N();if(!await t("health-records",y.value.length)){_.value=!1;return}}const o={dog_id:b,user_id:B.userId,title:a.value.title,record_date:a.value.visit_date,visit_date:a.value.visit_date,record_type:"checkup",diagnosis:a.value.diagnosis||null,treatment:a.value.treatment||null,vet_id:a.value.vet_id||null,cost:a.value.cost,notes:a.value.notes||null};if(u.value){const{error:t}=await p.from("doghealthy_health_records").update(o).eq("id",u.value.id);if(t)throw t}else{const{error:t}=await p.from("doghealthy_health_records").insert(o);if(t)throw t}await S(),j()}catch(o){console.error("Error saving health record:",o),w.value=o.message||"Failed to save health record"}finally{_.value=!1}},Z=o=>{R.value=o,D.value=!0},J=async()=>
1{if(R.value)try{M.value=!0;const{error:o}=await p.from("doghealthy_health_records").delete().eq("id",R.value.id);if(o)throw o;await S(),D.value=!1,R.value=null}catch(o){console.error("Error deleting health record:",o),alert("Failed to delete health record")}finally{M.value=!1}};return te(async()=>{F(),z(),S();const{resumeAddUi:o}=N();await o(()=>{u.value=null,h.value=!0})}),se(g,S),(o,t)=>{const k=ne,V=de;return i(),n(U,null,[e("div",ce,[e("div",me,[A(k,{to:`/dogs/${l(b)}`,class:"text-blue-600 hover:text-blue-700 font-medium mb-6 inline-flex items-center"},{default:T(()=>[t[9]||(t[9]=e("svg",{class:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 19l-7-7m0 0l7-7m-7 7h18"})],-1)),E(" Back to "+r(l(c)||"Dog"),1)]),_:1},8,["to"]),e("div",ge,[e("div",null,[t[10]||(t[10]=e("h1",{class:"text-3xl font-bold text-gray-900"},"Health Records",-1)),e("p",ve,"Track medical history and diagnoses for "+r(l(c)),1)]),e("button",{onClick:$,class:"bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors inline-flex items-center"},[...t[11]||(t[11]=[e("svg",{class:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})],-1),E(" Add Record ",-1)])])]),l(C)?(i(),n("div",pe,[...t[12]||(t[12]=[e("div",{class:"inline-block animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"},null,-1),e("p",{class:"mt-4 text-gray-600"},"Loading health records...",-1)])])):l(x)>0?(i(),n("div",fe,[(i(!0),n(U,null,q(l(y),s=>(i(),n("div",{key:s.id,class:"bg-white rounded-lg shadow-md p-6"},[e("div",be,[e("div",xe,[e("div",ye,[e("div",null,[e("h3",he,r(s.title),1),e("p",_e,r(G(s.visit_date||s.record_date)),1)]),e("div",we,[e("button",{onClick:H=>O(s),class:"text-blue-600 hover:text-blue-700 p-2",title:"Edit"},[...t[13]||(t[13]=[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})],-1)])],8,ke),e("button",{onClick:H=>Z(s),class:"text-red-600 hover:text-red-700 p-2",title:"Delete"},[...t[14]||(t[14]=[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1)])],8,Ce)])]),e("div",De,[s.diagnosis?(i(),n("div",Re,[t[15]||(t[15]=e("p",{class:"text-sm font-medium text-gray-500"},"Diagnosis",-1)),e("p",Me,r(s.diagnosis),1)])):m("",!0),s.treatment?(i(),n("div",Se,[t[16]||(t[16]=e("p",{class:"text-sm font-medium text-gray-500"},"Treatment",-1)),e("p",Ve,r(s.treatment),1)])):m("",!0),s.vet_name?(i(),n("div",He,[t[17]||(t[17]=e("p",{class:"text-sm font-medium text-gray-500"},"Veterinarian",-1)),e("p",je,r(s.vet_name),1)])):m("",!0),s.cost?(i(),n("div",Ae,[t[18]||(t[18]=e("p",{class:"text-sm font-medium text-gray-500"},"Cost",-1)),e("p",Ee,"£"+r(s.cost),1)])):m("",!0)]),s.notes?(i(),n("div",Ue,[t[19]||(t[19]=e("p",{class:"text-sm font-medium text-gray-500 mb-2"},"Notes",-1)),e("p",Ne,r(s.notes),1)])):m("",!0)])])]))),128)),A(V,{page:l(g),"onUpdate:page":t[0]||(t[0]=s=>oe(g)?g.value=s:null),total:l(x),disabled:l(C)},null,8,["page","total","disabled"])])):(i(),n("div",Be,[t[20]||(t[20]=e("div",{class:"text-6xl mb-4"},"ð",-1)),t[21]||(t[21]=e("h3",{class:"text-xl font-semibold text-gray-900 mb-2"},"No Health Records Yet",-1)),e("p",Le,"Start tracking "+r(l(c))+"'s medical history",1),e("button",{onClick:$,class:"bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors"}," Add First Health Record ")]))])]),l(h)?(i(),n("div",$e,[e("div",Te,[e("div",qe,[e("div",Ie,[e("h2",Pe,r(l(u)?"Edit Health Record":"Add Health Record"),1),e("button",{onClick:j,class:"text-gray-400 hover:text-gray-600"},[...t[22]||(t[22]=[e("svg",{class:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])]),e("form",{onSubmit:le(Y,["prevent"])},[e("div",Fe,[e("div",null,[t[23]||(t[23]=e("label",{for:"title",class:"block text-sm font-medium text-gray-700 mb-2"}," Title * ",-1)),v(e("input",{id:"title","onUpdate:modelValue":t[1]||(t[1]=s=>l(a).title=s),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",placeholder:"e.g., Annual Checkup, Ear Infection"},null,512),[[f,l(a).title]])]),e("div",null,[t[24]||(t[24]=e("label",{for:"visit_date",class:"block text-sm font-medium text-gray-700 mb-2"}," Visit Date * ",-1)),v(e("input",{id:"visit_date","onUpdate:modelValue":t[2]||(t[2]=s=>l(a).visit_date=s),type:"date",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),[[f,l(a).visit_date]])]),e("div",null,[t[25]||(t[25]=e("label",{for:"diagnosis",class:"block text-sm font-medium text-gray-700 mb-2"}," Diagnosis ",-1)),v(e("input",{id:"diagnosis","onUpdate:modelValue":t[3]||(t[3]=s=>l(a).diagnosis=s),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",placeholder:"e.g., Ear infection, Healthy"},null,512),[[f,l(a).diagnosis]])]),e("div",null,[t[26]||(t[26]=e("label",{for:"treatment",class:"block text-sm font-medium text-gray-700 mb-2"}," Treatment ",-1)),v(e("input",{id:"treatment","onUpdate:modelValue":t[4]||(t[4]=s=>l(a).treatment=s),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",placeholder:"e.g., Prescribed antibiotics"},null,512),[[f,l(a).treatment]])]),e("div",null,[t[29]||(t[29]=e("label",{for:"vet_id",class:"block text-sm font-medium text-gray-700 mb-2"}," Veterinarian ",-1)),v(e("select",{id:"vet_id","onUpdate:modelValue":t[5]||(t[5]=s=>l(a).vet_id=s),class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},[t[27]||(t[27]=e("option",{value:""},"Select a vet...",-1)),(i(!0),n(U,null,q(l(L),s=>(i(),n("option",{key:s.id,value:s.id},r(s.name)+r(s.clinic_name?` - ${s.clinic_name}`:""),9,ze))),128))],512),[[ae,l(a).vet_id]]),e("p",Ge,[A(k,{to:`/dogs/${l(b)}/vets`,class:"text-blue-600 hover:underline"},{default:T(()=>[...t[28]||(t[28]=[E(" Manage vets ",-1)])]),_:1},8,["to"])])]),e("div",null,[t[30]||(t[30]=e("label",{for:"cost",class:"block text-sm font-medium text-gray-700 mb-2"}," Cost (£) ",-1)),v(e("input",{id:"cost","onUpdate:modelValue":t[6]||(t[6]=s=>l(a).cost=s),type:"number",step:"0.01",min:"0",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"0.00"},null,512),[[f,l(a).cost,void 0,{number:!0}]])]),e("div",null,[t[31]||(t[31]=e("label",{for:"notes",class:"block text-sm font-medium text-gray-700 mb-2"}," Notes ",-1)),v(e("textarea",{id:"notes","onUpdate:modelValue":t[7]||(t[7]=s=>l(a).notes=s),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",placeholder:"Additional notes about the visit..."},null,512),[[f,l(a).notes]])])]),l(w)?(i(),n("div",Oe,[e("p",Ye,r(l(w)),1)])):m("",!0),e("div",Ze,[e("button",{type:"button",onClick:j,class:"px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"}," Cancel "),e("button",{type:"submit",disabled:l(_),class:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50"},r(l(_)?"Saving...":l(u)?"Update":"Add"),9,Je)])],32)])])])):m("",!0),l(D)?(i(),n("div",Ke,[e("div",Qe,[t[32]||(t[32]=e("h3",{class:"text-xl font-bold text-gray-900 mb-4"},"Delete Health Record",-1)),t[33]||(t[33]=e("p",{class:"text-gray-600 mb-6"},"Are you sure you want to delete this health record? This action cannot be undone.",-1)),e("div",We,[e("button",{onClick:t[8]||(t[8]=s=>D.value=!1),class:"px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"}," Cancel "),e("button",{onClick:J,disabled:l(M),class:"px-6 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50"},r(l(M)?"Deleting...":"Delete"),9,Xe)])])])):m("",!0)],64)}}});
1export{nt 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.