"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6542],{66542:function(e,n,t){t.d(n,{_A:function(){return y},D1:function(){return m},tf:function(){return D},rC:function(){return b},$E:function(){return w},Rj:function(){return h},eG:function(){return F},cp:function(){return C},Uy:function(){return p},f4:function(){return g},cn:function(){return l}});var o,r,c=t(41121);let a={allCountries:null,featuredCountries:null,trendingCountries:null,countryDetails:{},countrySearch:{},countriesByTag:{},countriesByRegion:{},countriesByContinent:{},minimalCountries:{},timestamps:{allCountries:0,featuredCountries:0,trendingCountries:0,countryDetails:{},countrySearch:{},countriesByTag:{},countriesByRegion:{},countriesByContinent:{},minimalCountries:{}}};console.log("Resetting country cache".concat("").concat("")),a.allCountries=null,a.featuredCountries=null,a.trendingCountries=null,a.countryDetails={},a.countrySearch={},a.countriesByTag={},a.countriesByRegion={},a.countriesByContinent={},a.minimalCountries={},a.timestamps={allCountries:0,featuredCountries:0,trendingCountries:0,countryDetails:{},countrySearch:{},countriesByTag:{},countriesByRegion:{},countriesByContinent:{},minimalCountries:{}},console.log("Country service core module loaded");let i={allCountries:null,countriesByRegion:{},countriesByContinent:{},countrySearch:{},timestamps:{allCountries:0}},u=e=>Date.now()-i.timestamps[e]<36e5,s=["continent","region"];function l(e){return(e||"").toLowerCase().trim()}function g(e){return s.includes(l(e))}let d={"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"]},y=d,f={Popular:["Italy","France","Spain","Greece"],Trending:["Croatia","Portugal","Iceland"],"Family Friendly":["Netherlands","Denmark","Germany"],Beach:["Greece","Spain","Croatia","Portugal"],Adventure:["Iceland","Norway","Switzerland"]};function m(e){return console.debug("\uD83D\uDD04 Converting ".concat(e.length," countries to destination data format")),e.map(e=>{var n,t;return{id:String(e.id),name:e.name,slug:e.slug||e.name.toLowerCase().replace(/\s+/g,"-"),region:(null===(n=e.region)||void 0===n?void 0:n.toString())||"",country_name:e.name,continent:"Europe",description:e.description||"",recommendedStay:7,rating:4.8,image:e.country_image||e.flag||"",country_image:e.country_image||"",tags:e.tags?e.tags.map(e=>({id:String("string"==typeof e?e:e.id),name:"string"==typeof e?e:e.name})):[],featured:(null===(t=e.tags)||void 0===t?void 0:t.some(e=>"string"==typeof e&&"Featured"===e||"string"!=typeof e&&"featured"===e.type))||!1,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 D=async()=>{if(console.log("fetchCountries called"),console.debug("\uD83C\uDF10 Fetching all countries"),i.allCountries&&u("allCountries"))return console.log("Using cached countries data"),i.allCountries;console.log("Cache miss for countries - making API call");try{console.log("Making API request to /trip/countries/");let e=await c.Z.get("/trip/countries/");console.log("API response received:",e.status),console.debug("✅ Fetched ".concat(e.data.length," countries successfully"));let n=e.data;console.log("Received ".concat(n.length," countries from API"));let t=m(n);return i.allCountries=t,i.timestamps.allCountries=Date.now(),console.log("Countries data cached"),t}catch(n){console.error("Failed to fetch countries:",n),console.log("Falling back to generated data");let e=function(){let e=[];return Object.entries(d).forEach(n=>{let[t,o]=n;o.forEach((n,o)=>{o<3&&e.push({id:"fallback-".concat(n.toLowerCase().replace(/\s+/g,"-")),name:n,slug:n.toLowerCase().replace(/\s+/g,"-"),region:t,country_name:n,continent:"Europe",description:"".concat(n," is a country in ").concat(t,"."),recommendedStay:7,rating:4.5,image:"",country_image:"",tags:[{id:t.toLowerCase(),name:t}],featured:f.Popular.includes(n),type:"country",capital:"",climate:"",food:"",culture:"",currency:"",currency_name:"",travel_seasons:""})})}),e}();return console.log("Using ".concat(e.length," fallback countries")),i.allCountries||(i.allCountries=e,i.timestamps.allCountries=Date.now(),console.log("Fallback countries data cached")),e}},h=async e=>{if(!e||""===e.trim())return D();console.debug('\uD83D\uDD0D Searching countries with query: "'.concat(e,'"'));let n=e.toLowerCase().trim();if(i.countrySearch[n])return console.log('Using cached search results for "'.concat(e,'"')),i.countrySearch[n];try{let t=(await c.Z.get("/trip/countries/?search=".concat(encodeURIComponent(e)))).data;console.debug("✅ Found ".concat(t.length," countries matching search query"));let o=m(t);return i.countrySearch[n]=o,o}catch(o){console.error('Failed to search countries with query "'.concat(e,'":'),o);let t=(await D()).filter(n=>n.name.toLowerCase().includes(e.toLowerCase())||n.description&&n.description.toLowerCase().includes(e.toLowerCase())||n.capital&&n.capital.toLowerCase().includes(e.toLowerCase()));return i.countrySearch[n]=t,t}},C=async()=>(console.debug("⭐ Fetching featured countries"),F("category","Popular")),p=async()=>(console.debug("\uD83D\uDD25 Fetching trending countries"),F("category","Trending")),b=async e=>{console.log("Fetching countries for continent: ".concat(e)),console.debug('\uD83C\uDF0D Fetching countries by continent: "'.concat(e,'"'));let n="continent:".concat(e);if(i.countriesByContinent[n])return i.countriesByContinent[n];try{console.log("Making API request to /trip/countries/by-tag/continent/".concat(e,"/"));let t="/trip/countries/by-tag/continent/".concat(e);console.debug("\uD83D\uDCE4 API Request: GET ".concat(t));let o=await c.Z.get(t);console.debug("✅ Fetched ".concat(o.data.length," countries in continent ").concat(e));let r=Array.isArray(o.data)?o.data:o.data.results&&Array.isArray(o.data.results)?o.data.results:[],a=m(r);return i.countriesByContinent[n]=a,a}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 D()).filter(n=>{var t,o;return(null===(t=n.tags)||void 0===t?void 0:t.some(n=>("string"==typeof n?n:n.name)===e))||(null===(o=n.region)||void 0===o?void 0:o.includes(e))});return console.debug("✅ Found ".concat(t.length," countries in continent ").concat(e," via fallback")),i.countriesByContinent[n]=t,t}catch(e){return console.error("Fallback error:",e),[]}}},w=async e=>{if(console.debug('\uD83C\uDFD9️ Fetching countries by region: "'.concat(e,'"')),i.countriesByRegion[e])return console.log("Using cached countries for region ".concat(e)),i.countriesByRegion[e];try{let n="/trip/countries/by-tag/region/".concat(e);console.debug("\uD83D\uDCE4 API Request: GET ".concat(n));let t=await c.Z.get(n);console.debug("✅ Fetched ".concat(t.data.length," countries in region ").concat(e));let o=t.data,r=m(o);return i.countriesByRegion[e]=r,r}catch(t){console.error('❌ Error fetching countries by region "'.concat(e,'":'),t),console.debug("\uD83D\uDD04 Fallback: Fetching all countries and filtering by region");let n=(await D()).filter(n=>!!(n.region===e||d[e]&&d[e].includes(n.name)||n.tags&&n.tags.some(n=>{let t="string"==typeof n?n:n.name,o="string"==typeof n?"":n.type||"";return t===e&&("region"===o||""===o)})));return console.debug("✅ Found ".concat(n.length," countries in region ").concat(e," via fallback")),i.countriesByRegion[e]=n,n}},F=async(e,n)=>{if(!e||!n)return console.debug("\uD83D\uDD0D Missing type or value, fetching all countries"),D();let t=l(e),o=l(n);console.debug("\uD83D\uDD0D Fetching countries by tag: ".concat(t,"/").concat(o));try{let e="";g(t)?(console.debug("\uD83D\uDD0D Using ".concat(t," as tag type with value ").concat(n)),e="/trip/countries/by-tag/".concat(t,"/").concat(n)):(console.debug("\uD83D\uDD0D Using category type with value ".concat(n)),e="/trip/countries/by-tag/category/".concat(n)),console.debug("\uD83D\uDCE4 API Request: GET ".concat(e));let r=await c.Z.get(e);return console.debug("✅ Fetched ".concat(r.data.length," countries for tag ").concat(t,"/").concat(o)),m(r.data)}catch(e){if(console.error("❌ Error fetching countries by tag ".concat(t,"/").concat(o,":"),e),"region"===t&&Object.keys(d).some(e=>l(e)===o))return console.debug("\uD83D\uDD04 Falling back to client-side filtering for region ".concat(n)),(await D()).filter(e=>!!e&&!!n&&(!!e.region&&l(e.region)===l(n)||(d[n]||[]).some(n=>l(n)===l(e.name||""))));if("category"===t&&f[n])return console.debug("\uD83D\uDD04 Falling back to predefined category for ".concat(n)),(await D()).filter(e=>f[n].some(n=>l(n)===l(e.name)));return[]}}}}]);