"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__, {
    AtomicInsightSmartSnippetSuggestions: ()=>AtomicInsightSmartSnippetSuggestions
});
const bueno_namespaceObject = require("@coveo/bueno");
const insight_namespaceObject = require("@coveo/headless/insight");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const attributes_slot_cjs_namespaceObject = require("../../common/item-link/attributes-slot.cjs");
const answer_and_source_wrapper_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet-suggestions/answer-and-source-wrapper.cjs");
const footer_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet-suggestions/footer.cjs");
const get_question_part_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet-suggestions/get-question-part.cjs");
const question_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet-suggestions/question.cjs");
const question_wrapper_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet-suggestions/question-wrapper.cjs");
const suggestions_wrapper_cjs_namespaceObject = require("../../common/smart-snippets/atomic-smart-snippet-suggestions/suggestions-wrapper.cjs");
const validate_props_controller_cjs_namespaceObject = require("../../common/validate-props-controller/validate-props-controller.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 utils_cjs_namespaceObject = require("../../../utils/utils.cjs");
const arrow_down_cjs_namespaceObject = require("../../../images/arrow-down.cjs");
var arrow_down_cjs_default = /*#__PURE__*/ __webpack_require__.n(arrow_down_cjs_namespaceObject);
const arrow_right_cjs_namespaceObject = require("../../../images/arrow-right.cjs");
var arrow_right_cjs_default = /*#__PURE__*/ __webpack_require__.n(arrow_right_cjs_namespaceObject);
require("../../common/atomic-icon/atomic-icon.cjs");
require("../../common/atomic-smart-snippet-source/atomic-smart-snippet-source.cjs");
require("../../common/atomic-smart-snippet-answer/atomic-smart-snippet-answer.cjs");
const external_atomic_insight_smart_snippet_suggestions_tw_css_cjs_namespaceObject = require("./atomic-insight-smart-snippet-suggestions.tw.css.cjs");
var external_atomic_insight_smart_snippet_suggestions_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_insight_smart_snippet_suggestions_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 AtomicInsightSmartSnippetSuggestions extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.accordionId = (0, utils_cjs_namespaceObject.randomID)('atomic-smart-snippet-suggestions-');
        this.smartSnippetQuestionsList = (0, insight_namespaceObject.buildSmartSnippetQuestionsList)(this.bindings.engine);
    }
    render() {
        const shouldDisplay = this.smartSnippetQuestionsListState.questions.length > 0;
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(shouldDisplay, ()=>(0, suggestions_wrapper_cjs_namespaceObject.renderSuggestionsWrapper)({
                props: {
                    headingLevel: this.headingLevel,
                    i18n: this.bindings.i18n
                }
            })((0, external_lit_namespaceObject.html)`
          ${this.smartSnippetQuestionsListState.questions.map((relatedQuestion, i)=>this.renderRelatedQuestion(relatedQuestion, i))}
        `), ()=>external_lit_namespaceObject.nothing)}`;
    }
    renderRelatedQuestion(relatedQuestion, index) {
        return (0, question_wrapper_cjs_namespaceObject.renderQuestionWrapper)({
            props: {
                expanded: relatedQuestion.expanded,
                key: relatedQuestion.questionAnswerId
            }
        })((0, external_lit_namespaceObject.html)`
      ${this.renderQuestionButton(relatedQuestion, index)}
      ${(0, when_js_namespaceObject.when)(relatedQuestion.expanded, ()=>this.renderAnswer(relatedQuestion, index))}
    `);
    }
    renderQuestionButton(relatedQuestion, index) {
        return (0, question_cjs_namespaceObject.renderQuestion)({
            props: {
                ariaControls: `${this.accordionId}-${index}`,
                expanded: relatedQuestion.expanded,
                headingLevel: this.headingLevel,
                onClick: ()=>this.toggleQuestion(relatedQuestion),
                question: relatedQuestion.question
            }
        })((0, external_lit_namespaceObject.html)`
      <atomic-icon
        .icon=${relatedQuestion.expanded ? arrow_down_cjs_default() : arrow_right_cjs_default()}
        part=${(0, get_question_part_cjs_namespaceObject.getQuestionPart)('icon', relatedQuestion.expanded)}
        class="mr-3 w-2.5 stroke-[1.25]"
      ></atomic-icon>
    `);
    }
    renderAnswer(relatedQuestion, index) {
        return (0, answer_and_source_wrapper_cjs_namespaceObject.renderAnswerAndSourceWrapper)({
            props: {
                id: `${this.accordionId}-${index}`
            }
        })((0, external_lit_namespaceObject.html)`
      <atomic-smart-snippet-answer
        exportparts="answer"
        .htmlContent=${relatedQuestion.answer}
        .innerStyle=${this.computedSnippetStyle}
        @selectInlineLink=${(e)=>this.smartSnippetQuestionsList.selectInlineLink(relatedQuestion.questionAnswerId, e.detail)}
        @beginDelayedSelectInlineLink=${(e)=>this.smartSnippetQuestionsList.beginDelayedSelectInlineLink(relatedQuestion.questionAnswerId, e.detail)}
        @cancelPendingSelectInlineLink=${(e)=>this.smartSnippetQuestionsList.cancelPendingSelectInlineLink(relatedQuestion.questionAnswerId, e.detail)}
      ></atomic-smart-snippet-answer>
      ${(0, when_js_namespaceObject.when)(relatedQuestion.source, ()=>this.renderSource(relatedQuestion.questionAnswerId, relatedQuestion.source))}
    `);
    }
    renderSource(questionAnswerId, source) {
        return (0, footer_cjs_namespaceObject.renderFooter)({
            props: {
                i18n: this.bindings.i18n
            }
        })((0, external_lit_namespaceObject.html)`
      <atomic-smart-snippet-source
        .anchorAttributes=${(0, attributes_slot_cjs_namespaceObject.getAttributesFromLinkSlotContent)(this, 'source-anchor-attributes')}
        @beginDelayedSelectSource=${()=>this.smartSnippetQuestionsList.beginDelayedSelectSource(questionAnswerId)}
        @cancelPendingSelectSource=${()=>this.smartSnippetQuestionsList.cancelPendingSelectSource(questionAnswerId)}
        @selectSource=${()=>this.smartSnippetQuestionsList.selectSource(questionAnswerId)}
        .source=${source}
      ></atomic-smart-snippet-source>
    `);
    }
    get computedSnippetStyle() {
        const styleTag = this.querySelector('template')?.content.querySelector('style');
        if (!styleTag) return this.snippetStyle;
        return styleTag.innerHTML;
    }
    toggleQuestion(relatedQuestion) {
        if (relatedQuestion.expanded) this.smartSnippetQuestionsList.collapse(relatedQuestion.questionAnswerId);
        else this.smartSnippetQuestionsList.expand(relatedQuestion.questionAnswerId);
    }
    constructor(){
        super(), this.headingLevel = 0;
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                headingLevel: this.headingLevel
            }), AtomicInsightSmartSnippetSuggestions.propsSchema, false);
    }
}
AtomicInsightSmartSnippetSuggestions.propsSchema = new bueno_namespaceObject.Schema({
    headingLevel: new bueno_namespaceObject.NumberValue({
        min: 0,
        max: 5,
        required: false
    })
});
AtomicInsightSmartSnippetSuggestions.styles = external_atomic_insight_smart_snippet_suggestions_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightSmartSnippetSuggestions.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightSmartSnippetSuggestions.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('smartSnippetQuestionsList'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof SmartSnippetQuestionsListState ? Object : SmartSnippetQuestionsListState)
], AtomicInsightSmartSnippetSuggestions.prototype, "smartSnippetQuestionsListState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: Number,
        attribute: 'heading-level'
    })
], AtomicInsightSmartSnippetSuggestions.prototype, "headingLevel", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'snippet-style'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightSmartSnippetSuggestions.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)
], AtomicInsightSmartSnippetSuggestions.prototype, "render", null);
AtomicInsightSmartSnippetSuggestions = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-insight-smart-snippet-suggestions'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicInsightSmartSnippetSuggestions);
exports.AtomicInsightSmartSnippetSuggestions = __webpack_exports__.AtomicInsightSmartSnippetSuggestions;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicInsightSmartSnippetSuggestions"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
