const BinarySocket     = require('../../../socket');
const BinaryPjax       = require('../../../../base/binary_pjax');
const State            = require('../../../../base/storage').State;
const getPropertyValue = require('../../../../base/utility').getPropertyValue;
const Client           = require('../../../../base/client');
const localize         = require('../../../../base/localize').localize;
const Url              = require('../../../../base/url');


const professionalClient = (() => {
    let is_in_page = false;

    const onLoad = () => {
        BinarySocket.wait('get_account_status').then((response) => {
            if (/professional_requested|professional/.test(getPropertyValue(response, ['get_account_status', 'status']))) {
                BinaryPjax.loadPreviousUrl();
                return;
            }
            init(Client.isAccountOfType('financial'), true, Client.get('is_ico_only'));
        });
    };

    const init = (is_financial, is_page, is_ico_only) => {
        is_in_page = !!is_page;
        BinarySocket.wait('landing_company').then(() => { populateProfessionalClient(is_financial, is_ico_only); });
    };

    const populateProfessionalClient = (is_financial, is_ico_only) => {
        const financial_company = State.getResponse('landing_company.financial_company.shortcode');
        if ((!/costarica|maltainvest/.test(financial_company) ||    // limited to these landing companies
            (financial_company === 'maltainvest' && !is_financial)) && !is_ico_only) { // then it's not upgrading to financial
            if(is_in_page) {
                BinaryPjax.loadPreviousUrl();
            }
            return;
        }
        const $container        = $('#fs_professional');
        const $chk_professional = $container.find('#chk_professional');
        const $info             = $container.find('#professional_info');
        const $popup_contents   = $container.find('#popup');
        const popup_selector    = '#professional_popup';
        const $error             = $('#form_message');

        $container.find('#professional_info_toggle').off('click').on('click', function() {
            $(this).toggleClass('open');
            $info.slideToggle();
        });

        $chk_professional.on('change', () => {
            if ($chk_professional.is(':checked') && !$(popup_selector).length) {
                $('body').append($('<div/>', { id: 'professional_popup', class: 'lightbox' }).append($popup_contents.clone().setVisibility(1)));

                $(popup_selector).find('#btn_accept, #btn_decline').off('click').on('click dblclick', function() {
                    if ($(this).attr('data-value') === 'decline') {
                        $chk_professional.prop('checked', false);
                    }
                    $('#professional_popup').remove();
                });
            }
        });

        if (financial_company === 'maltainvest') {
            $container.find('#show_financial').setVisibility(1);
        }

        $container.setVisibility(1);

        if (is_in_page) {
            $('#loading').remove();
            $('#frm_professional')
                .off('submit')
                .on('submit', (e) => {
                    e.preventDefault();
                    if ($chk_professional.is(':checked')) {
                        BinarySocket.send(populateReq()).then((response) => {
                            if (response.error) {
                                $error.text(response.error.message).removeClass('invisible');
                            } else {
                                BinarySocket.send({get_account_status: 1}).then(() => {
                                    if(Client.get('is_ico_only')){
                                        BinaryPjax.load(Url.urlFor('user/ico-subscribe'));
                                    } else {
                                        BinaryPjax.loadPreviousUrl();
                                    }
                                });
                            }
                        });
                    } else {
                        $error.text(localize('This field is required.')).removeClass('invisible');
                    }
                })
                .setVisibility(1);

        }
    };

    const populateReq = () => {
        const req = {
            set_settings               : 1,
            request_professional_status: 1,
        };
        return req;
    };

    return {
        onLoad,
        init,
    };
})();

module.exports = professionalClient;

@@ -3298,24 +3298,102 @@
 hecked')) %7B%0A
+                        BinarySocket.wait('get_settings').then((res) =%3E %7B%0A    
             
@@ -3434,16 +3434,32 @@
 lateReq(
+res.get_settings
 )).then(
@@ -3498,24 +3498,28 @@
             
+    
 if (response
@@ -3524,24 +3524,28 @@
 se.error) %7B%0A
+    
             
@@ -3646,32 +3646,36 @@
                 
+    
 %7D else %7B%0A       
@@ -3691,32 +3691,36 @@
                 
+ 
+   
 BinarySocket.sen
@@ -3795,16 +3795,20 @@
         
+    
 if(Clien
@@ -3830,16 +3830,20 @@
 nly'))%7B%0A
+    
         
@@ -3953,32 +3953,36 @@
                 
+    
 %7D else %7B%0A       
@@ -3966,32 +3966,36 @@
        %7D else %7B%0A
+    
                 
@@ -4076,34 +4076,42 @@
                 
+  
-%7D%0A
+  %7D%0A    
                 
@@ -4150,33 +4150,69 @@
                 
-%7D
+    %7D%0A                            %7D);
 %0A               
@@ -4468,24 +4468,36 @@
 ulateReq = (
+get_settings
 ) =%3E %7B%0A     
@@ -4597,24 +4597,24 @@
 _status: 1,%0A
-
         %7D;%0A 
@@ -4612,16 +4612,278 @@
      %7D;%0A
+%0A        if (get_settings.tax_identification_number) %7B%0A            req.tax_identification_number = get_settings.tax_identification_number;%0A        %7D%0A        if (get_settings.tax_residence) %7B%0A            req.tax_residence = get_settings.tax_residence;%0A        %7D%0A%0A
         

Fix mf