<?php
/**
 * QrCdr Icons class
 *
 * Defines the svg icons.
 *
 * @since  1.0.0
 *
 * @category  WordPress_Plugin
 * @package   QrCdr
 * @author    Nicola Franchini
 * @link      https://veno.es
 */

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

if ( ! class_exists( 'QrCdr_Patterns' ) ) {
	/**
	 * QrCdr_Patterns class
	 */
	class QrCdr_Patterns {
		/**
		 * Holds an instance of the object
		 *
		 * @var instance
		 */
		protected static $instance = null;

		/**
		 * Cache for the icons array.
		 *
		 * @var array|null
		 */
		protected $patterns = null;

		/**
		 * Cache for the allowed SVG tags.
		 *
		 * @var array|null
		 */
		protected $frames = null;

		/**
		 * Cache for the allowed SVG tags.
		 *
		 * @var array|null
		 */
		protected $allowed_svg_tags = null;

		/**
		 * Returns the running object
		 *
		 * @return QrCdr_Patterns
		 */
		public static function get_instance() {
			if ( null === self::$instance ) {
				self::$instance = new self();
			}
			return self::$instance;
		}

		/**
		 * Get default tabs with their inputs
		 *
		 * @return array
		 */
		public function get_default_patterns() {
			require dirname( __DIR__ ) . '/lib/markers.php';
			$qrcdr_patterns = array(
				'markers' => $qrcdr_markers,
				'patterns' => $qrcdr_patterns,
			);
			return $qrcdr_patterns;
		}

		/**
		 * Get available patterns
		 *
		 * @return array
		 */
		public function get_patterns() {
			if ( null === $this->patterns ) {
				$this->patterns = apply_filters( 'qrcdr_available_patterns', $this->get_default_patterns() );
			}
			// Restituisci la versione in cache.
			return $this->patterns;
		}

		/**
		 * Get default tabs with their inputs
		 *
		 * @return array
		 */
		public function get_default_frames() {
			require dirname( __DIR__ ) . '/lib/frames.php';
			return $qrcdr_frames;
		}

		/**
		 * Get available frames
		 *
		 * @return array
		 */
		public function get_frames() {
			if ( null === $this->frames ) {
				$this->frames = apply_filters( 'qrcdr_available_frames', $this->get_default_frames() );
			}
			// Restituisci la versione in cache.
			return $this->frames;
		}

		/**
		 * Echo the selected path
		 *
		 * @param string $path The path to filter.
		 */
		public function filtered_path( $path ) {
			if ( null === $this->allowed_svg_tags ) {
				$this->allowed_svg_tags = qrcdr_plugin()->get_allowed_svg_tags();
			}
			echo wp_kses( $path, $this->allowed_svg_tags );
		}
	}
}
