'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-85d13173.js');
const partsExports = require('./partsExports-8da45cd3.js');

const klevuProductQueryCss = ":host{display:inline-block}:host([embedded]){width:var(--klevu-product-query-popup-width, 100%)}";

var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a getter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _KlevuProductQuery_instances, _KlevuProductQuery_checkIsPQAEnabled, _KlevuProductQuery_renderChatWindow;
const KlevuProductQuery = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    _KlevuProductQuery_instances.add(this);
    this.origin = undefined;
    this.isEnabled = false;
    this.removeAskloBranding = false;
    this.config = undefined;
    this.url = "";
    this.additionaldata = "";
    this.productId = undefined;
    this.pqaWidgetId = undefined;
    this.textFieldVariant = "pill";
    this.textFieldPlaceholder = "Enter your question here...";
    this.pqaWidgetLayout = "popup";
    this.popupTitle = this.pqaWidgetLayout === "popup" ? "Ask a Question" : "Live FAQs";
    this.buttonText = "Ask Product AI";
    this.finePrint = "";
    this.askButtonText = undefined;
    this.useBackground = undefined;
    this.popupAnchor = "bottom-start";
    this.popupOffset = 5;
    this.disableCloseOutsideClick = undefined;
    this.settings = undefined;
    this.useNativeScrollbars = undefined;
    this.productInfoGenerator = undefined;
    this.itemId = undefined;
    this.itemGroupId = undefined;
    this.itemVariantId = undefined;
    this.channelId = undefined;
    this.locale = undefined;
    this.hideEmbeddedTitle = false;
  }
  async connectedCallback() {
    var _a;
    this.config = await ((_a = this.el.closest("klevu-init")) === null || _a === void 0 ? void 0 : _a.getConfig());
    __classPrivateFieldGet(this, _KlevuProductQuery_instances, "m", _KlevuProductQuery_checkIsPQAEnabled).call(this);
  }
  render() {
    if (!this.isEnabled) {
      return null;
    }
    return this.pqaWidgetLayout === "popup" ? (index.h(index.Host, null, index.h("klevu-button", { ref: (el) => (this.origin = el), part: "klevu-query-open-button", exportparts: partsExports.partsExports("klevu-button") }, index.h("slot", { name: "before-button-text" }), this.buttonText, index.h("slot", { name: "after-button-text" })), index.h("klevu-util-portal", null, __classPrivateFieldGet(this, _KlevuProductQuery_instances, "m", _KlevuProductQuery_renderChatWindow).call(this)))) : (index.h(index.Host, { embedded: true }, __classPrivateFieldGet(this, _KlevuProductQuery_instances, "m", _KlevuProductQuery_renderChatWindow).call(this)));
  }
  get el() { return index.getElement(this); }
};
_KlevuProductQuery_instances = new WeakSet(), _KlevuProductQuery_checkIsPQAEnabled = async function _KlevuProductQuery_checkIsPQAEnabled() {
  var _a;
  if (!this.pqaWidgetId) {
    this.isEnabled = true;
    return;
  }
  const res = await window.fetch(`${(_a = this.config) === null || _a === void 0 ? void 0 : _a.moiApiUrl}chat/status?pqaWidgetId=${this.pqaWidgetId}`);
  const configJSON = await res.json();
  this.isEnabled = configJSON.status === "UNKNOWN" || configJSON.status === "ENABLED";
  this.removeAskloBranding = configJSON.removeAskloBranding || false;
}, _KlevuProductQuery_renderChatWindow = function _KlevuProductQuery_renderChatWindow() {
  return (index.h("klevu-product-query-popup", { additionaldata: this.additionaldata || "", url: this.url, productId: this.productId || this.itemId, pqaWidgetId: this.pqaWidgetId, tFinePrint: this.finePrint, tPopupTitle: this.popupTitle, tTextFieldPlaceholder: this.textFieldPlaceholder, askButtonText: this.askButtonText, settings: this.settings, popupAnchor: this.popupAnchor, popupOffset: this.popupOffset, exportparts: partsExports.partsExports("klevu-product-query-popup"), useBackground: this.useBackground, originElement: this.origin, disableCloseOutsideClick: this.disableCloseOutsideClick, config: this.config, useNativeScrollbars: this.useNativeScrollbars, itemId: this.itemId, itemVariantId: this.itemVariantId, itemGroupId: this.itemGroupId, channelId: this.channelId, locale: this.locale, productInfoGenerator: this.productInfoGenerator, textFieldVariant: this.textFieldVariant, pqaWidgetLayout: this.pqaWidgetLayout, removeAskloBranding: this.removeAskloBranding, hideEmbeddedTitle: this.hideEmbeddedTitle }, index.h("slot", { name: "after-fineprint", slot: "after-fineprint" })));
};
KlevuProductQuery.style = klevuProductQueryCss;

exports.klevu_product_query = KlevuProductQuery;

//# sourceMappingURL=klevu-product-query.cjs.entry.js.map