import { h } from "@stencil/core";
export class EclLink {
    constructor() {
        this.inverted = false;
        this.variant = '';
        this.branded = false;
        this.external = false;
        this.hideLabel = false;
        this.download = false;
        this.indicator = false;
    }
    getClass() {
        const styleClasses = [
            `ecl-link`,
            this.styleClass
        ];
        if (this.variant) {
            styleClasses.push(`ecl-link--${this.variant}`);
        }
        if (this.inverted) {
            styleClasses.push('ecl-link--inverted');
        }
        if (this.branded) {
            styleClasses.push('ecl-link--brand');
        }
        if (this.hideLabel) {
            styleClasses.push('ecl-link--icon-only');
        }
        if (this.el.querySelector('ecl-icon')) {
            styleClasses.push('ecl-link--icon');
            if (this.el.querySelector('ecl-icon').getAttribute('slot') === 'icon-after') {
                styleClasses.push('ecl-link--icon-after');
            }
            else {
                styleClasses.push('ecl-link--icon-before');
            }
        }
        return styleClasses.join(' ');
    }
    componentWillLoad() {
        var _a;
        this.theme = (_a = document.documentElement.getAttribute('data-ecl-theme')) !== null && _a !== void 0 ? _a : (this.theme || 'ec');
    }
    componentDidLoad() {
        const dataAttrs = Object.keys(this.el.dataset);
        if (dataAttrs) {
            dataAttrs.forEach((attr) => {
                const link = this.el.firstElementChild;
                link.dataset[attr] = '';
                delete this.el.dataset[attr];
            });
        }
        const attributes = this.el.attributes;
        Array.from(attributes).forEach((attr) => {
            if (attr.name.startsWith('aria-')) {
                this.el.querySelector('.ecl-link').setAttribute(attr.name, attr.value);
            }
        });
        if (this.el.querySelector('ecl-icon')) {
            this.el.querySelector('ecl-icon').classList.add('ecl-link__icon');
        }
    }
    getExternal() {
        return (h("ecl-icon", { icon: "external", "style-class": `ecl-link__icon sc-ecl-link-${this.theme}`, size: "2xs", "title-tag": this.srExternal }));
    }
    getAttrs() {
        const attrs = {
            'class': this.getClass(),
            'href': this.path,
        };
        if (this.elId) {
            attrs['id'] = this.elId;
        }
        if (this.titleAttr) {
            attrs['title'] = this.titleAttr;
        }
        if (this.download) {
            attrs['download'] = true;
        }
        if (this.ariaLabel && !this.external) {
            attrs['aria-label'] = this.ariaLabel;
        }
        if (this.target) {
            attrs['target'] = this.target;
        }
        return attrs;
    }
    get hasIconBefore() {
        return !!this.el.querySelector('[slot="icon-before"]');
    }
    get hasIconAfter() {
        return !!this.el.querySelector('[slot="icon-after"]');
    }
    render() {
        return (h("a", Object.assign({ key: '43d3a3e2795aec579bbebf77e2e59276bd1ac6d2' }, this.getAttrs()), this.hasIconBefore && !this.indicator && (h("slot", { key: '33a84e832a8676ab149f03a5e9dd871e9a2c335f', name: "icon-before" })), this.indicator && this.hasIconBefore && (h("span", { key: '301612af1925322ca0220843b9a2e2d733a14e36', class: "ecl-link__icon-container" }, h("slot", { key: 'a2bda9ae4c497110b18e8405e0d2d67598ef20df', name: "icon-before" }), h("ecl-indicator", { key: '73789cd38fa2ecf49b4479359aa5848151d9240d', value: this.indicatorValue, "sr-label": this.indicatorLabel }))), (this.hasIconBefore || this.hasIconAfter) ?
            h("span", { class: "ecl-link__label" }, h("slot", null)) : h("slot", null), (this.external || (this.hasIconAfter && !this.indicator)) && (h("slot", { key: '99a6f42508d46f70ffede4484844e62448a69dd8', name: "icon-after" }, this.external ? this.getExternal() : '')), this.indicator && this.hasIconAfter && (h("span", { key: 'f25140e61a1fc0e1ab2090b850eb6829201ab845', class: "ecl-link__icon-container" }, h("slot", { key: '8d7be685fbed0705018810379e0cce48d595d95a', name: "icon-after" }), h("ecl-indicator", { key: '06b10fab807e6d5ba6db40c2e575b216ca61ed1b', value: this.indicatorValue, "sr-label": this.indicatorLabel })))));
    }
    static get is() { return "ecl-link"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-link-ec.css"],
            "eu": ["./build/styles/ecl-link-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-link-ec.css"],
            "eu": ["build/styles/ecl-link-eu.css"]
        };
    }
    static get assetsDirs() { return ["build"]; }
    static get properties() {
        return {
            "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"
            },
            "path": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "path"
            },
            "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"
            },
            "elId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "el-id"
            },
            "inverted": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "inverted",
                "defaultValue": "false"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "variant",
                "defaultValue": "''"
            },
            "titleAttr": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "title-attr"
            },
            "branded": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "branded",
                "defaultValue": "false"
            },
            "external": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "external",
                "defaultValue": "false"
            },
            "hideLabel": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "hide-label",
                "defaultValue": "false"
            },
            "ariaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "aria-label"
            },
            "srExternal": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "sr-external"
            },
            "name": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "name"
            },
            "target": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "target"
            },
            "download": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download",
                "defaultValue": "false"
            },
            "indicator": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "indicator",
                "defaultValue": "false"
            },
            "indicatorValue": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "indicator-value"
            },
            "indicatorLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "indicator-label"
            }
        };
    }
    static get elementRef() { return "el"; }
}
