import { Component, OnInit } from '@angular/core';
import { Subject } from 'rxjs';
import { workerHandler } from "src/app/shared/worker-handler/worker-handler";
import { NanoService } from 'src/app/shared/nano/nano.service';
import { DownloadManagerService } from 'src/app/shared/services/download-manager-service';

export let showWorkerGraph = new Subject<boolean>();

@Component({
  selector: 'app-advanced-settings',
  templateUrl: './advanced-settings.component.html',
  styleUrls: ['./advanced-settings.component.scss']
})
export class AdvancedSettingsComponent implements OnInit {

  public maxWorker;
  public workerInput;
  public devOn = false;
  public fileStreamSizeLimit = NanoService.FILE_STREAM_MIN_SIZE/1000000;
  public holdFileInCache = DownloadManagerService.STORE_TIME_DOWNLOADED_DATA_IN_CACHE/1000;

  constructor() {
    this.maxWorker = workerHandler.getMaxProcess();
  }

  ngOnInit(): void {
  }

  changeMaxWorker(max: number){
    workerHandler.setMaxProcess(max);
    localStorage.setItem('workers', ""+max);
    this.maxWorker = workerHandler.getMaxProcess();
  }

  toggleWorkerGraph(show: boolean){
    showWorkerGraph.next(show);
  }

  changeFileStreamSizeLimit(limit: number){
    localStorage.setItem('file-stream-size-limit', ""+limit*1000000);
    NanoService.FILE_STREAM_MIN_SIZE = limit*1000000;
  }

  changeHoldFileInCache(sec: number){
    localStorage.setItem('hold-file-in-cache', ""+sec*1000);
    DownloadManagerService.STORE_TIME_DOWNLOADED_DATA_IN_CACHE = sec*1000;
  }

}
