(function () {
  "use strict";

  var config = window.modeloraConfig || {};
  var moduleUrl = config.modelViewerUrl || (config.pluginUrl ? config.pluginUrl + "assets/js/model-viewer.min.js" : '/wp-content/plugins/modelora-3d-product-viewer/assets/js/model-viewer.min.js');

  if (!moduleUrl) {
    if (window.console && typeof window.console.warn === 'function') {
      window.console.warn('[MODELORA] model-viewer module URL not configured.');
    }
    return;
  }

  function safeImport(url) {
    try {
      return import(url).catch(function (error) {
        if (window.console && typeof window.console.error === 'function') {
          window.console.error('[MODELORA] Failed to import model-viewer module via import():', url, error);
        }
        return new Promise(function (resolve) {
          var script = document.createElement('script');
          script.type = 'module';
          script.src = url;
          script.onload = function () {
            resolve(true);
          };
          script.onerror = function (e) {
            if (window.console && typeof window.console.error === 'function') {
              window.console.error('[MODELORA] module script fallback failed for', url, e);
            }
            resolve(false);
          };
          (document.head || document.documentElement).appendChild(script);
        });
      });
    } catch (e) {
      if (window.console && typeof window.console.error === 'function') {
        window.console.error('[MODELORA] import() threw synchronously for', url, e);
      }
      try {
        var script = document.createElement('script');
        script.type = 'module';
        script.src = url;
        (document.head || document.documentElement).appendChild(script);
      } catch (e2) {
        if (window.console && typeof window.console.error === 'function') {
          window.console.error('[MODELORA] failed to inject module script fallback for', url, e2);
        }
      }
      return Promise.resolve(false);
    }
  }

  if (window.customElements && window.customElements.get('model-viewer')) {
    return;
  }

  moduleUrl = String(moduleUrl);

  safeImport(moduleUrl).then(function (loaded) {
    if (!loaded && window.console && typeof window.console.warn === 'function') {
      window.console.warn('[MODELORA] model-viewer may not have loaded successfully:', moduleUrl);
    }
  });
})();