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