  var module_9026579 = (function() {
    var __hs_messages = {};
    i18n_getmessage = function() {
      return hs_i18n_getMessage(__hs_messages, hsVars['language'], arguments); 
    };
    i18n_getlanguage = function() {
      return hsVars['language']; 
    };
const form_id = $('#form-id')
	.attr('data-form-id')
	.toString();
const _gender = '.hs_gender2';
const _age = '.hs_age';
const _height = '.hs_height';
const _weight = '.hs_weight';

hbspt.forms.create({
	portalId: '2498149',
	// portalId: "6831331",
	formId: form_id,
	target: '#form-id',
	onFormReady: function () {
		$form_inits();
		//     $user_action();
	},
	onFormSubmit: function () {
		$thank_you();
	},
});

let imperial = true;
let end_of_slide;
let start_of_slide = false;
let meal_1_name;
let meal_2_name;
let meal_3_name;
let meal_1_result;
let meal_2_result;
let meal_3_result;
let meal_1_link;
let meal_2_link;
let meal_3_link;

$form_inits = () => {
	//** If Meal
	if ($('#meal_value').length > 0) {
		$('#first-slide').prependTo('#form-id form');
		$('#form-id').addClass('meal_quiz');
	}

	//** Creating the incremental steps for the calculator **//
	$('#form-id .hs-form-field').each(function () {
		if ($(this).is(':visible')) {
			$(this).addClass('slide_input');
		}
	});
	let number_of_slides = $('#form-images .number-of-inputs');
	let number_of_inputs = $('.slide_input');

	$(number_of_slides).each(function (s) {
		let input_ammount = $(this).attr('data-slide-input-ammount');
		let input_image = $(this).find('#image-container-main');
		let input_text = $(this).find('.step-text');
		let inputs_to_wrap =
			number_of_slides.length - 1 == s
				? number_of_inputs
				: number_of_inputs.slice(0, input_ammount);
		let first_slide =
			s == 0 ? "style='display:flex;'" : "style='display:none;'";
		let first_slide_class = s == 0 ? 'current' : '';
		let metric_indicator = false;

		inputs_to_wrap.each(function () {
			if (
				$(this)
					.find('input')
					.is('input[type="number"]')
			) {
				$(this).addClass('calc-input');
			} else if (
				$(this)
					.find('input')
					.is('input[type="radio"]')
			) {
				$(this).addClass('calc-input');
			}

			if ($(this).is("div[class*='age']")) {
				$(this).addClass('age');
			} else if ($(this).is("div[class*='height']")) {
				$(this).addClass('height metric_toggle');
				metric_indicator = true;
			} else if ($(this).is("div[class*='weight']")) {
				$(this).addClass('weight metric_toggle');
				metric_indicator = true;
			}
		});

		let metric_insert = metric_indicator == true ? 'has-metric-toggle' : '';

		inputs_to_wrap.removeClass('slide_input').addClass('active_inputs');
		inputs_to_wrap.wrapAll(
			'<div id="step-' +
			(s + 1) +
			'" class="step step-' +
			(s + 1) +
			' ' +
			metric_insert +
			' ' +
			first_slide_class +
			'" ' +
			first_slide +
			'><div class="step-inner"></div></div>'
		);
		input_text.prependTo('#step-' + (s + 1));
		input_image.prependTo('#step-' + (s + 1));

		//* resetting the inputs *//
		number_of_inputs = $('.slide_input');
		metric_indicator = false;
	});

	const num_form = $('.hs-fieldtype-number ');

	$('#calculator-form .hs-submit').hide();
	//   $('#calculator-form .hs-submit input').attr("disabled", true);
	//   $('#calculator-form .hs-submit input').css('background', 'black')

	//** adding the propper parts needed for the rangeslider **//
	num_form.each(function () {
		let min_max = $(this)
			.find('legend')
			.text();
		if (min_max.length != 0) {
			let el = $(this);
			let min_max_array = min_max.split(',');
			let value =
				el.find('input').val().length == 0 ? 0 : el.find('input').val();
			let range =
				"<input type='range' min=" +
				min_max_array[0] +
				' max=' +
				min_max_array[1] +
				' value=' +
				value +
				" class='range-slider' >";
			el.find('legend').hide();
			$(range).appendTo(el.find('.input'));
		}
		$(this)
			.find('input[type=number]')
			.attr('min', 0);
	});

	const radio_form = $('.hs-fieldtype-radio ul li span');

	//** Creating the styling for the radio buttons  **//
	radio_form.each(function () {
		//**  REGEX FILBIN **//
		let regex = /^(.*?)\,/gi;
		if (
			$(this)
				.text()
				.match(regex) != null
		) {
			$(this).addClass('activity');
			let txt = $(this).text();
			let sub = '<span class="main-label">$1</span>';
			txt = txt.replace(regex, sub);
			$(this)[0].innerHTML = txt;
		}
	});

	//** initializing the rangeslider.js **//
	$('input[type="range"]').rangeslider({
		polyfill: false,
		onSlide: function () {
			end_of_slide = false;
			start_of_slide = true;
		},
		onSlideEnd: function () {
			end_of_slide = true;
			start_of_slide = false;
		},
	});

	//**   create steps on top and buttons at the bottom **//
	let step_total = $('#calculator-form .step').length;

	$('#calculator-form .step').each(function (x) {
		let progress_increment = 100 / (step_total - 1);

		if (x == 0) {
			$(
				'<li id="top-step-' +
				(x + 1) +
				'" class="active" data-step="step-' +
				(x + 1) +
				'" > ✓</li>'
			).appendTo('#form-steps ul');
		} else {
			$(
				'<li id="top-step-' +
				(x + 1) +
				'" data-step="step-' +
				(x + 1) +
				'"> ✓</li>'
			).appendTo('#form-steps ul');
			if (x == step_total - 1) {
				$(
					'<a class="back button last-back-button" data-id="step-' +
					x +
					'" data-percent="' +
					progress_increment * (x - 1) +
					'"><img src="https://www.trifectanutrition.com/hubfs/Arrow%20Left.png"/></a>'
				).prependTo(this);
			} else {
				$(
					'<a class="back button" data-id="step-' +
					x +
					'" data-percent="' +
					progress_increment * (x - 1) +
					'"><img src="https://www.trifectanutrition.com/hubfs/Arrow%20Left.png"/></a>'
				).prependTo(this);
			}
		}
		if (x != step_total - 1) {
			if (x == step_total - 2) {
				$(
					'<a class="next button last-next-button"  data-id="step-' +
					(x + 2) +
					'" data-percent="' +
					progress_increment * (x + 1) +
					'">next</a>'
				).appendTo(this);
			} else if (x == 0 && $('#meal_value').length > 0) {
				$(
					'<a class="next button" data-id="step-' +
					(x + 2) +
					'" data-percent="' +
					progress_increment * (x + 1) +
					'">Let\'s Do This</a>'
				).appendTo(this);
			} else {
				$(
					'<a class="next button" data-id="step-' +
					(x + 2) +
					'" data-percent="' +
					progress_increment * (x + 1) +
					'">next</a>'
				).appendTo(this);
			}
		}

		//** Detecting if the step has metric on it **//
		if ($(this).hasClass('has-metric-toggle')) {
			$(
				'<label class="switch"><input id="metric-toggle" class="metric-toggle" type="checkbox" checked >Metric<span class="slider round"></span><span class="imp">Imperial</span></label>'
			).prependTo(this);
		}
	});

	//** Prevent the enter keybind for first steps **//
	$('#calculator-form').on('keyup keypress', function (e) {
		var keyCode = e.keyCode || e.which;
		if (keyCode === 13) {
			e.preventDefault();
			return false;
		}
	});

	$('.hs-fieldtype-radio ul li input:checked')
		.parent()
		.parent()
		.addClass('active');

	if ($('.hs-input[type="email"]').length > 0) {
		if ($('.hs-input[type="email"]').val().length > 0) {
			$('.hs-input[type="email"]')
				.parent()
				.parent()
				.addClass('user-interation');
		}
	}

	if ($('.hs-input[type="text"]').length > 0) {
		if ($('.hs-input[type="text"]').val().length > 0) {
			$('.hs-input[type="text"]')
				.parent()
				.parent()
				.addClass('user-interation');
		}
	}
	//** Setting up the fields for imperial **//
	$imperial_setup();
	$user_action();
	sizeDetection();
	$('input[type="number"]').trigger('input');
};

//** User interation with the calculator **//
$user_action = () => {
	const radio_input = $('.hs-fieldtype-radio ul li');
	const range_input = $('input[type="range"]');
	let num_input = $('input[type="number"]');
	const email_input = $('input[type="email"]');
	const text_input = $('input[type="text"]');

	email_input.on('click', function () {
		$(this)
			.parent()
			.parent()
			.addClass('user-interation');
	});

	text_input.on('click', function () {
		$(this)
			.parent()
			.parent()
			.addClass('user-interation');
	});

	//** toggling the styling for the selected radio button **//
	radio_input.on('click', function () {
		event.stopPropagation();
		$(this)
			.parent('ul')
			.find('li')
			.removeClass('active');
		$(this).addClass('active');
	});

	//** User input interations function **//
	$user_input = () => {
		num_input.trigger('input');
		range_input.trigger('input');
		let range_end_event = true;

		//** Calculating for metric, imperial, and updating the range slider to match values **//
		num_input.on('input', function () {
			if (num_input.val() == '') {
				$(num_input).val(0);
			}
			num_input.keypress(function () {
				if (event.key.replace(/[^\w\-.]/g, '') == '') event.preventDefault();
			});
			let el = $(this);
			let parent = el.parent('.input');
			let imperial_parent = el.parent('.imperial');
			let metric_parent = el.parent('.metric');
			let range = parent.find(range_input);
			if (imperial == true && imperial_parent.length > 0) {
				let inputs = imperial_parent.find('input');
				let main_parent = imperial_parent.parent('.input');
				let main_input = main_parent.find('input[type="number"].hs-input');
				if ($(imperial_parent).hasClass('imperial_height')) {
					let converted_imperial = $imperial_calc_to(
						inputs[0].id,
						inputs[0].value,
						inputs[1].id,
						inputs[1].value
					);
					main_input.val(converted_imperial);
					main_parent
						.find(range_input)
						.val(String(converted_imperial))
						.change();
					end_of_slide = true;
				} else {
					if (el.val() == '') {
						el.val(0);
					}
					main_input.val(el.val());
					main_parent
						.find(range_input)
						.val(el.val())
						.change();
					end_of_slide = true;
				}
			} else if (
				imperial == false &&
				metric_parent.length > 0 &&
				metric_parent[0].id == 'metric_height'
			) {
				let inputs = metric_parent.find('input');
				let main_parent = metric_parent.parent('.input');
				let main_input = main_parent.find('input[type="number"].hs-input');
				let convert_metric = Math.round(inputs[0].value / 2.54);
				main_input.val(convert_metric);
				main_parent
					.find(range_input)
					.val(String(convert_metric))
					.change();
				end_of_slide = true;
			} else if (
				imperial == false &&
				metric_parent.length > 0 &&
				metric_parent[0].id == 'metric_weight'
			) {
				let inputs = metric_parent.find('input');
				let main_parent = metric_parent.parent('.input');
				let main_input = main_parent.find('input[type="number"].hs-input');
				let convert_metric = Math.round(inputs[0].value * 2.205);
				main_input.val(convert_metric);
				main_parent
					.find(range_input)
					.val(String(convert_metric))
					.change();
				end_of_slide = true;
			} else {
				range.val(el.val()).change();
				end_of_slide = true;
			}
		});

		//** Calculating for metric, imperial, and updating the number field to match values **//
		range_input.rangeslider().on('input', function () {
			range_end_event = false;
			let el = $(this);
			let parent = el.parent('.input');
			let imperial_parent = parent.find('.imperial');
			let metric_parent = parent.find('.metric');
			let num = parent.find(num_input);
			if (imperial == true && imperial_parent.length > 0) {
				let inputs = imperial_parent.find('input');
				let input_vals = $imperial_calc_from(el.val());
				if ($(imperial_parent).hasClass('imperial_height')) {
					inputs[0].value = input_vals[0];
					inputs[1].value = input_vals[1];
					parent
						.find('input[type="number"].hs-input')
						.val(el.val())
						.change();
				} else {
					num.val(el.val()).change();
				}
			} else if (
				imperial == false &&
				metric_parent.length > 0 &&
				metric_parent[0].id == 'metric_height'
			) {
				let inputs = metric_parent.find('input');
				let input_vals = Math.round(el.val() * 2.54);
				inputs[0].value = input_vals;
				parent
					.find('input[type="number"].hs-input')
					.val(el.val())
					.change();
			} else if (
				imperial == false &&
				metric_parent.length > 0 &&
				metric_parent[0].id == 'metric_weight'
			) {
				let inputs = metric_parent.find('input');
				let input_vals = Math.round(el.val() / 2.205);
				inputs[0].value = input_vals;
				parent
					.find('input[type="number"].hs-input')
					.val(el.val())
					.change();
			} else {
				num.val(el.val()).change();
			}
		});
		//** END OF SLIDE EVENT */
		range_input.rangeslider().on('change', function (e) {
			e.stopPropagation();
			range_end_event = true;
			end_of_slide = true;
		});
		//** Check to see if all the needed requirements have been met or changed to run API **//
		$('.calc-input input').on('change', function (event) {
			$veri_data();
		});
		$veri_data = () => {
			let radio_ammount = $('.calc-input .input ul').length;
			let radio_check = 0;
			let number_ammount = $('.calc-input input.hs-input[type="number"]')
				.length;
			let number_check = 0;

			$('.calc-input input.hs-input[type="number"]').each(function () {
				if ($(this).val() != '') {
					number_check++;
				}
			});

			$('.calc-input .input ul').each(function () {
				if ($(this).find('input:checked').length == 1) {
					radio_check++;
				}
			});
			if (
				radio_check == radio_ammount &&
				number_check == number_ammount &&
				end_of_slide == true &&
				range_end_event == true
			) {
				check_data();
			}
		};
	};

	$user_input();

	//   $('.calc-input .input').last().addClass('last-input');

	//** Measurement toggle activation and respecive init of selected measurement type **//
	$('.metric-toggle').on('click', function () {
		if ($(this)[0].checked) {
			$('.metric-toggle').prop('checked', true);
			$('.metric_height').remove();
			$('.metric_weight').remove();
			$imperial_setup();
			num_input = $('input[type="number"]');
			$user_input();
			sizeDetection();
		} else {
			$('.metric-toggle').prop('checked', false);
			$('.imperial_height').remove();
			$('.imperial_weight').remove();
			$metric_setup();
			num_input = $('input[type="number" ]');
			$user_input();
		}
	});

	//** Calculaton from Imperial to inches **//
	$imperial_calc_to = (sys_1, val_1, sys_2, val_2) => {
		let feet = parseInt(val_1) ? parseInt(val_1) : 0;
		let inches = parseInt(val_2) ? parseInt(val_2) : 0;
		return feet * 12 + inches;
	};

	//** Calculaton from inches to feet & inches **//
	$imperial_calc_from = val => {
		let raw_val = val / 12;
		let feet = Math.floor(raw_val);
		let inches = Math.round((raw_val - feet) * 12);
		return [feet, inches];
	};

	//** Button click interterations **//
	$('#calculator-form .button, #calculator-form input[type="submit"]').on(
		'click',
		function () {
			let el = $(this);
			//     let current_step = el.parent();
			let current_step = $('#calculator-form .current');
			let progress = el.attr('data-percent');
			let id = el.attr('data-id');

			//** Back button functionality for the steps **//
			if (el.hasClass('back')) {
				let length = $('#calculator-form .current').length;
				let the_old = $('#calculator-form .current')[length - 1];
				let the_id = $(the_old).attr('id');
				$(the_old)
					.hide()
					.removeClass('current');
				$('#top-' + the_id).removeClass('active');
				$('#' + id)
					.fadeIn()
					.addClass('current');
				$('#calculator-form .hs-submit').hide();
				progress_bar();
			}

			//** Handeling the step progression **//
			if ($(this).hasClass('next') || $(this).is('input[type="submit"]')) {
				let el = $(this);
				if (el.is('input[type="submit"]')) {
					$validation(current_step);
				} else {
					$validation(current_step, function () {
						$('#calculator-form .current')
							.hide()
							.removeClass('current');
						$('#' + id)
							.fadeIn()
							.addClass('current');
						progress_bar();
						//** Final next button click and then send off to get results **//
						if (el.hasClass('last-next-button')) {
							$('#calculator-form .hs-submit').show();
							$('#calculator-form').unbind('keyup keypress');
						}
					});
				}
			}

			//** Animating the Top Progress Bar **//
			function progress_bar() {
				$('#calculator-form .progress').animate(
					{ width: progress + '%' },
					200,
					'linear',
					function () {
						$('#top-' + id).addClass('active');
					}
				);
			}

			//** Step Input Checker **//
			function $validation(step, callback) {
				let $step = $(step);
				let radio_ammount = $step.find('.input ul').length;
				let radio_check = 0;
				let number_ammount = $step.find('input.hs-input[type="number"]').length;
				let number_check = 0;
				let email_ammount = $step.find('input.hs-input[type="email"]').length;
				let email_check = 0;
				let text_ammount = $step.find('input.hs-input[type="text"]').length;
				let text_check = 0;

				$step.find('input.hs-input[type="number"]').each(function () {
					if ($(this).val() != '') {
						$(this)
							.parent()
							.find('input')
							.removeClass('in-valid');
						number_check++;
					} else {
						$(this)
							.parent()
							.find('input')
							.addClass('in-valid');
					}
				});

				$step.find('input.hs-input[type="email"]').each(function () {
					if ($(this).val() != '' && !$(this).hasClass('error')) {
						$(this)
							.parent()
							.find('input')
							.removeClass('in-valid');
						email_check++;
					} else {
						$(this)
							.parent()
							.find('input')
							.addClass('in-valid');
					}
				});

				$step.find('input.hs-input[type="text"]').each(function () {
					if ($(this).val() != '') {
						$(this)
							.parent()
							.find('input')
							.removeClass('in-valid');
						text_check++;
					} else {
						$(this)
							.parent()
							.find('input')
							.addClass('in-valid');
					}
				});

				$step.find('.input ul').each(function () {
					if ($(this).find('input:checked').length == 1) {
						$(this)
							.find('li')
							.removeClass('in-valid');
						radio_check++;
					} else {
						$(this)
							.find('li')
							.addClass('in-valid');
					}
				});

				if (
					radio_check == radio_ammount &&
					number_check == number_ammount &&
					email_check == email_ammount &&
					text_check == text_ammount
				) {
					callback();
				}
			}
		}
	);

	function check_data(id) {
		//** adding a loader to the page **//
		//       $('#form-id form').append('<div id="loader" style="height:'+form_height+'px"><img src="https://www.trifectanutrition.com/hubfs/Trifecta_Mark-1.svg" /></div>')
		let total_inputs = $('.calc-input');
		if ($('#meal_value').length > 0) {
			let gender, height, weight, goal, diet_focus, give_up, picky, activity;
			$(total_inputs).each(function (x) {
				let radio_input = $(this).find('.inputs-list .hs-input:checked');
				let number_input = $(this).find('.input .hs-input[type="number"]');
				if (radio_input.length > 0) {
					let name = radio_input.attr('name');
					if (name.includes('gender')) {
						gender = radio_input.val();
						gender = gender.toLowerCase().replace('s', '');
					} else if (name.includes('activity')) {
						if (radio_input.val().includes('Lightly')) {
							activity = 'light_active';
						} else {
							activity = radio_input.val();
							activity = activity.toLowerCase().replace(/\s/g, '_');
						}
					} else if (name.includes('focus')) {
						diet_focus = radio_input.val();
						diet_focus = diet_focus.toLowerCase().replace(/\s/g, '_');
					} else if (name.includes('goal')) {
						if (radio_input.val().includes('gain')) {
							goal = 'muscle_gain';
						} else if (radio_input.val().includes('maintain')) {
							goal = 'maintain';
						} else {
							goal = radio_input.val();
							goal = goal.toLowerCase().replace(/\s/g, '_');
						}
					} else if (name.includes('give_up')) {
						give_up = radio_input.val();
						give_up = give_up.toLowerCase().replace(/\s/g, '_');
					} else if (name.includes('picky_eater')) {
						picky = radio_input.val();
						picky = picky.toLowerCase().replace(/\s/g, '_');
					}
				}
				if (number_input.length >= 0) {
					for (z = 0; z < number_input.length; z++) {
						if (number_input[z].name == 'height') {
							height = number_input[z].value;
						} else if (number_input[z].name == 'weight') {
							weight = number_input[z].value;
						}
					}
				}
			});
			$sendCallMeal(
				gender,
				parseInt(height),
				parseInt(weight),
				goal,
				diet_focus,
				give_up,
				picky,
				activity,
				function () {
					$('#loader').remove();
					$('#calculator-form .hs-submit input').attr('disabled', false);
				}
			);

			// lets push this to the data layer
			let gtmData = JSON.stringify({
				gender: gender,
				height: height,
				weight: weight,
				fitness_goal: goal,
				current_diet: diet_focus,
				activity_level: activity,
				picky_eater: picky,
				not_willing_to_give_up: give_up,
			});
			dataLayerPush(gtmData);
		} else {
			let gender,
				height,
				weight,
				goal,
				birthday,
				activity,
				keto = $('#keto_value').length > 0 ? true : false;

			$(total_inputs).each(function (x) {
				let radio_input = $(this).find('.inputs-list .hs-input:checked');
				let number_input = $(this).find('.input .hs-input[type="number"]');
				if (radio_input.length > 0) {
					let name = radio_input.attr('name');
					if (name.includes('gender')) {
						gender = radio_input.val();
					} else if (name.includes('activity')) {
						activity = radio_input.val();
					} else if (name.includes('intensity')) {
					} else if (name.includes('goal')) {
						goal = radio_input.val();
					}
				}
				if (number_input.length >= 0) {
					for (z = 0; z < number_input.length; z++) {
						if (number_input[z].name == 'age') {
							let dateObj = new Date();
							let month = dateObj.getUTCMonth() + 1; //months from 1-12
							let day = dateObj.getUTCDate();
							let year = dateObj.getUTCFullYear() - number_input[z].value;
							birthday = month + '-' + day + '-' + year;
						} else if (number_input[z].name == 'height') {
							height = number_input[z].value;
						} else if (number_input[z].name == 'weight') {
							weight = number_input[z].value;
						} else if (number_input[z].name == 'activity_days_per_week') {
						} else if (number_input[z].name == 'cardio_days_per_week') {
						}
					}
				}
			});

			//** correction to the values to ensure they work with the API **//
			activity = activity.toLowerCase().replace(' ', '_');
			gender = gender.toLowerCase().replace('s', '');

			//** Sending the data to the  API fuction to retrieve results **//
			$sendCall(
				gender.toLowerCase(),
				parseInt(height),
				parseInt(weight),
				goal,
				birthday,
				activity,
				keto,
				function () {
					$('#loader').remove();
					$('#calculator-form .hs-submit input').attr('disabled', false);
				}
			);
		}
	}
};

//** Creating the fields for the imperial measurements **//
$imperial_setup = () => {
	imperial = true;
	$('.metric_toggle')
		.parent()
		.removeClass('metric-step');
	$('.metric_toggle')
		.parent()
		.addClass('imperial-step');
	$(
		'<div id="imperial_height" class="imperial_height imperial">My height:<input class="imperial_input" id="feet" min="0" type="number"></input><span class="ft">feet </span><input id="inches" class="imperial_input" min="0" max="11" type="number"></input><span class="in"> inches</span></div>'
	).prependTo('.height .input');
	$(
		'<div id="imperial_weight" class="imperial_weight imperial">My weight:<input id="lbs" type="number" min="0"></input> lbs</div>'
	).prependTo('.weight .input');
};

//** Creating the fields for the metric measurements **//
$metric_setup = () => {
	imperial = false;
	$('.metric_toggle')
		.parent()
		.removeClass('imperial-step');
	$('.metric_toggle')
		.parent()
		.addClass('metric-step');
	$(
		'<div id="metric_height" class="metric_height metric">My height:<input id="cm" type="number" min="0"></input> cm</div>'
	).prependTo('.height .input');
	$(
		'<div id="metric_weight" class="metric_weight metric">My weight:<input id="kilo" type="number" min="0"></input> kg</div>'
	).prependTo('.weight .input');
};

//** Sending the call to the api to retrieve results **//
$sendCall = (gender, height, weight, goal, date, activity, keto, callback) => {
	jQuery
		.ajax({
			url:
				'https://demo1.staging.trifectanutrition.com/wp-json/tf/v1/nutrition',
			type: 'POST',
			headers: {
				'Content-Type': 'application/json',
			},
			contentType: 'application/json',
			data: JSON.stringify({
				gender: gender,
				height: height,
				weight: weight,
				weight_unit_pref: 'lbs',
				goal: goal,
				birthday: date,
				activity: activity,
				key: '0yE7EJEZsqzwUYPSa7rDYm7OmeQibntZT4V0f8u6TVt51Msx',
				height_unit_pref: 'in',
				is_keto: keto,
			}),
		})
		.done(function (data, textStatus, jqXHR) {
			$assign_new_values(data);
		})
		.fail(function (jqXHR, textStatus, errorThrown) {
			console.log('HTTP Request Failed');
		})
		.always(function () {
			/* ... */
		});

	//** Taking the results from the API and adding the values to the respective fields **//
	$assign_new_values = data => {
		//     ONLY FOR TESTING
		// console.log(data)
		let bmr = $('[name="bmr"]'),
			tdee = $('[name="tdee"]'),
			daily_calories = $('[name="daily_calories"]'),
			protein = $('[name="protein"]'),
			carbs = $('[name="carbs"]'),
			fat = $('[name="fat"]'),
			keto = $('[name="is_keto"]');
		bmr.val(data.response.bmr).change();
		tdee.val(data.response.tdee).change();
		daily_calories.val(data.response.daily_calories).change();
		protein.val(data.response.protein).change();
		carbs.val(data.response.carbs).change();
		fat.val(data.response.fat).change();
	};
	callback();
};

$sendCallMeal = (
	gender,
	height,
	weight,
	goal,
	diet_focus,
	give_up,
	picky,
	activity,
	callback
) => {
	jQuery
		.ajax({
			url:
				'https://api.trifectanutrition.com/api/v1/nutrition/meal-plan-quiz',
			type: 'POST',
			headers: {
				'Content-Type': 'application/json',
			},
			contentType: 'application/json',
			data: JSON.stringify({
				//           "gender": gender,
				height: height,
				weight: weight,
				fitness_goal: goal,
				current_diet: diet_focus,
				activity_level: activity,
				picky_eater: picky,
				not_willing_to_give_up: give_up,
			}),
		})
		.done(function (data, textStatus, jqXHR) {
			$assign_new_values(data);
		})
		.fail(function (jqXHR, textStatus, errorThrown) {
			console.log('HTTP Request Failed');
		})
		.always(function (data) {
			/* ... */
		});

	//** Taking the results from the API and adding the values to the respective fields **//
	$assign_new_values = data => {
		//     ONLY FOR TESTING
		console.log(data);
		let meal_1 = $('[name="meal_quiz_result_1"]'),
			meal_1_email = $('[name="meal_quiz_result_1_email"]'),
			meal_1_percent = $('[name="meal_quiz_result_1_percent"]'),
			meal_1_subdirect = $('[name="meal_quiz_result_1_subdirect"]'),
			meal_2 = $('[name="meal_quiz_result_2"]'),
			meal_2_email = $('[name="meal_quiz_result_2_email"]'),
			meal_2_percent = $('[name="meal_quiz_result_2_percent"]'),
			meal_2_subdirect = $('[name="meal_quiz_result_2_subdirect"]'),
			meal_3 = $('[name="meal_quiz_result_3"]'),
			meal_3_email = $('[name="meal_quiz_result_3_email"]'),
			meal_3_percent = $('[name="meal_quiz_result_3_percent"]'),
			meal_3_subdirect = $('[name="meal_quiz_result_3_subdirect"]');
		meal_1.val(Object.keys(data.response)[0]).change();
		meal_1_email
			.val(Object.keys(data.response)[0].replace(/[\s]/g, '%20'))
			.change();
		meal_1_percent.val(Object.values(data.response)[0] * 100 + '%').change();
		meal_2.val(Object.keys(data.response)[1]).change();
		meal_2_email
			.val(Object.keys(data.response)[1].replace(/[\s]/g, '%20'))
			.change();
		meal_2_percent.val(Object.values(data.response)[1] * 100 + '%').change();
		meal_3.val(Object.keys(data.response)[2]).change();
		meal_3_email
			.val(Object.keys(data.response)[2].replace(/[\s]/g, '%20'))
			.change();
		meal_3_percent.val(Object.values(data.response)[2] * 100 + '%').change();
		meal_1_subdirect.val($link_finder(Object.keys(data.response)[0])).change();
		meal_2_subdirect.val($link_finder(Object.keys(data.response)[1])).change();
		meal_3_subdirect.val($link_finder(Object.keys(data.response)[2])).change();
		function $link_finder(response) {
			if (response == 'A la Carte') {
				return '/a-la-carte';
			}
			if (response == 'Classic') {
				return '/classic-meals';
			} else if (response == 'Clean') {
				return '/clean-eating-meal-plan';
			} else if (response == 'Keto') {
				return '/keto-meal-plan';
			} else if (response == 'Paleo') {
				return '/paleo-meal-plan';
			} else if (response == 'Vegan') {
				return '/vegan-meal-plan';
			} else if (response == 'Vegetarian') {
				return '/vegetarian-meal-plan';
			}
		}
		meal_1_name = meal_1.val();
		meal_2_name = meal_2.val();
		meal_3_name = meal_3.val();
		meal_1_result = meal_1.val() + ': ' + meal_1_percent.val();
		meal_2_result = meal_2.val() + ': ' + meal_2_percent.val();
		meal_3_result = meal_3.val() + ': ' + meal_3_percent.val();
		meal_1_link = meal_1_subdirect.val();
		meal_2_link = meal_2_subdirect.val();
		meal_3_link = meal_3_subdirect.val();
	};
	callback();
};

$(window).resize(function () {
	sizeDetection();
});

function dataLayerPush(data) {
	window.dataLayer = window.dataLayer || [];
	window.dataLayer.push({
		event: 'meal_plan_quiz',
		results: {
			data,
		},
	});
}

function sizeDetection() {
	const main_form = $('#calculator-form');
	if (main_form.width() <= 490) {
		main_form.addClass('smaller');
		main_form.find('span.ft').text('ft');
		main_form.find('span.in').text('in');
		if (main_form.width() <= 390) {
			main_form.addClass('smallest');
		}
	} else {
		if (main_form.hasClass('smaller')) {
			main_form.removeClass('smaller & smallest');
			main_form.find('span.ft').text('feet');
			main_form.find('span.in').text('inches');
		}
	}
}

$thank_you = () => {
	console.log(
		meal_1_name,
		meal_2_name,
		meal_3_name,
		meal_1_link,
		meal_2_link,
		meal_3_link
	);
	var results =
		'<p><strong>' +
		meal_1_result +
		'</strong></p><a class="d-block" href="https://www.trifectanutrition.com/' +
		meal_1_link +
		'"><img src="https://www.trifectanutrition.com/hubfs/Email%20Images/meal_quiz/' +
		meal_1_name +
		'.jpg"  align="middle" style="width:100%; max-width: 100%;height: auto;"  ></a><p><strong>' +
		meal_2_result +
		'</strong></p><a class="d-block" href="https://www.trifectanutrition.com/' +
		meal_2_link +
		'"><img src="https://www.trifectanutrition.com/hubfs/Email%20Images/meal_quiz/' +
		meal_2_name +
		'.jpg"  align="middle" style="width:100%; max-width: 100%;height: auto;"  ></a><p><strong>' +
		meal_3_result +
		'</strong></p><a class="d-block" href="https://www.trifectanutrition.com/' +
		meal_3_link +
		'"><img src="https://www.trifectanutrition.com/hubfs/Email%20Images/meal_quiz/' +
		meal_3_name +
		'.jpg"  align="middle" style="width:100%; max-width: 100%;height: auto;"  ></a>';
	if ($('#results_toggle').length == 1) {
		$('#thank-you').append(results);
	}
	$('#form-id form').hide();
	$('#thank-you').fadeIn(900);
	$('html, body').animate(
		{
			scrollTop: $('#form-steps').offset().top,
		},
		900
	);
};

  })();
