const domainSelector = document.querySelector(".header-container > .domain-selector");
const currentDomain = domainSelector && domainSelector.querySelector(".current-domain-item");
const domainDropDown = domainSelector && domainSelector.querySelector(".domain-dropdown");
const countryList = domainSelector && domainSelector.querySelector(".country-list");

const toggleDomainSelector = () => {
  domainSelector && domainSelector.classList.toggle("open")

   if (countryList && countryList.classList.contains("open")) {
    toggleOtherCountryList()
  }
}

const toggleOtherCountryList = () => {
  if (!domainSelector || !countryList) return

  countryList.classList.toggle("open")
}


document.addEventListener('click', (event) => {
  if (!domainSelector || !domainDropDown) return

  event.stopPropagation();

  const isClickInsideElement = domainDropDown.contains(event.target);
  const clickedDomainSelector = currentDomain.contains(event.target);

  const isOpen = domainSelector.classList.contains("open");

  if (!isClickInsideElement && isOpen || clickedDomainSelector) {
    return toggleDomainSelector()
  }
});(function initHeader() {
	const body = document.querySelector("body");
	const header = document.querySelector(".header");
	const toggle = header.querySelector(".link-menu-toggle");
	const navLinks = header.querySelectorAll(
		".nav-dropdown > .link"
	);

	const headerItemWithDropdownToggles =
		header.querySelectorAll(
			".header-item-with-dropdown-toggle"
		);

	const menuItemChildrenToggles = header.querySelectorAll(
		".show-children-toggle"
	);

  const domainSubMenuToggle = true

	const menu = header.querySelector(".nav-menu");
	const vacancyOverviewFilters =
		document.querySelector(".form-filters");
	const closeMenu = header.querySelector(
		".close-menu .close-icon svg"
	);

	const headerItemWithDropdowns = header.querySelectorAll(
			".header-item-with-dropdown"
	);



	[...headerItemWithDropdowns].map((headerItemWithDropdown) => {
		if (window.innerWidth >= 992) {
			headerItemWithDropdown.addEventListener("click", (event) => {
				const withToggle = event.currentTarget.querySelector(".header-item-with-dropdown-toggle");
				withToggle.classList.toggle("is-open");
				event.currentTarget.blur();
			});
			document.addEventListener("click", (event) => {
				const linkLabel = headerItemWithDropdown.querySelector(".link-label")
				if (event.target !== linkLabel) {
					const withToggle = headerItemWithDropdown.querySelector(".header-item-with-dropdown-toggle");
					withToggle.classList.remove("is-open");
				}
			});
		}
		headerItemWithDropdown.addEventListener("focus", (event) => {
			event.target.classList.add("has-submenu-focus");

			document.addEventListener("click", function(event) {
				if (event.target !== headerItemWithDropdown) {
					headerItemWithDropdown.classList.remove("has-submenu-focus");
				}
			});
		});

		headerItemWithDropdown.addEventListener("keydown", function(event) {
				if (event.key === "Tab" && event.shiftKey && event.target === headerItemWithDropdown) {
					headerItemWithDropdown.classList.remove("has-submenu-focus");
				};
		});

		const dropdownMenuItems = headerItemWithDropdown.querySelectorAll(
			".dropdown-menu .dropdown-menu-item .link"
		);

		dropdownMenuItems &&
			[...dropdownMenuItems].map((dropdownMenuItem) => {
				dropdownMenuItem.addEventListener("focus", (event) => {
					headerItemWithDropdown.classList.add("has-submenu-focus");
				});

				dropdownMenuItem.addEventListener("blur", (event) => {
					const lastElementOfSubMenu = findLastNestedElement(headerItemWithDropdown);
					checkIfLast(event.target, lastElementOfSubMenu, headerItemWithDropdown);
				});

			});
	});

	function checkIfLast(element, elementOfSubMenu, headerItemWithDropdown) {
		if (element === elementOfSubMenu) {
			headerItemWithDropdown.classList.remove("has-submenu-focus");
		};
	}

	function findLastNestedElement(element) {
			const children = element.children;

			if (children.length === 0) {
				return element;
			} else {
				const lastChild = children[children.length - 1];
				return findLastNestedElement(lastChild);
			}
	}

	const checkForMobile = window.matchMedia(
		"(max-width: 992px)"
	);

	const onScroll = function onScroll(event) {
		if (window.pageYOffset > header.clientHeight) {
			header.classList.add("header-sm");
			vacancyOverviewFilters &&
				vacancyOverviewFilters.classList.add("header-sm");
		} else {
			header.classList.remove("header-sm");
			vacancyOverviewFilters &&
				vacancyOverviewFilters.classList.remove(
					"header-sm"
				);
		}
	};

  // We would prefer to define onScroll inline, but JavaScript does not allow inline ifs
  window.addEventListener("scroll", onScroll);

	if (window.innerWidth <= 992) {
		toggle &&
			toggle.addEventListener("click", (event) => {
				toggle.classList.toggle("is-open");
				menu.classList.toggle("is-open");
				body.classList.toggle("no-scroll");
			});

		navLinks &&
			domainSubMenuToggle &&
			[...navLinks].map((navLink) => {
				navLink.addEventListener("click", (event) => {
					event.preventDefault();
					event.target
						.closest(".nav-dropdown")
						.classList.toggle("is-open");
				});
			});

		closeMenu &&
			closeMenu.addEventListener("click", (event) => {
				closeMenu.classList.toggle("is-open");
				toggle && toggle.classList.remove("is-open");
				menu && menu.classList.remove("is-open");
				body && body.classList.remove("no-scroll");
			});

		headerItemWithDropdownToggles &&
			domainSubMenuToggle &&
			[...headerItemWithDropdownToggles].map(
				(headerItemWithDropdownToggle) => {
					headerItemWithDropdownToggle.addEventListener(
						"click",
						function () {
							headerItemWithDropdownToggle.classList.toggle(
								"is-open"
							);
						}
					);
				}
			);
	}
	menuItemChildrenToggles &&
		[...menuItemChildrenToggles].map((item) => {
			item &&
				item.addEventListener("click", (event) => {
					event.target.parentNode.classList.toggle(
						"is-open"
					);
				});
		});
})();

