import { Injectable } from '@angular/core';
import { ThemeService } from 'src/app/services/theme.service';
import { StorageService} from 'src/app/services/storage.service';

@Injectable({
  providedIn: 'root'
})
export class BackgroundService {

  callBacks: {
    type: 'Offline' | 'Online' | 'Notification',
    object?: string
    funx: Function
  }[] = []

  constructor(
    private themeservice: ThemeService,
    private storageservice: StorageService
  ) { }

  online() {
    if (this.themeservice.currentTheme == 'gov') {

      document.body.style.setProperty(`--color`, "#d9d9d9");
      document.body.style.setProperty(`--color2`, "#f0f0f0");
      document.body.style.setProperty(`--color3`, "#d9d9d9");
      document.body.style.setProperty(`--color4`, "#d9d9d9ee");
      document.body.style.setProperty(`--color5`, "#ececec");
      this.storageservice.store('networkCheckStore','online');

    } else {
      document.body.style.setProperty(`--color`, "#0782C9");
      document.body.style.setProperty(`--color2`, "#45BAFF");
      document.body.style.setProperty(`--color3`, "#0782C9");
      document.body.style.setProperty(`--color4`, "#0782c9f0");
      document.body.style.setProperty(`--color5`, "#45BAFF");
      this.storageservice.store('networkCheckStore','online');
    }

    this.callBacks.forEach((e) => {
      if (e.type == 'Online') {
        e.funx()
      }
    })
  }

  offline() {
    document.body.style.setProperty(`--color`, "#ffb703");
    document.body.style.setProperty(`--color2`, "#ffb703");
    document.body.style.setProperty(`--color3`, "#ffb703");
    document.body.style.setProperty(`--color4`, "#ffb703");
    document.body.style.setProperty(`--color5`, "#ffb703");
    this.storageservice.store('networkCheckStore','offline');
    this.callBacks.forEach((e) => {
      if (e.type == 'Offline') {
        e.funx()
      }
    })
  }

  registerBackService(type: 'Offline' | 'Online' | 'Notification', funx: Function, object = '') {
    this.callBacks.push({
      type,
      funx,
      object
    })
  }


  greyTheme() {
    document.body.style.setProperty(`--color`, "#D9D9D9");
    document.body.style.setProperty(`--color2`, "#f0f0f0");
    document.body.style.setProperty(`--color3`, "#D9D9D9");
    document.body.style.setProperty(`--color4`, "#d9d9d9ee");
    document.body.style.setProperty(`--color5`, "#ececec");

    document.body.style.setProperty(`--header-container-background`, "#fff");
    document.body.style.setProperty(`--headercolor`, "#000");

    document.body.style.setProperty(`--login-background`, "linear-gradient(180deg, #c63527 60%, #000 100%) !important");
    document.body.style.setProperty(`--button-hover`, "#ffb81c");
    document.body.style.setProperty(`--inicio-open-page-from-box`, "#c63527");
    document.body.style.setProperty(`--header-tab-top-border`, "#000");
    document.body.style.setProperty(`--header-tab-text-white`, "rgb(0, 0, 0)");
    document.body.style.setProperty(`--header-tab-text-white`, "rgb(0, 0, 0)");

    document.body.style.setProperty(`--header-bottom-line-background`, "rgb(255, 0, 0)");
    document.body.style.setProperty(`--header-bottom-line-background-image`, "linear-gradient(to right,  #C63527,  #FFB81C, #FFC72C)");
  }

  blueTheme() {

    document.body.style.setProperty(`--color`, "#0782C9");
    document.body.style.setProperty(`--color2`, "#45BAFF");
    document.body.style.setProperty(`--color3`, "#0782C9");
    document.body.style.setProperty(`--color4`, "#0782c9f0");
    document.body.style.setProperty(`--color5`, "#f7f5f2");

    document.body.style.setProperty(`--header-container-background`, "linear-gradient(270deg, var(--color2) 0%, var(--color3) 23.44%, var(--color4) 78.13%, var(--color5) 100%) !important");
    document.body.style.setProperty(`--headercolor`, "#000");

    document.body.style.setProperty(`--header-bottom-line-background`, "linear-gradient(270deg, var(--color2) 0%, var(--color3) 23.44%, var(--color4) 78.13%, var(--color5) 100%) !important");
    document.body.style.setProperty(`--header-bottom-line-background-image`, "linear-gradient(270deg, var(--color2) 0%, var(--color3) 23.44%, var(--color4) 78.13%, var(--color5) 100%) !important");

    document.body.style.setProperty(`--login-background`, "linear-gradient(180deg, #42b9fe 0%, #0782c9 100%) !importantt");
    document.body.style.setProperty(`--button-hover`, "#42b9fe");
    document.body.style.setProperty(`--inicio-open-page-from-box`, "#42b9fe");
    document.body.style.setProperty(`--header-tab-top-border`, "white");
    document.body.style.setProperty(`--header-tab-text-white`, "white");

  }

  default() {
    document.body.style.setProperty(`--color`, "#0782C9");
    document.body.style.setProperty(`--color2`, "#45BAFF");
    document.body.style.setProperty(`--color3`, "#0782C9");
    document.body.style.setProperty(`--color4`, "#0782c9f0");
    document.body.style.setProperty(`--color5`, "#45BAFF");
  }
}
