<?php

if (! defined('ABSPATH')) {
    exit;
} function puffergo_get_header_logo_identity()
{
    return puffergo_get_site_brand_identity();
} function puffergo_get_header_menu_items()
{
    static $cached = null;

    if (null !== $cached) {
        return $cached;
    } $tree = puffergo_get_menu_tree('puffergo_primary', 'PufferGo Header');
    $cached = puffergo_inject_dynamic_product_categories($tree);

    return $cached;
} function puffergo_inject_dynamic_product_categories(array $items)
{
    $archive_url = get_post_type_archive_link('puffergo_product');

    if (! $archive_url) {
        return $items;
    } $archive_path = '/' . trim((string) wp_parse_url($archive_url, PHP_URL_PATH), '/');

    foreach ($items as &$item) {
        $item_path = '/' . trim((string) wp_parse_url($item->url, PHP_URL_PATH), '/');

        if ($item_path !== $archive_path) {
            continue;
        } $terms = get_terms(array('taxonomy' => 'puffergo_product_cat', 'hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC', ));

        if (is_wp_error($terms) || empty($terms)) {
            break;
        } $item->children = puffergo_build_product_cat_tree($terms, 0);
        break;
    } unset($item);

    return $items;
} function puffergo_build_product_cat_tree(array $terms, $parent_id)
{
    $nodes = array();

    foreach ($terms as $term) {
        if ((int) $term->parent !== (int) $parent_id) {
            continue;
        } $children = puffergo_build_product_cat_tree($terms, (int) $term->term_id);

        if ((int) $term->count === 0 && empty($children)) {
            continue;
        } $term_link = get_term_link($term);
        $node = new stdClass();
        $node->id = 0;
        $node->url = is_wp_error($term_link) ? '' : $term_link;
        $node->title = $term->name;
        $node->object_id = $term->term_id;
        $node->object = 'puffergo_product_cat';
        $node->icon = '';
        $node->description = isset($term->description) ? $term->description : '';
        $node->children = $children;
        $nodes[] = $node;
    }

return $nodes;
} function puffergo_is_clickable_parent($item)
{
    $url = trim((string) ($item->url ?? ''));

    return '' !== $url && '#' !== $url;
} function puffergo_get_header_context(array $options = array())
{
    $current_page_id = get_queried_object_id();
    $home_url = PufferGo_Polylang::home_url();
    $front_page_id = (int) get_option('page_on_front', 0);
    $current_path = untrailingslashit((string) wp_parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH));
    $is_current = function ($item) use ($current_page_id, $home_url, $front_page_id, $current_path) {
        if (in_array($item->object, array('post', 'page'), true)) {
            if ((int) $item->object_id === (int) $current_page_id) {
                return true;
            }
        }

if (! empty($item->url)) {
            $item_path = untrailingslashit((string) wp_parse_url($item->url, PHP_URL_PATH));

            if ('' !== $item_path && $item_path === $current_path) {
                return true;
            }
        }

if (is_front_page()) {
            $item_url = trailingslashit($item->url);

            if ($item_url === $home_url) {
                return true;
            }

if ($front_page_id > 0 && in_array($item->object, array('post', 'page'), true) && (int) $item->object_id === $front_page_id) {
                return true;
            }
        }

return false;
    };
    $menu_items = puffergo_get_header_menu_items();
    $context = array('menu_items' => $menu_items, 'has_menu' => ! empty($menu_items), 'current_page_id' => $current_page_id, 'home_url' => $home_url, 'is_current' => $is_current, );

    if (! empty($options['with_site_identity'])) {
        $context['site_name'] = get_bloginfo('name');
        $context['site_description'] = get_bloginfo('description');
        $logo_identity = puffergo_get_header_logo_identity();
        $context['logo_id'] = $logo_identity['logo_id'];
        $context['logo_url'] = $logo_identity['logo_url'];
        $context['logo_alt'] = $logo_identity['logo_alt'];
        $context['brand_name'] = $logo_identity['brand_name'];
    }

if (! empty($options['with_fullpage_ui'])) {
        $context['show_header_style_selector'] = ! empty($GLOBALS['puffergo_fullpage_template']) && current_user_can('edit_posts');
        $context['current_footer_template'] = class_exists('PufferGo_Template_Loader') ? PufferGo_Template_Loader::get_active_footer() : get_option('puffergo_footer_template', 'footer-3');
    }

return apply_filters('puffergo_header_context', $context, $options);
}
