"use strict";

import ParentNode from "./ParentNode.js";
import * as layoutActions from "../actions/layoutActions.js";
const isCenterChild = child => child.type === 'SideMenuCenter';
const isLeftChild = child => child.type === 'SideMenuLeft';
const isRightChild = child => child.type === 'SideMenuRight';
export default class SideMenuRootNode extends ParentNode {
  constructor(layout, parentNode) {
    super(layout, 'SideMenuRoot', parentNode);
    this.visibleChild = this._getCenterChild();
    if (!this.visibleChild) {
      throw new Error('SideMenuRootNode must have a SideMenuCenter child');
    }
  }
  applyOptions(_options) {
    super.applyOptions(_options);
    this._updateVisibility(_options);
  }
  mergeOptions(options) {
    super.mergeOptions(options);
    this._updateVisibility(options);
  }

  /**
   * @override
   */
  getVisibleLayout() {
    return this.visibleChild.getVisibleLayout();
  }
  _updateVisibility(options) {
    if (options.sideMenu) {
      if (options.sideMenu.left?.visible) {
        this.visibleChild = this._getLeftChild();
        layoutActions.openSideMenu(this.visibleChild);
      } else if (options.sideMenu.right?.visible) {
        this.visibleChild = this._getRightChild();
        layoutActions.openSideMenu(this.visibleChild);
      } else {
        this.visibleChild = this._getCenterChild();
        layoutActions.closeSideMenu(this.visibleChild);
      }
    }
  }
  _getCenterChild = () => this.children.find(isCenterChild);
  _getLeftChild = () => this.children.find(isLeftChild);
  _getRightChild = () => this.children.find(isRightChild);
}
export class SideMenuNode extends ParentNode {
  constructor(layout, type, parentNode) {
    super(layout, type, parentNode);
  }
  getVisibleLayout() {
    return this.children[0].getVisibleLayout();
  }
}
export class SideMenuLeftNode extends SideMenuNode {
  constructor(layout, parentNode) {
    super(layout, 'SideMenuLeft', parentNode);
  }
}
export class SideMenuRightNode extends SideMenuNode {
  constructor(layout, parentNode) {
    super(layout, 'SideMenuRight', parentNode);
  }
}
export class SideMenuCenterNode extends SideMenuNode {
  constructor(layout, parentNode) {
    super(layout, 'SideMenuCenter', parentNode);
  }
}
//# sourceMappingURL=SideMenu.js.map