<?php
/**
 * Widget Name: Product Price
 * Description: Outputs the WooCommerce product price (sale-aware, variable-range
 *              aware) for the current product or a chosen product, with an
 *              optional prefix/suffix, a configurable sale badge, a "you save"
 *              line, empty handling and multiple attractive styles.
 *
 * @package    captain-widgets-kit
 * @subpackage captain-widgets-kit/includes
 * @since      1.4.0
 */

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

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;

/**
 * Class Captwiki_Woo_Product_Price
 *
 * @since 1.4.0
 */
class Captwiki_Woo_Product_Price extends Widget_Base {

	/**
	 * Get widget name.
	 *
	 * @since 1.4.0
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-woo-product-price';
	}

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

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

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

	/**
	 * Get widget keywords.
	 *
	 * @since 1.4.0
	 * @return array
	 */
	public function get_keywords(): array {
		return array( 'woocommerce', 'woo', 'product', 'price', 'sale', 'discount', 'amount', 'captain-widgets-kit' );
	}

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

	/**
	 * Available visual styles.
	 *
	 * @since 1.4.0
	 * @return array
	 */
	private function captwiki_style_options(): array {
		return array(
			'style-1' => esc_html__( 'Style 1 – Classic', 'captain-widgets-kit' ),
			'style-2' => esc_html__( 'Style 2 – Sale Emphasis', 'captain-widgets-kit' ),
			'style-3' => esc_html__( 'Style 3 – Boxed', 'captain-widgets-kit' ),
			'style-4' => esc_html__( 'Style 4 – Stacked', 'captain-widgets-kit' ),
			'style-5' => esc_html__( 'Style 5 – Pill', 'captain-widgets-kit' ),
			'style-6' => esc_html__( 'Style 6 – Outline Tag', 'captain-widgets-kit' ),
		);
	}

	/**
	 * Build a list of published products for the source selector.
	 *
	 * @since 1.4.0
	 * @return array
	 */
	private function captwiki_get_products_options(): array {

		$options = array();

		if ( ! function_exists( 'wc_get_products' ) ) {
			return $options;
		}

		$products = wc_get_products(
			array(
				'status'  => 'publish',
				'limit'   => 50,
				'orderby' => 'title',
				'order'   => 'ASC',
				'return'  => 'objects',
			)
		);

		foreach ( $products as $product ) {
			$options[ $product->get_id() ] = $product->get_name();
		}

		return $options;
	}

	/**
	 * Register controls.
	 *
	 * @since 1.4.0
	 */
	protected function register_controls(): void {
		$this->register_content_controls();
		$this->register_price_style_controls();
		$this->register_badge_style_controls();
		$this->register_box_style_controls();
	}

