'use strict';

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

var Extensions = require('../extensions/Extensions.js');
var autoDetectRenderer = require('../rendering/renderers/autoDetectRenderer.js');
var Container = require('../rendering/scene/Container.js');

const _Application = class {
  constructor() {
    /**
     * The root display container that's rendered.
     * @member {Container}
     */
    this.stage = new Container.Container();
  }
  /**
   * @param options - The optional application and renderer parameters.
   */
  async init(options) {
    options = {
      ...{
        // forceCanvas: false,
      },
      ...options
    };
    this.renderer = await autoDetectRenderer.autoDetectRenderer(options);
    _Application._plugins.forEach((plugin) => {
      plugin.init.call(this, options);
    });
  }
  /** Render the current stage. */
  render() {
    this.renderer.render({ container: this.stage });
  }
  /**
   * Reference to the renderer's canvas element.
   * @member {ICanvas}
   * @readonly
   */
  get canvas() {
    return this.renderer.element;
  }
  /**
   * Reference to the renderer's screen rectangle. Its safe to use as `filterArea` or `hitArea` for the whole screen.
   * @member {Rectangle}
   * @readonly
   */
  get screen() {
    return this.renderer.screen;
  }
  /**
   * Destroys the application and all of its resources.
   * @param {object|boolean} [options=false] - The options for destroying the application.
   * @param {boolean} [options.removeView=false] - Whether to remove the application's canvas element from the DOM.
   * @param {boolean} [options.children=false] - If set to true, all the children will have their destroy method
   * called as well. `options` will be passed on to those calls.
   * @param {boolean} [options.texture=false] - Only used for children with textures e.g. Sprites.
   * If options.children is set to true,
   * it should destroy the texture of the child sprite.
   * @param {boolean} [options.textureSource=false] - Only used for children with textures e.g. Sprites.
   *  If options.children is set to true,
   * it should destroy the texture source of the child sprite.
   * @param {boolean} [options.context=false] - Only used for children with graphicsContexts e.g. Graphics.
   * If options.children is set to true,
   * it should destroy the context of the child graphics.
   */
  destroy(options = false) {
    const plugins = _Application._plugins.slice(0);
    plugins.reverse();
    plugins.forEach((plugin) => {
      plugin.destroy.call(this);
    });
    this.stage.destroy(options);
    this.stage = null;
    this.renderer.destroy(options);
    this.renderer = null;
  }
};
let Application = _Application;
/** Collection of installed plugins. */
Application._plugins = [];
Extensions.extensions.handleByList(Extensions.ExtensionType.Application, Application._plugins);

exports.Application = Application;
//# sourceMappingURL=Application.js.map
