var t,s,e,i,a,o,n,r=Object.defineProperty,h=(t,s,e)=>(((t,s,e)=>{s in t?r(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e})(t,"symbol"!=typeof s?s+"":s,e),e),c=(t,s,e)=>{if(!s.has(t))throw TypeError("Cannot "+e)},d=(t,s,e)=>(c(t,s,"read from private field"),e?e.call(t):s.get(t)),l=(t,s,e)=>{if(s.has(t))throw TypeError("Cannot add the same private member more than once");s instanceof WeakSet?s.add(t):s.set(t,e)},p=(t,s,e,i)=>(c(t,s,"write to private field"),i?i.call(t,e):s.set(t,e),e);import{r as g}from"./react-B_SyE9nW.js";import{aG as u,F as _,aH as T,P as m,aZ as y,au as L,aW as S,a_ as D,p as C,q as E,r as R,ao as f,y as O,V as I,R as w,aS as P,a$ as k}from"./index-Flm6m8Wj.js";import{B,S as U}from"./PublishContext-DeaOYrx6.js";const A=new class extends u{constructor(){super("/users/home_screen")}async getHomeTopLists(t){return this.get("_tops/",t,{isPublic:!_.isAuth})}async getTopActiveUserCity(t){return this.get("/top_active_user_city",t)}async getTopBestFoodieMonth(t){return this.get("/top_best_foodie_month",t)}async getTopBookmarkedListsCity(t){return this.get("/top_bookmarked_lists_city",t)}async getTopCuisineTypesNear(t){return this.get("/top_cuisine_types_near",t)}async getTopProduct(t){return this.get("/top_rated_dishes_near",t)}async getTopProductCity(t){return this.get("/top_rated_dishes_on_city",t)}},N={endpoint:"",params:{}};class v extends T{constructor(){super(),l(this,t,N),h(this,"setInfo",((s={...N})=>(p(this,t,s),this))),h(this,"clear",(()=>(this.resetPagination(),this.setInfo(),this))),h(this,"callSvc",(async({page:t,page_size:s})=>{const{endpoint:e,params:i}=this.info,{data:a,errors:o,success:n}=await A[e]({...i,page:t,page_size:s});return n||console.log(`ERROR: ${JSON.stringify(o,null,2)}`),{success:n,data:a}})),h(this,"onClickFollowState",(async(t=!1,s="")=>{if(await _.isValidAction({modalOpen:"LOGIN_FORM"})){m(!0);try{await y[t?"setUnfollow":"setFollow"](s),L((()=>this.elements.some((e=>{const i=e.username===s;return i&&(e.following=!t),i})))),this.setElements(S(this.elements))}catch(e){console.log("ERROR(followState): ",e)}finally{m()}}}))}get info(){return d(this,t)}}t=new WeakMap;class b extends B{constructor(){super(),h(this,"callSvc",(async({page:t,page_size:s})=>{const{search:e}=this.info,{errors:i,success:a,data:o}=await y.getLists(!1,{search:e,order_by:"-updated_at",is_default:!1,page:t,page_size:s});return a?o.results=o.results.map((t=>{const{name:s,uuid:e}=t;return{label:s,value:e,data:t}})):console.log(`ERROR: ${JSON.stringify(i,null,2)}`),{success:a,data:o}}))}}class M extends B{constructor(){super(),h(this,"callSvc",(async({page:t,page_size:s})=>{const{search:e,location:i}=this.info,a="-rating,-num_reviews",o={name:e,order_by:a,page:t,page_size:s};i&&(o.order_by=`location,${a}`,o.current_location=i);const{errors:n,success:r,data:h}=await D.getProducts(o);return r?h.results=h.results.map((({name:t,slug:s,...e})=>({label:`${t}${e&&e.business?` (${String(e.business.name)})`:""}`,value:s,data:e}))):console.log(`ERROR: ${JSON.stringify(n,null,2)}`),{success:r,data:h}}))}}class F extends B{constructor(){super(),h(this,"callSvc",(async({page:t,page_size:s})=>{const{search:e}=this.info,{errors:i,success:a,data:o}=await y.getUsers({search:e,page:t,page_size:s});return a?o.results=o.results.map((({profile_name:t="",username:s=""})=>({label:t,value:s}))):console.log(`ERROR: ${JSON.stringify(i,null,2)}`),{success:a,data:o}}))}}const $={SEARCH_NEAR:"search_near",SEARCH_CITY:"search_city",TOP_CUISINE_TYPES_NEAR:"top_cuisine_types_near",TOP_BOOKMARKED_LISTS_CITY:"top_bookmarked_lists_city",TOP_ACTIVE_USER_CITY:"top_active_user_city",TOP_BEST_FOODIE_MONTH:"top_best_foodie_month",TOP_RATED_DISHES_NEAR:"top_rated_dishes_near",TOP_RATED_DISHES_ON_CITY:"top_rated_dishes_on_city"},H={PRODUCT:"product",OTHER:"list",USER:"user",CUISINE:"product_tag"};function Y(t,s,e){return e&&(t[s]=e),t}s=new WeakMap,e=new WeakMap,i=new WeakMap,a=new WeakMap,o=new WeakMap,n=new WeakMap;const z=g.createContext(new class{constructor(){h(this,"data",[]),h(this,"topTitle",""),h(this,"topBestFoodieMonth"),h(this,"topActiveUser"),h(this,"topRatedDishes"),h(this,"topRatedDishesCity"),h(this,"topBookmarkedLists"),h(this,"topCuisineNear"),l(this,s,{}),l(this,e,new U),l(this,i,new M),l(this,a,new F),l(this,o,new b),l(this,n,new v),h(this,"loadingProduct",!1),h(this,"loadingActiveUsers",!1),h(this,"loadingDishes",!1),h(this,"loadingDishesCity",!1),h(this,"loadingBusiness",!1),h(this,"loadingUser",!1),h(this,"loadingList",!1),h(this,"loadingData",!0),h(this,"loadingTopProducts",!0),h(this,"loadingTopLists",!0),h(this,"loadingTopCuisines",!0),h(this,"loadingTopUsers",!0),h(this,"homeSections",[]),h(this,"setInfo",((t={})=>{p(this,s,t)})),h(this,"setLoadingData",((t=!1)=>{this.loadingData=t})),h(this,"setLoadingTopProducts",((t=!1)=>{this.loadingTopProducts=t})),h(this,"setLoadingTopLists",((t=!1)=>{this.loadingTopLists=t})),h(this,"setLoadingTopCuisines",((t=!1)=>{this.loadingTopCuisines=t})),h(this,"setLoadingTopUsers",((t=!1)=>{this.loadingTopUsers=t})),h(this,"setLoadingProduct",((t=!1)=>{this.loadingProduct=t})),h(this,"setLoadingDishes",((t=!1)=>{this.loadingDishes=t})),h(this,"setLoadingDishesCity",((t=!1)=>{this.loadingDishesCity=t})),h(this,"setLoadingBusiness",((t=!1)=>{this.loadingBusiness=t})),h(this,"setLoadingUser",((t=!1)=>{this.loadingUser=t})),h(this,"setLoadingList",((t=!1)=>{this.loadingList=t})),h(this,"setLoadingTopActiveUsers",((t=!1)=>{this.loadingActiveUsers=t})),h(this,"setTopBestFoodieMonth",(t=>{this.topBestFoodieMonth=t})),h(this,"setTopActiveUser",(t=>{this.topActiveUser=t})),h(this,"setTopBookmarkedLists",(t=>{this.topBookmarkedLists=t})),h(this,"setTopCuisineNear",(t=>{this.topCuisineNear=t})),h(this,"setTopRatedDishes",(t=>{this.topRatedDishes=t})),h(this,"setTopRatedDishesCity",(t=>{this.topRatedDishesCity=t})),h(this,"setHomeSections",(t=>{this.homeSections=t})),h(this,"setData",(t=>{this.data=t})),h(this,"clear",(()=>{d(this,o).clear(),d(this,e).clear(),d(this,i).clear(),d(this,a).clear()})),h(this,"loadBaseInfoData",(async t=>{f.isApiLoaded||f.init();let e=!1;if(p(this,s,{}),f.isApiLoaded){const{longitude:t,latitude:i}=await f.getCurrentPosition()||{};if(t&&i){e=!0,d(this,s).point=`${i},${t}`;const a=await f.fetchGeocode({location:{lat:i,lng:t}}),o=f.getTypeValueFromGeocode(a)||f.getTypeValueFromGeocode(a,"administrative_area_level_2")||f.getTypeValueFromGeocode(a,"administrative_area_level_1");Y(d(this,s),"city",o),Y(d(this,s),"place_id",a.place_id)}}return null==t||t(e),e})),h(this,"loadData",(async()=>{this.setLoadingData(!0);try{const t=await this.loadBaseInfoData(),{data:e,success:i,errors:a}=await A.getHomeTopLists(t?d(this,s):void 0);i?(this.setHomeSections(e),e.forEach((t=>{this.loadHomeSections({see_more:t.endpoint,name:t.name,type:t.type,search_limited:t.search_limited})}))):console.log(`ERROR: ${JSON.stringify(a,null,2)}`)}catch(t){console.log("ERROR: ",t)}finally{this.setLoadingData(!1)}})),h(this,"searchProd",[]),h(this,"loadProducts",(async(t,s="")=>{this.searchProd.push(t),this.setLoadingProduct(!0);const e=await d(this,i).clear().setInfo({search:t,location:s}).loadData();setTimeout((()=>{const t=this.searchProd.pop()||"";!e&&t?(this.searchProd=[],this.loadProducts(t,s)):this.setLoadingProduct()}))})),h(this,"searchBusiness",[]),h(this,"loadBusiness",(async(t,s="")=>{this.searchBusiness.push(t),this.setLoadingBusiness(!0);const i=await d(this,e).clear().setInfo({search:t,location:s}).loadData();setTimeout((()=>{const t=this.searchBusiness.pop()||"";!i&&t?(this.searchBusiness=[],this.loadBusiness(t,s)):this.setLoadingBusiness()}))})),h(this,"searchUser",[]),h(this,"loadUsers",(async t=>{if(d(this,a).clear(),!_.isAuth)return;this.searchUser.push(t),this.setLoadingUser(!0);const s=await d(this,a).setInfo({search:t}).loadData();setTimeout((()=>{const t=this.searchUser.pop()||"";!s&&t?(this.searchUser=[],this.loadUsers(t)):this.setLoadingUser()}))})),h(this,"searchList",[]),h(this,"loadLists",(async t=>{this.searchList.push(t),this.setLoadingList(!0);const s=await d(this,o).clear().setInfo({search:t}).loadData();setTimeout((()=>{const t=this.searchList.pop()||"";!s&&t?(this.searchList=[],this.loadLists(t)):this.setLoadingList()}))})),h(this,"onBookmarkCb",(t=>{t.refresh&&this.loadData()})),h(this,"onBookmarkTopCb",(async t=>{if(t.refresh){m(!0);try{const t=Y({page:1,page_size:50},"city",d(this,s).city);await A.getTopBookmarkedListsCity(t)}catch(e){console.log("ERROR: ",e)}finally{m()}}})),h(this,"onSeeMoreClick",(async({see_more:t,name:e,search_limited:i},a,o=!1)=>{this.topTitle=e;let n,r="";const h={page:1,page_size:50},{point:c,city:l,place_id:p}=d(this,s);switch(t){case $.TOP_ACTIVE_USER_CITY:Y(h,"city",l),r="getTopActiveUserCity",n=w.TopUsers;break;case $.TOP_BEST_FOODIE_MONTH:r="getTopBestFoodieMonth",n=w.TopBestFoodieMonth;break;case $.TOP_BOOKMARKED_LISTS_CITY:h.search_limited=i,i&&Y(h,"city",l),c||l||(h.search_limited=!1),l&&(Y(h,"city",l),h.search_limited=!0),r="getTopBookmarkedListsCity",n=w.TopLists;break;case $.TOP_CUISINE_TYPES_NEAR:h.search_limited=i,(i||o)&&Y(h,"point",c??k),r="getTopCuisineTypesNear",n=w.TopCuisine;break;case $.TOP_RATED_DISHES_ON_CITY:if(a.clearStore(),f.resetZoom(),a.setIsApiLoaded(!1),p&&i){let t,s="";if(a.setFilterLocation(p,!0),c){const[e,i]=c.split(",");e&&i&&(t={lat:Number(e),lng:Number(i)});const o=Y({country:"es"},"locality",l),n=await f.getGeocodeByLatLong(Number(e),Number(i),o);a.setFilterLocation(n.place_id),s=`${f.getTypeValueFromGeocode(n,"locality")}, ${f.getTypeValueFromGeocode(n,"country")}`}l&&await a.loadLocation(l,t),O.push(`${String(I(w.Search))}?location=${s}`)}else d(this,s).point&&i||O.push(`${String(I(w.Search))}?location=España`);return;case $.TOP_RATED_DISHES_NEAR:return a.clearStore(),f.resetZoom(),a.setIsApiLoaded(!1),void(c&&i?O.push(String(I(w.Search))):d(this,s).point||O.push(`${String(I(w.Search))}?location=España`))}await this.loadTopData(r,h,n)})),h(this,"loadTopUsersData",(async()=>{const t={page:1,page_size:4};m(!0);try{await d(this,n).clear().setInfo({params:t,endpoint:"getTopBestFoodieMonth"}).loadData()}catch(s){console.log("ERROR: ",s)}finally{m(!1)}})),h(this,"loadTopData",(async(t,s,e)=>{if(t){m(!0);try{await d(this,n).clear().setInfo({params:s,endpoint:t}).loadData();const{search:i}=O.location;O.push(`${String(I(e))}${i}`)}catch(i){console.log("ERROR: ",i)}finally{m(!1)}}})),h(this,"onClickCuisineTag",((t,e,i,a)=>{if(i.clearStore(),i.getCuisineTags.onChange([{label:t,value:e}]),d(this,s).point)O.push(a);else{const t=new URL(`${window.location.origin}${a}`);t.searchParams.set("location","Pamplona, España"),O.push(`${t.pathname}${t.search}`)}})),h(this,"onSearch",(async t=>{if(!t)return this.clear();this.setLoadingProduct(!0),this.setLoadingBusiness(!0),this.setLoadingList(!0),this.setLoadingUser(!0),await P(1),this.loadUsers(t).then(),this.loadLists(t).then();const s=await f.getCurrentPosition();let e="";const{latitude:i,longitude:a}=s||{latitude:void 0,longitude:void 0};i&&a&&(e=`${i},${a}`),this.loadProducts(t,e).then(),this.loadBusiness(t,e).then()})),h(this,"loadHomeSections",(async({see_more:t,name:e,type:i,search_limited:a})=>{this.topTitle=e;let o="";const n={page:1,page_size:50,is_home:!0,search_limited:a},{point:r,city:h}=d(this,s);switch(t){case $.TOP_ACTIVE_USER_CITY:{this.setLoadingTopActiveUsers(!0),Y(n,"city",h),o="getTopActiveUserCity";const t=new v;await t.clear().setInfo({params:n,endpoint:o}).loadData(),this.setTopActiveUser({name:e,type:i,top:t.getElements,see_more:$.TOP_ACTIVE_USER_CITY,search_limited:a}),this.setLoadingTopActiveUsers();break}case $.TOP_RATED_DISHES_NEAR:{this.setLoadingDishes(!0),Y(n,"point",r),o="getTopProduct";const t=new v;await t.clear().setInfo({params:n,endpoint:o}).loadData(),this.setTopRatedDishes({name:e,type:i,top:t.getElements,see_more:$.TOP_RATED_DISHES_NEAR,search_limited:a}),this.setLoadingDishes();break}case $.TOP_RATED_DISHES_ON_CITY:{this.setLoadingDishesCity(!0),Y(n,"city",h),o="getTopProductCity";const t=new v;await t.clear().setInfo({params:n,endpoint:o}).loadData(),this.setTopRatedDishesCity({name:e,type:i,top:t.getElements,see_more:$.TOP_RATED_DISHES_ON_CITY,search_limited:a}),this.setLoadingDishesCity();break}case $.TOP_BEST_FOODIE_MONTH:{this.setLoadingTopUsers(!0),o="getTopBestFoodieMonth";const t=new v;await t.clear().setInfo({params:n,endpoint:o}).loadData(),this.setTopBestFoodieMonth({name:e,type:i,top:t.getElements,see_more:$.TOP_BEST_FOODIE_MONTH,search_limited:a}),this.setLoadingTopUsers();break}case $.TOP_BOOKMARKED_LISTS_CITY:{this.setLoadingTopLists(!0),Y(n,"city",h),o="getTopBookmarkedListsCity";const t=new v;await t.clear().setInfo({params:n,endpoint:o}).loadData(),this.setTopBookmarkedLists({name:e,type:i,top:t.getElements,see_more:$.TOP_BOOKMARKED_LISTS_CITY,search_limited:a}),this.setLoadingTopLists();break}case $.TOP_CUISINE_TYPES_NEAR:{this.setLoadingTopCuisines(!0),Y(n,"point",r),o="getTopCuisineTypesNear";const t=new v;await t.clear().setInfo({params:n,endpoint:o}).loadData(),this.setTopCuisineNear({name:e,type:i,top:t.getElements,see_more:$.TOP_CUISINE_TYPES_NEAR,search_limited:a}),this.setLoadingTopCuisines();break}}})),h(this,"getSectionInfoByEndpoint",(t=>{switch(t){case"top_rated_dishes_near":return{loading:this.loadingDishes,data:this.getTopRatedDishes};case"top_cuisine_types_near":return{loading:this.loadingTopCuisines,data:this.getTopCuisineNear};case"top_rated_dishes_on_city":return{loading:this.loadingDishesCity,data:this.getTopRatedDishesCity};case"top_bookmarked_lists_city":return{loading:this.loadingTopLists,data:this.getTopBookmarkedLists};case"top_best_foodie_month":return{loading:this.loadingTopUsers,data:this.getTopBestFoodieMonth};default:return{loading:!1,data:void 0}}})),C(this,{data:E,loadingProduct:E,loadingDishes:E,loadingDishesCity:E,loadingBusiness:E,loadingUser:E,loadingList:E,loadingData:E,topRatedDishes:E,topRatedDishesCity:E,topBestFoodieMonth:E,topActiveUser:E,topBookmarkedLists:E,topCuisineNear:E,loadingTopProducts:E,loadingTopLists:E,loadingTopCuisines:E,loadingTopUsers:E,loadingActiveUsers:E,homeSections:E,setLoadingProduct:R,setLoadingDishes:R,setLoadingBusiness:R,setLoadingUser:R,setLoadingList:R,setData:R,setTopRatedDishes:R,setTopRatedDishesCity:R,setLoadingData:R,setTopActiveUser:R,setTopBestFoodieMonth:R,setTopBookmarkedLists:R,setTopCuisineNear:R,setLoadingTopProducts:R,setLoadingTopLists:R,setLoadingTopCuisines:R,setLoadingTopUsers:R,setLoadingTopActiveUsers:R,setHomeSections:R})}get businessStr(){return d(this,e)}get productStr(){return d(this,i)}get userStr(){return d(this,a)}get listStr(){return d(this,o)}get topStr(){return d(this,n)}get getInfoCity(){return d(this,s).city||""}get getInfo(){return d(this,s)}get getHomeSections(){return this.homeSections}get getData(){return this.data}get getTopTitle(){return this.topTitle}get getTopRatedDishes(){return this.topRatedDishes}get getTopRatedDishesCity(){return this.topRatedDishesCity}get getTopBestFoodieMonth(){return this.topBestFoodieMonth}get getTopActiveUser(){return this.topActiveUser}get getTopBookmarkedLists(){return this.topBookmarkedLists}get getTopCuisineNear(){return this.topCuisineNear}});export{z as H,$ as S,H as T};