import { ResultTemplatesHelpers } from "@coveo/headless/recommendation";
import { LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { RecsResultTemplateController } from "../../common/result-templates/recs-result-template-controller.js";
import { makeMatchConditions } from "../../common/template-controller/template-utils.js";
import { withTailwindStyles } from "../../../decorators/with-tailwind-styles.js";
import { mapProperty } from "../../../utils/props-utils.js";
import "../../common/atomic-component-error/atomic-component-error.js";
import { arrayConverter } from "../../../converters/array-converter.js";
import { errorGuard } from "../../../decorators/error-guard.js";
import "../atomic-recs-result/atomic-recs-result.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 AtomicRecsResultTemplate extends LitElement {
    connectedCallback() {
        super.connectedCallback();
        this.recsResultTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch, ResultTemplatesHelpers);
    }
    render() {
        return nothing;
    }
    async getTemplate() {
        return this.recsResultTemplateController?.getTemplate(this.conditions) || null;
    }
    constructor(){
        super(), this.conditions = [];
        const validParents = [
            'atomic-recs-list',
            'atomic-ipx-recs-list'
        ];
        const allowEmpty = true;
        this.recsResultTemplateController = new RecsResultTemplateController(this, validParents, allowEmpty);
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicRecsResultTemplate.prototype, "error", void 0);
_ts_decorate([
    property({
        attribute: false,
        type: Array,
        converter: arrayConverter
    }),
    _ts_metadata("design:type", Array)
], AtomicRecsResultTemplate.prototype, "conditions", void 0);
_ts_decorate([
    mapProperty({
        splitValues: true,
        attributePrefix: 'must-match'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicRecsResultTemplate.prototype, "mustMatch", void 0);
_ts_decorate([
    mapProperty({
        splitValues: true,
        attributePrefix: 'must-not-match'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicRecsResultTemplate.prototype, "mustNotMatch", void 0);
_ts_decorate([
    errorGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicRecsResultTemplate.prototype, "render", null);
AtomicRecsResultTemplate = _ts_decorate([
    customElement('atomic-recs-result-template'),
    withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicRecsResultTemplate);
export { AtomicRecsResultTemplate };
