import { __decorate, __metadata } from "tslib";
import { Host, h } from "@stencil/core";
import { BEM } from "../../utils/bem";
import { ListenToBreakpoints, balBreakpoints } from "../../utils/breakpoints";
import { raf } from "../../utils/helpers";
import { ListenToWindowResize } from "../../utils/resize";
export class ProgressBar {
    constructor() {
        this.animated = true;
        this.isTouch = balBreakpoints.isTouch; // need this part to improve a none side effect import
        /**
         * PUBLIC PROPERTY API
         * ------------------------------------------------------
         */
        /**
         * The value of the bar in percentage. So min is 0 and 100 would be the max value.
         */
        this.value = 0;
        /**
         * The background color
         */
        this.background = 'white';
        /**
         * The progress bar color
         */
        this.color = 'primary';
    }
    /**
     * LIFECYCLE
     * ------------------------------------------------------
     */
    componentDidRender() {
        this.updateProgress();
    }
    /**
     * LISTENERS
     * ------------------------------------------------------
     */
    breakpointListener(_breakpoints) {
        this.updateProgress();
    }
    windowResizeListener() {
        this.updateProgress();
    }
    async configChanged(state) {
        this.animated = state.animated;
    }
    /**
     * PRIVATE METHODS
     * ------------------------------------------------------
     */
    updateProgress() {
        if (this.lineEl) {
            raf(() => {
                const maxWidth = this.el.clientWidth;
                const value = Math.max(0, Math.min(100, this.value));
                const lineWidth = (maxWidth / 100) * value;
                this.lineEl.style.width = `${lineWidth}px`;
                if (value === 100) {
                    this.lineEl.classList.add('bal-progress-bar__line--full');
                }
                else {
                    this.lineEl.classList.remove('bal-progress-bar__line--full');
                }
            });
        }
    }
    /**
     * RENDER
     * ------------------------------------------------------
     */
    render() {
        const block = BEM.block('progress-bar');
        const bemLineEl = block.element('line');
        return (h(Host, { key: '3560c076e654839526d357edec7f7d605793d9b0', "aria-hidden": "true", class: Object.assign(Object.assign({}, block.class()), block.modifier(`background-${this.background}-of-${this.color}`).class()) }, h("div", { key: 'd89c4e6cf2d0c12abd70696606c47f03de988889', class: Object.assign(Object.assign(Object.assign({}, bemLineEl.class()), bemLineEl.modifier(`color-${this.color}`).class()), bemLineEl.modifier(`animated`).class(this.animated)), ref: lineEl => (this.lineEl = lineEl) })));
    }
    static get is() { return "bal-progress-bar"; }
    static get originalStyleUrls() {
        return {
            "$": ["bal-progress-bar.sass"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bal-progress-bar.css"]
        };
    }
    static get properties() {
        return {
            "value": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The value of the bar in percentage. So min is 0 and 100 would be the max value."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "value",
                "defaultValue": "0"
            },
            "background": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalProgressBarBackground",
                    "resolved": "\"grey\" | \"white\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The background color"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "background",
                "defaultValue": "'white'"
            },
            "color": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "BalProps.BalProgressBarColor",
                    "resolved": "\"green\" | \"primary\" | \"purple\" | \"red\" | \"yellow\"",
                    "references": {
                        "BalProps": {
                            "location": "global",
                            "id": "global::BalProps"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The progress bar color"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "color",
                "defaultValue": "'primary'"
            }
        };
    }
    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": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
}
__decorate([
    ListenToBreakpoints(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ProgressBar.prototype, "breakpointListener", null);
__decorate([
    ListenToWindowResize(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ProgressBar.prototype, "windowResizeListener", null);