	/**
	 * Content tab controls.
	 *
	 * @since 1.4.0
	 */
	private function register_content_controls(): void {

		$this->start_controls_section(
			'section_content',
			array(
				'label' => esc_html__( 'Price', '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(
			'product_source',
			array(
				'label'   => esc_html__( 'Product', 'captain-widgets-kit' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'current',
				'options' => array(
					'current'  => esc_html__( 'Current Product', 'captain-widgets-kit' ),
					'specific' => esc_html__( 'Select a Product', 'captain-widgets-kit' ),
				),
			)
		);

		$this->add_control(
			'product_id',
			array(
				'label'       => esc_html__( 'Choose Product', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::SELECT2,
				'label_block' => true,
				'options'     => $this->captwiki_get_products_options(),
				'condition'   => array( 'product_source' => 'specific' ),
			)
		);

		$this->add_control(
			'prefix_text',
			array(
				'label'       => esc_html__( 'Prefix', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => '',
				'placeholder' => esc_html__( 'e.g. From', 'captain-widgets-kit' ),
			)
		);

		$this->add_control(
			'suffix_text',
			array(
				'label'       => esc_html__( 'Suffix', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => '',
				'placeholder' => esc_html__( 'e.g. / month', 'captain-widgets-kit' ),
			)
		);

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

		$this->add_control(
			'show_sale_badge',
			array(
				'label'        => esc_html__( 'Show Sale Badge', '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(
			'sale_badge_type',
			array(
				'label'     => esc_html__( 'Badge Content', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'percent',
				'options'   => array(
					'percent' => esc_html__( 'Discount Percent', 'captain-widgets-kit' ),
					'amount'  => esc_html__( 'Amount Saved', 'captain-widgets-kit' ),
					'custom'  => esc_html__( 'Custom Text', 'captain-widgets-kit' ),
				),
				'condition' => array( 'show_sale_badge' => 'yes' ),
			)
		);

		$this->add_control(
			'sale_badge_percent_tpl',
			array(
				'label'       => esc_html__( 'Percent Template', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( '-{value}%', 'captain-widgets-kit' ),
				'description' => esc_html__( 'Use {value} for the discount number.', 'captain-widgets-kit' ),
				'condition'   => array(
					'show_sale_badge' => 'yes',
					'sale_badge_type' => 'percent',
				),
			)
		);

		$this->add_control(
			'sale_badge_amount_tpl',
			array(
				'label'       => esc_html__( 'Amount Template', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Save {value}', 'captain-widgets-kit' ),
				'description' => esc_html__( 'Use {value} for the saved amount.', 'captain-widgets-kit' ),
				'condition'   => array(
					'show_sale_badge' => 'yes',
					'sale_badge_type' => 'amount',
				),
			)
		);

		$this->add_control(
			'sale_badge_custom',
			array(
				'label'     => esc_html__( 'Custom Text', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => esc_html__( 'Sale', 'captain-widgets-kit' ),
				'condition' => array(
					'show_sale_badge' => 'yes',
					'sale_badge_type' => 'custom',
				),
			)
		);

		$this->add_control(
			'show_save_line',
			array(
				'label'        => esc_html__( 'Show "You Save" Line', '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'      => 'no',
				'separator'    => 'before',
			)
		);

		$this->add_control(
			'save_line_tpl',
			array(
				'label'       => esc_html__( 'Save Line Template', 'captain-widgets-kit' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'You save {amount} ({percent}%)', 'captain-widgets-kit' ),
				'description' => esc_html__( 'Use {amount} and {percent}.', 'captain-widgets-kit' ),
				'condition'   => array( 'show_save_line' => 'yes' ),
			)
		);

		$this->add_responsive_control(
			'price_align',
			array(
				'label'     => esc_html__( 'Alignment', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'flex-start' => 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',
					),
					'flex-end'   => array(
						'title' => esc_html__( 'Right', 'captain-widgets-kit' ),
						'icon'  => 'eicon-text-align-right',
					),
				),
				'default'   => 'flex-start',
				'separator' => 'before',
				'selectors' => array(
					'{{WRAPPER}} .captwiki-pprice'         => 'justify-content: {{VALUE}}; align-items: {{VALUE}};',
					'{{WRAPPER}} .captwiki-pprice__main'   => 'justify-content: {{VALUE}};',
				),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Price style controls.
	 *
	 * @since 1.4.0
	 */
	private function register_price_style_controls(): void {

		$price_selector   = '{{WRAPPER}} .captwiki-pprice__price';
		$ins_selector     = '{{WRAPPER}} .captwiki-pprice__price ins, {{WRAPPER}} .captwiki-pprice__price ins .amount';
		$del_selector     = '{{WRAPPER}} .captwiki-pprice__price del, {{WRAPPER}} .captwiki-pprice__price del .amount';
		$affix_selector   = '{{WRAPPER}} .captwiki-pprice__prefix, {{WRAPPER}} .captwiki-pprice__suffix';

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

		$this->add_control(
			'price_color',
			array(
				'label'     => esc_html__( 'Price Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					$price_selector => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'price_typography',
				'selector' => $price_selector,
			)
		);

		$this->add_control(
			'sale_price_color',
			array(
				'label'     => esc_html__( 'Sale Price Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'separator' => 'before',
				'selectors' => array(
					$ins_selector => 'color: {{VALUE}}; text-decoration: none;',
				),
			)
		);

		$this->add_control(
			'regular_price_color',
			array(
				'label'     => esc_html__( 'Original (Struck) Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					$del_selector => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_control(
			'affix_color',
			array(
				'label'     => esc_html__( 'Prefix / Suffix Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'separator' => 'before',
				'selectors' => array(
					$affix_selector => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'affix_typography',
				'selector' => $affix_selector,
			)
		);

		$this->add_control(
			'save_line_color',
			array(
				'label'     => esc_html__( '"You Save" Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'separator' => 'before',
				'condition' => array( 'show_save_line' => 'yes' ),
				'selectors' => array(
					'{{WRAPPER}} .captwiki-pprice__save' => 'color: {{VALUE}};',
				),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Sale badge style controls.
	 *
	 * @since 1.4.0
	 */
	private function register_badge_style_controls(): void {

		$selector = '{{WRAPPER}} .captwiki-pprice__badge';

		$this->start_controls_section(
			'section_badge_style',
			array(
				'label'     => esc_html__( 'Sale Badge', 'captain-widgets-kit' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'show_sale_badge' => 'yes' ),
			)
		);

		$this->add_control(
			'badge_color',
			array(
				'label'     => esc_html__( 'Text Color', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					$selector => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_control(
			'badge_bg',
			array(
				'label'     => esc_html__( 'Background', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					$selector => 'background-color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'badge_typography',
				'selector' => $selector,
			)
		);

		$this->add_responsive_control(
			'badge_padding',
			array(
				'label'      => esc_html__( 'Padding', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em' ),
				'selectors'  => array(
					$selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

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

		$this->end_controls_section();
	}

	/**
	 * Box style controls.
	 *
	 * @since 1.4.0
	 */
	private function register_box_style_controls(): void {

		$wrap_selector = '{{WRAPPER}} .captwiki-pprice';

		$this->start_controls_section(
			'section_box_style',
			array(
				'label' => esc_html__( 'Box & Spacing', 'captain-widgets-kit' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_responsive_control(
			'item_gap',
			array(
				'label'      => esc_html__( 'Gap', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array( 'px' => array( 'min' => 0, 'max' => 40 ) ),
				'selectors'  => array(
					'{{WRAPPER}} .captwiki-pprice__main' => 'gap: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_control(
			'box_bg',
			array(
				'label'     => esc_html__( 'Background', 'captain-widgets-kit' ),
				'type'      => Controls_Manager::COLOR,
				'separator' => 'before',
				'selectors' => array(
					$wrap_selector => 'background-color: {{VALUE}};',
				),
			)
		);

		$this->add_responsive_control(
			'box_padding',
			array(
				'label'      => esc_html__( 'Padding', 'captain-widgets-kit' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em' ),
				'selectors'  => array(
					$wrap_selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'box_border',
				'selector' => $wrap_selector,
			)
		);

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

		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'box_shadow',
				'selector' => $wrap_selector,
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Resolve the product.
	 *
	 * @since 1.4.0
	 * @param array $settings Widget settings.
	 * @return \WC_Product|false
	 */
	private function captwiki_resolve_product( array $settings ) {

		$source = ! empty( $settings['product_source'] ) ? $settings['product_source'] : 'current';

		if ( 'specific' === $source && ! empty( $settings['product_id'] ) ) {
			return wc_get_product( absint( $settings['product_id'] ) );
		}

		$product = wc_get_product( get_the_ID() );

		if ( $product ) {
			return $product;
		}

		if ( \Elementor\Plugin::$instance->editor->is_edit_mode() || \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
			$latest = wc_get_products(
				array(
					'status' => 'publish',
					'limit'  => 1,
				)
			);

			if ( ! empty( $latest ) ) {
				return $latest[0];
			}
		}

		return false;
	}

	/**
	 * Compute the discount (amount + percent) for a product on sale.
	 *
	 * @since 1.4.0
	 * @param \WC_Product $product Product.
	 * @return array|null Array with 'amount' (float) and 'percent' (int) or null.
	 */
	private function captwiki_get_discount( $product ) {

		if ( ! $product->is_on_sale() ) {
			return null;
		}

		$regular = (float) $product->get_regular_price();
		$sale    = (float) $product->get_sale_price();

		// Variable / complex products: regular/sale not directly numeric.
		if ( $regular <= 0 || $sale < 0 || $sale >= $regular ) {
			return null;
		}

		$amount  = $regular - $sale;
		$percent = (int) round( ( $amount / $regular ) * 100 );

		return array(
			'amount'  => $amount,
			'percent' => $percent,
		);
	}

	/**
	 * Build the sale badge label.
	 *
	 * @since 1.4.0
	 * @param array      $settings Widget settings.
	 * @param array|null $discount Discount data.
	 * @return string
	 */
	private function captwiki_badge_label( array $settings, $discount ): string {

		$type = ! empty( $settings['sale_badge_type'] ) ? $settings['sale_badge_type'] : 'percent';

		if ( 'custom' === $type ) {
			return ! empty( $settings['sale_badge_custom'] ) ? $settings['sale_badge_custom'] : esc_html__( 'Sale', 'captain-widgets-kit' );
		}

		// Percent / amount need computed discount; fall back to "Sale".
		if ( null === $discount ) {
			return esc_html__( 'Sale', 'captain-widgets-kit' );
		}

		if ( 'amount' === $type ) {
			$tpl = ! empty( $settings['sale_badge_amount_tpl'] ) ? $settings['sale_badge_amount_tpl'] : 'Save {value}';
			return str_replace( '{value}', wp_strip_all_tags( wc_price( $discount['amount'] ) ), $tpl );
		}

		$tpl = ! empty( $settings['sale_badge_percent_tpl'] ) ? $settings['sale_badge_percent_tpl'] : '-{value}%';
		return str_replace( '{value}', (string) $discount['percent'], $tpl );
	}

	/**
	 * Output an editor-only notice.
	 *
	 * @since 1.4.0
	 * @param string $message Notice text.
	 */
	private function captwiki_render_editor_notice( string $message ): void {

		if ( ! \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
			return;
		}

		echo '<div class="captwiki-pprice captwiki-pprice--notice"><p>' . esc_html( $message ) . '</p></div>';
	}

	/**
	 * Render widget output on the frontend.
	 *
	 * @since 1.4.0
	 */
	protected function render(): void {

		if ( ! class_exists( 'WooCommerce' ) || ! function_exists( 'wc_get_product' ) ) {
			$this->captwiki_render_editor_notice( esc_html__( 'WooCommerce is required for the Product Price widget.', 'captain-widgets-kit' ) );
			return;
		}

		$settings = $this->get_settings_for_display();
		$product  = $this->captwiki_resolve_product( $settings );

		if ( ! $product instanceof \WC_Product ) {
			$this->captwiki_render_editor_notice( esc_html__( 'No product found. Place this widget on a product template or select a product.', 'captain-widgets-kit' ) );
			return;
		}

		$price_html = $product->get_price_html();

		if ( empty( $price_html ) ) {
			$this->captwiki_render_editor_notice( esc_html__( 'This product has no price to display.', 'captain-widgets-kit' ) );
			return;
		}

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

		wp_enqueue_style(
			'captwiki-woo-product-price-' . $style,
			CAPTWIKI_URL . 'assets/css/widgets/woo-product-price/captwiki-woo-product-price-' . $style . '.css',
			array( 'captwiki-woo-product-price' ),
			CAPTWIKI_VERSION
		);

		$is_on_sale      = $product->is_on_sale();
		$discount        = $this->captwiki_get_discount( $product );
		$show_sale_badge = ! empty( $settings['show_sale_badge'] ) && 'yes' === $settings['show_sale_badge'] && $is_on_sale;
		$show_save_line  = ! empty( $settings['show_save_line'] ) && 'yes' === $settings['show_save_line'] && $is_on_sale && null !== $discount;

		$wrapper_classes = array(
			'captwiki-pprice',
			'captwiki-' . $style,
			'captwiki-widget-' . $this->get_id(),
		);

		if ( $is_on_sale ) {
			$wrapper_classes[] = 'captwiki-pprice--on-sale';
		}

		echo '<div class="' . esc_attr( implode( ' ', $wrapper_classes ) ) . '">';
		echo '<div class="captwiki-pprice__main">';

		if ( ! empty( $settings['prefix_text'] ) ) {
			echo '<span class="captwiki-pprice__prefix">' . esc_html( $settings['prefix_text'] ) . '</span>';
		}

		echo '<span class="captwiki-pprice__price">' . wp_kses_post( $price_html ) . '</span>';

		if ( ! empty( $settings['suffix_text'] ) ) {
			echo '<span class="captwiki-pprice__suffix">' . esc_html( $settings['suffix_text'] ) . '</span>';
		}

		if ( $show_sale_badge ) {
			echo '<span class="captwiki-pprice__badge">' . esc_html( $this->captwiki_badge_label( $settings, $discount ) ) . '</span>';
		}

		echo '</div>'; // main.

		if ( $show_save_line ) {
			$tpl  = ! empty( $settings['save_line_tpl'] ) ? $settings['save_line_tpl'] : 'You save {amount} ({percent}%)';
			$line = str_replace(
				array( '{amount}', '{percent}' ),
				array( wp_strip_all_tags( wc_price( $discount['amount'] ) ), (string) $discount['percent'] ),
				$tpl
			);

			echo '<div class="captwiki-pprice__save">' . esc_html( $line ) . '</div>';
		}

		echo '</div>'; // wrapper.
	}
}
