import { h } from "@stencil/core";
import classNames from "classnames";
import { isNestedInIfxComponent } from "../..//shared/utils/dom-utils";
import { detectFramework } from "../..//shared/utils/framework-detection";
import { trackComponent } from "../../shared/utils/tracking";
export class Link {
    el;
    /**
     * URL the link navigates to.
     * @default undefined
     */
    href = undefined;
    /**
     * Target window for the link.
     * @default "_self"
     */
    target = "_self";
    /**
     * Visual style variant of the link.
     * @default "bold"
     */
    variant = "bold";
    /**
     * Font size of the link.
     * @default "m"
     */
    size = "m";
    /**
     * Disables interaction.
     * @default false
     */
    disabled = false;
    /**
     * Optional filename or download hint for the linked resource.
     * @default undefined
     */
    download;
    /**
     * Accessible label announced by assistive technologies.
     * @default undefined
     */
    ariaLabelText;
    internalHref = "";
    internalTarget = "";
    internalVariant = "";
    setInternalStates() {
        if (this.href) {
            this.internalHref = this.href.trim();
        }
        else {
            this.internalHref = undefined;
        }
        this.internalTarget = this.target.trim();
        this.internalVariant = this.variant.trim().toLowerCase();
    }
    componentWillRender() {
        this.setInternalStates();
    }
    async componentDidLoad() {
        if (!isNestedInIfxComponent(this.el)) {
            const framework = detectFramework();
            trackComponent("ifx-link", await framework);
        }
    }
    render() {
        return (h("a", { key: '1f3bedc0c8a1e6e8d8226210c83d386fef692467', tabindex: "0", "aria-label": this.ariaLabelText, "aria-disabled": this.disabled || !this.internalHref, href: this.disabled ? undefined : this.internalHref, download: this.download, target: this.internalTarget, class: this.linkClassNames() }, h("slot", { key: 'b1830a0721c9566301f34ffb089ba5b213530552' })));
    }
    getSizeClass() {
        const small = this.size === "s" ? "small" : null;
        const medium = this.size === "m" ? "medium" : null;
        const large = this.size === "l" ? "large" : null;
        const extraLarge = this.size === "xl" ? "extraLarge" : null;
        if (small) {
            return small;
        }
        else if (medium) {
            return medium;
        }
        else if (large) {
            return large;
        }
        else if (extraLarge && this.internalVariant === "underlined") {
            return "large";
        }
        else if (extraLarge && this.internalVariant !== "underlined") {
            return extraLarge;
        }
        else
            return "";
    }
    getVariantClass() {
        const bold = this.internalVariant === "bold" ? "bold" : null;
        const title = this.internalVariant === "title" ? "title" : null;
        const underlined = this.internalVariant === "underlined" ? "underlined" : null;
        const menu = this.internalVariant === "menu" ? "menu" : null;
        if (bold) {
            return bold;
        }
        else if (title) {
            return title;
        }
        else if (underlined) {
            return underlined;
        }
        else if (menu) {
            return menu;
        }
        else
            return bold;
    }
    linkClassNames() {
        return classNames("link", "primary", this.getVariantClass(), this.getSizeClass(), this.disabled ? "disabled" : "");
    }
    static get is() { return "ifx-link"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["link.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["link.css"]
        };
    }
    static get properties() {
        return {
            "href": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "undefined"
                        }],
                    "text": "URL the link navigates to."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "href",
                "defaultValue": "undefined"
            },
            "target": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "\"_self\""
                        }],
                    "text": "Target window for the link."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "target",
                "defaultValue": "\"_self\""
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "\"underlined\" | \"bold\" | \"title\" | \"menu\"",
                    "resolved": "\"bold\" | \"menu\" | \"title\" | \"underlined\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "\"bold\""
                        }],
                    "text": "Visual style variant of the link."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "variant",
                "defaultValue": "\"bold\""
            },
            "size": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "\"s\" | \"m\" | \"l\" | \"xl\"",
                    "resolved": "\"l\" | \"m\" | \"s\" | \"xl\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "\"m\""
                        }],
                    "text": "Font size of the link."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "size",
                "defaultValue": "\"m\""
            },
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "false"
                        }],
                    "text": "Disables interaction."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "disabled",
                "defaultValue": "false"
            },
            "download": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "undefined"
                        }],
                    "text": "Optional filename or download hint for the linked resource."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download"
            },
            "ariaLabelText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string | null",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "undefined"
                        }],
                    "text": "Accessible label announced by assistive technologies."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "aria-label-text"
            }
        };
    }
    static get states() {
        return {
            "internalHref": {},
            "internalTarget": {},
            "internalVariant": {}
        };
    }
    static get elementRef() { return "el"; }
}
