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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
  if (kind === "m")
    throw new TypeError("Private method is not writable");
  if (kind === "a" && !f)
    throw new TypeError("Private accessor was defined without a setter");
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
    throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _KlevuProductQueryPopup_instances, _KlevuProductQueryPopup_popup, _KlevuProductQueryPopup_layoutElement, _KlevuProductQueryPopup_contentDiv, _KlevuProductQueryPopup_disclaimer, _KlevuProductQueryPopup_sendMessage, _KlevuProductQueryPopup_register, _KlevuProductQueryPopup_pqafeedback, _KlevuProductQueryPopup_closeModal, _KlevuProductQueryPopup_fireProductInfoGenerator, _KlevuProductQueryPopup_start, _KlevuProductQueryPopup_onAction, _KlevuProductQueryPopup_onQuestionClick, _KlevuProductQueryPopup_onFeedback, _KlevuProductQueryPopup_onTypeWriterEffectEnds, _KlevuProductQueryPopup_productClick, _KlevuProductQueryPopup_renderChat, _KlevuProductQueryPopup_renderFeedback;
import { Fragment, Host, h } from "@stencil/core";
import { KlevuInit } from "../klevu-init/klevu-init";
import { startMoi, } from "@klevu/core";
import { getTranslation } from "../../utils/getTranslation";
import { partsExports } from "../../utils/partsExports";
/**
 * Klevu Product Query popup application that shows a popup for asking questions about a product
 *
 * @csspart product-query-popup-header Header of the popup
 * @csspart product-query-popup-footer Footer of the popup where input is
 * @csspart product-query-popup-feedback Feedback section of the popup when it is being closed
 *
 */