(function allowFavorites() {
  fetch("/api/cookie-consent")
    .then((response) => response.json())
    .then((data) => {
      const favoriteToggle = document.querySelector("#favorites-page-link");
      data !== "necessary" && favoriteToggle && favoriteToggle.classList.remove("hidden");
    });
})();

(function favoritesCount() {
  fetch("/api/1/favorites")
    .then((response) => response.json())
    .then((data) => {
      const counter = document.querySelector(".link-counter");
      const span = counter && counter.querySelector("span");
      const linkFavorites = document.querySelector(".link.link-favorites");
      if (data && data.length > 0 && span) {
        counter.classList.remove("hidden");
        linkFavorites.classList.add("with-counter");
        span.textContent = data.length;
      }
    });
})();
(function () {
    var app = Elm.Form.init({
        node: document.getElementById("application-form-" + "hident3"),
        flags: {
            formEntity: {"formRequired":[[{"tag":"phone-number"}],[{"tag":"last-name"}],[{"tag":"first-name"}],[{"tag":"privacy"}],[{"tag":"email-address"}]],"formLabel":"Form","formIsDefaultApplicationForm":true,"formFields":[[{"type_":{"tag":"text","contents":{"maxLength":100,"minLength":0}},"defaultPlaceholder":"","missingError":[],"hiddenLabel":false,"name":{"tag":"first-name"},"defaultMissingError":"","defaultInvalidError":"","defaultLabel":"","placeholder":[],"label":[],"invalidError":[]},{"type_":{"tag":"text","contents":{"maxLength":100,"minLength":0}},"defaultPlaceholder":"","missingError":[],"hiddenLabel":false,"name":{"tag":"last-name"},"defaultMissingError":"","defaultInvalidError":"","defaultLabel":"","placeholder":[],"label":[],"invalidError":[]}],[{"type_":{"tag":"email-address"},"defaultPlaceholder":"","missingError":[],"hiddenLabel":false,"name":{"tag":"email-address"},"defaultMissingError":"","defaultInvalidError":"","defaultLabel":"","placeholder":[],"label":[],"invalidError":[]}],[{"type_":{"tag":"text","contents":{"maxLength":100,"minLength":0}},"defaultPlaceholder":"","missingError":[],"hiddenLabel":false,"name":{"tag":"phone-number"},"defaultMissingError":"","defaultInvalidError":"","defaultLabel":"","placeholder":[],"label":[],"invalidError":[]}],[{"type_":{"tag":"file","contents":{"mimeTypes":["application/vnd.oasis.opendocument.text","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/pdf","application/x-iwork-pages-sffpages","text/plain"],"maxFileSizeInMB":30}},"defaultPlaceholder":"","missingError":[],"hiddenLabel":false,"name":{"tag":"resume"},"defaultMissingError":"","defaultInvalidError":"","defaultLabel":"","placeholder":[],"label":[],"invalidError":[]}],[{"type_":{"tag":"checkbox"},"defaultPlaceholder":"","missingError":[],"hiddenLabel":false,"name":{"tag":"privacy"},"defaultMissingError":"","defaultInvalidError":"","defaultLabel":"","placeholder":[],"label":[],"invalidError":[]}]],"id":1,"formInserted":"2024-02-19T13:47:35.420426Z","formFormType":"job-application","formUpdated":"2024-04-16T07:56:45.243497Z"},
            translations: {"welcome-page-rule3":"Everyone displayed in footage agrees to sharing the content","referral-form-matching-metadata":"What kind of vacancies best suit the one you refer?","referral-thanks-description":"Thank you for your referral! Together with your help we can continue to grow. Your trust and confidence in us is greatly appreciated!","house-number-placeholder":"Enter your house number","city-label":"City","status":"Status","open-text-label":"Open text","referral-form-opt-out-text":"Sorry to see you go.","referral-form-personal-message-placeholder":"Enter a personal message for the person you\'re referring to us","submit-form-success-message":"Successfully submitted the form","motivation-label":"Upload your motivation","street-placeholder":"Enter your street name","welcome-page-intro-text":"We are such a fun and passionate brand! We would love to share this even more with our (S)heroes who shop at Hunkmöller around the world! Let’s inspire them what HKM means! Help us create content that we can share on are international platforms! We are super curious to see your ideas!","success-page-follow-instagram-button":"Follow HKM People Instagram Channel","internship-evaluation2-placeholder":"Choose file","referral-form-refer-someone-label":"Which website do you want the person you refer to apply on?","no-uploads-found":"No uploads found","open-checkbox-three-label":"Select field (3)","referral-tool-change-filter":"What kind of vacancies suit you best?","resume-label":"Upload your CV","privacy-label":"Privacy statement","grades-master1-label":"Grades master 1","referral-form-phone-number":"Add the phone number","upload-page-banner-subtitle":"Let\'s go","address-label":"Address","referral-form-email-placeholder":"Enter your email","welcome-page-rule2":"No customers are allowed in footage","url-placeholder":"https://www.example.url","grades-bachelor1-label":"Grades bachelor 1","privacy-consent-text":"I accept the","xing-url-placeholder":"https://www.xing.com/profile/username","additional-file1-label":"Upload file (1)","privacy-consent-link-text":"privacy conditions","grades-master2-placeholder":"Choose file","linked-in-url-placeholder":"https://www.linkedin.com/username","privacy-link-text":"privacy conditions","first-name-label":"Firstname","grades-bachelor2-placeholder":"Choose file","internal-application-label":"Internal application","upload-page-step1":"Step 1","salary-indication-placeholder":"Salary indication","max-request-size-exceeded-title":"Upload size too big","success-page-back-to-upload-page-button":"That was fun do it again","personal-message":"Personal message","caption":"Caption","welcome-page-rule1":"Share fun and authentic content from your store-team","privacy-text":"I accept the","custom-how-did-you-get-here-select-label":"How did you get here?","open-select-option-five":"Open select option 5","grades-bachelor2-label":"Grades bachelor 2","referral-form-banner-title":"Welcome","status-pending":"Pending","salary-indication-label":"Salary indication","first-name-placeholder":"Enter your first name","grades-master2-label":"Grades master 2","linked-in-url-label":"LinkedIn URL","phone-number-with-calling-code-label":"Phone with country code","success-page-banner-title":"Submitted!","email-address-placeholder":"hello@example.com","referral-form-last-name-placeholder":"Enter your last name","open-checkbox-three-text":"Extra checkbox 3 text","welcome-page-rules-title":"The basics","phone-number-label":"Phonenumber","internship-evaluation1-label":"Internship evaluation 1","referral-form-first-name-placeholder":"Enter your first name","referral-form-intro-text":"Do you have someone in mind who would be a perfect fit for us? Become an ambassador and send your friend a personal invitation to apply with us.","open-select-option-four":"Open select option 4","submit":"Submit","referral-form-first-name-label":"First name","daypart-availability-description":"Day part availability description","phone-number-with-calling-code-placeholder":"Enter your phone number","success-page-to-my-uploads-button":"See all submissions","no-uploads-found-description":"We couldn\'t find any uploads for you yet","newsletter-subscription-label":"Subscribe to newsletter","open-select-option-three":"Open select option 3","daypart-availability-label":"Daypart availability","phone-number-placeholder":"Enter your phone number","email-address-label":"Emailaddress","referral-form-last-name-label":"Last name","internship-evaluation1-placeholder":"Choose file","resume-placeholder":"Choose file","newsletter-subscription-text":"Subscribe to newsletter","referral-form-filters-label":"Which jobs are interesting?","browse-media":"Browse media","submit-form":"Submit","referral-thanks":"Thanks for your referral!","referral-form-upload-label":"Select a personal image","screening-questions-label":"Screening Questions","upload-page-media-label":"Add your tags","referral-form-personal-message-label":"Personal message","upload-page-tags-label":"Add your tags","open-select-description":"Open select description","open-select-label":"Open select","motivation-placeholder":"Upload your motivation","open-checkbox-four-label":"Select field (4)","address-with-auto-fill-label":"Address (with autofill)","street-label":"Streetname","status-approved":"Approved","open-text-placeholder":"Open text placeholder","internship-evaluation2-label":"Internship evaluation 2","availability-label":"Availability (daypart)","welcome-page-call-to-action-button":"Submit your content","max-request-size-exceeded-description":"If you\'re uploading multiple files, try to upload less files at once.","additional-file1-placeholder":"Choose file","xing-url-label":"Xing url","success-page-banner-subtitle":"Your content is","upload-page-caption-label":"(Optional) Do you have suggestion for a caption to come with your content?","no-feedback-yet":"No feedback yet","open-checkbox-two-label":"Select field (2)","upload-page-privacy-link-label":"Read more","open-checkbox-one-label":"Select field (1)","grades-master1-placeholder":"Choose file","internal-application-text":"I work here","referral-form-email-label":"Email","motivation-text-area-placeholder":"Write your motivation here","welcome-page-banner-title":"Share your passion","url-label":"Url","grades-bachelor1-placeholder":"Choose file","upload-page-step2":"Step 2","postal-code-placeholder":"Enter your postal code","additional-file2-label":"Upload file (2)","success-page-explanation-text":"Your content has been submitted. It will be checked soon! You can see your submissions and their statuses by tapping on the star-icon! Next time you log in you will be notified when the status has changed!","click-to-remove":"Click to remove","select-file":"Select file","open-checkbox-two-text":"Extra checkbox 2 text","upload-page-privacy-link-path":"","open-checkbox-one-text":"Extra checkbox 1 text","last-name-label":"Lastname","date-of-birth-label":"Date of birth","success-page-explanation-title":"Way to go!","upload-page-consent-text":"Yes, I have asked all persons in the uploaded content for approval of the usage (make sure to have written consent).","open-select-option-two":"Open select option 2","open-select-option-one":"Open select option 1","additional-file2-placeholder":"Choose file","postal-code-label":"Postal code","privacy-consent-label":"Privacy statement","status-honors":"You rock!","last-name-placeholder":"Enter your last name","status-retry":"Retry","house-number-label":"House number","feedback":"Feedback","upload-page-step3":"Step 3","tags":"Page tags","open-checkbox-four-text":"Extra checkbox 4 text","city-placeholder":"Enter your city","upload-page-banner-title":"Share your content","store-data-label":"Store data longer","vacancy-description-label":"Vacancy description"},
            formTypeData: {"tag":"job-application-data","contents":32},
            today: {
              now: Date.now(),
              timeZoneOffset: -(new Date().getTimezoneOffset())
            },
            buttonOverwriteText: null,
            privacyPagePath: "https://www.oranjegroep.com/privacy",
            defaultCallingCode: "netherlands",
            domainId: 1,
            schemaFields: [{"type_":{"tag":"file","contents":{"mimeTypes":["application/vnd.oasis.opendocument.text","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/pdf","application/x-iwork-pages-sffpages","text/plain"],"maxFileSizeInMB":30}},"name":{"tag":"resume"},"requiredByExport":false},{"type_":{"tag":"email-address"},"name":{"tag":"email-address"},"requiredByExport":true},{"type_":{"tag":"text","contents":{"maxLength":100,"minLength":0}},"name":{"tag":"first-name"},"requiredByExport":true},{"type_":{"tag":"text","contents":{"maxLength":100,"minLength":0}},"name":{"tag":"last-name"},"requiredByExport":true},{"type_":{"tag":"url","contents":"linked-in-url"},"name":{"tag":"linked-in-url"},"requiredByExport":false},{"type_":{"tag":"file","contents":{"mimeTypes":["application/vnd.oasis.opendocument.text","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/pdf","application/x-iwork-pages-sffpages","text/plain"],"maxFileSizeInMB":30}},"name":{"tag":"motivation"},"requiredByExport":false},{"type_":{"tag":"text","contents":{"maxLength":100,"minLength":0}},"name":{"tag":"phone-number"},"requiredByExport":false},{"type_":{"tag":"checkbox"},"name":{"tag":"privacy"},"requiredByExport":true}],
            screeningQuestions : []
        }
    });

    app.ports.redirectTo.subscribe(function(url) {
        window.location.assign(url);
    });

    function getTrackingCode() {
        var scripts = [...document.getElementsByTagName('script')];
        var script = scripts.filter(script => script.src.includes('/gtag/js?id='))[0];
        if (script !== undefined) {
          const urlParams = new URLSearchParams(script.src);
          return urlParams.get('https://www.googletagmanager.com/gtag/js?id')
        }
    };

    function getClientID () {
      var cookie = {};
      document.cookie.split(';').forEach(function(el) {
        var splitCookie = el.split('=');
        var key = splitCookie[0].trim();
        var value = splitCookie[1];
        cookie[key] = value;
      });
      return cookie["_ga"].substring(6);
    }


    window.addEventListener("load", function () {
      // Check if GA is loaded, if so send data to elm
      (function check_ga(i) {
        if (getTrackingCode()) {
          const trackingId = getTrackingCode();
          const clientId = getClientID();
          trackingId && clientId &&
           app.ports.receiveGoogleAnalyticsInfo.send({
            trackingId: trackingId,
            clientId: clientId,
            utmCustom: "eyJkZXBhcnRtZW50IjoiQ29uc3RydWN0aW9uIiwic2FsYXJ5IjoiMSIsImV2ZW50Ijoiam9iX2RldGFpbHNfbG9hZGVkIiwibG9jYXRpb24tbmFtZSI6IlJvdHRlcmRhbSIsImNvbnRyYWN0LXR5cGUiOiJGbGV4IChEdXRjaCBjb250cmFjdCkiLCJjdXN0b20tZmlsdGVyLTAxIjoiIiwiZWR1Y2F0aW9uIjoiIiwiZGlzY2lwbGluZSI6Ik1lY2hhbmljYWwgIiwiY3VzdG9tLWZpbHRlci0wNiI6IiIsImV4dGVybmFsLWlkIjoiMTI3IiwiY291bnRyeSI6Ik5ldGhlcmxhbmRzIiwibG9jYXRpb24tdHlwZSI6IiIsImhvdXJzIjpudWxsLCJjdXN0b20tZmlsdGVyLTA1IjoiIiwicmVjcnVpdGVyIjoiRnJlZCBCYWlyZCIsImN1c3RvbS1maWx0ZXItMDQiOiIiLCJjaXR5IjoiUm90dGVyZGFtIiwiam9idGl0bGUiOiJJbnN0cnVtZW50YXRpb24gbWVjaGFuaWMiLCJwcm92aW5jZSI6IiIsImN1c3RvbS1maWx0ZXItMDMiOiIiLCJleHBlcmllbmNlIjoiMCA+IDIgeWVhcnMiLCJmdWxsdGltZS1wYXJ0dGltZSI6IiIsImN1c3RvbS1maWx0ZXItMDIiOiIifQ=="
          });
        } else if (i <= 5) {
          setTimeout(() => check_ga(i + 1), 500);
        }
      })(1);
    });

    // If ports are unused Elm throws them away during compilation
    try {
        app.ports.logError_.subscribe(console.error);
    } catch (err) {
    }

    try {
        app.ports.logWarning_.subscribe(console.warn);
    } catch (err) {
    }

    try {
        app.ports.logInfo_.subscribe(console.info);
    } catch (err) {
    }
})();
addEventListener('DOMContentLoaded', (event) => {
  fetch("/api/token")
    .then(res => res.ok && res.json())
    .then((value) => {
      const input = document.createElement("input");

      input.setAttribute("type", "hidden");
      input.setAttribute("name", "_token");
      input.setAttribute("value", value.token);

      document.getElementById("toggle-32").appendChild(input);
    });
});

