<?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 Sifency\Traits\Sifency_Addons_Button_Style_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Controls;
use Sifency\Traits\Sifency_Addons_Animation_Manager;
use Sifency\Traits\Sifency_Addons_Help_Controls;
use Sifency\Classes\Sifency_Addons_Widget_Base;
class Sifency_Offcanvas_Trigger_Widget extends Sifency_Addons_Widget_Base {

	use Sifency_Addons_Button_Style_Controls;
	use Sifency_Addons_Animation_Controls;
	use Sifency_Addons_Help_Controls;
	public function __construct( $data = array(), $args = null ) {
		parent::__construct( $data, $args );
		$this->wg_config = array(
			'name'          => 'sifency_offcanvas_trigger',
			'title'         => 'Offcanvas Trigger',
			'icon'          => 'eicon-menu-bar',
			'category'      => array( 'sifency-addons-widget' ),
			'style_depends' => array( 'sifency-frontend-style', 'sifency-icon', 'sifency-offcanvas-trigger-style', 'sifency-button-style' ),
			'keywords'      => array( 'offcanvas', 'trigger', 'button', 'sifency' ),
		);}

	protected function register_controls() {
		$this->start_controls_section(
			'section_content',
			array(
				'label' => esc_html__( 'Button', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'button_text',
			array(
				'label'   => esc_html__( 'Text', 'sifency-addons' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Open', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'icon',
			array(
				'label' => esc_html__( 'Icon', 'sifency-addons' ),
				'type'  => Controls_Manager::ICONS,
			)
		);
		$this->add_control(
			'icon_align',
			array(
				'label'     => esc_html__( 'Icon Position', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'left',
				'options'   => array(
					'left'  => esc_html__( 'Before', 'sifency-addons' ),
					'right' => esc_html__( 'After', 'sifency-addons' ),
				),
				'condition' => array(
					'icon[value]!' => '',
				),
			)
		);
		$this->add_responsive_control(
			'align',
			array(
				'label'        => esc_html__( 'Alignment', 'sifency-addons' ),
				'type'         => Controls_Manager::CHOOSE,
				'options'      => array(
					'left'   => array(
						'title' => esc_html__( 'Left', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-left',
					),
					'center' => array(
						'title' => esc_html__( 'Center', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-center',
					),
					'right'  => array(
						'title' => esc_html__( 'Right', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-right',
					),
				),
				'prefix_class' => 'elementor-align%s-',
			)
		);
		$this->end_controls_section();
		$this->add_sifency_addons_help_controls();
		$this->add_Sifency_Addons_Button_Style_Controls(
			array(
				'selector'        => '.sifency-trigger-btn',
				'show_dimensions' => true,
			)
		);
		$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();
		$this->add_render_attribute( 'button', 'class', 'sifency-trigger-btn sifency-button sifency-addons-primary-button' );
		$this->add_render_attribute( 'button', 'href', '#' );
		$this->add_render_attribute( 'button', 'data-sifency-offcanvas', 'open' );

		?>
		<div id="<?php echo esc_attr( $wrapper_id ); ?>" class="sifency-trigger-wrapper">
			<a <?php echo wp_kses( $this->get_render_attribute_string( 'button' ), array() ); ?>>
				<?php
				// Icon Before
				if ( ! empty( $settings['icon']['value'] ) && $settings['icon_align'] === 'left' ) :
					?>
					<span class="elementor-button-icon elementor-align-icon-left">
						<?php \Elementor\Icons_Manager::render_icon( $settings['icon'], array( 'aria-hidden' => 'true' ) ); ?>
					</span>
				<?php endif; ?>

				<?php if ( ! empty( $settings['button_text'] ) ) : ?>
					<span class="elementor-button-text">
						<?php echo esc_html( $settings['button_text'] ); ?>
					</span>
				<?php endif; ?>

				<?php
				// Icon After
				if ( ! empty( $settings['icon']['value'] ) && $settings['icon_align'] === 'right' ) :
					?>
					<span class="elementor-button-icon elementor-align-icon-right">
						<?php \Elementor\Icons_Manager::render_icon( $settings['icon'], array( 'aria-hidden' => 'true' ) ); ?>
					</span>
				<?php endif; ?>
			</a>
		</div>
		<?php
	}
}