export class KlevuProductQueryPopup {
  constructor() {
    _KlevuProductQueryPopup_instances.add(this);
    _KlevuProductQueryPopup_popup.set(this, void 0);
    _KlevuProductQueryPopup_layoutElement.set(this, void 0);
    _KlevuProductQueryPopup_contentDiv.set(this, void 0);
    this.poweredByMessage = "Powered by ASKLO.";
    _KlevuProductQueryPopup_disclaimer.set(this, getTranslation("productQueryPopup.disclaimer")
    /**
     * Text of the button for asking a question
     */
    );
    this.url = "";
    this.productId = undefined;
    this.pqaWidgetId = undefined;
    this.textFieldVariant = "pill";
    this.tTextFieldPlaceholder = getTranslation("productQueryPopup.tTextFieldPlaceholder");
    this.tPopupTitle = getTranslation("productQueryPopup.tPopuptitle");
    this.tButtonText = getTranslation("productQueryPopup.tButtonText");
    this.tFinePrint = "";
    this.tLoadingSorry = getTranslation("productQueryPopup.tLoadingSorry");
    this.tAnswerError = getTranslation("productQueryPopup.tAnswerError");
    this.tRateExperienceTitle = getTranslation("productQueryPopup.tRateExperienceTitle");
    this.tRateExperienceText = getTranslation("productQueryPopup.tRateExperienceText");
    this.tDataProtectionNotice = getTranslation("productQueryPopup.tDataProtectionNotice");
    this.askButtonText = undefined;
    this.useBackground = undefined;
    this.popupAnchor = "bottom-start";
    this.popupOffset = undefined;
    this.settings = undefined;
    this.originElement = undefined;
    this.disableCloseOutsideClick = undefined;
    this.config = undefined;
    this.useNativeScrollbars = undefined;
    this.additionaldata = "";
    this.productInfoGenerator = undefined;
    this.itemId = undefined;
    this.itemGroupId = undefined;
    this.itemVariantId = undefined;
    this.channelId = undefined;
    this.locale = undefined;
    this.pqaWidgetLayout = "popup";
    this.removeAskloBranding = false;
    this.hideEmbeddedTitle = false;
    this.text = "";
    this.name = "";
    this.email = "";
    this.registered = true // change to false when registering works
    ;
    this.showFeedback = false;
    this.showLoading = false;
    this.showLoadingSorry = false;
    this.sendMessageError = false;
    this.feedbacks = [];
    this.showMessageFeedbackFor = undefined;
    this.messages = [];
    this.questions = [];
    this.hideQuestions = false;
  }
  async connectedCallback() {
    var _a, _b;
    await KlevuInit.ready();
    if (!this.productId) {
      this.productId = this.itemId;
    }
    if (!this.productId && ((_a = window.klevu_page_meta) === null || _a === void 0 ? void 0 : _a.itemId)) {
      this.productId = window.klevu_page_meta.itemId;
    }
    if (!this.productId && this.url == "") {
      const canonical = document.querySelector("link[rel='canonical']");
      this.url = (_b = canonical === null || canonical === void 0 ? void 0 : canonical.href) !== null && _b !== void 0 ? _b : window.location.href;
    }
    if (this.pqaWidgetLayout !== "popup") {
      __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_start).call(this);
    }
  }
  onMessage() {
    var _a;
    if (!this.session) {
      return;
    }
    this.messages = this.session.messages;
    this.feedbacks = this.session.feedbacks;
    this.questions = this.session.questions;
    (_a = __classPrivateFieldGet(this, _KlevuProductQueryPopup_layoutElement, "f")) === null || _a === void 0 ? void 0 : _a.scrollMainToBottom();
    this.sendMessageError = false;
  }
  async onMessageFeedback(e) {
    var _a, _b, _c;
    await ((_a = this.session) === null || _a === void 0 ? void 0 : _a.addFeedback(e.detail.feedback.id, e.detail.feedback.thumbs, e.detail.reason));
    this.feedbacks = ((_b = this.session) === null || _b === void 0 ? void 0 : _b.feedbacks) || [];
    this.messages = ((_c = this.session) === null || _c === void 0 ? void 0 : _c.messages) || [];
  }
  /** By default redirect the page if product click is not cancelled */
  onKlevuMoiProductClick(event) {
    setTimeout(() => {
      if (!event.defaultPrevented) {
        window.location.href = event.detail.url;
      }
    }, 1);
  }
  render() {
    return this.pqaWidgetLayout === "popup" ? (h(Host, null, h("klevu-popup", { ref: (el) => (__classPrivateFieldSet(this, _KlevuProductQueryPopup_popup, el, "f")), exportparts: partsExports("klevu-popup"), onKlevuPopupClose: __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_closeModal).bind(this), onKlevuPopupOpen: () => {
        __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_start).call(this);
      }, anchor: this.popupAnchor, offset: this.popupOffset, elevation: 3, useBackground: this.useBackground, originElement: this.originElement, closeAtOutsideClick: !this.disableCloseOutsideClick, fullscreenOnMobileSize: true }, h("div", { class: "content", slot: "content", ref: (el) => (__classPrivateFieldSet(this, _KlevuProductQueryPopup_contentDiv, el, "f")) }, this.showFeedback ? __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_renderFeedback).call(this) : __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_renderChat).call(this))))) : (h(Host, { embedded: true }, h("div", { class: "embedded" }, h("div", { class: "content", slot: "content", ref: (el) => (__classPrivateFieldSet(this, _KlevuProductQueryPopup_contentDiv, el, "f")) }, this.showFeedback ? __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_renderFeedback).call(this) : __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_renderChat).call(this, false)))));
  }
  static get is() { return "klevu-product-query-popup"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-product-query-popup.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-product-query-popup.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\""
      },
      "tTextFieldPlaceholder": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Placeholder of the textfield"
        },
        "attribute": "t-text-field-placeholder",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tTextFieldPlaceholder\")"
      },
      "tPopupTitle": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Title of the popup"
        },
        "attribute": "t-popup-title",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tPopuptitle\")"
      },
      "tButtonText": {
        "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": "t-button-text",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tButtonText\")"
      },
      "tFinePrint": {
        "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": "t-fine-print",
        "reflect": false,
        "defaultValue": "\"\""
      },
      "tLoadingSorry": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "When loading takes a bit longer, show this text"
        },
        "attribute": "t-loading-sorry",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tLoadingSorry\")"
      },
      "tAnswerError": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "When sending a message fails, show this text"
        },
        "attribute": "t-answer-error",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tAnswerError\")"
      },
      "tRateExperienceTitle": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Title of the feedback section when closing the popup"
        },
        "attribute": "t-rate-experience-title",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tRateExperienceTitle\")"
      },
      "tRateExperienceText": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Description of the feedback section when closing the popup"
        },
        "attribute": "t-rate-experience-text",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tRateExperienceText\")"
      },
      "tDataProtectionNotice": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Data protection notice when user registering is enabled"
        },
        "attribute": "t-data-protection-notice",
        "reflect": false,
        "defaultValue": "getTranslation(\"productQueryPopup.tDataProtectionNotice\")"
      },
      "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 | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "How many pixels to offset the popup from origin"
        },
        "attribute": "popup-offset",
        "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."
        }
      },
      "originElement": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "HTMLElement",
          "resolved": "HTMLElement | undefined",
          "references": {
            "HTMLElement": {
              "location": "global",
              "id": "global::HTMLElement"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Element to anchor the product query popup to"
        }
      },
      "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
      },
      "config": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "KlevuConfig",
          "resolved": "KlevuConfig | undefined",
          "references": {
            "KlevuConfig": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::KlevuConfig"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Config for Klevu"
        }
      },
      "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
      },
      "additionaldata": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string | undefined",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "Pass any additional data you would want the AI to use for context"
        },
        "attribute": "additionaldata",
        "reflect": false,
        "defaultValue": "\"\""
      },
      "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"
        },
        "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
      },
      "pqaWidgetLayout": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "WidgetLayout",
          "resolved": "\"embedded\" | \"popup\"",
          "references": {
            "WidgetLayout": {
              "location": "import",
              "path": "../klevu-product-query/klevu-product-query",
              "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 this in place instead of dialog box"
        },
        "attribute": "pqa-widget-layout",
        "reflect": false,
        "defaultValue": "\"popup\""
      },
      "removeAskloBranding": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": "Set to true if you want to remove the powered by ribbon"
        },
        "attribute": "remove-asklo-branding",
        "reflect": false,
        "defaultValue": "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 {
      "text": {},
      "name": {},
      "email": {},
      "registered": {},
      "showFeedback": {},
      "showLoading": {},
      "showLoadingSorry": {},
      "sendMessageError": {},
      "feedbacks": {},
      "showMessageFeedbackFor": {},
      "messages": {},
      "questions": {},
      "hideQuestions": {}
    };
  }
  static get events() {
    return [{
        "method": "klevuMoiProductClick",
        "name": "klevuMoiProductClick",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": ""
        },
        "complexType": {
          "original": "MoiProduct",
          "resolved": "{ id: string; currency: string; image: string; itemGroupId: string; name: string; noOfVariants: number; options: { chat: string; intent: string; name: string; }[]; originalContent: string | null; price: string; salePrice: string; shortDesc: string; url: string; }",
          "references": {
            "MoiProduct": {
              "location": "import",
              "path": "@klevu/core",
              "id": "../klevu-core/dist/cjs/index.d.ts::MoiProduct"
            }
          }
        }
      }];
  }
  static get elementRef() { return "el"; }
  static get listeners() {
    return [{
        "name": "klevuMessageFeedbackReason",
        "method": "onMessageFeedback",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "klevuMoiProductClick",
        "method": "onKlevuMoiProductClick",
        "target": undefined,
        "capture": false,
        "passive": false
      }];
  }
}
_KlevuProductQueryPopup_popup = new WeakMap(), _KlevuProductQueryPopup_layoutElement = new WeakMap(), _KlevuProductQueryPopup_contentDiv = new WeakMap(), _KlevuProductQueryPopup_disclaimer = new WeakMap(), _KlevuProductQueryPopup_instances = new WeakSet(), _KlevuProductQueryPopup_sendMessage = async function _KlevuProductQueryPopup_sendMessage(overrideMessageValue) {
  var _a, _b;
  const message = overrideMessageValue || this.text.trim();
  if (message == "") {
    return;
  }
  this.text = "";
  (_a = __classPrivateFieldGet(this, _KlevuProductQueryPopup_layoutElement, "f")) === null || _a === void 0 ? void 0 : _a.scrollMainToBottom();
  this.showLoading = true;
  const timeout = setTimeout(() => {
    this.showLoadingSorry = true;
  }, 4000);
  await ((_b = this.session) === null || _b === void 0 ? void 0 : _b.query({
    message: message,
    klevuSettings: this.settings,
  }, "send").catch((err) => {
    this.sendMessageError = true;
  }));
  clearTimeout(timeout);
  this.showLoadingSorry = false;
  this.showLoading = false;
}, _KlevuProductQueryPopup_register = function _KlevuProductQueryPopup_register() {
  var _a, _b;
  (_a = this.session) === null || _a === void 0 ? void 0 : _a.messages.push({
    message: {
      id: "register",
      type: "text",
      value: `${this.name}, (${this.email})`,
      note: null,
    },
  });
  this.registered = true;
  (_b = __classPrivateFieldGet(this, _KlevuProductQueryPopup_layoutElement, "f")) === null || _b === void 0 ? void 0 : _b.scrollMainToBottom();
}, _KlevuProductQueryPopup_pqafeedback = function _KlevuProductQueryPopup_pqafeedback(dir) {
  var _a;
  (_a = __classPrivateFieldGet(this, _KlevuProductQueryPopup_popup, "f")) === null || _a === void 0 ? void 0 : _a.closeModal();
}, _KlevuProductQueryPopup_closeModal = function _KlevuProductQueryPopup_closeModal(e) {
  /*
  if (!this.showFeedback) {
    this.showFeedback = true
    e.preventDefault()
    return
  }
  */
}, _KlevuProductQueryPopup_fireProductInfoGenerator = function _KlevuProductQueryPopup_fireProductInfoGenerator() {
  try {
    if (this.productInfoGenerator)
      return eval(this.productInfoGenerator);
  }
  catch (err) {
    console.error("Failed to generate product info, check function passed", err);
  }
  return undefined;
}, _KlevuProductQueryPopup_start = async function _KlevuProductQueryPopup_start() {
  var _a, _b, _c;
  this.showLoading = true;
  this.showFeedback = false;
  const useConfig = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.apiKey) && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiKey) !== "";
  const productInfo = this.productInfoGenerator
    ? typeof this.productInfoGenerator === "string"
      ? __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_fireProductInfoGenerator).call(this)
      : this.productInfoGenerator()
    : undefined;
  this.session = await startMoi({
    onMessage: this.onMessage.bind(this),
    // Do nothing on redirect as we have our own system
    onRedirect: () => { },
    url: this.url === "" ? undefined : this.url,
    productId: this.productId,
    mode: "PQA",
    onAction: __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_onAction).bind(this),
    pqaWidgetId: this.pqaWidgetId,
    additionalData: this.additionaldata,
    itemId: this.itemId,
    itemGroupId: this.itemGroupId,
    itemVariantId: this.itemVariantId,
    channelId: this.channelId,
    locale: this.locale,
    productInfo,
    settings: {
      configOverride: useConfig ? this.config : undefined,
      alwaysStartConversation: true,
    },
  });
  this.messages = this.session.messages;
  this.questions = this.session.questions;
  this.feedbacks = this.session.feedbacks;
  await ((_c = __classPrivateFieldGet(this, _KlevuProductQueryPopup_layoutElement, "f")) === null || _c === void 0 ? void 0 : _c.scrollMainToBottom("instant"));
  this.showLoading = false;
  // add this when registering works
  //this.registered = this.messages.length > 1
}, _KlevuProductQueryPopup_onAction = function _KlevuProductQueryPopup_onAction(action) {
  if (action.type !== "askFeedbackReason") {
    return;
  }
  this.showMessageFeedbackFor = action.context.messageId;
}, _KlevuProductQueryPopup_onQuestionClick = function _KlevuProductQueryPopup_onQuestionClick(question) {
  __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_sendMessage).call(this, question);
}, _KlevuProductQueryPopup_onFeedback = async function _KlevuProductQueryPopup_onFeedback(e) {
  var _a, _b;
  await ((_a = this.session) === null || _a === void 0 ? void 0 : _a.addFeedback(e.detail.message.id, e.detail.feedback));
  this.feedbacks = ((_b = this.session) === null || _b === void 0 ? void 0 : _b.feedbacks) || [];
}, _KlevuProductQueryPopup_onTypeWriterEffectEnds = function _KlevuProductQueryPopup_onTypeWriterEffectEnds(hideQuestions) {
  var _a;
  this.hideQuestions = hideQuestions;
  if (!hideQuestions) {
    (_a = __classPrivateFieldGet(this, _KlevuProductQueryPopup_layoutElement, "f")) === null || _a === void 0 ? void 0 : _a.scrollMainToBottom();
  }
}, _KlevuProductQueryPopup_productClick = async function _KlevuProductQueryPopup_productClick(product) {
  if (!this.session || !product.id || !product.url) {
    return;
  }
  await this.session.query({
    product: {
      id: product.id,
      context: {
        url: product.url,
      },
      intent: "redirect",
    },
  });
  this.klevuMoiProductClick.emit(product);
}, _KlevuProductQueryPopup_renderChat = function _KlevuProductQueryPopup_renderChat(popupMode = true) {
  return (h(Fragment, null, h("klevu-chat-layout", { originElement: this.originElement, exportparts: partsExports("klevu-chat-layout"), useNativeScrollbars: this.useNativeScrollbars, ref: (el) => (__classPrivateFieldSet(this, _KlevuProductQueryPopup_layoutElement, el, "f")) }, h("div", { part: "product-query-popup-header", slot: "header" }, h("div", { class: "header" }, (popupMode || !this.hideEmbeddedTitle) && (h("klevu-typography", { variant: "body-m-bold" }, this.tPopupTitle)), popupMode && (h("klevu-icon", { originElement: this.originElement, name: "close", id: "closeDialog", onClick: () => { var _a; return (_a = __classPrivateFieldGet(this, _KlevuProductQueryPopup_popup, "f")) === null || _a === void 0 ? void 0 : _a.closeModal(); } }))), h("div", { class: "fineprintContainer" }, this.tFinePrint && (h("klevu-typography", { variant: "body-xs", class: "fineprint" }, this.tFinePrint)), h("slot", { name: "after-fineprint" }))), h("div", { class: "chat-messages" }, h("klevu-chat-messages", { exportparts: partsExports("klevu-chat-messages"), messages: this.messages, feedbacks: this.feedbacks, enableMessageFeedback: true, onKlevuMessageFeedback: __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_onFeedback).bind(this), showFeedbackFor: this.showMessageFeedbackFor, handleTypeWriterEffectEnds: __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_onTypeWriterEffectEnds).bind(this), scrollBottom: () => { var _a; return (_a = __classPrivateFieldGet(this, _KlevuProductQueryPopup_layoutElement, "f")) === null || _a === void 0 ? void 0 : _a.scrollMainToBottom("instant"); }, onKlevuChatProductClick: (event) => {
      event.preventDefault();
      event.stopPropagation();
      __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_productClick).call(this, event.detail.product);
      return false;
    } }, h("div", { slot: "chat-messages-after" }, this.showLoading ? (h("klevu-loading-indicator", { exportparts: partsExports("klevu-loading-indicator") })) : null, this.showLoadingSorry ? (h("klevu-typography", { class: "loading-sorry", variant: "body-xs" }, this.tLoadingSorry)) : null, this.sendMessageError ? (h("klevu-typography", { class: "error-text", variant: "body-xs" }, h("klevu-icon", { name: "error", class: "error-icon" }), this.tAnswerError)) : null)), this.showLoading || this.hideQuestions ? null : (h("div", { class: "questions-container" }, this.questions.map((question, index) => (h("div", { role: "button", class: "klevu-question", onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_onQuestionClick).call(this, question), style: { animationDelay: `${0.4 * index}s` } }, h("svg", { width: "13", height: "13", viewBox: "0 0 13 13", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M4.49609 12.5352C4.44141 12.5352 4.39453 12.5176 4.35547 12.4824C4.32031 12.4512 4.30078 12.4102 4.29688 12.3594C4.24219 11.9688 4.1875 11.6641 4.13281 11.4453C4.08203 11.2266 3.99805 11.0625 3.88086 10.9531C3.76758 10.8398 3.5957 10.752 3.36523 10.6895C3.13477 10.627 2.81836 10.5586 2.41602 10.4844C2.29492 10.4609 2.23438 10.3945 2.23438 10.2852C2.23438 10.2305 2.25195 10.1855 2.28711 10.1504C2.32227 10.1152 2.36523 10.0938 2.41602 10.0859C2.81836 10.0312 3.13477 9.97656 3.36523 9.92188C3.5957 9.86328 3.76758 9.77734 3.88086 9.66406C3.99805 9.54688 4.08398 9.37695 4.13867 9.1543C4.19336 8.92773 4.24609 8.61523 4.29688 8.2168C4.3125 8.0957 4.37891 8.03516 4.49609 8.03516C4.61328 8.03516 4.67773 8.09766 4.68945 8.22266C4.74023 8.61328 4.79102 8.91797 4.8418 9.13672C4.89648 9.35547 4.98242 9.51953 5.09961 9.62891C5.2207 9.73828 5.39648 9.82422 5.62695 9.88672C5.85742 9.94531 6.17188 10.0117 6.57031 10.0859C6.69141 10.1094 6.75195 10.1758 6.75195 10.2852C6.75195 10.3945 6.68359 10.4609 6.54688 10.4844C6.14844 10.5469 5.83594 10.6074 5.60938 10.666C5.38281 10.7246 5.21094 10.8105 5.09375 10.9238C4.98047 11.0371 4.89648 11.2051 4.8418 11.4277C4.79102 11.6504 4.74023 11.957 4.68945 12.3477C4.67773 12.4727 4.61328 12.5352 4.49609 12.5352ZM1.71289 7.43164C1.66992 7.43164 1.63672 7.41992 1.61328 7.39648C1.58984 7.36914 1.57422 7.33594 1.56641 7.29688C1.51562 7.01953 1.46875 6.80078 1.42578 6.64062C1.38281 6.47656 1.32031 6.35156 1.23828 6.26562C1.15625 6.17578 1.0332 6.10742 0.869141 6.06055C0.705078 6.01367 0.476562 5.96484 0.183594 5.91406C0.09375 5.89844 0.0488281 5.84961 0.0488281 5.76758C0.0488281 5.68555 0.09375 5.63672 0.183594 5.62109C0.476562 5.57031 0.705078 5.52148 0.869141 5.47461C1.0332 5.42383 1.15625 5.35547 1.23828 5.26953C1.32031 5.18359 1.38281 5.06055 1.42578 4.90039C1.46875 4.73633 1.51562 4.51367 1.56641 4.23242C1.58203 4.14648 1.63086 4.10352 1.71289 4.10352C1.79102 4.10352 1.83789 4.14648 1.85352 4.23242C1.9043 4.51367 1.95117 4.73633 1.99414 4.90039C2.03711 5.06055 2.09961 5.18359 2.18164 5.26953C2.26367 5.35547 2.38672 5.42383 2.55078 5.47461C2.71484 5.52148 2.94531 5.57031 3.24219 5.62109C3.33203 5.63672 3.37695 5.68555 3.37695 5.76758C3.37695 5.84961 3.33203 5.89844 3.24219 5.91406C2.94531 5.96484 2.71484 6.01367 2.55078 6.06055C2.38672 6.10742 2.26367 6.17578 2.18164 6.26562C2.09961 6.35156 2.03711 6.47656 1.99414 6.64062C1.95117 6.80078 1.9043 7.01953 1.85352 7.29688C1.83789 7.38672 1.79102 7.43164 1.71289 7.43164ZM4.92383 3.68164C4.85742 3.68164 4.81641 3.64648 4.80078 3.57617C4.75391 3.3418 4.71094 3.1582 4.67188 3.02539C4.63281 2.88867 4.57812 2.78516 4.50781 2.71484C4.44141 2.64062 4.33984 2.58398 4.20312 2.54492C4.07031 2.50195 3.88086 2.45508 3.63477 2.4043C3.56055 2.39258 3.52344 2.35352 3.52344 2.28711C3.52344 2.2207 3.56055 2.17969 3.63477 2.16406C3.88086 2.11328 4.07031 2.06836 4.20312 2.0293C4.33984 1.98633 4.44141 1.92969 4.50781 1.85938C4.57812 1.78516 4.63281 1.68164 4.67188 1.54883C4.71094 1.41602 4.75391 1.23242 4.80078 0.998047C4.81641 0.923828 4.85742 0.886719 4.92383 0.886719C4.98633 0.886719 5.02539 0.923828 5.04102 0.998047C5.0918 1.23242 5.13477 1.41602 5.16992 1.54883C5.20898 1.68164 5.26172 1.78516 5.32812 1.85938C5.39844 1.92969 5.50195 1.98633 5.63867 2.0293C5.77539 2.06836 5.96484 2.11328 6.20703 2.16406C6.28125 2.17969 6.31836 2.2207 6.31836 2.28711C6.31836 2.35352 6.28125 2.39258 6.20703 2.4043C5.96484 2.45508 5.77539 2.50195 5.63867 2.54492C5.50195 2.58398 5.39844 2.64062 5.32812 2.71484C5.26172 2.78516 5.20898 2.88867 5.16992 3.02539C5.13477 3.1582 5.0918 3.3418 5.04102 3.57617C5.02539 3.64648 4.98633 3.68164 4.92383 3.68164ZM9.76367 5.75C9.68164 5.75 9.63281 5.70703 9.61719 5.62109C9.56641 5.33984 9.51953 5.11914 9.47656 4.95898C9.43359 4.79492 9.37109 4.66992 9.28906 4.58398C9.20703 4.49805 9.08398 4.43164 8.91992 4.38477C8.75586 4.33398 8.52734 4.2832 8.23438 4.23242C8.14453 4.2168 8.09961 4.16797 8.09961 4.08594C8.09961 4.04688 8.11133 4.01562 8.13477 3.99219C8.16211 3.96484 8.19531 3.94727 8.23438 3.93945C8.52734 3.88867 8.75586 3.83984 8.91992 3.79297C9.08398 3.74609 9.20703 3.67969 9.28906 3.59375C9.37109 3.50391 9.43359 3.37891 9.47656 3.21875C9.51953 3.05469 9.56641 2.83398 9.61719 2.55664C9.63281 2.4668 9.68164 2.42188 9.76367 2.42188C9.8418 2.42188 9.88867 2.4668 9.9043 2.55664C9.95508 2.83398 10.002 3.05469 10.0449 3.21875C10.0879 3.37891 10.1504 3.50391 10.2324 3.59375C10.3145 3.67969 10.4375 3.74609 10.6016 3.79297C10.7695 3.83984 11 3.88867 11.293 3.93945C11.3828 3.95508 11.4277 4.00391 11.4277 4.08594C11.4277 4.16797 11.3828 4.2168 11.293 4.23242C11 4.2832 10.7695 4.33398 10.6016 4.38477C10.4375 4.43164 10.3145 4.49805 10.2324 4.58398C10.1504 4.66992 10.0879 4.79492 10.0449 4.95898C10.002 5.11914 9.95508 5.33984 9.9043 5.62109C9.88867 5.70703 9.8418 5.75 9.76367 5.75ZM11.7148 12.4414L6.14844 6.85742C6.02734 6.73242 5.9668 6.58203 5.9668 6.40625C5.9668 6.23047 6.02734 6.07812 6.14844 5.94922C6.26562 5.82422 6.41406 5.76172 6.59375 5.76172C6.77734 5.76172 6.92969 5.82422 7.05078 5.94922L12.623 11.5391C12.7402 11.6641 12.7988 11.8125 12.7988 11.9844C12.8027 12.1602 12.7441 12.3125 12.623 12.4414C12.5059 12.5664 12.3555 12.6289 12.1719 12.6289C11.9922 12.6289 11.8398 12.5664 11.7148 12.4414ZM8.31055 8.41602L8.60352 8.13477L6.88086 6.41211C6.82617 6.35742 6.76953 6.32617 6.71094 6.31836C6.65234 6.30664 6.60156 6.32422 6.55859 6.37109C6.50781 6.42188 6.48633 6.47656 6.49414 6.53516C6.50586 6.58984 6.53906 6.64258 6.59375 6.69336L8.31055 8.41602Z" })), question)))))), h("div", { part: "product-query-popup-footer", slot: "footer" }, !this.registered ? (h(Fragment, null, h("div", { class: "inputs" }, h("klevu-textfield", { exportparts: partsExports("klevu-textfield"), value: this.name, variant: "pill", placeholder: "Name", onKlevuTextEnterPressed: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_register).call(this), onKlevuTextChanged: (e) => (this.name = e.detail) }), h("klevu-textfield", { exportparts: partsExports("klevu-textfield"), value: this.email, variant: "pill", placeholder: "Email", onKlevuTextEnterPressed: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_register).call(this), onKlevuTextChanged: (e) => {
      this.email = e.detail;
    } }), h("klevu-button", { originElement: this.originElement, exportparts: partsExports("klevu-button"), icon: "chevron_right", onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_register).call(this) })), h("klevu-typography", { variant: "body-xs" }, this.tDataProtectionNotice))) : (h("div", { class: "sendmessage" }, h("klevu-textfield", { exportparts: partsExports("klevu-textfield"), value: this.text, variant: this.textFieldVariant, placeholder: this.tTextFieldPlaceholder, onKlevuTextEnterPressed: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_sendMessage).call(this), onKlevuTextChanged: (e) => (this.text = e.detail) }), this.askButtonText ? (h("klevu-button", { exportparts: partsExports("klevu-button"), onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_sendMessage).call(this) }, this.askButtonText)) : (h("klevu-button", { originElement: this.originElement, exportparts: partsExports("klevu-button"), icon: "chevron_right", onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_sendMessage).call(this) })))), h("div", { style: { textAlign: "center" } }, !this.removeAskloBranding && (h("a", { target: "_blank", href: "https://asklo.ai/", class: "powered-by-message" }, this.poweredByMessage)), h("span", { class: "disclaimer" }, __classPrivateFieldGet(this, _KlevuProductQueryPopup_disclaimer, "f")))))));
}, _KlevuProductQueryPopup_renderFeedback = function _KlevuProductQueryPopup_renderFeedback() {
  return (h("div", { class: "pqa_feedback", part: "product-query-popup-feedback" }, h("klevu-typography", { variant: "body-l-bold" }, this.tRateExperienceTitle), h("klevu-typography", { variant: "body-m" }, this.tRateExperienceText), h("div", null, h("klevu-icon", { originElement: this.originElement, onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_pqafeedback).call(this, "up"), name: "thumb_up" }), h("klevu-icon", { originElement: this.originElement, onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_pqafeedback).call(this, "down"), name: "thumb_down" }))));
};
//# sourceMappingURL=klevu-product-query-popup.js.map
