"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6706],{6021:function(e,t,n){let i,a;n.r(t),n.d(t,{clearAllCaches:function(){return C},debugCacheState:function(){return w},flushCachesToStorage:function(){return v},getCacheStatus:function(){return f},initializeGlobalCache:function(){return h},migrateCache:function(){return S},safeGetItem:function(){return g},safeSetItem:function(){return d},syncAllCachesWithSWR:function(){return p},validateAndRepairCache:function(){return b},validateCacheData:function(){return y},writeToSWRCache:function(){return m}});var o=n(96965),c=n(9212),r=n(6275);let s="auth_data",l=()=>"undefined"!=typeof localStorage,u=new Map,g=e=>{try{if(!l())return console.debug("Server-side getItem for ".concat(e,", using memory cache")),u.get(e)||null;let t=localStorage.getItem(e);if(t){let n=Math.round(t.length/1024);n>1&&console.debug("Retrieved ".concat(e,": ").concat(n," KB"))}return t}catch(t){return console.warn("Failed to access storage for key ".concat(e,":"),t),null}},d=(e,t)=>{try{if(!l())return console.debug("Server-side setItem for ".concat(e,", using memory cache")),u.set(e,t),!0;localStorage.setItem(e,t);let n=Math.round(t.length/1024);return n>1&&console.debug("Saved ".concat(e,": ").concat(n," KB")),!0}catch(t){return console.warn("Failed to write to storage for key ".concat(e,":"),t),!1}},y=e=>e?Array.isArray(e)?e.every(e=>Array.isArray(e)&&2===e.length&&"string"==typeof e[0]&&e[1]&&"object"==typeof e[1])?{valid:!0}:{valid:!1,reason:"Invalid entry structure"}:{valid:!1,reason:"Not an array"}:{valid:!1,reason:"Empty data"};function m(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];try{console.log("Writing to SWR cache: ".concat(e," with ").concat(Array.isArray(t)?t.length+" items":"object"));let i=g(c.oy)||"[]";try{let a=JSON.parse(i),o=new Map(a.map(e=>{let[t,n]=e;return[t,{data:n.data}]}));o.set(e,{data:t});let r=Array.from(o.entries()),s=d(c.oy,JSON.stringify(r));return n&&s&&d(c.TI,JSON.stringify(r)),console.log("SWR cache updated, now has ".concat(r.length," entries")),s}catch(o){console.error("Failed to parse existing cache:",o);let i=[[e,{data:t}]],a=d(c.oy,JSON.stringify(i));return n&&a&&d(c.TI,JSON.stringify(i)),console.log("Created new cache with single entry"),a}}catch(e){return console.error("Failed to write to SWR cache:",e),!1}}function h(){if(!l()||(console.log("Initializing global cache system"),i=(0,o.Mp)(),a=(0,r.initCityCache)(),!l())){console.debug("Server environment detected, skipping cache initialization");return}console.log("Initializing global cache system"),S();let e=p();e.success||console.warn("Initial cache sync failed:",e.error),setTimeout(()=>{try{let e=f();console.log("Cache initialization verification:",e)}catch(e){console.error("Error verifying cache initialization:",e)}},500)}function p(){if(!l())return console.debug("Server environment detected, skipping cache sync"),{success:!1,error:"Cannot sync caches in server environment"};console.debug("Syncing caches with SWR");try{let e,t=g(c.oy);if(!t&&(console.debug("No versioned cache found, checking legacy cache"),(t=g(c.TI))&&(console.debug("Found legacy cache, will use and migrate it"),d(c.oy,t))),!t)return{success:!1,error:"No SWR cache data found in storage"};try{e=JSON.parse(t)}catch(e){return{success:!1,error:"Failed to parse cache data: "+String(e)}}let n=y(e);if(!n.valid)return{success:!1,error:"Invalid cache data: "+n.reason};let i=e,r={countries:!1,cities:!1,auth:!1},s=i.find(e=>e[0]&&e[0].includes("/trip/countries/"));s&&s[1]&&s[1].data&&Array.isArray(s[1].data)&&(console.debug("Found country data in SWR cache with ".concat(s[1].data.length," countries")),(0,o.ax)("allCountries",s[1].data),r.countries=!0);let l=i.find(e=>e[0]&&e[0].includes("/trip/cities/"));l&&l[1]&&l[1].data&&Array.isArray(l[1].data)&&(console.debug("Found city data in SWR cache with ".concat(l[1].data.length," cities")),a.allCities=l[1].data,a.timestamps.allCities=Date.now(),r.cities=!0);let u=i.find(e=>e[0]&&e[0].includes("/api/auth/user"));return u&&u[1]&&u[1].data&&(r.auth=!0),{success:!0,syncedItems:r}}catch(e){return console.error("Error syncing with SWR cache:",e),{success:!1,error:String(e)}}}function f(){if(!l())return{timestamp:Date.now(),environment:"server",status:"unavailable in server environment"};try{var e,t,n,o,r,u,d;let l=g(c.oy),y=g(c.TI),m=g(s),h=[],p=null;try{l?h=JSON.parse(l):y&&(h=JSON.parse(y))}catch(e){p=String(e)}let f=h.find(e=>e[0]&&e[0].includes("/trip/countries/")),C=h.find(e=>e[0]&&e[0].includes("/trip/cities/")),S=h.find(e=>e[0]&&e[0].includes("/api/auth/user")),v=null,b=null;try{m&&(b=(null==(v=JSON.parse(m))?void 0:v.expiresAt)||null)}catch(e){}let w=Date.now();return{timestamp:w,formattedTime:new Date(w).toISOString(),environment:"browser",swr:{exists:!!(l||y),entryCount:h.length,version:"1.0.0",key:c.oy,versionedCacheExists:!!l,legacyCacheExists:!!y,parseError:p,countryData:f?{exists:!0,count:Array.isArray(null===(e=f[1])||void 0===e?void 0:e.data)?f[1].data.length:0}:{exists:!1},cityData:C?{exists:!0,count:Array.isArray(null===(t=C[1])||void 0===t?void 0:t.data)?C[1].data.length:0}:{exists:!1},authData:S?{exists:!0,type:typeof(null===(n=S[1])||void 0===n?void 0:n.data)}:{exists:!1}},countryCache:{allCountries:{exists:!!i.allCountries,count:(null===(o=i.allCountries)||void 0===o?void 0:o.length)||0,timestamp:i.timestamps.allCountries,age:w-i.timestamps.allCountries},featuredCountries:{exists:!!i.featuredCountries,count:(null===(r=i.featuredCountries)||void 0===r?void 0:r.length)||0,timestamp:i.timestamps.featuredCountries,age:w-i.timestamps.featuredCountries},minimalCountries:{exists:!!i.minimalCountries,count:(null===(u=i.minimalCountries)||void 0===u?void 0:u.length)||0,timestamp:i.timestamps.minimalCountries,age:w-i.timestamps.minimalCountries}},cityCache:{allCities:{exists:!!a.allCities,count:(null===(d=a.allCities)||void 0===d?void 0:d.length)||0,timestamp:a.timestamps.allCities,age:w-a.timestamps.allCities},citiesByRegion:Object.keys(a.citiesByRegion).length,citiesByCountry:Object.keys(a.citiesByCountry).length},authCache:{exists:!!m,expired:b?w>b:null,timeToExpiry:b?b-w:null}}}catch(e){return console.error("Error getting cache status:",e),{error:"Failed to retrieve cache status: "+String(e)}}}function C(){console.log("Clearing all caches");try{l()&&(localStorage.removeItem(c.oy),localStorage.removeItem(c.TI),localStorage.removeItem(s)),i.allCountries=null,i.featuredCountries=null,i.trendingCountries=null,i.minimalCountries=null,i.countryDetails={},i.countrySearch={},i.countriesByTag={},i.countriesByRegion={},i.countriesByContinent={},i.timestamps.allCountries=0,i.timestamps.featuredCountries=0,i.timestamps.trendingCountries=0,i.timestamps.minimalCountries=0,i.timestamps.countryDetails={},i.timestamps.countrySearch={},i.timestamps.countriesByTag={},i.timestamps.countriesByRegion={},i.timestamps.countriesByContinent={},a.allCities=null,a.citiesByRegion={},a.citiesByCountry={},a.cityDetails={},a.citySearch={},a.timestamps={allCities:0},console.log("All caches successfully cleared")}catch(e){console.error("Error clearing caches:",e)}}function S(){if(!l())return!1;console.log("Starting cache migration check...");try{let e=g(c.TI),t=g(c.oy);if(!e&&!t)return console.log("No cache exists yet, no migration needed"),!1;if(e){if(t){console.log("Both legacy and versioned caches exist, checking if merge is needed...");try{let n=JSON.parse(e),i=JSON.parse(t);if(Array.isArray(n)&&Array.isArray(i)){if(n.length>i.length)return console.log("Legacy cache has more entries, using it as primary"),d(c.oy,e),!0;return console.log("Versioned cache has same or more entries, keeping it as primary"),d(c.TI,t),!0}}catch(n){console.error("Error parsing caches during migration:",n);try{return JSON.parse(t),console.log("Using valid versioned cache"),d(c.TI,t),!0}catch(t){try{return JSON.parse(e),console.log("Versioned cache is corrupted, using legacy cache"),d(c.oy,e),!0}catch(e){console.log("Both caches are corrupted, clearing them"),localStorage.removeItem(c.oy),localStorage.removeItem(c.TI)}}}}else{console.log("Found legacy unversioned cache but no versioned cache, migrating...");let t=d(c.oy,e);return console.log("Cache migration ".concat(t?"successful":"failed")),t}}else if(t)return console.log("Only versioned cache exists, updating legacy cache"),d(c.TI,t);return!1}catch(e){return console.error("Error during cache migration:",e),!1}}function v(){if(!l())return!1;console.log("Flushing all cache data to storage");try{let e=g(c.oy);if(!e)return console.log("No cache data to flush"),!1;return d(c.TI,e),!0}catch(e){return console.error("Error flushing caches to storage:",e),!1}}function b(){if(!l())return!1;try{let e;console.log("Validating and repairing SWR cache...");let t=g(c.oy);if(!t){console.log("No SWR cache found, checking legacy cache");let e=g(c.TI);if(e)return console.log("Found legacy cache, migrating to versioned format"),d(c.oy,e),!0;return console.log("No cache found, nothing to repair"),!1}try{e=JSON.parse(t)}catch(e){return console.error("SWR cache is corrupted, clearing it:",e),localStorage.removeItem(c.oy),localStorage.removeItem(c.TI),!1}let n=y(e);if(!n.valid)return console.error("SWR cache has invalid structure: ".concat(n.reason,", clearing it")),localStorage.removeItem(c.oy),localStorage.removeItem(c.TI),!1;return console.log("SWR cache is valid"),d(c.TI,t),!0}catch(e){return console.error("Error validating cache:",e),!1}}function w(){try{let e=f();return JSON.stringify(e,null,2)}catch(e){return"Error generating cache debug: ".concat(e)}}},6275:function(e,t,n){n.r(t),n.d(t,{CATEGORIES:function(){return y},CITY_REGIONS:function(){return g},REGION_HIERARCHY:function(){return d},SPECIAL_TAG_TYPES:function(){return r},cache:function(){return c},clearCityCache:function(){return L},fetchCities:function(){return C},fetchCitiesByCategory:function(){return k},fetchCitiesByCountry:function(){return I},fetchCitiesByRegion:function(){return R},fetchCitiesBySearch:function(){return b},fetchCitiesBySearchAdapter:function(){return N},fetchCitiesByTag:function(){return B},fetchCitiesByTagAdapter:function(){return F},fetchCityCostDetails:function(){return w},fetchCityDetails:function(){return A},fetchFeaturedCities:function(){return _},fetchFeaturedCitiesAdapter:function(){return T},fetchTrendingCities:function(){return D},fetchTrendingCitiesAdapter:function(){return E},getCitiesInRegion:function(){return p},initCityCache:function(){return s},isCacheValid:function(){return m},isCityInRegion:function(){return h},isSpecialTagType:function(){return u},mapCityToDestinationData:function(){return f},normalizeTag:function(){return l}});var i=n(41121),a=n(6021),o=n(9212);console.debug("City service core module loaded");let c={allCities:null,citiesByRegion:{},citiesByCountry:{},cityDetails:{},citySearch:{},timestamps:{allCities:0}},r=["region","country"];function s(){return c}function l(e){return(e||"").toLowerCase().trim()}function u(e){return r.includes(l(e))}let g={"Western Europe":["Paris","Lyon","Amsterdam","Brussels","Luxembourg","London","Dublin","Frankfurt","Munich","Vienna","Zurich","Geneva"],"Southern Europe":["Barcelona","Madrid","Rome","Florence","Venice","Lisbon","Porto","Athens","Naples","Malaga","Valencia"],"Eastern Europe":["Prague","Budapest","Warsaw","Krakow","Bucharest","Sofia","Belgrade"],"Northern Europe":["Stockholm","Oslo","Copenhagen","Helsinki","Reykjavik"],France:["Paris","Lyon","Marseille","Bordeaux","Strasbourg","Nice","Lille","Toulouse"]},d=g,y={Trending:["Barcelona","Athens","Lisbon","Prague","Dubrovnik"],Historical:["Rome","Athens","Prague","Vienna","Budapest"],Coastal:["Barcelona","Split","Nice","Dubrovnik","Lisbon"],Cultural:["Paris","Vienna","Florence","Berlin","Amsterdam"]},m=e=>{let t=!1;if("allCities"===e)t=!!(c.allCities&&c.allCities.length>0);else if(e.startsWith("city:")){let n=e.replace("city:","");t=!!c.cityDetails[n]}else if(e.startsWith("region:")){let n=e.replace("region:","");t=!!(c.citiesByRegion[n]&&c.citiesByRegion[n].length>0)}else if(e.startsWith("country:")){let n=e.replace("country:","");t=!!(c.citiesByCountry[n]&&c.citiesByCountry[n].length>0)}else t=!!(c.citySearch[e]&&c.citySearch[e].length>0);if(!t)return console.debug("Cache check for ".concat(e,": MISSING DATA")),!1;let n=o.mJ.MEDIUM,i=c.timestamps[e]||0,a=Date.now();if(0===i||i>a)return console.debug("Cache check for ".concat(e,": EXPIRED (invalid timestamp)")),!1;let r=a-i,s=rt===e.name))}function p(e){return g[e]||[]}function f(e){return console.debug("Mapping city data for ".concat(e.name)),{id:String(e.id),name:e.name,slug:e.slug||e.name.toLowerCase().replace(/\s+/g,"-"),region:e.region||"",country_name:e.country_name||"",description:e.short_description||"",recommendedStay:e.recommended_stay_length||0,image:e.image||e.image_url||"",country_image:"",latitude:void 0!==e.latitude&&null!==e.latitude?parseFloat(String(e.latitude)):void 0,longitude:void 0!==e.longitude&&null!==e.longitude?parseFloat(String(e.longitude)):void 0,population:e.population||0,tags:Array.isArray(e.tags)?e.tags.map(e=>({id:String(e.id),name:e.name,type:e.type||""})):[],featured:Array.isArray(e.tags)&&e.tags.some(e=>"Featured"===e.name||"featured"===e.type)||!1,type:"city"}}let C=async()=>{if(console.debug("\uD83C\uDF06 Fetching all cities"),c.allCities&&m("allCities"))return console.log("Using cached cities data (".concat(c.allCities.length," cities)")),c.allCities;if(console.debug("Cache miss - checking SWR global cache"),(0,a.syncAllCachesWithSWR)(),c.allCities&&m("allCities"))return console.log("Using synced cities data (".concat(c.allCities.length," cities)")),c.allCities;console.log("Cache miss for cities - making API call");try{console.log("Making API request to /trip/cities/");let e=await i.Z.get("/trip/cities/");console.log("API response received: ".concat(e.status));let t=Array.isArray(e.data)?e.data:e.data.results?e.data.results:[];console.log("Received ".concat(t.length," cities from API"));let n=t.map(f);return c.allCities=n,c.timestamps.allCities=Date.now(),console.log("".concat(n.length," cities cached")),(0,a.writeToSWRCache)("/trip/cities/",n),n}catch(t){console.error("Failed to fetch cities:",t),console.log("Falling back to generated data");let e=function(){let e=[];return Object.entries(g).forEach(t=>{let[n,i]=t;i.forEach((t,i)=>{i<3&&e.push({id:"fallback-".concat(t.toLowerCase().replace(/\s+/g,"-")),name:t,slug:t.toLowerCase().replace(/\s+/g,"-"),region:n,country_name:"Unknown",description:"".concat(t," is a city in ").concat(n,"."),recommendedStay:3,rating:4.5,image:"",tags:[{id:n.toLowerCase(),name:n}],featured:y.Trending.includes(t),type:"city"})})}),e}();return console.log("Using ".concat(e.length," fallback cities")),c.allCities||(c.allCities=e,c.timestamps.allCities=Date.now(),console.log("Fallback cities data cached")),e}},S=e=>e.map(e=>({id:parseInt(e.id.toString(),10)||0,name:e.name,slug:e.slug,image_url:e.image||"",short_description:e.description||"",recommended_stay_length:e.recommendedStay||3,tags:(e.tags||[]).map(e=>({id:parseInt(e.id.toString(),10)||0,name:e.name,type:"default"})),latitude:void 0!==e.latitude?parseFloat(e.latitude.toString()):0,longitude:void 0!==e.longitude?parseFloat(e.longitude.toString()):0,image:e.image||"",population:void 0!==e.population?parseInt(e.population.toString(),10):0,country_name:e.country_name||"Unknown",type:"city"})),v=async()=>S(await C()),b=async e=>{if(!e||""===e.trim())return v();let t=e.toLowerCase().trim();console.debug('\uD83D\uDD0D Searching cities with query: "'.concat(t,'"'));let n="search:".concat(t);if(c.citySearch[n]&&m(n))return console.log('Using cached search results for "'.concat(t,'"')),S(c.citySearch[n]);try{let e=await i.Z.get("/trip/cities/?search=".concat(encodeURIComponent(t))),o=Array.isArray(e.data)?e.data:e.data.results?e.data.results:[];console.debug("✅ Found ".concat(o.length," cities matching search query"));let r=o.map(f);return c.citySearch[n]=r,c.timestamps[n]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/search/".concat(t),r),S(r)}catch(i){console.error('Failed to search cities with query "'.concat(t,'":'),i);let e=(await C()).filter(e=>e.name.toLowerCase().includes(t)||e.description&&e.description.toLowerCase().includes(t)||e.region&&e.region.toLowerCase().includes(t));return c.citySearch[n]=e,c.timestamps[n]=Date.now(),S(e)}},w=async e=>{let t="cost:".concat(e);if(c.citySearch[t]&&m(t))return console.log("Using cached cost details for city ID ".concat(e)),c.citySearch[t][0];try{let n=(await i.Z.get("/trip/cities/".concat(e,"/cost/"))).data;return c.citySearch[t]=[n],c.timestamps[t]=Date.now(),n}catch(e){throw console.error("Failed to fetch city cost details:",e),e}},_=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;console.debug("⭐ Fetching featured cities");let n="featured:".concat(e,":").concat(t);if(c.citySearch[n]&&m(n))return console.log("Using cached featured cities data (".concat(c.citySearch[n].length," cities)")),c.citySearch[n];try{let i=await B("tag","Featured",e,t);return c.citySearch[n]=i,c.timestamps[n]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/featured/".concat(e,"/").concat(t),i),i}catch(i){console.error("Failed to fetch featured cities:",i);let e=(await C()).filter(e=>{var t;return null===(t=e.tags)||void 0===t?void 0:t.some(e=>"Featured"===e.name)}).slice(0,t);return c.citySearch[n]=e,c.timestamps[n]=Date.now(),e}},D=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;console.debug("\uD83D\uDD25 Fetching trending cities");let n="trending:".concat(e,":").concat(t);if(c.citySearch[n]&&m(n))return console.log("Using cached trending cities data (".concat(c.citySearch[n].length," cities)")),c.citySearch[n];try{let i=await B("tag","Trending",e,t);return c.citySearch[n]=i,c.timestamps[n]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/trending/".concat(e,"/").concat(t),i),i}catch(i){console.error("Failed to fetch trending cities:",i);let e=(await C()).filter(e=>y.Trending.includes(e.name)).slice(0,t);return c.citySearch[n]=e,c.timestamps[n]=Date.now(),e}},R=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:8;console.debug('\uD83C\uDFD9️ Fetching cities by region: "'.concat(e,'"'));let o="region:".concat(e);if(c.citiesByRegion[e]&&m(o))return console.log("Using cached cities for region ".concat(e," (").concat(c.citiesByRegion[e].length," cities)")),c.citiesByRegion[e];try{let r=await C(),s=g[e]||[],l=r.filter(t=>t.region===e||s.includes(t.name));if(console.log("Found ".concat(l.length," matching cities for ").concat(e)),l.lengtht.region===e||s.includes(t.name)).forEach(e=>{l.some(t=>t.name===e.name)||l.push(e)})}catch(t){console.warn("API request failed for region ".concat(e,", using local data only:"),t)}return l.length0&&s.filter(e=>!l.some(t=>t.name===e)).forEach(t=>{l.push({id:"fallback-".concat(t.toLowerCase().replace(/\s+/g,"-")),name:t,slug:t.toLowerCase().replace(/\s+/g,"-"),region:e,country_name:"Unknown",description:"".concat(t," is a city in ").concat(e,"."),recommendedStay:3,image:"",tags:[{id:e.toLowerCase(),name:e}],featured:!1,type:"city"})}),console.log("Final city count for ".concat(e,": ").concat(l.length)),c.citiesByRegion[e]=l,c.timestamps[o]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/by-region/".concat(e),l),l}catch(n){console.error("❌ Error fetching cities by region:",n);let t=(g[e]||[]).map(t=>({id:"fallback-".concat(t.toLowerCase().replace(/\s+/g,"-")),name:t,slug:t.toLowerCase().replace(/\s+/g,"-"),region:e,country_name:"Unknown",description:"".concat(t," is a city in ").concat(e,"."),recommendedStay:3,image:"",tags:[{id:e.toLowerCase(),name:e}],featured:!1,type:"city"}));return c.citiesByRegion[e]=t,c.timestamps[o]=Date.now(),t}},I=async e=>{console.debug('\uD83C\uDF0D Fetching cities by country: "'.concat(e,'"'));let t="country:".concat(e);if(c.citiesByCountry[e]&&m(t))return console.log("Using cached cities for country ".concat(e," (").concat(c.citiesByCountry[e].length," cities)")),c.citiesByCountry[e];try{let n=await i.Z.get("/trip/countries/".concat(encodeURIComponent(e),"/cities/")),o=Array.isArray(n.data)?n.data:n.data.results?n.data.results:[];console.debug("✅ Fetched ".concat(o.length," cities in country ").concat(e));let r=o.map(t=>({id:Number(t.id),name:t.name,slug:t.slug,image_url:t.image_url,short_description:t.short_description||"",recommended_stay_length:t.recommended_stay_length||0,tags:t.tags||[],latitude:"string"==typeof t.latitude?parseFloat(t.latitude):t.latitude||0,longitude:"string"==typeof t.longitude?parseFloat(t.longitude):t.longitude||0,image:t.image||t.image_url||"",population:"string"==typeof t.population?parseInt(t.population):t.population||0,country_name:t.country_name||e,type:"city"}));return c.citiesByCountry[e]=r,c.timestamps[t]=Date.now(),(0,a.writeToSWRCache)("/trip/countries/".concat(encodeURIComponent(e),"/cities/"),r),r}catch(i){console.error("Failed to fetch cities by country ".concat(e,":"),i),console.debug("\uD83D\uDD04 Fallback: Fetching all cities and filtering by country");let n=(await C()).filter(t=>t.country_name&&t.country_name.toLowerCase()===e.toLowerCase()).map(t=>({id:Number(t.id),name:t.name,slug:t.slug,image_url:t.image,short_description:t.description||"",recommended_stay_length:t.recommendedStay||0,tags:(t.tags||[]).map(e=>({id:parseInt(e.id.toString(),10)||0,name:e.name,type:"default"})),latitude:"string"==typeof t.latitude?parseFloat(t.latitude):t.latitude||0,longitude:"string"==typeof t.longitude?parseFloat(t.longitude):t.longitude||0,image:t.image||"",population:"string"==typeof t.population?parseInt(t.population):t.population||0,country_name:t.country_name||e,type:"city"}));return console.debug("✅ Found ".concat(n.length," cities in country ").concat(e," via fallback")),c.citiesByCountry[e]=n,c.timestamps[t]=Date.now(),n}},B=async function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5;if(!e||!t)return console.debug("\uD83D\uDD0D Missing type or value, fetching all cities"),C();console.debug("\uD83D\uDD0D Fetching cities by tag: ".concat(e,"/").concat(t));let r="tag:".concat(e,":").concat(t,":").concat(n,":").concat(o);if(c.citySearch[r]&&m(r))return console.log("Using cached cities for tag ".concat(e,"/").concat(t," (").concat(c.citySearch[r].length," cities)")),c.citySearch[r];try{let s="";s=u(e)?"/trip/cities/?".concat(e,"=").concat(encodeURIComponent(t),"&page=").concat(n,"&page_size=").concat(o):"/trip/cities/?tag=".concat(encodeURIComponent(t),"&tag_type=").concat(encodeURIComponent(e),"&page=").concat(n,"&page_size=").concat(o),console.debug("\uD83D\uDCE4 API Request: GET ".concat(s));let l=await i.Z.get(s),d=Array.isArray(l.data)?l.data:l.data.results?l.data.results:[];console.debug("✅ Fetched ".concat(d.length," cities for tag ").concat(e,"/").concat(t));let y=d.map(f),m=y.filter(n=>{if("category"===e){var i;return null===(i=n.tags)||void 0===i?void 0:i.some(e=>e.name===t&&("category"===e.type||!e.type))}return"region"!==e||n.region===t||g[t]&&g[t].includes(n.name)}),h=m.length>0?m:y;return c.citySearch[r]=h,c.timestamps[r]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/by-tag/".concat(e,"/").concat(t,"/").concat(n,"/").concat(o),h),h}catch(a){console.error("❌ Error fetching cities by tag ".concat(e,"/").concat(t,":"),a);let n=await C(),i=[];return i="category"===e?n.filter(e=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.some(e=>e.name===t)}):"region"===e?n.filter(e=>e.region===t||g[t]&&g[t].includes(e.name)):n.filter(e=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.some(e=>e.name===t)}),c.citySearch[r]=i,c.timestamps[r]=Date.now(),i}},A=async e=>{let t="city:".concat(e);if(c.cityDetails[e]&&m(t))return console.log("Using cached details for city ".concat(e)),c.cityDetails[e];try{let n=(await i.Z.get("/trip/cities/".concat(encodeURIComponent(e),"/"))).data;return c.cityDetails[e]=n,c.timestamps[t]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/".concat(encodeURIComponent(e),"/"),n),n}catch(a){console.error("Failed to fetch city details for ".concat(e,":"),a);try{let i=(await C()).find(t=>t.slug===e||t.name.toLowerCase()===e.toLowerCase());if(i){var n;let a={id:parseInt(i.id,10)||-1,name:i.name,slug:i.slug,country:{id:-1,name:i.country_name||"Unknown",slug:(i.country_name||"unknown").toLowerCase().replace(/\s+/g,"-"),flag:"",description:"",capital:"",official_languages:[],currency:"",currency_name:"",currency_symbol:"",calling_code:"",timezone:"",climate:"",visa_requirements:"",safety_health:"",travel_seasons:[],neighboring_countries:[],nearby_countries:[],region:i.region||"",official_website:"",latitude:0,longitude:0,major_airports:[],public_transport:"",emergency_contacts:"",food:"",culture:"",tipping_culture:"",country_image:"",tags:[],links:[],travel_advisory_url:"",history:""},region:i.region||"",description:i.description||"",short_description:i.description||"",affordability:null,image_url:i.image,recommended_stay_length:i.recommendedStay||null,nearby_cities:[],tags:(null===(n=i.tags)||void 0===n?void 0:n.map(e=>({id:parseInt(e.id.toString(),10),name:e.name,type:"default"})))||[],latitude:void 0!==i.latitude?parseFloat(i.latitude.toString()):null,longitude:void 0!==i.longitude?parseFloat(i.longitude.toString()):null,population:null!==i.population&&void 0!==i.population?"string"==typeof i.population?parseInt(i.population,10):i.population:null,language:null,currency:null,timezone:null,area:null,elevation:null,founded:null,practical_information:null,best_times_to_visit:null,neighborhoods:null,must_see_attractions:null,off_the_beaten_path:null,day_trips:null,festivals:null,long_description:null,food_description:null,history_description:null,transportation:null,accommodation:null,culture:null,travel_seasons:null,travel_advisory_url:null,image:i.image,official_website:null,links:[],food_image_url:null,history_image_url:null,culture_image_url:null,seasons_image_url:null,food_experiences:[],historical_sites:[]};return c.cityDetails[e]=a,c.timestamps[t]=Date.now(),a}}catch(e){console.error("Fallback search for city details failed:",e)}let i={id:-1,name:e.replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase()),slug:e,country:{id:-1,name:"Unknown",slug:"unknown",flag:"",description:"",capital:"",official_languages:[],currency:"",currency_name:"",currency_symbol:"",calling_code:"",timezone:"",climate:"",visa_requirements:"",safety_health:"",travel_seasons:[],neighboring_countries:[],region:"",official_website:"",latitude:0,longitude:0,major_airports:[],public_transport:"",emergency_contacts:"",food:"",culture:"",tipping_culture:"",country_image:"",tags:[],links:[],travel_advisory_url:"",history:"",nearby_countries:[]},region:"",description:"Details for this city are not available at the moment.",short_description:"No details available.",affordability:null,image_url:null,recommended_stay_length:null,nearby_cities:[],tags:[],latitude:null,longitude:null,population:null,language:null,currency:null,timezone:null,area:null,elevation:null,founded:null,practical_information:null,best_times_to_visit:null,neighborhoods:null,must_see_attractions:null,off_the_beaten_path:null,day_trips:null,festivals:null,long_description:null,food_description:null,history_description:null,transportation:null,accommodation:null,culture:null,travel_seasons:null,travel_advisory_url:null,image:null,official_website:null,links:[],food_image_url:null,history_image_url:null,culture_image_url:null,seasons_image_url:null,food_experiences:[],historical_sites:[]};return c.cityDetails[e]=i,c.timestamps[t]=Date.now(),i}},k=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5;console.debug('\uD83D\uDD0D Fetching cities by category: "'.concat(e,'"'));let i="category:".concat(e,":").concat(t,":").concat(n);if(c.citySearch[i]&&m(i))return console.log("Using cached cities for category ".concat(e," (").concat(c.citySearch[i].length," cities)")),c.citySearch[i];if("All Cities"===e){let e=await C();return c.citySearch[i]=e,c.timestamps[i]=Date.now(),e}if(["Western Europe","Eastern Europe","Balkans"].includes(e)){let a=await R(e,t,n);return c.citySearch[i]=a,c.timestamps[i]=Date.now(),a}if(y[e]){let o=await C(),r=y[e]||[],s=o.filter(e=>r.includes(e.name));if(s.length>0)return c.citySearch[i]=s,c.timestamps[i]=Date.now(),(0,a.writeToSWRCache)("/trip/cities/by-category/".concat(e,"/").concat(t,"/").concat(n),s),s}try{let a=await B("category",e,t,n);return c.citySearch[i]=a,c.timestamps[i]=Date.now(),a}catch(n){console.error("Failed to fetch cities by category ".concat(e,":"),n);let t=(await C()).filter(t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some(t=>t.name.toLowerCase()===e.toLowerCase())});return c.citySearch[i]=t,c.timestamps[i]=Date.now(),t}},T=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;return _(e,t)},F=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return B(e,t,n)},E=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;return D(e,t)},N=e=>b(e).then(e=>e.map(e=>({...e,id:e.id.toString(),type:"city",tags:e.tags.map(e=>({id:e.id.toString(),name:e.name}))}))),L=(e,t)=>{if(console.log("Clearing city cache".concat(e?" for ".concat(e):"").concat(t?" with key ".concat(t):"")),!e){c.allCities=null,c.citiesByRegion={},c.citiesByCountry={},c.cityDetails={},c.citySearch={},c.timestamps={allCities:0};return}switch(e){case"allCities":c.allCities=null,c.timestamps.allCities=0;break;case"cityDetails":t?(delete c.cityDetails[t],delete c.timestamps["city:".concat(t)]):c.cityDetails={};break;case"citiesByRegion":t?(delete c.citiesByRegion[t],delete c.timestamps["region:".concat(t)]):c.citiesByRegion={};break;case"citiesByCountry":t?(delete c.citiesByCountry[t],delete c.timestamps["country:".concat(t)]):c.citiesByCountry={};break;case"citySearch":t?(delete c.citySearch[t],delete c.timestamps[t]):c.citySearch={};break;default:console.warn("Unknown cache type: ".concat(e))}};t.default={fetchCities:C,fetchCitiesBySearch:b,fetchCitiesBySearchAdapter:N,fetchFeaturedCities:_,fetchFeaturedCitiesAdapter:T,fetchTrendingCities:D,fetchTrendingCitiesAdapter:E,fetchCitiesByRegion:R,fetchCitiesByCountry:I,fetchCitiesByCategory:k,fetchCitiesByTag:B,fetchCitiesByTagAdapter:F,fetchCityDetails:A,fetchCityCostDetails:w,mapCityToDestinationData:f,isCityInRegion:h,getCitiesInRegion:p,normalizeTag:l,isSpecialTagType:u,clearCityCache:L,CITY_REGIONS:g,REGION_HIERARCHY:d,CATEGORIES:y,SPECIAL_TAG_TYPES:r,cache:c}},96965:function(e,t,n){n.d(t,{D6:function(){return m},Mp:function(){return o},aL:function(){return y},ax:function(){return d},cache:function(){return c}});var i=n(9212);let a=()=>"undefined"!=typeof localStorage;function o(){return a()&&u(),c}let c={allCountries:null,featuredCountries:null,trendingCountries:null,minimalCountries:null,countryDetails:{},countrySearch:{},countriesByTag:{},countriesByRegion:{},countriesByContinent:{},cacheTimeout:i.mJ.MEDIUM,timestamps:{allCountries:0,featuredCountries:0,trendingCountries:0,minimalCountries:0,countryDetails:{},countrySearch:{},countriesByTag:{},countriesByRegion:{},countriesByContinent:{}}},r=e=>["allCountries","featuredCountries","trendingCountries","minimalCountries"].includes(e),s=e=>["countryDetails","countrySearch","countriesByTag","countriesByRegion","countriesByContinent"].includes(e),l=e=>{try{if(!a())return console.debug("Server-side getItem for ".concat(e,", using memory cache")),null;return localStorage.getItem(e)}catch(t){return console.warn("Failed to access storage for key ".concat(e,":"),t),null}};function u(){console.debug("Initializing country cache timestamps");try{if(c.timestamps.allCountries=c.allCountries?Date.now():0,c.timestamps.featuredCountries=c.featuredCountries?Date.now():0,c.timestamps.trendingCountries=c.trendingCountries?Date.now():0,c.timestamps.minimalCountries=c.minimalCountries?Date.now():0,!a()){console.debug("Server environment detected, skipping initial cache sync");return}let e=function(){if(console.debug("Syncing country cache with SWR cache"),!a())return console.debug("Server environment detected, skipping SWR cache sync"),{synced:!1};try{let e=l("swr-cache");if(!e)return console.debug("No SWR cache data found in storage"),{synced:!1};let t=JSON.parse(e).find(e=>e[0]&&e[0].includes("/trip/countries/"));if(t&&t[1]&&t[1].data)return console.debug("Found country data in SWR cache with ".concat(t[1].data.length," countries")),c.allCountries=t[1].data,c.timestamps.allCountries=Date.now(),c.minimalCountries=t[1].data,c.timestamps.minimalCountries=Date.now(),{synced:!0,items:t[1].data.length};return{synced:!1}}catch(e){return console.error("Error syncing with SWR cache:",e),{synced:!1}}}();console.debug("Cache sync result: ".concat(e.synced?"successful":"failed"))}catch(e){console.error("Error initializing country cache:",e)}}let g=(e,t)=>{let n=Date.now(),i=!1;if(t&&s(e)?i=!!c[e][t]:r(e)&&(i=!!c[e]),!i)return console.debug("Cache miss for ".concat(e).concat(t?":"+t:"",": NO DATA")),!1;if(t){if(!s(e))return console.error("Type error: Attempted to use nested key with non-nested structure: ".concat(e)),!1;{let i=c.timestamps[e][t]||0;if(0===i||i>n)return console.debug("Cache miss for ".concat(e,":").concat(t,": INVALID TIMESTAMP")),!1;let a=n-i,o=an)return console.debug("Cache miss for ".concat(e,": INVALID TIMESTAMP")),!1;let i=n-t,a=i5?console.log("Cached ".concat(e,":").concat(n," with ").concat(t.length," items")):console.debug("Cached ".concat(e,":").concat(n," with ").concat(Array.isArray(t)?t.length+" items":"data"))):console.error("Type error: Attempted to use nested key with non-nested structure: ".concat(e)):r(e)?(c[e]=t,c.timestamps[e]=i,Array.isArray(t)&&t.length>5?console.log("Cached ".concat(e," with ").concat(t.length," items")):console.debug("Cached ".concat(e," with ").concat(Array.isArray(t)?t.length+" items":"data"))):console.error("Type error: Missing nested key for nested structure: ".concat(e))}let y=(e,t)=>{if(g(e,t)){if(console.debug("Using cached data for ".concat(t?e+":"+t:e)),t&&s(e))return c[e][t];if(r(e))return c[e]}return null},m=(e,t)=>{if(console.log("Resetting country cache".concat(e?" for ".concat(e):"").concat(t?" with key ".concat(t):"")),!e){c.allCountries=null,c.featuredCountries=null,c.trendingCountries=null,c.minimalCountries=null,c.countryDetails={},c.countrySearch={},c.countriesByTag={},c.countriesByRegion={},c.countriesByContinent={},c.timestamps={allCountries:0,featuredCountries:0,trendingCountries:0,minimalCountries:0,countryDetails:{},countrySearch:{},countriesByTag:{},countriesByRegion:{},countriesByContinent:{}};return}switch(e){case"countryDetails":t?(c.countryDetails&&delete c.countryDetails[t],c.timestamps.countryDetails&&delete c.timestamps.countryDetails[t],console.debug("Reset cache for country details: ".concat(t))):(c.countryDetails={},c.timestamps.countryDetails={},console.debug("Reset all country details cache"));break;case"allCountries":c.allCountries=null,c.timestamps.allCountries=0,console.debug("Reset all countries cache");break;case"featuredCountries":c.featuredCountries=null,c.timestamps.featuredCountries=0,console.debug("Reset featured countries cache");break;case"trendingCountries":c.trendingCountries=null,c.timestamps.trendingCountries=0,console.debug("Reset trending countries cache");break;case"minimalCountries":c.minimalCountries=null,c.timestamps.minimalCountries=0,console.debug("Reset minimal countries cache");break;case"countrySearch":t?(delete c.countrySearch[t],c.timestamps.countrySearch&&delete c.timestamps.countrySearch[t],console.debug("Reset cache for country search: ".concat(t))):(c.countrySearch={},c.timestamps.countrySearch={},console.debug("Reset all country search cache"));break;case"countriesByRegion":t?(delete c.countriesByRegion[t],c.timestamps.countriesByRegion&&delete c.timestamps.countriesByRegion[t],console.debug("Reset cache for countries by region: ".concat(t))):(c.countriesByRegion={},c.timestamps.countriesByRegion={},console.debug("Reset all countries by region cache"));break;case"countriesByContinent":t?(delete c.countriesByContinent[t],c.timestamps.countriesByContinent&&delete c.timestamps.countriesByContinent[t],console.debug("Reset cache for countries by continent: ".concat(t))):(c.countriesByContinent={},c.timestamps.countriesByContinent={},console.debug("Reset all countries by continent cache"));break;default:console.warn("Unknown cache type: ".concat(e))}};a()&&u()},9212:function(e,t,n){n.d(t,{TI:function(){return o},mJ:function(){return i},oy:function(){return a}});let i={SHORT:3e5,MEDIUM:18e5,LONG:36e5,EXTENDED:864e5},a="swr-cache-v1.0.0",o="swr-cache"},41121:function(e,t,n){var i=n(83464),a=n(40257);let o=()=>{var e;return(null===(e=document.cookie.match(/csrftoken=([\w-]+)/))||void 0===e?void 0:e[1])||""},c=i.default.create({baseURL:a.env.NEXT_PUBLIC_API_URL||"https://backend.nomadstravelguides.com/api",withCredentials:!0,headers:{"Content-Type":"application/json",Accept:"application/json"},timeout:15e3});c.interceptors.request.use(e=>("get"!==e.method&&(e.headers["X-CSRFToken"]=o()),e)),c.interceptors.response.use(e=>e,e=>{var t,n,i;return console.error("API Error:",null===(t=e.response)||void 0===t?void 0:t.status,null===(n=e.response)||void 0===n?void 0:n.data),null===(i=e.response)||void 0===i||i.status,Promise.reject(e)}),t.Z=c}}]);