import { Component, Input, OnInit } from "@angular/core";
import { CommonModule } from "@angular/common";
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import {
  FormBuilder,
  FormControl,
  FormGroup,
  ReactiveFormsModule,
} from "@angular/forms";
import { HelpersService } from "src/app/cores/services/helpers.service";
import { WhiteSpaceValidator } from "src/app/cores/form-validators/whitespace";

@Component({
  selector: "app-submit",
  standalone: true,
  imports: [CommonModule, ReactiveFormsModule],
  templateUrl: "./submit.component.html",
  styleUrls: ["./submit.component.scss"],
})
export class SubmitComponent implements OnInit {
  @Input() modalType: number = 0;
  @Input() message: string = "";

  form: FormGroup = {} as FormGroup;

  constructor(
    public activeModal: NgbActiveModal,
    private formBuilder: FormBuilder,
    public helpers: HelpersService
  ) {}

  ngOnInit(): void {
    this.initForm();
  }

  initForm(): void {
    this.form = this.formBuilder.group({
      note: [null, [WhiteSpaceValidator.noWhiteSpace]],
    });
  }

  onSubmit(): void {
    this.activeModal.close(this.form.value);
  }
}
