/* @license GPL-2.0-or-later https://www.drupal.org/licensing/faq */
(function ($,Drupal){// #########################################################
  // # README FIRST:these are the instructions for adding a #
  // # Domain expiry - moved to subdomain notification popup #
  // # using this file as a JS Injection on the site.        #
  // # Please read the instructions and follow steps #1-5    #
  // #########################################################

  // STEP #1:// Edit your user (<your_name>@kalaam.org) on the website admin Users page,// and give yourself the role DPM Addon:JS Injector
  // Then go to Setup > JS Injector,click on + Add JS Injector
  
  // Paste in Label:Subdomain Notification
  //
  // Copy ALL (CTRL-A) the text in this file and paste into the Code textbox.
  
  // NB:DO NOT EDIT THIS FILE! Edit the pasted text in the Code box!
  
  // STEP #2:// Now working inside the Code textbox,do the following:// Paste the subdomain in between the "" in the line below:const newUrl = "spotlight-alman.ethnosites.com";// STEP #3:// Change the date to match the expiry of the domain:// (year-month-day)
  const dateOfExpiry = new Date("2026-04-05");// STEP #4:// Which language should be displayed?:// Possible values = en,fr,es,pt,ru,id,hi,am,ar
  // (comma separated values are possible e.g. "hi,en")
  const language = "en";// STEP #5:// Click Save. The notify pop-up should now be working.
  
  // #########################################################
  // # End of instructions. Code follows.                    #
  // #########################################################
  
  // Set the wait time in milliseconds:const waitBeforeNotifying = 5000;const options ={weekday:'long',year:'numeric',month:'long',day:'numeric'};const englishMessage = "On " + dateOfExpiry.toLocaleDateString('en-US',options) + ", this website will move to " + newUrl + "<br> Please save this new address in your bookmarks or favorites and continue visiting the website!"

  const spanishMessage = "El " + dateOfExpiry.toLocaleDateString('es-ES',options) + ", este sitio web se trasladará a " + newUrl + "<br> Por favor, guarda esta nueva dirección en tus marcadores o favoritos y continúa visitando el sitio web.";const portugueseMessage = "Em " + dateOfExpiry.toLocaleDateString('pt-BR',options) + ", este site será movido para " + newUrl + "<br> Por favor, salve este novo endereço em seus favoritos ou marcadores e continue visitando o site.";const frenchMessage = "Le " + dateOfExpiry.toLocaleDateString('fr-FR',options) + ", ce site web sera déplacé vers " + newUrl + "<br> Veuillez enregistrer cette nouvelle adresse dans vos favoris et continuer à visiter le site web.";const indonesianMessage = "Pada " + dateOfExpiry.toLocaleDateString('id-ID',options) + ", situs web ini akan pindah ke " + newUrl + "<br> Silakan simpan alamat baru ini di bookmark atau favorit Anda dan terus kunjungi situs web ini.";const hindiMessage = dateOfExpiry.toLocaleDateString('hi-IN',options) + " को यह वेबसाइट " + newUrl + "<br> पर स्थानांतरित हो जाएगी। कृपया इस नए पते को अपने बुकमार्क या पसंदीदा में सहेज लें और वेबसाइट पर आते रहें।";const amharicMessage = "በ" + dateOfExpiry.toLocaleDateString('am-ET',options) + "፣ ይህ ድህረ ገጽ ወደ " + newUrl + " <br>ይዛወራል። እባክዎ ይህን አዲስ አድራሻ በመዝገቦችዎ ወይም በተወዳጆችዎ ውስጥ ያስቀምጡ እና ድህረ ገጹን መጎብኘት ይቀጥሉ።";const russianMessage = dateOfExpiry.toLocaleDateString('ru-RU',options) + " этот веб-сайт переедет на " + newUrl + "<br> Пожалуйста, сохраните этот новый адрес в закладках или избранном и продолжайте посещать сайт!";const arabicMessage = "في " +dateOfExpiry.toLocaleDateString('ar-SA',options) + " سينتقل هذا الموقع الإلكتروني إلى" + newUrl + "<br>" + "يرجى حفظ هذا العنوان الجديد في إشاراتك المرجعية أو المفضلة لديك ومتابعة زيارة الموقع!";let message ={"en":englishMessage,"fr":frenchMessage,"es":spanishMessage,"pt":portugueseMessage,"id":indonesianMessage,"hi":hindiMessage,"am":amharicMessage,"ru":russianMessage,"ar":arabicMessage};let title ={"en":"Attention","fr":"Attention","es":"Atención","pt":"Atenção","id":"Perhatian","hi":"ध्यान","am":"ትኩረት","ru":"Внимание","ar":"تنبيه"};languages = language.split(',');languages.forEach((v,i,a) =>{a[i]=v.trim();})
  messageText = "";messageTitle = "";for (const lang of languages){if (messageText == ""){if (Object.keys(message).includes(lang)){messageText = message[lang];messageTitle = title[lang];}else{messageText = message['en'];messageTitle = title['en'];}}else{if (Object.keys(message).includes(lang)){messageText += "<br><br>";messageText += message[lang];}}}Drupal.behaviors.subdomainNotify ={attach:function (context,settings){once('notification-dialog','html').forEach((element) =>{let isMessageImparted = "false";try{isMessageImparted = sessionStorage.getItem('subdomainMessageImparted');}catch (error){isMessageImparted = "false";}if (isMessageImparted != "true"){setTimeout(subdomainNotify,waitBeforeNotifying);}});}};function subdomainNotify(){let $confirmDialog = $("<div>" + messageText + "</div>");Drupal.dialog($confirmDialog,{title:messageTitle,width:400,modal:true,draggable:true,autoResize:false,classes:{"ui-dialog":"wildfire_dbp_usfm_confirm"},buttons:[{text:Drupal.t('OK'),click:function click(){$(this).dialog('close');return true;}}],}).showModal();try{sessionStorage.setItem('subdomainMessageImparted','true');}catch (error){}}})(jQuery,Drupal);
