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

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

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

    return new Class({

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

        Binds: [
            '$onImport'
        ],

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

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

        $onImport: function () {
            const BusinessType = this.getElm().getElement('[name="general.businessType"]');

            this.getElm().getElements('.ecoyn-setup-wizard-distributionType-entry').addEvent('click', (event) => {
                this.getElm().getElements('.ecoyn-setup-wizard-distributionType-entry').removeClass('active');

                let Target = event.target;

                if (!Target.hasClass('ecoyn-setup-wizard-distributionType-entry')) {
                    Target = Target.getParent('.ecoyn-setup-wizard-distributionType-entry');
                }

                this.getElm().getElement('[name="general.businessType"]').value = Target.get('data-dt');
                Target.addClass('active');
            });

            if (BusinessType.value !== '') {
                const BusinessTypeSelect = this.getElm().getElement('[data-dt="' + BusinessType.value + '"]');

                if (BusinessTypeSelect) {
                    BusinessTypeSelect.addClass('active');
                }
            }
        },

        next: function () {
            return this.getElm().getElement('[name="general.businessType"]').value !== '';
        }
    });
});
