import { buildQuerySummary, buildSearchStatus } from "@coveo/headless/insight";
import { LitElement, html } from "lit";
import { customElement, state } from "lit/decorators.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 { AriaLiveRegionController } from "../../../utils/accessibility-utils.js";
import { renderNoItemsContainer } from "../../common/no-items/container.js";
import { noItemsGuard } from "../../common/no-items/guard.js";
import { renderMagnifyingGlass } from "../../common/no-items/magnifying-glass.js";
import { renderNoItems } from "../../common/no-items/no-items.js";
import { renderSearchTips } from "../../common/no-items/tips.js";
import { getSummary } from "../../common/no-items/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 AtomicInsightNoResults extends LitElement {
    initialize() {
        this.searchStatus = buildSearchStatus(this.bindings.engine);
        this.querySummary = buildQuerySummary(this.bindings.engine);
    }
    render() {
        const { bindings: { i18n } } = this;
        this.ariaMessage.message = getSummary(i18n, this.querySummaryState.query, this.searchStatusState.hasResults, 'no-results');
        return html`${noItemsGuard({
            isLoading: this.searchStatusState.isLoading,
            firstSearchExecuted: this.searchStatusState.firstSearchExecuted,
            hasResults: this.searchStatusState.hasResults
        }, ()=>renderNoItemsContainer()(html`
          ${renderMagnifyingGlass()} ${this.renderNoItems()}
          ${this.renderSearchTips()}
        `))}`;
    }
    renderNoItems() {
        return renderNoItems({
            props: {
                query: this.querySummaryState.query,
                i18n: this.bindings.i18n,
                i18nKey: 'no-results'
            }
        });
    }
    renderSearchTips() {
        return renderSearchTips({
            props: {
                i18n: this.bindings.i18n
            }
        });
    }
    constructor(...args){
        super(...args), this.ariaMessage = new AriaLiveRegionController(this, 'no-results');
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightNoResults.prototype, "bindings", void 0);
_ts_decorate([
    bindStateToController('searchStatus'),
    state(),
    _ts_metadata("design:type", "u" < typeof SearchStatusState ? Object : SearchStatusState)
], AtomicInsightNoResults.prototype, "searchStatusState", void 0);
_ts_decorate([
    bindStateToController('querySummary'),
    state(),
    _ts_metadata("design:type", "u" < typeof QuerySummaryState ? Object : QuerySummaryState)
], AtomicInsightNoResults.prototype, "querySummaryState", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightNoResults.prototype, "error", void 0);
_ts_decorate([
    bindingGuard(),
    errorGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightNoResults.prototype, "render", null);
AtomicInsightNoResults = _ts_decorate([
    customElement('atomic-insight-no-results'),
    bindings(),
    withTailwindStyles
], AtomicInsightNoResults);
export { AtomicInsightNoResults };
