"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__, {
    AtomicInsightSmartSnippet: ()=>AtomicInsightSmartSnippet
});
const insight_namespaceObject = require("@coveo/headless/insight");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
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_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 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 utils_cjs_namespaceObject = require("../../../utils/utils.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");
require("../../common/atomic-smart-snippet-source/atomic-smart-snippet-source.cjs");
const when_js_namespaceObject = require("lit/directives/when.js");
require("../atomic-insight-smart-snippet-feedback-modal/atomic-insight-smart-snippet-feedback-modal.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const external_atomic_insight_smart_snippet_tw_css_cjs_namespaceObject = require("./atomic-insight-smart-snippet.tw.css.cjs");
var external_atomic_insight_smart_snippet_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_insight_smart_snippet_tw_css_cjs_namespaceObject);
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);
}
class AtomicInsightSmartSnippet extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.smartSnippetId ||= (0, utils_cjs_namespaceObject.randomID)();
        this.smartSnippet = (0, insight_namespaceObject.buildSmartSnippet)(this.bindings.engine);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (this.modalRef) this.modalRef.removeEventListener('feedbackSent', this.feedbackSentHandler);
    }
    willUpdate() {
        if (!this.smartSnippetState) return;
        if (!(this.smartSnippetState.liked || this.smartSnippetState.disliked)) this.feedbackSent = false;
    }
    loadModal() {
        if (this.modalRef) return;
        const modalRef = document.createElement('atomic-insight-smart-snippet-feedback-modal');
        modalRef.addEventListener('feedbackSent', this.feedbackSentHandler);
        this.modalRef = modalRef;
        this.renderRoot.parentElement?.insertAdjacentElement('beforebegin', modalRef);
    }
    renderSource() {
        const source = this.smartSnippetState.source;
        if (!source) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`<atomic-smart-snippet-source
      .anchorAttributes=${(0, attributes_slot_cjs_namespaceObject.getAttributesFromLinkSlotContent)(this, 'source-anchor-attributes')}
      .onBeginDelayedSelectSource=${this.smartSnippet.beginDelayedSelectSource}
      .onCancelPendingSelectSource=${this.smartSnippet.cancelPendingSelectSource}
      .onSelectSource=${this.smartSnippet.selectSource}
      .source=${source}
    ></atomic-smart-snippet-source>`;
    }
    renderFeedbackBanner() {
        const explainWhyRef = (button)=>{
            if (this.modalRef && button) this.modalRef.source = button;
        };
        return (0, smart_snippet_feedback_banner_cjs_namespaceObject.renderSmartSnippetFeedbackBanner)({
            props: {
                disliked: this.smartSnippetState.disliked,
                explainWhyRef,
                feedbackSent: this.feedbackSent,
                id: this.smartSnippetId,
                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;
                }
            }
        });
    }
    render() {
        const shouldDisplay = this.smartSnippetState?.answerFound ?? false;
        this.classList.toggle('atomic-hidden', !shouldDisplay);
        return (0, external_lit_namespaceObject.html)` ${(0, when_js_namespaceObject.when)(shouldDisplay, ()=>(0, snippet_wrapper_cjs_namespaceObject.renderSnippetWrapper)({
                props: {
                    headingLevel: this.headingLevel,
                    i18n: this.bindings.i18n
                }
            })((0, external_lit_namespaceObject.html)`
        <atomic-smart-snippet-collapse-wrapper>
          ${(0, snippet_question_cjs_namespaceObject.renderSnippetQuestion)({
                props: {
                    headingLevel: this.headingLevel,
                    question: this.smartSnippetState.question
                }
            })}
          <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.snippetStyle}
          ></atomic-smart-snippet-expandable-answer>
          ${(0, snippet_footer_cjs_namespaceObject.renderSnippetFooter)({
                props: {
                    i18n: this.bindings.i18n
                }
            })((0, external_lit_namespaceObject.html)` ${this.renderSource()} ${this.renderFeedbackBanner()} `)}
        </atomic-smart-snippet-collapse-wrapper>
      `))}`;
    }
    constructor(...args){
        super(...args), this.feedbackSent = false, this.feedbackSentHandler = ()=>{
            this.feedbackSent = true;
        }, this.headingLevel = 0, this.maximumHeight = 250, this.collapsedHeight = 180;
    }
}
AtomicInsightSmartSnippet.styles = external_atomic_insight_smart_snippet_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightSmartSnippet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightSmartSnippet.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('smartSnippet'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightSmartSnippetState ? Object : InsightSmartSnippetState)
], AtomicInsightSmartSnippet.prototype, "smartSnippetState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicInsightSmartSnippet.prototype, "feedbackSent", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'heading-level'
    })
], AtomicInsightSmartSnippet.prototype, "headingLevel", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'maximum-height'
    })
], AtomicInsightSmartSnippet.prototype, "maximumHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'collapsed-height'
    })
], AtomicInsightSmartSnippet.prototype, "collapsedHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true,
        attribute: 'snippet-style'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightSmartSnippet.prototype, "snippetStyle", void 0);
_ts_decorate([
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightSmartSnippet.prototype, "render", null);
AtomicInsightSmartSnippet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-insight-smart-snippet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicInsightSmartSnippet);
exports.AtomicInsightSmartSnippet = __webpack_exports__.AtomicInsightSmartSnippet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicInsightSmartSnippet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
