(() => {
  // ns-hugo:/builds/purchase/pricing/conholdate.com/themes/mytheme/assets/js/redesign.js
  function initPlatformSelects() {
    document.addEventListener("change", function(e) {
      if (e.target.classList && e.target.classList.contains("rd-pcard__platform") && e.target.value) {
        window.location.href = e.target.value;
      }
    });
  }
  function initProductSearch() {
    var input = document.getElementById("rd-product-search");
    var grid = document.getElementById("rd-product-grid");
    if (!input || !grid)
      return;
    var cards = [].slice.call(grid.querySelectorAll(".rd-pcard"));
    var empty = document.getElementById("rd-product-empty");
    var chips = [].slice.call(document.querySelectorAll(".rd-chip[data-q]"));
    function apply() {
      var q = input.value.trim().toLowerCase();
      var shown = 0;
      cards.forEach(function(card) {
        var match = !q || card.getAttribute("data-name").indexOf(q) !== -1;
        card.hidden = !match;
        if (match)
          shown++;
      });
      chips.forEach(function(chip) {
        chip.classList.toggle("is-active", chip.getAttribute("data-q").toLowerCase() === q);
      });
      if (empty) {
        empty.hidden = shown > 0;
        empty.querySelector("[data-q-echo]").textContent = input.value.trim();
      }
    }
    input.addEventListener("input", apply);
    chips.forEach(function(chip) {
      chip.addEventListener("click", function() {
        input.value = chip.getAttribute("data-q");
        apply();
      });
    });
    if (empty) {
      empty.querySelector("[data-clear]").addEventListener("click", function(e) {
        e.preventDefault();
        input.value = "";
        apply();
        input.focus();
      });
    }
    document.addEventListener("keydown", function(e) {
      var tag = document.activeElement && document.activeElement.tagName || "";
      if (e.key === "/" && !/INPUT|TEXTAREA|SELECT/.test(tag)) {
        e.preventDefault();
        input.focus();
      }
    });
  }
  function initKnowledgebase() {
    var list = document.getElementById("rd-kb-list");
    if (!list)
      return;
    var input = document.getElementById("rd-kb-search");
    var empty = document.getElementById("rd-kb-empty");
    var cards = [].slice.call(list.querySelectorAll(".rd-kb-card"));
    var pills = [].slice.call(document.querySelectorAll(".rd-pill[data-cat]"));
    var activeCat = "all";
    function apply() {
      var q = input ? input.value.trim().toLowerCase() : "";
      var first = null;
      cards.forEach(function(card) {
        var match = (activeCat === "all" || card.getAttribute("data-cat") === activeCat) && (!q || card.getAttribute("data-search").indexOf(q) !== -1);
        card.hidden = !match;
        card.classList.remove("is-featured");
        if (match && !first)
          first = card;
      });
      if (first)
        first.classList.add("is-featured");
      if (empty)
        empty.hidden = !!first;
    }
    pills.forEach(function(pill) {
      pill.addEventListener("click", function() {
        activeCat = pill.getAttribute("data-cat");
        pills.forEach(function(p) {
          p.classList.toggle("is-active", p === pill);
        });
        apply();
      });
    });
    if (input)
      input.addEventListener("input", apply);
  }
  function startsWithNote(el) {
    return /^\s*note\s*:/i.test(el.textContent);
  }
  function isCtaLike(el) {
    if (!el)
      return false;
    var text = el.textContent.trim();
    return /^ready\b/i.test(text) && /purchase\.(aspose|groupdocs)\.com|contact/i.test(el.innerHTML);
  }
  function enhanceNotes(prose) {
    [].slice.call(prose.querySelectorAll(":scope > p, :scope > blockquote")).forEach(function(el) {
      if (startsWithNote(el))
        el.classList.add("rd-note");
    });
  }
  function enhanceTables(prose) {
    [].slice.call(prose.querySelectorAll(":scope > table")).forEach(function(table) {
      var wrap = document.createElement("div");
      wrap.className = "rd-table-wrap";
      table.parentNode.insertBefore(wrap, table);
      wrap.appendChild(table);
    });
  }
  function enhanceKeyItems(prose) {
    [].slice.call(prose.querySelectorAll(":scope > ol")).forEach(function(ol) {
      var items = [].slice.call(ol.children);
      if (items.length < 2 || items.length > 6)
        return;
      var ok = items.every(function(li) {
        var first = li.firstElementChild;
        return first && first.tagName === "STRONG" && li.textContent.trim().indexOf(first.textContent.trim()) === 0 && li.textContent.length < 280 && !li.querySelector("ul, ol");
      });
      if (!ok)
        return;
      ol.classList.add("rd-keycards");
      items.forEach(function(li, i) {
        var strong = li.firstElementChild;
        var title = strong.textContent.replace(/[:\s]+$/, "");
        li.removeChild(strong);
        var rest = li.innerHTML.replace(/^\s*(?:[-–—:]\s*)?/, "");
        var restFirst = rest.charAt(0);
        if (restFirst)
          rest = restFirst.toUpperCase() + rest.slice(1);
        li.innerHTML = '<div class="rd-keycards__no">' + String(i + 1).padStart(2, "0") + '</div><div class="rd-keycards__title"></div><div>' + rest + "</div>";
        li.querySelector(".rd-keycards__title").textContent = title;
      });
    });
  }
  function enhanceFaq(prose) {
    var heading = [].slice.call(prose.querySelectorAll(":scope > h2")).filter(function(h) {
      return /faq|frequently asked/i.test(h.textContent);
    })[0];
    if (!heading)
      return;
    var items = [];
    var current = null;
    var node = heading.nextElementSibling;
    var consumed = [];
    while (node && node.tagName !== "H2" && node.tagName !== "HR" && node.tagName !== "BLOCKQUOTE") {
      var first = node.firstElementChild;
      var isQuestionP = node.tagName === "P" && first && first.tagName === "STRONG" && node.textContent.trim().indexOf(first.textContent.trim()) === 0;
      var isQuestionH = node.tagName === "H3";
      if (isQuestionP || isQuestionH) {
        var q = (isQuestionH ? node : first).textContent.replace(/^\s*Q\s*[:.]\s*/i, "").trim();
        var answer = document.createElement("div");
        if (isQuestionP) {
          var clone = node.cloneNode(true);
          clone.removeChild(clone.firstElementChild);
          var html = clone.innerHTML.replace(/^\s*(<br\s*\/?>\s*)*/i, "").replace(/^\s*A\s*[:.]\s*/i, "").trim();
          if (html)
            answer.innerHTML = "<p>" + html + "</p>";
        }
        current = { q, a: answer };
        items.push(current);
        consumed.push(node);
      } else if (current && !isCtaLike(node) && !/^\s*(#\w+\s*)+$/.test(node.textContent)) {
        var p = node.cloneNode(true);
        if (node.tagName === "P")
          p.innerHTML = p.innerHTML.replace(/^\s*A\s*[:.]\s*/i, "");
        current.a.appendChild(p);
        consumed.push(node);
      } else {
        break;
      }
      node = node.nextElementSibling;
    }
    if (items.length < 2)
      return;
    var box = document.createElement("div");
    box.className = "rd-faq";
    items.forEach(function(item, i) {
      var id = "rd-faq-a-" + i;
      var wrap = document.createElement("div");
      wrap.className = "rd-faq__item";
      var btn = document.createElement("button");
      btn.type = "button";
      btn.className = "rd-faq__q";
      btn.setAttribute("aria-controls", id);
      btn.innerHTML = '<span></span><span class="rd-faq__icon" aria-hidden="true"></span>';
      btn.firstChild.textContent = item.q;
      item.a.className = "rd-faq__a";
      item.a.id = id;
      wrap.appendChild(btn);
      wrap.appendChild(item.a);
      box.appendChild(wrap);
    });
    consumed[0].parentNode.insertBefore(box, consumed[0]);
    consumed.forEach(function(n) {
      n.parentNode.removeChild(n);
    });
    var wraps = [].slice.call(box.children);
    function open(index) {
      wraps.forEach(function(w, i) {
        var isOpen = i === index;
        w.querySelector(".rd-faq__a").hidden = !isOpen;
        w.querySelector(".rd-faq__q").setAttribute("aria-expanded", String(isOpen));
        w.querySelector(".rd-faq__icon").textContent = isOpen ? "\u2212" : "+";
      });
    }
    wraps.forEach(function(w, i) {
      w.querySelector(".rd-faq__q").addEventListener("click", function() {
        open(this.getAttribute("aria-expanded") === "true" ? -1 : i);
      });
    });
    open(0);
  }
  function enhanceTail(prose) {
    var author = null;
    var last = prose.lastElementChild;
    if (last && last.tagName === "P" && /^\s*written by\b/i.test(last.textContent)) {
      author = last;
      prose.removeChild(last);
      author.className = "rd-author";
    }
    processTail(prose);
    if (author)
      prose.appendChild(author);
  }
  function processTail(prose) {
    var children = [].slice.call(prose.children);
    for (var i = children.length - 1; i >= 0; i--) {
      var el = children[i];
      var text = el.textContent.trim();
      if (el.tagName === "HR" || /^(#[A-Za-z]\w*\s*)+$/.test(text) || !text) {
        prose.removeChild(el);
        continue;
      }
      if (isCtaLike(el)) {
        var strong = el.querySelector("strong");
        var titleEl = document.querySelector("[data-cta-title]");
        var title = strong ? strong.textContent.trim() : text.split(/(?<=\?)\s/)[0];
        if (titleEl && title && title.length < 120)
          titleEl.textContent = title;
        prose.removeChild(el);
      }
      break;
    }
  }
  function buildToc(prose) {
    var toc = document.getElementById("rd-toc");
    if (!toc)
      return;
    var headings = [].slice.call(prose.querySelectorAll(":scope > h2[id]"));
    if (!headings.length)
      return;
    var nav = toc.querySelector(".rd-toc__nav");
    var links = headings.map(function(h) {
      var a = document.createElement("a");
      a.href = "#" + h.id;
      a.textContent = h.textContent.replace(/\s*[-–—:]\s*Frequently Asked Questions.*$/i, "").trim();
      nav.appendChild(a);
      return a;
    });
    toc.hidden = false;
    var ticking = false;
    function update() {
      ticking = false;
      var active = -1;
      headings.forEach(function(h, i) {
        if (h.getBoundingClientRect().top < window.innerHeight * 0.35)
          active = i;
      });
      links.forEach(function(a, i) {
        a.classList.toggle("is-active", i === active);
      });
    }
    window.addEventListener(
      "scroll",
      function() {
        if (!ticking) {
          ticking = true;
          window.requestAnimationFrame(update);
        }
      },
      { passive: true }
    );
    update();
  }
  function initArticle() {
    var prose = document.getElementById("rd-prose");
    if (!prose)
      return;
    enhanceTail(prose);
    enhanceNotes(prose);
    enhanceTables(prose);
    enhanceKeyItems(prose);
    enhanceFaq(prose);
    buildToc(prose);
  }
  function formatUsd(n) {
    return Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  }
  function initLicenses() {
    var tabs = [].slice.call(document.querySelectorAll(".rd-tab[data-tab]"));
    var panels = [].slice.call(document.querySelectorAll(".rd-lic-panel[data-panel]"));
    function show(key, updateHash) {
      if (!panels.some(function(p) {
        return p.getAttribute("data-panel") === key;
      }))
        return;
      panels.forEach(function(p) {
        p.hidden = p.getAttribute("data-panel") !== key;
      });
      tabs.forEach(function(t) {
        var on = t.getAttribute("data-tab") === key;
        t.classList.toggle("is-active", on);
        t.setAttribute("aria-selected", String(on));
      });
      if (updateHash)
        history.replaceState(null, "", "#" + key);
    }
    tabs.forEach(function(t) {
      t.addEventListener("click", function() {
        show(t.getAttribute("data-tab"), true);
      });
    });
    if (window.location.hash)
      show(window.location.hash.slice(1), false);
    [].slice.call(document.querySelectorAll("[data-license]")).forEach(function(card) {
      var base = parseFloat(card.getAttribute("data-base")) || 0;
      var support = parseFloat(card.getAttribute("data-support")) || 0;
      var consulting = parseFloat(card.getAttribute("data-consulting")) || 0;
      var sup = card.querySelector('[data-addon="support"]');
      var con = card.querySelector('[data-addon="consulting"]');
      var total = card.querySelector("[data-total]");
      var cart = card.querySelector("[data-cart]");
      var cartBase = cart.getAttribute("href");
      function update() {
        var href = cartBase;
        var sum = base;
        if (sup.checked) {
          href += "&paidSupport=true";
          sum += support;
        }
        if (con.checked) {
          href += "&paidConsulting=true";
          sum += consulting;
        }
        cart.href = href;
        total.textContent = formatUsd(sum);
        sup.closest(".rd-addon").classList.toggle("is-checked", sup.checked);
        con.closest(".rd-addon").classList.toggle("is-checked", con.checked);
      }
      sup.addEventListener("change", update);
      con.addEventListener("change", update);
      update();
    });
    document.addEventListener("click", function(e) {
      if (e.target.closest && e.target.closest(".rd-tip"))
        e.preventDefault();
    });
  }
  document.addEventListener("DOMContentLoaded", function() {
    initLicenses();
    initPlatformSelects();
    initProductSearch();
    initKnowledgebase();
    initArticle();
  });

  // <stdin>
  document.addEventListener("DOMContentLoaded", function() {
    var tabList = [].slice.call(document.querySelectorAll("#myTab a"));
    tabList.forEach(function(tab) {
      var tabTrigger = new bootstrap.Tab(tab);
      tab.addEventListener("click", function(event) {
        event.preventDefault();
        tabTrigger.show();
      });
    });
  });
  var tooltipTriggerList = document.querySelectorAll(
    '[data-bs-toggle="tooltip"]'
  );
  var tooltipList = [...tooltipTriggerList].map(
    (tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl)
  );
  var cardElements = document.getElementsByClassName("card");
  document.addEventListener("DOMContentLoaded", function() {
    var supportCheckboxes = document.querySelectorAll("[id^='checkSupport_']");
    var consultingCheckboxes = document.querySelectorAll(
      "[id^='checkConsulting_']"
    );
    function updateLinkHref(ppId) {
      var supportCheckbox = document.getElementById("checkSupport_" + ppId);
      var consultingCheckbox = document.getElementById("checkConsulting_" + ppId);
      var basePrice = parseFloat(supportCheckbox.getAttribute("data-base-price"));
      var supportPrice = parseFloat(
        supportCheckbox.getAttribute("data-support-price")
      );
      var link = document.getElementById("myLink_" + ppId);
      var totalPriceElement = document.getElementById("totalPrice_" + ppId);
      var baseHref = "https://purchase.conholdate.com/buy/cart?ppId=" + ppId;
      var totalPrice = basePrice;
      if (supportCheckbox.checked) {
        baseHref += "&paidSupport=true";
        totalPrice += supportPrice;
      }
      if (consultingCheckbox.checked) {
        baseHref += "&paidConsulting=true";
        totalPrice += 5999;
      }
      link.href = baseHref;
      totalPriceElement.innerText = totalPrice.toFixed(0);
    }
    supportCheckboxes.forEach(function(checkbox) {
      checkbox.addEventListener("change", function() {
        updateLinkHref(checkbox.getAttribute("data-pp-id"));
      });
      updateLinkHref(checkbox.getAttribute("data-pp-id"));
    });
    consultingCheckboxes.forEach(function(checkbox) {
      checkbox.addEventListener("change", function() {
        updateLinkHref(checkbox.getAttribute("data-pp-id"));
      });
      updateLinkHref(checkbox.getAttribute("data-pp-id"));
    });
  });
  document.addEventListener("DOMContentLoaded", function() {
    var tabLinks = document.querySelectorAll(".nav-link");
    tabLinks.forEach(function(tabLink) {
      tabLink.addEventListener("click", function(event) {
        event.preventDefault();
        var tabId = this.getAttribute("href");
        document.querySelector(tabId).classList.add("show", "active");
        var tabContents = document.querySelectorAll(".tab-pane");
        tabContents.forEach(function(tabContent) {
          if ("#" + tabContent.getAttribute("id") !== tabId) {
            tabContent.classList.remove("show", "active");
          }
        });
        history.pushState(null, null, tabId);
      });
    });
    var hash = window.location.hash;
    if (hash) {
      var hashLink = document.querySelector('.nav-link[href="' + hash + '"]');
      if (hashLink)
        hashLink.click();
    }
  });
})();
