import { ProductTemplatesHelpers } from "@coveo/headless/commerce";
import { LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { ProductTemplateController } from "../../common/product-template/product-template-controller.js";
import { makeMatchConditions } from "../../common/template-controller/template-utils.js";
import { errorGuard } from "../../../decorators/error-guard.js";
import { mapProperty } from "../../../utils/props-utils.js";
import "../atomic-product/atomic-product.js";
import { arrayConverter } from "../../../converters/array-converter.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 AtomicProductTemplate extends LitElement {
    connectedCallback() {
        super.connectedCallback();
        this.productTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch, ProductTemplatesHelpers);
    }
    async getTemplate() {
        return this.productTemplateController.getTemplate(this.conditions);
    }
    render() {
        return nothing;
    }
    constructor(){
        super(), this.conditions = [];
        const validParent = [
            'atomic-commerce-product-list',
            'atomic-commerce-recommendation-list',
            'atomic-commerce-search-box-instant-products'
        ];
        const allowEmpty = true;
        this.productTemplateController = new ProductTemplateController(this, validParent, allowEmpty);
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicProductTemplate.prototype, "error", void 0);
_ts_decorate([
    property({
        attribute: false,
        type: Array,
        converter: arrayConverter
    }),
    _ts_metadata("design:type", Array)
], AtomicProductTemplate.prototype, "conditions", void 0);
_ts_decorate([
    mapProperty({
        splitValues: true,
        attributePrefix: 'must-match'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicProductTemplate.prototype, "mustMatch", void 0);
_ts_decorate([
    mapProperty({
        splitValues: true,
        attributePrefix: 'must-not-match'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicProductTemplate.prototype, "mustNotMatch", void 0);
_ts_decorate([
    errorGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicProductTemplate.prototype, "render", null);
AtomicProductTemplate = _ts_decorate([
    customElement('atomic-product-template'),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicProductTemplate);
export { AtomicProductTemplate };
