"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__, {
    AtomicAgentStreamOfThought: ()=>AtomicAgentStreamOfThought,
    resolveSteps: ()=>resolveSteps
});
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const class_map_js_namespaceObject = require("lit/directives/class-map.js");
const map_js_namespaceObject = require("lit/directives/map.js");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const external_atomic_agent_stream_of_thought_tw_css_cjs_namespaceObject = require("./atomic-agent-stream-of-thought.tw.css.cjs");
var external_atomic_agent_stream_of_thought_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_agent_stream_of_thought_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);
}
const stepLabelKeys = {
    'thinking-before-search': {
        active: 'agent-generation-step-analyzing-question',
        completed: 'agent-generation-step-analyzing-question-completed'
    },
    searching: {
        active: 'agent-generation-step-search',
        completed: 'agent-generation-step-search-completed'
    },
    'thinking-after-search': {
        active: 'agent-generation-step-analyzing-results',
        completed: 'agent-generation-step-analyzing-results-completed'
    },
    answering: {
        active: 'agent-generation-step-answering',
        completed: 'agent-generation-step-answering-completed'
    }
};
class AtomicAgentStreamOfThought extends external_lit_namespaceObject.LitElement {
    willUpdate(changed) {
        if (changed.has('isStreaming')) this.expanded = this.isStreaming;
    }
    render() {
        const resolvedSteps = resolveSteps(this.agentSteps);
        if (0 === resolvedSteps.length) return external_lit_namespaceObject.nothing;
        const isComplete = !this.isStreaming;
        const isCollapsible = resolvedSteps.length > 1;
        if (isComplete && !this.expanded && isCollapsible) return (0, external_lit_namespaceObject.html)`
        <div class="timeline">${this.renderCollapsedTimelineSummary()}</div>
      `;
        return (0, external_lit_namespaceObject.html)`
      <div class="timeline">
        ${(0, map_js_namespaceObject.map)(resolvedSteps, (step)=>this.renderStep(step))}
        ${isComplete && isCollapsible ? this.renderToggleButton() : external_lit_namespaceObject.nothing}
      </div>
    `;
    }
    renderStep(step) {
        const labelKey = 'active' === step.status ? stepLabelKeys[step.type].active : stepLabelKeys[step.type].completed;
        const label = this.i18n.t(labelKey);
        return (0, external_lit_namespaceObject.html)`
      <div class="step">
        ${'active' === step.status ? this.renderSpinner() : this.renderCheckmark()}
        <span class="step-label">${label}</span>
      </div>
    `;
    }
    renderCollapsedTimelineSummary() {
        const resolvedSteps = resolveSteps(this.agentSteps);
        if (0 === resolvedSteps.length) return external_lit_namespaceObject.nothing;
        const step = resolvedSteps[resolvedSteps.length - 1];
        const labelKey = stepLabelKeys[step.type].completed;
        const label = this.i18n.t(labelKey);
        return (0, external_lit_namespaceObject.html)`
      <button
        class="collapsed-timeline-summary"
        @click=${this.handleToggle}
        aria-expanded=${this.expanded}
        type="button"
      >
        ${this.renderCheckmark()}
        <span class="step-label">${label}</span>
        ${this.renderChevron()}
      </button>
    `;
    }
    renderToggleButton() {
        return (0, external_lit_namespaceObject.html)`
      <button
        class="toggle-button"
        @click=${this.handleToggle}
        aria-expanded=${this.expanded}
        type="button"
      >
        <span class="toggle-label">${this.i18n.t('collapse')}</span>
        ${this.renderChevron()}
      </button>
    `;
    }
    renderSpinner() {
        return (0, external_lit_namespaceObject.html)`<span class="step-icon"
      ><span class="spinner" aria-hidden="true"></span
    ></span>`;
    }
    renderCheckmark() {
        return (0, external_lit_namespaceObject.html)`
      <span class="step-icon checkmark-icon">
        <svg
          width="12"
          height="9"
          viewBox="0 0 12 9"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
          aria-hidden="true"
        >
          <path
            d="M1 4.33333L4.33333 7.66667L11 1"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
          />
        </svg>
      </span>
    `;
    }
    renderChevron() {
        return (0, external_lit_namespaceObject.html)`
      <span class=${(0, class_map_js_namespaceObject.classMap)({
            chevron: true,
            'chevron-up': this.expanded
        })}>
        <svg
          width="11"
          height="6"
          viewBox="0 0 11 6"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
          aria-hidden="true"
        >
          <path
            d="M1.18998 0.52682L5.43262 4.76946L9.67526 0.526821"
            stroke="currentColor"
            stroke-linecap="round"
            stroke-linejoin="round"
          />
        </svg>
      </span>
    `;
    }
    handleToggle() {
        this.expanded = !this.expanded;
    }
    constructor(...args){
        super(...args), this.agentSteps = [], this.isStreaming = false, this.expanded = true;
    }
}
AtomicAgentStreamOfThought.styles = [
    external_atomic_agent_stream_of_thought_tw_css_cjs_default()
];
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: false
    }),
    _ts_metadata("design:type", "u" < typeof i18n ? Object : i18n)
], AtomicAgentStreamOfThought.prototype, "i18n", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: false
    }),
    _ts_metadata("design:type", Array)
], AtomicAgentStreamOfThought.prototype, "agentSteps", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: false
    })
], AtomicAgentStreamOfThought.prototype, "isStreaming", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicAgentStreamOfThought.prototype, "expanded", void 0);
AtomicAgentStreamOfThought = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-agent-stream-of-thought'),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicAgentStreamOfThought);
function resolveSteps(steps) {
    let searchWasPerformed = false;
    return steps.map((step)=>{
        let type;
        if ('searching' === step.name) {
            searchWasPerformed = true;
            type = 'searching';
        } else type = 'answering' === step.name ? 'answering' : searchWasPerformed ? 'thinking-after-search' : 'thinking-before-search';
        return {
            type,
            status: step.status
        };
    });
}
exports.AtomicAgentStreamOfThought = __webpack_exports__.AtomicAgentStreamOfThought;
exports.resolveSteps = __webpack_exports__.resolveSteps;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicAgentStreamOfThought",
    "resolveSteps"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
