import{d as M,D as N,i as p,p as E,q as V,H as m,E as f,J as _,r as v,o as $,a as I,w as a,b as s,n as h,T as R,k as b,t as C,c as t,f as z,L as A,N as H,O as J,m as O,Q,B as j}from"./index.29cf2edd.js";import{M as G}from"./MapMarker.eb059847.js";import{_ as K}from"./MultiUploader.7b09acaa.js";import{_ as W}from"./ProvinceSelection.2a107c65.js";/* empty css              *//* empty css              */const X={class:"font-bold"},Y={class:""},le=M({__name:"TouristCreate",setup(Z){const F={province_id:{required:!0,message:"Please choose a province",trigger:"change"},title:{required:!0,message:"Please enter title",trigger:"change"},short_description:{required:!0,message:"Please enter short description",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=N({id:void 0,province_id:void 0,title:"",short_description:"",long_description:"",address:"",contact:"",lat:"",lng:"",images:[]});p(!1),p(""),p("");const S=E(),d=p(),l=p();V(async()=>{d.value=S.params.id,d.value&&await T()});const T=async()=>{m(),await f.getTouristPlace(d.value).then(n=>{_(),l.value=n.data,w()}).catch(n=>{_(),v.push("/data/tourist")})},w=()=>{l&&(e.province_id=l.value.province_id,e.title=l.value.title,e.short_description=l.value.short_description,e.long_description=l.value.long_description,e.address=l.value.address,e.contact=l.value.contact,e.lat=l.value.lat,e.lng=l.value.lng,e.images=l.value.images,console.log(e))},U=()=>{if(!e.lat||!e.lng)return h.error("Please mark location");e.lat=e.lat.toString(),e.lng=e.lng.toString(),d.value?k():q()},k=()=>{e.id=d.value,m(),f.updateTouristPlaces(e).then(n=>{_(),h.success("Updated tourist place successful"),v.push("/data/tourist")}).catch(n=>{_()})},q=()=>{m(),f.createTouristPlaces(e).then(n=>{_(),h.success("Created tourist place successful"),v.push("/data/tourist")}).catch(n=>{_()})},y=()=>{},L=n=>{n&&(e.lat=n.lat,e.lng=n.lng)},x=n=>{e.images=n};return(n,o)=>{const i=A,u=H,c=J,g=O,P=Q,B=j,D=R;return $(),I(D,{class:"col-form",ref:"formRef",layout:"vertical",model:s(e),rules:F,onFinish:U,onFinishFailed:y},{default:a(()=>[b("h1",X,C(d.value?"Edit":"Create")+" Tourist Place",1),t(c,{gutter:24},{default:a(()=>[t(u,{span:12},{default:a(()=>[t(i,{name:"province_id",label:"Province"},{default:a(()=>[t(W,{value:s(e).province_id,onChange:o[0]||(o[0]=r=>s(e).province_id=r)},null,8,["value"])]),_:1})]),_:1})]),_:1}),t(c,{gutter:24},{default:a(()=>[t(u,{span:24},{default:a(()=>[t(i,{name:"title",label:"Title"},{default:a(()=>[t(g,{value:s(e).title,"onUpdate:value":o[1]||(o[1]=r=>s(e).title=r)},null,8,["value"])]),_:1})]),_:1})]),_:1}),t(c,{gutter:24},{default:a(()=>[t(u,{span:24},{default:a(()=>[t(i,{name:"short_description",label:"Short Description"},{default:a(()=>[t(P,{value:s(e).short_description,"onUpdate:value":o[2]||(o[2]=r=>s(e).short_description=r),rows:4},null,8,["value"])]),_:1})]),_:1})]),_:1}),t(c,{gutter:24},{default:a(()=>[t(u,{span:24},{default:a(()=>[t(i,{name:"long_description",label:"Long Description"},{default:a(()=>[t(P,{value:s(e).long_description,"onUpdate:value":o[3]||(o[3]=r=>s(e).long_description=r),rows:8},null,8,["value"])]),_:1})]),_:1})]),_:1}),t(c,{gutter:24},{default:a(()=>[t(u,{span:16},{default:a(()=>[t(i,{name:"address",label:"Address"},{default:a(()=>[t(g,{value:s(e).address,"onUpdate:value":o[4]||(o[4]=r=>s(e).address=r)},null,8,["value"])]),_:1})]),_:1}),t(u,{span:8},{default:a(()=>[t(i,{name:"contact",label:"Contact"},{default:a(()=>[t(g,{value:s(e).contact,"onUpdate:value":o[5]||(o[5]=r=>s(e).contact=r)},null,8,["value"])]),_:1})]),_:1})]),_:1}),t(c,{gutter:24},{default:a(()=>[t(u,{span:16},{default:a(()=>[t(i,{label:"Images"},{default:a(()=>[t(K,{files:s(e).images,onUpload:x},null,8,["files"])]),_:1})]),_:1})]),_:1}),t(c,{gutter:24},{default:a(()=>[t(u,{span:24},{default:a(()=>[t(i,{label:"Location"},{default:a(()=>[t(G,{title:s(e).title,lat:s(e).lat,lng:s(e).lng,onChange:L},null,8,["title","lat","lng"])]),_:1})]),_:1})]),_:1}),b("div",Y,[t(B,{type:"primary","html-type":"submit",size:"large"},{default:a(()=>[z(C(d.value?"Save":"Create"),1)]),_:1})])]),_:1},8,["model"])}}});export{le as default};
