var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to set private field on non-instance");
    }
    privateMap.set(receiver, value);
    return value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
    if (!privateMap.has(receiver)) {
        throw new TypeError("attempted to get private field on non-instance");
    }
    return privateMap.get(receiver);
};
var _items, _menu;
import { h } from "@stencil/core";
import { Icon } from '../bce-icon/bce-icon';
import { MenuControl } from '../../utils/menu-control';
import { ripple } from '../../utils/ripple';
export class Fab {
    constructor() {
        this.icon = Icon.DEFAULT_ICON.iconName;
        this.info = '';
        _items.set(this, []);
        _menu.set(this, void 0);
        this.handleMouseDown = (event) => {
            if (this.disabled)
                return;
            ripple(event.target, event);
        };
        this.handleSlotChange = () => {
            __classPrivateFieldSet(this, _items, Array.from(this.el.querySelectorAll('bce-button')));
            __classPrivateFieldGet(this, _menu).setItems(__classPrivateFieldGet(this, _items));
            for (const item of __classPrivateFieldGet(this, _items))
                this.initButton(item);
        };
        this.disableClick = (event) => {
            if (this.disabled)
                event.stopPropagation();
        };
    }
    get trigger() {
        const root = this.el.shadowRoot;
        return root.querySelector('.trigger');
    }
    watch() {
        for (const button of __classPrivateFieldGet(this, _items))
            this.propagateState(button);
    }
    async next() {
        return __classPrivateFieldGet(this, _menu).next();
    }
    async prev() {
        return __classPrivateFieldGet(this, _menu).prev();
    }
    async toggle(active = !this.active) {
        if (__classPrivateFieldGet(this, _items).length)
            this.active = active;
    }
    componentDidLoad() {
        __classPrivateFieldSet(this, _menu, new MenuControl(this.el, this.trigger, this.toggle.bind(this)));
        const slot = this.el.shadowRoot.querySelector('slot');
        slot === null || slot === void 0 ? void 0 : slot.addEventListener('slotchange', this.handleSlotChange);
        this.handleSlotChange();
    }
    initButton(button) {
        this.propagateState(button);
        // Always use default design for internal buttons
        button.design = undefined;
        // Ensure that there is always an icon
        button.icon = button.icon || Icon.DEFAULT_ICON.iconName;
    }
    propagateState(button) {
        if (!this.active)
            button.dataset.inactive = '';
        else
            delete button.dataset.inactive;
        if (this.inline)
            button.dataset.inline = '';
        else
            delete button.dataset.inline;
    }
    renderMenu() {
        return (h("div", { role: "menu" },
            h("slot", null)));
    }
    render() {
        return [
            !this.inline && this.renderMenu(),
            // this.info && (
            //   <div data-info>
            //     <bce-button
            //       design={this.active ? 'text' : 'contained'}
            //       color={this.color}
            //       disabled={this.disabled}
            //       onClick={this.handleClick}
            //       onMouseDown={this.handleMouseDown}
            //       small
            //     >
            //       {this.info}
            //     </bce-button>
            //   </div>
            // ),
            h("button", { class: "trigger", disabled: this.disabled, onMouseDown: this.handleMouseDown, "aria-haspopup": true, "aria-expanded": this.active },
                h("bce-icon", { raw: this.icon, size: "lg", onClick: this.disableClick, "fixed-width": true })),
            this.inline && this.renderMenu(),
            h("div", { class: "backdrop", onClick: () => this.toggle(false) })
        ];
    }
    static get is() { return "bce-fab"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() { return {
        "$": ["bce-fab.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["bce-fab.css"]
    }; }
    static get properties() { return {
        "active": {
            "type": "boolean",
            "mutable": true,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "active",
            "reflect": true
        },
        "color": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "color",
            "reflect": true
        },
        "disabled": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "disabled",
            "reflect": true
        },
        "icon": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "icon",
            "reflect": true,
            "defaultValue": "Icon.DEFAULT_ICON.iconName"
        },
        "info": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "info",
            "reflect": true,
            "defaultValue": "''"
        },
        "inline": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "inline",
            "reflect": true
        }
    }; }
    static get methods() { return {
        "next": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "prev": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        },
        "toggle": {
            "complexType": {
                "signature": "(active?: boolean) => Promise<void>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "el"; }
    static get watchers() { return [{
            "propName": "active",
            "methodName": "watch"
        }, {
            "propName": "inline",
            "methodName": "watch"
        }]; }
}
_items = new WeakMap(), _menu = new WeakMap();
