import { __decorate, __metadata } from "tslib";
import { h, Host } from "@stencil/core";
import camelCase from "lodash.camelcase";
import upperFirst from "lodash.upperfirst";
import { BEM } from "../../utils/bem";
import { defaultConfig, ListenToConfig } from "../../utils/config";
import { sanitizeSvg } from "../../utils/svg";
export class Icon {
    constructor() {
        this.icons = defaultConfig.icons;
        this.svgContent = '';
        this.innerColor = '';
        this.innerSize = '';
        /**
         * PUBLIC API
         * ------------------------------------------------------
         */
        /**
         * Name of the baloise icon.
         */
        this.name = undefined;
        /**
         * Svg content.
         */
        this.svg = '';
        /**
         * Defines the size of the icon.
         */
        this.size = '';
        /**
         * The theme type of the button.
         */
        this.color = '';
        this.colorHovered = '';
        this.colorPressed = '';
        /**
         * If `true` the icon acts as a tile with a background color.
         */
        this.tile = false;
        /**
         * If `true` the icon acts as a tile with a background color. Default is purple
         */
        this.tileColor = '';
        /**
         * If `true` the icon has display inline style
         */
        this.inline = false;
        /**
         * If `true` the icon is inverted
         */
        this.inverted = false;
        /**
         * If `true` the icon is rotated 180deg
         */
        this.turn = false;
        /**
         * If `true` adds a box shadow to improve readability on image background
         * */
        this.shadow = false;
        /**
         * If `true`, the element is not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants.
         */
        this.disabled = undefined;
        /**
         * If `true` the component gets a invalid red style.
         */
        this.invalid = undefined;
        /**
         * @internal
         */
        this.hovered = false;
        /**
         * @internal
         */
        this.pressed = false;
        /**
         * PRIVATE METHODS
         * ------------------------------------------------------
         */
        this.generateSvgContent = (iconName) => {
            const hasIcons = Object.keys(this.icons).length > 0;
            if (hasIcons && iconName && iconName.length > 0) {
                // We are doing this to avoid breaking change.
                if (iconName.startsWith('alert')) {
                    iconName = 'alert-triangle';
                }
                if (iconName.startsWith('info')) {
                    iconName = 'info-circle';
                }
                const icon = this.icons[`balIcon${upperFirst(camelCase(iconName))}`];
                if (icon) {
                    this.svgContent = icon;
                    return;
                }
                else {
                    console.error(`Icon "${iconName}" not found in design system configuration.`, '\n\nCheck out the documentation on how to import icons during initialization.', '\nhttps://design.baloise.dev/?path=/docs/components-data-display-icon--documentation&globals=framework:angular#import-during-initialization');
                }
            }
            this.svgContent = sanitizeSvg(this.svg);
        };
    }
    /**
     * LIFE CYCLE
     * ------------------------------------------------------
     */
    connectedCallback() {
        this.generateSvgContent(this.name);
    }
    componentWillRender() {
        this.generateSvgContent(this.name);
    }
    /**
     * LISTENERS
     * ------------------------------------------------------
     */
    /**
     * @internal define config for the component
     */
    async configChanged(state) {
        this.icons = state.icons;
        this.generateSvgContent(this.name);
    }
    parseColor() {
        if (this.colorHovered && this.hovered) {
            return this.colorHovered;
        }
        if (this.colorPressed && this.pressed) {
            return this.colorPressed;
        }
        if (this.colorHovered && this.colorPressed) {
            return this.color;
        }
        if (!!this.disabled) {
            return 'grey';
        }
        if (!!this.invalid) {
            if (this.pressed) {
                return 'danger-darker';
            }
            else if (this.hovered) {
                return 'danger-dark';
            }
            else {
                return 'danger';
            }
        }
        if (this.color !== 'auto' && (this.color === 'primary' || this.color === '')) {
            if (this.pressed) {
                return 'primary-dark';
            }
            else if (this.hovered) {
                return 'light-blue';
            }
        }
        return [
            'auto',
            'white',
            'blue',
            'grey',
            'grey-light',
            'grey-dark',
            'danger',
            'danger-dark',
            'danger-darker',
            'warning',
            'warning-dark',
            'warning-darker',
            'success',
            'success-dark',
            'success-darker',
            'primary',
            'primary-light',
            'light-blue',
        ].includes(this.color)
            ? this.color
            : 'primary';
    }
    /**
     * RENDER
     * ------------------------------------------------------
     */
    render() {
        const color = this.parseColor();
        const block = BEM.block('icon');
        return (h(Host, { key: '1e9a500d95dbf86f756d4f4e3e34a9fe0cf7ae1c', "aria-hidden": "true", class: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, block.class()), block.modifier('tile').class(this.tile)), block.modifier(`tile-color-${this.tileColor}`).class(this.tile && !!this.tileColor)), block.modifier('is-inverted').class(this.inverted)), block.modifier('is-inline').class(this.inline)), block.modifier('is-disabled').class(this.disabled)), block.modifier('shadow').class(this.shadow)), block.modifier(`is-${this.size}`).class(!!this.size)), block.modifier(`is-${color}`).class()) }, h("div", { key: '6969015d29cd3e94155858ff8bf15b3f4f7fe751', class: Object.assign(Object.assign(Object.assign(Object.assign({}, block.element('inner').class()), block.element('inner').modifier(`turn-${this.name}`).class(this.turn)), block.element('inner').modifier('tile').class(this.tile)), block.modifier(`is-${this.size}`).class(!!this.size)), innerHTML: this.svgContent })));
    }
    static get is() { return "bal-icon"; }
    static get originalStyleUrls() {
        return {
            "$": ["bal-icon.sass"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bal-icon.css"]
        };
    }
    static get properties() {
        return {
            "name": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string | undefined",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Name of the baloise icon."
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "name",
                "defaultValue": "undefined"
            },
            "svg": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Svg content."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "svg",
                "defaultValue": "''"
            },
            "size": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalIconSize",
                    "resolved": "\"\" | \"large\" | \"medium\" | \"small\" | \"x-large\" | \"x-small\" | \"xsmall\" | \"xx-large\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Defines the size of the icon."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "size",
                "defaultValue": "''"
            },
            "color": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalIconColor",
                    "resolved": "string",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The theme type of the button."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "color",
                "defaultValue": "''"
            },
            "colorHovered": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalIconColor",
                    "resolved": "string",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "color-hovered",
                "defaultValue": "''"
            },
            "colorPressed": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalIconColor",
                    "resolved": "string",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "color-pressed",
                "defaultValue": "''"
            },
            "tile": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the icon acts as a tile with a background color."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "tile",
                "defaultValue": "false"
            },
            "tileColor": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalIconTileColor",
                    "resolved": "string",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the icon acts as a tile with a background color. Default is purple"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "tile-color",
                "defaultValue": "''"
            },
            "inline": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the icon has display inline style"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "inline",
                "defaultValue": "false"
            },
            "inverted": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the icon is inverted"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "inverted",
                "defaultValue": "false"
            },
            "turn": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the icon is rotated 180deg"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "turn",
                "defaultValue": "false"
            },
            "shadow": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` adds a box shadow to improve readability on image background"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "shadow",
                "defaultValue": "false"
            },
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "If `true`, the element is not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "disabled",
                "defaultValue": "undefined"
            },
            "invalid": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "If `true` the component gets a invalid red style."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "invalid",
                "defaultValue": "undefined"
            },
            "hovered": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": undefined
                        }],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "hovered",
                "defaultValue": "false"
            },
            "pressed": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "internal",
                            "text": undefined
                        }],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "pressed",
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "icons": {},
            "svgContent": {},
            "innerColor": {},
            "innerSize": {}
        };
    }
    static get methods() {
        return {
            "configChanged": {
                "complexType": {
                    "signature": "(state: BalConfigState) => Promise<void>",
                    "parameters": [{
                            "name": "state",
                            "type": "BalConfigState",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "BalConfigState": {
                            "location": "import",
                            "path": "../../utils/config",
                            "id": "src/utils/config/index.ts::BalConfigState"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": [{
                            "name": "internal",
                            "text": "define config for the component"
                        }]
                }
            }
        };
    }
}
__decorate([
    ListenToConfig(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], Icon.prototype, "configChanged", null);
