<?php
/**
 * Filters the menu toggles for specific modules in the Divi Builder.
 * This function adds a toggle for Divi Responsive Helper to the settings modal toggles
 * of the 'et_pb_menu' and 'et_pb_fullwidth_menu' modules.
 *
 * @param array $modules An array of modules.
 * @param string $post_type The post-type of the current page.
 *
 * @return array The modified array of modules.
 */
if (!function_exists('pac_drh_filter_menu_toggles')):
    function pac_drh_filter_menu_toggles($modules, $post_type)
    {
        static $is_applied = false;
        if ($is_applied) {
            return $modules;
        }
        if (empty($modules)) {
            return $modules;
        }
        foreach ($modules as $module_slug => $module) {
            if ('et_pb_menu' === $module_slug || 'et_pb_fullwidth_menu' === $module_slug) {
                if (!isset($module->settings_modal_toggles) || !isset($module->fields_unprocessed)) {
                    continue;
                }
                $toggles_list = $module->settings_modal_toggles;
                if (isset($toggles_list['general']) && !empty($toggles_list['general']['toggles'])) {
                    $toggles_list['general']['toggles']['divi_responsive_helper'] = [
                        'title' => __('Divi Responsive Helper', 'divi-responsive-helper'),
                        'priority' => 15,
                    ];
                    $module->settings_modal_toggles = $toggles_list;
                }
            }
        }
        $is_applied = true;

        return $modules;
    }

    add_filter('et_builder_get_parent_modules', 'pac_drh_filter_menu_toggles', 10, 2);
endif;
/**
 * Filter menu fields to add custom options.
 *
 * @param array $fields_unprocessed The original menu fields.
 *
 * @return array The modified menu fields.
 */
