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, _KlevuProductQuery_renderChatWindow;
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.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" ? (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" })), h("klevu-util-portal", null, __classPrivateFieldGet(this, _KlevuProductQuery_instances, "m", _KlevuProductQuery_renderChatWindow).call(this)))) : (h(Host, { embedded: true }, __classPrivateFieldGet(this, _KlevuProductQuery_instances, "m", _KlevuProductQuery_renderChatWindow).call(this)));
  }
  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": "\"\""
      },
      "additionaldata": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "additionaldata",
        "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": "\"Enter your question here...\""
      },
      "pqaWidgetLayout": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "WidgetLayout",
          "resolved": "\"embedded\" | \"popup\"",
          "references": {
            "WidgetLayout": {
              "location": "local",
              "path": "/home/runner/work/frontend-sdk/frontend-sdk/packages/klevu-ui/src/components/klevu-product-query/klevu-product-query.tsx",
              "id": "src/components/klevu-product-query/klevu-product-query.tsx::WidgetLayout"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Set to false if you want to show the popup in place instead of dialog box"
        },
        "attribute": "pqa-widget-layout",
        "reflect": false,
        "defaultValue": "\"popup\""
      },
      "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": "this.pqaWidgetLayout === \"popup\" ? \"Ask a Question\" : \"Live FAQs\""
      },
      "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 Product AI\""
      },
      "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": "\"\""
      },
      "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
      },
      "productInfoGenerator": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string | (() => ProductInfo)",
          "resolved": "(() => ProductInfo) | string | undefined",
          "references": {
            "ProductInfo": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::ProductInfo"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "returns",
              "text": "ProductInfo object"
            }],
          "text": "Pass function to call that will return the product info\neg: pass function call as string - \"getProductInfo()\" or function itself"
        },
        "attribute": "product-info-generator",
        "reflect": false
      },
      "itemId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Product Id to be used in analytics"
        },
        "attribute": "item-id",
        "reflect": false
      },
      "itemGroupId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Product Group Id to be used in analytics, in case of multiple variants"
        },
        "attribute": "item-group-id",
        "reflect": false
      },
      "itemVariantId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Optional Product Variant Id to be used in analytics"
        },
        "attribute": "item-variant-id",
        "reflect": false
      },
      "channelId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Channel Id to be used in analytics\neg: Shopify, BigCommerce"
        },
        "attribute": "channel-id",
        "reflect": false
      },
      "locale": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Locale to be used in analytics\neg: en_US"
        },
        "attribute": "locale",
        "reflect": false
      },
      "hideEmbeddedTitle": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Set to true if you want to hide the embedded title"
        },
        "attribute": "hide-embedded-title",
        "reflect": false,
        "defaultValue": "false"
      }
    };
  }
  static get states() {
    return {
      "origin": {},
      "isEnabled": {},
      "removeAskloBranding": {},
      "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 configJSON = await res.json();
  this.isEnabled = configJSON.status === "UNKNOWN" || configJSON.status === "ENABLED";
  this.removeAskloBranding = configJSON.removeAskloBranding || false;
}, _KlevuProductQuery_renderChatWindow = function _KlevuProductQuery_renderChatWindow() {
  return (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("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 }, h("slot", { name: "after-fineprint", slot: "after-fineprint" })));
};
//# sourceMappingURL=klevu-product-query.js.map
