<?php
/**
 * Widget Name: Dual Button (Advanced)
 * Description: A dynamic button split into left text, center icon, and right text with full styling controls.
 *
 * @package    captain-widgets-kit
 * @subpackage captain-widgets-kit/includes
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Icons_Manager;

/**
 * Class Captwiki_Dual_Button
 *
 * @since 1.0.0
 */
class Captwiki_Dual_Button extends Widget_Base {

	/**
	 * Get Widget Name.
	 *
	 * @since 1.0.0
	 */
	public function get_name() {
		return 'captwiki-dual-button';
	}

	/**
	 * Get Widget Title.
	 *
	 * @since 1.0.0
	 */
	public function get_title() {
		return esc_html__( 'Dual Button', 'captain-widgets-kit' );
	}

	/**
	 * Get Widget Icon.
	 *
	 * @since 1.0.0
	 */
	public function get_icon() {
		return 'eicon-button captwiki-el-logo';
	}

	/**
	 * Get Widget Categories.
	 *
	 * @since 1.0.0
	 */
	public function get_categories() {
		return array( 'captwiki-essential' );
	}

	/**
	 * Get Widget Keywords.
	 *
	 * @since 1.0.0
	 */
	public function get_keywords() {
		return array( 'dual', 'button', 'split', 'icon', 'captain-widgets-kit' );
	}

	/**
	 * Disable Elementor's default inner wrapper.
	 *
	 * @since 1.0.0
	 */
	public function has_widget_inner_wrapper(): bool {
		return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
	}

	/**
	 * Register controls
	 *
	 * @since 1.0.0
	 * */
	public function register_controls() {

		$this->start_controls_section(
			'content_section',
			array(
				'label' => esc_html__( 'Content', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'left_text',
			array(
				'label'   => esc_html__( 'Left Text', 'captain-widgets-kit' ),
				'type'    => Controls_Manager::TEXT,
				'default' => 'Elementor',
			)
		);
		$this->add_control(
			'right_text',
			array(
				'label'   => esc_html__( 'Right Text', 'captain-widgets-kit' ),
				'type'    => Controls_Manager::TEXT,
				'default' => 'Gutenberg',
			)
		);
		$this->add_control(
			'group_type',
			array(
				'label'   => esc_html__( 'Group Type', 'captain-widgets-kit' ),
				'type'    => Controls_Manager::TEXT,
				'default' => 'OR',
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'left_s_section',
			array(
				'label' => esc_html__( 'Left Button', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_control(
			'left_btn_txt_cr',
			array(
				'label'     => esc_html__( 'Text Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-dual-btn .captwiki-dual-btn-left' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'left_btn_txt_bg',
			array(
				'label'     => esc_html__( 'Background Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-dual-btn .captwiki-dual-btn-left' => 'background-color: {{VALUE}};',
				),
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'right_r_section',
			array(
				'label' => esc_html__( 'Right Button', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_control(
			'right_btn_txt_cr',
			array(
				'label'     => esc_html__( 'Text Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-dual-btn .captwiki-dual-btn-right' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'right_btn_txt_bg',
			array(
				'label'     => esc_html__( 'Background Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-dual-btn .captwiki-dual-btn-right' => 'background-color: {{VALUE}};',
				),
			)
		);
		$this->end_controls_section();
	}

	/**
	 * Render widget output on the frontend.
	 *
	 * @since 1.0.0
	 */
	public function render() {
		$settings = $this->get_settings_for_display();
		
		$left_text  = ! empty( $settings['left_text'] ) ? $settings['left_text'] : '';
		$right_text = ! empty( $settings['right_text'] ) ? $settings['right_text'] : '';
		$group_type = ! empty( $settings['group_type'] ) ? $settings['group_type'] : '';

		echo '<div class="captwiki-dual-btn style-1">';
			echo '<div class="captwiki-dual-btn-wrapper">';
				echo '<a class="captwiki-dual-btn-left" href="#">';
					echo '<span>' . esc_html( $left_text ) . '</span>';
				echo '</a>';
				echo '<span class="captwiki-dual-btn-text">' . esc_html( $group_type ) . '</span>';
			echo '</div>';
			echo '<div class="captwiki-dual-btn-wrapper">';
				echo '<a class="captwiki-dual-btn-right" href="#">';
					echo '<span>' . esc_html( $right_text ) . '</span>';
				echo '</a>';
			echo '</div>';
		echo '</div>';
	}
}
