1import{f as X,D as ee,u as te,g as se,r as i,h as oe,L as ne,c as l,a as e,i as b,b as L,w as R,j as n,t as r,d as $,F as T,k as F,s as ae,l as le,m as g,v as x,I as re,e as de,o as d}from"#entry";import{p as ie,D as z,t as ue,_ as ce}from"./DO1Ijhay.js";import{u as me}from"./Dy9pVEbO.js";import{u as q}from"./Z8EQgydt.js";import"./DKLWY9DJ.js";const be={class:"min-h-screen bg-gray-50 py-8"},ve={class:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"},ge={class:"mb-8 flex justify-between items-center"},fe={class:"text-gray-600 mt-2"},pe={key:0,class:"text-center py-12"},xe={key:1,class:"space-y-4"},_e={class:"flex justify-between items-start"},ye={class:"flex-1"},he={class:"flex items-start justify-between mb-4"},we={class:"flex items-start"},ke={class:"text-xl font-semibold text-gray-900"},De={class:"text-sm text-gray-500 mt-1"},Ve={key:0,class:"inline-block mt-2 px-2 py-1 bg-red-100 text-red-800 text-xs font-semibold rounded"},Ce={key:1,class:"inline-block mt-2 px-2 py-1 bg-green-100 text-green-800 text-xs font-semibold rounded"},Me={class:"flex space-x-2 ml-4"},Ne=["onClick"],je=["onClick"],Ae={class:"grid md:grid-cols-3 gap-4 text-sm"},Be={key:0},Se={class:"text-gray-900 font-mono"},Ue={key:1},Ee={class:"text-gray-900"},Le={key:2},$e={class:"text-gray-900"},Te={key:0,class:"mt-4 pt-4 border-t border-gray-200"},qe={class:"text-gray-700 text-sm"},He={key:2,class:"bg-white rounded-lg shadow-md p-12 text-center"},Pe={class:"text-gray-600 mb-6"},Ie={key:0,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50"},Re={class:"bg-white rounded-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto"},Fe={class:"p-6"},ze={class:"flex justify-between items-center mb-6"},Ge={class:"text-2xl font-bold text-gray-900"},Ke={class:"space-y-4"},Oe={class:"grid md:grid-cols-2 gap-4"},Ye=["value"],Ze={class:"text-sm text-gray-500 mt-1"},Je={key:0,class:"mt-4 p-4 bg-red-50 border border-red-200 rounded-lg"},Qe={class:"text-red-800"},We={class:"mt-6 flex justify-end space-x-4"},Xe=["disabled"],et={key:1,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50"},tt={class:"bg-white rounded-lg max-w-md w-full p-6"},st={class:"flex justify-end space-x-4"},ot=["disabled"],ut=X({__name:"vaccinations",setup(nt){const G=ee(),f=te(),H=se(),_=G.params.id,c=i(""),v=i(1),y=i(0);me(()=>({title:c.value?`Vaccinations â ${c.value}`:"Dog Vaccinations",description:c.value?`Track ${c.value}âs vaccination schedule on DogHealthy â UK dog vaccine records and reminders.`:"Track dog vaccinations on DogHealthy with records and reminders for UK owners.",index:!1}));const h=i([]),S=i([]),V=i(!0),w=i(!1),C=i(!1),u=i(null),M=i(null),k=i(!1),N=i(!1),D=i(""),a=i({vaccine_name:"",administered_date:"",next_due_date:"",batch_number:"",vet_id:"",cost:null,notes:""}),K=async()=>{const{data:s}=await f.from("doghealthy_dogs").select("name").eq("id",_).single();s&&(c.value=s.name)},O=async()=>{const{data:s}=await f.from("doghealthy_vets").select("id, name, clinic_name").eq("user_id",H.userId).order("is_primary",{ascending:!1}).order("name");s&&(S.value=s)},j=async()=>{try{V.value=!0;const{from:s,to:t}=ie(v.value,z),{data:p,error:A,count:o}=await f.from("doghealthy_vaccinations").select("*",{count:"exact"}).eq("dog_id",_).order("vaccination_date",{ascending:!1}).range(s,t);if(A)throw A;y.value=o||0;const B=ue(y.value,z);if(v.value>B){v.value=B;return}const I=new Map;for(const m of S.value||[])I.set(m.id,m.name);h.value=(p||[]).map(m=>({...m,administered_date:m.administered_date||m.vaccination_date||null,vet_name:m.vet_id&&I.get(m.vet_id)||null}))}catch(s){console.error("Error fetching vaccinations:",s),h.value=[],y.value=0}finally{V.value=!1}},U=s=>s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"",Y=s=>{if(!s)return!1;const t=new Date;return new Date(s)<=t},Z=s=>{u.value=s,a.value={vaccine_name:s.vaccine_name,administered_date:s.administered_date,next_due_date:s.next_due_date||"",batch_number:s.batch_number||"",vet_id:s.vet_id||"",cost:s.cost,notes:s.notes||""},w.value=!0},E=()=>{w.value=!1,u.value=null,a.value={vaccine_name:"",administered_date:"",next_due_date:"",batch_number:"",vet_id:"",cost:null,notes:""},D.value=""},P=async()=>{const{ensureCanCreate:s}=q();await s("vaccinations",h.value.length)&&(u.value=null,w.value=!0)},J=async()=>{try{if(k.value=!0,D.value="",!u.value){const{ensureCanCreate:t}=q();if(!await t("vaccinations",h.value.length)){k.value=!1;return}}const s={dog_id:_,user_id:H.userId,vaccine_name:a.value.vaccine_name,administered_date:a.value.administered_date,vaccination_date:a.value.administered_date,next_due_date:a.value.next_due_date||null,batch_number:a.value.batch_number||null,vet_id:a.value.vet_id||null,cost:a.value.cost,notes:a.value.notes||null};if(u.value){const{error:t}=await f.from("doghealthy_vaccinations").update(s).eq("id",u.value.id);if(t)throw t}else{const{error:t}=await f.from("doghealthy_vaccinations").insert(s);if(t)throw t}await j(),E()}catch(s){console.error("Error saving vaccination:",s),D.value=s.message||"Failed to save vaccination"}finally{k.value=!1}},Q=s=>{M.value=s,C.value=!0},W=async()=>
1{if(M.value)try{N.value=!0;const{error:s}=await f.from("doghealthy_vaccinations").delete().eq("id",M.value.id);if(s)throw s;await j(),C.value=!1,M.value=null}catch(s){console.error("Error deleting vaccination:",s),alert("Failed to delete vaccination")}finally{N.value=!1}};return oe(async()=>{K(),O(),j();const{resumeAddUi:s}=q();await s(()=>{u.value=null,w.value=!0})}),ne(v,j),(s,t)=>{const p=de,A=ce;return d(),l(T,null,[e("div",be,[e("div",ve,[L(p,{to:`/dogs/${n(_)}`,class:"text-blue-600 hover:text-blue-700 font-medium mb-6 inline-flex items-center"},{default:R(()=>[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)),$(" Back to "+r(n(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"},"Vaccinations",-1)),e("p",fe,"Track vaccination history for "+r(n(c)),1)]),e("button",{onClick:P,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),$(" Add Vaccination ",-1)])])]),n(V)?(d(),l("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 vaccinations...",-1)])])):n(y)>0?(d(),l("div",xe,[(d(!0),l(T,null,F(n(h),o=>(d(),l("div",{key:o.id,class:"bg-white rounded-lg shadow-md p-6"},[e("div",_e,[e("div",ye,[e("div",he,[e("div",we,[t[13]||(t[13]=e("div",{class:"w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center text-2xl mr-4"}," ð ",-1)),e("div",null,[e("h3",ke,r(o.vaccine_name),1),e("p",De,"Given on "+r(U(o.administered_date)),1),Y(o.next_due_date)?(d(),l("span",Ve," Due "+r(U(o.next_due_date)),1)):o.next_due_date?(d(),l("span",Ce," Next due "+r(U(o.next_due_date)),1)):b("",!0)])]),e("div",Me,[e("button",{onClick:B=>Z(o),class:"text-blue-600 hover:text-blue-700 p-2",title:"Edit"},[...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:"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,Ne),e("button",{onClick:B=>Q(o),class:"text-red-600 hover:text-red-700 p-2",title:"Delete"},[...t[15]||(t[15]=[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,je)])]),e("div",Ae,[o.batch_number?(d(),l("div",Be,[t[16]||(t[16]=e("p",{class:"text-gray-500"},"Batch Number",-1)),e("p",Se,r(o.batch_number),1)])):b("",!0),o.vet_name?(d(),l("div",Ue,[t[17]||(t[17]=e("p",{class:"text-gray-500"},"Administered By",-1)),e("p",Ee,r(o.vet_name),1)])):b("",!0),o.cost?(d(),l("div",Le,[t[18]||(t[18]=e("p",{class:"text-gray-500"},"Cost",-1)),e("p",$e,"£"+r(o.cost),1)])):b("",!0)]),o.notes?(d(),l("div",Te,[t[19]||(t[19]=e("p",{class:"text-sm font-medium text-gray-500 mb-2"},"Notes",-1)),e("p",qe,r(o.notes),1)])):b("",!0)])])]))),128)),L(A,{page:n(v),"onUpdate:page":t[0]||(t[0]=o=>ae(v)?v.value=o:null),total:n(y),disabled:n(V)},null,8,["page","total","disabled"])])):(d(),l("div",He,[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 Vaccinations Yet",-1)),e("p",Pe,"Start tracking "+r(n(c))+"'s vaccination history",1),e("button",{onClick:P,class:"bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors"}," Add First Vaccination ")]))])]),n(w)?(d(),l("div",Ie,[e("div",Re,[e("div",Fe,[e("div",ze,[e("h2",Ge,r(n(u)?"Edit Vaccination":"Add Vaccination"),1),e("button",{onClick:E,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(J,["prevent"])},[e("div",Ke,[e("div",null,[t[23]||(t[23]=e("label",{for:"vaccine_name",class:"block text-sm font-medium text-gray-700 mb-2"}
1," Vaccine Name * ",-1)),g(e("input",{id:"vaccine_name","onUpdate:modelValue":t[1]||(t[1]=o=>n(a).vaccine_name=o),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., Rabies, DHPP, Bordetella"},null,512),[[x,n(a).vaccine_name]])]),e("div",Oe,[e("div",null,[t[24]||(t[24]=e("label",{for:"administered_date",class:"block text-sm font-medium text-gray-700 mb-2"}," Date Administered * ",-1)),g(e("input",{id:"administered_date","onUpdate:modelValue":t[2]||(t[2]=o=>n(a).administered_date=o),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),[[x,n(a).administered_date]])]),e("div",null,[t[25]||(t[25]=e("label",{for:"next_due_date",class:"block text-sm font-medium text-gray-700 mb-2"}," Next Due Date ",-1)),g(e("input",{id:"next_due_date","onUpdate:modelValue":t[3]||(t[3]=o=>n(a).next_due_date=o),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),[[x,n(a).next_due_date]])])]),e("div",null,[t[26]||(t[26]=e("label",{for:"batch_number",class:"block text-sm font-medium text-gray-700 mb-2"}," Batch/Lot Number ",-1)),g(e("input",{id:"batch_number","onUpdate:modelValue":t[4]||(t[4]=o=>n(a).batch_number=o),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:"Enter batch or lot number"},null,512),[[x,n(a).batch_number]])]),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)),g(e("select",{id:"vet_id","onUpdate:modelValue":t[5]||(t[5]=o=>n(a).vet_id=o),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)),(d(!0),l(T,null,F(n(S),o=>(d(),l("option",{key:o.id,value:o.id},r(o.name)+r(o.clinic_name?` - ${o.clinic_name}`:""),9,Ye))),128))],512),[[re,n(a).vet_id]]),e("p",Ze,[L(p,{to:`/dogs/${n(_)}/vets`,class:"text-blue-600 hover:underline"},{default:R(()=>[...t[28]||(t[28]=[$(" 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)),g(e("input",{id:"cost","onUpdate:modelValue":t[6]||(t[6]=o=>n(a).cost=o),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),[[x,n(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)),g(e("textarea",{id:"notes","onUpdate:modelValue":t[7]||(t[7]=o=>n(a).notes=o),rows:"3",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Any reactions or additional information..."},null,512),[[x,n(a).notes]])])]),n(D)?(d(),l("div",Je,[e("p",Qe,r(n(D)),1)])):b("",!0),e("div",We,[e("button",{type:"button",onClick:E,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:n(k),class:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50"},r(n(k)?"Saving...":n(u)?"Update":"Add"),9,Xe)])],32)])])])):b("",!0),n(C)?(d(),l("div",et,[e("div",tt,[t[32]||(t[32]=e("h3",{class:"text-xl font-bold text-gray-900 mb-4"},"Delete Vaccination",-1)),t[33]||(t[33]=e("p",{class:"text-gray-600 mb-6"},"Are you sure you want to delete this vaccination record? This action cannot be undone.",-1)),e("div",st,[e("button",{onClick:t[8]||(t[8]=o=>C.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:W,disabled:n(N),class:"px-6 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50"},r(n(N)?"Deleting...":"Delete"),9,ot)])])])):b("",!0)],64)}}});
1export{ut 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.