import { Controller } from 'stimulus';

/*
 * This is an example Stimulus controller!
 *
 * Any element with a data-controller="default" attribute will cause
 * this controller to be executed. The name "default" comes from the filename:
 * default_controller.js -> "default"
 *
 * Delete this file or adapt it for your use!
 */
export default class extends Controller {
    connect() {
        var buttonReferenceModal = this.element.querySelector('button.show-reference-modal');
        
        buttonReferenceModal.addEventListener('click', function () {
            $.ajax({
                dataType: "HTML",
                method: 'GET',
                crossDomain: false,
                url: '/widget/reference',
                success(response) {
                    var popupWrap = document.getElementById('popup');
                    popupWrap.querySelector('.modal-title').innerHTML = 'Налоговый вычет на лечение';
                    popupWrap.querySelector('.modal-dialog').classList.remove('modal-lg');
                    var popupBody = popupWrap.querySelector('#popup-body');
                    popupBody.innerHTML = response;
                    $(popupWrap).modal('show');
                }
            });
        })
    }
}
