"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__, {
    AtomicSmartSnippetExpandableAnswer: ()=>AtomicSmartSnippetExpandableAnswer
});
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const boolean_converter_cjs_namespaceObject = require("../../../converters/boolean-converter.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 event_utils_cjs_namespaceObject = require("../../../utils/event-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 external_atomic_smart_snippet_expandable_answer_tw_css_cjs_namespaceObject = require("./atomic-smart-snippet-expandable-answer.tw.css.cjs");
var external_atomic_smart_snippet_expandable_answer_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_smart_snippet_expandable_answer_tw_css_cjs_namespaceObject);
require("../atomic-icon/atomic-icon.cjs");
require("../atomic-smart-snippet-answer/atomic-smart-snippet-answer.cjs");
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 AtomicSmartSnippetExpandableAnswer extends external_lit_namespaceObject.LitElement {
    validateProps() {
        if (this.maximumHeight < this.collapsedHeight) throw new Error('maximumHeight must be greater than or equal to collapsedHeight');
    }
    initialize() {
        this.validateProps();
    }
    get showButton() {
        return void 0 !== this.fullHeight && this.fullHeight > this.maximumHeight;
    }
    get isExpanded() {
        return this.expanded || !this.showButton;
    }
    updated(changedProperties) {
        super.updated(changedProperties);
        if (changedProperties.has('fullHeight')) {
            this.style.setProperty('--full-height', `${this.fullHeight}px`);
            this.style.setProperty('--collapsed-size', `${this.showButton ? this.collapsedHeight : this.fullHeight}px`);
        }
    }
    async firstUpdated(_changedProperties) {
        super.firstUpdated(_changedProperties);
        this.fullHeight = await this.establishInitialHeight();
    }
    async establishInitialHeight() {
        const answerElement = document.createElement('atomic-smart-snippet-answer');
        answerElement.htmlContent = this.htmlContent;
        answerElement.innerStyle = this.snippetStyle;
        answerElement.style.visibility = 'hidden';
        answerElement.style.position = 'absolute';
        return new Promise((resolve)=>{
            (0, event_utils_cjs_namespaceObject.listenOnce)(answerElement, 'answerSizeUpdated', (event)=>{
                answerElement.remove();
                resolve(event.detail.height);
            });
            this.parentElement.appendChild(answerElement);
        });
    }
    handleExpand() {
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('expand'));
    }
    handleCollapse() {
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('collapse'));
    }
    handleSelectInlineLink(e) {
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('selectInlineLink', e.detail));
    }
    handleBeginDelayedSelectInlineLink(e) {
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('beginDelayedSelectInlineLink', e.detail));
    }
    handleCancelPendingSelectInlineLink(e) {
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('cancelPendingSelectInlineLink', e.detail));
    }
    renderAnswer() {
        return (0, external_lit_namespaceObject.html)`
      <div part="truncated-answer">
        <atomic-smart-snippet-answer
          exportparts="answer"
          .htmlContent=${this.htmlContent}
          .innerStyle=${this.snippetStyle}
          @answerSizeUpdated=${(e)=>{
            this.fullHeight = e.detail.height;
        }}
          @selectInlineLink=${this.handleSelectInlineLink}
          @beginDelayedSelectInlineLink=${this.handleBeginDelayedSelectInlineLink}
          @cancelPendingSelectInlineLink=${this.handleCancelPendingSelectInlineLink}
        ></atomic-smart-snippet-answer>
      </div>
    `;
    }
    renderButton() {
        return (0, when_js_namespaceObject.when)(this.showButton, ()=>(0, external_lit_namespaceObject.html)`
        <button
          @click=${()=>this.isExpanded ? this.handleCollapse() : this.handleExpand()}
          class="text-primary mb-4 hover:underline"
          part=${this.isExpanded ? 'show-less-button' : 'show-more-button'}
        >
          ${this.bindings.i18n.t(this.isExpanded ? 'show-less' : 'show-more')}
          <atomic-icon
            .icon=${arrow_down_cjs_default()}
            class="ml-2 w-3 align-baseline"
          ></atomic-icon>
        </button>
      `);
    }
    render() {
        return (0, external_lit_namespaceObject.html)`
      <div class=${this.isExpanded ? 'expanded' : ''}>
        ${this.renderAnswer()} ${this.renderButton()}
      </div>
    `;
    }
    constructor(...args){
        super(...args), this.maximumHeight = 250, this.collapsedHeight = 180;
    }
}
AtomicSmartSnippetExpandableAnswer.styles = external_atomic_smart_snippet_expandable_answer_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof AnyBindings ? Object : AnyBindings)
], AtomicSmartSnippetExpandableAnswer.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicSmartSnippetExpandableAnswer.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter
    }),
    _ts_metadata("design:type", Boolean)
], AtomicSmartSnippetExpandableAnswer.prototype, "expanded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicSmartSnippetExpandableAnswer.prototype, "htmlContent", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true
    })
], AtomicSmartSnippetExpandableAnswer.prototype, "maximumHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true
    })
], AtomicSmartSnippetExpandableAnswer.prototype, "collapsedHeight", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicSmartSnippetExpandableAnswer.prototype, "snippetStyle", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Number)
], AtomicSmartSnippetExpandableAnswer.prototype, "fullHeight", 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)
], AtomicSmartSnippetExpandableAnswer.prototype, "render", null);
AtomicSmartSnippetExpandableAnswer = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-smart-snippet-expandable-answer'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicSmartSnippetExpandableAnswer);
exports.AtomicSmartSnippetExpandableAnswer = __webpack_exports__.AtomicSmartSnippetExpandableAnswer;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicSmartSnippetExpandableAnswer"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
