import { h } from "@stencil/core";
import ContentBlock from "@ecl/content-block";
export class EclContentBlock {
    constructor() {
        this.styleClass = '';
        this.noScript = false;
        this.metaSecondaryDir = 'vertical';
    }
    getClass() {
        return [
            `ecl-content-block`,
            this.styleClass
        ].join(' ');
    }
    componentWillLoad() {
        var _a;
        this.theme = (_a = document.documentElement.getAttribute('data-ecl-theme')) !== null && _a !== void 0 ? _a : (this.theme || 'ec');
    }
    componentDidLoad() {
        if (this.hasTitle) {
            const titleLink = this.el.querySelector('.ecl-content-block__title .ecl-link');
            if (titleLink) {
                titleLink.setAttribute('data-ecl-title-link', "");
            }
        }
        if (this.hasLabels) {
            const labelsContainer = this.el.querySelector('.ecl-content-block__label-container');
            const labels = this.el.querySelectorAll('.ecl-label');
            if (labels) {
                labelsContainer.innerHTML = '';
                labels.forEach((label) => {
                    label.classList.add(`sc-ecl-content-block-${this.theme}`);
                    const listEl = document.createElement('li');
                    listEl.classList.add('ecl-content-block__label-item', `sc-ecl-content-block-${this.theme}`);
                    listEl.appendChild(label);
                    labelsContainer.appendChild(listEl);
                });
            }
        }
        if (this.hasLinks) {
            const linksContainers = this.el.querySelectorAll('.ecl-content-block__link-list');
            linksContainers.forEach((linkList) => {
                const thisLinks = linkList.querySelectorAll('.ecl-link');
                if (thisLinks) {
                    linkList.innerHTML = '';
                    thisLinks.forEach((link) => {
                        link.classList.add(`sc-ecl-content-block-${this.theme}`);
                        const listEl = document.createElement('li');
                        listEl.classList.add('ecl-content-block__link-item', `sc-ecl-content-block-${this.theme}`);
                        listEl.appendChild(link);
                        linkList.appendChild(listEl);
                    });
                }
            });
        }
        if (this.hasLists) {
            const list = this.el.querySelector('.ecl-content-block__list-container .ecl-description-list');
            if (list) {
                list.classList.add('ecl-content-block__list', `sc-ecl-content-block-${this.theme}`);
            }
        }
        if (!this.noScript) {
            ;
            window.ECL = window.ECL || {};
            ECL.ContentBlock = ContentBlock;
            const contentBlock = new ContentBlock(this.el);
            contentBlock.init();
        }
    }
    render() {
        const metaPrimaryArray = this.metaPrimary ? JSON.parse(this.metaPrimary) : '';
        const metaSecondaryArray = this.metaSecondary ? JSON.parse(this.metaSecondary) : '';
        return (h("div", { key: '22005ec634534bf7db9de576a853f22677de7667', class: this.getClass() }, this.hasLabels &&
            h("ul", { key: '9a5997330f7da15741c6ba20982d460be41915e4', class: "ecl-content-block__label-container" }, h("slot", { key: '68aaccd4dba988e099674572027acd0aafe46a61', name: "labels" })), metaPrimaryArray &&
            h("ul", { key: '8f511308aa18d963e45a5ac29adf27303de0c9bc', class: "ecl-content-block__primary-meta-container" }, metaPrimaryArray.map((meta) => (h("li", { class: "ecl-content-block__primary-meta-item" }, meta)))), this.hasTitle &&
            h("div", { key: '7080f5d51172597fc8f0abb2b98c6cce5c528819', class: "ecl-content-block__title" }, h("slot", { key: '52d9c0838b7f6c8cf5c4edd5e30d1dd5557440f1', name: "title" })), this.hasDescription &&
            h("div", { key: '1dd5562cccf23e8a99bb6ec23f86f4c9e0eaf504', class: "ecl-content-block__description" }, h("slot", { key: '9dfbf270ecaf6700ceb72fb0628158243e121b4f', name: "description" })), metaSecondaryArray &&
            h("ul", { key: 'a434f7b3fcd259f27a035f302f8562c424942e79', class: `ecl-content-block__secondary-meta-container ${this.metaSecondaryDir === 'horizontal' ? 'ecl-content-block__secondary-meta-container--horizontal' : ''}` }, metaSecondaryArray.map((meta) => (h("li", { class: "ecl-content-block__secondary-meta-item" }, meta.icon &&
                h("ecl-icon", { icon: meta.icon, size: "s", "style-class": `ecl-content-block__secondary-meta-icon sc-ecl-content-block-${this.theme}` }), meta.label &&
                h("span", { class: "ecl-content-block__secondary-meta-label" }, meta.label))))), this.hasLists &&
            h("div", { key: 'e9823b201b40f6ef7e0ddaebfb66e11c13d05e82', class: "ecl-content-block__list-container" }, h("slot", { key: '8d1e3509091d2fe942a0021268b1984581da69e5', name: "lists" })), this.hasLinks &&
            h("div", { key: '2b4de75ace3d13098e5517f69046db2762e59489', class: "ecl-content-block__link-container" }, h("ul", { key: '12c36d2c1e7eccd8d3a9e4326b59cde3638ef231', class: "ecl-content-block__link-list" }, h("slot", { key: '3cdc8039d32ced8bec1fcdd50951782b50683a8a', name: "links" })), this.hasSecondaryLinks &&
                h("ul", { key: 'e5132e032bdc12e221c90f0d617366ddf67a9dc9', class: "ecl-content-block__link-list" }, h("slot", { key: '54c35f37dacb41ce0980da0abf586e68a2b6aa12', name: "links-secondary" })))));
    }
    static get is() { return "ecl-content-block"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-content-block-ec.css"],
            "eu": ["./build/styles/ecl-content-block-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-content-block-ec.css"],
            "eu": ["build/styles/ecl-content-block-eu.css"]
        };
    }
    static get assetsDirs() { return ["build"]; }
    static get properties() {
        return {
            "styleClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "style-class",
                "defaultValue": "''"
            },
            "theme": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "theme"
            },
            "hasDescription": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-description"
            },
            "noScript": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "no-script",
                "defaultValue": "false"
            },
            "hasTitle": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-title"
            },
            "hasLabels": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-labels"
            },
            "hasLinks": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-links"
            },
            "hasSecondaryLinks": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-secondary-links"
            },
            "hasLists": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "has-lists"
            },
            "metaPrimary": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "meta-primary"
            },
            "metaSecondary": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "meta-secondary"
            },
            "metaSecondaryDir": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "meta-secondary-dir",
                "defaultValue": "'vertical'"
            }
        };
    }
    static get elementRef() { return "el"; }
}
