<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
use Elementor\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_Animation_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Manager;
use Sifency\Traits\Sifency_Addons_Master_Typography;
use Sifency\Traits\Sifency_Addons_Button_Style_Controls;
use Sifency\Traits\Sifency_Addons_Icon_Style_Controls;
use Sifency\Traits\Sifency_Addons_Help_Controls;
use Sifency\Classes\Sifency_Addons_Widget_Base;
class Sifency_Addons_Widget_Info_Button extends Sifency_Addons_Widget_Base {
	use Sifency_Addons_Master_Typography;
	use Sifency_Addons_Animation_Controls;
	use Sifency_Addons_Button_Style_Controls;
	use Sifency_Addons_Icon_Style_Controls;
	use Sifency_Addons_Help_Controls;
	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'          => 'sifency-info-button',
			'title'         => 'Sifency Info Button',
			'icon'          => 'eicon-info-circle-o',
			'category'      => array( 'sifency-addons-widgets' ),
			'style_depends' => array( 'sifency-info-button-style', 'sifency-icon' ),
		);}

	protected function register_controls() {
		$this->start_controls_section(
			'section_content',
			array(
				'label' => esc_html__( 'Button Content', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'layout_type',
			array(
				'label'   => esc_html__( 'Layout Style', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'expand',
				'options' => array(
					'expand'      => esc_html__( '1. Expand on Hover', 'sifency-addons' ),
					'tooltip'     => esc_html__( '2. Modern Tooltip', 'sifency-addons' ),
					'slide'       => esc_html__( '3. Slide Out', 'sifency-addons' ),
					'flip'        => esc_html__( '4. 3D Flip (Mini)', 'sifency-addons' ),
					'pulse'       => esc_html__( '5. Glowing Pulse', 'sifency-addons' ),
					'basic'       => esc_html__( '6. Basic', 'sifency-addons' ),
					'bottom_info' => esc_html__( '7. Bottom Info', 'sifency-addons' ),
				),
			)
		);
		$this->add_control(
			'selected_icon',
			array(
				'label'   => esc_html__( 'Icon', 'sifency-addons' ),
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'icon-right',
					'library' => 'sifency-icons',
				),
			)
		);
		$this->add_control(
			'title',
			array(
				'label'     => esc_html__( 'Main Text / Title', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => esc_html__( 'More Info', 'sifency-addons' ),
				'condition' => array( 'layout_type!' => 'flip' ),
			)
		);
		$this->add_control(
			'description',
			array(
				'label'     => esc_html__( 'Hidden Info / Description', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXTAREA,
				'default'   => esc_html__( 'Info content goes here.', 'sifency-addons' ),
				'condition' => array( 'layout_type' => array( 'tooltip', 'flip', 'basic', 'bottom_info' ) ),
			)
		);
		$this->add_control(
			'link',
			array(
				'label'       => esc_html__( 'Link', 'sifency-addons' ),
				'type'        => Controls_Manager::URL,
				'placeholder' => esc_html__( 'https://your-link.com', 'sifency-addons' ),
				'default'     => array(
					'url' => '#',
				),
			)
		);
		$this->add_responsive_control(
			'alignment',
			array(
				'label'     => esc_html__( 'Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'left'   => array(
						'title' => 'Left',
						'icon'  => 'eicon-text-align-left',
					),
					'center' => array(
						'title' => 'Center',
						'icon'  => 'eicon-text-align-center',
					),
					'right'  => array(
						'title' => 'Right',
						'icon'  => 'eicon-text-align-right',
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-ib-wrapper' => 'text-align: {{VALUE}};',
				),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_addons_help_controls();
		$this->add_Sifency_Addons_Button_Style_Controls(
			array(
				'show_dimensions' => true,
			)
		);
		$this->add_sifency_addons_icon_style_controls(
			array(
				'prefix'          => 'icon_',
				'label'           => esc_html__( 'Icon Style', 'sifency-addons' ),
				'selector'        => '.sifency-info-btn .sifency-info-button-icon',
				'hover_selector'  => '.sifency-info-btn .sifency-info-button-icon i',
				'condition'       => array( 'selected_icon!' => '' ),
				'show_dimensions' => true,
			)
		);
		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'         => 'content_style',
				'label'          => 'Description',
				'selector'       => '.sifency-content-style',
				'hover_selector' => '.sifency-info-btn:hover .sifency-content-style',
				'condition'      => array( 'layout_type' => array( 'basic', 'bottom_info', 'tooltip', 'flip' ) ),
				'color_only'     => true,
				'exclude'        => array( 'alignment', 'bg', 'radius', 'shadow', 'stroke' ),
				'show_alignment' => false,
			)
		);
		$this->add_Sifency_Addons_Animation_Controls();
		$this->update_control(
			'sifency_animation_target',
			array(
				'type'    => Controls_Manager::HIDDEN,
				'default' => 'wrapper',
			)
		);
	}

	protected function render_dom( array $context ) {
		$wrapper_id        = esc_attr( $context['dom_id'] );
		$settings          = $this->get_settings_for_display();
		$animation_manager = new Sifency_Addons_Animation_Manager( $settings );

		$this->add_render_attribute( 'wrapper', 'class', 'sifency-ib-wrapper' );

		$animation_attrs_string = $animation_manager->get_wrapper_attributes();

		$this->add_render_attribute( 'button', 'class', 'sifency-info-btn sifency-button-style' );
		$this->add_render_attribute( 'button', 'class', 'sifency-ib-layout-' . $settings['layout_type'] );

		if ( ! empty( $settings['link']['url'] ) ) {
			$this->add_link_attributes( 'button', $settings['link'] );
		}

		?>
		<div id="<?php echo esc_attr( $wrapper_id ); ?>" <?php echo wp_kses_post( $this->get_render_attribute_string( 'wrapper' ) . ' ' . $animation_attrs_string ); ?>>
			
			<?php if ( 'flip' === $settings['layout_type'] ) : ?>
				<div class="sifency-ib-flip-container">
					 <a <?php echo wp_kses_post( $this->get_render_attribute_string( 'button' ) ); ?>>
						<div class="sifency-ib-flip-inner sifency-button-style">
							<div class="sifency-ib-flip-front">
								<div class="sifency-info-button-icon">
									<?php Icons_Manager::render_icon( $settings['selected_icon'], array( 'aria-hidden' => 'true' ) ); ?>
								</div>
							</div>
							<div class="sifency-ib-flip-back">
								<div class="sifency-ib-desc sifency-content-style"><?php echo esc_html( $settings['description'] ); ?></div>
							</div>
						</div>
					 </a>
				</div>

			<?php elseif ( 'basic' === $settings['layout_type'] ) : ?>
				 <a <?php echo wp_kses_post( $this->get_render_attribute_string( 'button' ) ); ?>>
					<div class="sifency-ib-basic-content">
						<span class="sifency-info-button-icon">
							<?php Icons_Manager::render_icon( $settings['selected_icon'], array( 'aria-hidden' => 'true' ) ); ?>
						</span>
						<div class="sifency-ib-text-group">
							<span class="sifency-ib-text"><?php echo esc_html( $settings['title'] ); ?></span>
							<div class="sifency-ib-desc sifency-content-style"><?php echo esc_html( $settings['description'] ); ?></div>
						</div>
					</div>
				 </a>

			<?php elseif ( 'bottom_info' === $settings['layout_type'] ) : ?>
				 <a <?php echo wp_kses_post( $this->get_render_attribute_string( 'button' ) ); ?>>
						<span class="sifency-info-button-icon">
							<?php Icons_Manager::render_icon( $settings['selected_icon'], array( 'aria-hidden' => 'true' ) ); ?>
							<span class="sifency-ib-text"><?php echo esc_html( $settings['title'] ); ?></span>
						</span>
							<div class="sifency-ib-desc sifency-content-style"><?php echo esc_html( $settings['description'] ); ?></div>
				 </a>

			<?php else : ?>
				<a <?php echo wp_kses_post( $this->get_render_attribute_string( 'button' ) ); ?>>
					
					<span class="sifency-info-button-icon">
						<?php Icons_Manager::render_icon( $settings['selected_icon'], array( 'aria-hidden' => 'true' ) ); ?>
					</span>

					<span class="sifency-ib-text">
						<?php echo esc_html( $settings['title'] ); ?>
					</span>

					<?php if ( 'tooltip' === $settings['layout_type'] ) : ?>
						<div class="sifency-ib-tooltip-content">
							<div class="sifency-ib-desc sifency-content-style"><?php echo esc_html( $settings['description'] ); ?></div>
						</div>
					<?php endif; ?>

				</a>
			<?php endif; ?>

		</div>
		<?php
	}
}
