1import{I as P,a as I,c as E,f as G,m as O}from"./chunk-ENLTPXSF.js";import{Ud as R}from"./chunk-JEUNMMQS.js";import"./chunk-DJKPENO3.js";import{Da as p,Dc as h,Ec as f,Fc as C,Ja as u,Rc as v,Td as w,Xc as A,Yc as y,Za as a,Zc as b,bc as m,e as l,hb as c,qd as _,uc as g,w as d,xa as r}from"./chunk-AAVCIRPQ.js";import"./chunk-RA2WU32H.js";var T=["addressCheckout"],S=class s{changeDetector=u(w);userAddressService=u(R);searchAddressAuto;formId;input="";name="";placeholder="";isoCode="";countries$;required=!1;componentRestrictions;onFocus=new a;parsedAddress=new a;autocomplete;onChange;onTouch;isoCode$;restrictedCountries;constructor(){this.isoCode$=new l(void 0),this.countries$=this.userAddressService.getDeliveryCountries().pipe(r(e=>{Object.keys(e).length===0&&this.userAddressService.loadDeliveryCountries()}))}ngAfterViewInit(){this.countries$?.pipe(d(e=>Object.values(e).map(t=>t.isocode)),r(e=>{this.restrictedCountries=e??null})).subscribe({next:()=>this.getGooglePlacesInput(),error:e=>console.error(e)})}ngOnChanges(){this.isoCode$.next(this.isoCode)}writeValue(e){this.input=e??"",this.changeDetector.detectChanges()}registerOnChange(e){this.onChange=e}registerOnTouched(e){this.onTouch=e}onFocusCallback(e){this.onFocus.next(e)}getGooglePlacesInput(){let e=this.componentRestrictions??{country:this.restrictedCountries};this.autocomplete=new google.maps.places.Autocomplete(this.searchAddressAuto?.nativeElement,{types:["geocode"],componentRestrictions:e}),this.autocomplete.addListener("place_changed",()=>{if(!this.autocomplete)return;let t=this.autocomplete?.getPlace();!t||t.geometry===void 0||t.geometry===null||(this.writeValue((this.searchAddressAuto?.nativeElement).value),this.onChange(this.input),this.parseAddress(t))})}parseAddress(e){let t=e.address_components;this.parsedAddress.emit({street:this.findStreet(e),city:this.findCity(t),region:this.findRegion(e),postalCode:this.findAddressComponent(t,"postal_code")?.long_name??"",country:this.findAddressComponent(t,"country")?.short_name??""})}findStreet(e){if(e.name)return e.name;let t=this.findAddressComponent(e.address_components,"route");return t?t.long_name:""}findCity(e){let t=this.findAddressComponent(e,"postal_town")?.long_name??"",o=this.findAddressComponent(e,"locality");return o&&(t=t?`${t}, ${o.long_name}`:o.long_name),t}findRegion(e){return this.findAddressComponent(e.address_components,"administrative_area_level_1")?.long_name??""}findAddressComponent(e,t){return e?.find(o=>!!o.types.find(n=>n===t))}static \u0275fac=function(t){return new(t||s)};static \u0275cmp=m({type:s,selectors:[["jpg-google-autocomplete-input"]],viewQuery:function(t,o){if(t&1&&A(T,5),t&2){let n;y(n=b())&&(o.searchAddressAuto=n.first)}},hostAttrs:[1,"jpg-google-autocomplete-input"],inputs:{formId:"formId",input:"input",name:"name",placeholder:"placeholder",isoCode:"isoCode",countries$:"countries$",required:"required",componentRestrictions:"componentRestrictions"},outputs:{onFocus:"onFocus",parsedAddress:"parsedAddress"},features:[_([{provide:I,useExisting:p(()=>s),multi:!0}]),c],decls:2,vars:5,consts:[["addressCheckout",""],["type","text","autocomplete","off",1,"field-text",3,"keydown.enter","ngModelChange","blur","focus","id","placeholder","ngModel","ariaRequired"]],template:function(t,o){t&1&&(f(0,"input",1,0),v("keydown.enter",function(i){return i.preventDefault()})("ngModelChange",function(i){return o.onChange(i)})("blur",function(){return o.onTouch()})("focus",function(i){return o.onFocusCallback(i)}),C()),t&2&&(h("id",o.formId)("placeholder",o.placeholder||"")("ngModel",o.input)("ariaRequired",o.required),g("name",o.name))},dependencies:[P,E,G,O],encapsulation:2})};export{S as GoogleAutocompleteInputComponent};
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.