(function allowFavorites() {
	fetch("/api/cookie-consent")
		.then((response) => response.json())
		.then((data) => {
      const toggleLinks = document.querySelectorAll("#favorites-toggle-link");
      Array.from(toggleLinks).forEach((link) => {
        data !== "necessary" && link && link.classList.remove("hidden");
		  });
    })
})();

(function inFavorites() {
	fetch("/api/1/favorites")
		.then((response) => response.json())
		.then((data) => {
      const icons = document.querySelectorAll(".favorites-icon");
      Array.from(icons).forEach((icon) => {
        const emptyIcon = icon && icon.querySelector(".empty-icon");
        const filledIcon = icon && icon.querySelector(".filled-icon");
        if (data && data.includes(32) && emptyIcon && filledIcon) {
          filledIcon.classList.remove("hidden");
          emptyIcon.classList.add("hidden");
        }
      })
		});
})();
addEventListener('DOMContentLoaded', (event) => {
  fetch("/api/token")
    .then(res => res.ok && res.json())
    .then((value) => {
      const input = document.createElement("input");

      input.setAttribute("type", "hidden");
      input.setAttribute("name", "_token");
      input.setAttribute("value", value.token);

      document.getElementById("toggle-32").appendChild(input);
    });
});

(function allowFavorites() {
	fetch("/api/cookie-consent")
		.then((response) => response.json())
		.then((data) => {
      const toggleLinks = document.querySelectorAll("#favorites-toggle-link");
      Array.from(toggleLinks).forEach((link) => {
        data !== "necessary" && link && link.classList.remove("hidden");
		  });
    })
})();

