<?php
/**
 * LabelProvider
 *
 * Single source of truth for all default labels.
 * Respects the disabled_default_* options set in the admin UI.
 * Exposes filters so developers can add or replace labels via code.
 *
 * @package Relatedly\Labels
 * @since   2.0.0
 */

namespace Relatedly\Labels;

use Relatedly\Core\Options;

defined( 'ABSPATH' ) || exit;

/**
 * Provides default and filtered labels for Relatedly displays.
 *
 * @since 2.0.0
 */
class LabelProvider {

	/**
	 * Plugin settings repository.
	 *
	 * @since 2.0.0
	 * @var Options
	 */
	private Options $options;

	/**
	 * Create the label provider.
	 *
	 * @since 2.0.0
	 * @param Options $options Plugin settings repository.
	 */
	public function __construct( Options $options ) {
		$this->options = $options;
	}

	// -------------------------------------------------------------------------
	// Public API
	// -------------------------------------------------------------------------

	/**
	 * Get active inline labels (defaults minus any the user has disabled).
	 *
	 * @return string[]
	 */
	public function get_inline_labels(): array {
		$disabled = (array) $this->options->get( 'disabled_default_inline_labels', [] );
		$active   = array_values( array_diff( $this->default_inline_labels(), $disabled ) );
		return (array) apply_filters( 'relatedly_inline_labels', $active );
	}

	/**
	 * Get active end-content labels.
	 *
	 * @return string[]
	 */
	public function get_end_content_labels(): array {
		$disabled = (array) $this->options->get( 'disabled_default_end_content_labels', [] );
		$active   = array_values( array_diff( $this->default_end_content_labels(), $disabled ) );
		return (array) apply_filters( 'relatedly_end_content_labels', $active );
	}

	/** Pick one random inline label. */
	public function random_inline(): string {
		$labels = $this->get_inline_labels();
		return ! empty( $labels ) ? $labels[ array_rand( $labels ) ] : 'Related:';
	}

	/** Pick one random end-content label. */
	public function random_end_content(): string {
		$labels = $this->get_end_content_labels();
		return ! empty( $labels ) ? $labels[ array_rand( $labels ) ] : 'You might also like';
	}

	/** Return the full default inline labels array (used in admin UI). */
	public function default_inline_labels(): array {
		return [
			'Related:',
			'See also:',
			'Recommended:',
			'You might like:',
			"Don't miss:",
			'Check this out:',
			'Read more:',
			'Further reading:',
			'Explore this:',
			'Worth reading:',
			'Give this a look:',
			'Just for you:',
			'In case you missed it:',
			'Also trending:',
			'Popular choice:',
			"Editor's pick:",
			'Must read:',
			'Hot topic:',
			'Trending now:',
			'Featured:',
			'Top pick:',
			'Staff favorite:',
			"Reader's choice:",
			'Most popular:',
			'Key article:',
			'Related article:',
			'Keep reading:',
			'Explore more:',
			'Similar post:',
			'Related content:',
			'Continue reading:',
			'Related story:',
			'Popular post:',
			'Top story:',
			'Latest update:',
			'Recent post:',
			'New content:',
			'Featured content:',
			'Trending article:',
			'Further exploration:',
			"Don't miss this:",
			'Read this next:',
			'More on this topic:',
			'Related reading:',
			'Similar content:',
			'Discover more:',
			'Explore further:',
			'Continue exploring:',
			'Additional reading:',
			'Related topic:',
			'Similar story:',
			'More from this series:',
			'Expand your knowledge:',
			'Learn more:',
			'Related post:',
			'More like this:',
			'Also check out:',
			'Continue the journey:',
			'Explore this topic:',
			'More to discover:',
			'Similar article:',
			'More content:',
			'Additional post:',
			'Related story below:',
			'Keep exploring:',
			'More story:',
			'Similar topic:',
			'More article:',
			'Explore related:',
			'More reading:',
			'Discover similar:',
			'More on this:',
			'Explore similar:',
			'Up next:',
			'What to read next:',
		];
	}


	/** Return the full default end-content labels array (used in admin UI). */
	public function default_end_content_labels(): array {
		return [
			'Handpicked posts you may love',
			"Related articles you shouldn't miss",
			"More stories you'll enjoy reading",
			'Discover more content like this',
			'Continue your reading journey here',
			'Explore these related topics further',
			'Dive deeper into similar content',
			'Expand your knowledge with these articles',
			'Find more insights on this topic',
			'Discover related stories worth reading',
			'Explore more from this category',
			'Continue exploring related content',
			'More articles that match your interests',
			'Additional reading you might enjoy',
			'Related stories that will captivate you',
			'More content tailored to your interests',
			'Discover more articles in this series',
			'Continue learning with these related posts',
			'Explore more topics that interest you',
			'Find more articles worth your time',
			'Dive into more related content here',
			'Continue your learning journey below',
			'More stories that will engage you',
			'Discover additional related articles',
			'Explore these carefully selected posts',
			'You might also like',
			'Recommended reading',
			'More great content',
			"Don't miss these",
			'More from this topic',
			'Additional resources',
			'Curated posts just for you',
			"Hand-selected articles you'll love",
			'More must-read content below',
			'Continue reading these related posts',
			'Explore similar stories here',
			'Discover more in this series',
			'Related content worth exploring',
			'More articles to expand your knowledge',
			'Continue your journey with these posts',
			"Handpicked stories you'll enjoy",
			'More content that matches your taste',
			'Explore these related articles',
			'Continue learning with similar posts',
			"Discover more topics you'll love",
			'Additional articles in this category',
			'More stories that will interest you',
			'Explore related content below',
			'Continue reading with these posts',
			'More carefully chosen articles',
		];
	}
}
