<?php


if (!function_exists('fgt_render_font')) {
	function fgt_render_font($fontStyleName, $selectors, $overrides = '')
	{
		$fontStyle = getStylekitFontStyle($fontStyleName);

		// Desktop
		$style = $selectors . ' {';
		if (isset($fontStyle["lineHeight"])) {
			$style .= 'line-height: ' . $fontStyle["lineHeight"] . 'em;';
		}
		if (isset($fontStyle["fontSize"])) {
			$style .= 'font-size: ' . ($fontStyle["fontSize"] / 16) . 'rem;';
		}
		if (isset($fontStyle["letterSpacing"])) {
			$style .= 'letter-spacing: ' . $fontStyle["letterSpacing"] . 'em;';
		}
		if (isset($fontStyle["fontFamily"])) {
			$style .= 'font-family: ' . $fontStyle["fontFamily"] . ';';
		}
		if (isset($fontStyle["fontWeight"])) {
			$fontWeight = $fontStyle["fontWeight"];
			if ($fontWeight === 'regular') {
				$fontWeight = 'normal';
			}
			$style .= 'font-weight: ' . $fontWeight . ';';
		}
		if (isset($fontStyle["fontStyle"])) {
			$style .= 'font-style: ' . $fontStyle["fontStyle"] . ';';
		}
		if (isset($fontStyle["textDecoration"])) {
			$style .= 'text-decoration: ' . $fontStyle["textDecoration"] . ';';
		}
		if (isset($fontStyle["textTransform"])) {
			$style .= 'text-transform: ' . $fontStyle["textTransform"] . ';';
		}
		$style .= $overrides;
		$style .= '}';

		// Mobile
		$style .= '@media (max-width: 767px) {';

		$style .= ' {';

		if (isset($fontStyle['mobile']["lineHeight"])) {
			$style .= 'line-height: ' . $fontStyle['mobile']["lineHeight"] . 'em;';
		}

		if (isset($fontStyle['mobile']["fontSize"])) {
			$style .= 'font-size: ' . ($fontStyle['mobile']["fontSize"] / 16) . 'rem;';
		}

		if (isset($fontStyle['mobile']["letterSpacing"])) {
			$style .= 'letter-spacing: ' . $fontStyle['mobile']["letterSpacing"] . 'em;';
		}

		$style .= '
        }
      }
    ';

		return $style;
	}
}

if (!function_exists('fgt_render_form_styles')) {
	function fgt_render_form_styles()
	{
		if (!function_exists('getStylekitFontStyle')) {
			return;
		}

		$data = flo_get_global_option_arr('fgt_options');
		if (gettype($data) === 'string') {
			$data = json_decode($data, TRUE);
		}

		$style = '';

		// Field Color
		$style .= '
      body {
        --fgt-field-color: ' . getStyleKitColor($data['formsFieldColor']) . ';
      }
    ';

		// Label Font
		$style .= fgt_render_font(
			$data['formsFieldLabelFont'],
			'
        /* Generic */
        body label,

        /* Ninja Form */
        .entry-content .nf-field-label label,

        /* WP Forms */
        .entry-content div.wpforms-container-full .wpforms-form  .wpforms-field-label,
        .entry-content div.wpforms-container-full .wpforms-form  label
      '
		);

		// Field Font
		$style .= fgt_render_font(
			$data['formsFieldFont'],
			'
        /* Generic */
          *:not(.flo-block-newsletter):not(.flo-comments-block) input:not([type="button"]):not([type="submit"]),
          *:not(.flo-block-newsletter):not(.flo-comments-block) textarea,
         body select,
         body .select2-selection__placeholder,
         body .select2-selection__rendered,

        /* Ninja Form */
        .entry-content .nf-field-element input:not([type="button"]):not([type="submit"]),
        .entry-content select.ninja-forms-field.nf-element,
        .entry-content textarea.ninja-forms-field.nf-element,

        /* WP Forms */
        .entry-content div.wpforms-container-full .wpforms-form input:not([type="button"]):not([type="submit"]),
        .entry-content div.wpforms-container-full .wpforms-form textarea

      '
		);

		// Field Border Style

		// Checkbox Label Font
		$style .= fgt_render_font(
			$data['formsCheckboxLabelFont'],
			'
        /* Contact Form 7 */
        .entry-content .wpcf7-list-item-label,

        /* Flo Form */
        .field-checklist .list-row label,
        .field-radios .radio-list label,
        .field-checkbox label,

        /* WP Forms */
        .entry-content div.wpforms-container-full .wpforms-form .wpforms-field-label-inline,

        /* Ninja Forms */
        .listcheckbox-container .nf-field-element label
      '
		);

		// Button Font
		$style .= fgt_render_font(
			$data['formsButtonFont'],
			'
        /* Generic */
         *:not(.flo-block-newsletter):not(.flo-comments-block) input[type="submit"]:not(.flo-generic-button),
         *:not(.flo-block-newsletter):not(.flo-comments-block) input[type="button"],
         *:not(.flo-block-newsletter):not(.flo-comments-block) button[type="submit"],
        body .woocommerce a.button,

        /* Ninja Form */
        .entry-content  .nf-field-element input[type="button"],

        /* WP Forms */
        .entry-content  div.wpforms-container-full .wpforms-form .wpforms-submit,

        /* Flo Forms */
        .app-flo-forms .vue-form-generator:not(.ff-pro) .field-submit input[type=submit]
      '
		);

		// Ninja Form Before Text
		$style .= fgt_render_font(
			'second_level/paragraph',
			'
        .entry-content .nf-before-form-content
      '
		);

		// Ninja Form Checkbox Label Font
		$style .= fgt_render_font(
			$data['formsCheckboxLabelFont'],
			'
        .entry-content .nf-field .checkbox-wrap .nf-field-label label
      ',
			'line-height: 1.6em;'
		);

		// Ninja Form Error Message
		$style .= fgt_render_font(
			$data['formsFieldLabelFont'],
			'
        .entry-content .nf-error-msg.nf-error-invalid-email
      '
		);

		// Ninja Form Error Message
		$style .= fgt_render_font(
			'second_level/paragraph',
			'
        .entry-content .nf-error-msg.nf-error-field-errors
      '
		);

		// WP Forms Slider Hint
		$style .= fgt_render_font(
			$data['formsCheckboxLabelFont'],
			'
        /* Ninja Form */
        .entry-content div.wpforms-container-full .wpforms-form .wpforms-field-number-slider-hint
      '
		);


		echo '
      <style class="fgt-form-styles">
        ' . $style . '
      </style>
    ';
	}
}