(function inFavorites() {
	fetch("/api/1/favorites")
		.then((response) => response.json())
		.then((data) => {
      const icons = document.querySelectorAll(".favorites-icon");
      Array.from(icons).forEach((icon) => {
        const emptyIcon = icon && icon.querySelector(".empty-icon");
        const filledIcon = icon && icon.querySelector(".filled-icon");
        if (data && data.includes(32) && emptyIcon && filledIcon) {
          filledIcon.classList.remove("hidden");
          emptyIcon.classList.add("hidden");
        }
      })
		});
})();
(function sticky () {
  const selector = document.getElementById("hident2")
  const sticky = document.querySelectorAll(".vacancy-sticky");
  const bannerHeight = selector.querySelector(".banner-wrapper").clientHeight;

  const onScroll = function onScroll(evt) {
    if (window.pageYOffset > bannerHeight) {
      sticky.forEach((element) => {
        element.classList.add("active");
      });

    } else {
      sticky.forEach((element) => {
        element.classList.contains("active") && element.classList.remove("active");
      });
    }
  };

  window.addEventListener("scroll", onScroll, { capture: true });
})();

function stickyScrollOpenForm (uuid) {
  var selector = document.getElementById(uuid);
  var formContainer = selector.querySelector(".form-container");

  window.scrollTo({
    top: 0,
    behavior: 'smooth'
  });

  if (!formContainer.classList.contains("visible")) {
      toggleForm(uuid);
  };
}(function vacancyBackButton() {
  const element = document.getElementById("hident2");
  const vacancyBackButton = element.querySelector(".vacancy-back-button");
  const vacancyBackButtonText =
    vacancyBackButton && vacancyBackButton.querySelector(".btn-text");
  const referrer = document.referrer !== location.href && document.referrer;
  const comesFromVacancyOverview =
    referrer && referrer.includes("https://www.oranjegroep.com/vacancies");
  const comesFromCMSpage =
    referrer &&
    !comesFromVacancyOverview &&
    new URL(referrer).origin == new URL(location.href).origin;
  const comesFromVacancyDetailPage =
  referrer &&
    ((window.location.href.indexOf("solliciteer") > -1) || (window.location.href.indexOf("apply") > -1))
  vacancyBackButtonText.innerText =
    (comesFromVacancyOverview && "Back to Vacancies Results") ||
    vacancyBackButtonText.innerText;
  vacancyBackButtonText.innerText =
    (comesFromCMSpage && "Back to previous page") ||
    vacancyBackButtonText.innerText;
  vacancyBackButtonText.innerText =
    (comesFromVacancyDetailPage && "Back to previous page") ||
    vacancyBackButtonText.innerText;

  function clickLogic() {
    (comesFromVacancyOverview && window.history.back()) ||
      (comesFromCMSpage && window.history.back());

    if (!comesFromCMSpage && !comesFromVacancyOverview) {
      document.location.href = "https://www.oranjegroep.com/vacancies";
    }
  }

  vacancyBackButton && vacancyBackButton.addEventListener("click", clickLogic);
})();

