<?php
/**
 * Class: Modal_Box_Widget
 * Name: Boîte Modale
 * Slug: eac-addon-modal-box
 *
 * Description: Construit et affiche une popup avec différents contenus (Texte, Formulaire, Templates)
 * déclenchée par un bouton, une image, du texte ou automatiquement
 *
 * @since 1.6.1
 */

namespace EACCustomWidgets\Includes\Widgets;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

use EACCustomWidgets\Core\Utils\Eac_Tools_Util;
use EACCustomWidgets\Core\Eac_Load_Config;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Control_Media;
use Elementor\Group_Control_Typography;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Utils;
use Elementor\Icons_Manager;
use Elementor\Group_Control_Css_Filter;
use Elementor\Group_Control_Background;
use Elementor\TemplateLibrary\Source_Local;

class Modal_Box_Widget extends Widget_Base {

	/**
	 * Le nom de la clé du composant dans le fichier de configuration
	 *
	 * @var $slug
	 *
	 * @access private
	 */
	private $slug = 'modal-box';

	/**
	 * Retrieve widget name.
	 *
	 * @access public
	 *
	 * @return string widget name.
	 */
	public function get_name(): string {
		return Eac_Load_Config::get_widget_name( $this->slug );
	}

	/**
	 * Retrieve widget title.
	 *
	 * @access public
	 *
	 * @return string widget title.
	 */
	public function get_title(): string {
		return Eac_Load_Config::get_widget_title( $this->slug );
	}

	/**
	 * Retrieve widget icon.
	 *
	 * @access public
	 *
	 * @return string widget icon.
	 */
	public function get_icon(): string {
		return Eac_Load_Config::get_widget_icon( $this->slug );
	}

	/**
	 * Affecte le composant à la catégorie définie dans plugin.php
	 *
	 * @access public
	 *
	 * @return array widget category.
	 */
	public function get_categories(): array {
		return Eac_Load_Config::get_widget_categories( $this->slug );
	}

	/**
	 * Load dependent libraries
	 *
	 * @access public
	 *
	 * @return array libraries list.
	 */
	public function get_script_depends(): array {
		return array( 'eac-modalbox' );
	}

	/**
	 * Load dependent styles
	 * Les styles sont chargés dans le footer
	 *
	 * @access public
	 *
	 * @return array CSS list.
	 */
	public function get_style_depends(): array {
		return array( 'eac-modalbox' );
	}

	/**
	 * Get widget keywords.
	 *
	 * Retrieve the list of keywords the widget belongs to.
	 *
	 * @access public
	 *
	 * @return array Widget keywords.
	 */
	public function get_keywords(): array {
		return Eac_Load_Config::get_widget_keywords( $this->slug );
	}

	/**
	 * Get help widget get_custom_help_url.
	 *
	 * @access public
	 *
	 * @return string URL help center
	 */
	public function get_custom_help_url(): string {
		return Eac_Load_Config::get_widget_help_url( $this->slug );
	}

	/**
	 * has_widget_inner_wrapper
	 *
	 * @return bool
	 */
	public function has_widget_inner_wrapper(): bool {
		return false;
	}

	/**
	 * is_dynamic_content
	 *
	 * @return bool
	 */
	protected function is_dynamic_content(): bool {
		return true;
	}

