1import{f as st,D as ot,u as nt,g as lt,r as p,q as Y,h as at,L as rt,c as a,a as t,i as u,b as B,w as Z,j as n,t as i,d as E,F as U,k as N,s as it,l as dt,m as g,v as h,I as J,e as ut,o as r}from"#entry";import{p as pt,D as K,t as ct,_ as mt}from"./DO1Ijhay.js";import{u as gt}from"./Dy9pVEbO.js";import{u as q}from"./Z8EQgydt.js";import"./DKLWY9DJ.js";const vt={class:"min-h-screen bg-gray-50 py-8"},xt={class:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"},ft={class:"mb-8 flex justify-between items-center"},bt={class:"text-gray-600 mt-2"},yt={key:0,class:"text-center py-12"},_t={key:1},ht={key:0,class:"mb-8"},wt={class:"space-y-4"},kt={class:"flex justify-between items-start"},Ct={class:"flex-1"},Dt={class:"flex items-start justify-between mb-4"},At={class:"flex items-start"},St={class:"text-xl font-semibold text-gray-900"},Mt={class:"text-sm text-gray-600 mt-1"},jt={key:0,class:"inline-block mt-2 px-2 py-1 bg-blue-100 text-blue-800 text-xs font-semibold rounded"},Vt={key:1,class:"inline-block mt-2 px-2 py-1 bg-green-100 text-green-800 text-xs font-semibold rounded"},Lt={class:"flex space-x-2 ml-4"},Ut=["onClick"],$t=["onClick"],Tt={class:"grid md:grid-cols-2 gap-4 text-sm"},Bt={key:0},Et={class:"text-gray-900"},Nt={key:1},qt={class:"text-gray-900"},Ht={key:0,class:"mt-4 pt-4 border-t border-gray-200"},Pt={key:0,class:"mb-2"},It={class:"text-gray-700 text-sm"},Rt={key:1},Ft={class:"text-gray-700 text-sm"},zt={key:1},Ot={class:"space-y-4"},Gt={class:"flex justify-between items-start"},Yt={class:"flex-1"},Zt={class:"flex items-start justify-between mb-4"},Jt={class:"flex items-start"},Kt={class:"text-xl font-semibold text-gray-900"},Qt={class:"text-sm text-gray-600 mt-1"},Wt={key:0,class:"inline-block mt-2 px-2 py-1 bg-gray-100 text-gray-800 text-xs font-semibold rounded"},Xt={key:1,class:"inline-block mt-2 px-2 py-1 bg-red-100 text-red-800 text-xs font-semibold rounded"},te={class:"flex space-x-2 ml-4"},ee=["onClick"],se=["onClick"],oe={class:"grid md:grid-cols-2 gap-4 text-sm"},ne={key:0},le={class:"text-gray-900"},ae={key:1},re={class:"text-gray-900"},ie={key:0,class:"mt-4 pt-4 border-t border-gray-200"},de={class:"text-gray-700 text-sm"},ue={key:2,class:"bg-white rounded-lg shadow-md p-12 text-center"},pe={class:"text-gray-600 mb-6"},ce={key:0,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50"},me={class:"bg-white rounded-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto"},ge={class:"p-6"},ve={class:"flex justify-between items-center mb-6"},xe={class:"text-2xl font-bold text-gray-900"},fe={class:"space-y-4"},be={class:"grid md:grid-cols-2 gap-4"},ye=["value"],_e={class:"text-sm text-gray-500 mt-1"},he={key:0,class:"mt-4 p-4 bg-red-50 border border-red-200 rounded-lg"},we={class:"text-red-800"},ke={class:"mt-6 flex justify-end space-x-4"},Ce=["disabled"],De={key:1,class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50"},Ae={class:"bg-white rounded-lg max-w-md w-full p-6"},Se={class:"flex justify-end space-x-4"},Me=["disabled"],Be=st({__name:"appointments",setup(je){const Q=ot(),f=nt(),H=lt(),w=Q.params.id,m=p(""),v=p(1),k=p(0);gt(()=>({title:m.value?`Appointments â ${m.value}`:"Dog Appointments",description:m.value?`Schedule and track vet appointments for ${m.value} with DogHealthy.`:"Schedule and track dog vet appointments with DogHealthy.",index:!1}));const b=p([]),$=p([]),S=p(!0),C=p(!1),M=p(!1),c=p(null),j=p(null),D=p(!1),V=p(!1),A=p(""),l=p({title:"",appointment_date:"",appointment_time:"",purpose:"",vet_id:"",location:"",status:"scheduled",notes:""}),P=Y(()=>{const o=new Date;return b.value.filter(e=>new Date(e.appointment_date)>=o&&(e.status==="scheduled"||e.status==="confirmed"))}),I=Y(()=>{const o=new Date;return b.value.filter(e=>new Date(e.appointment_date)<o||e.status==="completed"||e.status==="cancelled")}),W=async()=>{const{data:o}=await f.from("doghealthy_dogs").select("name").eq("id",w).single();o&&(m.value=o.name)},X=async()=>{const{data:o}=await f.from("doghealthy_vets").select("id, name, clinic_name").eq("user_id",H.userId).order("is_primary",{ascending:!1}).order("name");o&&($.value=o)},L=async()=>{try{S.value=!0;const{from:o,to:e}=pt(v.value,K),{data:d,error:x,count:s}=await f.from("doghealthy_appointments").select("*",{count:"exact"}).eq("dog_id",w).order("appointment_date",{ascending:!1}).range(o,e);if(x)throw x;k.value=s||0;const y=ct(k.value,K);if(v.value>y){v.value=y;return}const G=new Map;for(const _ of $.value||[])G.set(_.id,_.name);b.value=(d||[]).map(_=>({..._,vet_name:_.vet_id&&G.get(_.vet_id)||null}))}catch(o){console.error("Error fetching appointments:",o),b.value=[],k.value=0}finally{S.value=!1}},R=o=>
1new Date(o).toLocaleString("en-US",{weekday:"short",year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),F=o=>{c.value=o;const e=new Date(o.appointment_date),d=e.toISOString().split("T")[0],x=e.toTimeString().slice(0,5);l.value={title:o.title,appointment_date:d,appointment_time:x,purpose:o.purpose||"",vet_id:o.vet_id||"",location:o.location||"",status:o.status,notes:o.notes||""},C.value=!0},T=()=>{C.value=!1,c.value=null,l.value={title:"",appointment_date:"",appointment_time:"",purpose:"",vet_id:"",location:"",status:"scheduled",notes:""},A.value=""},z=async()=>{const{ensureCanCreate:o}=q();await o("appointments",b.value.length)&&(c.value=null,C.value=!0)},tt=async()=>{try{if(D.value=!0,A.value="",!c.value){const{ensureCanCreate:d}=q();if(!await d("appointments",b.value.length)){D.value=!1;return}}const o=`${l.value.appointment_date}T${l.value.appointment_time}:00`,e={dog_id:w,user_id:H.userId,title:l.value.title,appointment_date:o,appointment_type:l.value.purpose||"general",purpose:l.value.purpose||null,vet_id:l.value.vet_id||null,location:l.value.location||null,status:l.value.status,notes:l.value.notes||null};if(c.value){const{error:d}=await f.from("doghealthy_appointments").update(e).eq("id",c.value.id);if(d)throw d}else{const{error:d}=await f.from("doghealthy_appointments").insert(e);if(d)throw d}await L(),T()}catch(o){console.error("Error saving appointment:",o),A.value=o.message||"Failed to save appointment"}finally{D.value=!1}},O=o=>{j.value=o,M.value=!0},et=async()=>{if(j.value)try{V.value=!0;const{error:o}=await f.from("doghealthy_appointments").delete().eq("id",j.value.id);if(o)throw o;await L(),M.value=!1,j.value=null}catch(o){console.error("Error deleting appointment:",o),alert("Failed to delete appointment")}finally{V.value=!1}};return at(async()=>{W(),X(),L();const{resumeAddUi:o}=q();await o(()=>{c.value=null,C.value=!0})}),rt(v,L),(o,e)=>{const d=ut,x=mt;return r(),a(U,null,[t("div",vt,[t("div",xt,[B(d,{to:`/dogs/${n(w)}`,class:"text-blue-600 hover:text-blue-700 font-medium mb-6 inline-flex items-center"},{default:Z(()=>
1[e[10]||(e[10]=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)),E(" Back to "+i(n(m)||"Dog"),1)]),_:1},8,["to"]),t("div",ft,[t("div",null,[e[11]||(e[11]=t("h1",{class:"text-3xl font-bold text-gray-900"},"Appointments",-1)),t("p",bt,"Manage vet appointments for "+i(n(m)),1)]),t("button",{onClick:z,class:"bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors inline-flex items-center"},[...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:"M12 6v6m0 0v6m0-6h6m-6 0H6"})],-1),E(" Add Appointment ",-1)])])]),n(S)?(r(),a("div",yt,[...e[13]||(e[13]=[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 appointments...",-1)])])):n(k)>0?(r(),a("div",_t,[n(P).length>0?(r(),a("div",ht,[e[21]||(e[21]=t("h2",{class:"text-xl font-semibold text-gray-900 mb-4"},"Upcoming Appointments",-1)),t("div",wt,[(r(!0),a(U,null,N(n(P),s=>(r(),a("div",{key:s.id,class:"bg-white rounded-lg shadow-md p-6 border-l-4 border-blue-500"},[t("div",kt,[t("div",Ct,[t("div",Dt,[t("div",At,[e[14]||(e[14]=t("div",{class:"w-12 h-12 bg-green-100 rounded-full flex items-center justify-center text-2xl mr-4"}," ð
",-1)),t("div",null,[t("h3",St,i(s.title),1),t("p",Mt,i(R(s.appointment_date)),1),s.status==="scheduled"?(r(),a("span",jt," Scheduled ")):s.status==="confirmed"?(r(),a("span",Vt," Confirmed ")):u("",!0)])]),t("div",Lt,[t("button",{onClick:y=>F(s),class:"text-blue-600 hover:text-blue-700 p-2",title:"Edit"},[...e[15]||(e[15]=[t("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("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,Ut),t("button",{onClick:y=>O(s),class:"text-red-600 hover:text-red-700 p-2",title:"Delete"},[...e[16]||(e[16]=[t("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("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,$t)])]),t("div",Tt,[s.vet_name?(r(),a("div",Bt,[e[17]||(e[17]=t("p",{class:"text-gray-500"},"Veterinarian",-1)),t("p",Et,i(s.vet_name),1)])):u("",!0),s.location?(r(),a("div",Nt,[e[18]||(e[18]=t("p",{class:"text-gray-500"},"Location",-1)),t("p",qt,i(s.location),1)])):u("",!0)]),s.purpose||s.notes?(r(),a("div",Ht,[s.purpose?(r(),a("div",Pt,[e[19]||(e[19]=t("p",{class:"text-sm font-medium text-gray-500"},"Purpose",-1)),t("p",It,i(s.purpose),1)])):u("",!0),s.notes?(r(),a("div",Rt,[e[20]||(e[20]=t("p",{class:"text-sm font-medium text-gray-500"},"Notes",-1)),t("p",Ft,i(s.notes),1)])):u("",!0)])):u("",!0)])])]))),128))])])):u("",!0),n(I).length>0?(r(),a("div",zt,[e[28]||(e[28]=t("h2",{class:"text-xl font-semibold text-gray-900 mb-4"},"Past Appointments",-1)),t("div",Ot,[(r(!0),a(U,null,N(n(I),s=>(r(),a("div",{key:s.id,class:"bg-white rounded-lg shadow-md p-6 opacity-75"},[t("div",Gt,[t("div",Yt,[t("div",Zt,[t("div",Jt,[e[22]||(e[22]=t("div",{class:"w-12 h-12 bg-gray-100 rounded-full flex items-center justify-center text-2xl mr-4"}," ð
",-1)),t("div",null,[t("h3",Kt,i(s.title),1),t("p",Qt,i(R(s.appointment_date)),1),s.status==="completed"?(r(),a("span",Wt," Completed ")):s.status==="cancelled"?(r(),a("span",Xt," Cancelled ")):u("",!0)])]),t("div",te,[t("button",{onClick:y=>F(s),class:"text-blue-600 hover:text-blue-700 p-2",title:"Edit"},[...e[23]||(e[23]=[t("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("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,ee),t("button",{onClick:y=>O(s),class:"text-red-600 hover:text-red-700 p-2",title:"Delete"},[...e[24]||(e[24]=[t("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("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,se)])]),t("div",oe,[s.vet_name?(r(),a("div",ne,[e[25]||(e[25]=t("p",{class:"text-gray-500"},"Veterinarian",-1)),t("p",le,i(s.vet_name),1)])):u("",!0),s.location?(r(),a("div",ae,[e[26]||(e[26]=t("p",{class:"text-gray-500"},"Location",-1)),t("p",re,i(s.location),1)])):u("",!0)]),s.purpose?(r(),a("div",ie,[e[27]||(e[27]=t("p",{class:"text-sm font-medium text-gray-500"},"Purpose",-1)),t("p",de,i(s.purpose),1)])):u("",!0)])])]))),128))])])):u("",!0),B(x,{page:n(v),"onUpdate:page":e[0]||(e[0]=s=>it(v)?v.value=s:null),total:n(k),disabled:n(S)},null,8,["page","total","disabled"])])):(r(),a("div",ue,[e[29]||(e[29]=t("div",{class:"text-6xl mb-4"},"ð
",-1)),e[30]||(e[30]=t("h3",{class:"text-xl font-semibold text-gray-900 mb-2"},"No Appointments Yet",-1)),t("p",pe,"Schedule vet appointments for "+i(n(m)),1),t("button",{onClick:z,class:"bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg font-semibold transition-colors"}," Add First Appointment ")]))])]),n(C)?(r(),a("div",ce,[t("div",me,[t("div",ge,[t("div",ve,[t("h2",xe,i(n(c)?"Edit Appointment":"Add Appointment"),1),t("button",{onClick:T,class:"text-gray-400 hover:text-gray-600"},[...e[31]||(e[31]=[t("svg",{class:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])]),t("form",{onSubmit:dt(tt,["prevent"])},[t("div",fe,[t("div",null,[e[32]||(e[32]=t("label",{for:"title",class:"block text-sm font-medium text-gray-700 mb-2"}," Title * ",-1)),g(t("input",{id:"title","onUpdate:modelValue":e[1]||(e[1]=s=>n(l).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, Dental Cleaning"},null,512),[[h,n(l).title]])]),t("div",be,[t("div",null,[e[33]||(e[33]=t("label",{for:"appointment_date",class:"block text-sm font-medium text-gray-700 mb-2"}," Date * ",-1)),g(t("input",{id:"appointment_date","onUpdate:modelValue":e[2]||(e[2]=s=>n(l).appointment_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),[[h,n(l).appointment_date]])]),t("div",null,[e[34]||(e[34]=t("label",{for:"appointment_time",class:"block text-sm font-medium text-gray-700 mb-2"}
1," Time * ",-1)),g(t("input",{id:"appointment_time","onUpdate:modelValue":e[3]||(e[3]=s=>n(l).appointment_time=s),type:"time",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),[[h,n(l).appointment_time]])])]),t("div",null,[e[35]||(e[35]=t("label",{for:"purpose",class:"block text-sm font-medium text-gray-700 mb-2"}," Purpose ",-1)),g(t("input",{id:"purpose","onUpdate:modelValue":e[4]||(e[4]=s=>n(l).purpose=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., Routine checkup, Follow-up"},null,512),[[h,n(l).purpose]])]),t("div",null,[e[38]||(e[38]=t("label",{for:"vet_id",class:"block text-sm font-medium text-gray-700 mb-2"}," Veterinarian ",-1)),g(t("select",{id:"vet_id","onUpdate:modelValue":e[5]||(e[5]=s=>n(l).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"},[e[36]||(e[36]=t("option",{value:""},"Select a vet...",-1)),(r(!0),a(U,null,N(n($),s=>(r(),a("option",{key:s.id,value:s.id},i(s.name)+i(s.clinic_name?` - ${s.clinic_name}`:""),9,ye))),128))],512),[[J,n(l).vet_id]]),t("p",_e,[B(d,{to:`/dogs/${n(w)}/vets`,class:"text-blue-600 hover:underline"},{default:Z(()=>[...e[37]||(e[37]=[E(" Manage vets ",-1)])]),_:1},8,["to"])])]),t("div",null,[e[39]||(e[39]=t("label",{for:"location",class:"block text-sm font-medium text-gray-700 mb-2"}," Location ",-1)),g(t("input",{id:"location","onUpdate:modelValue":e[6]||(e[6]=s=>n(l).location=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:"Clinic name or address"},null,512),[[h,n(l).location]])]),t("div",null,[e[41]||(e[41]=t("label",{for:"status",class:"block text-sm font-medium text-gray-700 mb-2"}," Status ",-1)),g(t("select",{id:"status","onUpdate:modelValue":e[7]||(e[7]=s=>n(l).status=s),class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},[...e[40]||(e[40]=[t("option",{value:"scheduled"},"Scheduled",-1),t("option",{value:"confirmed"},"Confirmed",-1),t("option",{value:"completed"},"Completed",-1),t("option",{value:"cancelled"},"Cancelled",-1)])],512),[[J,n(l).status]])]),t("div",null,[e[42]||(e[42]=t("label",{for:"notes",class:"block text-sm font-medium text-gray-700 mb-2"}," Notes ",-1)),g(t("textarea",{id:"notes","onUpdate:modelValue":e[8]||(e[8]=s=>n(l).notes=s),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:"Reminders, special instructions, etc."},null,512),[[h,n(l).notes]])])]),n(A)?(r(),a("div",he,[t("p",we,i(n(A)),1)])):u("",!0),t("div",ke,[t("button",{type:"button",onClick:T,class:"px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"}," Cancel "),t("button",{type:"submit",disabled:n(D),class:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50"},i(n(D)?"Saving...":n(c)?"Update":"Add"),9,Ce)])],32)])])])):u("",!0),n(M)?(r(),a("div",De,[t("div",Ae,[e[43]||(e[43]=t("h3",{class:"text-xl font-bold text-gray-900 mb-4"},"Delete Appointment",-1)),e[44]||(e[44]=t("p",{class:"text-gray-600 mb-6"},"Are you sure you want to delete this appointment? This action cannot be undone.",-1)),t("div",Se,[t("button",{onClick:e[9]||(e[9]=s=>M.value=!1),class:"px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"}," Cancel "),t("button",{onClick:et,disabled:n(V),class:"px-6 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50"},i(n(V)?"Deleting...":"Delete"),9,Me)])])])):u("",!0)],64)}}});export{Be 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.