<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Geroz
 * @since 1.0.0
 */ 
 
class Main_Header extends Widget_Base {

	/**
	 * Get widget name.
	 * Retrieve button widget name.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'geroz-main-header-widget';
	}

	/**
	 * Get widget title.
	 * Retrieve button widget title.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Main Header', 'geroz-core' );
	}

	/**
	 * Get widget icon.
	 * Retrieve button widget icon.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-header';
	}

	/**
	 * Get widget categories.
	 * Retrieve the list of categories the button widget belongs to.
	 * Used to determine where to display the widget in the editor.
	 *
	 * @since  2.0.0
	 * @access public
	 * @return array Widget categories.
	 */
	public function get_categories()
    {
        return ['geroz_widgets'];
    }	
	
	/**
	 * Register button widget controls.
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since  1.0.0
	 * @access protected
	 */
	protected function register_controls() {


		// Tab Start - 1

		$this->start_controls_section(
			'main-header-content',
			[
				'label' => esc_html__( 'Main Header', 'geroz-core' ),
			]
		);	

		$menus = $this->get_available_menus();
		$default_menu = !empty($menus) ? array_key_first($menus) : '';

		$this->add_control(
			'menu_select',
			[
				'label'   => esc_html__( 'Select Menu', 'geroz-core' ),
				'type'    => Controls_Manager::SELECT,
				'options' => $menus,
				'default' => $default_menu,
			]
		);

		$this->add_control(
			'style',
			[
				'label'   => esc_html__( 'Style', 'geroz-core' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'style1',
				'options' => [
					'style1' => esc_html__( 'Style 1', 'geroz-core' ),
					'style2' => esc_html__( 'Style 2', 'geroz-core' ),
					'style3' => esc_html__( 'Style 3', 'geroz-core' ),
				],
			]
		);

		$this->add_control(
			'image',
				[
					'label' => __( 'Logo', 'geroz-core' ),
					'type' => Controls_Manager::MEDIA,
					'default' => ['url' => Utils::get_placeholder_image_src(),],
				]
		);		
	

		$this->add_control(
			'show_btn',
			[
				'label'        => esc_html__( 'Show Button', 'geroz-core' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'geroz-core' ),
				'label_off'    => esc_html__( 'Hide', 'geroz-core' ),
				'default'      => 'yes',
				'return_value' => 'yes',
			]
		);

		$this->add_control(
			'header_btn',
			[
				'label'       => esc_html__( 'Button Text', 'geroz-core' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Get Started', 'geroz-core' ),
				'placeholder' => esc_html__( 'Enter your button text', 'geroz-core' ),
				'condition'   => [
					'show_btn' => 'yes',
				],
			]
		);

		$this->add_control(
			'header_btn_link',
			[
				'label'       => esc_html__( 'Button Link', 'geroz-core' ),
				'type'        => Controls_Manager::URL,
				'default'     => [
					'url' => '#',
				],
				'show_external' => true,
				'condition'   => [
					'show_btn' => 'yes',
				],
			]
		);

		$this->add_control(
			'show_search_btn',
			[
				'label'        => esc_html__( 'Show Search Button', 'geroz-core' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'geroz-core' ),
				'label_off'    => esc_html__( 'Hide', 'geroz-core' ),
				'default'      => 'yes',
				'return_value' => 'yes',
			]
		);

		$this->add_control(
			'show_callus',
			[
				'label'        => esc_html__( 'Show Call Us', 'geroz-core' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'geroz-core' ),
				'label_off'    => esc_html__( 'Hide', 'geroz-core' ),
				'default'      => 'yes',
				'return_value' => 'yes',
				'condition'	=> ['style' => ['style1', 'style3']],
			]
		);

		$this->add_control(
			'callus_btn_title',
			[
				'label'       => esc_html__( 'Call Us Title', 'geroz-core' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Call Us', 'geroz-core' ),
				'placeholder' => esc_html__( 'Enter your call us title', 'geroz-core' ),
				'condition'   => [
					'show_callus' => 'yes',
				],
			]
		);

		$this->add_control(
			'callus_btn_number',
			[
				'label'       => esc_html__( 'Call Us Number', 'geroz-core' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( '+1234567890', 'geroz-core' ),
				'placeholder' => esc_html__( 'Enter your call us number', 'geroz-core' ),
				'condition'   => [
					'show_callus' => 'yes',
				],
			]
		);

		$this->add_control(
			'callus_btn_link',
			[
				'label'       => esc_html__( 'Call Us Link', 'geroz-core' ),
				'type'        => Controls_Manager::URL,
				'default'     => [
					'url' => '#',
				],
				'show_external' => true,
				'condition'   => [
					'show_callus' => 'yes',
				],
			]
		);


		$this->end_controls_section();		
	


	
		}


	/**
	 * Get available menus.
	 * Retrieve a list of registered navigation menus.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return array Array of menu slugs and names.
	 */
	protected function get_available_menus() {
		$menus = wp_get_nav_menus();
		$options = [];

		foreach ( $menus as $menu ) {
			$options[ $menu->slug ] = $menu->name;
		}

		return $options;
	}	

	/**
	 * Render button widget output on the frontend.
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since  1.0.0
	 * @access protected
	 */
	protected function render() {
		$settings = $this->get_settings_for_display();
		$allowed_tags = wp_kses_allowed_html('post');
		?>

	<?php  if ( 'style1' === $settings['style'] ) : ?>

        <div id="header-sticky" class="header-1">
            <div class="container-fluid">
                <div class="mega-menu-wrapper">
                    <div class="header-main ">
                        <div class="header-left">
                            <div class="logo">
                               <a href="<?php echo esc_url(home_url('/')); ?>" class="header-logo">
                               <?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
									<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
								<?php endif;?>
                            </a>
                            </div>
                        </div>
                        <div class="header-right">
                            <div class="mean__menu-wrapper">
                                <div class="main-menu">                                 
								<?php
									if ( ! empty( $settings['menu_select'] ) ) {
										wp_nav_menu( array(
											'menu'           => $settings['menu_select'],
											'menu_class' => '',
											'container' => 'div',
											'container_class' => '',
											'container_id' => 'mobile-menu',
											'fallback_cb' => 'geroz_theme_fallback_menu',
										));
									}
								?>
                                </div>
                            </div>
                            <div class="header__hamburger  my-auto">
                                <div class="sidebar__toggle">
                                    <span></span>
                                    <span></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

	<?php  elseif ( 'style2' === $settings['style'] ) : ?>


	<?php endif ;?>	
             
		<?php 
	}


}

Plugin::instance()->widgets_manager->register_widget_type(new Main_Header());