"use strict";

import _ from 'lodash';
import { LayoutStore } from "../Stores/LayoutStore.js";
import LayoutNodeFactory from "./LayoutNodeFactory.js";
import Node from "./Node.js";
export default class ParentNode extends Node {
  constructor(layout, type, parentNode) {
    super(layout, type, parentNode);
    this.children = layout.children.map(childLayout => LayoutNodeFactory.create(childLayout, this));
  }
  componentDidMount() {}
  componentDidAppear() {
    this.getVisibleLayout().componentDidAppear();
  }
  componentDidDisappear() {
    this.getVisibleLayout().componentDidDisappear();
  }
  getVisibleLayout() {
    return this.children[this.children.length - 1].getVisibleLayout();
  }
  getTopParent() {
    if (this.parentNode) return this.parentNode.getTopParent();
    return this;
  }
  applyOptions(_options) {
    this.parentNode?.applyOptions(_options);
  }
  mergeOptions(options) {
    this.data.options = _.mergeWith(this.data.options, options, (objValue, srcValue, key) => {
      if (_.isArray(objValue)) {
        if (key === 'rightButtons' || key === 'leftButtons') {
          this.buttonsChanged(objValue, srcValue);
        }
        return srcValue;
      }
      if (key === 'title' && srcValue.component) {
        this.titleChanged(objValue, srcValue);
      }
    });
    this.parentNode?.mergeOptions(options);
  }
  buttonsChanged(_oldButtons, _newButtons) {}
  titleChanged(_oldComponent, _newComponent) {}
  resolveOptions() {
    const options = _.merge(_.cloneDeep(this.data.options), this.getVisibleLayout().data.options);
    return _.merge(_.cloneDeep(LayoutStore.getDefaultOptions()), options);
  }
  getStack() {
    if (this.type === 'Stack') {
      return this;
    } else if (this.parentNode) {
      return this.parentNode.getStack();
    }
    return undefined;
  }
  getBottomTabs() {
    if (this.type === 'BottomTabs') {
      return this;
    } else if (this.parentNode) {
      return this.parentNode.getBottomTabs();
    }
    return undefined;
  }
}
//# sourceMappingURL=ParentNode.js.map