"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    AtomicSmartSnippet: ()=>AtomicSmartSnippet
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
require("../../common/atomic-icon/atomic-icon.cjs");
require("../../common/atomic-smart-snippet-collapse-wrapper/atomic-smart-snippet-collapse-wrapper.cjs");
require("../../common/atomic-smart-snippet-expandable-answer/atomic-smart-snippet-expandable-answer.cjs");
const attributes_slot_cjs_namespaceObject = require("../../common/item-link/attributes-slot.cjs");
const snippet_footer_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet/snippet-footer.cjs");
const snippet_question_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet/snippet-question.cjs");
const snippet_truncated_answer_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet/snippet-truncated-answer.cjs");
const snippet_wrapper_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet/snippet-wrapper.cjs");
const smart_snippet_feedback_banner_cjs_namespaceObject = require("../../common/smart-snippets/smart-snippet-feedback-banner.cjs");
const array_converter_cjs_namespaceObject = require("../../../converters/array-converter.cjs");
const bind_state_cjs_namespaceObject = require("../../../decorators/bind-state.cjs");
const binding_guard_cjs_namespaceObject = require("../../../decorators/binding-guard.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const tab_utils_cjs_namespaceObject = require("../../../utils/tab-utils.cjs");
const utils_cjs_namespaceObject = require("../../../utils/utils.cjs");
const external_atomic_smart_snippet_tw_css_cjs_namespaceObject = require("./atomic-smart-snippet.tw.css.cjs");
var external_atomic_smart_snippet_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_smart_snippet_tw_css_cjs_namespaceObject);
require("../../common/atomic-smart-snippet-source/atomic-smart-snippet-source.cjs");
require("../atomic-smart-snippet-feedback-modal/atomic-smart-snippet-feedback-modal.cjs");
function _check_private_redeclaration(obj, privateCollection) {
    if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
}
function _class_apply_descriptor_get(receiver, descriptor) {
    if (descriptor.get) return descriptor.get.call(receiver);
    return descriptor.value;
}
function _class_apply_descriptor_set(receiver, descriptor, value) {
    if (descriptor.set) descriptor.set.call(receiver, value);
    else {
        if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
        descriptor.value = value;
    }
}
function _class_extract_field_descriptor(receiver, privateMap, action) {
    if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
    return privateMap.get(receiver);
}
function _class_private_field_get(receiver, privateMap) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
    return _class_apply_descriptor_get(receiver, descriptor);
}
function _class_private_field_init(obj, privateMap, value) {
    _check_private_redeclaration(obj, privateMap);
    privateMap.set(obj, value);
}
function _class_private_field_set(receiver, privateMap, value) {
    var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
    _class_apply_descriptor_set(receiver, descriptor, value);
    return value;
}
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
    else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}
