import { ResultTemplatesHelpers } from "@coveo/headless";
import { LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { ResultTemplateController } from "../../common/result-templates/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";
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 AtomicResultChildrenTemplate extends LitElement {
    connectedCallback() {
        super.connectedCallback();
        this.resultTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch, ResultTemplatesHelpers);
    }
    render() {
        return nothing;
    }
    async getTemplate() {
        return this.resultTemplateController?.getTemplate(this.conditions) || null;
    }
    constructor(){
        super(), this.conditions = [];
        this.resultTemplateController = new ResultTemplateController(this, [
            'atomic-result-children'
        ], false);
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicResultChildrenTemplate.prototype, "error", void 0);
_ts_decorate([
    property({
        attribute: false,
        type: Array,
        converter: arrayConverter
    }),
    _ts_metadata("design:type", Array)
], AtomicResultChildrenTemplate.prototype, "conditions", void 0);
_ts_decorate([
    mapProperty({
        splitValues: true,
        attributePrefix: 'must-match'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicResultChildrenTemplate.prototype, "mustMatch", void 0);
_ts_decorate([
    mapProperty({
        splitValues: true,
        attributePrefix: 'must-not-match'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicResultChildrenTemplate.prototype, "mustNotMatch", void 0);
_ts_decorate([
    errorGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicResultChildrenTemplate.prototype, "render", null);
AtomicResultChildrenTemplate = _ts_decorate([
    customElement('atomic-result-children-template'),
    withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicResultChildrenTemplate);
export { AtomicResultChildrenTemplate };
