// source --> https://caritasdev.cd/nzungu/modules/a84a680674/assets/js/client-locale-loader.js?ver=1.16.17 
function fb3dClientLocaleLoader() {
  if(window.jQuery && typeof jQuery.ajax==='function') {
    function fb3dNormalizeUrl(url) {
      return url.replace(/https{0,1}:/, location.protocol);
    }
    function fb3dFetch(url) {
      return new Promise(function(resolve, reject) {
        jQuery.ajax({url: fb3dNormalizeUrl(url), dataType: 'text'}).done(resolve).fail(reject);
      });
    }
    FB3D_CLIENT_LOCALE.render = function() {
      delete FB3D_CLIENT_LOCALE.render;
      var isStable = !Promise.withResolvers || /^((?!chrome|android).)*safari/i.test(navigator.userAgent),
        pdfJs = FB3D_CLIENT_LOCALE.pdfJS, assetsJs = FB3D_CLIENT_LOCALE.pluginurl+'assets/js/';
      window.FB3D_LOCALE = {
        dictionary: FB3D_CLIENT_LOCALE.dictionary
      };
      window.PDFJS_LOCALE = {
        pdfJsCMapUrl: fb3dNormalizeUrl(pdfJs.pdfJsCMapUrl),
        pdfJsWorker: fb3dNormalizeUrl(isStable? pdfJs.stablePdfJsWorker: pdfJs.pdfJsWorker)
      };
      Promise.all([
        fb3dFetch(FB3D_CLIENT_LOCALE.pluginurl+'assets/css/client.css?ver='+FB3D_CLIENT_LOCALE.version),
        fb3dFetch(FB3D_CLIENT_LOCALE.cacheurl+'skins.js?ver='+FB3D_CLIENT_LOCALE.version),
        fb3dFetch(isStable? pdfJs.stablePdfJsLib: pdfJs.pdfJsLib),
        fb3dFetch(assetsJs+'three.min.js?ver=125'),
        fb3dFetch(assetsJs+'html2canvas.min.js?ver=0.5'),
        fb3dFetch(assetsJs+'client.min.js?ver='+FB3D_CLIENT_LOCALE.version),
      ]).then(function(fs) {
        jQuery('head').append(['<style type="text/css">', fs[0].replace(/url\('..\//gi, 'url(\''+fb3dNormalizeUrl(FB3D_CLIENT_LOCALE.pluginurl+'assets/')), '</style>'].join(''));
        for(var i = 1; i<fs.length; ++i) {
          eval(fs[i]);
        }
      });
    };
    if(jQuery('._'+FB3D_CLIENT_LOCALE.key).length) {
      FB3D_CLIENT_LOCALE.render();
    }
  }
  else {
    setTimeout(fb3dClientLocaleLoader, 100);
  }
}
fb3dClientLocaleLoader();
// source --> https://caritasdev.cd/nzungu/modules/69eb2429ac/public/js/meteo-public.js?ver=1.0.0 
(function ($) {
	'use strict';

	/* -----------------------------------------------------------
     *  STRINGS
     * ----------------------------------------------------------- */
	const TEXT = {
		title: {
			english: 'Weather in ',
			french: 'Météo à '
		},
		sunrise: {
			english: 'Sunrise: ',
			french: 'Lever du soleil : '
		},
		sunset: {
			english: 'Sunset: ',
			french: 'Coucher du soleil : '
		},
		humidity: {
			english: 'Humidity: ',
			french: 'Humidité : '
		},
		wind: {
			english: 'Wind Speed: ',
			french: 'Vent : '
		},
		rain: {
			spanish: 'Lluvia: ',
			french: 'Risque de pluie : '
		}
	};


	/* -----------------------------------------------------------
     *  HELPERS
     * ----------------------------------------------------------- */
	function ucfirst(str) { return str.charAt(0).toUpperCase() + str.slice(1); }

	function t(key, lang) {
		return TEXT[key][lang] || '';
	}

	/* -----------------------------------------------------------
     *  INITIALISE ONE WIDGET
     * ----------------------------------------------------------- */
	function initWidget($w) {
		const city      = $w.attr('data-city');
		const country   = $w.attr('data-country');
		const language  = $w.attr('data-language') || 'french';
		const days      = parseInt($w.attr('data-days'), 10) || 0;
		const widthPref = $w.attr('data-width') === 'tight' ? 'tight' : 'maxwidth';
		const showCur   = $w.attr('data-current') === 'on';
		const showWind  = $w.attr('data-wind')    === 'on';
		const showSun   = $w.attr('data-sunrise') === 'on';
		const bg        = $w.attr('data-background') || 'linear-gradient(to left,#d3dfff,#fbfcff)';
		const fg        = $w.attr('data-text-color') || 'black';
		const place     = city.replace(' ', '_') + ',' + country;

		// --- create a hash of current config ---
		const hash = JSON.stringify({ city, country, language, days, widthPref, showCur, showWind, showSun, bg, fg });

		// --- skip if already rendered with same hash ---
		if ($w.attr('data-render-hash') === hash) return;

		// --- mark this widget as rendered with hash ---
		$w.attr('data-render-hash', hash);

		$w.removeClass('tight maxwidth').addClass(widthPref);

		$.getJSON(
			'https://www.weatherwp.com/api/common/publicWeatherForLocation.php',
			{ city, country, place, domain: location.href, language, widget: 'French' }
		).done(resp => draw(resp));

		function draw(r) {
			const wrap = $('<div>', {
				class : `main_wrap`,
				css   : { background: bg, color: fg }
			});

			$('<div>', {
				class : 'weather_title',
				html  : t('title', language) + ucfirst(city)
			}).appendTo(wrap);

			if (showCur) {
				const centre = $('<div>', { class: 'weather_center_wrap' }).appendTo(wrap);

				$('<div>', { class: 'weather_image_wrap' })
					.append($('<img>', { class: 'weather_image', src: r.icon }))
					.appendTo(centre);

				$('<div>', { class: 'weather_temp_wrap' })
					.append($('<span>', { class: 'weather_temp', html: r.temp + '&#176;' }))
					.append($('<span>', { class: 'weather_temp_type', text: 'C' }))
					.appendTo(centre);

				$('<div>', { class: 'weather_description', text: r.description })
					.appendTo(wrap);
			}

			if (showSun) {
				$('<div>', {
					class : 'weather_sunrise',
					text  : t('sunrise', language) + r.sunrise
				}).appendTo(wrap);

				$('<div>', {
					class : 'weather_sunset',
					text  : t('sunset', language) + r.sunset
				}).appendTo(wrap);
			}

			if (showWind) {
				const data = $('<div>', { class: 'weather_data_wrap' }).appendTo(wrap);

				$('<div>', {
					class : 'weather_humidity',
					text  : t('humidity', language) + r.humidity + '%'
				}).appendTo(data);

				$('<div>', {
					class : 'weather_wind',
					text  : t('wind', language) + r.windspeedKmph + 'Kmph'
				}).appendTo(data);

				$('<div>', {
					class : 'weather_rain',
					text  : t('rain', language) + r.chanceofrain + '%'
				}).appendTo(data);
			}

			if (days > 0) {
				const daysWrap = $('<div>', { class: 'weather_days_wrap' }).appendTo(wrap);
				for (let i = 0; i < days; i++) {
					const d  = r.days[i];
					const col = $('<div>', { class: 'weather_day_wrap' }).appendTo(daysWrap);

					$('<div>', { class: 'weather_day_name', text: d.dayName }).appendTo(col);
					$('<div>', { class: 'weather_day_image_wrap' })
						.append($('<img>', { class: 'weather_day_image', src: d.icon }))
						.appendTo(col);
					$('<div>', {
						class : 'weather_day_temp',
						html  : `${d.max}&#176;<span class="temp-separator">/</span>${d.min}&#176;`
					}).appendTo(col);
				}
			}

			const link = $('<a>', { href: r.deepLink, target: '_blank' });
			if (r.deepLinkAlt) link.attr({ title: r.deepLinkAlt, 'aria-label': r.deepLinkAlt });
			link.append(wrap);

			$w.find('.weather_widget_placeholder')
				.empty()
				.append(link);
		}
	}

	/* -----------------------------------------------------------
     *  INITIALISE ALL NOT‑YET‑DRAWN WIDGETS
     * ----------------------------------------------------------- */
	function refresh() {
		$('.meteo-widget').each(function () { initWidget($(this)); });
		$('.preview-weather-widget.meteo-widget').each(function () {
			initWidget($(this));
		});
		document.querySelectorAll('iframe').forEach(frame => {
			try {
				const doc = frame.contentDocument || frame.contentWindow.document;
				if (!doc) return;

				$(doc).find('.preview-weather-widget.meteo-widget').each(function () {
					initWidget($(this));
				});
			} catch (e) {
				// Cross-origin or inaccessible iframe — safely skip
				// console.warn('Skipping iframe due to CORS or sandbox:', e);
			}
		});
	}
	window.refreshMeteoWidgets = refresh;

	$(refresh);

	window.addEventListener('weather-widget-refresh', refresh);

})(jQuery);