<?php
/**
 * Widget Name: Blockquote
 * Description: A professional, fully customizable blockquote / pull-quote widget with
 *              selectable visual styles, decorative quote icon, author block ( avatar,
 *              name, role ) and an optional source citation link. Only the selected
 *              style CSS file is loaded on the frontend.
 *
 * @package    captain-widgets-kit
 * @subpackage captain-widgets-kit/includes
 * @since      1.3.0
 */

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

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Background;
use Elementor\Icons_Manager;
use Elementor\Utils;

/**
 * Class Captwiki_Blockquote
 *
 * @since 1.3.0
 */
class Captwiki_Blockquote extends Widget_Base {

	/**
	 * Get widget name.
	 *
	 * @since 1.3.0
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-blockquote';
	}

	/**
	 * Get widget title.
	 *
	 * @since 1.3.0
	 * @return string
	 */
	public function get_title(): string {
		return esc_html__( 'Blockquote', 'captain-widgets-kit' );
	}

	/**
	 * Get widget icon.
	 *
	 * @since 1.3.0
	 * @return string
	 */
	public function get_icon(): string {
		return 'eicon-blockquote captwiki-el-logo';
	}

	/**
	 * Get widget categories.
	 *
	 * @since 1.3.0
	 * @return array
	 */
	public function get_categories(): array {
		return array( 'captwiki-essential' );
	}

	/**
	 * Get widget keywords.
	 *
	 * @since 1.3.0
	 * @return array
	 */
	public function get_keywords(): array {
		return array( 'blockquote', 'quote', 'pullquote', 'testimonial', 'citation', 'captain-widgets-kit' );
	}

	/**
	 * Common stylesheet dependency.
	 *
	 * @since 1.3.0
	 * @return array
	 */
	public function get_style_depends(): array {
		return array( 'captwiki_blockquote' );
	}

	/**
	 * Disable Elementor's default inner wrapper.
	 *
	 * @since 1.3.0
	 * @return bool
	 */
	public function has_widget_inner_wrapper(): bool {
		return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
	}

	/**
	 * Selectable visual styles.
	 *
	 * @since 1.3.0
	 * @return array
	 */
	private function captwiki_style_options(): array {
		return array(
			'style-1' => esc_html__( 'Style 1 – Classic Border', 'captain-widgets-kit' ),
			'style-2' => esc_html__( 'Style 2 – Elevated Card', 'captain-widgets-kit' ),
			'style-3' => esc_html__( 'Style 3 – Modern Mark', 'captain-widgets-kit' ),
			'style-4' => esc_html__( 'Style 4 – Soft Highlight', 'captain-widgets-kit' ),
			'style-5' => esc_html__( 'Style 5 – Centered Minimal', 'captain-widgets-kit' ),
		);
	}

