<?php
/**
 * Interactive Banner / Promo Banner element.
 *
 * A background image with an overlay and stacked content (eyebrow, title, copy
 * and a CTA), built for promos. The "interactive" part: the overlay shifts
 * opacity on hover, the image can zoom, and the copy + button can stay put or
 * reveal on hover. Combines the best of the competitors' banner widgets:
 * solid/gradient overlay with default + hover opacity, image zoom, content
 * reveal, a promo badge, full typography and a whole-banner or button link.
 *
 * @package CraftAddonsForWPBakery
 */

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

/**
 * Class CAFW_Element_Interactive_Banner
 */
class CAFW_Element_Interactive_Banner extends CAFW_Element_Base {

	/**
	 * {@inheritDoc}
	 */
	public function get_shortcode_tag() {
		return 'cafw_interactive_banner';
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_label() {
		return esc_html__( 'Interactive Banner', 'craft-addons-for-wpbakery' );
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_description() {
		return esc_html__( 'Promo banner with hover effects.', 'craft-addons-for-wpbakery' );
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_admin_icon() {
		return 'dashicons-format-image';
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_editor_icon() {
		return 'cafw-vc-icon cafw-vc-icon-interactive-banner';
	}

	/**
	 * {@inheritDoc}
	 */
	protected function get_defaults() {
		return array(
			'image'            => '',
			'badge'            => esc_html__( '-50%', 'craft-addons-for-wpbakery' ),
			'subtitle'         => esc_html__( 'Limited time offer', 'craft-addons-for-wpbakery' ),
			'title'            => esc_html__( 'Summer Sale', 'craft-addons-for-wpbakery' ),
			'text'             => esc_html__( 'Save big on our best-selling products. Hurry while stocks last.', 'craft-addons-for-wpbakery' ),
			'button_text'      => esc_html__( 'Shop now', 'craft-addons-for-wpbakery' ),
			'link'             => '',
			'link_whole'       => '',
			'height'           => '340',
			'content_position' => 'bottom',
			'align'            => 'left',
			'reveal'           => 'always',
			'img_hover'        => 'zoom',
			'overlay_type'     => 'gradient',
			'overlay_color'    => '#1f1147',
			'overlay_color2'   => '#502bf8',
			'overlay_opacity'  => '55',
			'overlay_hover'    => '70',
			'badge_position'   => 'top-left',
			'badge_bg'         => '#502bf8',
			'badge_color'      => '#ffffff',
			'subtitle_color'   => '#ffd5e8',
			'text_color'       => '#f3f0ff',
			'btn_bg'           => '#ffffff',
			'btn_color'        => '#1f1147',
			'btn_hover_bg'     => '#502bf8',
			'btn_hover_color'  => '#ffffff',
			'btn_radius'       => '8',
			'radius'           => '16',
			'title_font'       => '',
			'title_google_font' => '',
			'text_font'        => '',
			'text_google_font' => '',
		);
	}

	/**
	 * Resolve the link to a url/target/rel array.
	 *
	 * @param array $atts Shortcode atts.
	 * @return array{url:string,target:string,rel:string}
	 */
	private function get_link( $atts ) {
		$out = array(
			'url'    => '',
			'target' => '',
			'rel'    => '',
		);
		if ( '' !== $atts['link'] && function_exists( 'vc_build_link' ) ) {
			$link          = vc_build_link( $atts['link'] );
			$out['url']    = isset( $link['url'] ) ? $link['url'] : '';
			$out['target'] = ( isset( $link['target'] ) && '' !== $link['target'] ) ? '_blank' : '';
			$out['rel']    = ( isset( $link['rel'] ) && '' !== $link['rel'] ) ? $link['rel'] : '';
		}
		return $out;
	}

	/**
	 * Build the href/target/rel attribute string.
	 *
	 * @param array $link Link array.
	 * @return string
	 */
	private function link_attrs( $link ) {
		$out = ' href="' . esc_url( $link['url'] ) . '"';
		if ( '' !== $link['target'] ) {
			$out .= ' target="_blank"';
		}
		$rel = trim( $link['rel'] . ( '' !== $link['target'] ? ' noopener' : '' ) );
		if ( '' !== $rel ) {
			$out .= ' rel="' . esc_attr( $rel ) . '"';
		}
		return $out;
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_params() {
		$styles = esc_html__( 'Styles', 'craft-addons-for-wpbakery' );

		return array_merge(
			array(
				array(
					'type'       => 'attach_image',
					'heading'    => esc_html__( 'Background image', 'craft-addons-for-wpbakery' ),
					'param_name' => 'image',
				),
				array(
					'type'        => 'textfield',
					'heading'     => esc_html__( 'Eyebrow', 'craft-addons-for-wpbakery' ),
					'param_name'  => 'subtitle',
					'value'       => esc_html__( 'Limited time offer', 'craft-addons-for-wpbakery' ),
					'description' => esc_html__( 'Small line above the title.', 'craft-addons-for-wpbakery' ),
				),
				array(
					'type'        => 'textfield',
					'heading'     => esc_html__( 'Title', 'craft-addons-for-wpbakery' ),
					'param_name'  => 'title',
					'value'       => esc_html__( 'Summer Sale', 'craft-addons-for-wpbakery' ),
					'admin_label' => true,
				),
				array(
					'type'       => 'textarea',
					'heading'    => esc_html__( 'Text', 'craft-addons-for-wpbakery' ),
					'param_name' => 'text',
					'value'      => esc_html__( 'Save big on our best-selling products. Hurry while stocks last.', 'craft-addons-for-wpbakery' ),
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Button text', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'button_text',
					'value'            => esc_html__( 'Shop now', 'craft-addons-for-wpbakery' ),
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Badge', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'badge',
					'value'            => esc_html__( '-50%', 'craft-addons-for-wpbakery' ),
					'description'      => esc_html__( 'Optional promo tag. Leave empty to hide.', 'craft-addons-for-wpbakery' ),
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'       => 'vc_link',
					'heading'    => esc_html__( 'Link', 'craft-addons-for-wpbakery' ),
					'param_name' => 'link',
				),
				array(
					'type'        => 'checkbox',
					'heading'     => esc_html__( 'Link the whole banner', 'craft-addons-for-wpbakery' ),
					'param_name'  => 'link_whole',
					'value'       => array( esc_html__( 'Yes', 'craft-addons-for-wpbakery' ) => 'yes' ),
					'description' => esc_html__( 'Make the entire banner clickable (the button is then decorative).', 'craft-addons-for-wpbakery' ),
				),
				array(
					'type'             => 'cafw_layout',
					'heading'          => esc_html__( 'Content position', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'content_position',
					'std'              => 'bottom',
					'options'          => array(
						'top'    => array(
							'label' => esc_html__( 'Top', 'craft-addons-for-wpbakery' ),
							'thumb' => $this->pos_thumb( 'top' ),
						),
						'center' => array(
							'label' => esc_html__( 'Center', 'craft-addons-for-wpbakery' ),
							'thumb' => $this->pos_thumb( 'center' ),
						),
						'bottom' => array(
							'label' => esc_html__( 'Bottom', 'craft-addons-for-wpbakery' ),
							'thumb' => $this->pos_thumb( 'bottom' ),
						),
					),
				),
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Alignment', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'align',
					'value'            => array(
						esc_html__( 'Left', 'craft-addons-for-wpbakery' )   => 'left',
						esc_html__( 'Center', 'craft-addons-for-wpbakery' ) => 'center',
						esc_html__( 'Right', 'craft-addons-for-wpbakery' )  => 'right',
					),
					'std'              => 'left',
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Reveal text & button', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'reveal',
					'value'            => array(
						esc_html__( 'Always show', 'craft-addons-for-wpbakery' )  => 'always',
						esc_html__( 'Reveal on hover', 'craft-addons-for-wpbakery' ) => 'hover',
					),
					'std'              => 'always',
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				// ---- Styles: banner ----
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Height (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'height',
					'value'            => '340',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Image hover', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'img_hover',
					'value'            => array(
						esc_html__( 'Zoom', 'craft-addons-for-wpbakery' ) => 'zoom',
						esc_html__( 'None', 'craft-addons-for-wpbakery' ) => 'none',
					),
					'std'              => 'zoom',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				// ---- Styles: overlay ----
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Overlay type', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'overlay_type',
					'value'            => array(
						esc_html__( 'Gradient', 'craft-addons-for-wpbakery' ) => 'gradient',
						esc_html__( 'Solid', 'craft-addons-for-wpbakery' )    => 'solid',
						esc_html__( 'None', 'craft-addons-for-wpbakery' )     => 'none',
					),
					'std'              => 'gradient',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Opacity (%)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'overlay_opacity',
					'value'            => '55',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'On hover (%)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'overlay_hover',
					'value'            => '70',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Overlay color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'overlay_color',
					'value'            => '#1f1147',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Overlay color 2 (gradient)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'overlay_color2',
					'value'            => '#502bf8',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				// ---- Styles: text colours ----
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Eyebrow color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'subtitle_color',
					'value'            => '#ffd5e8',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Text color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'text_color',
					'value'            => '#f3f0ff',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column cafw-bg-sep',
				),
				// ---- Styles: badge ----
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Badge position', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'badge_position',
					'value'            => array(
						esc_html__( 'Top left', 'craft-addons-for-wpbakery' )     => 'top-left',
						esc_html__( 'Top right', 'craft-addons-for-wpbakery' )    => 'top-right',
						esc_html__( 'Bottom left', 'craft-addons-for-wpbakery' )  => 'bottom-left',
						esc_html__( 'Bottom right', 'craft-addons-for-wpbakery' ) => 'bottom-right',
					),
					'std'              => 'top-left',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Badge background', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'badge_bg',
					'value'            => '#502bf8',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Badge color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'badge_color',
					'value'            => '#ffffff',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				// ---- Styles: button ----
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Button background', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'btn_bg',
					'value'            => '#ffffff',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Button text', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'btn_color',
					'value'            => '#1f1147',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Button bg (hover)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'btn_hover_bg',
					'value'            => '#502bf8',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Button text (hover)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'btn_hover_color',
					'value'            => '#ffffff',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-3 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Button radius (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'btn_radius',
					'value'            => '8',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Banner radius (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'radius',
					'value'            => '16',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
			),
			$this->typography_params(
				'title',
				esc_html__( 'Title', 'craft-addons-for-wpbakery' ),
				array(
					'tag' => true,
					'sep' => true,
				)
			),
			$this->typography_params( 'text', esc_html__( 'Text', 'craft-addons-for-wpbakery' ), array( 'sep' => true ) )
		);
	}

	/**
	 * Position-thumbnail for the content-position picker.
	 *
	 * @param string $pos Position key.
	 * @return string Inline SVG.
	 */
	private function pos_thumb( $pos ) {
		$ln = '#d8d5e4';
		$ac = '#502bf8';
		$y  = 'center' === $pos ? 16 : ( 'bottom' === $pos ? 26 : 6 );
		$inner = '<rect x="8" y="' . $y . '" width="26" height="4" rx="2" fill="' . $ln . '"/>'
			. '<rect x="8" y="' . ( $y + 7 ) . '" width="16" height="6" rx="3" fill="' . $ac . '"/>';
		return '<svg viewBox="0 0 60 42" width="60" height="42" xmlns="http://www.w3.org/2000/svg">'
			. '<rect width="60" height="42" rx="4" fill="#e9e6f4"/>' . $inner . '</svg>';
	}

	/**
	 * Append "px" to a numeric value, or '' when blank.
	 *
	 * @param mixed $value Raw value.
	 * @return string
	 */
	private function px( $value ) {
		$value = trim( (string) $value );
		if ( '' === $value || ! is_numeric( $value ) ) {
			return '';
		}
		return absint( $value ) . 'px';
	}

	/**
	 * Clamp a 0-100 percentage to a 0-1 opacity string.
	 *
	 * @param mixed $value Raw value.
	 * @param float $fallback Fallback 0-1.
	 * @return string
	 */
	private function opacity( $value, $fallback ) {
		$value = trim( (string) $value );
		if ( '' === $value || ! is_numeric( $value ) ) {
			return (string) $fallback;
		}
		$n = max( 0, min( 100, (float) $value ) );
		return (string) round( $n / 100, 2 );
	}

	/**
	 * {@inheritDoc}
	 */
	public function render( $atts, $content, $el_id ) {
		$position = in_array( $atts['content_position'], array( 'top', 'center', 'bottom' ), true ) ? $atts['content_position'] : 'bottom';
		$align    = in_array( $atts['align'], array( 'left', 'center', 'right' ), true ) ? $atts['align'] : 'left';
		$reveal   = ( 'hover' === $atts['reveal'] ) ? 'hover' : 'always';
		$ihover   = ( 'none' === $atts['img_hover'] ) ? 'none' : 'zoom';
		$ovtype   = in_array( $atts['overlay_type'], array( 'gradient', 'solid', 'none' ), true ) ? $atts['overlay_type'] : 'gradient';
		$badgepos = in_array( $atts['badge_position'], array( 'top-left', 'top-right', 'bottom-left', 'bottom-right' ), true ) ? $atts['badge_position'] : 'top-left';

		$title = (string) $atts['title'];
		$text  = (string) $atts['text'];
		$sub   = (string) $atts['subtitle'];
		$btn   = (string) $atts['button_text'];
		$badge = (string) $atts['badge'];

		// Overlay background (solid colour or a gradient of the two colours).
		$c1 = sanitize_hex_color( $atts['overlay_color'] );
		$c2 = sanitize_hex_color( $atts['overlay_color2'] );
		if ( 'gradient' === $ovtype && $c1 && $c2 ) {
			$overlay_bg = 'linear-gradient(160deg, ' . $c1 . ' 0%, ' . $c2 . ' 100%)';
		} elseif ( 'none' === $ovtype ) {
			$overlay_bg = 'transparent';
		} else {
			$overlay_bg = $c1 ? $c1 : '#1f1147';
		}

		$vars = array(
			'--cafw-bn-h'        => $this->px( $atts['height'] ),
			'--cafw-bn-radius'   => $this->px( $atts['radius'] ),
			'--cafw-bn-ov'       => $overlay_bg,
			'--cafw-bn-ov-op'    => 'none' === $ovtype ? '0' : $this->opacity( $atts['overlay_opacity'], 0.55 ),
			'--cafw-bn-ov-op-h'  => 'none' === $ovtype ? '0' : $this->opacity( $atts['overlay_hover'], 0.7 ),
			'--cafw-bn-sub'      => sanitize_hex_color( $atts['subtitle_color'] ),
			'--cafw-bn-text'     => sanitize_hex_color( $atts['text_color'] ),
			'--cafw-bn-badge-bg' => sanitize_hex_color( $atts['badge_bg'] ),
			'--cafw-bn-badge-c'  => sanitize_hex_color( $atts['badge_color'] ),
			'--cafw-bn-btn-bg'   => sanitize_hex_color( $atts['btn_bg'] ),
			'--cafw-bn-btn-c'    => sanitize_hex_color( $atts['btn_color'] ),
			'--cafw-bn-btn-bg-h' => sanitize_hex_color( $atts['btn_hover_bg'] ),
			'--cafw-bn-btn-c-h'  => sanitize_hex_color( $atts['btn_hover_color'] ),
			'--cafw-bn-btn-r'    => $this->px( $atts['btn_radius'] ),
		);
		$vars = array_filter(
			$vars,
			static function ( $v ) {
				return '' !== $v && null !== $v;
			}
		);

		$title_type = $this->part_typography( $atts, 'title' );
		$text_type  = $this->part_typography( $atts, 'text' );
		$title_tag  = in_array( $title_type['tag'], array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div' ), true ) ? $title_type['tag'] : 'h3';

		$classes = array(
			'cafw-banner',
			'cafw-banner--pos-' . $position,
			'cafw-banner--align-' . $align,
			'cafw-banner--reveal-' . $reveal,
			'cafw-banner--ihover-' . $ihover,
		);
		$dclass = CAFW_Element_Base::design_options_class( $atts );
		if ( $dclass ) {
			$classes[] = $dclass;
		}
		if ( '' !== trim( (string) $atts['el_class'] ) ) {
			$classes[] = $atts['el_class'];
		}

		$link        = $this->get_link( $atts );
		$has_link    = '' !== $link['url'];
		$whole       = $has_link && 'yes' === $atts['link_whole'];

		// Background image (or a soft placeholder while none is set).
		if ( absint( $atts['image'] ) > 0 ) {
			$media = wp_get_attachment_image( absint( $atts['image'] ), 'large', false, array( 'class' => 'cafw-banner__img' ) );
		} else {
			$media = '<span class="cafw-banner__img cafw-banner__img--placeholder" aria-hidden="true">'
				. '<svg viewBox="0 0 24 24" width="46" height="46" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>'
				. '</span>';
		}

		ob_start();
		?>
		<div id="<?php echo esc_attr( $el_id ); ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"<?php echo $this->style_attr( $vars ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- style_attr escapes internally. ?>>
			<div class="cafw-banner__media">
				<?php echo $media; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_get_attachment_image / static SVG. ?>
				<?php if ( 'none' !== $ovtype ) : ?>
					<span class="cafw-banner__overlay" aria-hidden="true"></span>
				<?php endif; ?>
			</div>

			<?php if ( '' !== trim( $badge ) ) : ?>
				<span class="cafw-banner__badge cafw-banner__badge--<?php echo esc_attr( $badgepos ); ?>"><?php echo esc_html( $badge ); ?></span>
			<?php endif; ?>

			<div class="cafw-banner__content">
				<?php if ( '' !== trim( $sub ) ) : ?>
					<span class="cafw-banner__sub"><?php echo esc_html( $sub ); ?></span>
				<?php endif; ?>
				<?php if ( '' !== trim( $title ) ) : ?>
					<<?php echo esc_attr( $title_tag ); ?> class="cafw-banner__title"<?php echo $this->style_attr( $title_type['styles'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escapes internally. ?>><?php echo esc_html( $title ); ?></<?php echo esc_attr( $title_tag ); ?>>
				<?php endif; ?>
				<?php if ( '' !== trim( $text ) ) : ?>
					<div class="cafw-banner__text"<?php echo $this->style_attr( $text_type['styles'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escapes internally. ?>><?php echo wp_kses_post( wpautop( $text ) ); ?></div>
				<?php endif; ?>
				<?php if ( '' !== trim( $btn ) ) : ?>
					<?php if ( $has_link && ! $whole ) : ?>
						<a class="cafw-banner__btn"<?php echo $this->link_attrs( $link ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escapes internally. ?>><?php echo esc_html( $btn ); ?></a>
					<?php else : ?>
						<span class="cafw-banner__btn"><?php echo esc_html( $btn ); ?></span>
					<?php endif; ?>
				<?php endif; ?>
			</div>

			<?php if ( $whole ) : ?>
				<a class="cafw-banner__link"<?php echo $this->link_attrs( $link ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escapes internally. ?>><span class="screen-reader-text"><?php echo esc_html( '' !== trim( $title ) ? $title : $btn ); ?></span></a>
			<?php endif; ?>
		</div>
		<?php
		return ob_get_clean();
	}
}
