/* eslint-disable @typescript-eslint/no-explicit-any */
import { h, Host } from "@stencil/core";
/**
 * @slot default - Ska vara en textnod
 * @slot icon - Ska vara en ikon (eller en ikonlik) komponent
 *
 * @swedishName Länk
 */
export class Link {
    constructor() {
        this.hasIcon = undefined;
        this.relation = undefined;
        this.afHref = undefined;
        this.afDescribedby = undefined;
        this.afAriaLabel = undefined;
        this.afTarget = undefined;
        this.afOverrideLink = false;
        this.afLinkContainer = false;
        this.hideVisitedColor = undefined;
        this.afDownload = undefined;
    }
    async afMGetLinkElement() {
        if (this.afLinkContainer) {
            return this.hostElement.children.length > 0
                ? this.hostElement.children.item(0)
                : undefined;
        }
        return this._link;
    }
    clickLinkHandler(e) {
        if (this.afOverrideLink) {
            e.preventDefault();
        }
        this.afOnClick.emit(e);
    }
    setRel() {
        var _a;
        this.relation =
            ((_a = this.afTarget) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === '_blank' ? 'noopener noreferrer' : null;
    }
    setHasIcon() {
        this.hasIcon = !!this.hostElement.querySelector('[slot="icon"]');
    }
    componentWillLoad() {
        this.setHasIcon();
        this.setRel();
    }
    componentWillUpdate() {
        this.setHasIcon();
        this.setRel();
    }
    componentDidLoad() {
        this.afOnReady.emit();
    }
    get cssModifiers() {
        return {
            'digi-link--has-icon': this.hasIcon,
            'digi-link--hide-visited': this.hideVisitedColor
        };
    }
    render() {
        return (h(Host, { key: '4ee4404f8d6d0b1b94671fda57e6b50ddccbd352', class: Object.assign({ 'digi-link': true }, this.cssModifiers) }, !this.afLinkContainer && (h("a", { key: '6524be94c4ec907ed6955ddf7da8c7aaaad18eac', href: this.afHref, onClick: (e) => this.clickLinkHandler(e), target: this.afTarget, rel: this.relation, ref: (el) => (this._link = el), "aria-describedby": this.afDescribedby, "aria-label": this.afAriaLabel, download: this.afDownload }, this.hasIcon && (h("div", { key: '20a853c07f6caf088c40d8c9ef8b80840017d5f8', class: "digi-link__icon-wrapper", "aria-hidden": "true" }, h("slot", { key: 'b9dd777361252aa876ff5db52435bb794a2f2228', name: "icon" }))), h("slot", { key: '498b649a1207efe49d65848cf991fb5a9a9569b8' }))), this.afLinkContainer && h("slot", { key: 'c60ef08fda6a2b5ffc899e59a78949031985b67a' })));
    }
    static get is() { return "digi-link"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "$": ["link.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["link.css"]
        };
    }
    static get properties() {
        return {
            "afHref": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set `href` attribute."
                        }],
                    "text": "S\u00E4tter attributet 'href'."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-href",
                "reflect": false
            },
            "afDescribedby": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Sets `aria-describedby` attribute."
                        }],
                    "text": "S\u00E4tter attributet 'aria-describedby'."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-describedby",
                "reflect": false
            },
            "afAriaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Sets `aria-label` attribute."
                        }],
                    "text": "S\u00E4tter attributet 'aria-label'."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-aria-label",
                "reflect": false
            },
            "afTarget": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set `target` attribute. If value is '_blank', the component automatically adds a 'ref' attribute with 'noopener noreferrer'."
                        }],
                    "text": "S\u00E4tter attributet 'target'. Om v\u00E4rdet \u00E4r '_blank' s\u00E5 l\u00E4gger komponenten automatikt till ett \u00B4ref\u00B4-attribut med 'noopener noreferrer'."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-target",
                "reflect": false
            },
            "afOverrideLink": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Override default link behavior. Should only be used if default link behaviour is a problem with e.g. routing"
                        }],
                    "text": "Kringg\u00E5r l\u00E4nkens vanliga beteende.\nB\u00F6r endast anv\u00E4ndas om det vanliga beteendet \u00E4r problematiskt pga dynamisk routing eller liknande."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-override-link",
                "reflect": false,
                "defaultValue": "false"
            },
            "afLinkContainer": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Set to true if using Angular"
                        }],
                    "text": "S\u00E4tt till true om du anv\u00E4nder Angular, se exempelkod under '\u00D6versikt'"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-link-container",
                "reflect": false,
                "defaultValue": "false"
            },
            "hideVisitedColor": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "If link color should change when visited"
                        }],
                    "text": "Avg\u00F6r om f\u00E4rgen inte ska \u00E4ndras p\u00E5 bes\u00F6kta l\u00E4nkar"
                },
                "getter": false,
                "setter": false,
                "attribute": "hide-visited-color",
                "reflect": false
            },
            "afDownload": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Use when the link is used to download a file. The attribute becomes tha name of the downloaded file."
                        }],
                    "text": "Ska anv\u00E4ndas n\u00E4r l\u00E4nken laddar ner en fil. Attributet blir namnet p\u00E5 filen som laddas ner."
                },
                "getter": false,
                "setter": false,
                "attribute": "af-download",
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "hasIcon": {},
            "relation": {}
        };
    }
    static get events() {
        return [{
                "method": "afOnClick",
                "name": "afOnClick",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "The link element's 'onclick' event."
                        }],
                    "text": "L\u00E4nkelementets 'onclick'-event."
                },
                "complexType": {
                    "original": "MouseEvent",
                    "resolved": "MouseEvent",
                    "references": {
                        "MouseEvent": {
                            "location": "global",
                            "id": "global::MouseEvent"
                        }
                    }
                }
            }, {
                "method": "afOnReady",
                "name": "afOnReady",
                "bubbles": false,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "When the component and slots are loaded and initialized this event will trigger."
                        }],
                    "text": "N\u00E4r komponenten och slotsen \u00E4r laddade och initierade s\u00E5 skickas detta eventet."
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }];
    }
    static get methods() {
        return {
            "afMGetLinkElement": {
                "complexType": {
                    "signature": "() => Promise<any>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<any>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "hostElement"; }
    static get watchers() {
        return [{
                "propName": "afTarget",
                "methodName": "setRel"
            }];
    }
}
