/*
 * Add/Remove Reward Points Tab
 */
jQuery( function ( $ ) {
    var AddRemovePointsTabScript = {
        init : function () {
            this.show_or_hide_for_reward_type_selection() ;
            this.show_or_hide_for_user_type_selection() ;
            $( document ).on( 'change' , '#rs_select_user_type' , this.user_type_selection ) ;
            $( document ).on( 'change' , '#rs_reward_select_type' , this.reward_type_selection ) ;
        } ,
        user_type_selection : function () {
            AddRemovePointsTabScript.show_or_hide_for_user_type_selection() ;
        } ,
        show_or_hide_for_user_type_selection : function () {
            if ( jQuery( '#rs_select_user_type' ).val() == '1' ) {
                jQuery( '#rs_select_to_include_customers' ).parent().parent().hide() ;
                jQuery( '#rs_select_to_exclude_customers' ).parent().parent().hide() ;
            } else if ( jQuery( '#rs_select_user_type' ).val() == '2' ) {
                jQuery( '#rs_select_to_include_customers' ).parent().parent().show() ;
                jQuery( '#rs_select_to_exclude_customers' ).parent().parent().hide() ;
            } else {
                jQuery( '#rs_select_to_include_customers' ).parent().parent().hide() ;
                jQuery( '#rs_select_to_exclude_customers' ).parent().parent().show() ;
            }
        } ,
        reward_type_selection : function () {
            AddRemovePointsTabScript.show_or_hide_for_reward_type_selection() ;
        } ,
        show_or_hide_for_reward_type_selection : function () {
            if ( jQuery( '#rs_reward_select_type' ).val() == '1' ) {
                jQuery( '#rs_remove_points' ).hide() ;
                jQuery( '#rs_add_points' ).show() ;
                jQuery( '#rs_expired_date' ).parent().parent().show() ;
                jQuery( '#send_mail_add_remove_settings' ).closest( 'tr' ).show() ;
                jQuery( '#send_mail_settings' ).closest( 'tr' ).hide() ;
                jQuery('#rs_email_subject_for_remove').closest('tr').hide();
                jQuery('#rs_email_message_for_remove').closest('tr').hide();
                 if (jQuery('#send_mail_add_remove_settings').is(':checked')) {
                        jQuery('#rs_email_subject_message').closest('tr').show();
                        jQuery('#rs_email_message').closest('tr').show();
                    } else {
                        jQuery('#rs_email_subject_message').closest('tr').hide();
                        jQuery('#rs_email_message').closest('tr').hide();
                    }
                    jQuery('#send_mail_add_remove_settings').click(function () {
                        if (jQuery('#send_mail_add_remove_settings').is(':checked')) {
                            jQuery('#rs_email_subject_message').closest('tr').show();
                            jQuery('#rs_email_message').closest('tr').show();
                        } else {
                            jQuery('#rs_email_subject_message').closest('tr').hide();
                            jQuery('#rs_email_message').closest('tr').hide();
                        }
                    });
            } else {
                jQuery( '#rs_remove_points' ).show() ;
                jQuery( '#rs_add_points' ).hide() ;
                jQuery( '#rs_expired_date' ).parent().parent().hide() ;
                jQuery( '#send_mail_add_remove_settings' ).closest( 'tr' ).hide() ;
                jQuery( '#send_mail_settings' ).closest( 'tr' ).show() ;
                jQuery( '#rs_email_subject_message' ).closest( 'tr' ).hide() ;
                jQuery( '#rs_email_message' ).closest( 'tr' ).hide() ;
                if (jQuery('#send_mail_settings').is(':checked')) {
                        jQuery('#rs_email_subject_for_remove').closest('tr').show();
                        jQuery('#rs_email_message_for_remove').closest('tr').show();
                    } else {
                        jQuery('#rs_email_subject_for_remove').closest('tr').hide();
                        jQuery('#rs_email_message_for_remove').closest('tr').hide();
                    }
                    jQuery('#send_mail_settings').click(function () {
                        if (jQuery('#send_mail_settings').is(':checked')) {
                            jQuery('#rs_email_subject_for_remove').closest('tr').show();
                            jQuery('#rs_email_message_for_remove').closest('tr').show();
                        } else {
                            jQuery('#rs_email_subject_for_remove').closest('tr').hide();
                            jQuery('#rs_email_message_for_remove').closest('tr').hide();
                        }
                    });
            }
        } ,
    } ;
    AddRemovePointsTabScript.init() ;
} ) ;