import{o as i,c as r,a as o,f as q,q as F,v as N,x as U,m as j,b as V,w as E,g as u,i as c,y as $,z as C,A as G,B as A,C as K,F as m,r as O,j as R,D as Q,H as X,d as p,h as J,t as _,T as W}from"./entry.e017eb4f.js";import{_ as Y}from"./nuxt-link.0da3f327.js";import{u as ee}from"./fetch.f410fe8a.js";const te={class:"bg-white min-h-screen"},ne={class:"flex flex-col text-gray-600 md:flex-row md:flex-row-reverse min-h-screen"},se=o("div",{class:"md:w-1/2"},[o("div",{class:"gmap h-[50vh] md:h-[100vh] md:w-1/2 md:!fixed md:right-0 md:top-0 md:bottom-0 md:left-1/2"})],-1),oe={class:"md:w-1/2 md:h-full md:overflow-y-auto"},ie={class:"ml-auto p-4 py-6 lg:p-8 lg:max-w-[640px] lg:pr-20"},ae=o("h1",{class:"text-2xl font-bold tracking-tight text-gray-900"}," Händler finden ",-1),re={key:0,class:"text-sm text-gray-600 mt-4"},le=["onSubmit"],de=o("option",{value:"10"}," 10km ",-1),ce=o("option",{value:"25"}," 25km ",-1),ue=o("option",{value:"50"}," 50km ",-1),me=o("option",{value:"75"}," 75km ",-1),pe=[de,ce,ue,me],fe=o("button",{class:"font-semibold w-full md:w-auto text-lg mx-auto block bg-sd-blue text-white px-5 py-3 rounded",type:"submit"}," Suchen ",-1),he={key:1,class:"mt-6 md:mt-8"},ye={key:2,class:"flex flex-col space-y-5 mt-6 md:mt-8 lg:space-y-8"},ge={class:"px-4 py-4 sm:px-5 font-semibold flex space-x-3 w-full items-center text-white"},_e={class:"w-full"},ve={key:0,class:"shrink-0 font-medium text-sm text-white/90 whitespace-nowrap ml-auto"},xe={class:"bg-gray-50 px-4 py-4 sm:px-5"};const we={key:1},ke={key:2},be={key:3},Ne={__name:"index",async setup(Se){var I;let w,z;const{data:B}=([w,z]=q(()=>ee(R().public.API_URL+"/api/vendors","$NZy9pNr2Bs")),w=await w,z(),w),k=F((I=B==null?void 0:B.value)==null?void 0:I.vendors),P=F(!1),f=N("vendor_city",()=>""),v=N("vendor_maxDistance",()=>50);let h;const b=U(()=>{var t;const e=[...(t=k.value)==null?void 0:t.filter(l=>l.distance<=parseInt(v.value))];return e.sort((l,a)=>l.distance-a.distance),e});async function L(){if(!f.value){alert("Bitte geben Sie eine Stadt oder PLZ ein.");return}await $fetch(R().public.API_URL+"/api/vendors/geolocate",{method:"POST",body:{city:f.value}}).then(e=>{if(e.error){alert("Leider konnte kein Standort zu Ihrer Eingabe gefunden werden. Bitte versuchen Sie es mit einer anderen Eingabe.");return}H(parseFloat(e.lat),parseFloat(e.lng))})}function H(e,t){const l={lat:e,lng:t};k.value.forEach(a=>{const d={lat:a.lat,lng:a.lng};a.distance=Z(l,d)}),k.value.sort((a,d)=>a.distance-d.distance),D(l),P.value=!0}function Z(e,t){const a=S(t.lat-e.lat),d=S(t.lng-e.lng),s=Math.sin(a/2)*Math.sin(a/2)+Math.cos(S(e.lat))*Math.cos(S(t.lat))*Math.sin(d/2)*Math.sin(d/2);return 6371*(2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)))}function S(e){return e*(Math.PI/180)}function T(){h=new google.maps.Map(document.querySelector(".gmap"),{center:{lat:52.520008,lng:13.404954},zoom:12,styles:[{featureType:"administrative",stylers:[{visibility:"simplified"}]},{featureType:"landscape",stylers:[{color:"#f3f4f6"},{visibility:"simplified"}]},{featureType:"poi",stylers:[{visibility:"off"}]},{featureType:"transit",stylers:[{visibility:"off"}]},{featureType:"water",stylers:[{visibility:"simplified"}]}]})}let x=[];function D(e){var d;if(!M.value||typeof google>"u"){setTimeout(()=>{D(e)},200);return}x==null||x.forEach(s=>{s.setMap(null)}),x=[];const t=[];(d=b.value)==null||d.forEach(s=>{if(!s.lat||!s.lng||s.distance>parseInt(v.value))return;let y="marker";(!s.type||s.type==="Normal")&&(y="marker-normal");const g=new google.maps.Marker({position:{lat:parseFloat(s.lat),lng:parseFloat(s.lng)},map:h,title:s.company,icon:{url:"/img/pics/"+y+".png",scaledSize:new google.maps.Size(26,44)}});g.addListener("click",()=>{Q().push("/haendler/"+s.slug)}),t.push(g)});const l=new google.maps.Marker({position:e,map:h,title:"Mein Standort"});if(t.push(l),x.push(...t),(t==null?void 0:t.length)===1){h.setCenter(t[0].position),h.setZoom(12);return}const a=new google.maps.LatLngBounds;t.forEach(s=>{a.extend({lat:s.position.lat(),lng:s.position.lng()})}),h.fitBounds(a)}const M=N("mapLoaded",()=>!1);return j(()=>{if(f.value&&L(),M.value){T();return}M.value=!0;const e=document.createElement("script"),t=document.getElementsByTagName("script")[0];e.defer=!0,e.src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA_eFl3r6IXcvZAPmiA8VmotQ-a-fG3ZcU&v=weekly",e.onload=e.onreadystatechange=T,t.parentNode.insertBefore(e,t)}),(e,t)=>{var s,y,g;const l=W,a=X,d=Y;return i(),r("div",te,[V(a,null,{default:E(()=>[V(l,null,{default:E(()=>[p("Händler finden | Solis")]),_:1})]),_:1}),o("div",ne,[se,o("div",oe,[o("div",ie,[ae,(s=u(k))!=null&&s.length?(i(),r("p",re," Bitte geben Sie eine Stadt oder PLZ ein, um die Händler in Ihrer Nähe zu finden. ")):c("",!0),o("form",{class:"mt-3 flex flex-col space-y-3 md:flex-row md:space-x-2 md:space-y-0",onSubmit:$(L,["prevent"])},[C(o("input",{id:"city","onUpdate:modelValue":t[0]||(t[0]=n=>A(f)?f.value=n:null),required:"",type:"text",name:"city",autocomplete:"city",placeholder:"Stadt oder PLZ eingeben",class:"block w-full rounded-md border-0 py-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"},null,512),[[G,u(f)]]),C(o("select",{id:"maxDistance","onUpdate:modelValue":t[1]||(t[1]=n=>A(v)?v.value=n:null),name:"maxDistance",autocomplete:"maxDistance",class:"block w-full md:max-w-[120px] rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm",onInput:L},pe,544),[[K,u(v)]]),fe],40,le),u(P)&&!((y=u(b))!=null&&y.length)?(i(),r("div",he," Es wurden leider keine Händler in Ihrer Nähe gefunden. Bitte versuchen Sie es mit einer anderen Eingabe oder einer größeren Entfernung. ")):c("",!0),(g=u(b))!=null&&g.length?(i(),r("div",ye,[(i(!0),r(m,null,O(u(b),n=>(i(),J(d,{key:"place-"+n.id,to:"/haendler/"+n.slug,class:"overflow-hidden rounded bg-sd-blue-light shadow-lg block"},{default:E(()=>[o("div",ge,[o("div",_e,_(n.company),1),n.distance?(i(),r("div",ve,_(e.$numberFormat(n.distance,n.distance<10?1:0))+" km ",1)):c("",!0)]),o("div",xe,[(n.type&&n.type,c("",!0)),n.street?(i(),r("div",we,_(n.street),1)):c("",!0),n.zip&&n.city?(i(),r("div",ke,_(n.zip)+" "+_(n.city),1)):c("",!0),n.country?(i(),r("div",be,[n.country==="DE"?(i(),r(m,{key:0},[p(" Deutschland ")],64)):n.country==="AT"?(i(),r(m,{key:1},[p(" Österreich ")],64)):n.country==="CH"?(i(),r(m,{key:2},[p(" Schweiz ")],64)):n.country==="FR"?(i(),r(m,{key:3},[p(" Frankreich ")],64)):n.country==="RS"?(i(),r(m,{key:4},[p(" Serbien ")],64)):(i(),r(m,{key:5},[p(_(n.country),1)],64))])):c("",!0)])]),_:2},1032,["to"]))),128))])):c("",!0)])])])])}}};export{Ne as default};