import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Roots } from '@enums/root.enum';
import { UserEducationForm } from '@interfaces/form';
import { IonicModule, NavController } from '@ionic/angular';
import { StateManagementService } from '@services/state-management.service';

@Component({
  selector: 'app-passive-user-education',
  templateUrl: './passive-user-education.page.html',
  styleUrls: ['./passive-user-education.page.scss'],
  standalone: true,
  imports: [IonicModule, FormsModule, ReactiveFormsModule]
})
export class PassiveUserEducationPage implements OnInit {
  userEducationForm: FormGroup<UserEducationForm>;
  constructor(
    private navCtrl: NavController,
    private stateManagementService: StateManagementService
  ) { }

  ngOnInit() {
    this.userEducationForm = new FormGroup<UserEducationForm>({
      schoolName: new FormControl(this.stateManagementService?.userInformation?.school_name),
      aboutUser: new FormControl(this.stateManagementService?.userInformation?.aboutUser)
    });
  }

  moveToNext(form) {
    if (!form.valid) {
      this.userEducationForm.markAllAsTouched();
      return;
    }
    this.stateManagementService.userInformation.school_name = form.value.schoolName;
    this.stateManagementService.userInformation.aboutUser = form.value.aboutUser;
    this.navCtrl.navigateForward(Roots.page + '/' + Roots.passiveUserProfileImage);
  }
  moveToBack() {
    this.navCtrl.navigateForward(Roots.page + '/' + Roots.passiveUserInformation);
  }
}
