import { buildQuerySummary } from "@coveo/headless/insight";
import { LitElement, css, html } from "lit";
import { customElement, state } from "lit/decorators.js";
import { renderQuerySummaryContainer } from "../../common/query-summary/container.js";
import { renderQuerySummaryGuard } from "../../common/query-summary/guard.js";
import { getQuerySummaryI18nParameters } from "../../common/query-summary/utils.js";
import { bindStateToController } from "../../../decorators/bind-state.js";
import { bindingGuard } from "../../../decorators/binding-guard.js";
import { bindings } from "../../../decorators/bindings.js";
import { errorGuard } from "../../../decorators/error-guard.js";
import { withTailwindStyles } from "../../../decorators/with-tailwind-styles.js";
import { localizedString } from "../../../directives/localized-string.js";
import { InitializeBindingsMixin } from "../../../mixins/bindings-mixin.js";
import { AriaLiveRegionController } from "../../../utils/accessibility-utils.js";
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 AtomicInsightQuerySummary extends InitializeBindingsMixin(LitElement) {
    initialize() {
        this.querySummary = buildQuerySummary(this.bindings.engine);
    }
    render() {
        const { hasError, hasQuery, hasResults, firstSearchExecuted, firstResult, lastResult, isLoading, query, total } = this.querySummaryState;
        const { ariaLiveMessage, highlights, i18nKey } = getQuerySummaryI18nParameters({
            first: firstResult,
            i18n: this.bindings.i18n,
            isLoading,
            last: lastResult,
            query,
            total
        });
        this.ariaMessage.message = ariaLiveMessage;
        if (hasQuery) return html`${renderQuerySummaryGuard({
            props: {
                firstSearchExecuted,
                hasResults,
                hasError
            }
        })(html`
        ${renderQuerySummaryContainer({
            props: {
                additionalClasses: 'px-6 py-4'
            }
        })(html`
          ${localizedString({
            i18n: this.bindings.i18n,
            key: i18nKey,
            params: {
                first: html`${highlights.first}`,
                last: html`${highlights.last}`,
                total: html`${highlights.total}`,
                query: html`${highlights.query}`
            },
            count: total
        })}
        `)}
      `)}`;
        if (hasError) return html``;
        return html`
      <div class="bg-[#F1F2FF] px-6 py-4 text-[#54698D] italic">
        ${this.bindings.i18n.t('insight-related-cases')}
      </div>
    `;
    }
    constructor(...args){
        super(...args), this.ariaMessage = new AriaLiveRegionController(this, 'query-summary');
    }
}
AtomicInsightQuerySummary.styles = [
    css`:host{overflow:hidden}`
];
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightQuerySummary.prototype, "bindings", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightQuerySummary.prototype, "error", void 0);
_ts_decorate([
    bindStateToController('querySummary'),
    state(),
    _ts_metadata("design:type", "u" < typeof QuerySummaryState ? Object : QuerySummaryState)
], AtomicInsightQuerySummary.prototype, "querySummaryState", void 0);
_ts_decorate([
    bindingGuard(),
    errorGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightQuerySummary.prototype, "render", null);
AtomicInsightQuerySummary = _ts_decorate([
    customElement('atomic-insight-query-summary'),
    bindings(),
    withTailwindStyles
], AtomicInsightQuerySummary);
export { AtomicInsightQuerySummary };
