import { h } from "@stencil/core";
import { Fragment } from "@stencil/core";
import SearchResult from "./SearchResult";
export class Category {
    constructor() {
        this.categories = {};
    }
    clearResultsHandler(_state) {
        this.categories = {};
    }
    componentShouldUpdate() {
        // console.log("componentShouldUpdate", this.categoryList)
        if (this.categoryList && this.categoryList.length > 0) {
            /*group by category*/
            let grouped = this.categoryList.reduce((result, currentValue) => {
                ;
                (result[currentValue["category"]] = result[currentValue["category"]] || []).push(currentValue);
                return result;
            }, {});
            this.categories = grouped;
        }
        else {
            this.categories = {};
        }
    }
    render() {
        return Object.entries(this.categories).map(([key, value], _index) => {
            return (h(Fragment, null, h("div", null, h("h1", { class: "custom-title" }, key)), h(SearchResult, { results: value, linkTarget: this.linkTarget })));
        });
    }
    static get is() { return "ai12z-category"; }
    static get originalStyleUrls() {
        return {
            "$": ["category.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["category.css"]
        };
    }
    static get properties() {
        return {
            "categoryList": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "category-list"
            },
            "linkTarget": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "link-target"
            }
        };
    }
    static get listeners() {
        return [{
                "name": "clearResults",
                "method": "clearResultsHandler",
                "target": "document",
                "capture": false,
                "passive": false
            }];
    }
}