	/**
	 * Register widget controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	protected function register_controls(): void {
		$this->register_content_controls();
		$this->register_author_controls();
		$this->register_general_style_controls();
		$this->register_quote_style_controls();
		$this->register_icon_style_controls();
		$this->register_author_style_controls();
	}

	/**
	 * Content tab — quote controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	private function register_content_controls(): void {

		$this->start_controls_section(
			'section_quote_content',
			array(
				'label' => esc_html__( 'Quote', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'widget_style',
			array(
				'label'   => esc_html__( 'Style', 'captain-widgets-kit' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'style-1',
				'options' => $this->captwiki_style_options(),
			)
		);

		$this->add_control(
			'quote_text',
			array(
				'label'       => esc_html__( 'Quote Text', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXTAREA,
				'rows'        => 5,
				'default'     => esc_html__( 'Design is not just what it looks like and feels like. Design is how it works — every detail matters when you build for people.', 'captain-widgets-kit' ),
				'placeholder' => esc_html__( 'Enter your quote', 'captain-widgets-kit' ),
				'dynamic'     => array( 'active' => true ),
			)
		);

		$this->add_control(
			'show_icon',
			array(
				'label'        => esc_html__( 'Show Quote Icon', 'captain-widgets-kit' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'captain-widgets-kit' ),
				'label_off'    => esc_html__( 'Hide', 'captain-widgets-kit' ),
				'return_value' => 'yes',
				'default'      => 'yes',
			)
		);

		$this->add_control(
			'quote_icon',
			array(
				'label'            => esc_html__( 'Icon', 'captain-widgets-kit' ),
				'type'             => Controls_Manager::ICONS,
				'fa4compatibility' => 'icon',
				'default'          => array(
					'value'   => 'fas fa-quote-left',
					'library' => 'fa-solid',
				),
				'skin'             => 'inline',
				'label_block'      => false,
				'condition'        => array( 'show_icon' => 'yes' ),
			)
		);

		$this->add_control(
			'citation_text',
			array(
				'label'       => esc_html__( 'Source / Citation', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => '',
				'placeholder' => esc_html__( 'e.g. The Design Handbook', 'captain-widgets-kit' ),
				'label_block' => true,
				'dynamic'     => array( 'active' => true ),
				'description' => esc_html__( 'Optional source shown after the author block.', 'captain-widgets-kit' ),
			)
		);

		$this->add_control(
			'citation_url',
			array(
				'label'         => esc_html__( 'Source Link', 'captain-widgets-kit' ),
				'type'          => Controls_Manager::URL,
				'placeholder'   => esc_html__( 'https://your-link.com', 'captain-widgets-kit' ),
				'show_external' => true,
				'dynamic'       => array( 'active' => true ),
				'condition'     => array( 'citation_text!' => '' ),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Content tab — author controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	private function register_author_controls(): void {

		$this->start_controls_section(
			'section_author_content',
			array(
				'label' => esc_html__( 'Author', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);

		$this->add_control(
			'show_author',
			array(
				'label'        => esc_html__( 'Show Author', 'captain-widgets-kit' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'captain-widgets-kit' ),
				'label_off'    => esc_html__( 'Hide', 'captain-widgets-kit' ),
				'return_value' => 'yes',
				'default'      => 'yes',
			)
		);

		$this->add_control(
			'author_name',
			array(
				'label'       => esc_html__( 'Name', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Steve Jobs', 'captain-widgets-kit' ),
				'placeholder' => esc_html__( 'Author name', 'captain-widgets-kit' ),
				'label_block' => true,
				'dynamic'     => array( 'active' => true ),
				'condition'   => array( 'show_author' => 'yes' ),
			)
		);

		$this->add_control(
			'author_role',
			array(
				'label'       => esc_html__( 'Role / Title', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Co-founder, Apple Inc.', 'captain-widgets-kit' ),
				'placeholder' => esc_html__( 'Role or company', 'captain-widgets-kit' ),
				'label_block' => true,
				'dynamic'     => array( 'active' => true ),
				'condition'   => array( 'show_author' => 'yes' ),
			)
		);

		$this->add_control(
			'show_avatar',
			array(
				'label'        => esc_html__( 'Show Avatar', 'captain-widgets-kit' ),
				'type'         => Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'captain-widgets-kit' ),
				'label_off'    => esc_html__( 'Hide', 'captain-widgets-kit' ),
				'return_value' => 'yes',
				'default'      => 'yes',
				'condition'    => array( 'show_author' => 'yes' ),
			)
		);

		$this->add_control(
			'author_image',
			array(
				'label'     => esc_html__( 'Avatar', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::MEDIA,
				'default'   => array(
					'url' => Utils::get_placeholder_image_src(),
				),
				'dynamic'   => array( 'active' => true ),
				'condition' => array(
					'show_author' => 'yes',
					'show_avatar' => 'yes',
				),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * General (wrapper) style controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	private function register_general_style_controls(): void {

		$this->start_controls_section(
			'section_general_style',
			array(
				'label' => esc_html__( 'General', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_responsive_control(
			'alignment',
			array(
				'label'     => esc_html__( 'Alignment', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'left'   => array(
						'title' => esc_html__( 'Left', 'captain-widgets-kit' ),
						'icon'  => 'eicon-text-align-left',
					),
					'center' => array(
						'title' => esc_html__( 'Center', 'captain-widgets-kit' ),
						'icon'  => 'eicon-text-align-center',
					),
					'right'  => array(
						'title' => esc_html__( 'Right', 'captain-widgets-kit' ),
						'icon'  => 'eicon-text-align-right',
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .captwiki-blockquote' => 'text-align: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'wrapper_background',
				'label'    => esc_html__( 'Background', 'captain-widgets-kit' ),
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .captwiki-blockquote',
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'wrapper_border',
				'label'    => esc_html__( 'Border', 'captain-widgets-kit' ),
				'selector' => '{{WRAPPER}} .captwiki-blockquote',
			)
		);

		$this->add_responsive_control(
			'wrapper_border_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'wrapper_box_shadow',
				'label'    => esc_html__( 'Box Shadow', 'captain-widgets-kit' ),
				'selector' => '{{WRAPPER}} .captwiki-blockquote',
			)
		);

		$this->add_responsive_control(
			'wrapper_padding',
			array(
				'label'      => esc_html__( 'Padding', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em', 'rem' ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'wrapper_margin',
			array(
				'label'      => esc_html__( 'Margin', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em', 'rem' ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'accent_color',
			array(
				'label'     => esc_html__( 'Accent Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-blockquote' => '--captwiki-bq-accent: {{VALUE}};',
				),
				'description' => esc_html__( 'Drives the border / highlight accent used by each style.', 'captain-widgets-kit' ),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Quote text style controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	private function register_quote_style_controls(): void {

		$this->start_controls_section(
			'section_quote_style',
			array(
				'label' => esc_html__( 'Quote Text', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_control(
			'quote_color',
			array(
				'label'     => esc_html__( 'Text Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-blockquote__text' => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'quote_typography',
				'selector' => '{{WRAPPER}} .captwiki-blockquote__text',
			)
		);

		$this->add_group_control(
			Group_Control_Text_Shadow::get_type(),
			array(
				'name'     => 'quote_text_shadow',
				'label'    => esc_html__( 'Text Shadow', 'captain-widgets-kit' ),
				'selector' => '{{WRAPPER}} .captwiki-blockquote__text',
			)
		);

		$this->add_responsive_control(
			'quote_spacing',
			array(
				'label'      => esc_html__( 'Bottom Spacing', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 80 ) ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote__text' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Quote icon style controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	private function register_icon_style_controls(): void {

		$this->start_controls_section(
			'section_icon_style',
			array(
				'label'     => esc_html__( 'Quote Icon', 'captain-widgets-kit' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'show_icon' => 'yes' ),
			)
		);

		$this->add_control(
			'icon_color',
			array(
				'label'     => esc_html__( 'Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-blockquote__icon'     => 'color: {{VALUE}};',
					'{{WRAPPER}} .captwiki-blockquote__icon svg' => 'fill: {{VALUE}};',
				),
			)
		);

		$this->add_responsive_control(
			'icon_size',
			array(
				'label'      => esc_html__( 'Size', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em' ),
				'range'      => array(
					'px' => array( 'min' => 10, 'max' => 160, 'step' => 1 ),
					'em' => array( 'min' => 0.5, 'max' => 10, 'step' => 0.1 ),
				),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote__icon' => 'font-size: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'icon_spacing',
			array(
				'label'      => esc_html__( 'Spacing', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 60 ) ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote__icon' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Author block style controls.
	 *
	 * @since 1.3.0
	 * @return void
	 */
	private function register_author_style_controls(): void {

		$this->start_controls_section(
			'section_author_style',
			array(
				'label'     => esc_html__( 'Author', 'captain-widgets-kit' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'show_author' => 'yes' ),
			)
		);

		$this->add_control(
			'name_heading',
			array(
				'label'     => esc_html__( 'Name', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);

		$this->add_control(
			'name_color',
			array(
				'label'     => esc_html__( 'Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-blockquote__author' => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'name_typography',
				'selector' => '{{WRAPPER}} .captwiki-blockquote__author',
			)
		);

		$this->add_control(
			'role_heading',
			array(
				'label'     => esc_html__( 'Role / Title', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);

		$this->add_control(
			'role_color',
			array(
				'label'     => esc_html__( 'Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-blockquote__role' => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'role_typography',
				'selector' => '{{WRAPPER}} .captwiki-blockquote__role',
			)
		);

		$this->add_control(
			'avatar_heading',
			array(
				'label'     => esc_html__( 'Avatar', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
				'condition' => array( 'show_avatar' => 'yes' ),
			)
		);

		$this->add_responsive_control(
			'avatar_size',
			array(
				'label'      => esc_html__( 'Size', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array( 'px' => array( 'min' => 24, 'max' => 160, 'step' => 1 ) ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote__avatar' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
				),
				'condition'  => array( 'show_avatar' => 'yes' ),
			)
		);

		$this->add_control(
			'avatar_radius',
			array(
				'label'      => esc_html__( 'Border Radius', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 100 ) ),
				'default'    => array( 'unit' => '%', 'size' => 50 ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote__avatar' => 'border-radius: {{SIZE}}{{UNIT}};',
				),
				'condition'  => array( 'show_avatar' => 'yes' ),
			)
		);

		$this->add_responsive_control(
			'author_spacing',
			array(
				'label'      => esc_html__( 'Top Spacing', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', 'em' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 80 ) ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-blockquote__footer' => 'margin-top: {{SIZE}}{{UNIT}};',
				),
				'separator'  => 'before',
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Render the decorative quote icon.
	 *
	 * @since 1.3.0
	 * @param array $settings Widget settings.
	 * @return void
	 */
	private function captwiki_render_icon( array $settings ): void {
		if ( 'yes' !== $settings['show_icon'] || empty( $settings['quote_icon']['value'] ) ) {
			return;
		}

		echo '<span class="captwiki-blockquote__icon" aria-hidden="true">';
		Icons_Manager::render_icon( $settings['quote_icon'], array( 'aria-hidden' => 'true' ) );
		echo '</span>';
	}

	/**
	 * Render the author block ( avatar + name + role ).
	 *
	 * @since 1.3.0
	 * @param array $settings Widget settings.
	 * @return void
	 */
	private function captwiki_render_author( array $settings ): void {
		$show_author = 'yes' === $settings['show_author'];
		$name        = trim( (string) $settings['author_name'] );
		$role        = trim( (string) $settings['author_role'] );
		$show_avatar = 'yes' === $settings['show_avatar'];
		$avatar_url  = ! empty( $settings['author_image']['url'] ) ? $settings['author_image']['url'] : '';
		$citation    = trim( (string) $settings['citation_text'] );

		if ( ! $show_author && '' === $citation ) {
			return;
		}

		echo '<footer class="captwiki-blockquote__footer">';

		if ( $show_author && $show_avatar && '' !== $avatar_url ) {
			$alt = '' !== $name ? $name : esc_attr__( 'Author avatar', 'captain-widgets-kit' );
			echo '<img class="captwiki-blockquote__avatar" src="' . esc_url( $avatar_url ) . '" alt="' . esc_attr( $alt ) . '" loading="lazy" />';
		}

		if ( $show_author && ( '' !== $name || '' !== $role ) ) {
			echo '<span class="captwiki-blockquote__meta">';

			if ( '' !== $name ) {
				echo '<cite class="captwiki-blockquote__author">' . esc_html( $name ) . '</cite>';
			}

			if ( '' !== $role ) {
				echo '<span class="captwiki-blockquote__role">' . esc_html( $role ) . '</span>';
			}

			$this->captwiki_render_citation( $settings );

			echo '</span>';
		} elseif ( '' !== $citation ) {
			$this->captwiki_render_citation( $settings );
		}

		echo '</footer>';
	}

	/**
	 * Render the source / citation, optionally linked.
	 *
	 * @since 1.3.0
	 * @param array $settings Widget settings.
	 * @return void
	 */
	private function captwiki_render_citation( array $settings ): void {
		$citation = trim( (string) $settings['citation_text'] );

		if ( '' === $citation ) {
			return;
		}

		$url = ! empty( $settings['citation_url']['url'] ) ? $settings['citation_url']['url'] : '';

		echo '<span class="captwiki-blockquote__source">';

		if ( '' !== $url ) {
			$target = ! empty( $settings['citation_url']['is_external'] ) ? ' target="_blank"' : '';
			$rel    = ! empty( $settings['citation_url']['nofollow'] ) ? ' rel="nofollow"' : '';
			echo '<a href="' . esc_url( $url ) . '"' . $target . $rel . '>' . esc_html( $citation ) . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		} else {
			echo esc_html( $citation );
		}

		echo '</span>';
	}

	/**
	 * Render widget output on the frontend.
	 *
	 * Loads only the selected style CSS file ( depends on the common stylesheet ).
	 *
	 * @since 1.3.0
	 * @return void
	 */
	protected function render(): void {
		$settings = $this->get_settings_for_display();

		$quote = trim( (string) $settings['quote_text'] );

		if ( '' === $quote ) {
			return;
		}

		$allowed_styles = array_keys( $this->captwiki_style_options() );
		$style          = in_array( $settings['widget_style'], $allowed_styles, true ) ? $settings['widget_style'] : 'style-1';

		// Load only the active style stylesheet, depending on the common one.
		wp_enqueue_style(
			'captwiki-blockquote-' . $style,
			CAPTWIKI_URL . 'assets/css/widgets/blockquote/captwiki-blockquote-' . $style . '.css',
			array( 'captwiki_blockquote' ),
			CAPTWIKI_VERSION
		);

		$unique_class = 'captwiki-widget-' . $this->get_id();

		echo '<blockquote class="captwiki-blockquote captwiki-' . esc_attr( $style ) . ' ' . esc_attr( $unique_class ) . '">';

			$this->captwiki_render_icon( $settings );

			echo '<div class="captwiki-blockquote__content">';
				echo '<p class="captwiki-blockquote__text">' . wp_kses_post( nl2br( esc_html( $quote ) ) ) . '</p>';
				$this->captwiki_render_author( $settings );
			echo '</div>';

		echo '</blockquote>';
	}
}
