<?php

class Flo_Flex_Builder_GET_Global_Data {
	public function __construct() {
        $this->set_global_vars();
    }

    public function set_global_vars() {
        global $active_stylekit_colors;
        global $active_stylekit_fonts;

        $id = get_the_ID();
        $custom_stylekits_per_page = get_option('flex_stylekits_pages');

        $active_stylekit_id = '';
        if (isset($custom_stylekits_per_page[$id]) && $custom_stylekits_per_page[$id]["enabled"] === '1') {
            $active_stylekit_id = $custom_stylekits_per_page[$id]["stylekit_value"];
        } else {
            $active_stylekit_id = get_option('flex_active_stylekit_name');
        }

        $all_stylekits = get_option('flex_all_stylekits_obj'); 
        $active_stylekit = $active_stylekit_id !== '' ? $all_stylekits[$active_stylekit_id] : [];
        $colors = isset($active_stylekit['colors']) ? $active_stylekit['colors'] : [];
        $fonts = isset($active_stylekit['fonts']) ? $active_stylekit['fonts']: [];

        $active_stylekit_colors = $colors;
        $active_stylekit_fonts = $fonts;
    }
}
add_action('wp', 'init_get_global_data');

function init_get_global_data() {
    new Flo_Flex_Builder_GET_Global_Data();
}
