'use strict';

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

const index = require('./index-85d13173.js');
const klevuInit = require('./klevu-init-a87b5171.js');
const getTranslation = require('./getTranslation-d40bbcba.js');
const partsExports = require('./partsExports-8da45cd3.js');
const moi = require('./moi-8ee228f7.js');
require('./KlevuDomEvents-e77df10c.js');

const klevuProductQueryPopupCss = ":host{display:block;text-align:left;--cornflower-blue:#428aca;--popup-height:var(--klevu-product-query-popup-height, 500px);--popup-width:var(--klevu-product-query-popup-width, 520px);--embedded-height:var(--klevu-product-query-popup-height, 100%);--embedded-width:var(--klevu-product-query-popup-width, 100%);--embedded-header-background:var(--klevu-product-query-popup-header-background, #6c757d1a);--embedded-border-color:var(--klevu-product-query-popup-border-color, #6c757d1a);--embedded-border-radius:var(--klevu-product-query-popup-border-radius, var(--klevu-border-radius-m));--end-spacer-display:var(--klevu-product-query-popup-spacer-display, block)}:host([embedded]){--klevu-chat-bubble-text-color-remote:var(--klevu-product-query-bubble-text-color-remote, #000);--klevu-chat-bubble-text-color:var(--klevu-product-query-bubble-text-color, #000);--klevu-chat-bubble-background:var(--klevu-product-query-bubble-background, #6c757d66);--klevu-chat-bubble-background-remote:var(--klevu-product-query-embedded-response-bg, #6c757d33);--klevu-loading-indicator-color:var(--klevu-loading-embedded-indicator-color, #6c757d33);--klevu-chat-layout-height:var(--klevu-product-query-chat-height, 100%);--klevu-chat-layout-max-height:var(--klevu-product-query-chat-max-height, 100%);--klevu-button-icon-color:var(--klevu-product-query-icon-color, #fff);--klevu-product-query-popup-width:100%;--klevu-button-background-color:var(--klevu-product-query-submit-button-background-color, #6c757d66);--klevu-button-background-hover:var(--klevu-product-query-submit-button-background-hover, #6c757d33);--klevu-chat-bubble-border-radius:var(--klevu-product-query-chat-bubble-border-radius, var(--klevu-border-radius-s));--klevu-chat-bubble-border-radius-remote:var(\n    --klevu-product-query-chat-bubble-border-radius-remote,\n    var(--klevu-border-radius-s)\n  );--klevu-footer-border-top:none;--klevu-chat-title-color:var(--klevu-product-query-title-color, #000);--klevu-button-border-radius:var(--klevu-product-query-submit-button-border-radius, 50%);--klevu-input-background-color:var(--klevu-product-query-input-background-color, var(--klevu-color-neutral-1));--klevu-input-color:var(--klevu-product-query-input-color, #000);--klevu-input-border:var(--klevu-product-query-input-border, 1px solid var(--klevu-color-neutral-2));--embedded-chat-background-color:var(--klevu-product-query-embedded-chat-background-color, #fff);--klevu-input-border-radius:var(--klevu-product-query-input-border-radius, 1000px);--klevu-input-placeholder-color:var(--klevu-product-query-input-placeholder-color, var(--klevu-color-neutral-5));--klevu-prepopulated-questions-color:var(--klevu-product-query-prepopulated-questions-color, #000);--klevu-prepopulated-questions-background:var(--klevu-product-query-prepopulated-questions-background, #f6f6f6);--klevu-prepopulated-questions-hover-background:var(\n    --klevu-product-query-prepopulated-questions-hover-background,\n    #6c757d33\n  );--klevu-prepopulated-questions-hover-color:var(--klevu-product-query-prepopulated-questions-hover-color, #000)}.content{padding:var(--klevu-spacing-04);box-sizing:border-box;display:flex;flex-direction:column;height:100%}klevu-chat-layout{height:var(--popup-height)}@media (max-width: 520px){klevu-chat-layout{height:100%}}klevu-chat-messages{padding-right:var(--klevu-spacing-04)}.chat-messages{height:100%}.embedded .chat-messages{max-height:550px}.header{display:flex;align-items:center;justify-content:space-between}.header klevu-icon{cursor:pointer}div[part=\"product-query-popup-header\"]{width:100%}div[part=\"product-query-popup-footer\"] .inputs{display:flex;gap:var(--klevu-spacing-04)}div[part=\"product-query-popup-footer\"] .sendmessage{display:flex;gap:var(--klevu-spacing-04)}div[part=\"product-query-popup-footer\"] .sendmessage klevu-textfield{width:100%}.pqa_feedback{text-align:center}.pqa_feedback>*{padding-bottom:var(--klevu-spacing-04)}.pqa_feedback klevu-icon{font-size:24px;padding:var(--klevu-spacing-04);cursor:pointer;border-radius:50%}.pqa_feedback klevu-icon:hover{background-color:var(--klevu-color-neutral-2)}.pqa_feedback klevu-icon:nth-child(1){color:var(--klevu-color-accent-1)}.pqa_feedback klevu-icon:nth-child(2){color:var(--klevu-color-accent-3)}.fineprintContainer{padding-bottom:var(--klevu-spacing-02);border-bottom:1px solid var(--klevu-color-neutral-4);margin-bottom:var(--klevu-spacing-04)}klevu-typography.fineprint{display:block;--klevu-body-xs-size:10px}.disclaimer{display:inline;font-size:8px;color:#666;margin-left:1px}.loading-sorry{display:block;--klevu-body-xs-size:10px}klevu-popup{--klevu-popup-width:var(--popup-width)}.questions-container{display:flex;flex-wrap:wrap;gap:8px;padding:var(--klevu-spacing-01);padding-bottom:var(--klevu-spacing-04)}.questions-container svg{margin-right:var(--klevu-spacing-03);fill:black}.questions-container .klevu-question{background-color:var(--klevu-prepopulated-questions-background);color:var(--klevu-prepopulated-questions-color);-webkit-animation:0.4s fadeIn;animation:0.4s fadeIn;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards;opacity:0}.questions-container .klevu-question{font-size:12px;font-weight:400;border-radius:7px;border-bottom-left-radius:0px;cursor:pointer;padding:10px}.questions-container .klevu-question:hover{background-color:#d8edfd;outline:0}@-webkit-keyframes fadeIn{0%{opacity:0}100%{opacity:1}}@keyframes fadeIn{0%{opacity:0}100%{opacity:1}}.powered-by-message,.powered-by-message:visited,.powered-by-message:active,.powered-by-message:hover{font-size:8px;margin-top:8px;display:inline;text-decoration:none;color:#666}.error-text{color:var(--klevu-color-negative)}.error-icon{font-size:14px;margin-right:5px;position:relative;top:2px}.embedded div[part=\"product-query-popup-header\"]{background:var(--embedded-header-background)}.embedded div[part=\"product-query-popup-footer\"]{--klevu-button-font-size:var(--klevu-body-xs-size);padding:var(--klevu-spacing-05);padding-top:var(--klevu-spacing-02)}.embedded{width:var(--embedded-width);max-width:var(--embedded-width);height:var(--embedded-height);border:1px solid var(--embedded-border-color);border-radius:var(--embedded-border-radius);--end-spacer-display:none;box-sizing:border-box;overflow:hidden}.embedded footer{border-top:none}.embedded .header{width:100%;padding-block:var(--klevu-spacing-03);padding-left:var(--klevu-spacing-05)}.embedded .header:empty{padding-block:0}.embedded .header klevu-typography{line-height:11px}.embedded .header klevu-typography span{color:var(--klevu-chat-title-color);font-size:var(--klevu-typography-font-size)}.embedded .content{padding:0}.embedded klevu-chat-messages{padding:var(--klevu-spacing-05);padding-bottom:0;gap:var(--klevu-spacing-04)}.embedded klevu-chat-messages .end-spacer{display:none}.embedded klevu-chat-layout{height:var(--embedded-height);max-height:var(--embedded-height);overflow:hidden;background-color:var(--embedded-chat-background-color)}.embedded div[part=\"product-query-popup-header\"] #closeDialog,.embedded div[part=\"product-query-popup-header\"] .fineprint{display:none}.embedded .questions-container{gap:12px;padding:var(--klevu-spacing-04)}.embedded .questions-container .klevu-question:hover{background-color:var(--klevu-prepopulated-questions-hover-background);color:var(--klevu-prepopulated-questions-hover-color)}";

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 __classPrivateFieldSet = (undefined && undefined.__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;
const KlevuProductQueryPopup = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.klevuMoiProductClick = index.createEvent(this, "klevuMoiProductClick", 7);
    _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.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.getTranslation("productQueryPopup.tTextFieldPlaceholder");
    this.tPopupTitle = getTranslation.getTranslation("productQueryPopup.tPopuptitle");
    this.tButtonText = getTranslation.getTranslation("productQueryPopup.tButtonText");
    this.tFinePrint = "";
    this.tLoadingSorry = getTranslation.getTranslation("productQueryPopup.tLoadingSorry");
    this.tAnswerError = getTranslation.getTranslation("productQueryPopup.tAnswerError");
    this.tRateExperienceTitle = getTranslation.getTranslation("productQueryPopup.tRateExperienceTitle");
    this.tRateExperienceText = getTranslation.getTranslation("productQueryPopup.tRateExperienceText");
    this.tDataProtectionNotice = getTranslation.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.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" ? (index.h(index.Host, null, index.h("klevu-popup", { ref: (el) => (__classPrivateFieldSet(this, _KlevuProductQueryPopup_popup, el, "f")), exportparts: partsExports.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 }, index.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))))) : (index.h(index.Host, { embedded: true }, index.h("div", { class: "embedded" }, index.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)))));
  }
  get el() { return index.getElement(this); }
};
_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 moi.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 (index.h(index.Fragment, null, index.h("klevu-chat-layout", { originElement: this.originElement, exportparts: partsExports.partsExports("klevu-chat-layout"), useNativeScrollbars: this.useNativeScrollbars, ref: (el) => (__classPrivateFieldSet(this, _KlevuProductQueryPopup_layoutElement, el, "f")) }, index.h("div", { part: "product-query-popup-header", slot: "header" }, index.h("div", { class: "header" }, (popupMode || !this.hideEmbeddedTitle) && (index.h("klevu-typography", { variant: "body-m-bold" }, this.tPopupTitle)), popupMode && (index.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(); } }))), index.h("div", { class: "fineprintContainer" }, this.tFinePrint && (index.h("klevu-typography", { variant: "body-xs", class: "fineprint" }, this.tFinePrint)), index.h("slot", { name: "after-fineprint" }))), index.h("div", { class: "chat-messages" }, index.h("klevu-chat-messages", { exportparts: partsExports.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;
    } }, index.h("div", { slot: "chat-messages-after" }, this.showLoading ? (index.h("klevu-loading-indicator", { exportparts: partsExports.partsExports("klevu-loading-indicator") })) : null, this.showLoadingSorry ? (index.h("klevu-typography", { class: "loading-sorry", variant: "body-xs" }, this.tLoadingSorry)) : null, this.sendMessageError ? (index.h("klevu-typography", { class: "error-text", variant: "body-xs" }, index.h("klevu-icon", { name: "error", class: "error-icon" }), this.tAnswerError)) : null)), this.showLoading || this.hideQuestions ? null : (index.h("div", { class: "questions-container" }, this.questions.map((question, index$1) => (index.h("div", { role: "button", class: "klevu-question", onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_onQuestionClick).call(this, question), style: { animationDelay: `${0.4 * index$1}s` } }, index.h("svg", { width: "13", height: "13", viewBox: "0 0 13 13", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, index.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)))))), index.h("div", { part: "product-query-popup-footer", slot: "footer" }, !this.registered ? (index.h(index.Fragment, null, index.h("div", { class: "inputs" }, index.h("klevu-textfield", { exportparts: partsExports.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) }), index.h("klevu-textfield", { exportparts: partsExports.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;
    } }), index.h("klevu-button", { originElement: this.originElement, exportparts: partsExports.partsExports("klevu-button"), icon: "chevron_right", onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_register).call(this) })), index.h("klevu-typography", { variant: "body-xs" }, this.tDataProtectionNotice))) : (index.h("div", { class: "sendmessage" }, index.h("klevu-textfield", { exportparts: partsExports.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 ? (index.h("klevu-button", { exportparts: partsExports.partsExports("klevu-button"), onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_sendMessage).call(this) }, this.askButtonText)) : (index.h("klevu-button", { originElement: this.originElement, exportparts: partsExports.partsExports("klevu-button"), icon: "chevron_right", onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_sendMessage).call(this) })))), index.h("div", { style: { textAlign: "center" } }, !this.removeAskloBranding && (index.h("a", { target: "_blank", href: "https://asklo.ai/", class: "powered-by-message" }, this.poweredByMessage)), index.h("span", { class: "disclaimer" }, __classPrivateFieldGet(this, _KlevuProductQueryPopup_disclaimer, "f")))))));
}, _KlevuProductQueryPopup_renderFeedback = function _KlevuProductQueryPopup_renderFeedback() {
  return (index.h("div", { class: "pqa_feedback", part: "product-query-popup-feedback" }, index.h("klevu-typography", { variant: "body-l-bold" }, this.tRateExperienceTitle), index.h("klevu-typography", { variant: "body-m" }, this.tRateExperienceText), index.h("div", null, index.h("klevu-icon", { originElement: this.originElement, onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_pqafeedback).call(this, "up"), name: "thumb_up" }), index.h("klevu-icon", { originElement: this.originElement, onClick: () => __classPrivateFieldGet(this, _KlevuProductQueryPopup_instances, "m", _KlevuProductQueryPopup_pqafeedback).call(this, "down"), name: "thumb_down" }))));
};
KlevuProductQueryPopup.style = klevuProductQueryPopupCss;

const klevuUtilPortalCss = ":host{display:block}";

const KlevuUtilPortal = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  connectedCallback() {
    this.createRoot();
  }
  createRoot() {
    if (this.root) {
      return;
    }
    this.root = document.createElement("div");
    const assignedContent = [];
    this.el.querySelectorAll("slot").forEach((slot) => {
      assignedContent.push(...slot.assignedElements());
    });
    this.root.appendChild(this.el);
    for (const element of assignedContent) {
      this.el.childNodes[0].appendChild(element);
    }
    this.root.setAttribute("data-name", "klevu-portal");
    document.body.appendChild(this.root);
  }
  disconnectedCallback() {
    if (!this.root) {
      return;
    }
    this.root.remove();
  }
  render() {
    return (index.h(index.Host, null, index.h("slot", null)));
  }
  get el() { return index.getElement(this); }
};
KlevuUtilPortal.style = klevuUtilPortalCss;

exports.klevu_product_query_popup = KlevuProductQueryPopup;
exports.klevu_util_portal = KlevuUtilPortal;

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