'use strict';

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

const index = require('./index-97fdbb7d.js');
const parts = require('./parts-295eb56e.js');

const klevuProductQueryCss = ":host{display:inline-block}";

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;
const KlevuProductQuery = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    _KlevuProductQuery_instances.add(this);
    this.origin = undefined;
    this.isEnabled = false;
    this.config = undefined;
    this.url = "";
    this.productId = undefined;
    this.pqaWidgetId = undefined;
    this.textFieldVariant = "pill";
    this.textFieldPlaceholder = "Ask a questions";
    this.popupTitle = "Ask a Question";
    this.buttonText = "Ask a Question";
    this.finePrint = "I'm an AI model. Sometimes, I may make mistakes. Please verify answers on the product page.";
    this.askButtonText = undefined;
    this.useBackground = undefined;
    this.popupAnchor = "bottom-start";
    this.popupOffset = 5;
    this.disableCloseOutsideClick = undefined;
    this.settings = undefined;
    this.useNativeScrollbars = undefined;
  }
  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 (index.h(index.Host, null, index.h("klevu-button", { ref: (el) => (this.origin = el), part: "klevu-query-open-button", exportparts: parts.parts["klevu-button"] }, index.h("slot", { name: "before-button-text" }), this.buttonText, index.h("slot", { name: "after-button-text" })), this.origin && (index.h("klevu-util-portal", null, index.h("klevu-product-query-popup", { url: this.url, productId: this.productId, 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: parts.parts["klevu-product-query-popup"], useBackground: this.useBackground, originElement: this.origin, disableCloseOutsideClick: this.disableCloseOutsideClick, config: this.config, useNativeScrollbars: this.useNativeScrollbars }, index.h("slot", { name: "after-fineprint", slot: "after-fineprint" }))))));
  }
  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 statusJSON = await res.json();
  this.isEnabled = statusJSON.status === "UNKNOWN" || statusJSON.status === "ENABLED";
};
KlevuProductQuery.style = klevuProductQueryCss;

exports.klevu_product_query = KlevuProductQuery;

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