/*
 * MyronCMS Release Shell Metadata
 * Single-source declaration for UI release identity in style-guide pages.
 */
(function initReleaseShell(global) {
  "use strict";

  var release = Object.freeze({
    product: "MyronCMS",
    codename: "Apollo",
    version: "v1.1.12"
  });

  function applyRelease(doc) {
    if (!doc) {
      return release;
    }

    var root = doc.documentElement;
    var titleContext = root ? root.getAttribute("data-sg-title-context") : "";
    var productNodes = doc.querySelectorAll("[data-sg-release-product]");
    var codenameNodes = doc.querySelectorAll("[data-sg-release-codename]");
    var versionNodes = doc.querySelectorAll("[data-sg-release-version]");

    productNodes.forEach(function writeProduct(node) {
      node.textContent = release.product;
    });

    codenameNodes.forEach(function writeCodename(node) {
      node.textContent = release.codename;
    });

    versionNodes.forEach(function writeVersion(node) {
      node.textContent = release.version;
    });

    if (titleContext) {
      doc.title =
        release.product +
        " · " +
        titleContext +
        " · " +
        release.codename +
        " " +
        release.version;
    }

    return release;
  }

  global.MyronRelease = release;
  global.applyMyronRelease = function applyMyronRelease(doc) {
    return applyRelease(doc || global.document);
  };

  if (global.document) {
    if (global.document.readyState === "loading") {
      global.document.addEventListener(
        "DOMContentLoaded",
        function onDomReady() {
          applyRelease(global.document);
        },
        { once: true }
      );
    } else {
      applyRelease(global.document);
    }
  }
})(window);
