const DEFAULT_SHOW_TEXT = '+';
const DEFAULT_HIDE_TEXT = '-';
const DEFAULT_TOGGLE_WIDTH_PERCENT = 20;

export default class ExpanderController {

  $onInit = () => {
    this.showText = this.showText || DEFAULT_SHOW_TEXT;
    this.hideText = this.hideText || DEFAULT_HIDE_TEXT;
    this.expanded = this.expanded || false;
    this.toggleWidthPercent = this.toggleWidthPercent || DEFAULT_TOGGLE_WIDTH_PERCENT;

    this.toggleWidth = `${this.toggleWidthPercent}%`;
    this.headerContentWidth = `${100 - this.toggleWidthPercent}%`;
  }

  toggle = () => {
    this.expanded = !this.expanded;
    if (this.expanded && this.onExpand) {
      this.onExpand();
    }

    if (!this.expanded && this.onCollapse) {
      this.onCollapse();
    }
  }

  getToggleText = () =>
    this.expanded ?
      this.hideText :
      this.showText;

  isExpanded = () => this.expanded;
}
