/* Info-page live widget loader — assembled into each info-<device>.html by build.sh.
   The host page sets window.INFO_DEVICE = {file, name}. This builds the embedded widget
   (<device>.html?embed=1, which loads the default set lists) and auto-sizes the iframe
   from the {type:'varasys-h'} height the widget posts back. Defers to DOM-ready. */
(function () {
  function init() {
    var d = window.INFO_DEVICE || { file: "/editor.html", name: "PolyMeter" };
    var ifr = document.getElementById("ifr"),
        nm = document.getElementById("ivName"),
        op = document.getElementById("ivOpen");
    if (nm) nm.innerHTML = "<b>" + d.name + "</b>";
    if (op) op.href = d.file;
    if (ifr) ifr.src = d.file + "?embed=1";
  }
  addEventListener("message", function (e) {
    var ifr = document.getElementById("ifr");
    if (!e.data || !ifr || e.source !== ifr.contentWindow) return;
    if (e.data.type === "varasys-h" && typeof e.data.h === "number") ifr.style.height = e.data.h + "px";
  });
  if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); else init();
})();
