{"ast":null,"code":"function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\nimport { client, previewClient } from './sanity';\nimport imageUrlBuilder from '@sanity/image-url';\nimport globalData from 'global/globalData'; // - - - - - - - - - - - - - - - - - - - - - helpers\n\nconst excludeDraft = (preview = false) => !preview ? \"&& !(_id in path('drafts.**'))\" : '';\n\nexport const imageBuilder = imageUrlBuilder(client); // - - - - - - - - - - - - - - - - - - - - - locale\n\nconst {\n  languages,\n  defaultLang\n} = globalData; // export async function getLocalisations() {\n// \tconst localisations = await sanity.client.fetch(`*[_id == 'global-localisations']{\n// \t\t'strings': strings[]{\n// \t\t\ttitle, key, ${languages.join(', ')}\n// \t\t}\n// \t}`)\n// \treturn localisations[0].strings\n// }\n// export const getLocalisation = (key, lang) => {\n// \treturn globalData.localisations[key] && globalData.localisations[key][lang]\n// }\n\nexport const localize = (value, lang = currentLang) => {\n  const languages = [lang];\n\n  if (Array.isArray(value)) {\n    return value.map(v => localize(v, languages));\n  } else if (value && typeof value === 'object') {\n    if (value._type != 'localeImageAlt' && value._type != 'localeSlug' && /^locale[A-Z]/.test(value._type)) {\n      const language = languages.find(lang => value[lang]);\n      return value[language] || null;\n    }\n\n    return Object.keys(value).reduce((result, key) => {\n      result[key] = localize(value[key], languages);\n      return result;\n    }, {});\n  }\n\n  return value;\n};\n\nconst enhanceHouses = (value, lang) => {\n  if (Array.isArray(value)) {\n    return value.map(v => enhanceHouses(v, lang));\n  } else {\n    const {\n      services,\n      servicesGlobal\n    } = value,\n          rest = _objectWithoutProperties(value, [\"services\", \"servicesGlobal\"]);\n\n    const accommodations = value.accommodations || [];\n    const accommodationsCount = value.status == 'future-closed' && value.canApplyAccommodations ? parseInt(value.canApplyAccommodations) : accommodations.length;\n    const availableCount = accommodations.reduce((acc, curr) => acc + (curr.available ? 1 : 0), 0);\n    const cheapest = accommodations.reduce((acc, curr) => {\n      if (!curr.available) return acc;\n      const price = parseInt(curr.price.replace('€', '')); //.replace('$', '').replace(' ', ''))\n\n      return price < acc ? price : acc;\n    }, 9999);\n    const open = value.status == 'open';\n    const fullHouse = accommodations.length > 0 && availableCount == 0;\n    const canApply = value.status != 'future-closed' && !fullHouse;\n    const status = value.status == 'future-closed' ? 'future-closed' : value.status + '-' + (fullHouse ? 'full' : 'available');\n    const statusTextKey = status == 'open-available' || status == 'future-open-available' ? 'available' : status == 'open-full' || status == 'future-open-full' ? 'full' : 'unavailable'; //status == 'future-closed' ? 'unavailable' \n\n    const statusColor = statusTextKey == 'available' ? 'green' : statusTextKey == 'full' ? 'blue-grey' : 'black';\n    return _objectSpread(_objectSpread({}, rest), {}, {\n      open,\n      canApply,\n      status,\n      statusTextKey,\n      statusColor,\n      accommodationsCount,\n      availableCount,\n      cheapest,\n      fullHouse,\n      services: services ? services.concat(servicesGlobal) : [],\n      url: value.city ? `/${lang}/${value.city.slug}/${value.slug}` : undefined\n    });\n  }\n};\n\nconst enhanceCities = (value, lang) => {\n  if (Array.isArray(value)) {\n    return value.map(v => enhanceCities(v, lang));\n  } else {\n    const houses = value.houses.map(house => _objectSpread(_objectSpread({}, enhanceHouses(house, lang)), {}, {\n      url: `/${lang}/${value.slug}/${house.slug}`\n    }));\n    const availableCount = houses.reduce((acc, curr) => acc + (curr.availableCount ? 1 : 0), 0);\n    return _objectSpread(_objectSpread({}, value), {}, {\n      url: `/${lang}/${value.slug}`,\n      houses,\n      housesCount: houses.length,\n      availableCount\n    });\n  }\n}; // - - - - - - - - - - - - - - - - - - - - - home page\n\n\nexport async function getDoc(type, id, lang, preview, fields = '') {\n  const results = await getClient(preview).fetch(`*[_type == '${type}' && _id == '${id}' ${excludeDraft(preview)}]${fields}`);\n  return localize(results[0], lang);\n}\nconst homeFields = `{\n\t...,\n\t'videos': videos[].asset->url,\n}`;\nexport async function getHomePage(lang, preview) {\n  return getDoc('home', 'home', lang, preview, homeFields);\n}\nexport async function getCityPage(lang, preview) {\n  return getDoc('cityPage', 'cityPage', lang, preview);\n}\nexport async function getHousePage(lang, preview) {\n  return getDoc('housePage', 'housePage', lang, preview);\n}\nexport async function getNewsPage(lang, preview) {\n  return getDoc('newsPage', 'newsPage', lang, preview);\n} // - - - - - - - - - - - - - - - - - - - - - pages\n\nconst pageFields = (lang = defaultLang) => `\n\t'slug': slug.${lang}.current,\n\t'allSlugs': slug,\n\t'title': title.${lang},\n\thero,\n`;\n\nexport async function getPageById(id, lang, preview) {\n  const results = await getClient(preview).fetch(`*[_id == '${id}' ${excludeDraft(preview)}]` + `{${pageFields(lang)}}`);\n  return results[0];\n}\nexport async function getPageSlugTranslation(slug, fromLang, toLang, preview) {\n  const results = await getClient(preview).fetch(`*[_type == 'page' && slug.${fromLang}.current == '${slug}' ${excludeDraft(preview)}]` + `{'slug': slug.${toLang}.current}`);\n  return results[0];\n}\nexport async function getPageBySlug(slug, lang, preview) {\n  const results = await getClient(preview).fetch(`*[_type == 'page' && slug.${lang}.current == '${slug}' ${excludeDraft(preview)}]` + `{${pageFields(lang)}}`);\n  return results[0];\n}\nexport async function getPages() {\n  const results = await getClient().fetch(`*[_type == 'page' ${excludeDraft()}]` //+ ` | order(date desc, _updatedAt desc)`\n  + `{${languages.map(lang => `'${lang}': slug.${lang}.current`).join(',')}}`);\n  return results.flatMap(result => Object.keys(result).map(key => ({\n    lang: key,\n    slug: result[key]\n  })));\n} // - - - - - - - - - - - - - - - - - - - - - cities\n\nconst cityFields = (lang = defaultLang) => `\n  _id,\n\t'slug': slug.${lang}.current,\n\t'allSlugs': slug,\n\ttitle,\n\tdepartment,\n\tareas,\n\tareasShort,\n\topen,\n\topeningDate,\n\tgeolocation,\n\thero,\n\t'videos': videos[].asset->url,\n  'houses': *[_type == 'house' && references(^._id) ${excludeDraft()}]\n\t{\n\t\ttitle,\n\t  'slug': slug.${lang}.current,\n\t  status,\n\t  openingDate,\n\t  canApplyAccommodations,\n\t  geolocation,\n\t  hero,\n\t  area,\n\t  surface,\n\t  'accommodationsCount': count(*[_type == 'accommodation' && references(^._id) ${excludeDraft()}]),\n\t  'availableCount': count(*[_type == 'accommodation' && references(^._id) ${excludeDraft()}][available]),\n\t  'accommodations': *[_type == 'accommodation' && references(^._id) ${excludeDraft()}]\n\t\t{\n\t\t\t_id,\n\t\t\ttitle,\n\t\t\tavailable,\n\t\t\tsurface,\n\t\t\tprice,\n\t\t\t'key': key.current,\n\t\t},\n\t},\n`;\n\nconst cityFieldsLight = (lang = defaultLang) => `\n\t_id,\n\t'slug': slug.${lang}.current,\n\ttitle,\n\thero,\n\tgeolocation,\n`;\n\nexport async function getCitiesSlugs() {\n  const results = await getClient().fetch(`*[_type == 'city' && open ${excludeDraft()}]` + `{${languages.map(lang => `'${lang}': slug.${lang}.current`).join(',')}}`);\n  return results.flatMap(city => Object.keys(city).map(lang => ({\n    lang,\n    city: city[lang]\n  })));\n}\nexport async function getCities(lang, preview) {\n  const results = await getClient(preview).fetch(`*[_type == 'city' ${excludeDraft(preview)}]` + `{${cityFields(lang)}}` + ` | order(_createdAt asc)`);\n  return enhanceCities(localize(results, lang), lang);\n}\nexport async function getCityBySlug(slug, lang, preview) {\n  const results = await getClient(preview).fetch(`*[_type == 'city' && slug.${lang}.current == '${slug}' ${excludeDraft(preview)}]` + `{${cityFields(lang)}}`);\n  return enhanceCities(localize(results[0], lang), lang);\n} // - - - - - - - - - - - - - - - - - - - - - houses\n\nconst houseFields = (lang = defaultLang) => `\n\t...,\n\t'slug': slug.${lang}.current,\n\t'allSlugs': slug,\n\t'city': {\n\t  'title': city->title,\n\t  'slug': city->slug.${lang}.current,\n\t},\n\t'accommodations': *[_type == 'accommodation' && references(^._id) ${excludeDraft()}]\n\t {\n\t\t_id,\n\t\ttitle,\n\t\tavailable,\n\t\tsurface,\n\t\tprice,\n\t\t'key': key.current,\n\t },\n\t\"services\": services[_type == 'service']{\n\t\t'id': _key,\n\t\ttitle,\n\t\ttype,\n\t\tdescription,\n\t\ticon,\n\t},\n\t\"servicesGlobal\": services[_type == 'reference']->{\n\t\t'id': _id,\n\t\ttitle,\n\t\ttype,\n\t\tdescription,\n\t\ticon,\n\t},\n`;\n/*\n`\nservices[]->{\n\ttitle,\n\ttype,\n\ticon,\n\tdescription,\n},\n`\n*/\n\n\nexport async function getHousesSlugs(lang, withTitles = false) {\n  const housesSlugFields = l => `'${l}': slug.${l}.current` + `,'city': city->slug.${l}.current`;\n\n  const results = await getClient().fetch(`*[_type == 'house' ${excludeDraft()}]` + `{\n\t\t\t\t${lang ? housesSlugFields(lang) : languages.map(housesSlugFields).join(',')},\n\t\t\t}`);\n  return results.flatMap(house => {\n    const {\n      city\n    } = house,\n          rest = _objectWithoutProperties(house, [\"city\"]);\n\n    return Object.keys(rest).map(lang => ({\n      lang,\n      city,\n      house: rest[lang]\n    }));\n  });\n}\nexport async function getHousesMenu(lang) {\n  const results = await getClient().fetch(`*[_type == 'city' ${excludeDraft()}]` + `{\n\t\t\t\t'slug': slug.${lang}.current,\n\t\t\t\ttitle,\n\t\t\t\t'houses': *[_type == 'house' && references(^._id) ${excludeDraft()}]{\n\t\t\t\t\ttitle,\n\t\t\t\t\t'slug': slug.${lang}.current,\n\t\t\t\t},\n\t\t\t}`);\n  return localize(results, lang).map(value => {\n    const houses = value.houses.map(house => _objectSpread(_objectSpread({}, house), {}, {\n      url: `/${lang}/${value.slug}/${house.slug}`\n    }));\n    return _objectSpread(_objectSpread({}, value), {}, {\n      houses\n    });\n  }); //({...house, url: `/${lang}/${house.city.slug}/${house.slug}`}))\n}\nexport async function getHouseBySlug(slug, lang, preview) {\n  const results = await getClient(preview).fetch(`*[_type == 'house' && slug.${lang}.current == '${slug}' ${excludeDraft(preview)}]` + `{${houseFields(lang)}}`);\n  return enhanceHouses(localize(results[0], lang), lang);\n} // - - - - - - - - - - - - - - - - - - - - - document\n\nexport async function getDocumentById(id, preview) {\n  // TODO - localize\n  const results = await getClient(preview).fetch(`*[_id == '${id}' && defined(slug.${defaultLang}) ${excludeDraft(preview)}]{\n\t\t\t_type,\n\t\t\t'slug': coalesce(slug.en.current, slug.${defaultLang}.current)\n\t\t}`);\n  return results[0];\n} // - - - - - - - - - - - - - - - - - - - - - OLD\n\nconst getUniquePosts = posts => {\n  const slugs = new Set();\n  return posts.filter(post => {\n    if (slugs.has(post.slug)) {\n      return false;\n    } else {\n      slugs.add(post.slug);\n      return true;\n    }\n  });\n};\n\nconst postFields = `\n  name,\n  title,\n  date,\n  excerpt,\n  'slug': slug.current,\n  'coverImage': coverImage.asset->url,\n  'author': author->{name, 'picture': picture.asset->url},\n`;\n\nconst getClient = preview => preview ? previewClient : client;\n\nexport async function getPreviewPostBySlug(slug) {\n  const data = await getClient(true).fetch(`*[_type == \"post\" && slug.current == $slug] | order(date desc){\n\t  ${postFields}\n\t  content\n\t}`, {\n    slug\n  });\n  return data[0];\n}\nexport async function getAllPostsWithSlug() {\n  const data = await client.fetch(`*[_type == \"post\"]{ 'slug': slug.current }`);\n  return data;\n}\nexport async function getAllPostsForHome(preview) {\n  const results = await getClient(preview).fetch(`*[_type == \"post\"] | order(date desc, _updatedAt desc){\n\t  ${postFields}\n\t}`);\n  return getUniquePosts(results);\n}\nexport async function getPostAndMorePosts(slug, preview) {\n  const curClient = getClient(preview);\n  const [post, morePosts] = await Promise.all([curClient.fetch(`*[_type == \"post\" && slug.current == $slug] | order(_updatedAt desc) {\n\t\t${postFields}\n\t\tcontent,\n\t  }`, {\n    slug\n  }).then(res => res === null || res === void 0 ? void 0 : res[0]), curClient.fetch(`*[_type == \"post\" && slug.current != $slug] | order(date desc, _updatedAt desc){\n\t\t${postFields}\n\t\tcontent,\n\t  }[0...2]`, {\n    slug\n  })]);\n  return {\n    post,\n    morePosts: getUniquePosts(morePosts)\n  };\n} // TEMP\n// export async function getAll() {\n// \tconst all = await getClient().fetch(`*[]`)\n// \tconsole.log('api.js::291 all', all)\n// \treturn all\n// }","map":null,"metadata":{},"sourceType":"module"}