var _id = /*#__PURE__*/ new WeakMap();
class AtomicSmartSnippet extends external_lit_namespaceObject.LitElement {
    connectedCallback() {
        super.connectedCallback();
        _class_private_field_set(this, _id, _class_private_field_get(this, _id) || (0, utils_cjs_namespaceObject.randomID)());
        this.addEventListener('selectInlineLink', this.onSelectInlineLink);
        this.addEventListener('beginDelayedSelectInlineLink', this.onBeginDelayedSelectInlineLink);
        this.addEventListener('cancelPendingSelectInlineLink', this.onCancelPendingSelectInlineLink);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('selectInlineLink', this.onSelectInlineLink);
        this.removeEventListener('beginDelayedSelectInlineLink', this.onBeginDelayedSelectInlineLink);
        this.removeEventListener('cancelPendingSelectInlineLink', this.onCancelPendingSelectInlineLink);
    }
    initialize() {
        this.smartSnippet = (0, headless_namespaceObject.buildSmartSnippet)(this.bindings.engine);
        this.tabManager = (0, headless_namespaceObject.buildTabManager)(this.bindings.engine);
    }
    willUpdate() {
        if (this.smartSnippetState && !(this.smartSnippetState.liked || this.smartSnippetState.disliked)) this.setFeedbackSent(false);
    }
    onSelectInlineLink(event) {
        this.smartSnippet.selectInlineLink(event.detail);
    }
    onBeginDelayedSelectInlineLink(event) {
        this.smartSnippet.beginDelayedSelectInlineLink(event.detail);
    }
    onCancelPendingSelectInlineLink(event) {
        this.smartSnippet.cancelPendingSelectInlineLink(event.detail);
    }
    setModalRef(ref) {
        this.modalRef = ref;
    }
    setFeedbackSent(isSent) {
        this.feedbackSent = isSent;
    }
    get computedStyle() {
        const styleTag = this.querySelector('template')?.content.querySelector('style');
        if (!styleTag) return this.snippetStyle;
        return styleTag.innerHTML;
    }
    loadModal() {
        if (this.modalRef) return;
        const modalRef = document.createElement('atomic-smart-snippet-feedback-modal');
        modalRef.addEventListener('feedbackSent', ()=>{
            this.setFeedbackSent(true);
        });
        this.setModalRef(modalRef);
        this.insertAdjacentElement('beforebegin', modalRef);
    }
    render() {
        const shouldDisplay = (0, tab_utils_cjs_namespaceObject.shouldDisplayOnCurrentTab)(this.tabsIncluded, this.tabsExcluded, this.tabManagerState?.activeTab) && this.smartSnippetState.answerFound;
        this.classList.toggle('atomic-hidden', !shouldDisplay);
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(shouldDisplay, ()=>this.renderContent())}`;
    }
    renderContent() {
        const source = this.smartSnippetState.source;
        return (0, snippet_wrapper_cjs_namespaceObject.renderSnippetWrapper)({
            props: {
                headingLevel: this.headingLevel,
                i18n: this.bindings.i18n
            }
        })((0, external_lit_namespaceObject.html)`
      <atomic-smart-snippet-collapse-wrapper
        .collapsedHeight=${this.snippetCollapsedHeight}
        .maximumHeight=${this.snippetMaximumHeight}
      >
        ${(0, snippet_question_cjs_namespaceObject.renderSnippetQuestion)({
            props: {
                headingLevel: this.headingLevel,
                question: this.smartSnippetState.question
            }
        })}
        ${(0, when_js_namespaceObject.when)(void 0 !== this.snippetMaximumHeight, ()=>(0, snippet_truncated_answer_cjs_namespaceObject.renderSnippetTruncatedAnswer)({
                props: {
                    answer: this.smartSnippetState.answer,
                    style: this.computedStyle
                }
            }), ()=>(0, external_lit_namespaceObject.html)`
            <atomic-smart-snippet-expandable-answer
              .collapsedHeight=${this.collapsedHeight}
              .expanded=${this.smartSnippetState.expanded}
              exportparts="answer,show-more-button,show-less-button,truncated-answer"
              .htmlContent=${this.smartSnippetState.answer}
              .maximumHeight=${this.maximumHeight}
              @collapse=${()=>this.smartSnippet.collapse()}
              @expand=${()=>this.smartSnippet.expand()}
              part="body"
              .snippetStyle=${this.computedStyle}
            ></atomic-smart-snippet-expandable-answer>
          `)}
        ${(0, snippet_footer_cjs_namespaceObject.renderSnippetFooter)({
            props: {
                i18n: this.bindings.i18n
            }
        })((0, external_lit_namespaceObject.html)`
          ${(0, when_js_namespaceObject.when)(source, ()=>(0, external_lit_namespaceObject.html)`
              <atomic-smart-snippet-source
                .source=${source}
                .anchorAttributes=${(0, attributes_slot_cjs_namespaceObject.getAttributesFromLinkSlotContent)(this, 'source-anchor-attributes')}
                @selectSource=${this.smartSnippet.selectSource}
                @beginDelayedSelectSource=${this.smartSnippet.beginDelayedSelectSource}
                @cancelPendingSelectSource=${this.smartSnippet.cancelPendingSelectSource}
              ></atomic-smart-snippet-source>
            `)}
          ${(0, smart_snippet_feedback_banner_cjs_namespaceObject.renderSmartSnippetFeedbackBanner)({
            props: {
                disliked: this.smartSnippetState.disliked,
                explainWhyRef: (button)=>{
                    if (this.modalRef && button) this.modalRef.source = button;
                },
                feedbackSent: this.feedbackSent,
                id: _class_private_field_get(this, _id),
                i18n: this.bindings.i18n,
                liked: this.smartSnippetState.liked,
                onDislike: ()=>{
                    this.loadModal();
                    this.smartSnippet.dislike();
                },
                onLike: ()=>this.smartSnippet.like(),
                onPressExplainWhy: ()=>{
                    if (this.modalRef) this.modalRef.isOpen = true;
                }
            }
        })}
        `)}
      </atomic-smart-snippet-collapse-wrapper>
    `);
    }
    constructor(...args){
        super(...args), _class_private_field_init(this, _id, {
            writable: true,
            value: void 0
        }), this.feedbackSent = false, this.headingLevel = 0, this.maximumHeight = 250, this.collapsedHeight = 180, this.tabsIncluded = [], this.tabsExcluded = [];
    }
}
AtomicSmartSnippet.styles = external_atomic_smart_snippet_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicSmartSnippet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicSmartSnippet.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('smartSnippet'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof SmartSnippetState ? Object : SmartSnippetState)
], AtomicSmartSnippet.prototype, "smartSnippetState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('tabManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof TabManagerState ? Object : TabManagerState)
], AtomicSmartSnippet.prototype, "tabManagerState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicSmartSnippet.prototype, "feedbackSent", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'heading-level'
    })
], AtomicSmartSnippet.prototype, "headingLevel", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'maximum-height'
    })
], AtomicSmartSnippet.prototype, "maximumHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'collapsed-height'
    })
], AtomicSmartSnippet.prototype, "collapsedHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true,
        attribute: 'snippet-style'
    }),
    _ts_metadata("design:type", String)
], AtomicSmartSnippet.prototype, "snippetStyle", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'tabs-included',
        converter: array_converter_cjs_namespaceObject.arrayConverter
    }),
    _ts_metadata("design:type", Array)
], AtomicSmartSnippet.prototype, "tabsIncluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'tabs-excluded',
        converter: array_converter_cjs_namespaceObject.arrayConverter
    }),
    _ts_metadata("design:type", Array)
], AtomicSmartSnippet.prototype, "tabsExcluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'snippet-maximum-height'
    }),
    _ts_metadata("design:type", Number)
], AtomicSmartSnippet.prototype, "snippetMaximumHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'snippet-collapsed-height'
    }),
    _ts_metadata("design:type", Number)
], AtomicSmartSnippet.prototype, "snippetCollapsedHeight", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicSmartSnippet.prototype, "render", null);
AtomicSmartSnippet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-smart-snippet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicSmartSnippet);
exports.AtomicSmartSnippet = __webpack_exports__.AtomicSmartSnippet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicSmartSnippet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
