import { ApplicationController } from './application_controller'; export class ApiTokenAutorisationController extends ApplicationController { static targets = [ 'procedures', 'procedureSelect', 'procedureSelectGroup', 'continueButton' ]; declare readonly continueButtonTarget: HTMLButtonElement; declare readonly procedureSelectTarget: HTMLSelectElement; declare readonly procedureSelectGroupTarget: HTMLElement; declare readonly proceduresTarget: HTMLElement; connect() { const urlSearchParams = new URLSearchParams(window.location.search); const targetIds = urlSearchParams.getAll('targets[]'); const customTargets = urlSearchParams.get('target') == 'custom'; this.setupProceduresTarget(targetIds); if (customTargets && targetIds.length > 0) { this.showProcedureSelectGroup(); } this.setContinueButtonState(); } setupProceduresTarget(targetIds: string[]) { const options = Array.from(this.procedureSelectTarget.options); targetIds .map((id) => options.find((x) => x.value == id)) .forEach((option) => option && this.addProcedureToSelect(option)); } addProcedure(e: Event) { e.preventDefault(); const selectedOption = this.procedureSelectTarget.selectedOptions[0]; this.addProcedureToSelect(selectedOption); this.setContinueButtonState(); } addProcedureToSelect(option: HTMLOptionElement) { const template = [ `