import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["providerNetworkField", "networkLogoField", "providerSectionField"]

  connect() {
    console.log("---provider update---")
  }

  syncDefaults() {
    const pnValue = this.providerNetworkFieldTarget.value
    if (pnValue == "Cigna") {
      this.networkLogoFieldTarget.value = 1
      this.providerSectionFieldTarget.value = 30
    } else if (pnValue == "Medcost") {
      this.networkLogoFieldTarget.value = 2
      this.providerSectionFieldTarget.value = 26
    } else {
      this.networkLogoFieldTarget.value = ""
      this.providerSectionFieldTarget.value = ""
    }
    const event = new Event('change', { bubbles: true });
    this.networkLogoFieldTarget.dispatchEvent(event);
  }
}