Source: jsdoc/node_modules/elements-sk/error-toast-sk/error-toast-sk.js

// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @module elements-sk/error-toast-sk
 * @description <h2><code>error-toast-sk</code></h2>
 *
 * <p>
 *   Listens for 'error-sk' events that bubble up to the document and displays them.
 *   These are normally generated by errorMessage.
 * </p>
 *
 * <p>
 *   The 'error-sk' event should have 'detail' of the form:
 * </p>
 *
 * <pre>
 *    {
 *      message: "The error message to display goes here.",
 *      duration: Integer, the number of ms to display or 0 for indefinitely.
 *                Defaults to 10000 (10s)
 *    }
 * </pre>
 *
 * @example
 *
 * <footer>
 *   <error-toast-sk></error-toast-sk>
 * </footer>
 */
import 'elements-sk/toast-sk'
import { define } from '../define'
import { upgradeProperty } from '../upgradeProperty'

define('error-toast-sk', class extends HTMLElement {
  connectedCallback() {
    this.innerHTML = `<toast-sk></toast-sk>`;
    this._toast = this.firstElementChild;
    document.addEventListener('error-sk', this);
  }

  disconnectedCallback() {
    document.removeEventListener('error-sk', this);
  }

  handleEvent(e) {
    if (e.detail.duration) {
      this._toast.duration = e.detail.duration
    }
    this._toast.textContent = e.detail.message;
    this._toast.show();
  }
});