1import{$ as e,D as t,F as a,Ht as s,K as l,L as o,O as r,Pt as n,T as u,_t as i,at as d,bt as c,cn as p,dt as v,et as m,k as f,nt as y,v as g,x}from"./B6EpUQT1.js";import{I as w,Mt as _,P as b,R as h}from"./ULF0pKjI.js";import{t as A}from"./CIojLGvs.js";import{o as j}from"./gNSfRsu6.js";import{t as T}from"./DgLP3hnZ2.js";import{t as C}from"./CBbU2S9p.js";var M=o({inheritAttrs:!1,__name:"AddressField",props:{modelValue:{type:Object,default:null}},emits:["update:modelValue"],setup(o,{emit:T}){const M=T,V=o,{loadGoogleMaps:k,isLoading:z}=C(),F=n(!1),I=n([]),P=n(!1),$=n(V.modelValue?.text??""),L=n(!1),R=n(),O=n(null),S=n({}),q=n(null);let B=null,D=null,G="";const H=()=>{setTimeout(()=>{L.value=!1},200)};e(async()=>{await k()&&(B=new google.maps.places.AutocompleteService,P.value=!0)}),m(()=>{D&&clearTimeout(D)});const K=e=>($.value=e,q.value=null,D&&clearTimeout(D),G&&e===G?(I.value=[],void(L.value=!1)):(G="",e&&B?void(D=setTimeout(async()=>{F.value=!0;try{const t=await(B?.getPlacePredictions({input:e,types:["geocode"]}));I.value=(t?.predictions??[]).map(e=>({text:e.description,value:e.place_id})),I.value.length>0?((()=>{if(!O.value)return;const e=O.value.getBoundingClientRect();S.value={position:"fixed",top:e.bottom-8+"px",left:`${e.left}px`,width:`${e.width}px`,zIndex:"2000"}})(),L.value=!0):L.value=!1}catch{I.value=[],L.value=!1}finally{F.value=!1}},300)):(I.value=[],void(L.value=!1))));i(()=>V.modelValue,e=>{e?.text&&(G=e.text,$.value=e.text)});const U=v(),E=u(()=>{if(q.value)return[q.value];const e=U["error-messages"]??U.errorMessages;return e?Array.isArray(e)?e:[e]:[]}),J=u(()=>{const e={};for(const t in U)"error-messages"!==t&&"errorMessages"!==t&&(e[t]=U[t]);return e});return(e,o)=>{const n=j;return y(),f("div",{ref_key:"wrapperRef",ref:O,class:"address-field-wrapper"},[a(b,l({ref_key:"textFieldRef",ref:R},s(J),{"model-value":s($),loading:s(z)||s(F),disabled:!s(P),"error-messages":s(E),type:"text",variant:"outlined",autocomplete:"off","onUpdate:modelValue":K,onBlur:H}),null,16,["model-value","loading","disabled","error-messages"]),a(n,null,{default:c(()=>[(y(),t(x,{to:"body"},[s(L)&&s(I).length?(y(),t(w,{key:0,density:"compact",class:"address-suggestions-list",style:p(s(S))},{default:c(()=>[(y(!0),f(g,null,d(s(I),e=>(y(),t(h,{key:e.value,title:e.text,onMousedown:_(t=>(async e=>{L.value=!1,I.value=[],q.value=null,F.value=!0;try{const a=new google.maps.places.Place({id:e});await a.fetchFields({fields:["formattedAddress","addressComponents"]});const s=a.addressComponents??[],l=(e,t=!1)=>{const a=s.find(t=>t.types.includes(e));return a?t?a.shortText:a.longText:null},o=l("street_number",!0),r=l("route"),n=l("colloquial_area"),u=l("locality"),i=l("postal_code",!0);if($.value=a.formattedAddress??$.value,!i)return void(q.value="Adresse incomplète, précisez un code postal");let d;try{d=await async function(e){return await A("/api/location/cities",{query:{postcode:e}})}(i)}catch(t){return void(q.value="Service adresse indisponible, réessayez dans un instant")}if(!d||0===d.length)return void(q.value="Cette adresse n'est pas reconnue, essayez-en une autre");let c=d.find(e=>u&&e.label.toLowerCase().includes(u.toLowerCase()));if(c||(c=d[0]),!c)return;const p={line1:o||r?`${o?o+" ":""}${r??""}`:n??"",postcode:i,city:u??c.label,locationId:c.id,text:a.formattedAddress??""};G=p.text??"",$.value=p.text??"",M("update:modelValue",p)}catch(t){q.value="Impossible de récupérer cette adresse, réessayez"}finally{F.value=!1}})(e.value),["prevent"])},null,8,["title","onMousedown"]))),128))]),_:1},8,["style"])):r("",!0)]))]),_:1})],512)}}}),V=Object.assign(T(M,[["__scopeId","data-v-a7b23049"]]),{__name:"SharedAddressField"});export{V as t};
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.