var body = document.querySelector("body");

function toggleForm(uuid) {
  var selector = document.getElementById(uuid);
  var formContainer = selector.querySelector(".form-container");
  var btnDisplay = selector.querySelector(".btn-display");
  formContainer.classList.toggle("visible");
  btnDisplay.classList.toggle("hidden");

  if (window.innerWidth <= 992) {
    body.classList.toggle("no-scroll");
  };
};

window.addEventListener("load", function () {
  var dataLayerObj = {"department":"Construction","salary":"1","event":"application_form","location-name":"Rotterdam","contract-type":"Flex (Dutch contract)","custom-filter-01":"","education":"","discipline":"Mechanical ","custom-filter-06":"","external-id":"127","country":"Netherlands","location-type":"","hours":null,"custom-filter-05":"","recruiter":"Fred Baird","custom-filter-04":"","city":"Rotterdam","jobtitle":"Instrumentation mechanic","province":"","custom-filter-03":"","experience":"0 \u003e 2 years","fulltime-parttime":"","custom-filter-02":""};
  window.dataLayer = window.dataLayer || [];
  fetch(`/api/cookie-consent`)
    .then((response) => response.json())
    .then((data) => { window.dataLayer.push({...dataLayerObj, consent: data})})
    .catch(() => { window.dataLayer.push({...dataLayerObj, consent: "necessary"})});
});

