/**
 * EverestFormsGeneralSettings JS
 */
 (function($) {

	var EverestFormsGeneralSettings = {

	   /**
		* Start the engine.
		*/
		init: function() {

		   // Document ready
		   $(document).ready(EverestFormsGeneralSettings.ready);
		   // Build UI Actions
		   EverestFormsGeneralSettings.bindUIActions();

		},

		ready: function() {
			if($('#everest_forms_scheduled_entry_delete').prop('checked')) {
				$(document).find('#everest_forms_scheduled_entry_delete_time').parent().parent().show();
			} else {
				$(document).find('#everest_forms_scheduled_entry_delete_time').parent().parent().hide();
			}

			if($('#everest_forms_admin_approval_entries_enable').prop('checked')){
				$(document).find('#everest_forms_admin_approval_entries_email_notification').closest('.everest-forms-global-settings').show();
				$(document).find('#everest_forms_admin_approval_entries_email_subject').closest('.everest-forms-global-settings').show();
				$(document).find('#everest_forms_admin_approval_entries_email_body').closest('.everest-forms-global-settings').show();
				$(document).find('#everest_forms_admin_approval_entries_email_as_raw_html').closest('.everest-forms-global-settings').show();
				$(document).find('#everest_forms_admin_approval_entries_pending_delete').closest('.everest-forms-global-settings').show();
				$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').show();
			}else{
				$(document).find('#everest_forms_admin_approval_entries_email_notification').closest('.everest-forms-global-settings').hide();
				$(document).find('#everest_forms_admin_approval_entries_email_subject').closest('.everest-forms-global-settings').hide();
				$(document).find('#everest_forms_admin_approval_entries_email_body').closest('.everest-forms-global-settings').hide();
				$(document).find('#everest_forms_admin_approval_entries_email_as_raw_html').closest('.everest-forms-global-settings').hide();
				$(document).find('#everest_forms_admin_approval_entries_pending_delete').closest('.everest-forms-global-settings').hide();
				$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').hide();
			}

			if($('#everest_forms_admin_approval_entries_pending_delete').prop('checked')){
				$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').show();
			}else{
				$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').hide();
			}

			var evf_admin_approval_notification = $('#everest_forms_admin_approval_entries_email_notification:checked').val();


				if('custom_email' === evf_admin_approval_notification){
					$(document).find('#everest_forms_admin_approval_entries_custom_email').closest('.everest-forms-global-settings').show();
				}else{
					$(document).find('#everest_forms_admin_approval_entries_custom_email').closest('.everest-forms-global-settings').hide();
				}

		},

		bindUIActions: function() {
			$(document).on('click', '#everest_forms_scheduled_entry_delete', function() {
				if($(this).prop('checked')) {
					$(document).find('#everest_forms_scheduled_entry_delete_time').closest('.everest-forms-global-settings').show();
				} else {
					$(document).find('#everest_forms_scheduled_entry_delete_time').closest('.everest-forms-global-settings').hide();
				}
			});
			$(document).on('click, change', '#everest_forms_admin_approval_entries_enable', function(){
				if($('#everest_forms_admin_approval_entries_enable').prop('checked')){
					$(document).find('#everest_forms_admin_approval_entries_email_notification').closest('.everest-forms-global-settings').show();
					$(document).find('#everest_forms_admin_approval_entries_email_subject').closest('.everest-forms-global-settings').show();
					$(document).find('#everest_forms_admin_approval_entries_email_body').closest('.everest-forms-global-settings').show();
					$(document).find('#everest_forms_admin_approval_entries_email_as_raw_html').closest('.everest-forms-global-settings').show();
					$(document).find('#everest_forms_admin_approval_entries_pending_delete').closest('.everest-forms-global-settings').show();
					$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').show();
				}else{
					$(document).find('#everest_forms_admin_approval_entries_email_notification').closest('.everest-forms-global-settings').hide();
					$(document).find('#everest_forms_admin_approval_entries_email_subject').closest('.everest-forms-global-settings').hide();
					$(document).find('#everest_forms_admin_approval_entries_email_body').closest('.everest-forms-global-settings').hide();
					$(document).find('#everest_forms_admin_approval_entries_email_as_raw_html').closest('.everest-forms-global-settings').hide();
					$(document).find('#everest_forms_admin_approval_entries_pending_delete').closest('.everest-forms-global-settings').hide();
					$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').hide();
				}
			});

			$(document).on('click, change', '#everest_forms_admin_approval_entries_pending_delete', function(){
				if($('#everest_forms_admin_approval_entries_pending_delete').prop('checked')){
					$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').show();
				}else{
					$(document).find('#everest_forms_admin_approval_entries_waiting_days').closest('.everest-forms-global-settings').hide();
				}
			});


			$(document).on('click, change', '#everest_forms_admin_approval_entries_email_notification', function(){
					var evf_admin_approval_notification = $('#everest_forms_admin_approval_entries_email_notification:checked').val();
				if('custom_email' === evf_admin_approval_notification){
					$(document).find('#everest_forms_admin_approval_entries_custom_email').closest('.everest-forms-global-settings').show();
				}else{
					$(document).find('#everest_forms_admin_approval_entries_custom_email').closest('.everest-forms-global-settings').hide();
				}
			});
		}
	}
	EverestFormsGeneralSettings.init();
})(jQuery);
