<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
use Elementor\Widget_Base;
use Sifency\Classes\Sifency_Addons_Widget_Base;
use Sifency\Classes\Sifency_Themebuilder_Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Background;
use Elementor\Icons_Manager;
use Sifency\Traits\Sifency_Addons_Master_Typography;
use Sifency\Traits\Sifency_Addons_Icon_Style_Controls;
use Sifency\Traits\Sifency_Addons_Item_Style_Controls;
use Sifency\Traits\Sifency_Addons_Flex_Controls;
use Sifency\Traits\Sifency_Addons_Label_Content_Controls;
use Sifency\Traits\Sifency_Addons_Help_Controls;
class Sifency_Addons_Widget_Advanced_Menu extends Widget_Base {
	use Sifency_Addons_Master_Typography;
	use Sifency_Addons_Icon_Style_Controls;
	use Sifency_Addons_Item_Style_Controls;
	use Sifency_Addons_Flex_Controls;
	use Sifency_Addons_Label_Content_Controls;
	use Sifency_Addons_Help_Controls;

	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'           => 'sifency-advanced-menu',
			'title'          => 'Sifency Navigation Menu',
			'icon'           => 'eicon-nav-menu',
			'category'       => array( 'sifency-category', 'theme-elements' ),
			'keywords'       => array( 'menu', 'navigation', 'nav', 'header', 'links' ),
			'style_depends'  => array( 'sifency-nav-style', 'sifency-typo-style' ),
			'script_depends' => array( 'sifency-nav-script' ),
		);
	}

	/**
	 * Register Controls (Updated from deprecated _register_controls)
	 */
	protected function register_controls() {
		$this->register_menu_content_controls();
		$this->register_menu_layout_controls();
		$this->register_main_menu_style_controls();
		$this->register_submenu_style_controls();
		$this->register_mobile_menu_controls();
		$this->register_developer_tools_controls();
		$this->add_sifency_addons_label_content_controls();
	}

	protected function register_menu_content_controls() {
		$this->start_controls_section(
			'section_menu_content',
			array(
				'label' => esc_html__( 'Menu Content', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$menus        = wp_get_nav_menus();
		$menu_options = array();
		if ( ! empty( $menus ) ) {
			foreach ( $menus as $menu ) {
				$menu_options[ $menu->term_id ] = $menu->name;
			}
		} else {
			$menu_options[''] = esc_html__( 'No Menus Found', 'sifency-addons' );
		}

		$this->add_control(
			'selected_menu',
			array(
				'label'       => esc_html__( 'Select Menu', 'sifency-addons' ),
				'type'        => Controls_Manager::SELECT,
				'options'     => $menu_options,
				'default'     => ! empty( $menu_options ) ? array_key_first( $menu_options ) : '',
				'description' => esc_html__( 'Choose which WordPress menu to display', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'menu_depth',
			array(
				'label' => esc_html__( 'Menu Depth', 'sifency-addons' ),
				'type'  => Controls_Manager::NUMBER,
				'min'   => 1,
				'max'   => 10,
				'step'  => 1,
			)
		);

		$this->add_control(
			'enable_mega_menu',
			array(
				'label'        => esc_html__( 'Enable Mega Menu', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'return_value' => 'yes',
			)
		);

		$this->end_controls_section();
	}

	protected function register_menu_layout_controls() {
		$this->start_controls_section(
			'section_menu_layout',
			array(
				'label' => esc_html__( 'Menu Layout', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'menu_type',
			array(
				'label'        => esc_html__( 'Menu Type', 'sifency-addons' ),
				'type'         => Controls_Manager::SELECT,
				'options'      => array(
					'horizontal' => esc_html__( 'Horizontal', 'sifency-addons' ),
					'vertical'   => esc_html__( 'Vertical', 'sifency-addons' ),
					'dropdown'   => esc_html__( 'Dropdown', 'sifency-addons' ),
					'accordion'  => esc_html__( 'Accordion', 'sifency-addons' ),
				),
				'prefix_class' => 'sifency-menu-type-',
			)
		);

		$this->add_responsive_control(
			'menu_align',
			array(
				'label'     => esc_html__( 'Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'left'    => array(
						'title' => esc_html__( 'Left', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-left',
					),
					'center'  => array(
						'title' => esc_html__( 'Center', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-center',
					),
					'right'   => array(
						'title' => esc_html__( 'Right', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-right',
					),
					'justify' => array(
						'title' => esc_html__( 'Justify', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-justify',
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-nav'      => 'text-align: {{VALUE}};',
					'{{WRAPPER}} .sifency-nav-list' => 'justify-content: {{VALUE}};',
				),
				'condition' => array( 'menu_type' => 'horizontal' ),
			)
		);

		$this->add_control(
			'submenu_animation',
			array(
				'label'        => esc_html__( 'Submenu Animation', 'sifency-addons' ),
				'type'         => Controls_Manager::SELECT,
				'options'      => array(
					'none'        => esc_html__( 'None', 'sifency-addons' ),
					'fade'        => esc_html__( 'Fade', 'sifency-addons' ),
					'slide-up'    => esc_html__( 'Slide Up', 'sifency-addons' ),
					'slide-down'  => esc_html__( 'Slide Down', 'sifency-addons' ),
					'slide-left'  => esc_html__( 'Slide Left', 'sifency-addons' ),
					'slide-right' => esc_html__( 'Slide Right', 'sifency-addons' ),
					'zoom-in'     => esc_html__( 'Zoom In', 'sifency-addons' ),
				),
				'prefix_class' => 'sifency-submenu-animation-',
			)
		);

		$this->add_control(
			'submenu_animation_duration',
			array(
				'label'     => esc_html__( 'Animation Duration (ms)', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min'  => 100,
						'max'  => 1000,
						'step' => 50,
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list .sub-menu' => 'transition-duration: {{SIZE}}ms;' ),
				'condition' => array( 'submenu_animation!' => 'none' ),
			)
		);

		$this->add_control(
			'dropdown_indicator',
			array(
				'label'   => esc_html__( 'Dropdown Indicator', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'none'    => esc_html__( 'None', 'sifency-addons' ),
					'arrow'   => esc_html__( 'Arrow', 'sifency-addons' ),
					'plus'    => esc_html__( 'Plus', 'sifency-addons' ),
					'chevron' => esc_html__( 'Chevron', 'sifency-addons' ),
					'custom'  => esc_html__( 'Custom Icon', 'sifency-addons' ),
				),
			)
		);

		$this->add_control(
			'dropdown_custom_icon',
			array(
				'label'     => esc_html__( 'Custom Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'condition' => array( 'dropdown_indicator' => 'custom' ),
			)
		);

		$this->add_control(
			'mobile_breakpoint',
			array(
				'label'       => esc_html__( 'Mobile Breakpoint (px)', 'sifency-addons' ),
				'type'        => Controls_Manager::NUMBER,
				'min'         => 320,
				'max'         => 1920,
				'description' => esc_html__( 'Screen width when menu switches to mobile mode', 'sifency-addons' ),
			)
		);

		$this->end_controls_section();
	}

	protected function register_main_menu_style_controls() {
		$this->start_controls_section(
			'section_main_menu_style',
			array(
				'label' => esc_html__( 'Main Menu', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'menu_typography',
				'selector' => '{{WRAPPER}} .sifency-nav-list > li > a',
			)
		);

		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'menu_background',
				'selector' => '{{WRAPPER}} .sifency-nav',
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'menu_border',
				'selector' => '{{WRAPPER}} .sifency-nav',
			)
		);

		$this->add_control(
			'menu_border_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);

		$this->add_responsive_control(
			'menu_padding',
			array(
				'label'      => esc_html__( 'Padding', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);

		$this->add_responsive_control(
			'menu_margin',
			array(
				'label'      => esc_html__( 'Margin', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);

		// --- ITEM TABS ---
		$this->start_controls_tabs( 'menu_item_tabs' );

		// Normal Tab
		$this->start_controls_tab( 'menu_item_normal', array( 'label' => esc_html__( 'Normal', 'sifency-addons' ) ) );
		$this->add_control(
			'menu_text_color',
			array(
				'label'     => esc_html__( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li > a' => 'color: {{VALUE}}' ),
			)
		);
		$this->add_control(
			'menu_item_bg_color',
			array(
				'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li > a' => 'background-color: {{VALUE}}' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'menu_item_border',
				'selector' => '{{WRAPPER}} .sifency-nav-list > li > a',
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'menu_item_box_shadow',
				'selector' => '{{WRAPPER}} .sifency-nav-list > li > a',
			)
		);
		$this->end_controls_tab();

		// Hover Tab
		$this->start_controls_tab( 'menu_item_hover', array( 'label' => esc_html__( 'Hover', 'sifency-addons' ) ) );
		$this->add_control(
			'menu_text_hover_color',
			array(
				'label'     => esc_html__( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li > a:hover, {{WRAPPER}} .sifency-nav-list > li:hover > a' => 'color: {{VALUE}}' ),
			)
		);
		$this->add_control(
			'menu_item_hover_bg_color',
			array(
				'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li > a:hover, {{WRAPPER}} .sifency-nav-list > li:hover > a' => 'background-color: {{VALUE}}' ),
			)
		);
		$this->add_control(
			'menu_item_hover_border_color',
			array(
				'label'     => esc_html__( 'Border Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li > a:hover, {{WRAPPER}} .sifency-nav-list > li:hover > a' => 'border-color: {{VALUE}}' ),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'menu_item_hover_box_shadow',
				'selector' => '{{WRAPPER}} .sifency-nav-list > li > a:hover, {{WRAPPER}} .sifency-nav-list > li:hover > a',
			)
		);
		$this->end_controls_tab();

		// Active Tab
		$this->start_controls_tab( 'menu_item_active', array( 'label' => esc_html__( 'Active', 'sifency-addons' ) ) );
		$this->add_control(
			'menu_text_active_color',
			array(
				'label'     => esc_html__( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li.current-menu-item > a, {{WRAPPER}} .sifency-nav-list > li.current-menu-ancestor > a' => 'color: {{VALUE}}' ),
			)
		);
		$this->add_control(
			'menu_item_active_bg_color',
			array(
				'label'     => esc_html__( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li.current-menu-item > a, {{WRAPPER}} .sifency-nav-list > li.current-menu-ancestor > a' => 'background-color: {{VALUE}}' ),
			)
		);
		$this->add_control(
			'menu_item_active_border_color',
			array(
				'label'     => esc_html__( 'Border Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list > li.current-menu-item > a, {{WRAPPER}} .sifency-nav-list > li.current-menu-ancestor > a' => 'border-color: {{VALUE}}' ),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'menu_item_active_box_shadow',
				'selector' => '{{WRAPPER}} .sifency-nav-list > li.current-menu-item > a, {{WRAPPER}} .sifency-nav-list > li.current-menu-ancestor > a',
			)
		);
		$this->end_controls_tab();

		$this->end_controls_tabs();

		// --- ITEM SPACING ---
		$this->add_control(
			'menu_item_spacing_heading',
			array(
				'label'     => esc_html__( 'Item Spacing', 'sifency-addons' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);
		$this->add_responsive_control(
			'menu_item_padding',
			array(
				'label'      => esc_html__( 'Padding', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list > li > a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'menu_item_margin',
			array(
				'label'      => esc_html__( 'Margin', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list > li' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_control(
			'menu_item_border_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list > li > a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_control(
			'menu_item_gap',
			array(
				'label'      => esc_html__( 'Item Gap', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 0,
						'max' => 100,
					),
				),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list > li:not(:last-child)' => 'margin-right: {{SIZE}}{{UNIT}};' ),
				'condition'  => array( 'menu_type' => 'horizontal' ),
			)
		);

		$this->end_controls_section();
	}

	protected function register_submenu_style_controls() {
		$this->start_controls_section(
			'section_submenu_style',
			array(
				'label' => esc_html__( 'Submenu', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_control(
			'submenu_position',
			array(
				'label'     => esc_html__( 'Position', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'options'   => array(
					'absolute' => esc_html__( 'Absolute', 'sifency-addons' ),
					'static'   => esc_html__( 'Static', 'sifency-addons' ),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-nav-list .sub-menu' => 'position: {{VALUE}};' ),
			)
		);

		$this->add_control(
			'submenu_width',
			array(
				'label'      => esc_html__( 'Width', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 100,
						'max' => 1000,
					),
					'%'  => array(
						'min' => 10,
						'max' => 100,
					),
				),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list .sub-menu' => 'width: {{SIZE}}{{UNIT}};' ),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'submenu_typography',
				'selector' => '{{WRAPPER}} .sifency-nav-list .sub-menu a',
			)
		);

		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'submenu_background',
				'selector' => '{{WRAPPER}} .sifency-nav-list .sub-menu',
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'submenu_border',
				'selector' => '{{WRAPPER}} .sifency-nav-list .sub-menu',
			)
		);

		$this->add_control(
			'submenu_border_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list .sub-menu' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);

		$this->add_responsive_control(
			'submenu_padding',
			array(
				'label'      => esc_html__( 'Padding', 'sifency-addons' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-nav-list .sub-menu' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);

		$this->end_controls_section();
	}

	protected function register_mobile_menu_controls() {
		$this->start_controls_section(
			'section_mobile_menu',
			array(
				'label' => esc_html__( 'Mobile Menu', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'mobile_menu_type',
			array(
				'label'        => esc_html__( 'Mobile Menu Type', 'sifency-addons' ),
				'type'         => Controls_Manager::SELECT,
				'options'      => array(
					'dropdown'   => esc_html__( 'Dropdown', 'sifency-addons' ),
					'fullscreen' => esc_html__( 'Fullscreen', 'sifency-addons' ),
					'sidebar'    => esc_html__( 'Sidebar', 'sifency-addons' ),
					'accordion'  => esc_html__( 'Accordion', 'sifency-addons' ),
				),
				'prefix_class' => 'sifency-mobile-menu-type-',
			)
		);

		$this->add_control(
			'mobile_menu_toggle',
			array(
				'label'   => esc_html__( 'Toggle Button', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'hamburger' => esc_html__( 'Hamburger Icon', 'sifency-addons' ),
					'text'      => esc_html__( 'Text Button', 'sifency-addons' ),
					'icon-text' => esc_html__( 'Icon + Text', 'sifency-addons' ),
					'custom'    => esc_html__( 'Custom Icon', 'sifency-addons' ),
				),
			)
		);

		$this->add_control(
			'mobile_menu_toggle_text',
			array(
				'label'     => esc_html__( 'Toggle Text', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'condition' => array( 'mobile_menu_toggle' => array( 'text', 'icon-text' ) ),
			)
		);

		$this->add_control(
			'mobile_menu_toggle_icon',
			array(
				'label'     => esc_html__( 'Toggle Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'condition' => array( 'mobile_menu_toggle' => array( 'icon-text', 'custom' ) ),
			)
		);

		$this->add_control(
			'mobile_menu_toggle_position',
			array(
				'label'   => esc_html__( 'Toggle Position', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'before' => esc_html__( 'Before Menu', 'sifency-addons' ),
					'after'  => esc_html__( 'After Menu', 'sifency-addons' ),
				),
			)
		);

		$this->end_controls_section();
	}

	protected function register_developer_tools_controls() {
		$this->start_controls_section(
			'section_developer_tools',
			array(
				'label' => esc_html__( 'Developer Tools', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'ex_class',
			array(
				'label'       => esc_html__( 'Extra Class', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'Enter Class', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'js_data_attr',
			array(
				'label'       => esc_html__( 'JS Data Attribute', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'e.g., data-aos', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'js_data_value',
			array(
				'label'       => esc_html__( 'JS Data Value', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'e.g., fade-up', 'sifency-addons' ),
			)
		);

		$this->end_controls_section();
		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'    => 'label_',
				'label'     => esc_html__( 'Label Style', 'sifency-addons' ),
				'selector'  => '.sifency-label-style',
				'exclude'   => array( 'alignment', 'tabs', 'transition' ),
				'condition' => array( 'show_label' => 'yes' ),
			)
		);
	}

	protected function render() {
		$settings = $this->get_settings_for_display();

		$wrapper_classes = array( 'sifency-nav-wrapper', 'cs_theme_header', 'cs-nav', 'cs-medium' );

		if ( ! empty( $settings['wrap_class'] ) ) {
			$wrapper_classes[] = sanitize_html_class( $settings['wrap_class'] );
		}
		if ( ! empty( $settings['ex_class'] ) ) {
			$wrapper_classes[] = sanitize_html_class( $settings['ex_class'] );
		}

		$data_attrs = '';
		if ( ! empty( $settings['js_data_attr'] ) && ! empty( $settings['js_data_value'] ) ) {
			$data_attrs = sprintf( ' %s="%s"', esc_attr( $settings['js_data_attr'] ), esc_attr( $settings['js_data_value'] ) );
		}

		$menu_classes = array( 'cs-nav_list', 'sifency-nav-list' );
		if ( ! empty( $settings['child_class'] ) ) {
			$menu_classes[] = sanitize_html_class( $settings['child_class'] );
		}

		$mobile_toggle = '';
		if ( ! empty( $settings['mobile_menu_toggle'] ) && $settings['mobile_menu_toggle'] !== 'none' ) {
			$toggle_icon = '';

			if ( ! empty( $settings['mobile_menu_toggle_icon']['value'] ) ) {
				ob_start();
				Icons_Manager::render_icon( $settings['mobile_menu_toggle_icon'], array( 'aria-hidden' => 'true' ) );
				$toggle_icon = ob_get_clean();
			}

			$toggle_text = '';
			if ( ! empty( $settings['mobile_menu_toggle_text'] ) ) {
				$toggle_text = '<span class="sifency-mobile-menu-toggle-text">' . esc_html( $settings['mobile_menu_toggle_text'] ) . '</span>';
			}

			$mobile_toggle = sprintf(
				'<button class="menu_toggle sifency-mobile-menu-toggle" aria-expanded="false" aria-label="%s">%s%s</button>',
				esc_attr__( 'Toggle Menu', 'sifency-addons' ),
				$toggle_icon,
				$toggle_text
			);
		}
		if ( 'yes' === $settings['show_label'] && ! empty( $settings['label_text'] ) ) : ?>
			<span class="sifency-label-style">
				<?php echo esc_html( $settings['label_text'] ); ?>
			</span>
			<?php
		endif;
		echo '<div class="' . esc_attr( implode( ' ', $wrapper_classes ) ) . '"' . wp_kses_post( $data_attrs ) . '>';

		if ( ! empty( $settings['mobile_menu_toggle_position'] ) && $settings['mobile_menu_toggle_position'] === 'before' ) {
			echo wp_kses_post( $mobile_toggle );
		}

		if ( ! empty( $settings['selected_menu'] ) ) {
			$menu_args = array(
				'menu'       => $settings['selected_menu'],
				'container'  => false,
				'menu_class' => implode( ' ', $menu_classes ),
				'depth'      => absint( $settings['menu_depth'] ),
				'echo'       => false,
			);

			if ( class_exists( '\Sifency_Walker_Nav_Primary' ) ) {
				$menu_args['fallback_cb'] = '\Sifency_Walker_Nav_Primary::fallback';
				$menu_args['walker']      = new \Sifency_Walker_Nav_Primary();
			}

			$menu_output = wp_nav_menu( $menu_args );

			if ( $menu_output && strpos( $menu_output, '<ul' ) === false ) {
				$menu_output = '<ul class="' . esc_attr( implode( ' ', $menu_classes ) ) . '">' . $menu_output . '</ul>';
			}

			echo wp_kses_post( $menu_output );

		} elseif ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
				echo '<div class="sifency-menu-placeholder" style="padding: 15px; border: 2px dashed #ccc; text-align: center;">';
				echo esc_html__( 'Please select a menu from the settings.', 'sifency-addons' );
				echo '</div>';
		}

		if ( ! empty( $settings['mobile_menu_toggle_position'] ) && $settings['mobile_menu_toggle_position'] === 'after' ) {
			echo wp_kses_post( $mobile_toggle );
		}

		if ( ! empty( $settings['mobile_menu_toggle'] ) && $settings['mobile_menu_toggle'] !== 'none' ) {
			echo '<div class="sifency-mobile-menu-container"></div>';
		}

		echo '</div>';
	}
}