window.addEventListener('DOMContentLoaded', (event) => {
  const endDates = Array.from(document.querySelectorAll(".metadata .date-metadata"));

  endDates.forEach(endDate => {
    const date = endDate.getAttribute("data-utc");

    endDate.innerHTML = formatDate(date, false);
  });
});
addEventListener('DOMContentLoaded', (event) => {
  fetch("/api/token")
    .then(res => res.ok && res.json())
    .then((value) => {
      const input = document.createElement("input");

      input.setAttribute("type", "hidden");
      input.setAttribute("name", "_token");
      input.setAttribute("value", value.token);

      document.getElementById("toggle-32").appendChild(input);
    });
});

(function allowFavorites() {
	fetch("/api/cookie-consent")
		.then((response) => response.json())
		.then((data) => {
      const toggleLinks = document.querySelectorAll("#favorites-toggle-link");
      Array.from(toggleLinks).forEach((link) => {
        data !== "necessary" && link && link.classList.remove("hidden");
		  });
    })
})();

(function inFavorites() {
	fetch("/api/1/favorites")
		.then((response) => response.json())
		.then((data) => {
      const icons = document.querySelectorAll(".favorites-icon");
      Array.from(icons).forEach((icon) => {
        const emptyIcon = icon && icon.querySelector(".empty-icon");
        const filledIcon = icon && icon.querySelector(".filled-icon");
        if (data && data.includes(32) && emptyIcon && filledIcon) {
          filledIcon.classList.remove("hidden");
          emptyIcon.classList.add("hidden");
        }
      })
		});
})();
(function stickyBanner() {
  const selector = document.getElementById("hident4")
  const sticky = document.querySelectorAll(".vacancy-sticky");
  const banner = selector.querySelector(".banner-background").clientHeight;

  const onScroll = function onScroll(evt) {
    if (banner && window.pageYOffset > banner) {
      sticky.forEach((element) => {
        element.classList.add("active");
      });
    } else {
      sticky.forEach((element) => {
        element.classList.contains("active") && element.classList.remove("active");
      });
    }
  };

  window.addEventListener("scroll", onScroll, { capture: true });
})();
(function vacancyBackButton() {
  const element = document.getElementById("hident4");
  const vacancyBackButton = element.querySelector(".vacancy-back-button");
  const vacancyBackButtonText =
    vacancyBackButton && vacancyBackButton.querySelector(".btn-text");
  const referrer = document.referrer !== location.href && document.referrer;
  const comesFromVacancyOverview =
    referrer && referrer.includes("https://www.oranjegroep.com/vacancies");
  const comesFromCMSpage =
    referrer &&
    !comesFromVacancyOverview &&
    new URL(referrer).origin == new URL(location.href).origin;
  const comesFromVacancyDetailPage =
  referrer &&
    ((window.location.href.indexOf("solliciteer") > -1) || (window.location.href.indexOf("apply") > -1))
  vacancyBackButtonText.innerText =
    (comesFromVacancyOverview && "Back to Vacancies Results") ||
    vacancyBackButtonText.innerText;
  vacancyBackButtonText.innerText =
    (comesFromCMSpage && "Back to previous page") ||
    vacancyBackButtonText.innerText;
  vacancyBackButtonText.innerText =
    (comesFromVacancyDetailPage && "Back to previous page") ||
    vacancyBackButtonText.innerText;

  function clickLogic() {
    (comesFromVacancyOverview && window.history.back()) ||
      (comesFromCMSpage && window.history.back());

    if (!comesFromCMSpage && !comesFromVacancyOverview) {
      document.location.href = "https://www.oranjegroep.com/vacancies";
    }
  }

  vacancyBackButton && vacancyBackButton.addEventListener("click", clickLogic);
})();