	/**
	 * Register widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @access protected
	 */
	protected function register_controls(): void {

		$this->start_controls_section(
			'mb_param_content',
			array(
				'label' => esc_html__( 'Content', 'eac-components' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

			$this->add_control(
				'mb_enable_header',
				array(
					'label'        => esc_html__( 'Enable modal header', 'eac-components' ),
					'type'         => Controls_Manager::SWITCHER,
					'label_on'     => esc_html__( 'Yes', 'eac-components' ),
					'label_off'    => esc_html__( 'No', 'eac-components' ),
					'return_value' => 'yes',
					'default'      => '',
				)
			);

			$this->add_control(
				'mb_texte_header',
				array(
					'label'       => esc_html__( 'Title', 'eac-components' ),
					'type'        => Controls_Manager::TEXT,
					'dynamic'     => array( 'active' => true ),
					'ai'          => array( 'active' => false ),
					'placeholder' => esc_html__( 'Header text', 'eac-components' ),
					'label_block' => true,
					'render_type' => 'none',
					'condition'   => array( 'mb_enable_header' => 'yes' ),
				)
			);

			$this->add_control(
				'mb_type_content',
				array(
					'label'       => esc_html__( 'Content type', 'eac-components' ),
					'type'        => Controls_Manager::SELECT,
					'description' => esc_html__( 'Content type to display', 'eac-components' ),
					'default'     => 'texte',
					'options'     => array(
						'links'      => esc_html__( 'Link Video or Map', 'eac-components' ),
						'html'       => esc_html__( 'HTML link', 'eac-components' ),
						'texte'      => esc_html__( 'Custom text', 'eac-components' ),
						'formulaire' => esc_html__( 'Shortcode', 'eac-components' ),
						'tmpl_cont'  => esc_html__( 'Elementor template container', 'eac-components' ),
						'tmpl_sec'   => esc_html__( 'Elementor template section', 'eac-components' ),
						'tmpl_page'  => esc_html__( 'Elementor template page', 'eac-components' ),
					),
					'label_block' => true,
					'separator'   => 'before',
				)
			);

			$this->add_control(
				'mb_shortcode_content',
				array(
					'label'       => esc_html__( 'Enter shortcode', 'eac-components' ),
					'type'        => Controls_Manager::TEXTAREA,
					'ai'          => array( 'active' => false ),
					'placeholder' => '[contact-form-7 id="XXXX""]',
					'default'     => '',
					'condition'   => array( 'mb_type_content' => 'formulaire' ),
				)
			);

			$this->add_control(
				'mb_url_content',
				array(
					'label'        => esc_html( 'URL' ),
					'type'         => Controls_Manager::URL,
					'placeholder'  => esc_html__( 'Type or paste your URL', 'eac-components' ),
					'dynamic'      => array(
						'active' => true,
					),
					'autocomplete' => true,
					'condition'    => array( 'mb_type_content' => array( 'links', 'html' ) ),
				)
			);

			$this->add_control(
				'mb_texte_content',
				array(
					'label'     => esc_html__( 'Description', 'eac-components' ),
					'type'      => Controls_Manager::WYSIWYG,
					'ai'        => array( 'active' => false ),
					'default'   => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.',
					'condition' => array( 'mb_type_content' => 'texte' ),
				)
			);

			$this->add_control(
				'mb_tmpl_cont_content',
				array(
					'label'       => esc_html__( 'Elementor template container', 'eac-components' ),
					'type'        => Controls_Manager::SELECT,
					'options'     => Eac_Tools_Util::get_elementor_templates( 'container' ),
					'condition'   => array( 'mb_type_content' => 'tmpl_cont' ),
					'label_block' => true,
				)
			);

			$this->add_control(
				'mb_tmpl_sec_content',
				array(
					'label'       => esc_html__( 'Elementor template section', 'eac-components' ),
					'type'        => Controls_Manager::SELECT,
					'options'     => Eac_Tools_Util::get_elementor_templates( 'section' ),
					'condition'   => array( 'mb_type_content' => 'tmpl_sec' ),
					'label_block' => true,
				)
			);

			$this->add_control(
				'mb_tmpl_page_content',
				array(
					'label'       => esc_html__( 'Elementor template page', 'eac-components' ),
					'type'        => Controls_Manager::SELECT,
					'options'     => Eac_Tools_Util::get_elementor_templates( 'page' ),
					'condition'   => array( 'mb_type_content' => 'tmpl_page' ),
					'label_block' => true,
				)
			);

		$this->end_controls_section();

		/**
		 * Generale Content Section
		 */
		$this->start_controls_section(
			'mb_param_trigger',
			array(
				'label' => esc_html__( 'Trigger options', 'eac-components' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

			$this->add_control(
				'mb_origin_trigger',
				array(
					'label'       => esc_html__( 'Trigger', 'eac-components' ),
					'type'        => Controls_Manager::SELECT,
					'options'     => array(
						'button'     => esc_html__( 'Button', 'eac-components' ),
						'image'      => esc_html__( 'Image', 'eac-components' ),
						'text'       => esc_html__( 'Text', 'eac-components' ),
						'pageloaded' => esc_html__( 'On page load', 'eac-components' ),
					),
					'label_block' => true,
					'default'     => 'button',
				)
			);

			$this->add_control(
				'mb_display_text_button',
				array(
					'label'       => esc_html__( 'Button label', 'eac-components' ),
					'default'     => esc_html__( 'Open modal box', 'eac-components' ),
					'type'        => Controls_Manager::TEXT,
					'dynamic'     => array( 'active' => true ),
					'ai'          => array( 'active' => false ),
					'label_block' => true,
					'condition'   => array( 'mb_origin_trigger' => 'button' ),
				)
			);

			$this->add_control(
				'mb_icon_activated',
				array(
					'label'        => esc_html__( 'Add pictogram', 'eac-components' ),
					'type'         => Controls_Manager::SWITCHER,
					'label_on'     => esc_html__( 'Yes', 'eac-components' ),
					'label_off'    => esc_html__( 'No', 'eac-components' ),
					'return_value' => 'yes',
					'default'      => '',
					'condition'    => array( 'mb_origin_trigger' => 'button' ),
				)
			);

			$this->add_control(
				'mb_display_icon_button',
				array(
					'label'                  => esc_html__( 'Pictograms', 'eac-components' ),
					'type'                   => Controls_Manager::ICONS,
					'default'                => array(
						'value'   => 'fas fa-arrow-right',
						'library' => 'fa-solid',
					),
					'skin'                   => 'inline',
					'condition'              => array(
						'mb_origin_trigger' => 'button',
						'mb_icon_activated' => 'yes',
					),
				)
			);

			$this->add_control(
				'mb_position_icon_button',
				array(
					'label'     => esc_html__( 'Position', 'eac-components' ),
					'type'      => Controls_Manager::SELECT,
					'default'   => 'before',
					'options'   => array(
						'before' => esc_html__( 'Before', 'eac-components' ),
						'after'  => esc_html__( 'After', 'eac-components' ),
					),
					'condition' => array(
						'mb_origin_trigger' => 'button',
						'mb_icon_activated' => 'yes',
					),
				)
			);

			$this->add_control(
				'mb_marge_icon_button',
				array(
					'label'              => esc_html__( 'Margin', 'eac-components' ),
					'type'               => Controls_Manager::DIMENSIONS,
					'allowed_dimensions' => array( 'left', 'right' ),
					'default'            => array(
						'left'     => 0,
						'right'    => 0,
						'unit'     => 'px',
						'isLinked' => false,
					),
					'range'              => array(
						'px' => array(
							'min'  => 0,
							'max'  => 20,
							'step' => 1,
						),
					),
					'selectors'          => array(
						'{{WRAPPER}} .button-icon' => 'margin-block: {{TOP}}px {{BOTTOM}}px; margin-inline: {{LEFT}}px {{RIGHT}}px;',
					),
					'condition'          => array(
						'mb_origin_trigger' => 'button',
						'mb_icon_activated' => 'yes',
					),
				)
			);

			$this->add_control(
				'mb_display_image',
				array(
					'label'     => esc_html__( 'Image', 'eac-components' ),
					'type'      => Controls_Manager::MEDIA,
					'dynamic'   => array( 'active' => true ),
					'ai'        => array( 'active' => false ),
					'default'   => array(
						'url' => Utils::get_placeholder_image_src(),
					),
					'condition' => array( 'mb_origin_trigger' => 'image' ),
				)
			);

			$this->add_control(
				'mb_image_dimension',
				array(
					'label'     => esc_html__( 'Size', 'eac-components' ),
					'type'      => Controls_Manager::SELECT,
					'default'   => 'medium_large',
					'options'   => array(
						'thumbnail'    => esc_html__( 'Thumbnail', 'eac-components' ),
						'medium'       => esc_html__( 'Medium', 'eac-components' ),
						'medium_large' => esc_html__( 'Medium-large', 'eac-components' ),
						'large'        => esc_html__( 'Large', 'eac-components' ),
						'full'         => esc_html__( 'Original', 'eac-components' ),
					),
					'condition' => array( 'mb_origin_trigger' => 'image' ),
				)
			);

			$this->add_control(
				'mb_caption_source',
				array(
					'label'     => esc_html__( 'Legend', 'eac-components' ),
					'type'      => Controls_Manager::SELECT,
					'options'   => array(
						'none'       => esc_html__( 'None', 'eac-components' ),
						'attachment' => esc_html__( 'Attachment', 'eac-components' ),
						'custom'     => esc_html__( 'Custom caption', 'eac-components' ),
					),
					'default'   => 'none',
					'condition' => array( 'mb_origin_trigger' => 'image' ),
				)
			);

			$this->add_control(
				'mb_caption_texte',
				array(
					'label'       => esc_html__( 'Custom caption', 'eac-components' ),
					'type'        => Controls_Manager::TEXT,
					'dynamic'     => array( 'active' => true ),
					'ai'          => array( 'active' => false ),
					'default'     => '',
					'placeholder' => esc_html__( 'Your custom caption', 'eac-components' ),
					'condition'   => array(
						'mb_origin_trigger' => 'image',
						'mb_caption_source' => 'custom',
					),
					'label_block' => true,
				)
			);

			$this->add_control(
				'mb_display_texte',
				array(
					'label'       => esc_html__( 'Text', 'eac-components' ),
					'type'        => Controls_Manager::TEXT,
					'dynamic'     => array( 'active' => true ),
					'ai'          => array( 'active' => false ),
					'label_block' => true,
					'default'     => esc_html__( 'Open modal box', 'eac-components' ),
					'condition'   => array( 'mb_origin_trigger' => 'text' ),
				)
			);

			$start = is_rtl() ? 'right' : 'left';
			$end   = is_rtl() ? 'left' : 'right';
			$this->add_control(
				'mb_align_button',
				array(
					'label'     => esc_html__( 'Alignment', 'eac-components' ),
					'type'      => Controls_Manager::CHOOSE,
					'options'   => array(
						'left'   => array(
							'title' => is_rtl() ? esc_html__( 'Right', 'eac-components' ) : esc_html__( 'Left', 'eac-components' ),
							'icon'  => "eicon-h-align-{$start}",
						),
						'center' => array(
							'title' => esc_html__( 'Center', 'eac-components' ),
							'icon'  => 'eicon-h-align-center',
						),
						'right'  => array(
							'title' => is_rtl() ? esc_html__( 'Left', 'eac-components' ) : esc_html__( 'Right', 'eac-components' ),
							'icon'  => "eicon-h-align-{$end}",
						),
					),
					'default'   => 'center',
					'selectors_dictionary' => array(
						'left'   => 'start',
						'right'  => 'end',
					),
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__wrapper' => 'text-align: {{VALUE}};' ),
					'condition' => array( 'mb_origin_trigger' => array( 'button', 'text', 'image' ) ),
				)
			);

			$this->add_control(
				'mb_popup_delay',
				array(
					'label'       => esc_html__( 'Delay in Popup Display (Sec)', 'eac-components' ),
					'type'        => Controls_Manager::NUMBER,
					'description' => esc_html__( 'When should the popup appear after page load ? (In seconds)', 'eac-components' ),
					'default'     => 5,
					'condition'   => array( 'mb_origin_trigger' => 'pageloaded' ),
				)
			);

			$this->add_control(
				'mb_popup_activated',
				array(
					'label'        => esc_html__( 'Enable in editor', 'eac-components' ),
					'type'         => Controls_Manager::SWITCHER,
					'description'  => esc_html__( 'Deactivate this option before leaving the page', 'eac-components' ),
					'label_on'     => esc_html__( 'Yes', 'eac-components' ),
					'label_off'    => esc_html__( 'No', 'eac-components' ),
					'return_value' => 'yes',
					'default'      => '',
					'condition'    => array( 'mb_origin_trigger' => 'pageloaded' ),
				)
			);

		$this->end_controls_section();

		/**
		 * Generale Style Section
		 */
		$this->start_controls_section(
			'mb_modal_box_style',
			array(
				'label' => esc_html__( 'Modal box', 'eac-components' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

			$this->add_responsive_control(
				'mb_modal_box_width',
				array(
					'label'          => esc_html__( 'Width', 'eac-components' ),
					'type'           => Controls_Manager::SLIDER,
					'size_units'     => array( 'px', '%', 'vw' ),
					'default'        => array(
						'unit' => '%',
						'size' => 70,
					),
					'tablet_default' => array(
						'unit' => '%',
						'size' => 80,
					),
					'mobile_default' => array(
						'unit' => '%',
						'size' => 100,
					),
					'range'          => array(
						'px' => array(
							'min'  => 50,
							'max'  => 1000,
							'step' => 10,
						),
						'%'  => array(
							'min'  => 10,
							'max'  => 100,
							'step' => 10,
						),
						'vw'  => array(
							'min'  => 10,
							'max'  => 100,
							'step' => 10,
						),
					),
					'label_block'    => true,
					'selectors'      => array(
						'#modalbox-hidden-{{ID}}.fancybox-content,
						.modalbox-visible-{{ID}} .fancybox-content' => 'max-inline-size: {{SIZE}}{{UNIT}}; inline-size: 100%;',
					),
				)
			);

			$this->add_responsive_control(
				'mb_modal_box_height',
				array(
					'label'       => esc_html__( 'Height (px)', 'eac-components' ),
					'type'        => Controls_Manager::SLIDER,
					'size_units'  => array( 'px' ),
					'default'     => array(
						'unit' => 'px',
						'size' => 360,
					),
					'range'       => array(
						'px' => array(
							'min'  => 10,
							'max'  => 1000,
							'step' => 10,
						),
					),
					'label_block' => true,
					'selectors'   => array( '.modalbox-visible-{{ID}} .fancybox-content' => 'max-block-size: {{SIZE}}px; block-size: 100%;' ),
					'condition'   => array( 'mb_type_content' => array( 'links', 'html' ) ),
				)
			);

			$this->add_group_control(
				Group_Control_Border::get_type(),
				array(
					'name'      => 'mb_modal_box_border',
					'selector'  => '.modalbox-visible-{{ID}} .fancybox-content, #modalbox-hidden-{{ID}}.fancybox-content',
					'separator' => 'before',
				)
			);

			$this->add_control(
				'mb_modal_box_close_color',
				array(
					'label'     => esc_html__( 'Upper close button color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
					'selectors' => array(
						'#modalbox-hidden-{{ID}}.fancybox-content button.fancybox-close-small,
						.modalbox-visible-{{ID}} .fancybox-content button.fancybox-close-small' => 'color: {{VALUE}}; opacity: 1;',
					),
				)
			);

			$this->start_controls_tabs( 'mb_modal_box_style_tabs' );

				$this->start_controls_tab(
					'mb_modal_box_style_effet',
					array(
						'label' => esc_html__( 'Effects', 'eac-components' ),
					)
				);

					$this->add_control(
						'mb_modal_box_effect',
						array(
							'label'       => esc_html__( 'Entry effect', 'eac-components' ),
							'type'        => Controls_Manager::SELECT,
							'default'     => 'zoom-in-out',
							'options'     => array(
								'zoom-in-out'         => esc_html__( 'Default', 'eac-components' ),
								'fade'                => esc_html__( 'Fade', 'eac-components' ),
								'slide-in-out-top'    => esc_html__( 'To the bottom', 'eac-components' ),
								'slide-in-out-bottom' => esc_html__( 'To the top', 'eac-components' ),
								'slide-in-out-right'  => esc_html__( 'To the left', 'eac-components' ),
								'slide-in-out-left'   => esc_html__( 'To the right', 'eac-components' ),
								'tube'                => esc_html( 'Tube' ),
							),
							'label_block' => true,
						)
					);

					$this->add_control(
						'mb_modal_box_position',
						array(
							'label'       => esc_html__( 'Position', 'eac-components' ),
							'type'        => Controls_Manager::SELECT,
							'default'     => 'default',
							'options'     => array(
								'default'     => esc_html__( 'Default', 'eac-components' ),
								'topleft'     => esc_html__( 'Top left', 'eac-components' ),
								'topright'    => esc_html__( 'Top right', 'eac-components' ),
								'bottomleft'  => esc_html__( 'Bottom left', 'eac-components' ),
								'bottomright' => esc_html__( 'Bottom right', 'eac-components' ),
							),
							'label_block' => true,
						)
					);

					$this->add_control(
						'mb_modal_box_duration',
						array(
							'label'     => esc_html__( 'Duration (ms)', 'eac-components' ),
							'type'      => Controls_Manager::NUMBER,
							'default'   => 600,
							'min'       => 200,
							'max'       => 5000,
							'step'      => 100,
						)
					);

				$this->end_controls_tab();

				$this->start_controls_tab(
					'mb_modal_box_style_background',
					array(
						'label'     => esc_html__( 'Background', 'eac-components' ),
						'condition' => array( 'mb_type_content!' => array( 'links', 'html' ) ),
					)
				);

					$this->add_group_control(
						Group_Control_Background::get_type(),
						array(
							'name'           => 'mb_modal_box_bg',
							'types'          => array( 'classic', 'gradient' ),
							'fields_options' => array(
								'size'     => array( 'default' => 'cover' ),
								'position' => array( 'default' => 'center center' ),
								'repeat'   => array( 'default' => 'no-repeat' ),
							),
							'selector'       => '{{WRAPPER}} .mb-modalbox__hidden-content-body-bg',
							'condition'      => array( 'mb_type_content!' => 'links' ),
						)
					);

					$this->add_control(
						'mb_modal_box_blend',
						array(
							'label'       => esc_html__( 'Blend mode', 'eac-components' ),
							'description' => esc_html__( 'You have selected a color and an image', 'eac-components' ),
							'type'        => Controls_Manager::SELECT,
							'default'     => 'normal',
							'options'     => array(
								'normal'      => 'Normal',
								'screen'      => 'Screen',
								'overlay'     => 'Overlay',
								'darken'      => 'Darken',
								'lighten'     => 'Lighten',
								'color-dodge' => 'Color-dodge',
								'color-burn'  => 'Color-burn',
								'hard-light'  => 'Hard-light',
								'soft-light'  => 'Soft-light',
								'difference'  => 'Difference',
								'exclusion'   => 'Exclusion',
								'hue'         => 'Hue',
								'saturation'  => 'Saturation',
								'color'       => 'Color',
								'luminosity'  => 'Luminosity',
							),
							'label_block' => true,
							'selectors'   => array( '{{WRAPPER}} .mb-modalbox__hidden-content-body-bg' => 'background-blend-mode: {{VALUE}};' ),
							'separator'   => 'before',
							'condition'   => array(
								'mb_modal_box_bg_background' => 'classic',
								'mb_type_content!' => 'links',
							),
						)
					);

					$this->add_control(
						'mb_modal_box_bg_opacity',
						array(
							'label'     => esc_html__( 'Opacity', 'eac-components' ),
							'type'      => Controls_Manager::SLIDER,
							'default'   => array( 'size' => 0.2 ),
							'range'     => array(
								'px' => array(
									'max'  => 1,
									'min'  => 0.1,
									'step' => 0.1,
								),
							),
							'selectors' => array( '{{WRAPPER}} .mb-modalbox__hidden-content-body-bg' => 'opacity: {{SIZE}};' ),
							'condition' => array(
								'mb_modal_box_bg_background' => 'classic',
								'mb_type_content!' => 'links',
							),
						)
					);

				$this->end_controls_tab();

			$this->end_controls_tabs();

		$this->end_controls_section();

		/** La caption de la boîte modale 'links et html' ne peut pas être stylisé */
		$this->start_controls_section(
			'mb_header_style',
			array(
				'label'     => esc_html__( 'Modal box header', 'eac-components' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array(
					'mb_enable_header' => 'yes',
					'mb_texte_header!' => '',
					'mb_type_content!' => array( 'links', 'html' ),
				),
			)
		);

			$this->add_control(
				'mb_header_color',
				array(
					'label'     => esc_html__( 'Title color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
					'default'   => '#000',
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__hidden-content-title' => 'color: {{VALUE}};' ),
				)
			);

			$this->add_group_control(
				Group_Control_Typography::get_type(),
				array(
					'name'     => 'mb_header_typography',
					'label'    => esc_html__( 'Title typography', 'eac-components' ),
					'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ),
					'selector' => '{{WRAPPER}} .mb-modalbox__hidden-content-title',
				)
			);

			$this->add_control(
				'mb_header_padding',
				array(
					'label'      => esc_html__( 'Padding', 'eac-components' ),
					'type'       => Controls_Manager::DIMENSIONS,
					'size_units' => array( 'px', 'em' ),
					'default'    => array(
						'unit'   => 'px',
						'top'    => 7,
						'right'  => 0,
						'bottom' => 5,
						'left'   => 0,
					),
					'selectors'  => array(
						'{{WRAPPER}} .mb-modalbox__hidden-content-title' => 'padding-block: {{TOP}}{{UNIT}} {{BOTTOM}}{{UNIT}}; padding-inline: {{LEFT}}{{UNIT}} {{RIGHT}}{{UNIT}};',
					),
				)
			);

			$this->add_control(
				'mb_header_background',
				array(
					'label'     => esc_html__( 'Background color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__hidden-content-title' => 'background-color: {{VALUE}};' ),
				)
			);

			$this->add_group_control(
				Group_Control_Border::get_type(),
				array(
					'name'      => 'mb_header_border',
					'selector'  => '{{WRAPPER}} .mb-modalbox__hidden-content-title',
					'separator' => 'before',
				)
			);

		$this->end_controls_section();

		$this->start_controls_section(
			'mb_texte_content_style',
			array(
				'label'     => esc_html__( 'Modal box content', 'eac-components' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'mb_type_content' => 'texte' ),
			)
		);

			$this->add_control(
				'mb_texte_content_color',
				array(
					'label'     => esc_html__( 'Color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
					'default'   => '#919CA7',
					'selectors' => array(
						'{{WRAPPER}} .mb-modalbox__hidden-content-body div,
						{{WRAPPER}} .mb-modalbox__hidden-content-body a i' => 'color: {{VALUE}};',
					),
				)
			);

			$this->add_group_control(
				Group_Control_Typography::get_type(),
				array(
					'name'     => 'mb_texte_content_typography',
					'label'    => esc_html__( 'Typography', 'eac-components' ),
					'global'    => array( 'default' => Global_Typography::TYPOGRAPHY_SECONDARY ),
					'selector' => '	{{WRAPPER}} .mb-modalbox__hidden-content-body div,
									{{WRAPPER}} .mb-modalbox__hidden-content-body a i',
				)
			);

		$this->end_controls_section();

		$this->start_controls_section(
			'mb_button_style',
			array(
				'label'     => esc_html__( 'Trigger button', 'eac-components' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'mb_origin_trigger' => 'button' ),
			)
		);

		$this->start_controls_tabs( 'mb_controls_tabs' );

				$this->start_controls_tab(
					'mb_controls_tab_normal',
					array(
						'label' => esc_html__( 'Normal', 'eac-components' ),
					)
				);

					$this->add_control(
						'mb_button_color',
						array(
							'label'     => esc_html__( 'Color', 'eac-components' ),
							'type'      => Controls_Manager::COLOR,
							'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
							'selectors' => array(
								'{{WRAPPER}} .mb-modalbox__wrapper-btn' => 'color: {{VALUE}};',
							),
						)
					);

					$this->add_group_control(
						Group_Control_Typography::get_type(),
						array(
							'name'     => 'mb_button_typography',
							'label'    => esc_html__( 'Typography', 'eac-components' ),
							'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_TEXT ),
							'selector' => '{{WRAPPER}} .mb-modalbox__wrapper-btn',
						)
					);

					$this->add_control(
						'mb_button_background',
						array(
							'label'     => esc_html__( 'Background color', 'eac-components' ),
							'type'      => Controls_Manager::COLOR,
							'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
							'selectors' => array( '{{WRAPPER}} .mb-modalbox__wrapper-btn' => 'background-color: {{VALUE}};' ),
						)
					);

				$this->end_controls_tab();

				$this->start_controls_tab(
					'mb_controls_tab_hover',
					array(
						'label' => esc_html__( 'Hover', 'eac-components' ),
					)
				);

					$this->add_control(
						'mb_button_color_hover',
						array(
							'label'     => esc_html__( 'Color', 'eac-components' ),
							'type'      => Controls_Manager::COLOR,
							'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
							'selectors' => array(
								'{{WRAPPER}} .mb-modalbox__wrapper-btn:hover, {{WRAPPER}} .mb-modalbox__wrapper-btn:focus' => 'color: {{VALUE}};',
								'{{WRAPPER}} .mb-modalbox__wrapper-btn:hover svg, {{WRAPPER}} .mb-modalbox__wrapper-btn:focus svg' => 'fill: {{VALUE}};',
							),
						)
					);

					$this->add_control(
						'mb_button_background_hover',
						array(
							'label'     => esc_html__( 'Background color', 'eac-components' ),
							'type'      => Controls_Manager::COLOR,
							'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
							'selectors' => array(
								'{{WRAPPER}} .mb-modalbox__wrapper-btn:hover, {{WRAPPER}} .mb-modalbox__wrapper-btn:focus' => 'background-color: {{VALUE}};',
							),
						)
					);

					$this->add_control(
						'mb_button_border_color_hover',
						array(
							'label'     => esc_html__( 'Border color', 'eac-components' ),
							'type'      => Controls_Manager::COLOR,
							'condition' => array( 'mb_button_border_border!' => 'none' ),
							'selectors' => array(
								'{{WRAPPER}} .mb-modalbox__wrapper-btn:hover, {{WRAPPER}} .mb-modalbox__wrapper-btn:focus' => 'border-color: {{VALUE}};',
							),
						)
					);

				$this->end_controls_tab();

			$this->end_controls_tabs();

			$this->add_group_control(
				Group_Control_Border::get_type(),
				array(
					'name'      => 'mb_button_border',
					'selector'  => '{{WRAPPER}} .mb-modalbox__wrapper-btn',
					'separator' => 'before',
				)
			);

			$this->add_control(
				'mb_button_radius',
				array(
					'label'              => esc_html__( 'Border radius', 'eac-components' ),
					'type'               => Controls_Manager::DIMENSIONS,
					'size_units'         => array( 'px', '%' ),
					'allowed_dimensions' => array( 'top', 'right', 'bottom', 'left' ),
					'default'            => array(
						'top'      => 8,
						'right'    => 8,
						'bottom'   => 8,
						'left'     => 8,
						'unit'     => 'px',
						'isLinked' => true,
					),
					'selectors'          => array(
						'{{WRAPPER}} .mb-modalbox__wrapper-btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					),
				)
			);

			$this->add_responsive_control(
				'mb_button_padding',
				array(
					'label'     => esc_html__( 'Padding', 'eac-components' ),
					'type'      => Controls_Manager::DIMENSIONS,
					'selectors' => array(
						'{{WRAPPER}} .mb-modalbox__wrapper-btn' => 'padding-block: {{TOP}}{{UNIT}} {{BOTTOM}}{{UNIT}}; padding-inline: {{LEFT}}{{UNIT}} {{RIGHT}}{{UNIT}};',
					),
				)
			);

			$this->add_group_control(
				Group_Control_Box_Shadow::get_type(),
				array(
					'name'     => 'mb_button_shadow',
					'label'    => esc_html__( 'Shadow', 'eac-components' ),
					'selector' => '{{WRAPPER}} .mb-modalbox__wrapper-btn',
				)
			);

		$this->end_controls_section();

		$this->start_controls_section(
			'mb_image_style',
			array(
				'label'     => esc_html__( 'Trigger image', 'eac-components' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'mb_origin_trigger' => 'image' ),
			)
		);

			$this->start_controls_tabs( 'mb_image_style_normal' );

				$this->start_controls_tab(
					'mb_image_tab_style_normal',
					array(
						'label' => esc_html__( 'Normal', 'eac-components' ),
					)
				);

					$this->add_control(
						'mb_image_padding',
						array(
							'label'      => esc_html__( 'Padding', 'eac-components' ),
							'type'       => Controls_Manager::DIMENSIONS,
							'size_units' => array( 'px', 'em' ),
							'default'    => array(
								'unit'   => 'px',
								'top'    => 5,
								'right'  => 5,
								'bottom' => 5,
								'left'   => 5,
							),
							'selectors'  => array(
								'{{WRAPPER}} .mb-modalbox__wrapper' => 'padding-block: {{TOP}}{{UNIT}} {{BOTTOM}}{{UNIT}}; padding-inline: {{LEFT}}{{UNIT}} {{RIGHT}}{{UNIT}};',
							),
						)
					);

					$this->add_group_control(
						Group_Control_Border::get_type(),
						array(
							'name'     => 'mb_image_border',
							'selector' => '{{WRAPPER}} .mb-modalbox__wrapper-img',
						)
					);

					$this->add_control(
						'mb_image_radius',
						array(
							'label'              => esc_html__( 'Border radius', 'eac-components' ),
							'type'               => Controls_Manager::DIMENSIONS,
							'size_units'         => array( 'px', '%' ),
							'allowed_dimensions' => array( 'top', 'right', 'bottom', 'left' ),
							'selectors'          => array(
								'{{WRAPPER}} .mb-modalbox__wrapper-img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
							),
						)
					);

					$this->add_group_control(
						Group_Control_Box_Shadow::get_type(),
						array(
							'name'     => 'mb_image_shadow',
							'label'    => esc_html__( 'Shadow', 'eac-components' ),
							'selector' => '{{WRAPPER}} .mb-modalbox__wrapper-img',
						)
					);

				$this->end_controls_tab();

				$this->start_controls_tab(
					'mb_image_tab_style_hover',
					array(
						'label' => esc_html__( 'Hover', 'eac-components' ),
					)
				);

					$this->add_control(
						'mb_image_opacity_hover',
						array(
							'label'     => esc_html__( 'Opacity', 'eac-components' ),
							'type'      => Controls_Manager::SLIDER,
							'default'   => array( 'size' => 0.2 ),
							'range'     => array(
								'px' => array(
									'max'  => 1,
									'min'  => 0.1,
									'step' => 0.1,
								),
							),
							'selectors' => array(
								'{{WRAPPER}} .mb-modalbox__wrapper-img:hover, {{WRAPPER}} .mb-modalbox__wrapper-img:focus' => 'opacity: {{SIZE}};',
							),
						)
					);

					$this->add_group_control(
						Group_Control_Css_Filter::get_type(),
						array(
							'name'     => 'mb_image_css_filters_hover',
							'selector' => '{{WRAPPER}} .mb-modalbox__wrapper-img:hover, {{WRAPPER}} .mb-modalbox__wrapper-img:focus',
						)
					);

					$this->add_control(
						'mb_image_hover_animation',
						array(
							'label' => esc_html__( 'Animation', 'eac-components' ),
							'type'  => Controls_Manager::HOVER_ANIMATION,
						)
					);

				$this->end_controls_tab();

			$this->end_controls_tabs();

		$this->end_controls_section();

		$this->start_controls_section(
			'mb_texte_style',
			array(
				'label'     => esc_html__( 'Trigger text', 'eac-components' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'mb_origin_trigger' => 'text' ),
			)
		);

			$this->add_control(
				'mb_texte_color',
				array(
					'label'     => esc_html__( 'Color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
					'default'   => '#000',
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__wrapper-text' => 'color: {{VALUE}} !important;' ),
				)
			);

			$this->add_group_control(
				Group_Control_Typography::get_type(),
				array(
					'name'     => 'mb_texte_typography',
					'label'    => esc_html__( 'Typography', 'eac-components' ),
					'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_TEXT ),
					'selector' => '{{WRAPPER}} .mb-modalbox__wrapper-text',
				)
			);

			$this->add_control(
				'mb_texte_background',
				array(
					'label'     => esc_html__( 'Background color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'global'    => array( 'default' => Global_Colors::COLOR_SECONDARY ),
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__wrapper-text' => 'background-color: {{VALUE}};' ),
				)
			);

			$this->add_control(
				'mb_texte_marges',
				array(
					'label'     => esc_html__( 'Margin', 'eac-components' ),
					'type'      => Controls_Manager::DIMENSIONS,
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__wrapper-text' => 'margin-block: {{TOP}}{{UNIT}} {{BOTTOM}}{{UNIT}}; margin-inline: {{LEFT}}{{UNIT}}  {{RIGHT}}{{UNIT}};' ),
				)
			);

		$this->end_controls_section();

		$this->start_controls_section(
			'mb_legende_style',
			array(
				'label'     => esc_html__( 'Image caption', 'eac-components' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array(
					'mb_origin_trigger' => 'image',
					'mb_caption_source' => 'custom',
				),
			)
		);

			$this->add_control(
				'mb_legende_margin',
				array(
					'label'      => esc_html__( 'Margin top', 'eac-components' ),
					'type'       => Controls_Manager::SLIDER,
					'size_units' => array( 'em', 'px' ),
					'default'    => array(
						'size' => 1,
						'unit' => 'em',
					),
					'range'      => array(
						'em' => array(
							'min'  => 0,
							'max'  => 5,
							'step' => 0.1,
						),
						'px' => array(
							'min'  => 0,
							'max'  => 100,
							'step' => 5,
						),
					),
					'selectors'  => array( '{{WRAPPER}} .mb-modalbox__wrapper figure figcaption' => 'padding-block-start: {{SIZE}}{{UNIT}};' ),
				)
			);

			$this->add_control(
				'mb_legende_color',
				array(
					'label'     => esc_html__( 'Color', 'eac-components' ),
					'type'      => Controls_Manager::COLOR,
					'separator' => 'none',
					'selectors' => array( '{{WRAPPER}} .mb-modalbox__wrapper figure figcaption' => 'color: {{VALUE}};' ),
					'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
				)
			);

			$this->add_group_control(
				Group_Control_Typography::get_type(),
				array(
					'name'     => 'mb_legende_typography',
					'label'    => esc_html__( 'Typography', 'eac-components' ),
					'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_TEXT ),
					'selector' => '{{WRAPPER}} .mb-modalbox__wrapper figure figcaption',
				)
			);

		$this->end_controls_section();
	}

	/**
	 * Render widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @access protected
	 */
	protected function render(): void {
		?>
		<div class='eac-modal-box'>
			<?php
			$this->render_modal();
			?>
		</div>
		<?php
	}

	/**
	 * Render widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @access protected
	 */
	protected function render_modal(): void {
		$settings = $this->get_settings_for_display();
		/**highlight_string("<?php\n\$settings =\n" . var_export($settings, true) . ";\n?>");*/
		$trigger     = $settings['mb_origin_trigger'];
		$content     = $settings['mb_type_content'];
		$link_url    = ! empty( $settings['mb_url_content']['url'] ) ? $settings['mb_url_content']['url'] : false;
		$short_code  = $settings['mb_shortcode_content'];
		$tmplcont    = $settings['mb_tmpl_cont_content'];
		$tmplsec     = $settings['mb_tmpl_sec_content'];
		$tmplpage    = $settings['mb_tmpl_page_content'];
		$icon_button = false;
		$type_inline = false;
		$header      = 'yes' === $settings['mb_enable_header'] && ! empty( $settings['mb_texte_header'] ) ? esc_html( $settings['mb_texte_header'] ) : '';
		$slideclass  = '';

		// Quelques tests
		if ( ( ( 'links' === $content || 'html' === $content ) && ! $link_url ) || ( 'formulaire' === $content && empty( $short_code ) ) || ( 'tmpl_cont' === $content && empty( $tmplcont ) ) || ( 'tmpl_sec' === $content && empty( $tmplsec ) ) || ( 'tmpl_page' === $content && empty( $tmplpage ) ) ) {
			return;
		}

		/**
		 * ID principal du document voir "data-elementor-id" class de la div section
		 * peut être différent de l'ID du post courant get_the_ID() de WP
		 * Si le post a été créé dans un template, il faut conserver ID du template
		 * pour que le CSS défini soit bien appliqué au widget
		 */
		$main_id = get_the_ID();
		if ( \Elementor\Plugin::$instance->documents->get_current() !== null ) {
			$main_id = \Elementor\Plugin::$instance->documents->get_current()->get_main_id();
		}

		// Unique ID du widget
		$id = $this->get_id();

		/** Le déclencheur */
		$label = '';

		if ( 'button' === $trigger ) {
			if ( 'yes' === $settings['mb_icon_activated'] && ! empty( $settings['mb_display_icon_button'] ) ) {
				$icon_button = true;
			}
			$label = $settings['mb_display_text_button'];
			$this->add_render_attribute( 'trigger', 'type', 'button' );
			$this->add_render_attribute( 'trigger', 'id', 'mb_labelby_' . esc_attr( $id ) );
			$this->add_render_attribute( 'trigger', 'class', 'mb-modalbox__wrapper-trigger mb-modalbox__wrapper-btn' );
			$this->add_render_attribute( 'trigger', 'tabindex', '-1' );
		} elseif ( 'image' === $trigger ) {
			$image_alt = '';
			$img_class = 'mb-modalbox__wrapper-trigger mb-modalbox__wrapper-img';
			if ( '' !== $settings['mb_image_hover_animation'] ) {
				$img_class = $img_class . ' elementor-animation-' . $settings['mb_image_hover_animation'];
			}
			$this->add_render_attribute( 'trigger', 'class', $img_class );

			// Image vient de la lib des médias. ID existe
			if ( ! empty( $settings['mb_display_image']['id'] ) ) {
				$image = wp_get_attachment_image_src( $settings['mb_display_image']['id'], $settings['mb_image_dimension'] );
				if ( $image ) {
					$this->add_render_attribute( 'trigger', 'src', esc_url( $image[0] ) );
					$this->add_render_attribute( 'trigger', 'width', absint( $image[1] ) );
					$this->add_render_attribute( 'trigger', 'height', absint( $image[2] ) );
					$image_alt = Control_Media::get_image_alt( $settings['mb_display_image'] );
				}
			} elseif ( ! empty( $settings['mb_display_image']['url'] ) ) { // Image externe
				$this->add_render_attribute( 'trigger', 'src', esc_url( $settings['mb_display_image']['url'] ) );
			}
			$this->add_render_attribute( 'trigger', 'alt', esc_attr( $image_alt ) );

			$has_caption = ! empty( $settings['mb_caption_source'] ) && 'none' !== $settings['mb_caption_source'] ? true : false;
			if ( $has_caption ) {
				if ( 'attachment' === $settings['mb_caption_source'] && ! empty( $settings['mb_display_image']['id'] ) ) {
					$label = wp_get_attachment_caption( $settings['mb_display_image']['id'] );
				} else {
					$label = ! empty( $settings['mb_caption_texte'] ) ? $settings['mb_caption_texte'] : '';
				}
			}
		} elseif ( 'text' === $trigger ) {
			$label = $settings['mb_display_texte'];
			$this->add_render_attribute( 'trigger', 'id', 'mb_labelby_' . esc_attr( $id ) );
			$this->add_render_attribute( 'trigger', 'class', 'mb-modalbox__wrapper-trigger mb-modalbox__wrapper-text' );
			$this->add_render_attribute( 'trigger', 'title', esc_attr( $settings['mb_display_texte'] ) );
		}

		/** Les attributs de la Fancybox */
		$this->add_render_attribute( 'a_fancybox', 'data-fancybox', '' );
		$this->add_render_attribute( 'a_fancybox', 'class', 'eac-accessible-link' );
		$this->add_render_attribute( 'a_fancybox', 'role', 'button' );
		$this->add_render_attribute( 'a_fancybox', 'aria-expanded', 'false' );
		$this->add_render_attribute( 'a_fancybox', 'aria-controls', 'modalbox-hidden-' . esc_attr( $id ) );
		$this->add_render_attribute( 'a_fancybox', 'aria-haspopup', 'dialog' );
		$this->add_render_attribute( 'a_fancybox', 'aria-label', esc_attr__( 'Open modal box', 'eac-components' ) );

		if ( 'html' === $content ) {
			$slideclass = 'modalbox-visible-' . esc_attr( $id );
			$this->add_render_attribute( 'a_fancybox', 'href', '#' );
			$this->add_render_attribute(
				'a_fancybox',
				'data-options',
				wp_json_encode(
					array(
						'type'    => 'iframe',
						'caption' => esc_attr( $header ),
						'src'     => esc_url( $link_url ),
					)
				)
			);
		} elseif ( 'links' === $content ) {
			$slideclass = 'modalbox-visible-' . esc_attr( $id );
			$this->add_render_attribute( 'a_fancybox', 'href', esc_url( $link_url ) );
			$this->add_render_attribute(
				'a_fancybox',
				'data-options',
				wp_json_encode(
					array(
						'caption' => esc_attr( $header ),
					)
				)
			);
		} else {
			$type_inline = true;
			$this->add_render_attribute( 'a_fancybox', 'href', '#' );
			$this->add_render_attribute(
				'a_fancybox',
				'data-options',
				wp_json_encode(
					array(
						'type' => 'inline',
						'src'  => '#modalbox-hidden-' . esc_attr( $id ),
					)
				)
			);
		}

		// Le wrapper global du composant
		$this->add_render_attribute( 'mb_wrapper', 'class', 'mb-modalbox__wrapper' );
		$this->add_render_attribute( 'mb_wrapper', 'id', esc_attr( $id ) );
		$this->add_render_attribute( 'mb_wrapper', 'data-settings', $this->get_settings_json() );
		?>
		<div <?php $this->print_render_attribute_string( 'mb_wrapper' ); ?>>
			<?php if ( 'button' === $trigger ) { ?>
				<a <?php $this->print_render_attribute_string( 'a_fancybox' ); ?>>
					<button <?php $this->print_render_attribute_string( 'trigger' ); ?>>
						<?php
						if ( $icon_button && 'before' === $settings['mb_position_icon_button'] ) { ?>
							<span class='button-icon eac-icon-svg'>
							<?php Icons_Manager::render_icon( $settings['mb_display_icon_button'], array( 'aria-hidden' => 'true' ) ); ?>
							</span>
						<?php }
							echo '<span class="label-icon">' . esc_html( $label ) . '</span>';
						if ( $icon_button && 'after' === $settings['mb_position_icon_button'] ) { ?>
							<span class='button-icon eac-icon-svg'>
							<?php Icons_Manager::render_icon( $settings['mb_display_icon_button'], array( 'aria-hidden' => 'true' ) ); ?>
							</span>
						<?php } ?>
					</button>
				</a>
			<?php } elseif ( 'image' === $trigger ) { ?>
				<a <?php $this->print_render_attribute_string( 'a_fancybox' ); ?>>
					<?php if ( ! empty( $label ) ) { ?>
						<figure>
					<?php } ?>
						<img <?php $this->print_render_attribute_string( 'trigger' ); ?>>
						<?php if ( ! empty( $label ) ) { ?>
							<figcaption id="mb_labelby_<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $label ); ?></figcaption>
						<?php } ?>
					<?php if ( ! empty( $label ) ) { ?>
						</figure>
					<?php } ?>
				</a>
			<?php } elseif ( 'text' === $trigger ) { ?>
				<a <?php $this->print_render_attribute_string( 'a_fancybox' ); ?>>
					<div <?php $this->print_render_attribute_string( 'trigger' ); ?>><?php echo esc_html( $label ); ?></div>
				</a>
				<?php
			} else {
				$type_inline = true; // déclencheur automatique 'On page load'
			}
			?>

			<!-- Affichage en ligne pour les contenus 'automatique, texte, template, formulaire' -->
			<?php
			if ( $type_inline ) {
				ob_start();
				?>
				<div id="modalbox-hidden-<?php echo esc_attr( $id ); ?>" class="mb-modalbox__hidden-content-wrapper elementor-<?php echo esc_attr( $main_id ); ?>" role='dialog' aria-labelledby="modal-<?php echo esc_attr( $id ); ?>" aria-modal='true'>
					<div class="elementor-element elementor-element-<?php echo esc_attr( $id ); ?>">
						<div class='mb-modalbox__hidden-content-body-bg'></div>
						<div fancybox-title class='mb-modalbox__hidden-content-title'>
							<span id="modal-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $header ); ?></span>
						</div>
						<div fancybox-body class='mb-modalbox__hidden-content-body'>
							<?php
							if ( 'texte' === $content ) { ?>
								<div><?php echo wp_kses_post( $settings['mb_texte_content'] ); ?></div>
							<?php } elseif ( 'tmpl_cont' === $content ) {
								if ( get_the_ID() === (int) $tmplcont ) {
									esc_html_e( 'The Template ID cannot be the same as the currently edited template', 'eac-components' );
								} else {
									$tmplcont = apply_filters( 'wpml_object_id', $tmplcont, Source_Local::CPT, true );
									echo \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $tmplcont ); // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
								}
							} elseif ( 'tmpl_sec' === $content ) {
								if ( get_the_ID() === (int) $tmplsec ) {
									esc_html_e( 'The Template ID cannot be the same as the currently edited template', 'eac-components' );
								} else {
									// Filtre wpml
									$tmplsec = apply_filters( 'wpml_object_id', $tmplsec, Source_Local::CPT, true );
									echo \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $tmplsec ); // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
								}
							} elseif ( 'tmpl_page' === $content ) {
								if ( get_the_ID() === (int) $tmplpage ) {
									esc_html_e( 'The Template ID cannot be the same as the currently edited template', 'eac-components' );
								} else {
									// Filtre wpml
									$tmplpage = apply_filters( 'wpml_object_id', $tmplpage, Source_Local::CPT, true );
									echo \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $tmplpage ); // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
								}
							} elseif ( 'formulaire' === $content ) { // Exécute un shortcode
								echo do_shortcode( shortcode_unautop( $short_code ) );
							} else {
								esc_html_e( "'On page load' does not support HTML, Video or Map formats", 'eac-components' );
							}
							?>
						</div>
					</div>
				</div>
				<?php
				echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			}
			?>
		</div>
		<?php
	}

	/**
	 * get_settings_json
	 *
	 * Retrieve fields values to pass at the widget container
	 * Convert on JSON format
	 * Modification de la règles 'data_filtre'
	 *
	 * @uses wp_json_encode()
	 * @return JSON oject
	 * @access   protected
	 */
	protected function get_settings_json(): string {
		$settings = $this->get_settings_for_display();

		$module_settings = array(
			'data_id'         => esc_attr( $this->get_id() ),
			'data_trigger'    => $settings['mb_origin_trigger'],
			'data_delay'      => absint( $settings['mb_popup_delay'] ),
			'data_active'     => 'yes' === $settings['mb_popup_activated'] ? true : false,
			'data_effet'      => $settings['mb_modal_box_effect'],
			'data_position'   => $settings['mb_modal_box_position'],
			'data_duration'   => ! empty( $settings['mb_modal_box_duration'] ) ? absint( $settings['mb_modal_box_duration'] ) : 600,
			'data_modal'      => true,
			'data_slideclass' => 'modalbox-visible-' . esc_attr( $this->get_id() ),
		);

		return wp_json_encode( $module_settings );
	}

	protected function content_template(): void {}
}
