import{d as x,D as L,i as m,p as N,q as V,H as f,E as h,J as p,r as v,o as M,a as I,w as t,b as l,n as g,T as R,k as E,t as y,c as a,f as O,P as z,L as G,N as J,O as $,m as j,B as K}from"./index.29cf2edd.js";/* empty css              */import{M as Q}from"./MapMarker.eb059847.js";import{_ as W}from"./MultiUploader.7b09acaa.js";/* empty css              */const X={class:"font-bold"},Y={class:"",style:{"margin-left":"125px"}},ne=x({__name:"HospitalCreate",setup(Z){const C=[{id:"GOV",value:"\u0EC2\u0EAE\u0E87\u0EDD\u0ECD\u0EA5\u0EB1\u0E94"},{id:"PRIVATE",value:"\u0EC2\u0EAE\u0E87\u0EDD\u0ECD\u0EC0\u0EAD\u0E81\u0EB0\u0E8A\u0EBB\u0E99"}],b={type:{required:!0,message:"Please choose a hospital type",trigger:"change"},name:{required:!0,message:"Please enter location name",trigger:"change"},tel:{required:!0,message:"Please enter contact phone",trigger:"change"},address:{required:!0,message:"Please enter address",trigger:"change"},lat:{required:!0,message:"Please make location latitude",trigger:"change"},lng:{required:!0,message:"Please make location longitude",trigger:"change"}};let e=L({id:"",type:"",name:"",address:"",tel:"",lat:"",lng:"",images:[]});m(!1),m(""),m("");const D=N(),u=m(),n=m();V(async()=>{u.value=D.params.id,u.value&&await B()});const B=async()=>{f(),await h.getHospital(u.value).then(s=>{p(),n.value=s.data,F()}).catch(s=>{p(),v.push("/data/hospital")})},F=()=>{n&&(e.type=n.value.hospitaltype,e.name=n.value.name,e.address=n.value.address,e.tel=n.value.tel,e.lat=n.value.lat,e.lng=n.value.lng,e.images=n.value.images)},P=()=>{if(!e.lat||!e.lng)return g.error("Please mark location");e.lat=e.lat.toString(),e.lng=e.lng.toString(),u.value?H():S()},H=()=>{e.id=u.value,f(),h.updateHospital(e).then(s=>{p(),g.success("Updated hospital successful"),v.push("/data/hospital")}).catch(s=>{p()})},S=()=>{f(),h.createHospital(e).then(s=>{p(),g.success("Created hospital successful"),v.push("/data/hospital")}).catch(s=>{p(),g.error(s.message)})},k=()=>{},q=s=>{s&&(e.lat=s.lat,e.lng=s.lng)},A=s=>{e.images=s};return(s,o)=>{const U=z,i=G,d=J,c=$,_=j,w=K,T=R;return M(),I(T,{class:"col-form",ref:"formRef",model:l(e),rules:b,onFinish:P,onFinishFailed:k},{default:t(()=>[E("h1",X,y(u.value?"Edit":"Create")+" Hospital",1),a(c,{gutter:24},{default:t(()=>[a(d,{span:8},{default:t(()=>[a(i,{name:"type",label:"Hospital Type"},{default:t(()=>[a(U,{value:l(e).type,"onUpdate:value":o[0]||(o[0]=r=>l(e).type=r),placeholder:"Choose a hospital type",options:C,"field-names":{label:"value",value:"id"}},null,8,["value"])]),_:1})]),_:1})]),_:1}),a(c,{gutter:24},{default:t(()=>[a(d,{span:8},{default:t(()=>[a(i,{name:"name",label:"Name"},{default:t(()=>[a(_,{value:l(e).name,"onUpdate:value":o[1]||(o[1]=r=>l(e).name=r)},null,8,["value"])]),_:1})]),_:1}),a(d,{span:8},{default:t(()=>[a(i,{name:"tel",label:"Telephone"},{default:t(()=>[a(_,{value:l(e).tel,"onUpdate:value":o[2]||(o[2]=r=>l(e).tel=r)},null,8,["value"])]),_:1})]),_:1})]),_:1}),a(c,{gutter:24},{default:t(()=>[a(d,{span:16},{default:t(()=>[a(i,{name:"address",label:"Address"},{default:t(()=>[a(_,{value:l(e).address,"onUpdate:value":o[3]||(o[3]=r=>l(e).address=r)},null,8,["value"])]),_:1})]),_:1})]),_:1}),a(c,{gutter:24},{default:t(()=>[a(d,{span:16},{default:t(()=>[a(i,{label:"Images"},{default:t(()=>[a(W,{files:l(e).images,onUpload:A},null,8,["files"])]),_:1})]),_:1})]),_:1}),a(c,{gutter:24},{default:t(()=>[a(d,{span:24},{default:t(()=>[a(i,{label:"Location"},{default:t(()=>[a(Q,{title:l(e).name,lat:l(e).lat,lng:l(e).lng,onChange:q},null,8,["title","lat","lng"])]),_:1})]),_:1})]),_:1}),E("div",Y,[a(w,{type:"primary","html-type":"submit",size:"large"},{default:t(()=>[O(y(u.value?"Save":"Create"),1)]),_:1})])]),_:1},8,["model"])}}});export{ne as default};
