export interface IMenuItem {
  name: string;
  translateKey: string;
  rout: string;
  routAsArray?: string[];
  isActive: boolean;
  isVisible: boolean;
  subMenu?: IMenuItem[];
  parent?: IMenuItem;
  absolute?: string;
  disabled?: boolean;
  forKnokser?: boolean;
}

export class MenuItem implements IMenuItem {
  name: string;
  translateKey: string;
  rout: string;
  isActive: boolean;
  isVisible: boolean;
  subMenu?: IMenuItem[];
  parent?: IMenuItem;
  absolute?: string;
  disabled?: boolean;
  forKnokser?: boolean;

  get routAsArray(): string[] {
    return this.rout.split('/') || [];
  }

  constructor(item: IMenuItem) {
    this.name = undefined;
    this.translateKey = undefined;
    this.rout = undefined;
    this.isActive = false;
    this.isVisible = false;
    this.subMenu = [];
    this.parent = undefined;
    this.absolute = undefined;
    this.disabled = false;
    this.forKnokser = false;

    Object.keys(item).forEach((key: string): void => {
      this[key] = item[key];
    }, this);
  }
}
