import{j as e,C as me,a as ue,R as fe}from"./ui-vendor-8uIfD_JC.js";import{r as s,j as ge}from"./react-vendor-28t7dxFl.js";import{u as O}from"./useQuery-XqhZ5yOb.js";import{a as he}from"./analytics-vendor-Buw7Jr8C.js";import{d as xe,c as te,B as S,a as V,l as be,b as z,L as ve,t as F,G as W,S as B}from"./index-BagLllOy.js";import{X as je,H as we}from"./header-B8URyXEE.js";import{C as ke,N as Ce,S as J,d as Q,e as Z,f as X,h as Y,u as Te,g as Ne,a as Se,s as A,b as G,E as Le,c as Ee}from"./user-preferences-Bp23os94.js";import{I as Me}from"./input-BsaA4GDQ.js";import{S as ee}from"./search-C9cjY_J1.js";import{L as $e,G as ze}from"./maps-vendor-DDYrA5Sj.js";import{a as D}from"./api-Cp4ZovNS.js";import{g as Ie,o as _e}from"./seo-BoELg83m.js";import{b as Pe,M as Ae}from"./analytics-DwWXTewx.js";import"./convex-vendor-BbyM1w2O.js";import"./chevron-down-BbzELEph.js";import"./badge-DdeHRCon.js";import"./empty-CqAWvc3s.js";import"./status-badge-Ci7U3cAc.js";/**
 * @license lucide-react v0.546.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const De=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],Re=xe("list",De);function Ue({className:r,...m}){return e.jsx(me,{"data-slot":"checkbox",className:te("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",r),...m,children:e.jsx(ue,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:e.jsx(ke,{className:"size-3.5"})})})}function q({className:r,...m}){return e.jsx(fe,{"data-slot":"label",className:te("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",r),...m})}function Oe({establishmentType:r,onEstablishmentTypeChange:m,countries:L,cities:T,selectedCountryId:v,selectedCityId:E,onCountryChange:x,onCityChange:M,openNow:u,onOpenNowChange:g,searchQuery:j,onSearchQueryChange:o,onDetectLocation:h,isDetectingLocation:d=!1,isLoadingCountries:y=!1,isLoadingCities:p=!1}){const[I,w]=s.useState(!1);return e.jsx("div",{className:"bg-card border-b p-4",children:e.jsxs("div",{className:"max-w-4xl mx-auto space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:r==="places"?"default":"secondary",onClick:()=>m("places"),className:"flex-1",children:"Кальянные"}),e.jsx(S,{variant:r==="shops"?"default":"secondary",onClick:()=>m("shops"),className:"flex-1",children:"Магазины"})]}),e.jsxs("div",{className:"flex gap-2",children:[I?e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(ee,{className:"absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground"}),e.jsx(Me,{value:j,onChange:n=>o(n.target.value),placeholder:"Поиск заведений...",className:"pl-9 pr-9",autoFocus:!0}),j&&e.jsx("button",{onClick:()=>o(""),"aria-label":"Очистить поиск",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:e.jsx(je,{className:"size-4"})})]}):e.jsxs(S,{variant:"secondary",onClick:()=>w(!0),className:"min-w-[120px]",children:[e.jsx(ee,{className:"mr-2 size-4"}),"Поиск"]}),h&&e.jsx(S,{variant:"secondary",size:"icon",onClick:h,disabled:d,title:"Определить моё местоположение",className:"shrink-0",children:e.jsx(Ce,{className:`size-4 ${d?"animate-pulse":""}`})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:"Страна"}),y?e.jsx(V,{className:"h-10 w-full"}):e.jsxs(J,{value:v,onValueChange:x,children:[e.jsx(Q,{children:e.jsx(Z,{placeholder:"Выберите страну"})}),e.jsx(X,{children:L.map(n=>e.jsx(Y,{value:n.id,children:n.name},n.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:"Город"}),p?e.jsx(V,{className:"h-10 w-full"}):e.jsxs(J,{value:E,onValueChange:M,disabled:!v||T.length===0,children:[e.jsx(Q,{children:e.jsx(Z,{placeholder:v?"Выберите город":"Сначала выберите страну"})}),e.jsx(X,{children:T.map(n=>e.jsx(Y,{value:n.id,children:n.name},n.id))})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ue,{id:"open-now",checked:u,onCheckedChange:g}),e.jsx(q,{htmlFor:"open-now",className:"cursor-pointer",children:"Открыто сейчас"})]}),j&&e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{o(""),w(!1)},children:"Сбросить поиск"})]})]})})}const Fe={width:"100%",height:"100%"},Ge={lat:55.7558,lng:37.6173},qe=[{featureType:"all",elementType:"labels.text.fill",stylers:[{saturation:36},{color:"#858585"},{lightness:10}]},{featureType:"all",elementType:"labels.text.stroke",stylers:[{visibility:"on"},{color:"#272726"}]},{featureType:"all",elementType:"labels.icon",stylers:[{visibility:"off"}]},{featureType:"administrative",elementType:"geometry.fill",stylers:[{color:"#323432"},{lightness:20}]},{featureType:"administrative",elementType:"geometry.stroke",stylers:[{color:"#323432"},{lightness:17},{weight:1.2}]},{featureType:"administrative.locality",elementType:"labels.text.fill",stylers:[{color:"#e6e6e6"}]},{featureType:"landscape",elementType:"geometry",stylers:[{color:"#323432"}]},{featureType:"landscape.man_made",elementType:"geometry.fill",stylers:[{visibility:"on"},{color:"#323432"}]},{featureType:"landscape.man_made",elementType:"geometry.stroke",stylers:[{color:"#323432"},{visibility:"on"}]},{featureType:"poi",elementType:"geometry",stylers:[{color:"#2f2f2e"},{lightness:"7"}]},{featureType:"poi",elementType:"labels.text.fill",stylers:[{color:"#858585"}]},{featureType:"poi",elementType:"labels.text.stroke",stylers:[{visibility:"on"},{color:"#272726"},{weight:1}]},{featureType:"road.highway",elementType:"geometry.fill",stylers:[{color:"#454545"}]},{featureType:"road.highway",elementType:"geometry.stroke",stylers:[{weight:.2},{visibility:"on"},{color:"#2f2f2e"}]},{featureType:"road.highway",elementType:"labels.text.fill",stylers:[{color:"#454545"}]},{featureType:"road.highway",elementType:"labels.text.stroke",stylers:[{visibility:"on"},{color:"#2f2f2e"}]},{featureType:"road.arterial",elementType:"geometry",stylers:[{color:"#2f2f2e"},{lightness:18}]},{featureType:"road.arterial",elementType:"geometry.fill",stylers:[{color:"#454545"}]},{featureType:"road.arterial",elementType:"geometry.stroke",stylers:[{visibility:"on"},{color:"#2f2f2e"}]},{featureType:"road.arterial",elementType:"labels.text.fill",stylers:[{color:"#c9c9c9"}]},{featureType:"road.local",elementType:"geometry",stylers:[{color:"#55553"}]},{featureType:"road.local",elementType:"geometry.fill",stylers:[{color:"#2f2f2e"},{visibility:"on"}]},{featureType:"road.local",elementType:"geometry.stroke",stylers:[{visibility:"off"}]},{featureType:"road.local",elementType:"labels.text.fill",stylers:[{color:"#595959"}]},{featureType:"transit",elementType:"geometry",stylers:[{color:"#2f2f2e"}]},{featureType:"water",elementType:"geometry",stylers:[{color:"#191a1a"}]}],Ke="/images/map-marker-icon.png",He="DEMO_MAP_ID";function Ve({establishments:r,center:m,onMarkerClick:L,selectedEstablishment:T,establishmentType:v,cities:E}){const[x,M]=s.useState(null),[u,g]=s.useState(null),[j,o]=s.useState(!1),[h,d]=s.useState(null),y=s.useRef(new Map),p=s.useRef(new Map),I=s.useCallback(async n=>{if(M(n),window.google?.maps?.importLibrary)try{const a=await window.google.maps.importLibrary("marker");d(a),o(!0)}catch(a){be.error("Failed to load marker library",{context:"MapContainer",error:a}),o(!0)}else o(!0)},[]),w=s.useCallback(()=>{y.current.forEach(n=>{n.map=null}),y.current.clear(),p.current.forEach(n=>{n.close()}),p.current.clear(),M(null),o(!1),d(null)},[]);return s.useEffect(()=>{if(!x||!j||!h)return;const n=h.AdvancedMarkerElement;return y.current.forEach(a=>{a.map=null}),y.current.clear(),p.current.forEach(a=>{a.close()}),p.current.clear(),r.forEach(a=>{const k=T?.id===a.id,C={lat:a.lat,lng:a.lon},N=E.find(f=>f.id===a.city_id)?.slug||a.city_id,P=v==="places"?`/place/${N}/${a.slug}`:`/shop/${N}/${a.slug}`,l=document.createElement("div");l.style.width=k?"48px":"40px",l.style.height=k?"48px":"40px",l.style.backgroundImage=`url(${Ke})`,l.style.backgroundSize="contain",l.style.backgroundRepeat="no-repeat",l.style.backgroundPosition="center",l.style.cursor="pointer",l.style.transition="transform 0.2s",l.title=a.name;const b=new n({map:x,position:C,content:l});l.addEventListener("click",()=>{L(a)}),l.addEventListener("mouseenter",()=>{g(a.id),l.style.transform="scale(1.1)"}),l.addEventListener("mouseleave",()=>{g(null),l.style.transform="scale(1)"}),y.current.set(a.id,b);const R=new google.maps.InfoWindow({content:`
          <div style="padding: 8px; max-width: 300px;">
            <div style="display: flex; gap: 12px; align-items: flex-start;">
              ${a.icon_image?`
                <img 
                  src="${a.icon_image.url}" 
                  alt="${a.name}" 
                  style="width: 48px; height: 48px; border-radius: 4px; object-fit: cover; flex-shrink: 0;"
                />
              `:""}
              <div style="flex: 1; min-width: 0;">
                <h3 style="font-weight: bold; font-size: 14px; margin-bottom: 4px; color: #111827; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
                  ${a.name}
                </h3>
                <div style="display: flex; align-items: flex-start; gap: 4px; font-size: 12px; color: #4b5563; margin-bottom: 4px;">
                  <span style="margin-top: 2px;">📍</span>
                  <span style="display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;">
                    ${a.address}
                  </span>
                </div>
                ${a.open_to?`
                  <div style="display: flex; align-items: center; gap: 4px; font-size: 12px; color: #16a34a; margin-bottom: 4px;">
                    <span>🕐</span>
                    <span>
                      ${a.open_to==="Круглосуточно"?"Круглосуточно":`Открыто до ${a.open_to}`}
                    </span>
                  </div>
                `:""}
                ${a.open_in?`
                  <div style="display: flex; align-items: center; gap: 4px; font-size: 12px; color: #dc2626; margin-bottom: 4px;">
                    <span>🕐</span>
                    <span>Откроется в ${a.open_in}</span>
                  </div>
                `:""}
                ${a.rate?`
                  <div style="display: flex; align-items: center; gap: 4px; font-size: 12px; color: #d97706; margin-top: 4px;">
                    <span>⭐</span>
                    <span>${a.rate.toFixed(1)}</span>
                  </div>
                `:""}
                <a href="${P}" style="display: inline-block; margin-top: 8px; color: #6366f1; font-size: 13px; font-weight: 500; text-decoration: none;">
                  Подробнее →
                </a>
              </div>
            </div>
          </div>
        `});p.current.set(a.id,R)}),()=>{y.current.forEach(a=>{a.map=null}),y.current.clear(),p.current.forEach(a=>{a.close()}),p.current.clear()}},[x,j,h,r,T,v,E,L]),s.useEffect(()=>{if(!x||!u){p.current.forEach(C=>{C.close()});return}if(!r.find(C=>C.id===u))return;const a=p.current.get(u),k=y.current.get(u);a&&k&&a.open({map:x,anchor:k})},[u,x,r]),e.jsx($e,{googleMapsApiKey:z.googleMapsApiKey,libraries:["marker"],children:e.jsx(ze,{mapContainerStyle:Fe,center:m||Ge,zoom:13,onLoad:I,onUnmount:w,options:{streetViewControl:!1,mapTypeControl:!1,fullscreenControl:!1,styles:qe,disableDefaultUI:!1,zoomControl:!0,gestureHandling:"greedy",minZoom:3,maxZoom:20,mapId:He}})})}function pt(){const r=Te(),[m,L]=ge(),T=m.get("type"),v=m.get("country"),E=m.get("city"),x=m.get("openNow")==="true",M=m.get("search"),u=Ne(),[g,j]=s.useState(T||"places"),[o,h]=s.useState(v||u.countryId||""),[d,y]=s.useState(E||u.cityId||""),[p,I]=s.useState(x),[w,n]=s.useState(M||""),[a,k]=s.useState(!1),[C,_]=s.useState(null),[N,P]=s.useState(!0),[l]=Se(w,300),{data:b=[],isLoading:R}=O({queryKey:["countries"],queryFn:D.getCountries,staleTime:B.STATIC,gcTime:W.STATIC}),{data:f=[],isLoading:ae}=O({queryKey:["cities",o],queryFn:()=>D.getCities(o),enabled:!!o,staleTime:B.STATIC,gcTime:W.STATIC}),{data:K=[],isLoading:se}=O({queryKey:[g,o,d],queryFn:()=>g==="places"?D.getPlaces({country_id:o,city_id:d}):D.getShops({country_id:o,city_id:d}),enabled:!!d});s.useEffect(()=>{if(r.data&&b.length>0&&!o&&!u.countryId){const t=b.find(c=>c.name.toLowerCase()===r.data.country.toLowerCase());t?(h(t.id),A(t.id)):b.length>0&&(h(b[0].id),A(b[0].id))}},[r.data,b,o,u.countryId]),s.useEffect(()=>{if(r.data&&o&&f.length>0&&!d&&!u.cityId){const t=f.find(c=>c.name.toLowerCase()===r.data.city.toLowerCase());if(t)y(t.id),G(t.id);else{const i=f.find(ye=>ye.capital)?.id||f[0].id;y(i),G(i)}}},[r.data,o,f,d,u.cityId]);const U=s.useMemo(()=>{let t=K;if(p&&(t=t.filter(c=>c.open_to!==null)),l.trim()){const c=l.toLowerCase();t=t.filter(i=>i.name.toLowerCase().includes(c)||i.address.toLowerCase().includes(c))}return t},[K,p,l]),re=s.useMemo(()=>{const t=f.find(c=>c.id===d);return t?{lat:t.lat,lng:t.lon}:r.data?{lat:r.data.lat,lng:r.data.lon}:{lat:55.7558,lng:37.6173}},[d,f,r.data]);s.useEffect(()=>{Pe(g,{country:o||void 0,city:d||void 0,openNow:p||void 0,search:w||void 0})},[]);const $=t=>{L(c=>{const i=new URLSearchParams(c);return t.type!==void 0&&(t.type==="places"?i.delete("type"):i.set("type",t.type)),t.country!==void 0&&(t.country?i.set("country",t.country):i.delete("country")),t.city!==void 0&&(t.city?i.set("city",t.city):i.delete("city")),t.openNow!==void 0&&(t.openNow?i.set("openNow","true"):i.delete("openNow")),t.search!==void 0&&(t.search?i.set("search",t.search):i.delete("search")),i},{replace:!0})},oe=t=>{j(t),$({type:t})},ne=t=>{h(t),y(""),_(null),A(t),Ee(),$({country:t,city:""})},le=t=>{y(t),_(null),G(t),$({city:t})},ie=t=>{I(t),$({openNow:t})},ce=t=>{n(t),$({search:t})},H=t=>{_(t)},de=async()=>{k(!0);try{const t=await r.refresh(),c=b.find(i=>i.name.toLowerCase()===t.country.toLowerCase());c?(h(c.id),A(c.id),$({country:c.id,city:""}),F.success(`Определено местоположение: ${t.city}, ${t.country}`)):F.info("Ваша страна не найдена в списке")}catch{F.error("Ошибка при определении местоположения")}finally{k(!1)}},pe=Ie([{name:"Главная",url:z.siteUrl},{name:"Карта",url:`${z.siteUrl}/map`}]);return e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx("title",{children:"Карта кальянных и магазинов | Goh.Place"}),e.jsx("meta",{name:"description",content:"Интерактивная карта кальянных и магазинов табачных изделий. Поиск по городам и странам, фильтры по времени работы и рейтингам."}),e.jsx("link",{rel:"canonical",href:`${z.siteUrl}/map`}),e.jsx("meta",{property:"og:title",content:"Карта кальянных и магазинов | Goh.Place"}),e.jsx("meta",{property:"og:description",content:"Интерактивная карта кальянных и магазинов табачных изделий. Найдите лучшие заведения в вашем городе."}),e.jsx("meta",{property:"og:type",content:"website"}),e.jsx("meta",{property:"og:url",content:`${z.siteUrl}/map`}),e.jsx("meta",{property:"og:image",content:`${z.siteUrl}/images/logo-favicon.png`}),e.jsx("meta",{property:"og:site_name",content:"Goh.Place"}),e.jsx("script",{type:"application/ld+json",children:JSON.stringify(_e)}),e.jsx("script",{type:"application/ld+json",children:JSON.stringify(pe)})]}),e.jsxs("div",{className:"h-screen flex flex-col",children:[e.jsx(we,{}),e.jsxs("div",{id:"main-content",className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Oe,{establishmentType:g,onEstablishmentTypeChange:oe,countries:b,cities:f,selectedCountryId:o,selectedCityId:d,onCountryChange:ne,onCityChange:le,openNow:p,onOpenNowChange:ie,searchQuery:w,onSearchQueryChange:ce,onDetectLocation:de,isDetectingLocation:a,isLoadingCountries:R,isLoadingCities:ae}),e.jsxs("div",{className:"md:hidden flex gap-2 p-2 bg-card border-b",children:[e.jsxs(S,{variant:N?"default":"secondary",onClick:()=>P(!0),className:"flex-1",size:"sm",children:[e.jsx(Ae,{className:"mr-2 size-4"}),"Карта"]}),e.jsxs(S,{variant:N?"secondary":"default",onClick:()=>P(!1),className:"flex-1",size:"sm",children:[e.jsx(Re,{className:"mr-2 size-4"}),"Список (",U.length,")"]})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("div",{className:`${N?"flex-1":"hidden md:flex md:flex-1"} relative`,children:[se&&e.jsx("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm flex items-center justify-center z-10",children:e.jsx(ve,{className:"size-8 animate-spin text-primary"})}),e.jsx(Ve,{establishments:U,center:re,onMarkerClick:H,selectedEstablishment:C,establishmentType:g,cities:f})]}),e.jsx("div",{className:`${N?"hidden md:block md:w-96":"w-full"} border-l bg-card overflow-hidden`,children:e.jsx(Le,{establishments:U,selectedEstablishment:C,onEstablishmentClick:H,establishmentType:g,cities:f,compact:!0})})]})]})]})]})}export{pt as default};