import { buildProductListing, buildSearch } from "@coveo/headless/commerce";
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 AtomicCommerceNoProducts extends LitElement {
    initialize() {
        const controller = 'search' === this.bindings.interfaceElement.type ? buildSearch(this.bindings.engine) : buildProductListing(this.bindings.engine);
        this.summary = controller.summary();
    }
    render() {
        const { bindings: { i18n } } = this;
        const query = 'query' in this.summaryState ? this.summaryState.query : '';
        this.ariaMessage.message = getSummary(i18n, query, this.summary.state.hasProducts, 'no-products');
        return html`${noItemsGuard({
            isLoading: this.summaryState.isLoading,
            firstSearchExecuted: this.summaryState.firstRequestExecuted,
            hasResults: this.summaryState.hasProducts
        }, ()=>renderNoItemsContainer()(html`
          ${renderMagnifyingGlass()} ${this.renderNoItems()}
          ${this.renderSearchTips()}
        `))}`;
    }
    renderNoItems() {
        return renderNoItems({
            props: {
                query: 'query' in this.summaryState ? this.summaryState.query : '',
                i18n: this.bindings.i18n,
                i18nKey: 'no-products'
            }
        });
    }
    renderSearchTips() {
        return renderSearchTips({
            props: {
                i18n: this.bindings.i18n
            }
        });
    }
    constructor(...args){
        super(...args), this.ariaMessage = new AriaLiveRegionController(this, 'no-products');
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicCommerceNoProducts.prototype, "bindings", void 0);
_ts_decorate([
    bindStateToController('summary'),
    state(),
    _ts_metadata("design:type", Object)
], AtomicCommerceNoProducts.prototype, "summaryState", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicCommerceNoProducts.prototype, "error", void 0);
_ts_decorate([
    bindingGuard(),
    errorGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicCommerceNoProducts.prototype, "render", null);
AtomicCommerceNoProducts = _ts_decorate([
    customElement('atomic-commerce-no-products'),
    bindings(),
    withTailwindStyles
], AtomicCommerceNoProducts);
export { AtomicCommerceNoProducts };
