<?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\Plugin;
use Sifency\Traits\Sifency_Addons_Master_Typography;
use Sifency\Traits\Sifency_Addons_Help_Controls;
class Sifency_Widget_Doc_Navigation extends Sifency_Themebuilder_Widget_Base {
	use Sifency_Addons_Master_Typography;
	use Sifency_Addons_Help_Controls;

	protected function get_allowed_template_types() {
		return 'documentation';
	}
	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'           => 'sifency-doc-navigation',
			'title'          => 'Doc Nav Menu',
			'icon'           => 'eicon-menu-bar',
			'category'       => array( 'sifency-doc-components' ),
			'style_depends'  => array( 'sifency-doc-style' ),
			'script_depends' => array( 'sifency-doc-script' ),
		);}
	protected function register_controls() {
		$this->add_sifency_addons_help_controls();
		$this->start_controls_section(
			'style_container',
			array(
				'label' => 'Container',
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_control(
			'nav_bg',
			array(
				'label'     => 'Background',
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-doc-nav-wrapper' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_responsive_control(
			'nav_padding',
			array(
				'label'      => 'Padding',
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em' ),
				'selectors'  => array( '{{WRAPPER}} .sifency-doc-nav-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'          => 'heading_style',
				'label'           => 'Manu Items',
				'selector'        => 'a.toc-link-h1, a.toc-link-h2',
				'hover_tab_label' => esc_html__( 'Active', 'sifency-addons' ),
				'hover_selector'  => 'a.toc-link-h1.is-active, a.toc-link-h2.is-active',
				'color_only'      => true,
				'exclude'         => array( 'alignment' ),
			)
		);
	}
	protected function render_dom( array $context ) {
		$wrapper_id = esc_attr( $context['dom_id'] ); ?>
		<nav id="<?php echo esc_attr( $wrapper_id ); ?>" class="sifency-doc-nav-wrapper">
			<div class="sifency-doc-nav-inner" id="sifency-toc-root">
				<?php if ( Plugin::$instance->editor->is_edit_mode() ) : ?>
					<div class="toc-item-h1 open">
						<div class="toc-header">
							<span class="toc-toggle"></span>
							<a href="#" class="toc-link-h1 sifency-heading-style">Getting Started</a>
						</div>
						<ul class="toc-sub-list" style="max-height: 500px;">
							<li><a href="#" class="toc-link-h2 sifency-sub-heading-style">Installation</a></li>
							<li><a href="#" class="toc-link-h2 sifency-sub-heading-style is-active">Activation</a></li>
						</ul>
					</div>
					<div class="toc-item-h1">
						<div class="toc-header">
							<span class="toc-toggle"></span>
							<a href="#" class="toc-link-h1 sifency-heading-style">Advanced Usage</a>
						</div>
					</div>
				<?php endif; ?>
			</div>
		</nav>
		<?php if ( ! Plugin::$instance->editor->is_edit_mode() ) : ?>
			<?php
		endif;
	}
}
