var __classPrivateFieldGet = (this && this.__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;
import { Host, h } from "@stencil/core";
import { partsExports } from "../../utils/partsExports";
/**
 * Button that is placed on the site to start a product query session
 *
 * @csspart product-query-open-button Button that opens the popup
 *
 * @slot before-button-text - Before origin button text
 * @slot after-button-text - After origin button text
 * @slot after-fineprint - After fineprint in the popup
 */
export class KlevuProductQuery {
  constructor() {
    _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: partsExports("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: partsExports("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" }))))));
  }
  static get is() { return "klevu-product-query"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-product-query.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-product-query.css"]
    };
  }
  static get properties() {
    return {
      "url": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Url of the page where the product is"
        },
        "attribute": "url",
        "reflect": false,
        "defaultValue": "\"\""
      },
      "productId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Alternative to url, productId can be used to start a session"
        },
        "attribute": "product-id",
        "reflect": false
      },
      "pqaWidgetId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Instead of Klevu API-key use a widget id to start a session"
        },
        "attribute": "pqa-widget-id",
        "reflect": false
      },
      "textFieldVariant": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "KlevuTextfieldVariant",
          "resolved": "\"default\" | \"pill\"",
          "references": {
            "KlevuTextfieldVariant": {
              "location": "import",
              "path": "../klevu-textfield/klevu-textfield",
              "id": "src/components/klevu-textfield/klevu-textfield.tsx::KlevuTextfieldVariant"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Variant of the textfield how does it look like"
        },
        "attribute": "text-field-variant",
        "reflect": false,
        "defaultValue": "\"pill\""
      },
      "textFieldPlaceholder": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Placeholder of the textfield"
        },
        "attribute": "text-field-placeholder",
        "reflect": false,
        "defaultValue": "\"Ask a questions\""
      },
      "popupTitle": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Title of the popup"
        },
        "attribute": "popup-title",
        "reflect": false,
        "defaultValue": "\"Ask a Question\""
      },
      "buttonText": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Text of the button to open the popup"
        },
        "attribute": "button-text",
        "reflect": false,
        "defaultValue": "\"Ask a Question\""
      },
      "finePrint": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Fine print of the popup under the title"
        },
        "attribute": "fine-print",
        "reflect": false,
        "defaultValue": "\"I'm an AI model. Sometimes, I may make mistakes. Please verify answers on the product page.\""
      },
      "askButtonText": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Text of the button for asking a question"
        },
        "attribute": "ask-button-text",
        "reflect": false
      },
      "useBackground": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Use dark background with the popup"
        },
        "attribute": "use-background",
        "reflect": false
      },
      "popupAnchor": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "Placement",
          "resolved": "\"bottom\" | \"bottom-end\" | \"bottom-start\" | \"left\" | \"left-end\" | \"left-start\" | \"right\" | \"right-end\" | \"right-start\" | \"top\" | \"top-end\" | \"top-start\"",
          "references": {
            "Placement": {
              "location": "import",
              "path": "@floating-ui/dom",
              "id": ""
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Anchor popup to which side of the origin"
        },
        "attribute": "popup-anchor",
        "reflect": false,
        "defaultValue": "\"bottom-start\""
      },
      "popupOffset": {
        "type": "number",
        "mutable": false,
        "complexType": {
          "original": "number",
          "resolved": "number",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "How many pixels to offset the popup from origin"
        },
        "attribute": "popup-offset",
        "reflect": false,
        "defaultValue": "5"
      },
      "disableCloseOutsideClick": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Disable closing the popup when clicking outside of it"
        },
        "attribute": "disable-close-outside-click",
        "reflect": false
      },
      "settings": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "MoiRequest[\"klevuSettings\"]",
          "resolved": "undefined | { offset?: number | undefined; excludeIds?: { key: string; value: string; }[] | undefined; typeOfSearch?: KlevuTypeOfSearch | undefined; advancedSorting?: { type: \"FIELD\"; key: string; order: AdvancedSortingDiretion; }[] | undefined; personalisation?: { enablePersonalisation: true; fields?: KlevuRecordFields[] | undefined; } | undefined; groupBy?: \"name\" | \"id\" | undefined; typeOfRecords?: KlevuAnyTypeOfRecord[] | undefined; fields?: KlevuRecordFields[] | undefined; sort?: KlevuSearchSorting | undefined; limit?: number | undefined; searchPrefs?: KlevuSearchPreference[] | undefined; fallbackQueryId?: string | undefined; fallbackWhenCountLessThan?: number | undefined; topIds?: { key: string; value: string; }[] | undefined; includeIds?: { key: string; value: string; }[] | undefined; customANDQuery?: string | undefined; context?: { recentObjects?: { typeOfRecord: KlevuAnyTypeOfRecord; records: { id: string; }[]; }[] | undefined; sourceObjects?: { typeOfRecord: KlevuAnyTypeOfRecord; records: ({ itemGroupId: string; } | { id: string; } | { url: string; })[]; }[] | undefined; } | undefined; priceFieldSuffix?: string | undefined; visibilityGroupID?: string | undefined; campaignForCatNav?: string | undefined; groupCondition?: KlevuGroupConditions | undefined; }",
          "references": {
            "MoiRequest": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::MoiRequest"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Settings for requests to Klevu. Deeper modification on how the product query works."
        }
      },
      "useNativeScrollbars": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Use native scrollbars instead of custom ones"
        },
        "attribute": "use-native-scrollbars",
        "reflect": false
      }
    };
  }
  static get states() {
    return {
      "origin": {},
      "isEnabled": {},
      "config": {}
    };
  }
  static get elementRef() { return "el"; }
}
_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";
};
//# sourceMappingURL=klevu-product-query.js.map
