'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const __chunk_1 = require('./chunk-6bde8416.js');

class SnackBarOptions {
}

class SnackbarController {
    constructor(hostRef) {
        __chunk_1.registerInstance(this, hostRef);
        this.snackQueue = [];
    }
    async create(options) {
        this.controllerEl = document.querySelector('materials-snackbar-controller');
        if (!this.controllerEl) {
            this.controllerEl = document.body.appendChild(document.createElement('materials-snackbar-controller'));
        }
        const snack = document.createElement('materials-snackbar');
        Object.assign(snack, new SnackBarOptions(), options);
        snack.addEventListener('close', (ev) => {
            const closedSnack = ev.target;
            closedSnack.remove();
            this.controllerEl.sliceQueue();
        });
        this.controllerEl.pushToQueue(snack);
    }
    async pushToQueue(snack) {
        this.snackQueue = [...this.snackQueue, snack];
    }
    async sliceQueue() {
        this.snackQueue = this.snackQueue.length > 1 ? [...this.snackQueue.slice(1, this.snackQueue.length)] : [];
    }
    handleQueue(newValue, oldValue) {
        if (newValue.length > 0 && (oldValue.length > newValue.length || newValue.length === 1)) {
            document.body.appendChild(newValue[0]);
        }
    }
    get host() { return __chunk_1.getElement(this); }
    static get watchers() { return {
        "snackQueue": ["handleQueue"]
    }; }
}

exports.materials_snackbar_controller = SnackbarController;
