import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { p as parts, d as defineCustomElement$9 } from './klevu-product2.js';
import { d as defineCustomElement$g } from './klevu-button2.js';
import { d as defineCustomElement$f } from './klevu-chat-bubble2.js';
import { d as defineCustomElement$e } from './klevu-chat-layout2.js';
import { d as defineCustomElement$d } from './klevu-chat-messages2.js';
import { d as defineCustomElement$c } from './klevu-icon2.js';
import { d as defineCustomElement$b } from './klevu-loading-indicator2.js';
import { d as defineCustomElement$a } from './klevu-popup2.js';
import { d as defineCustomElement$8 } from './klevu-product-query-popup2.js';
import { d as defineCustomElement$7 } from './klevu-rating2.js';
import { d as defineCustomElement$6 } from './klevu-slides2.js';
import { d as defineCustomElement$5 } from './klevu-textfield2.js';
import { d as defineCustomElement$4 } from './klevu-typography2.js';
import { d as defineCustomElement$3 } from './klevu-util-portal2.js';
import { d as defineCustomElement$2 } from './klevu-util-scrollbars2.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$1 = /*@__PURE__*/ proxyCustomElement(class KlevuProductQuery extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    _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 (h(Host, null, h("klevu-button", { ref: (el) => (this.origin = el), part: "klevu-query-open-button", exportparts: parts["klevu-button"] }, h("slot", { name: "before-button-text" }), this.buttonText, h("slot", { name: "after-button-text" })), this.origin && (h("klevu-util-portal", null, 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["klevu-product-query-popup"], useBackground: this.useBackground, originElement: this.origin, disableCloseOutsideClick: this.disableCloseOutsideClick, config: this.config, useNativeScrollbars: this.useNativeScrollbars }, h("slot", { name: "after-fineprint", slot: "after-fineprint" }))))));
  }
  get el() { return this; }
  static get style() { return klevuProductQueryCss; }
}, [1, "klevu-product-query", {
    "url": [1],
    "productId": [1, "product-id"],
    "pqaWidgetId": [1, "pqa-widget-id"],
    "textFieldVariant": [1, "text-field-variant"],
    "textFieldPlaceholder": [1, "text-field-placeholder"],
    "popupTitle": [1, "popup-title"],
    "buttonText": [1, "button-text"],
    "finePrint": [1, "fine-print"],
    "askButtonText": [1, "ask-button-text"],
    "useBackground": [4, "use-background"],
    "popupAnchor": [1, "popup-anchor"],
    "popupOffset": [2, "popup-offset"],
    "disableCloseOutsideClick": [4, "disable-close-outside-click"],
    "settings": [16],
    "useNativeScrollbars": [4, "use-native-scrollbars"],
    "origin": [32],
    "isEnabled": [32],
    "config": [32]
  }]);
_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";
};
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["klevu-product-query", "klevu-button", "klevu-chat-bubble", "klevu-chat-layout", "klevu-chat-messages", "klevu-icon", "klevu-loading-indicator", "klevu-popup", "klevu-product", "klevu-product-query-popup", "klevu-rating", "klevu-slides", "klevu-textfield", "klevu-typography", "klevu-util-portal", "klevu-util-scrollbars"];
  components.forEach(tagName => { switch (tagName) {
    case "klevu-product-query":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, KlevuProductQuery$1);
      }
      break;
    case "klevu-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$g();
      }
      break;
    case "klevu-chat-bubble":
      if (!customElements.get(tagName)) {
        defineCustomElement$f();
      }
      break;
    case "klevu-chat-layout":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "klevu-chat-messages":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "klevu-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "klevu-loading-indicator":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "klevu-popup":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "klevu-product":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "klevu-product-query-popup":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "klevu-rating":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "klevu-slides":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "klevu-textfield":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "klevu-typography":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "klevu-util-portal":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "klevu-util-scrollbars":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const KlevuProductQuery = KlevuProductQuery$1;
const defineCustomElement = defineCustomElement$1;

export { KlevuProductQuery, defineCustomElement };

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