(function (window, document) {
  var cfg = window.flexilayAdminCrisp || {};
  if (!cfg.websiteId || document.getElementById('flexilay-crisp-loader')) {
    return;
  }

  window.$crisp = window.$crisp || [];
  window.CRISP_WEBSITE_ID = cfg.websiteId;
  if (cfg.themeColor) {
    window.CRISP_THEME_COLOR = cfg.themeColor;
  }

  if (cfg.shopDomain) {
    try { window.$crisp.push(["set", "session:data", [["shop_domain", cfg.shopDomain]]]); } catch (e) {}
    try { window.$crisp.push(["set", "session:segments", [cfg.shopDomain]]); } catch (e) {}
  }

  var script = document.createElement('script');
  script.id = 'flexilay-crisp-loader';
  script.src = 'https://client.crisp.chat/l.js';
  script.async = true;
  document.head.appendChild(script);
})(window, document);
