<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Theme_Button 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 'pubzi-theme-button-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__( 'Theme Button', 'pubzi-core' );
	}

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

	/**
	 * 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 ['pubzi_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(
			'theme_button',
			[
				'label' => esc_html__( 'Theme Button', 'pubzi-core' ),
			]
		);	
		
		$this->add_control(
			'style',
			[
				'label'   => esc_html__( 'Select Style', 'pubzi-core' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'style1',
				'options' => array(
					'style1'   => esc_html__( 'Button 1', 'pubzi-core' ),
					'style2'   => esc_html__( 'Slider Arrow 1', 'pubzi-core' ),
					'style3'   => esc_html__( 'Button 2', 'pubzi-core' ),
					'style4'   => esc_html__( 'Video Button', 'pubzi-core' ),
					'style5'   => esc_html__( 'Button 3', 'pubzi-core' ),
					'style6'   => esc_html__( 'Button 4', 'pubzi-core' ),
				),
			]
		);
		
		$this->add_control(
			'button',
			[
				'label'       => __( 'Button', 'pubzi-core' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => esc_html__( 'Enter your button text', 'pubzi-core' ),
				'default' => esc_html__('Read More', 'pubzi-core'),
			]
		);	

		$this->add_control(
			'button_link',
			[
			  'label' => __( 'Button Url', 'pubzi-core' ),
			  'type' => Controls_Manager::URL,
			  'placeholder' => __( 'https://your-link.com', 'pubzi-core' ),
			  'show_external' => true,
			  'default' => [
				'url' => '',
				'is_external' => true,
				'nofollow' => true,
			  ],
			
		   ]
		);



		$this->end_controls_section();


		//========== Button with Background ===================================
		$this->start_controls_section(
			'button_control',
			array(
				'label' => __( 'Button Settings', 'pubzi-core' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);
		
		$this->add_control(
			'show_button',
			array(
				'label' => esc_html__( 'Show Button', 'pubzi-core' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'show' => esc_html__( 'Show', 'pubzi-core' ),	
						'icon' => 'eicon-check-circle',
					],
					'none' => [
						'none' => esc_html__( 'Hide', 'pubzi-core' ),
						'icon' => 'eicon-close-circle',
					],
				],
				'default' => 'show',
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'display: {{VALUE}} !important',
				), 
			)
		);		
		$this->add_control(
			'button_alingment',
			array(
				'label' => esc_html__( 'Alignment', 'pubzi-core' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'condition'    => array( 'show_button' => 'show' ),
				'options' => [
					'left' => [
						'title' => esc_html__( 'Left', 'pubzi-core' ),
						'icon' => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'pubzi-core' ),
						'icon' => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'pubzi-core' ),
						'icon' => 'eicon-text-align-right',
					],
				],
				'default' => 'left',
				'toggle' => true,
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'text-align: {{VALUE}} !important',
				),
			)
		);	
		$this->add_control(
			'button_color',
			array(
				'label'     => __( 'Button Color', 'pubzi-core' ),
				'condition'    => array( 'show_button' => 'show' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'color: {{VALUE}} !important',

				),
			)
		);

		$this->add_control(
			'button_bg_color',
			array(
				'label'     => __( 'Button Background Color', 'pubzi-core' ),
				'condition'    => array( 'show_button' => 'show' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'background: {{VALUE}} !important',

				),
			)
		);

		$this->add_control(
			'button_hover_color',
			array(
				'label'     => __( 'Button Hover Color', 'pubzi-core' ),
				'condition'    => array( 'show_button' => 'show' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .theme-btn:hover' => 'color: {{VALUE}} !important',

				),
			)
		);
		
		
		$this->add_control(
			'button_bg_hover_color',
			array(
				'label'     => __( 'Button Background Hover Color', 'pubzi-core' ),
				'condition'    => array( 'show_button' => 'show' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .theme-btn:hover' => 'background: {{VALUE}} !important',

				),
			)
		);
		
		$this->add_control(
			'button_padding',
			array(
				'label'     => __( 'Padding', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::DIMENSIONS,
				'condition'    => array( 'show_button' => 'show' ),
				'size_units' =>  ['px', '%', 'em' ],
			
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important',
				),
			)
		);

		$this->add_control(
			'button_margin',
			array(
				'label'     => __( 'Margin', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::DIMENSIONS,
				'condition'    => array( 'show_button' => 'show' ),
				'size_units' =>  ['px', '%', 'em' ],
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important',
				),
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			array(
				'name'     => 'button_typography',
				'condition'    => array( 'show_button' => 'show' ),
				'label'    => __( 'Typography', 'pubzi-core' ),
				'selector' => '{{WRAPPER}} .theme-btn',
			)
		);
		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			array(
				'name' => 'border',
				'condition'    => array( 'show_button' => 'show' ),
				'selector' => '{{WRAPPER}} .theme-btn',
			)
		);
		
		$this->add_control(
			'border_radius',
			array(
				'label'     => __( 'Border Radius', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::DIMENSIONS,
				'condition'    => array( 'show_button' => 'show' ),
				'size_units' =>  ['px', '%', 'em' ],
			
				'selectors' => array(
					'{{WRAPPER}} .theme-btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important',
				),
			)
		);

		$this->end_controls_section();
		
		//End of Button		
	

	
		}

	/**
	 * 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'] ) : ?>

	 <a href="<?php echo esc_url($settings['button_link']['url']);?>" class="theme-btn wow fadeInUp" data-wow-delay=".5s">
		<?php echo $settings['button'];?>
	</a>

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

  		<div class="array-button d-flex align-items-center wow fadeInUp" data-wow-delay=".5s">
			<button class="array-prev">
				<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
					<g clip-path="url(#clip0_135_87)">
						<path d="M0.000243405 1.16006L0.000243999 14.762C0.000244027 15.4019 0.520557 15.9222 1.1604 15.9222C1.80024 15.9222 2.32056 15.4019 2.32056 14.762L2.32056 3.96553L16.0174 17.6589C16.4709 18.1124 17.2057 18.1124 17.6592 17.6589C18.1127 17.2054 18.1127 16.4706 17.6592 16.0171L3.96235 2.32373L14.7588 2.32373C15.3987 2.32373 15.919 1.80342 15.919 1.16357C15.919 0.523731 15.3987 0.0034173 14.7588 0.00341732L1.1604 0.00341792C0.520556 -9.72975e-05 0.000243377 0.520214 0.000243405 1.16006Z" fill="#0B0E13"/>
					</g>
					<defs>
						<clipPath id="clip0_135_87">
						<rect width="18" height="18" fill="white" transform="translate(0.000244141 18) rotate(-90)"/>
						</clipPath>
					</defs>
					</svg>
			</button>
			<button class="array-next">
				<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
				<g clip-path="url(#clip0_135_80)">
					<path d="M17.9944 16.8399L17.9944 3.23799C17.9944 2.59814 17.4741 2.07783 16.8342 2.07783C16.1944 2.07783 15.6741 2.59814 15.6741 3.23799L15.6741 14.0345L1.9772 0.341113C1.52368 -0.112403 0.788916 -0.112403 0.335402 0.341112C-0.118115 0.794628 -0.118115 1.52939 0.335401 1.98291L14.0323 15.6763L3.23579 15.6763C2.59595 15.6763 2.07563 16.1966 2.07563 16.8364C2.07563 17.4763 2.59595 17.9966 3.23579 17.9966L16.8342 17.9966C17.4741 18.0001 17.9944 17.4798 17.9944 16.8399Z" fill="#0B0E13"/>
				</g>
				<defs>
					<clipPath id="clip0_135_80">
					<rect width="18" height="18" fill="white" transform="translate(17.9944) rotate(90)"/>
					</clipPath>
				</defs>
				</svg>
			</button>
		</div>

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

			 <a href="<?php echo esc_url($settings['button_link']['url']);?>" class="theme-btn style-2 wow fadeInUp" data-wow-delay=".9s">
				<span class="left-line"></span>
				<?php echo $settings['button'];?>
				<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
				<path d="M9.41099 8.46917L1.88219 16L0 14.1166L7.53013 6.58846L0.941096 0H16V15.0576L9.41099 8.46917Z" fill="#0B0E13"></path>
				</svg>
			</a>

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

			<div class="gt-match-details-wrapper m-0 p-0">
				<div class="gt-details-content m-0 p-0">
					<div class="thumb m-0 p-0">
						<a href="<?php echo esc_url($settings['button_link']['url']);?>" class="video-btn ripple video-popup">
							<i class="fa-solid fa-play"></i>
						</a>
					</div>
				</div>
			</div>

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

			<div class="gt-team-details-wrapper m-0 p-0">
				<div class="gt-team-details-content m-0 p-0">
					<div class="gt-team-bottom m-0 p-0 border-0">
						<a href="<?php echo esc_url($settings['button_link']['url']);?>" class="theme-btn boder-10">
							<?php echo $settings['button'];?> <i class="fa-solid fa-download"></i>
						</a>
					</div>
				</div>
			</div>

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

			<a href="<?php echo esc_url($settings['button_link']['url']);?>" class="gt-theme-btn gt-style-border">
				<?php echo $settings['button'];?> 
			</a>

	<?php endif ;?>	

             
		<?php 
	}


}

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