<?php

namespace SugarCalendarBookings\Support\Admin;

use SugarCalendarBookings\Support\Helpers\UI;

/**
 * Page abstract.
 *
 * @since 1.2.0
 */
abstract class AbstractEducationPage extends AbstractPage {

	/**
	 * Whether to show the subheader.
	 *
	 * @since 1.2.0
	 *
	 * @return bool
	 */
	public function should_show_subheader() {

		return false;
	}

	/**
	 * Wrapper element ID.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_wrapper_element_id() {

		return esc_attr( 'sugar-calendar-bookings-education-' . static::get_slug() );
	}

	/**
	 * Get page description.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_description() {

		return '';
	}

	/**
	 * Get screenshots array.
	 *
	 * @since 1.2.0
	 *
	 * @return array Array of screenshot data. Each item should contain 'url', 'url_thumbnail', and 'title' keys.
	 */
	public function get_screenshots() {

		return [];
	}

	/**
	 * Render screenshots.
	 *
	 * @since 1.2.0
	 *
	 * @return void
	 */
	public function render_screenshots() {

		$screenshots = $this->get_screenshots();

		// Bail if no screenshots are found.
		if ( empty( $screenshots ) ) {
			return;
		}

		foreach ( $screenshots as $screenshot ) {

			ob_start();
			UI::image_modal_trigger( $screenshot );
			$image_trigger_html = ob_get_clean();

			$screenshot_html = wp_sprintf(
				'<figure>
					%1$s
					<figcaption>%2$s</figcaption>
				</figure>',
				$image_trigger_html,
				esc_html( $screenshot['title'] )
			);

			echo wp_kses(
				$screenshot_html,
				[
					'figure'     => [],
					'a'          => [
						'href'           => [],
						'class'          => [],
						'data-image-alt' => [],
					],
					'img'        => [
						'src' => [],
						'alt' => [],
					],
					'figcaption' => [],
				]
			);
		}
	}

	/**
	 * Get features heading.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_features_heading() {

		return '';
	}

	/**
	 * Get features list.
	 *
	 * @since 1.2.0
	 *
	 * @return array Array of feature strings.
	 */
	public function get_features() {

		return [];
	}

	/**
	 * Render features list.
	 *
	 * @since 1.2.0
	 *
	 * @return void
	 */
	public function render_features() {

		$features = $this->get_features();

		// Bail if no features are found.
		if ( empty( $features ) ) {
			return;
		}

		$features_html = '<ul>';

		foreach ( $features as $feature ) {

			$features_html .= wp_sprintf(
				'<li>%1$s</li>',
				esc_html( $feature )
			);
		}

		$features_html .= '</ul>';

		echo wp_kses(
			$features_html,
			[
				'ul' => [],
				'li' => [],
			]
		);
	}

	/**
	 * Get UTM medium parameter.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_utm_medium() {

		return static::get_slug();
	}

	/**
	 * Get UTM content parameter.
	 *
	 * @since 1.2.0
	 *
	 * @param string $position Button position ('top' or 'bottom').
	 *
	 * @return string
	 */
	public function get_utm_content( $position = 'top' ) {

		$position_text = $position === 'top' ? esc_html__( 'Top', 'sugar-calendar-bookings-scheduling-appointments-lite' ) : esc_html__( 'Bottom', 'sugar-calendar-bookings-scheduling-appointments-lite' );

		/* translators: %1$s - button position (Top or Bottom). */
		return sprintf( esc_html__( 'Upgrade to Sugar Calendar Bookings Pro %1$s', 'sugar-calendar-bookings-scheduling-appointments-lite' ), $position_text );
	}
}
