1import{f as M,D as $,H as q,u as A,q as F,r as b,h as L,L as I,C as h,w as f,j as o,o as i,a as l,c,i as g,b as R,e as T,d as x,t as y,l as O,m as r,v as n,I as P,n as C}from"#entry";import{_ as j}from"./BRsHvoYg.js";import{u as G}from"./Dy9pVEbO.js";import"./DKLWY9DJ.js";const H={class:"mb-4 flex flex-wrap gap-3 text-sm"},W={key:0,class:"mb-4 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2"},z={key:1,class:"mb-4 text-sm text-green-800 bg-green-50 border border-green-200 rounded-lg px-3 py-2"},J={key:2,class:"text-slate-600 py-8"},K={class:"grid sm:grid-cols-2 gap-4"},Q={class:"sm:col-span-2"},X={class:"flex items-center gap-2 text-sm text-slate-700"},Y={class:"flex items-center gap-2 text-sm text-slate-700"},Z={class:"flex flex-wrap gap-2"},ee=["disabled"],te=["disabled"],le=["disabled"],ne=M({__name:"[id]",setup(oe){const S=$(),V=q(),_=A(),u=F(()=>S.params.id);G({title:"Edit dog â Admin",path:"/admin/dogs",index:!1});const w=b(!0),m=b(!1),v=b(!1),d=b(""),p=b(""),t=b(null),U=async()=>{w.value=!0,d.value="",p.value="";try{const{data:s,error:e}=await _.from("doghealthy_dogs").select("*").eq("id",u.value).maybeSingle();if(e)throw e;if(!s)throw new Error("Dog not found");t.value={user_id:s.user_id,name:s.name||"",breed:s.breed||"",gender:s.gender||"",birth_date:s.birth_date||"",weight_kg:s.weight_kg,color:s.color||"",microchip_number:s.microchip_number||"",photo_url:s.photo_url||"",notes:s.notes||"",is_active:s.is_active!==!1,nfc_tag_enabled:!!s.nfc_tag_enabled}}catch(s){d.value=s?.message||"Failed to load dog",t.value=null}finally{w.value=!1}},D=async()=>{if(t.value){m.value=!0,d.value="",p.value="";try{const{error:s}=await _.from("doghealthy_dogs").update({name:t.value.name.trim(),breed:t.value.breed.trim()||null,gender:t.value.gender||null,birth_date:t.value.birth_date||null,weight_kg:t.value.weight_kg,color:t.value.color.trim()||null,microchip_number:t.value.microchip_number.trim()||null,photo_url:t.value.photo_url.trim()||null,notes:t.value.notes.trim()||null,is_active:t.value.is_active,nfc_tag_enabled:t.value.nfc_tag_enabled}).eq("id",u.value);if(s)throw s;p.value="Dog saved."}catch(s){d.value=s?.message||"Failed to save dog"}finally{m.value=!1}}},N=async()=>{t.value&&confirm(`Deactivate ${t.value.name}?`)&&(t.value.is_active=!1,await D())},E=async()=>{if(t.value&&confirm(`Delete dog â${t.value.name}â and related records? This cannot be undone.`)){v.value=!0,d.value="";try{const s=t.value.user_id,{error:e}=await _.from("doghealthy_dogs").delete().eq("id",u.value);if(e)throw e;s?await V.push(`/admin/users/${s}`):await V.push("/admin/dogs")}catch(s){d.value=s?.message||"Failed to delete dog"}finally{v.value=!1}}};return L(U),I(u,U),(s,e)=>{const k=T,B=j;return i(),h(B,{title:o(t)?.name||"Edit dog",subtitle:"Update this dogâs profile fields."},{default:f(()=>[l("div",H,[R(k,{to:"/admin/dogs",class:"text-blue-700 hover:underline"},{default:f(()=>[...e[11]||(e[11]=[x("â All dogs",-1)])]),_:1}),o(t)?.user_id?(i(),h(k,{key:0,to:`/admin/users/${o(t).user_id}`,class:"text-blue-700 hover:underline"},{default:f(()=>[...e[12]||(e[12]=[x(" Owner profile ",-1)])]),_:1},8,["to"])):g("",!0),o(u)?(i(),h(k,{key:1,to:`/dogs/${o(u)}`,class:"text-slate-600 hover:underline",target:"_blank"},{default:f(()=>[...e[13]||(e[13]=[x(" Open app view ",-1)])]),_:1},8,["to"])):g("",!0)]),o(d)?(i(),c("div",W,y(o(d)),1)):g("",!0),o(p)?(i(),c("div",z,y(o(p)),1)):g("",!0),o(w)?(i(),c("div",J,"Loadingâ¦")):o(t)?(i(),c("form",{key:3,class:"bg-white rounded-xl border border-slate-200 shadow-sm p-6 space-y-5",onSubmit:O(D,["prevent"])},[l("div",K,[l("div",null,[e[14]||(e[14]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Name",-1)),r(l("input",{"onUpdate:modelValue":e[0]||(e[0]=a=>o(t).name=a),required:"",type:"text",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).name]])]),l("div",null,[e[15]||(e[15]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Breed",-1)),r(l("input",{"onUpdate:modelValue":e[1]||(e[1]=a=>o(t).breed=a),type:"text",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).breed]])]),l("div",null,[e[17]||(e[17]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Gender",-1)),r(l("select",{"onUpdate:modelValue":e[2]||(e[2]=a=>o(t).gender=a),class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},[...e[16]||(e[16]=[l("option",{value:""},"â",-1),l("option",{value:"male"},"male",-1),l("option",{value:"female"},"female",-1),l("option",{value:"unknown"},"unknown",-1)])],512),[[P,o(t).gender]])]),l("div",null,[e[18]||(e[18]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Birth date",-1)),r(l("input",{"onUpdate:modelValue":e[3]||(e[3]=a=>o(t).birth_date=a),type:"date",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).birth_date]])]),l("div",null,[e[19]||(e[19]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Weight (kg)",-1)),r(l("input",{"onUpdate:modelValue":e[4]||(e[4]=a=>
1o(t).weight_kg=a),type:"number",step:"0.1",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).weight_kg,void 0,{number:!0}]])]),l("div",null,[e[20]||(e[20]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Colour",-1)),r(l("input",{"onUpdate:modelValue":e[5]||(e[5]=a=>o(t).color=a),type:"text",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).color]])]),l("div",null,[e[21]||(e[21]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Microchip",-1)),r(l("input",{"onUpdate:modelValue":e[6]||(e[6]=a=>o(t).microchip_number=a),type:"text",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).microchip_number]])]),l("div",null,[e[22]||(e[22]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Photo URL",-1)),r(l("input",{"onUpdate:modelValue":e[7]||(e[7]=a=>o(t).photo_url=a),type:"url",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).photo_url]])]),l("div",Q,[e[23]||(e[23]=l("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Notes",-1)),r(l("textarea",{"onUpdate:modelValue":e[8]||(e[8]=a=>o(t).notes=a),rows:"3",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm"},null,512),[[n,o(t).notes]])]),l("label",X,[r(l("input",{"onUpdate:modelValue":e[9]||(e[9]=a=>o(t).is_active=a),type:"checkbox",class:"rounded border-slate-300"},null,512),[[C,o(t).is_active]]),e[24]||(e[24]=x(" Active ",-1))]),l("label",Y,[r(l("input",{"onUpdate:modelValue":e[10]||(e[10]=a=>o(t).nfc_tag_enabled=a),type:"checkbox",class:"rounded border-slate-300"},null,512),[[C,o(t).nfc_tag_enabled]]),e[25]||(e[25]=x(" NFC tag enabled (public scan profile) ",-1))])]),l("div",Z,[l("button",{type:"submit",class:"px-5 py-2.5 bg-slate-900 hover:bg-slate-800 text-white rounded-lg text-sm font-semibold disabled:opacity-60",disabled:o(m)},y(o(m)?"Savingâ¦":"Save dog"),9,ee),l("button",{type:"button",class:"px-5 py-2.5 border border-slate-300 text-slate-700 rounded-lg text-sm font-semibold hover:bg-slate-50 disabled:opacity-60",disabled:o(m),onClick:N}," Deactivate ",8,te),l("button",{type:"button",class:"px-5 py-2.5 border border-red-300 text-red-700 rounded-lg text-sm font-semibold hover:bg-red-50 disabled:opacity-60",disabled:o(m)||o(v),onClick:E},y(o(v)?"Deletingâ¦":"Delete dog"),9,le)])],32)):g("",!0)]),_:1},8,["title"])}}});export{ne 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.