import { Router } from '@angular/router';
import { NgClass } from '@angular/common';
import { Component, OnInit, inject } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { FormGroup, FormBuilder, Validators, ReactiveFormsModule, FormsModule } from '@angular/forms';

import { AuthenticationService } from '../../../providers/user/authentication.service';

@Component({
  standalone: true,
  selector: 'status-set-remark',
  templateUrl: './statussetremark.component.html',
  imports: [FormsModule, ReactiveFormsModule, NgClass]
})
export class StatusSetRemarkComponent implements OnInit
{
  private readonly formBuilder = inject(FormBuilder);
  private readonly activeModal = inject(NgbActiveModal);

  public submitted = false;
  public statusSetRemarkForm: FormGroup;

  constructor()
  {
    const router = inject(Router);
    const authService = inject(AuthenticationService);

    if (!authService.currentUserValue)
    {
      router.navigate(['/login']);
    }
  }

  ngOnInit()
  {
    this.statusSetRemarkForm = this.formBuilder.group({ remarks: ['', Validators.required] });
  }

  get f() { return this.statusSetRemarkForm.controls; }

  public okay(): void
  {
    this.submitted = true;
    if (this.statusSetRemarkForm.invalid)
      return;

    this.activeModal.close(this.f.remarks.value);
  }

  public close(): void
  {
    this.activeModal.close(false);
  }
}
