import{j as e}from"./ui-vendor-8uIfD_JC.js";import{i as G,r as i}from"./react-vendor-28t7dxFl.js";import{u as j}from"./useQuery-XqhZ5yOb.js";import{a as O}from"./analytics-vendor-Buw7Jr8C.js";import{b as x,B as Q,t as S,G as I,S as T}from"./index-BagLllOy.js";import{H as z}from"./header-B8URyXEE.js";import{F as H}from"./footer-B4a-Tf9e.js";import{L as K}from"./list-filters-n5aWiPdP.js";import{u as J,g as R,a as V,s as g,b,E as W,c as X}from"./user-preferences-Bp23os94.js";import{a as L}from"./api-Cp4ZovNS.js";import{g as Y,o as Z}from"./seo-BoELg83m.js";import{a as ee,M as te,b as se}from"./analytics-DwWXTewx.js";import"./convex-vendor-BbyM1w2O.js";import"./search-C9cjY_J1.js";import"./chevron-down-BbzELEph.js";import"./badge-DdeHRCon.js";import"./empty-CqAWvc3s.js";import"./status-badge-Ci7U3cAc.js";function Le(){const E=G(),c=J(),m=R(),[a,h]=i.useState(m.countryId||""),[o,y]=i.useState(m.cityId||""),[u,D]=i.useState(!1),[p,P]=i.useState(""),[k,w]=i.useState(!1),[l]=V(p,300),{data:r=[],isLoading:F}=j({queryKey:["countries"],queryFn:L.getCountries,staleTime:T.STATIC,gcTime:I.STATIC}),{data:d=[],isLoading:q}=j({queryKey:["cities",a],queryFn:()=>L.getCities(a),enabled:!!a,staleTime:T.STATIC,gcTime:I.STATIC}),{data:N=[],isLoading:ae}=j({queryKey:["shops",a,o],queryFn:()=>L.getShops({country_id:a,city_id:o}),enabled:!!o});i.useEffect(()=>{if(c.data&&r.length>0&&!a&&!m.countryId){const t=r.find(s=>s.name.toLowerCase()===c.data.country.toLowerCase());t?(h(t.id),g(t.id)):r.length>0&&(h(r[0].id),g(r[0].id))}},[c.data,r,a,m.countryId]),i.useEffect(()=>{if(c.data&&a&&d.length>0&&!o&&!m.cityId){const t=d.find(s=>s.name.toLowerCase()===c.data.city.toLowerCase());if(t)y(t.id),b(t.id);else{const n=d.find(C=>C.capital)?.id||d[0].id;y(n),b(n)}}},[c.data,a,d,o,m.cityId]);const f=i.useMemo(()=>{let t=N;if(u&&(t=t.filter(s=>s.open_to!==null)),l.trim()){const s=l.toLowerCase();t=t.filter(n=>n.name.toLowerCase().includes(s)||n.address.toLowerCase().includes(s))}return t.sort((s,n)=>{const C=s.rate??0;return(n.rate??0)-C})},[N,u,l]);i.useEffect(()=>{l.trim()&&ee(l,f.length)},[l,f.length]);const A=t=>{h(t),y(""),g(t),X()},M=t=>{y(t),b(t)},U=async()=>{w(!0);try{const t=await c.refresh(),s=r.find(n=>n.name.toLowerCase()===t.country.toLowerCase());s?(h(s.id),g(s.id),S.success(`Определено меÑтоположение: ${t.city}, ${t.country}`)):S.info("Ваша Ñтрана не найдена в ÑпиÑке")}catch{S.error("Ошибка при определении меÑтоположениÑ")}finally{w(!1)}},$=()=>{se("shops",{country:a,city:o,openNow:u||void 0,search:p||void 0});const t=new URLSearchParams;t.set("type","shops"),a&&t.set("country",a),o&&t.set("city",o),u&&t.set("openNow","true"),p&&t.set("search",p),E(`/map?${t.toString()}`)},_=Y([{name:"ГлавнаÑ",url:x.siteUrl},{name:"Магазины",url:`${x.siteUrl}/shops`}]),B=u||l.trim().length>0,v=`${x.siteUrl}/shops`;return e.jsxs(e.Fragment,{children:[e.jsxs(O,{children:[e.jsx("title",{children:"Магазины табачных изделий - ÑпиÑок | Goh.Place"}),e.jsx("meta",{name:"description",content:"СпиÑок магазинов табачных изделий. Фильтры по городам и Ñтранам, поиÑк по названию и адреÑу."}),B&&e.jsx("meta",{name:"robots",content:"noindex, follow"}),e.jsx("link",{rel:"canonical",href:v}),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:v}),e.jsx("meta",{property:"og:image",content:`${x.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(Z)}),e.jsx("script",{type:"application/ld+json",children:JSON.stringify(_)})]}),e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(z,{}),e.jsxs("div",{id:"main-content",className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"bg-gradient-to-b from-primary/10 to-background border-b",children:e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsx("div",{className:"max-w-6xl mx-auto",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl md:text-4xl font-bold mb-2",children:"Магазины"}),e.jsx("p",{className:"text-muted-foreground",children:f.length>0?`Ðайдено магазинов: ${f.length}`:"Выберите город Ð´Ð»Ñ Ð¿Ñ€Ð¾Ñмотра магазинов"})]}),o&&e.jsxs(Q,{size:"lg",onClick:$,className:"hover:scale-105 transition-transform shrink-0",children:[e.jsx(te,{className:"mr-2 size-5"}),"Отобразить на карте"]})]})})})}),e.jsx(K,{countries:r,cities:d,selectedCountryId:a,selectedCityId:o,onCountryChange:A,onCityChange:M,openNow:u,onOpenNowChange:D,searchQuery:p,onSearchQueryChange:P,onDetectLocation:U,isDetectingLocation:k,isLoadingCountries:F,isLoadingCities:q}),e.jsx("div",{className:"flex-1 bg-background",children:e.jsx("div",{className:"container mx-auto px-4 py-6",children:e.jsx("div",{className:"max-w-6xl mx-auto",children:e.jsx(W,{establishments:f,selectedEstablishment:null,onEstablishmentClick:()=>{},establishmentType:"shops",cities:d})})})})]}),e.jsx(H,{})]})]})}export{Le as default};