<?php

namespace WPEventGenius\Common\SEO\Compatibility;

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

class YoastSEOCompatibility implements SEOCompatibilityInterface {

	/**
	 * @inheritDoc
	 */
	public function is_available() {
		return function_exists( 'yoast_breadcrumb' );
	}

	/**
	 * @inheritDoc
	 */
	public function render( $post_id, array $breadcrumb_context = array() ) {
		if ( ! $this->is_available() ) {
			return '';
		}

		$before = apply_filters( 'evge_yoast_breadcrumb_before', '', $post_id, $breadcrumb_context );
		$after  = apply_filters( 'evge_yoast_breadcrumb_after', '', $post_id, $breadcrumb_context );

		$breadcrumbs = yoast_breadcrumb( $before, $after, false );

		if ( ! is_string( $breadcrumbs ) ) {
			return '';
		}

		return trim( $breadcrumbs );
	}
}
