<?php

namespace Dev4Press\Plugin\BreadcrumbsPress\Blocks;

use Dev4Press\Plugin\BreadcrumbsPress\Crumbs\Build;

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

class Render {
	private function __construct() {
	}

	public static function instance() : Render {
		static $instance = false;

		if ( $instance === false ) {
			$instance = new Render();
		}

		return $instance;
	}

	public function single( $post_id = 0, $attributes = array() ) : string {
		$attributes['echo'] = false;
		$attributes['id']   = 'breadcrumbs-block-' . $attributes['block_id'];

		if ( $post_id > 0 ) {
			return Build::instance()->post( $post_id, $attributes );
		} else {
			return Build::instance()->current( $attributes );
		}
	}

	public function multi( $post_id = 0, $attributes = array() ) : string {
		$attributes['echo'] = false;
		$attributes['id']   = 'breadcrumbs-block-' . $attributes['block_id'];

		if ( $post_id > 0 ) {
			$generate = array();

			foreach ( array( 'basic', 'posts', 'archive', 'author', 'date', 'terms' ) as $key ) {
				$generate[ $key ] = $attributes[ 'show_' . $key ];
			}

			return \Dev4Press\Plugin\BreadcrumbsPress\Pro\Crumbs\Build::instance()->multi( $post_id, $attributes, $generate );
		}

		return '';
	}
}
