"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__, {
    AtomicAskFollowUpInput: ()=>AtomicAskFollowUpInput
});
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
const external_button_cjs_namespaceObject = require("../button.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const external_atomic_ask_follow_up_input_tw_css_cjs_namespaceObject = require("./atomic-ask-follow-up-input.tw.css.cjs");
var external_atomic_ask_follow_up_input_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_ask_follow_up_input_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 AtomicAskFollowUpInput extends external_lit_namespaceObject.LitElement {
    async handleSubmit() {
        const input = this.textAreaRef.value;
        if (!input || this.isSubmitting) return;
        const inputValue = input.value.trim();
        if (!inputValue || this.submitButtonDisabled) return;
        this.isSubmitting = true;
        try {
            input.value = '';
            this.clearReplicaText();
            this.collapseTextArea();
            await this.askFollowUp(inputValue);
        } finally{
            this.isSubmitting = false;
        }
    }
    handleInput() {
        this.expandTextArea();
        this.syncTextWithReplica();
    }
    handleKeyDown(e) {
        if ('Enter' === e.key && !e.shiftKey) {
            e.preventDefault();
            this.handleSubmit();
        }
    }
    syncTextWithReplica() {
        const textArea = this.textAreaRef.value;
        const parent = textArea?.parentNode;
        if (!parent || !textArea) return;
        parent.dataset.replicatedValue = textArea.value;
    }
    clearReplicaText() {
        const parent = this.textAreaRef.value?.parentNode;
        if (!parent) return;
        delete parent.dataset.replicatedValue;
    }
    expandTextArea() {
        const parent = this.textAreaRef.value?.parentNode;
        if (!parent) return;
        parent.classList.add('expanded');
    }
    collapseTextArea() {
        const parent = this.textAreaRef.value?.parentNode;
        if (!parent) return;
        parent.classList.remove('expanded');
    }
    render() {
        return (0, external_lit_namespaceObject.html)`
      <div
        part="input-container"
        class="relative flex rounded-md border border-neutral"
      >
        <div part="textarea-expander" class="grid grow overflow-hidden">
          <textarea
            part="input-field"
            ${(0, ref_js_namespaceObject.ref)(this.textAreaRef)}
            rows="1"
            @input=${this.handleInput}
            @keydown=${this.handleKeyDown}
            @focus=${this.expandTextArea}
            @blur=${this.collapseTextArea}
            placeholder=${this.i18n.t('ask-follow-up')}
            aria-label=${this.i18n.t('ask-follow-up')}
          ></textarea>
        </div>
        ${(0, external_button_cjs_namespaceObject.renderButton)({
            props: {
                style: 'primary',
                part: 'submit-button',
                class: 'absolute right-1 bottom-1 flex h-8 w-8 items-center justify-center rounded-md disabled:bg-primary/60 disabled:opacity-100',
                type: 'button',
                disabled: this.submitButtonDisabled,
                ariaLabel: this.i18n.t('submit-follow-up'),
                onClick: ()=>this.handleSubmit()
            }
        })((0, external_lit_namespaceObject.html)`<svg
            class="h-4 w-4"
            viewBox="0 0 20 20"
            fill="currentColor"
            part="submit-icon"
          >
            <path
              fill-rule="evenodd"
              d="M10 17a.75.75 0 01-.75-.75V5.612L5.29 9.77a.75.75 0 01-1.08-1.04l5.25-5.5a.75.75 0 011.08 0l5.25 5.5a.75.75 0 11-1.08 1.04L10.75 5.612V16.25A.75.75 0 0110 17z"
              clip-rule="evenodd"
            />
          </svg>`)}
      </div>
    `;
    }
    constructor(...args){
        super(...args), this.submitButtonDisabled = false, this.isSubmitting = false, this.textAreaRef = (0, ref_js_namespaceObject.createRef)();
    }
}
AtomicAskFollowUpInput.styles = external_atomic_ask_follow_up_input_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: false
    }),
    _ts_metadata("design:type", Boolean)
], AtomicAskFollowUpInput.prototype, "submitButtonDisabled", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: false
    }),
    _ts_metadata("design:type", "u" < typeof i18n ? Object : i18n)
], AtomicAskFollowUpInput.prototype, "i18n", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: false
    }),
    _ts_metadata("design:type", Function)
], AtomicAskFollowUpInput.prototype, "askFollowUp", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Boolean)
], AtomicAskFollowUpInput.prototype, "isSubmitting", void 0);
AtomicAskFollowUpInput = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-ask-follow-up-input'),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicAskFollowUpInput);
exports.AtomicAskFollowUpInput = __webpack_exports__.AtomicAskFollowUpInput;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicAskFollowUpInput"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
