/**
 * @module package/ecoyn/core/bin/backend/controls/Setup/Steps/Modules
 * @author www.pcsg.de (Henning Leutz)
 */
define('package/ecoyn/core/bin/backend/controls/Setup/Steps/Modules', [

    'qui/QUI',
    'qui/controls/Control'

], function (QUI, QUIControl) {
    "use strict";

    return new Class({

        Extends: QUIControl,
        Type   : 'package/ecoyn/core/bin/backend/controls/Setup/Steps/Modules',

        Binds: [
            '$onImport'
        ],

        initialize: function (options) {
            this.parent(options);

            this.addEvents({
                onImport: this.$onImport
            });
        },

        $onImport: function () {
            this.getElm().getElements('form [type="checkbox"]').addEvent('change', (event) => {
                let Input = event.target;

                if (Input.checked) {
                    Input.getParent('label').addClass('active');
                } else {
                    Input.getParent('label').removeClass('active');
                }
            });

            this.getElm().getElements('[name="licence"]').addEvent('change', (event) => {
                let Input = event.target;

                if (Input.checked) {
                    this.getElm()
                        .getElement('.ecoyn-setup-wizard-modules-container-checkbox')
                        .setStyle('display', 'none');

                    this.getElm().getElement('form[name="modules"]').setStyle('display', null);
                }
            });
        },

        load: function () {
            // licence check
            const Wizard = this.getAttribute('Wizard');
            const currentData = Wizard.getData();

            if (typeof currentData.licence === 'undefined' || !currentData.licence) {
                // show licence checkbox
                this.getElm().getElement('form[name="modules"]').setStyle('display', 'none');

                this.getElm()
                    .getElement('.ecoyn-setup-wizard-modules-container-checkbox')
                    .setStyle('display', null);
            } else {
                this.getElm()
                    .getElement('.ecoyn-setup-wizard-modules-container-checkbox')
                    .setStyle('display', 'none');

                this.getElm().getElement('form[name="modules"]').setStyle('display', null);
            }
        }
    });
});
