<?php

/**
 * Helper functions for the Registry::class
 * 
 */

if (!function_exists('neurogenesis_theme_registry_get')) {
    /**
     * neurogenesis_theme_registry_get Helper function to get a variable from the registry
     *
     * @param  string $name
     * @param  mixed $default
     * @return mixed value
     */

    function neurogenesis_theme_registry_get($name, $default = null)
    {
        $registry = \NeurogenesisTheme\Core\Registry::getInstance();
        
        
        if (strpos($name, '/') !== false) {
            $temp_var = explode('/', $name);
            $group_name = $temp_var[0];
            $var_name = $temp_var[1];
            $_var = $registry->get($group_name, []);

            if (isset($_var[$var_name])) {
                return $_var[$var_name];
            }

            return $default;
        }

        return $registry->get($name, $default);        
    }
}

if (!function_exists('neurogenesis_theme_registry_set')) {
    /**
     * neurogenesis_theme_registry_set Helper function to set a variable into the registry
     *
     * @param  string $name
     * @param  mixed $default
     * @return void
     */

    function neurogenesis_theme_registry_set($name, $value)
    {
        $registry = \NeurogenesisTheme\Core\Registry::getInstance();
        $registry->set($name, $value);
    }
}

if (!function_exists('neurogenesis_theme_registry_delete')) {
    /**
     * neurogenesis_theme_registry_delete Helper function to delete a variable fromt the registry
     *
     * @param  string $name     
     * @return void
     */

    function neurogenesis_theme_registry_delete($name)
    {
        $registry = \NeurogenesisTheme\Core\Registry::getInstance();
        $registry->delete($name);
    }
}