'use strict';

/**
 * Render given price with browsers own currency format.
 *
 * @param amount
 * @param currency
 * @returns formatted price
 */
function renderPrice(amount, currency) {
  var _a;
  // @ts-expect-error
  if ((_a = window === null || window === void 0 ? void 0 : window["klevu_ui_settings"]) === null || _a === void 0 ? void 0 : _a.renderPrice) {
    // @ts-expect-error
    return window["klevu_ui_settings"].renderPrice(amount, currency);
  }
  const price = typeof amount === "string" ? parseFloat(amount) : amount;
  return new Intl.NumberFormat(undefined, { style: "currency", currency }).format(price);
}
/**
 * Run callback only if it hasn't been requested in last `delay` milliseconds.
 *
 * @param callback function to call
 * @param wait time to wait in milliseconds
 * @returns
 */
function debounce(callback, wait) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    return new Promise((resolve) => {
      timer = setTimeout(() => resolve(callback(...args)), wait);
    });
  };
}
/**
 * Strip html tags from string.
 *
 * @param html
 * @returns
 */
function stripTags(html) {
  if (!document) {
    return html;
  }
  const tmp = document.createElement("DIV");
  tmp.innerHTML = html;
  return tmp.textContent || tmp.innerText || "";
}
/**
 * List of css ::parts() that are exposed to the developers.
 *
 * Essentially this is list of css selectors that are exposed to the developers.
 * See global.css for the list of selectors.
 */
const globalExportedParts = ["klevu-list", "material-icon"].join(", ");
function getGlobalSettings() {
  if (window) {
    return Object.assign({ renderPrice }, window["klevu_ui_settings"]);
  }
  return undefined;
}

exports.debounce = debounce;
exports.getGlobalSettings = getGlobalSettings;
exports.globalExportedParts = globalExportedParts;
exports.renderPrice = renderPrice;
exports.stripTags = stripTags;

//# sourceMappingURL=utils-4717dffd.js.map