<?php
/**
 * Wave Access – Page-Builder-Integrationen (Elementor, WPBakery)
 *
 * Beide sind dünne Hüllen um render_accessibility_block() bzw. den
 * Shortcode [wave_access] und registrieren sich nur, wenn der jeweilige
 * Builder aktiv ist.
 */

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

/* ---------- Elementor ---------- */
add_action( 'elementor/widgets/register', function( $widgets_manager ) {
	if ( ! class_exists( '\Elementor\Widget_Base' ) ) return;

	class Wave_Elementor_Widget extends \Elementor\Widget_Base {
		public function get_name()  { return 'wave_access'; }
		public function get_title() { return __( 'Wave Access – Eingabehilfen', 'wave-access' ); }
		public function get_icon()  { return 'eicon-accessibility'; }
		public function get_categories() { return array( 'general' ); }
		public function get_keywords()   { return array( 'accessibility', 'barrierefreiheit', 'a11y', 'wave' ); }

		protected function register_controls() {
			$this->start_controls_section( 'section_content', array(
				'label' => __( 'Eingabehilfen-Panel', 'wave-access' ),
			) );
			$this->add_control( 'panel_title', array(
				'label'   => __( 'Titel', 'wave-access' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Eingabehilfen', 'wave-access' ),
			) );
			$this->add_control( 'show_title', array(
				'label'   => __( 'Titel anzeigen', 'wave-access' ),
				'type'    => \Elementor\Controls_Manager::SWITCHER,
				'default' => 'yes',
			) );
			$this->add_control( 'show_reset', array(
				'label'   => __( 'Zurücksetzen-Button anzeigen', 'wave-access' ),
				'type'    => \Elementor\Controls_Manager::SWITCHER,
				'default' => 'yes',
			) );
			$this->end_controls_section();
		}

		protected function render() {
			$s = $this->get_settings_for_display();
			echo Wave_Access::get_instance()->render_accessibility_block( array(
				'showTitle' => 'yes' === $s['show_title'],
				'showReset' => 'yes' === $s['show_reset'],
				'title'     => $s['panel_title'],
			) );
		}
	}

	$widgets_manager->register( new Wave_Elementor_Widget() );
} );

/* ---------- WPBakery (Visual Composer) ---------- */
add_action( 'vc_before_init', function() {
	if ( ! function_exists( 'vc_map' ) ) return;
	vc_map( array(
		'name'        => __( 'Wave Access – Eingabehilfen', 'wave-access' ),
		'base'        => 'wave_access',
		'description' => __( 'Barrierefreiheits-Panel an dieser Stelle einfügen', 'wave-access' ),
		'category'    => __( 'Inhalt', 'wave-access' ),
		'icon'        => 'icon-wpb-ui-accordion',
		'params'      => array(
			array(
				'type'        => 'textfield',
				'heading'     => __( 'Titel', 'wave-access' ),
				'param_name'  => 'title',
				'value'       => __( 'Eingabehilfen', 'wave-access' ),
			),
			array(
				'type'        => 'checkbox',
				'heading'     => __( 'Titel anzeigen', 'wave-access' ),
				'param_name'  => 'show_title',
				'value'       => array( __( 'Ja', 'wave-access' ) => '1' ),
				'std'         => '1',
			),
			array(
				'type'        => 'checkbox',
				'heading'     => __( 'Zurücksetzen-Button anzeigen', 'wave-access' ),
				'param_name'  => 'show_reset',
				'value'       => array( __( 'Ja', 'wave-access' ) => '1' ),
				'std'         => '1',
			),
		),
	) );
} );