if (!function_exists('pac_drh_filter_menu_fields')):
    function pac_drh_filter_menu_fields($fields_unprocessed)
    {

        $custom_fields = [];
        // Choose Navigation Menu Per Device In Menu Module
        $fields_unprocessed['menu_id']['mobile_options'] = true;
        // Show A Hamburger Menu On Desktop
        $custom_fields['use_hamburger_menu_desktop'] = [
            'label' => __('Show A Hamburger Menu On Desktop', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to replace the open Desktop menu with a hamburger menu instead.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        $custom_fields['closed_menu_icon'] = [
            'label' => __('Menu Closed Icon', 'divi-responsive-helper'),
            'type' => 'select_icon',
            'description' => __('Choose an icon for the menu when it is closed.', 'divi-responsive-helper'),
            'default' => 'a',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        $custom_fields['opened_menu_icon'] = [
            'label' => __('Menu Opened Icon', 'divi-responsive-helper'),
            'type' => 'select_icon',
            'description' => __('Choose an icon for the menu when it is opened.', 'divi-responsive-helper'),
            'default' => 'M',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Add Text Beside Hamburger Menu Icon
        $custom_fields['use_hamburger_menu_text'] = [
            'label' => __('Add Text Beside Hamburger Menu Icon', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Add custom text to the left side of the hamburger menu icon.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Hamburger Menu Text
        $custom_fields['hamburger_menu_text'] = [
            'label' => __('Hamburger Menu Text', 'divi-responsive-helper'),
            'type' => 'text',
            'description' => __('Enter custom text to show on the left side of the hamburger menu icon.', 'divi-responsive-helper'),
            'default' => __('Menu', 'divi-responsive-helper'),
            'show_if' => [
                'use_hamburger_menu_text' => 'on'
            ],
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Show An Open Menu On Phone
        $custom_fields['use_opened_menu_on_phone'] = [
            'label' => __('Show An Open Menu On Phone', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to remove the hamburger menu icon and open the menu instead on Phone devices.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Collapse Mobile Menu Submenus
        $custom_fields['use_collapse_mobile_submenus'] = [
            'label' => __('Collapse Mobile Menu Submenus', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to collapse the submenu by default.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        $custom_fields['use_collapse_other_submenus'] = [
            'label' => __('Collapse Submenu When Another Is Opened', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to collapse the open submenu when another submenu is opened.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'show_if' => ['use_collapse_mobile_submenus' => 'on'],
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Open/Close Submenus By Clicking Parent Menu Item
        $custom_fields['use_openclose_submenu_with_parent'] = [
            'label' => __('Open/Close Submenus By Clicking Parent Menu Item', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to open and close the submenu by clicking the parent menu item. This effectively disables the parent menu link.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'show_if' => ['use_collapse_mobile_submenus' => 'on'],
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        $custom_fields['collapse_icon_color'] = [
            'label' => __('Collapsible Submenu Icon Color', 'divi-responsive-helper'),
            'type' => 'color-alpha',
            'custom_color' => true,
            'description' => __('Pick a color for the collapsible submenus icon.', 'divi-responsive-helper'),
            'default' => '#2ea3f2',
            'show_if' => ['use_collapse_mobile_submenus' => 'on'],
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        $custom_fields['collapse_icon_bg_color'] = [
            'label' => __('Collapsible Submenu Icon Background Color', 'divi-responsive-helper'),
            'type' => 'color-alpha',
            'custom_color' => true,
            'description' => __('Pick a color for the collapsible submenus icon background.', 'divi-responsive-helper'),
            'default' => '#f0f3f6',
            'show_if' => ['use_collapse_mobile_submenus' => 'on'],
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Close Mobile Menu Outside Click
        $custom_fields['use_close_mobile_menu_outside_click'] = [
            'label' => __('Close Mobile Menu By Clicking Outside Dropdown', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to make the mobile menu dropdown close by clicking the area around the outside of it.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Menu Breakpoint
        $custom_fields['use_menu_break_point'] = [
            'label' => __('Menu Breakpoint', 'divi-responsive-helper'),
            'type' => 'range',
            'range_settings' => [
                'min' => 0,
                'max' => '2000',
                'step' => '1',
            ],
            'default' => '',
            'validate_unit' => true,
            'fixed_unit' => 'px',
            'fixed_range' => true,
            'description' => __('Enter the screen width pixel value for the responsive breakpoint for for when the menu changes between desktop and mobile versions. The default value in Divi is 981px.',
                'divi-responsive-helper'),
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        // Mobile Menu Height Scrollable
        $custom_fields['use_mobile_menu_scrollable'] = [
            'label' => __('Make Mobile Menu Height Scrollable', 'divi-responsive-helper'),
            'type' => 'yes_no_button',
            'description' => __('Choose to make the mobile menu scrollable to solve the situations when the menu is too tall and goes off the bottom of the screen.', 'divi-responsive-helper'),
            'options' => [
                'on' => et_builder_i18n('Yes'),
                'off' => et_builder_i18n('No'),
            ],
            'default' => 'off',
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];
        $custom_fields['mobile_menu_max_height'] = [
            'label' => __('Mobile Menu Scrollable Max Height', 'divi-responsive-helper'),
            'type' => 'text',
            'description' => __('Set the maximum height of the mobile menu. A scrollbar will be used if the menu is taller than this height.', 'divi-responsive-helper'),
            'default' => '80vh',
            'show_if' => [
                'use_mobile_menu_scrollable' => 'on'
            ],
            'option_category' => 'basic_option',
            'toggle_slug' => 'divi_responsive_helper',
        ];

        return wp_parse_args($custom_fields, $fields_unprocessed);
    }

    add_filter('et_pb_all_fields_unprocessed_et_pb_menu', 'pac_drh_filter_menu_fields');
    add_filter('et_pb_all_fields_unprocessed_et_pb_fullwidth_menu', 'pac_drh_filter_menu_fields');
endif;
/**
 * Filters the output of the Divi menu module.
 *
 * @param string|array $output The output of the Divi menu module.
 * @param string $render_slug The slug of the module being rendered.
 * @param object $module The Divi module object.
 *
 * @return string|array The modified output of the Divi menu module.
 */
if (!function_exists('pac_drh_filter_menu_output')):
    function pac_drh_filter_menu_output($output, $render_slug, $module)
    {
        if (function_exists('et_fb_is_enabled') && et_fb_is_enabled()) {
            return $output;
        }
        if (function_exists('et_builder_bfb_enabled') && et_builder_bfb_enabled()) {
            return $output;
        }
        if (is_admin() || wp_doing_ajax() || is_array($output)) {
            return $output;
        }
        if ('et_pb_menu' !== $render_slug && 'et_pb_fullwidth_menu' !== $render_slug) {
            return $output;
        }
        $props = $module->props;
        $module_order = ET_Builder_Element::get_module_order_class($render_slug);
        $order_class = '.'.$module_order;
        //======================================================================
        // Menu Icon
        //======================================================================
        $closed_menu_icon = isset($props['closed_menu_icon']) ? $props['closed_menu_icon'] : '';
        if (!empty($closed_menu_icon)) {
            if ((function_exists('et_pb_get_icon_font_family') && function_exists('et_pb_get_icon_font_weight'))) {
                ET_Builder_Element::set_style($render_slug, [
                    'selector' => '%%order_class%% .et_mobile_nav_menu .mobile_nav.closed .mobile_menu_bar:before',
                    'declaration' => sprintf("font-family:%s !important;font-weight:%s;", et_pb_get_icon_font_family($closed_menu_icon), et_pb_get_icon_font_weight($closed_menu_icon)),
                ]);
            }
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_mobile_nav_menu .mobile_nav.closed .mobile_menu_bar:before',
                'declaration' => sprintf("content:'%s';", html_entity_decode(esc_attr(et_pb_process_font_icon($closed_menu_icon))))
            ]);
        }
        $opened_menu_icon = isset($props['opened_menu_icon']) ? $props['opened_menu_icon'] : '';
        if (!empty($opened_menu_icon)) {
            if ((function_exists('et_pb_get_icon_font_family') && function_exists('et_pb_get_icon_font_weight'))) {
                ET_Builder_Element::set_style($render_slug, [
                    'selector' => '%%order_class%% .et_mobile_nav_menu .mobile_nav.opened .mobile_menu_bar:before',
                    'declaration' => sprintf("font-family:%s !important;font-weight:%s;", et_pb_get_icon_font_family($opened_menu_icon), et_pb_get_icon_font_weight($opened_menu_icon)),
                ]);
            }
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_mobile_nav_menu .mobile_nav.opened .mobile_menu_bar:before',
                'declaration' => sprintf("content:'%s';", html_entity_decode(esc_attr(et_pb_process_font_icon($opened_menu_icon))))
            ]);
        }
        //======================================================================
        // Add Text Beside Hamburger Menu Icon
        //======================================================================
        $use_hamburger_menu_text = isset($props['use_hamburger_menu_text']) && 'on' === $props['use_hamburger_menu_text'];
        $hamburger_menu_text = !empty($props['hamburger_menu_text']) ? $props['hamburger_menu_text'] : '';
        if ($use_hamburger_menu_text) {
            $menu_font = $props['menu_font'];
            $menu_text_color = $props['menu_text_color'];
            $active_link_color = $props['menu_text_color__hover'] ?? null;
            $menu_font_size = $props['menu_font_size'];
            $menu_letter_spacing = $props['menu_letter_spacing'];
            $menu_line_height = $props['menu_line_height'];
            $text_shadow_declaration = '';
            if (
                !empty($props['menu_text_shadow_horizontal_length']) &&
                !empty($props['menu_text_shadow_vertical_length']) &&
                !empty($props['menu_text_shadow_blur_strength']) &&
                !empty($props['menu_text_shadow_color'])
            ) {
                $text_shadow_declaration = sprintf(
                    'text-shadow: %1$s %2$s %3$s %4$s;',
                    esc_attr($props['menu_text_shadow_horizontal_length']),
                    esc_attr($props['menu_text_shadow_vertical_length']),
                    esc_attr($props['menu_text_shadow_blur_strength']),
                    esc_attr($props['menu_text_shadow_color'])
                );
            }
            ET_Builder_Element::set_style(
                $render_slug,
                [
                    'selector' => '%%order_class%% .et_mobile_nav_menu:before',
                    'declaration' => sprintf(
                        'content:"%1$s"; position:relative; %2$s %3$s',
                        esc_attr($hamburger_menu_text),
                        implode(' ', array_filter([
                            !empty($menu_text_color) ? 'color:'.esc_attr($menu_text_color).';' : '',
                            !empty($menu_font_size) ? 'font-size:'.esc_attr($menu_font_size).';' : '',
                            !empty($menu_line_height) ? 'line-height:'.esc_attr($menu_line_height).';' : '',
                            !empty($menu_letter_spacing) ? 'letter-spacing:'.esc_attr($menu_letter_spacing).';' : '',
                            !empty($menu_font) ? et_builder_set_element_font($menu_font) : '',
                        ])), $text_shadow_declaration
                    ),
                ]
            );
            ET_Builder_Element::set_style(
                $render_slug,
                [
                    'selector' => '%%order_class%% .et_mobile_nav_menu.active_menu:before',
                    'declaration' => sprintf("color:%s;", esc_attr($active_link_color)),
                ]
            );
            wp_register_script('divi-responsive-helper-menu-text-'.$module_order, false);
            wp_enqueue_script('divi-responsive-helper-menu-text-'.$module_order);
            wp_add_inline_script('divi-responsive-helper-menu-text-'.$module_order, "jQuery(document).ready(function () {
                                jQuery('$order_class .mobile_menu_bar').on('click', function () {
                                    var mobileNav = jQuery(this).closest('.et_mobile_nav_menu').find('.et_mobile_menu');
                                    setTimeout(function () {
                                        if (mobileNav.css('display') === 'block') {
                                            jQuery('.et_mobile_nav_menu').addClass('active_menu');
                                        } else {
                                            jQuery('.et_mobile_nav_menu').removeClass('active_menu');
                                        }
                                    }, 550);
                                });
                            });");
        }
        //======================================================================
        // Show A Hamburger Menu On Desktop
        //======================================================================
        $use_hamburger_menu_desktop = isset($props['use_hamburger_menu_desktop']) && 'on' === $props['use_hamburger_menu_desktop'];
        if ($use_hamburger_menu_desktop) {
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%%.et_pb_menu .et_pb_menu__menu, %%order_class%%.et_pb_fullwidth_menu .et_pb_menu__menu',
                'declaration' => 'display:none;',
                'media_query' => ET_Builder_Element::get_media_query('min_width_981'),
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%%.et_pb_menu .et_mobile_nav_menu, %%order_class%%.et_pb_fullwidth_menu .et_mobile_nav_menu',
                'declaration' => 'display:flex;float:none;margin:0 6px;align-items:center;',
                'media_query' => ET_Builder_Element::get_media_query('min_width_981'),
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%%.et_pb_menu .et_mobile_nav_menu li',
                'declaration' => 'list-style-type:none;',
                'media_query' => ET_Builder_Element::get_media_query('min_width_981'),
            ]);
        }
        //======================================================================
        // Show An Open Menu On Phone
        //======================================================================
        $use_opened_menu_on_phone = isset($props['use_opened_menu_on_phone']) && 'on' === $props['use_opened_menu_on_phone'];
        if ($use_opened_menu_on_phone) {
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_pb_menu__menu',
                'declaration' => 'display:flex!important;',
                'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_mobile_nav_menu',
                'declaration' => 'display:none!important;',
                'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
            ]);
        }
        //======================================================================
        // Collapse Mobile Menu Submenus
        //======================================================================
        $use_collapse_mobile_submenus = isset($props['use_collapse_mobile_submenus']) && 'on' === $props['use_collapse_mobile_submenus'];
        if ($use_collapse_mobile_submenus) {
            $color = !empty($props['collapse_icon_color']) ? $props['collapse_icon_color'] : '#2ea3f2';
            $bg_color = !empty($props['collapse_icon_bg_color']) ? $props['collapse_icon_bg_color'] : '#f0f3f6';
            // CSS
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu li.menu-item-has-children .mobile-toggle,%%order_class%% ul.et_mobile_menu li.page_item_has_children .mobile-toggle,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu li.menu-item-has-children .mobile-toggle,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu li.page_item_has_children .mobile-toggle',
                'declaration' => 'width: 44px;height: 100%;padding: 0px !important;max-height: 44px;border: none;position: absolute;right: 0px;top: 0px;z-index: 999;background-color: transparent;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu > li.menu-item-has-children,%%order_class%% ul.et_mobile_menu > li.page_item_has_children,%%order_class%% ul.et_mobile_menu > li.menu-item-has-children .sub-menu li.menu-item-has-children,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu > li.menu-item-has-children,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu > li.page_item_has_children,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu > li.menu-item-has-children .sub-menu li.menu-item-has-children',
                'declaration' => 'position: relative;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_mobile_menu .menu-item-has-children > a,%%order_class%% .et-db #et-boc .et-l .et_mobile_menu .menu-item-has-children > a',
                'declaration' => 'background-color: transparent;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu .menu-item-has-children .sub-menu,%%order_class%% #main-header ul.et_mobile_menu .menu-item-has-children .sub-menu,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu .menu-item-has-children .sub-menu,%%order_class%% .et-db #main-header ul.et_mobile_menu .menu-item-has-children .sub-menu',
                'declaration' => 'display: none !important;visibility: hidden !important;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu .menu-item-has-children .sub-menu.visible,%%order_class%% #main-header ul.et_mobile_menu .menu-item-has-children .sub-menu.visible,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu .menu-item-has-children .sub-menu.visible,%%order_class%% .et-db #main-header ul.et_mobile_menu .menu-item-has-children .sub-menu.visible',
                'declaration' => 'display: block !important;visibility: visible !important;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu li.menu-item-has-children .mobile-toggle,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu li.menu-item-has-children .mobile-toggle',
                'declaration' => 'text-align: center;opacity: 1;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu li.menu-item-has-children .mobile-toggle::after,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu li.menu-item-has-children .mobile-toggle::after',
                'declaration' => 'top: 10px;position: relative;font-family: "ETModules", serif;content: \'\33\';color: '.esc_attr($color).';background:'.esc_attr($bg_color).';border-radius: 50%;padding: 3px;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% ul.et_mobile_menu li.menu-item-has-children.dt-open > .mobile-toggle::after,%%order_class%% .et-db #et-boc .et-l ul.et_mobile_menu li.menu-item-has-children.dt-open > .mobile-toggle::after',
                'declaration' => 'content: \'\32\';',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_pb_menu .et_mobile_menu:after',
                'declaration' => "position: absolute;right: 5%;margin-left: -20px;top: -23px;width: 0;height: 0;content: '';border-left: 20px solid transparent;border-right: 20px solid transparent;border-bottom: 20px solid #ffffff;",
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .mobile_menu_bar',
                'declaration' => 'position: relative;display: block;line-height: 0;',
            ]);
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%% .et_pb_menu .et_mobile_menu,%%order_class%% .et_pb_menu .et_mobile_menu ul',
                'declaration' => 'background-color: #ffffff !important;border-radius: 10px;',
            ]);
            //======================================================================
            // Menu Click Settings
            //======================================================================
            $use_openclose_submenu_with_parent = isset($props['use_openclose_submenu_with_parent']) && 'on' === $props['use_openclose_submenu_with_parent'];
            $use_collapse_other_submenus = isset($props['use_collapse_other_submenus']) && 'on' === $props['use_collapse_other_submenus'];
            $use_close_mobile_menu_outside_click = isset($props['use_close_mobile_menu_outside_click']) && 'on' === $props['use_close_mobile_menu_outside_click'];
            add_action('wp_footer', function () use ($use_openclose_submenu_with_parent, $use_collapse_other_submenus, $use_close_mobile_menu_outside_click, $module_order, $order_class) { ?>
                <script type="text/javascript" id="divi-responsive-helper-menu-module-collapse-menu-submenus-inline-js">
                    jQuery(function ($) {
                        $(document).ready(function () {
                            let orderClass = '<?php echo esc_js($order_class);?>';
                            let isCollapseMobileSubMenus = '<?php echo esc_js($use_collapse_other_submenus);?>';
                            let isCollapseSubmenuWithParent = '<?php echo esc_js($use_openclose_submenu_with_parent);?>';
                            let isCloseMenuWithOutSideClick = '<?php echo esc_js($use_close_mobile_menu_outside_click);?>';
                            const $toggle = $('<a>', {
                                href: '#',
                                class: 'mobile-toggle',
                                'aria-label': 'Toggle menu'
                            });
                            $(`${orderClass}.et_pb_menu ul.et_mobile_menu li.menu-item-has-children, body .et_pb_menu ul.et_mobile_menu li.page_item_has_children`).append($toggle);
                            $(`${orderClass}.et_pb_menu ul.et_mobile_menu li.menu-item-has-children .mobile-toggle, .et_pb_menu ul.et_mobile_menu li.page_item_has_children .mobile-toggle`).click(function (e) {
                                e.preventDefault();
                                let parentItem = jQuery(this).parent('li');
                                if (parentItem.hasClass('dt-open')) {
                                    parentItem.toggleClass('dt-open');
                                    parentItem.find('ul.children').first().toggleClass('visible');
                                    parentItem.find('ul.sub-menu').first().toggleClass('visible');
                                } else {
                                    if (!parentItem.parent('ul').hasClass('visible') && isCollapseMobileSubMenus) {
                                        jQuery('li.menu-item-has-children').removeClass('dt-open');
                                        jQuery('li.menu-item-has-children .sub-menu').removeClass('visible');
                                    }
                                    parentItem.toggleClass('dt-open');
                                    parentItem.find('ul.children').first().toggleClass('visible');
                                    parentItem.find('ul.sub-menu').first().toggleClass('visible');
                                }
                            });
                            $(`${orderClass} ul.et_mobile_menu li.menu-item-has-children, body ul.et_mobile_menu li.page_item_has_children`).attr('data-icon', 'P');
                            $(`${orderClass}.mobile-toggle`).on('mouseover', function () {
                                $(this).parent().addClass('is-hover');
                            }).on('mouseout', function () {
                                $(this).parent().removeClass('is-hover');
                            })
                            // Collapse Sub menus With Parent Click
                            if (isCollapseSubmenuWithParent) {
                                $(`${orderClass} .et_mobile_nav_menu ul.et_mobile_menu li.menu-item-has-children, ${orderClass} .et_mobile_nav_menu ul.et_mobile_menu li.page_item_has_children`).each(function () {
                                    $(this).find('a:first').attr('href', 'javascript:void(0)').off('click');
                                    $(this).find('a:first').click(function () {
                                        $(this).find('ul').toggleClass('visible')
                                    });
                                });
                                setTimeout(function () {
                                    $(`${orderClass} .et_mobile_nav_menu .et_mobile_menu .menu-item.menu-item-has-children a:first-child`).click(function (e) {
                                        let parentItem = $(this).parent('li');
                                        if (parentItem.hasClass('dt-open')) {
                                            parentItem.toggleClass('dt-open');
                                            parentItem.find('ul.children').first().toggleClass('visible');
                                            parentItem.find('ul.sub-menu').first().toggleClass('visible');
                                        } else {
                                            if (!parentItem.parent('ul').hasClass('visible')) {
                                                $(`${orderClass} .et_mobile_nav_menu .et_mobile_menu li.menu-item-has-children`).removeClass('dt-open');
                                                $(`${orderClass} .et_mobile_nav_menu .et_mobile_menu li.menu-item-has-children .sub-menu`).removeClass('visible');
                                            }
                                            parentItem.toggleClass('dt-open');
                                            parentItem.find('ul.children').first().toggleClass('visible');
                                            parentItem.find('ul.sub-menu').first().toggleClass('visible');
                                        }
                                    });
                                }, 100)
                            }
                            // Closed Menu With Outside Click
                            if (isCloseMenuWithOutSideClick) {
                                $('body').click(function (e) {
                                    e.preventDefault();
                                    let mobileNav = $(`${orderClass} .et_mobile_nav_menu .mobile_nav`);
                                    if (!mobileNav.find('a').is(e.target) && mobileNav.hasClass('opened')) {
                                        $(`${orderClass} .et_mobile_nav_menu .mobile_menu_bar`).click();
                                    }
                                });
                            }
                        });
                    });
                </script>
                <?php
            });
        }
        //======================================================================
        // Menu Breakpoint
        //======================================================================
        if ((!empty($props['use_menu_break_point'])) && 0 !== (int)$props['use_menu_break_point']) {
            $breakpoint = esc_html($props['use_menu_break_point']);
            add_action('wp_footer', function () use ($breakpoint, $order_class) {
                echo PHP_EOL;
                $breakpoint_css = '';
                $int_breakpoint = (int)$breakpoint;
                if ($int_breakpoint > 981) {
                    $breakpoint_css = "@media only screen and (max-width:".esc_attr($breakpoint)."){ ".esc_attr($order_class)." .et_pb_menu__menu{display:none!important} ".esc_attr($order_class)." .et_mobile_nav_menu{display:flex!important} ".esc_attr($order_class)." ul.et_mobile_menu{list-style-type:none!important;padding:0!important}}";
                }
                if ($int_breakpoint < 980) {
                    $breakpoint_css = "@media only screen and (min-width:".esc_attr($breakpoint)."){ ".esc_attr($order_class)." .et_mobile_nav_menu{display:none!important} ".esc_attr($order_class)." .et_pb_menu__menu{display:flex!important} ".esc_attr($order_class)." ul.et_mobile_menu{list-style-type:none!important;padding:0!important}}";
                }
                echo sprintf('<style id="divi-responsive-helper-mmb-%1$s-inline-css">%2$s</style>', esc_html($int_breakpoint), esc_html($breakpoint_css));
                echo "</style>";
                echo PHP_EOL;
            });
        }
        //======================================================================
        // Add Text Beside Hamburger Menu Icon
        //======================================================================
        $use_mobile_menu_scrollable = isset($props['use_mobile_menu_scrollable']) && 'on' === $props['use_mobile_menu_scrollable'];
        if ($use_mobile_menu_scrollable) {
            $mobile_menu_max_height = isset($props['mobile_menu_max_height']) ? $props['mobile_menu_max_height'] : '80vh';
            ET_Builder_Element::set_style($render_slug, [
                'selector' => '%%order_class%%.et_pb_menu .et_mobile_menu, %%order_class%%.et_pb_fullwidth_menu .et_mobile_menu',
                'declaration' => "overflow-y:scroll!important;max-height:$mobile_menu_max_height!important;-overflow-scrolling:touch!important;-webkit-overflow-scrolling:touch!important",
            ]);
        }
        //======================================================================
        // Add Responsive Menus
        //======================================================================
        $menu_ids = et_pb_responsive_options()->get_property_values($props, 'menu_id');
        $is_responsive_enabled = et_pb_responsive_options()->is_responsive_enabled($props, 'menu_id');
        if ($is_responsive_enabled && !empty($output) && !empty(array_filter($menu_ids))) {
            $menu_ids = array_map('trim', $menu_ids);
            if (empty($menu_ids['tablet'])) {
                $menu_ids['tablet'] = $menu_ids['desktop'];
            }
            if (empty($menu_ids['phone'])) {
                $menu_ids['phone'] = $menu_ids['tablet'];
            }
            if (class_exists('DOMDocument')) {
                $dom_document = pac_drh_create_dom($output);
                $dom_xpath = new DOMXpath($dom_document);
                $original_menu_container_dom = $dom_xpath->query('//div[contains(@class,"et_pb_menu__menu")]');
                if ($original_menu_container_dom->length > 0) {
                    $original_menu_container = $original_menu_container_dom->item(0);
                    if ($original_menu_container) {
                        $original_ul_dom = $dom_xpath->query('.//ul', $original_menu_container);
                        if ($original_ul_dom->length > 0) {
                            $original_ul = $original_ul_dom->item(0);
                            if ($original_ul) {
                                $original_ul->setAttribute('data-drh-menu-device', 'desktop');
                            }
                        }
                        foreach ($menu_ids as $device_type => $menu_id) {
                            if ($device_type === 'desktop') {
                                continue;
                            }
                            $nav_menu_class = ($device_type === 'tablet') ? 'tablet__menu' : 'phone__menu';
                            $nav_menu_html = wp_nav_menu([
                                'theme_location' => '',
                                'container' => '',
                                'fallback_cb' => '',
                                'menu' => $menu_id,
                                'echo' => false,
                                'items_wrap' => '<ul class="et-menu nav '.$nav_menu_class.'" data-drh-menu-device="'.$device_type.'">%3$s</ul>'
                            ]);
                            $new_menu_container = $dom_document->createElement('div');
                            $new_menu_container->setAttribute('class', 'et_pb_menu__menu');
                            $nav_element = $dom_document->createElement('nav');
                            $nav_element->setAttribute('class', 'et-menu-nav');
                            $fragment = $dom_document->createDocumentFragment();
                            $fragment->appendXML($nav_menu_html);
                            $nav_element->appendChild($fragment);
                            $new_menu_container->appendChild($nav_element);
                            $original_menu_container->parentNode->insertBefore($new_menu_container, $original_menu_container->nextSibling);
                        }
                        $output = $dom_document->saveHTML();
                    }
                }
            }
        }

        return $output;
    }

    add_filter('et_module_shortcode_output', 'pac_drh_filter_menu_output', 10, 3);
endif;