import { h } from "@stencil/core";
import { UtilBreakpointObserverBreakpoints, TitleLogoVariation } from "../../../enums";
/**
 * @enums UtilBreakpointObserverBreakpoints - util-breakpoint-observer-breakpoints.enum.ts
 * @enums TitleLogoVariation - title-logo-variation.enum.ts
 * @swedishName Titellogotyp
 * @new
 */
export class TitleLogo {
    constructor() {
        this.handleWindowResize = () => {
            this.titleLogoVariation = this.setLogoVariation(window.innerWidth);
        };
        this.isMobile = undefined;
        this.isTablet = undefined;
        this.titleLogoVariation = undefined;
        this.afAriaLabel = undefined;
        this.afLogoBreakpoint = undefined;
    }
    setLogoVariation(width) {
        if (this.isMobile)
            return TitleLogoVariation.MOBILE;
        const isNarrow = this.afLogoBreakpoint
            ? width < this.afLogoBreakpoint
            : this.isTablet;
        if (isNarrow) {
            return this.hasTwoRowLogoName
                ? TitleLogoVariation.TWO_ROWS
                : TitleLogoVariation.ONE_ROW;
        }
        return this.hasOneRowLogoName
            ? TitleLogoVariation.ONE_ROW
            : TitleLogoVariation.TWO_ROWS;
    }
    /**
     * Find out if we have one or both of the possible logo variations
     * Throw an error if we have none
     */
    componentWillLoad() {
        this.hasOneRowLogoName = !!this.hostElement.querySelector('[slot="logo-one-row"]');
        this.hasTwoRowLogoName = !!this.hostElement.querySelector('[slot="logo-two-rows"]');
        if (!this.hasOneRowLogoName && !this.hasTwoRowLogoName) {
            throw new Error('Du behöver ange minst en variant av logo-text');
        }
    }
    /**
     * We need a custom resize listener here, since we're
     * not only relying on breakpoints
     */
    componentDidLoad() {
        if (window) {
            this.handleWindowResize();
            window.addEventListener('resize', this.handleWindowResize, { passive: true });
        }
    }
    /**
     * Let's clean up as well
     */
    disconnectedCallback() {
        if (window) {
            window.removeEventListener('resize', this.handleWindowResize);
        }
    }
    handleBreakpointObserver(e) {
        this.isMobile = e.detail.value === UtilBreakpointObserverBreakpoints.SMALL;
        this.isTablet = e.detail.value === UtilBreakpointObserverBreakpoints.MEDIUM;
    }
    get cssModifiers() {
        return {
            'digi-title-logo--mobile': this.titleLogoVariation === TitleLogoVariation.MOBILE,
            'digi-title-logo--one-row': this.titleLogoVariation === TitleLogoVariation.ONE_ROW,
            'digi-title-logo--two-rows': this.titleLogoVariation === TitleLogoVariation.TWO_ROWS
        };
    }
    render() {
        return (h("div", { key: '3529ae2c761883716e7ef698ea2ce35f70108bb9', class: Object.assign({ 'digi-title-logo': true }, this.cssModifiers) }, h("digi-util-breakpoint-observer", { key: '5404aac52451d6041e5a6e60d430b6d81a24a63f', onAfOnChange: (e) => this.handleBreakpointObserver(e) }), h("div", { key: 'f417c914c65d6898d34187a1aa3f31e9c7137bf2', class: "digi-title-logo-symbol" }, h("svg", { key: '6d3a73a4b112f93af24d2bee57278380d7f1ab4e', viewBox: "0 0 44 44", fill: "none", xmlns: "http://www.w3.org/2000/svg", role: "img" }, h("path", { key: 'eee432df3edbb799bc79dd4b47521499ed73ce39', "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M15.0076 6.97426V0C31.0194 0 44 12.9056 44 28.8261C44 34.3951 42.4073 39.5923 39.6561 44L33.8019 40.1595C35.822 36.8551 36.9855 32.9758 36.9855 28.8261C36.9855 16.7575 27.1458 6.97426 15.0076 6.97426ZM6.99059 28.8257C6.99059 33.2284 10.5795 36.7972 15.0076 36.7972C19.4356 36.7972 23.0245 33.2284 23.0245 28.8257C23.0245 24.4235 19.4356 20.8548 15.0076 20.8548C10.5795 20.8548 6.99059 24.4235 6.99059 28.8257ZM0 28.8257C0 20.5853 6.71916 13.9047 15.0076 13.9047C23.296 13.9047 30.0151 20.5853 30.0151 28.8257C30.0151 37.0666 23.296 43.7472 15.0076 43.7472C6.71916 43.7472 0 37.0666 0 28.8257Z", class: "main-symbol" }))), h("div", { key: 'd4367443a500da7d0767c1525ca5af1704ff13d7', class: "digi-title-logo-name-wrapper" }, h("slot", { key: 'f508b45dc39f72a2ec5626a8bc5d550a61c2a43c', name: "logo-one-row" }), h("slot", { key: 'faa09969cd0a8149e58bcf93a065c5956c766477', name: "logo-two-rows" }))));
    }
    static get is() { return "digi-title-logo"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "$": ["title-logo.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["title-logo.css"]
        };
    }
    static get properties() {
        return {
            "afAriaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Input aria-label attribute"
                        }],
                    "text": "S\u00E4tter attributet 'aria-label' p\u00E5 titellogotypen"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-aria-label",
                "reflect": false
            },
            "afLogoBreakpoint": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "en",
                            "text": "Decides at which screen size the title logo changes from one to two rows"
                        }],
                    "text": "Best\u00E4mmer vid vilken sk\u00E4rmbredd som titellogotypen \u00E4ndras fr\u00E5n en till tv\u00E5 rader"
                },
                "getter": false,
                "setter": false,
                "attribute": "af-logo-breakpoint",
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "isMobile": {},
            "isTablet": {},
            "titleLogoVariation": {}
        };
    }
    static get elementRef() { return "hostElement"; }
}
