import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = [ "selector", "link" ]
  static values = { urlTemplate: String } // Pass template like "/users/:id/edit"

  update() {
    console.log("## ## %%")
    const selectedId = this.selectorTarget.value
    // Replace placeholder with selected ID
    const newUrl = this.urlTemplateValue.replace(":id", selectedId)
    
    // Update the link href
    this.linkTarget.href = newUrl
  }
}