import { Component, OnInit, Input, ElementRef, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core"
import { FormGroup, ReactiveFormsModule } from "@angular/forms"
import { BooleanValueAccessorDirective, TextValueAccessorDirective } from "../value-accessors"
import { NgIf } from "@angular/common"

@Component({
  standalone: true,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  selector: "app-investment-origin",
  templateUrl: "./investment-origin.component.html",
  imports: [
    ReactiveFormsModule,
    BooleanValueAccessorDirective,
    TextValueAccessorDirective,
    NgIf
  ],
  styleUrls: ["./investment-origin.component.scss"]
})
export class InvestmentOriginComponent implements OnInit {
  @Input() form: FormGroup
  hasExtras = false
  extrasValue = ""

  constructor() {}

  ngOnInit(): void {}

  handleExtrasChange(event: CustomEvent) {
    this.hasExtras = event.detail.checked

    if (!event.detail.checked) {
      this.form.get("extras").setValue(null)
    }
  }
}
