<?php

/**
 * The header for our theme
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package FLEX_GUTENBERG_THEME
 */

$body_class = '';

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

// Block Appear On Scroll
if ($data['disableFadingDesktop'] === FALSE) {
	$body_class .= ' fgt-block-appear-on-scroll-desktop';
}
if ($data['disableFadingTablet'] === FALSE) {
	$body_class .= ' fgt-block-appear-on-scroll-tablet';
}
if ($data['disableFadingMobile'] === FALSE) {
	$body_class .= ' fgt-block-appear-on-scroll-mobile';
}

// Favicon
$favicon = '';
if (isset($data['favicon']) && $data['favicon']) {
	$href = $data['favicon']['sizes']['full']['url'];
	$favicon =  '<link rel="shortcut icon" href="' . $href . '" />';
}

// Button Scheme Body Class
$body_class .= ' fgt-button-' . $data['formsDefaultButtonScheme'];

// Fields Style Body Class
$body_class .= ' fgt-fields-style-' . $data['formsFieldBorderStyle'];

// Content Width
$content_width = $data['contentWidth'];
//$post = get_post();
global $fgt_global_post;


if ($fgt_global_post->post_type === 'fgt_g_template' || $fgt_global_post->post_type === 'fgt_p_template') {
	$useGlobalWidth = get_post_meta($fgt_global_post->ID, '_flothemes_use_global_content_width_metabox_field', TRUE);
	$useGlobalWidth = $useGlobalWidth === "on" || $useGlobalWidth === '';

	if (!$useGlobalWidth) {
		$content_width = get_post_meta($fgt_global_post->ID, '_flothemes_content_width_metabox_field', TRUE);
		$content_width = $content_width ? $content_width : 800;
	}
}


?>
<!doctype html>
<html <?php language_attributes(); ?>>

<head>
	<meta charset="<?php bloginfo('charset'); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="profile" href="https://gmpg.org/xfn/11">

	<?php echo $favicon ?>
	<?php wp_head(); ?>
	<?php echo fgt_render_header_custom_code($data); ?>
	<?php fgt_render_link_styles($data) ?>
</head>

<body <?php body_class($body_class); ?> style="
		--siteBackgroundColor: <?php echo getStyleKitColor($data['siteBackgroundColor']); ?>;
		--siteColor: <?php echo getStyleKitColor($data['siteColor']); ?>;
		--siteContentWidth: <?php echo $content_width / 16 ?>rem;
		--postImageMarginBottom: <?php echo $data['postImageMarginBottom'] / 16 ?>rem;
	">
	<?php fgt_render_preloader($data) ?>

	<?php wp_body_open(); ?>
	<?php include 'flo-app/public/render/headers/index.php'; ?>