import{d as M,D,i as m,p as E,q as T,H as p,E as f,J as i,r as v,o as V,a as I,w as t,b as s,n as h,T as R,k as S,t as L,c as a,f as z,m as A,L as H,N as J,O,B as $}from"./index.29cf2edd.js";import{M as j}from"./MapMarker.eb059847.js";import{_ as G}from"./MultiUploader.7b09acaa.js";/* empty css              */const K={class:"font-bold"},Q={class:"",style:{"margin-left":"125px"}},ae=M({__name:"ServiceLocationCreate",setup(W){const b={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=D({id:"",name:"",address:"",tel:"",lat:"",lng:"",images:[]});m(!1),m(""),m("");const F=E(),o=m(),l=m();T(async()=>{o.value=F.params.id,o.value&&await k()});const k=async()=>{p(),await f.getServiceLocation(o.value).then(n=>{i(),l.value=n.data,y()}).catch(n=>{i(),v.push("/data/service/location")})},y=()=>{l&&(e.name=l.value.name,e.address=l.value.address,e.tel=l.value.tel,e.lat=l.value.lat,e.lng=l.value.lng,e.images=l.value.images,console.log(e))},C=()=>{if(!e.lat||!e.lng)return h.error("Please mark location");e.lat=e.lat.toString(),e.lng=e.lng.toString(),o.value?q():w()},q=()=>{e.id=o.value,p(),f.updateServiceLocation(e).then(n=>{i(),h.success("Updated service location successful"),v.push("/data/service/location")}).catch(n=>{i()})},w=()=>{p(),f.createServiceLocation(e).then(n=>{i(),h.success("Created service location successful"),v.push("/data/service/location")}).catch(n=>{i()})},P=()=>{},U=n=>{n&&(e.lat=n.lat,e.lng=n.lng)},x=n=>{e.images=n};return(n,r)=>{const _=A,u=H,c=J,g=O,B=$,N=R;return V(),I(N,{class:"col-form",ref:"formRef",model:s(e),rules:b,onFinish:C,onFinishFailed:P},{default:t(()=>[S("h1",K,L(o.value?"Edit":"Create")+" Service Location",1),a(g,{gutter:24},{default:t(()=>[a(c,{span:8},{default:t(()=>[a(u,{name:"name",label:"Name"},{default:t(()=>[a(_,{value:s(e).name,"onUpdate:value":r[0]||(r[0]=d=>s(e).name=d)},null,8,["value"])]),_:1})]),_:1}),a(c,{span:8},{default:t(()=>[a(u,{name:"tel",label:"Telephone"},{default:t(()=>[a(_,{value:s(e).tel,"onUpdate:value":r[1]||(r[1]=d=>s(e).tel=d)},null,8,["value"])]),_:1})]),_:1})]),_:1}),a(g,{gutter:24},{default:t(()=>[a(c,{span:16},{default:t(()=>[a(u,{name:"address",label:"Address"},{default:t(()=>[a(_,{value:s(e).address,"onUpdate:value":r[2]||(r[2]=d=>s(e).address=d)},null,8,["value"])]),_:1})]),_:1})]),_:1}),a(g,{gutter:24},{default:t(()=>[a(c,{span:16},{default:t(()=>[a(u,{label:"Images"},{default:t(()=>[a(G,{files:s(e).images,onUpload:x},null,8,["files"])]),_:1})]),_:1})]),_:1}),a(g,{gutter:24},{default:t(()=>[a(c,{span:24},{default:t(()=>[a(u,{label:"Location"},{default:t(()=>[a(j,{title:s(e).name,lat:s(e).lat,lng:s(e).lng,onChange:U},null,8,["title","lat","lng"])]),_:1})]),_:1})]),_:1}),S("div",Q,[a(B,{type:"primary","html-type":"submit",size:"large"},{default:t(()=>[z(L(o.value?"Save":"Create"),1)]),_:1})])]),_:1},8,["model"])}}});export{ae as default};
