class MegaMobileBottomBar extends MegaComponent {

    constructor(options) {

        super(options);

        // If ads are disabled, use the original bottom bar
        // Otherwise create a new bottom bar wrapper and return the node for the bottom bar
        const bottomNode = (options.adWrapper /* && mega.flags.ab_ads*/)
            ? mega.commercials.addCommsToBottomBar(this.domNode, options.adWrapper === 'adFolder')
            : this.domNode;

        bottomNode.classList.add('mega-bottom-bar');

        this.actions = [];

        const buildAction = (options) => {

            const buttonAction = new MegaButton(options);

            if (typeof options.binding === 'function') {
                buttonAction.on('tap', () => {
                    options.binding();
                    return false;
                });
            }

            this.actions.push(buttonAction);
        };

        let subNode = document.createElement('div');
        const actions = options.actions && options.actions[0];
        subNode.className = `text-actions${ actions.length > 1 ? ' multiple' : ''}`;
        bottomNode.appendChild(subNode);

        if (actions) {
            for (let i = 0; i < actions.length; i++) {
                const action = actions[i];

                const textOptions = {
                    parentNode: subNode,
                    type: 'normal',
                    componentClassname: `${i === 0 ? 'primary' : 'secondary'} block ${action[0]}`,
                    text : action[1],
                    binding: action[2],
                    disabled: !!action[3]
                };

                buildAction(textOptions);
            }
        }

        subNode = document.createElement('div');
        subNode.className = 'icon-actions';
        bottomNode.appendChild(subNode);

        if (options.actions && options.actions[1]) {

            for (const action of options.actions[1]) {

                const iconOptions = {
                    parentNode: subNode,
                    type: 'icon',
                    iconSize: 16,
                    componentClassname: `secondary block ${action[0]}`,
                    icon : `sprite-mobile-fm-mono ${action[1]}`,
                    binding: action[2],
                    disabled: !!action[3]
                };

                buildAction(iconOptions);
            }
        }

        // Create new ads in the bottom bar
        if (options.adWrapper /* && mega.flags.ab_ads*/) {
            mega.commercials.createMobileBottomBarSlots(this.domNode, options.adWrapper === 'adFolder');
        }
    }
}
