"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6215],{46215:function(e,t,n){n.r(t),n.d(t,{CATEGORIES:function(){return g},REGIONS:function(){return s},REGION_HIERARCHY:function(){return u},SPECIAL_TAG_TYPES:function(){return r},convertCountriesToDestinationData:function(){return y},fetchCountries:function(){return m},fetchCountriesByCategory:function(){return F},fetchCountriesByContinent:function(){return b},fetchCountriesByRegion:function(){return S},fetchCountriesBySearch:function(){return C},fetchCountriesByTag:function(){return A},fetchCountryDetails:function(){return x},fetchFeaturedCountries:function(){return w},fetchMinimalCountries:function(){return p},fetchSearchSuggestions:function(){return D},fetchTrendingCountries:function(){return v},getCountriesInRegion:function(){return h},isCountryInRegion:function(){return d},isSpecialTagType:function(){return l},normalizeTag:function(){return i}});var o=n(41121),a=n(96965),c=n(6021);console.debug("Country service core module loaded");let r=["continent","region"];function i(e){return(e||"").toLowerCase().trim()}function l(e){return r.includes(i(e))}let s={"Western Europe":["France","Germany","Netherlands","Belgium","Luxembourg","Switzerland","Austria"],"Eastern Europe":["Poland","Czech Republic","Slovakia","Hungary","Romania"],"Southern Europe":["Italy","Spain","Portugal","Greece"],"Northern Europe":["Sweden","Norway","Finland","Denmark","Iceland"],Balkans:["Croatia","Serbia","Bosnia and Herzegovina","Montenegro","Albania","North Macedonia"]},u=s,g={Popular:["Italy","France","Spain","Greece"],Trending:["Croatia","Portugal","Iceland"],"Family Friendly":["Netherlands","Denmark","Germany"],Beach:["Greece","Spain","Croatia","Portugal"],Adventure:["Iceland","Norway","Switzerland"]};function d(e,t){return!!e&&!!t&&(!!e.region&&i(e.region)===i(t)||(s[t]||[]).some(t=>i(t)===i(e.name||"")))}function h(e){return s[e]||[]}function f(){let e=[];return Object.entries(s).forEach(t=>{let[n,o]=t;o.forEach((t,o)=>{o<3&&e.push({id:"fallback-".concat(t.toLowerCase().replace(/\s+/g,"-")),name:t,slug:t.toLowerCase().replace(/\s+/g,"-"),region:n,country_name:t,continent:"Europe",description:"".concat(t," is a country in ").concat(n,"."),recommendedStay:7,rating:4.5,image:"",country_image:"",tags:[{id:n.toLowerCase(),name:n}],featured:g.Popular.includes(t),type:"country",capital:"",climate:"",food:"",culture:"",currency:"",currency_name:"",travel_seasons:""})})}),e}function y(e){return console.debug("Converting ".concat(e.length," countries to destination data format")),e.map(e=>{var t,n;let o=e.latitude,a=e.longitude,c=null!=o?"string"==typeof o?parseFloat(o):o:void 0,r=null!=a?"string"==typeof a?parseFloat(a):a:void 0;return{id:String(e.id||e.slug||Math.random().toString(36).substring(2,11)),name:e.name,slug:e.slug||e.name.toLowerCase().replace(/\s+/g,"-"),region:e.region||"",country_name:e.name,continent:(t=e.region||"")?t.includes("Europe")?"Europe":t.includes("Asia")?"Asia":t.includes("Africa")?"Africa":t.includes("America")||t.includes("Caribbean")?"Americas":t.includes("Oceania")||t.includes("Australia")?"Oceania":"Unknown":"Unknown",latitude:c,longitude:r,description:e.description||e.short_description||"",recommendedStay:7,rating:4.8,image:e.country_image||e.flag||"",country_image:e.country_image||"",flag:e.flag||"",tags:e.tags?e.tags.map(e=>({id:String("string"==typeof e?e:e.id),name:"string"==typeof e?e:e.name})):[],featured:(n=e.name,g.Popular.includes(n)),type:"country",capital:e.capital||"",climate:e.climate||"",food:e.food||"",culture:e.culture||"",currency:e.currency||"",currency_name:e.currency_name||"",travel_seasons:e.travel_seasons||""}})}let m=async()=>{console.debug("\uD83C\uDF10 Fetching all countries");let e=(0,a.aL)("allCountries");if(null==e?void 0:e.length)return console.log("Using cached countries data (".concat(e.length," countries)")),e;console.debug("Cache miss - checking global SWR cache"),(0,c.syncAllCachesWithSWR)();let t=(0,a.aL)("allCountries");if(null==t?void 0:t.length)return console.log("Using synced cache data (".concat(t.length," countries)")),t;console.log("Cache miss for countries - making API call");try{console.log("Making API request to /trip/countries/");let e=await o.Z.get("/trip/countries/");console.log("API response received: ".concat(e.status,", ").concat(e.data.length," countries"));let t=y(e.data);return(0,a.ax)("allCountries",t),(0,c.writeToSWRCache)("/trip/countries/",t),console.log("".concat(t.length," countries cached")),t}catch(t){console.error("Failed to fetch countries:",t),console.log("Falling back to generated data");let e=f();return console.log("Using ".concat(e.length," fallback countries")),(0,a.ax)("allCountries",e),console.log("Fallback countries data cached"),e}},p=async()=>{console.debug("\uD83C\uDF10 Fetching minimal countries data");let e=(0,a.aL)("minimalCountries");if(null==e?void 0:e.length)return console.log("Using cached minimal countries data (".concat(e.length," countries)")),e;let t=(0,a.aL)("allCountries");if(null==t?void 0:t.length)return console.log("Using cached regular countries as minimal countries"),(0,a.ax)("minimalCountries",t),t;(0,c.syncAllCachesWithSWR)();let n=(0,a.aL)("minimalCountries");if(null==n?void 0:n.length)return console.log("Using synced minimal countries data (".concat(n.length," countries)")),n;console.log("Cache miss for minimal countries - making API call");try{console.log("Making API request to /trip/countries/minimal/");let e=await o.Z.get("/trip/countries/minimal/");console.log("API response received: ".concat(e.status,", ").concat(e.data.length," minimal countries"));let t=y(e.data);return(0,a.ax)("minimalCountries",t),(0,c.writeToSWRCache)("/trip/countries/minimal/",t),console.log("".concat(t.length," minimal countries cached")),t}catch(e){console.error("Failed to fetch minimal countries:",e);try{let e=await m();return(0,a.ax)("minimalCountries",e),e}catch(t){console.error("Fallback to full countries also failed:",t);let e=f();return(0,a.ax)("minimalCountries",e),e}}},C=async e=>{if(!e||""===e.trim())return m();let t=e.toLowerCase().trim();console.debug('\uD83D\uDD0D Searching countries with query: "'.concat(t,'"'));let n=(0,a.aL)("countrySearch",t);if(null==n?void 0:n.length)return console.log('Using cached search results for "'.concat(t,'" (').concat(n.length," countries)")),n;try{let e=await o.Z.get("/trip/countries/?search=".concat(encodeURIComponent(t)));console.debug("✅ Found ".concat(e.data.length," countries matching search query"));let n=y(e.data);return(0,a.ax)("countrySearch",n,t),(0,c.writeToSWRCache)("/trip/countries/search/".concat(t),n),n}catch(n){console.error('Failed to search countries with query "'.concat(t,'":'),n);let e=(await m()).filter(e=>{var n,o,a,c,r,i,l,s;return!!(e.name.toLowerCase().includes(t)||(null===(n=e.country_name)||void 0===n?void 0:n.toLowerCase().includes(t))||(null===(o=e.description)||void 0===o?void 0:o.toLowerCase().includes(t))||(null===(a=e.capital)||void 0===a?void 0:a.toLowerCase().includes(t))||(null===(c=e.region)||void 0===c?void 0:c.toLowerCase().includes(t))||(null===(r=e.continent)||void 0===r?void 0:r.toLowerCase().includes(t))||(null===(i=e.culture)||void 0===i?void 0:i.toLowerCase().includes(t))||(null===(l=e.climate)||void 0===l?void 0:l.toLowerCase().includes(t))||(null===(s=e.tags)||void 0===s?void 0:s.some(e=>e.name.toLowerCase().includes(t))))});return(0,a.ax)("countrySearch",e,t),e}},D=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;if(!e||e.trim().length<2)return[];let n=e.toLowerCase().trim();console.debug('\uD83D\uDD0D Fetching search suggestions for: "'.concat(n,'"'));let c="suggestions-".concat(n,"-").concat(t),r=(0,a.aL)("countrySearch",c);if(null==r?void 0:r.length)return console.log('Using cached suggestions for "'.concat(n,'" (').concat(r.length," items)")),r;try{let e=await o.Z.get("/trip/countries/search/?q=".concat(encodeURIComponent(n),"&limit=").concat(t));console.debug("✅ Found ".concat(e.data.length," suggestion matches"));let r=y(e.data);return(0,a.ax)("countrySearch",r,c),r}catch(e){console.error('Failed to fetch search suggestions for "'.concat(n,'":'),e);try{let e=(0,a.aL)("allCountries")||(0,a.aL)("minimalCountries");if(null==e?void 0:e.length){let o=e.filter(e=>e.name.toLowerCase().includes(n)||e.region&&e.region.toLowerCase().includes(n)).slice(0,t);return(0,a.ax)("countrySearch",o,c),o}let o=(await p()).filter(e=>e.name.toLowerCase().includes(n)||e.region&&e.region.toLowerCase().includes(n)).slice(0,t);return(0,a.ax)("countrySearch",o,c),o}catch(e){return console.error("Fallback suggestion search failed:",e),[]}}},w=async()=>{console.debug("⭐ Fetching featured countries");let e=(0,a.aL)("featuredCountries");if(null==e?void 0:e.length)return console.log("Using cached featured countries data (".concat(e.length," countries)")),e;try{let e=await A("category","Popular");return(0,a.ax)("featuredCountries",e),e}catch(t){console.error("Failed to fetch featured countries:",t);let e=(await m()).filter(e=>g.Popular.includes(e.name));return(0,a.ax)("featuredCountries",e),e}},v=async()=>{console.debug("\uD83D\uDD25 Fetching trending countries");let e=(0,a.aL)("trendingCountries");if(null==e?void 0:e.length)return console.log("Using cached trending countries data (".concat(e.length," countries)")),e;try{let e=await A("category","Trending");(0,a.ax)("trendingCountries",e),(0,a.ax)("countriesByTag",e,"category-trending");try{localStorage.setItem("explore_cache_v1_trendingCountries",JSON.stringify({timestamp:Date.now(),expiry:Date.now()+36e5,data:e}))}catch(e){console.warn("Failed to cache trending countries to localStorage",e)}return e}catch(t){console.error("Failed to fetch trending countries:",t);let e=(await m()).filter(e=>g.Trending.includes(e.name));return(0,a.ax)("trendingCountries",e),e}},b=async e=>{console.debug('\uD83C\uDF0D Fetching countries by continent: "'.concat(e,'"'));let t=(0,a.aL)("countriesByContinent",e);if(null==t?void 0:t.length)return console.log("Using cached countries for continent ".concat(e," (").concat(t.length," countries)")),t;try{let t="/trip/countries/by-tag/continent/".concat(e);console.debug("\uD83D\uDCE4 API Request: GET ".concat(t));let n=await o.Z.get(t);console.debug("✅ Fetched ".concat(n.data.length," countries in continent ").concat(e));let r=Array.isArray(n.data)?n.data:n.data.results&&Array.isArray(n.data.results)?n.data.results:[],i=y(r);return(0,a.ax)("countriesByContinent",i,e),(0,c.writeToSWRCache)("/trip/countries/by-tag/continent/".concat(e),i),i}catch(t){console.error("Error fetching countries by continent:",t);try{console.debug("\uD83D\uDD04 Fallback: Fetching all countries and filtering by continent");let t=(await m()).filter(t=>{var n;let o=null===(n=t.tags)||void 0===n?void 0:n.some(t=>("string"==typeof t?t:t.name)===e),a=t.continent===e;return o||a});return console.debug("✅ Found ".concat(t.length," countries in continent ").concat(e," via fallback")),(0,a.ax)("countriesByContinent",t,e),t}catch(e){return console.error("Fallback error:",e),[]}}},S=async e=>{console.debug('\uD83C\uDFD9️ Fetching countries by region: "'.concat(e,'"'));let t=(0,a.aL)("countriesByRegion",e);if(null==t?void 0:t.length)return console.log("Using cached countries for region ".concat(e," (").concat(t.length," countries)")),t;try{let t="/trip/countries/by-tag/region/".concat(e);console.debug("\uD83D\uDCE4 API Request: GET ".concat(t));let n=await o.Z.get(t);console.debug("✅ Fetched ".concat(n.data.length," countries in region ").concat(e));let r=y(n.data);return(0,a.ax)("countriesByRegion",r,e),(0,c.writeToSWRCache)(t,r),r}catch(n){console.error('❌ Error fetching countries by region "'.concat(e,'":'),n),console.debug("\uD83D\uDD04 Fallback: Fetching all countries and filtering by region");let t=(await m()).filter(t=>{var n;return!!(t.region===e||s[e]&&s[e].includes(t.name)||(null===(n=t.tags)||void 0===n?void 0:n.some(t=>{let n="string"==typeof t?t:t.name,o="string"==typeof t?"":t.type||"";return n===e&&("region"===o||""===o)})))});return console.debug("✅ Found ".concat(t.length," countries in region ").concat(e," via fallback")),(0,a.ax)("countriesByRegion",t,e),t}},F=async e=>{let t="category-".concat(e),n=(0,a.aL)("countriesByTag",t);if(null==n?void 0:n.length)return console.log("Using cached countries for category ".concat(e," (").concat(n.length," countries)")),n;if("All Countries"===e){let e=await m();return(0,a.ax)("countriesByTag",e,t),e}if("Europe"===e){let e=await b("Europe");return(0,a.ax)("countriesByTag",e,t),e}if(["Western Europe","Eastern Europe","Balkans"].includes(e)){let n=await S(e);return(0,a.ax)("countriesByTag",n,t),n}let o=await A("category",e);return(0,a.ax)("countriesByTag",o,t),o},A=async(e,t)=>{if(!e||!t)return console.debug("\uD83D\uDD0D Missing type or value, fetching all countries"),m();let n=t,r=i(e),l=i(t);console.debug("\uD83D\uDD0D Fetching countries by tag: ".concat(r,"/").concat(l));let u="".concat(r,"-").concat(l),h="".concat(r,"_").concat(l),f=(0,a.aL)("countriesByTag",u);if((null==f?void 0:f.length)||(f=(0,a.aL)("countriesByTag",h)),null==f?void 0:f.length)return console.log("Using cached countries for tag ".concat(r,"/").concat(l," (").concat(f.length," countries)")),f;try{"category"===r&&(n=n.charAt(0).toUpperCase()+n.slice(1));let i="/trip/countries/by-tag/".concat(e,"/").concat(n,"/");console.debug("\uD83D\uDCE4 API Request: GET ".concat(i));let s=await o.Z.get(i);console.debug("✅ Fetched ".concat(s.data.length," countries for tag ").concat(r,"/").concat(l));let g=y(s.data);if((0,a.ax)("countriesByTag",g,u),(0,a.ax)("countriesByTag",g,h),"category"===r){if("trending"===l)(0,a.ax)("trendingCountries",g);else{let e="category".concat(t.charAt(0).toUpperCase()+t.slice(1));try{localStorage.setItem("explore_cache_v1_".concat(e),JSON.stringify({timestamp:Date.now(),expiry:Date.now()+36e5,data:g})),console.log("✅ Also cached to ".concat(e," format for page component"))}catch(t){console.warn("Failed to set localStorage cache for ".concat(e,":"),t)}}}if("region"===r){(0,a.ax)("countriesByRegion",g,l);let e="region_".concat(t);try{localStorage.setItem("explore_cache_v1_".concat(e),JSON.stringify({timestamp:Date.now(),expiry:Date.now()+36e5,data:g})),console.log("✅ Also cached to ".concat(e," format for page component"))}catch(t){console.warn("Failed to set localStorage cache for ".concat(e,":"),t)}}return(0,c.writeToSWRCache)(i,g),g}catch(e){if(console.error("❌ Error fetching countries by tag ".concat(r,"/").concat(l,":"),e),"region"===r&&Object.keys(s).some(e=>i(e)===l)){console.debug("\uD83D\uDD04 Falling back to client-side filtering for region ".concat(t));let e=(await m()).filter(e=>d(e,t));(0,a.ax)("countriesByTag",e,u),(0,a.ax)("countriesByTag",e,h),(0,a.ax)("countriesByRegion",e,l);let n="region_".concat(t);try{localStorage.setItem("explore_cache_v1_".concat(n),JSON.stringify({timestamp:Date.now(),expiry:Date.now()+36e5,data:e}))}catch(e){console.warn("Failed to set localStorage cache for ".concat(n,":"),e)}return e}if(g[t]){console.debug("\uD83D\uDD04 Falling back to predefined category for ".concat(t));let e=(await m()).filter(e=>g[t].some(t=>i(t)===i(e.name)));(0,a.ax)("countriesByTag",e,u),(0,a.ax)("countriesByTag",e,h),"trending"===l&&(0,a.ax)("trendingCountries",e);let n="category".concat(t.charAt(0).toUpperCase()+t.slice(1));try{localStorage.setItem("explore_cache_v1_".concat(n),JSON.stringify({timestamp:Date.now(),expiry:Date.now()+36e5,data:e}))}catch(e){console.warn("Failed to set localStorage cache for ".concat(n,":"),e)}return e}return[]}},x=async function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(console.log('[API] fetchCountryDetails called for "'.concat(e,'", forceRefresh: ').concat(t)),t)console.log('[API] Cache check bypassed for "'.concat(e,'" due to forceRefresh')),(0,a.D6)("countryDetails",e);else{let t=(0,a.aL)("countryDetails",e);if(t)return console.log('[API] Using cached details for "'.concat(e,'"')),t;console.log('[API] No cached data found for "'.concat(e,'"'))}try{let n=Date.now(),r="/trip/countries/".concat(encodeURIComponent(e),"/?_t=").concat(n);console.log("[API] Making API request to: ".concat(r));let i=await o.Z.get(r,{headers:{"Cache-Control":"no-cache, no-store, must-revalidate",Pragma:"no-cache",Expires:"0"}});console.log("[API] Response received for ".concat(e,":"),i.status);let l=i.data;console.log("[API] Country data received with fields:",Object.keys(l));let s={...l,latitude:"string"==typeof l.latitude?parseFloat(l.latitude):l.latitude,longitude:"string"==typeof l.longitude?parseFloat(l.longitude):l.longitude,region:"number"==typeof l.region?String(l.region):l.region,travel_seasons:Array.isArray(l.travel_seasons)?l.travel_seasons:"string"==typeof l.travel_seasons?[{season:"All Year",months:l.travel_seasons}]:[]};return t?console.log("[API] Skipped caching details for ".concat(e," due to forceRefresh")):((0,a.ax)("countryDetails",s,e),console.log("[API] Cached details for ".concat(e)),(0,c.writeToSWRCache)("/trip/countries/".concat(encodeURIComponent(e)),s)),s}catch(t){throw console.error("[API] Failed to fetch country details for ".concat(e,":"),t),t}}}}]);