window.addEventListener('DOMContentLoaded', (event) => {
  const endDates = Array.from(document.querySelectorAll(".metadata .date-metadata"));
  endDates.forEach(endDate => {
    const date = endDate.getAttribute("data-utc");
    endDate.innerHTML = formatDate(date, false);
  });
});
(function () {
    var app = Elm.Slider.init({
        node: document.getElementById("card-slider-hident5"),
        flags: {
            slider: {"tag":"card-slider","contents":[{"image":{"url":"","src":"/static/uploads/65-afif-ramdhasuma-h8-at-mkh-yn-io-unsplash-1.jpg","align":"vertical-align-top","ariaLabel":"","title":"","horizontalAlign":"horizontal-align-fill","alt":""},"heading":{"color":"light","size":3,"text":"WE WILL ARRANGE\u0026nbsp;\u003cb\u003eTRANSPORTATION\u003c/b\u003e\u0026nbsp; \u0026amp;\u0026nbsp;\u003cb\u003eHOUSING\u003c/b\u003e","align":"left"},"spacer":null,"plainText":{"color":"background-dependent","text":"From the moment you start working for ORANJEGROEP, we will provide you with housing close to the project.  Furthermore, we will arrange transportation to and from the project location.\u0026nbsp;","align":"left"},"linkElement":{"style":"style1","text":"","href":"","align":"horizontal-align-left","ariaLabel":"","target":"_self"}},{"image":{"url":"","src":"/static/uploads/71-130874593-3435329183246454-3123865624046807728-n-1.jpg","align":"vertical-align-top","ariaLabel":"","title":"","horizontalAlign":"horizontal-align-fill","alt":""},"heading":{"color":"light","size":3,"text":"ALL THE \u003cb\u003eSPECIAL TOOLS\u003c/b\u003e\u0026nbsp;AND\u0026nbsp;\u003cb\u003eORANGE GEAR\u003c/b\u003e\u0026nbsp;YOU NEED\u0026nbsp; \u0026nbsp;","align":"left"},"spacer":null,"plainText":{"color":"background-dependent","text":"To work comfortably and with the right tools, ORANJEGROEP will provide you with your very own equipment and gear.\u0026nbsp;","align":"left"},"linkElement":{"style":"style1","text":"","href":"","align":"horizontal-align-left","ariaLabel":"","target":"_self"}},{"image":{"url":"","src":"/static/uploads/76-christopher-burns-8-kf-c-r12oe-u-m-unsplash-1.jpg","align":"vertical-align-top","ariaLabel":"","title":"","horizontalAlign":"horizontal-align-fill","alt":""},"heading":{"color":"light","size":3,"text":"WE WILL HELP YOU GET THE\u0026nbsp;\u003cb\u003eCERTIFICATES\u003c/b\u003e\u0026nbsp;YOU NEED\u0026nbsp;\u0026nbsp;","align":"left"},"spacer":null,"plainText":{"color":"background-dependent","text":"Don\'t have all the neccessary certificates to start working, or you want to develop your skills further?  We can help you obtain your certifications before and during your employment, which you can add to your very own ORANJEGROEP CV\u0026nbsp;\u0026nbsp;","align":"left"},"linkElement":{"style":"style1","text":"","href":"","align":"horizontal-align-left","ariaLabel":"","target":"_self"}}]},
            sliderType : "in-twos",
            windowWidth: window.innerWidth,
            infinity: false,
            project: "oranje-groep"
        }
    });
})();
(function () {
    var app = Elm.Slider.init({
        node: document.getElementById("application-procedure-" + "hident6"),
        flags: {
            slider: {"tag":"application-procedure-slider","contents":[{"icon":"/static/uploads/start.svg","title":"YOU APPLY HERE!","description":"Use the form and we will get in touch with you!","maskColor":"secondary"},{"icon":"/static/uploads/start.svg","title":"WE MEET FOR THE \u003cbr\u003eFIRST TIME","description":"This will be in our office in Rotterdam or online.","maskColor":"secondary"},{"icon":"/static/uploads/start.svg","title":"YOU’LL RECEIVE A \u003cbr\u003ePROPOSAL \u003cbr\u003eIMMEDIATELY","description":"Right after the interview!","maskColor":"secondary"},{"icon":"/static/uploads/start.svg","title":"WE’LL ARRANGE \u003cbr\u003eEVERYTHING FOR YOU \u003cbr\u003eTO DO YOUR JOB!","description":"And you will start on a project!","maskColor":"secondary"}]},
            sliderType : "in-threes",
            windowWidth: window.innerWidth,
            infinity: false,
            project: "oranje-groep"
        }
    });
})();
window.addEventListener('DOMContentLoaded', (event) => {
  const allEvents = Array.from(document.querySelectorAll(".events-container .start-date"));

  allEvents.forEach(eventHtml => {
    const date = eventHtml.getAttribute("data-utc");
    const showTime = eventHtml.dataset.showTime ? true : false;

    eventHtml.innerHTML = formatDate(date, showTime);
  });
});
