<?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\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Sifency\Traits\Sifency_Addons_Animation_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Manager;
use Sifency\Traits\Sifency_Addons_Button_Style_Controls;
use Sifency\Traits\Sifency_Addons_Help_Controls;
class Sifency_Widget_Digital_Live_Demo extends Sifency_Themebuilder_Widget_Base {
	use Sifency_Addons_Animation_Controls;
	use Sifency_Addons_Button_Style_Controls;
	use Sifency_Addons_Help_Controls;

	protected function get_allowed_template_types() {
		return 'digital';
	}
	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'     => 'sifency-digital-live-demo',
			'title'    => 'Digital Live Demo Button',
			'icon'     => 'eicon-meta-data',
			'category' => array( 'sifency-digital-components' ),
			'keywords' => array( 'digital', 'live demo', 'button', 'link', 'meta', 'sifency' ),
		);}
	protected function register_controls() {
		$this->start_controls_section(
			'section_button_content',
			array(
				'label' => esc_html__( 'Button', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'placeholder_text',
			array(
				'label'       => esc_html__( 'Placeholder Text', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Live Demo', 'sifency-addons' ),
				'description' => esc_html__( 'This text is shown in the editor if the dynamic fields are empty.', 'sifency-addons' ),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_addons_help_controls();
		$this->add_Sifency_Addons_Button_Style_Controls();
		$this->add_Sifency_Addons_Animation_Controls();
	}
	protected function render_dom( array $context ) {
		$wrapper_id = esc_attr( $context['dom_id'] );
		$settings   = $this->get_settings_for_display();
		$url        = sifency_get_field( 'digital_live_demo_url' );
		if ( ! empty( $url ) ) {
			$display_url  = $url;
			$display_text = ! empty( $text ) ? $text : esc_html__( 'Live Demo', 'sifency-addons' );
		} elseif ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
			$display_url  = '#';
			$display_text = $settings['placeholder_text'];
		} else {
			return;
		}
		$animation_manager = new Sifency_Addons_Animation_Manager( $settings );
		$animation_attrs   = $animation_manager->get_wrapper_attributes( array() );
		$this->add_render_attribute( 'button', 'class', 'sifency-button-style sifency-button' );
		$this->add_render_attribute( 'button', 'href', esc_url( $display_url ) );
		$this->add_render_attribute( 'button', 'target', '_blank' );
		$this->add_render_attribute( 'button', 'rel', 'noopener noreferrer' ); ?>
		<div id="<?php echo esc_attr ( $wrapper_id ); ?>" <?php echo $animation_attrs; // phpcs:ignore ?>>
			<a <?php echo wp_kses( $this->get_render_attribute_string( 'button' ), array() ); ?>>				
				<span class="sifency-button-text"><?php esc_html_e( 'Live Demo', 'sifency-addons' ); ?></span>
			</a>
		</div>
		<?php
	}
}
