import { Component } from '@angular/core';

import { FormGroup } from "@angular/forms";
import { MgFormControlsAccessor, MgControlName, MgCustomProperties } from "./Login.mg.controls.g";


import { TaskBaseMagicComponent, magicProviders } from "@magic-xpa/angular";


import {
    MagicServices, // Add
  } from '@magic-xpa/angular';
  import {
    ChangeDetectorRef, // Add
    ViewContainerRef,
  } from '@angular/core';
  
  import { Router } from '@angular/router';
  import { cilMenu } from '@coreui/icons';
  import { IconSetService } from '@coreui/icons-angular';

@Component({
    selector: 'mga-Login',
    providers: [...magicProviders],
    templateUrl: './Login.component.html'
})
export class Login extends TaskBaseMagicComponent {

    mgc = MgControlName;
    mgcp = MgCustomProperties;
    mgfc!: MgFormControlsAccessor;
    override createFormControlsAccessor(formGroup: FormGroup) {
        this.mgfc = new MgFormControlsAccessor(formGroup, this.magicServices);
    }


    constructor(
        ref: ChangeDetectorRef,
        magicServices: MagicServices,
        protected vcRef: ViewContainerRef,
        public router: Router,
        public iconSet: IconSetService,
      ) {
        super(ref, magicServices);
        this.iconSet.icons = { cilMenu };
        // iconSet.icons = { cilMenu };
      }
    Login(URL: string) {
      URL.replace("xpa-canvas", "");
      if (URL.trim() == '/' || URL.trim() == '' || URL.trim().includes("Login")) {
          this.router.navigate(['/StartingProgram']);
        } else {
          this.router.navigate([URL.trim()]);
        }
      }

      BLogin=()=>{
      var LoginID = document.getElementById('LoginID') as HTMLInputElement;
      var Password = document.getElementById('Password') as HTMLInputElement;
      this.mg.setValueToControl(this.mgc.LoginID,LoginID.value);
      this.mg.setValueToControl(this.mgc.Password,Password.value);
      this.mg.simulateClick(this.mgc.BLogin);
    }  
}