import { Component, OnInit } from '@angular/core';
import { Server } from "../../../server";
import { QuestEntryModel } from "../../../models/atlasData/questEntry.model";
import { BlueprintGeneratedClassModel } from "../../../models/atlasData/blueprintGeneratedClass.model";

@Component({
  selector: 'app-quests',
  templateUrl: './quests.component.html'
})

export class QuestsComponent implements OnInit {
  quests: QuestEntryModel[];

  constructor(private server: Server) {
    this.quests = server.serverGrid.globalGameplaySetup.QuestEntries;
  }

  ngOnInit() {
  }

  // Issue with text arrays and editing jumps on each change.
  trackByFn(index: any, item: any) {
    return index;
  }

  private addQuestFeat(quest) {
    if (quest.UnlockFeatNames === undefined) {
      quest.UnlockFeatNames = [];
    }
    quest.UnlockFeatNames.push('');
  }

  private removeQuestFeat(quest, j) {
    quest.UnlockFeatNames.splice(j, 1);
    if (quest.UnlockFeatNames.length === 0) {
      quest.UnlockFeatNames = undefined;
    }
  }

  private addEngramClass(quest) {
    if (quest.CompleteGiveEngramClasses === undefined) {
      quest.CompleteGiveEngramClasses = [];
    }
    quest.CompleteGiveEngramClasses.push(new BlueprintGeneratedClassModel());
  }

  private removeEngramClass(quest, j) {
    quest.CompleteGiveEngramClasses.splice(j, 1);
    if (quest.CompleteGiveEngramClasses.length === 0) {
      quest.UnlockFeatNames = undefined;
    }
  }
}
