import{d as M,bE as P,p as b,G as K,c as V,o as j,bF as T,e as p,f as I,g as E,az as z,h as i,F,r as H,t as G,j as k,w,B as O,v as W,aC as X,X as N,m as Y,u as J,bG as Q,bA as U,i as D,a5 as Z,bH as x,k as ee,bI as te,bq as ae}from"./index-B4gewkxT.js";import{L as le}from"./index.esm-Cw6omFHi.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},r=new o.Error().stack;r&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[r]="c4f15635-fa8c-4238-b0ea-d32e612dab16",o._sentryDebugIdIdentifier="sentry-dbid-c4f15635-fa8c-4238-b0ea-d32e612dab16")}catch{}})();const se=["id","name","value","data-testId"],oe={key:0,class:"geoloc__list"},ne=M({__name:"FormAutocomplete",props:{name:{},error:{default:""},handleChange:{},errorMessage:{default:""},value:{default:null},multiple:{type:Boolean},autocompleteTypes:{default:()=>["(regions)"]},styleInline:{type:Boolean},testId:{}},emits:["set-error"],setup(o,{emit:r}){const u="AIzaSyB5yoN7eWndyX4q_36_PuoCHxVcWfzewwM",d=P(),t=o,C=r,f=new le({apiKey:u,language:"fr",region:"FR",version:"weekly",libraries:["places"]}),c=b(null),m=b(""),n=b(t.multiple&&t.value?t.value:[]),y=b(null);K(()=>t.value,e=>{t.multiple&&Array.isArray(e)&&(n.value=e)});const _=V(()=>{var e,l,a;return t.multiple?m.value:t.value&&!Array.isArray(t.value)?((e=t.value)==null?void 0:e.name)??((l=t.value)==null?void 0:l.city)??((a=t.value)==null?void 0:a.formatted_address):""});j(async()=>{if(c.value)try{const e=await f.load(),l=new e.maps.places.Autocomplete(c.value,{fields:["address_components","formatted_address","geometry","name","types","place_id"],strictBounds:!1,types:t.autocompleteTypes});l.addListener("place_changed",()=>{y.value&&clearTimeout(y.value);const a=l.getPlace();!a.geometry||!a.geometry.location||g(a)}),c.value.addEventListener("keydown",a=>{a.key==="Enter"&&a.preventDefault()})}catch(e){console.error(e)}});const g=e=>{t.multiple?n.value.some(l=>l.formatted_address===e.formatted_address)||(n.value=[...n.value,e],t.handleChange(T(n.value)),m.value=""):t.handleChange(e)},B=async e=>{var A;const l=new google.maps.places.AutocompleteService,a=new google.maps.places.PlacesService(document.createElement("div")),v=await l.getPlacePredictions({input:e,types:t.autocompleteTypes});if(((A=v==null?void 0:v.predictions)==null?void 0:A.length)>0){const R=v.predictions[0];await a.getDetails({placeId:R.place_id,fields:["address_components","formatted_address","geometry","name","types"]},(S,$)=>{S&&$===google.maps.places.PlacesServiceStatus.OK&&g(S)})}else return null},s=e=>{const l=e.target.value;l===""&&t.handleChange(null),t.multiple&&(m.value=l)},h=e=>{n.value=n.value.filter(l=>l.formatted_address!==e.formatted_address),t.handleChange(T(n.value))},q=async()=>{y.value=setTimeout(async()=>{var a;const e=((a=c.value)==null?void 0:a.value)||"",l=document.querySelectorAll(".pac-container .pac-item");e!==""?l.length>0?await B(e):C("set-error"):t.multiple&&(m.value="")},100)};return(e,l)=>(p(),I(F,null,[E("input",z({id:e.name},i(d),{ref_key:"inputRef",ref:c,type:"text",name:e.name,class:["field__input text-sm",{"field__input--error":e.error||e.errorMessage,"field__input--inline":e.styleInline}],value:_.value,"data-testId":e.testId,onInput:s,onBlur:q}),null,16,se),e.multiple?(p(),I("div",oe,[(p(!0),I(F,null,H(n.value,a=>(p(),I("div",{key:a.formatted_address,class:"geoloc__item"},[E("span",null,G(a.formatted_address),1),k(X,{theme:i(W).DISCRET,class:"geoloc__item__close-button",onClick:v=>h(a)},{default:w(()=>[k(O,{legacy:"",name:"cross",class:"geoloc__item__close-button--icon"})]),_:2},1032,["theme","onClick"])]))),128))])):N("",!0)],64))}}),re=Y(ne,[["__scopeId","data-v-42533901"]]),ue=M({__name:"FormGoogleLocation",props:{name:{},modelValue:{default:void 0},rules:{default:void 0},multiple:{type:Boolean},autocompleteTypes:{default:()=>["(regions)"]},styleInline:{type:Boolean},testId:{}},emits:["update:modelValue"],setup(o,{emit:r}){const{t:u}=J(),d=P(),t=o,C=r,f=V(()=>t.rules?typeof t.rules=="string"?t.rules.includes("required"):Object.keys(t.rules).includes("required"):!1),c=s=>f.value&&!ae(s)?u("required"):!0,m=V(()=>t.name||Q()),{handleChange:n,value:y,errorMessage:_,setErrors:g}=U(m.value,c,{initialValue:t.modelValue,standalone:!t.name,syncVModel:!0}),B=s=>{n(s),C("update:modelValue",s)};return(s,h)=>(p(),D(te,{required:f.value},{label:w(()=>[Z(s.$slots,"label")]),default:w(()=>[k(re,z({...i(d)},{multiple:s.multiple,name:m.value,"model-value":t.modelValue,"handle-change":B,value:i(y),"autocomplete-types":s.autocompleteTypes,"style-inline":s.styleInline,"test-id":s.testId,onSetError:h[0]||(h[0]=q=>f.value&&i(g)(i(u)("required")))}),null,16,["multiple","name","model-value","value","autocomplete-types","style-inline","test-id"]),i(_)?(p(),D(x,{key:0},{default:w(()=>[ee(G(i(_)),1)]),_:1})):N("",!0)]),_:3},8,["required"]))}});function L(o){const r=o;r.__i18n=r.__i18n||[],r.__i18n.push({locale:"",resource:{fr:{required:u=>{const{normalize:d}=u;return d(["Le champ est obligatoire et doit être sélectionné dans les propositions"])}},en:{required:u=>{const{normalize:d}=u;return d(["The field is required and must be selected in the proposals"])}}}})}typeof L=="function"&&L(ue);export{ue as _}; //# sourceMappingURL=FormGoogleLocation-ggJ5k1gY.js.map