<?php
declare( strict_types=1 );

namespace FiboFilters\Integrations;

use FiboFilters\Config\Env;
use FiboFilters\DI\ContainerWrapper;
use FiboFilters\Util\Helpers;

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

/**
 * Class Themes
 */
class Themes {
	/** @var array */
	private $current_integration = [];
	/** @var string */

	private $theme_version = '';
	/** @var string */
	private $theme_slug = '';
	/** @var string */
	private $theme_name = '';
	/** @var string */
	private $parent_theme_name = '';
	/** @var string */
	private $parent_theme_version = '';
	/** @var \WP_Theme */
	private $theme;

	/** @var ContainerWrapper */
	private $container;

	public function __construct( ContainerWrapper $container ) {
		$this->container = $container;
	}

	public function init(): void {
		$this->set_current_theme();
		$this->load_integration();

		add_filter( 'fibofilters/integrations/themes/extra_guide_steps', [ $this, 'get_extra_guide_steps' ], 10, 2 );
	}

	public function get_current_integration() {
		return $this->current_integration;
	}

	public function is_current_integration_enabled() {
		$current_integration = $this->get_current_integration();
		if ( empty( $current_integration ) ) {
			return false;
		}

		return (bool) get_option( 'fibofilters_general_enable_theme_integration_' . $current_integration['slug'] );
	}

	private function set_current_theme(): void {
		$theme = wp_get_theme();

		if ( is_object( $theme ) && is_a( $theme, 'WP_Theme' ) ) {
			$template         = $theme->get_template();
			$stylesheet       = $theme->get_stylesheet();
			$is_child_theme   = $template !== $stylesheet;
			$this->theme_slug = sanitize_title( $theme->name );

			if ( $is_child_theme ) {
				$this->theme_slug           = strtolower( $template );
				$this->parent_theme_version = ! empty( $theme->parent() ) ? $theme->parent()->get( 'Version' ) : '';
			}

			$this->theme             = $theme;
			$this->theme_name        = $theme->name;
			$this->theme_version     = $theme->version;
			$this->parent_theme_name = ! empty( $theme->parent_theme ) ? $theme->parent_theme : '';
		}

		$this->theme_slug = apply_filters( 'fibofilters/integrations/themes/current_theme_slug', $this->theme_slug );
		$this->theme_name = apply_filters( 'fibofilters/integrations/themes/current_theme_name', $this->theme_name );
		if ( $this->is_child_theme() ) {
			$this->parent_theme_name = apply_filters( 'fibofilters/integrations/themes/current_parent_theme_name', $this->parent_theme_name );
		}
	}

	public function get_integration_context(): array {
		$is_child = $this->is_child_theme();

		$active_slug = ( is_a( $this->theme, 'WP_Theme' ) )
			? $this->theme->get_stylesheet()
			: $this->theme_slug;

		$parent_slug = ( $is_child && is_a( $this->theme, 'WP_Theme' ) )
			? $this->theme->get_template()
			: '';

		return [
			'active' => [
				'name'    => $this->theme_name,
				'slug'    => $active_slug,
				'version' => $this->theme_version,
			],
			'parent' => $is_child ? [
				'name'    => $this->parent_theme_name,
				'slug'    => $parent_slug,
				'version' => $this->parent_theme_version,
			] : null,
		];
	}

	/**
	 * Check if the current them is child theme
	 */
	public function is_child_theme(): bool {
		return ! empty( $this->parent_theme_name );
	}

	/**
	 * Check if the integration is under white label
	 */
	public function is_white_label(): bool {
		return apply_filters( 'fibofilters/integrations/themes/white_label', false );
	}

	/**
	 * Get the name of the current parent theme
	 */
	public function get_parent_theme_name(): string {
		return ! empty( $this->parent_theme_name ) ? $this->parent_theme_name : '';
	}

	/**
	 * Get current theme image src
	 */
	public function get_theme_image_src(): string {
		$src = '';

		if ( is_a( $this->theme, 'WP_Theme' ) ) {
			foreach ( [ 'png', 'jpg' ] as $ext ) {
				if ( file_exists( $this->theme->get_template_directory() . '/screenshot.' . $ext ) ) {
					$src = $this->theme->get_template_directory_uri() . '/screenshot.' . $ext;
					break;
				}
			}
		}

		return ! empty( $src ) ? esc_url( $src ) : '';
	}

	/**
	 * Get direct URL to the documentation ot the theme integration.
	 *
	 * @param string $slug Theme slug.
	 */
	public function theme_docs( string $slug ): string {
		return esc_url( Env::$doc_url . 'theme-integrations/' . $slug . '/' );
	}

	/**
	 * All supported themes
	 */
	public function get_supported_themes(): array {
		return [
			[
				'slug' => 'avada',
				'name' => 'Avada',
				'args' => [
					'docs_url'            => $this->theme_docs( 'avada-theme' ),
					'main_breakpoint'     => 800,
					'overridden'          => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
						],
					],
					'integration_scope'   => [
						'color_replacement',
						'breakpoints',
						'css',
						'products_per_page',
					],
					'show_more_as_button' => true,
				],
			],
			[
				'slug' => 'astra',
				'name' => 'Astra',
				'args' => [
					'docs_url'          => $this->theme_docs( 'astra-theme' ),
					'overridden'        => [
						'appearance' => [
							'base_color',
							'link_color',
							// 'pagination_strategy' - added in Themes\Astra class
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'css',
						// 'pagination_strategy' - added in Themes\Astra class
					],
				],
			],
			[
				'slug' => 'blocksy',
				'name' => 'Blocksy',
				'args' => [
					'docs_url'          => $this->theme_docs( 'blocksy-theme' ),
					'main_breakpoint'   => 999,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
					],
				],
			],
			[
				'slug' => 'divi',
				'name' => 'Divi',
				'args' => [
					'docs_url'            => $this->theme_docs( 'divi-theme' ),
					'main_breakpoint'     => 980,
					'overridden'          => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
						],
					],
					'integration_scope'   => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'css',
					],
					'show_more_as_button' => true,
					'sidebar_guide'       => [
						'widgets_type'      => 'blocks',
						'widget_area_id'    => 'sidebar-1',
						'widget_area_label' => 'Sidebar',
					],
				],
			],
			[
				'slug' => 'generatepress',
				'name' => 'GeneratePress',
				'args' => [
					'show_more_as_button' => true,
					'docs_url'            => $this->theme_docs( 'generatepress-theme' ),
					'main_breakpoint'     => 768,
					'overridden'          => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
						],
					],
					'integration_scope'   => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
					],
				],
			],
			[
				'slug' => 'kadence',
				'name' => 'Kadence',
				'args' => [
					'docs_url'          => $this->theme_docs( 'kadence-theme' ),
					'main_breakpoint'   => 1024,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
					],
				],
			],
			[
				'slug' => 'storefront',
				'name' => 'Storefront',
				'args' => [
					'docs_url'        => $this->theme_docs( 'storefront-theme' ),
					'main_breakpoint' => 767,
					'overridden'      => [
						'general' => [
							'main_breakpoint',
						],
					],
					'sidebar_guide'   => [
						'widgets_type'      => 'blocks',
						'widget_area_id'    => 'sidebar-1',
						'widget_area_label' => 'Sidebar',
					],
				],
			],
			[
				'slug' => 'oceanwp',
				'name' => 'OceanWP',
				'args' => [
					'docs_url'          => $this->theme_docs( 'oceanwp-theme' ),
					'main_breakpoint'   => 959,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
					],
				],
			],
			[
				'slug' => 'woodmart',
				'name' => 'Woodmart',
				'args' => [
					'docs_url'          => $this->theme_docs( 'woodmart-theme' ),
					'main_breakpoint'   => 1024,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'mobile_toolbar',
						'css',
					],
				],
			],
			[
				'slug' => 'shoptimizer',
				'name' => 'Shoptimizer',
				'args' => [
					'docs_url'          => $this->theme_docs( 'shoptimizer-theme' ),
					'main_breakpoint'   => 993,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
					],
					'sidebar_guide'     => [
						'widgets_type'      => 'classic',
						'widget_area_id'    => 'sidebar-1',
						'widget_area_label' => 'Sidebar',
					],
				],
			],
			[
				'slug' => 'flatsome',
				'name' => 'Flatsome',
				'args' => [
					'docs_url'          => $this->theme_docs( 'flatsome-theme' ),
					'main_breakpoint'   => 849,
					'mobile_breakpoint' => 549,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
							'mobile_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
					'sidebar_guide'     => [
						'widgets_type'      => 'classic',
						'widget_area_id'    => 'shop-sidebar',
						'widget_area_label' => 'Shop Sidebar',
					],
				],
			],
			[
				'slug' => 'electro',
				'name' => 'Electro',
				'args' => [
					'docs_url'          => $this->theme_docs( 'electro-theme' ),
					'main_breakpoint'   => 1200,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'freestyle',
				'name' => 'Freestyle',
				'args' => [
					'docs_url'          => $this->theme_docs( 'freestyle-theme' ),
					'main_breakpoint'   => 1024,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'rey',
				'name' => 'Rey',
				'args' => [
					'docs_url'          => $this->theme_docs( 'rey-theme' ),
					'main_breakpoint'   => 767,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'pagination_strategy',
						'css',
					],
					'sidebar_guide'     => [
						'widgets_type'      => 'classic',
						'widget_area_id'    => 'shop-sidebar',
						'widget_area_label' => 'Shop Sidebar ',
					],
				],
			],
			[
				'slug' => 'xstore',
				'name' => 'XStore',
				'args' => [
					'docs_url'          => $this->theme_docs( 'xstore-theme' ),
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'color_replacement',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'salient',
				'name' => 'Salient',
				'args' => [
					'docs_url'            => $this->theme_docs( 'salient' ),
					'main_breakpoint'     => 999,
					'overridden'          => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope'   => [
						'breakpoints',
						'color_replacement',
						'css',
					],
					'show_more_as_button' => true,
				],
			],
			[
				'slug' => 'botiga',
				'name' => 'Botiga',
				'args' => [
					'docs_url'            => $this->theme_docs( 'botiga-theme' ),
					'main_breakpoint'     => 990,
					'overridden'          => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							// 'pagination_strategy' - added in Themes\Botiga class
						],
					],
					'integration_scope'   => [
						'breakpoints',
						'color_replacement',
						'products_per_page',
						'off_canvas_position',
						// 'pagination_strategy' - added in Themes\Botiga class
						'css',
					],
					'show_more_as_button' => true,
				],
			],
			[
				'slug' => 'basel',
				'name' => 'Basel',
				'args' => [
					'docs_url'          => $this->theme_docs( 'basel-theme' ),
					'main_breakpoint'   => 1024,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'color_replacement',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'betheme',
				'name' => 'Betheme',
				'args' => [
					'docs_url'          => $this->theme_docs( 'betheme-theme' ),
					'main_breakpoint'   => 767,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'color_replacement',
						'products_per_page',
					],
				],
			],
			[
				'slug' => 'bricks',
				'name' => 'Bricks',
				'args' => [
					'docs_url'          => $this->theme_docs( 'bricks-theme' ),
					'integration_scope' => [
						'products_per_page',
						'css',
						'pagination_strategy',
					],
				],
			],
			[
				'slug' => 'armania',
				'name' => 'Armania',
				'args' => [
					'docs_url'          => $this->theme_docs( 'armania-theme' ),
					'main_breakpoint'   => 1199,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'products_per_page',
						'pagination_strategy',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'elessi-theme',
				'name' => 'Elessi',
				'args' => [
					'docs_url'          => $this->theme_docs( 'elessi-theme' ),
					'main_breakpoint'   => 1024,
					'mobile_breakpoint' => 767,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
							'mobile_breakpoint',
						],
						'appearance' => [
							'base_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'products_per_page',
						'pagination_strategy',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'enfold',
				'name' => 'Enfold',
				'args' => [
					'docs_url'          => $this->theme_docs( 'enfold-theme' ),
					'main_breakpoint'   => 767,
					'mobile_breakpoint' => 479,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
							'mobile_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'the7',
				'name' => 'The7',
				'args' => [
					'docs_url'          => $this->theme_docs( 'the7-theme' ),
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
							'mobile_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'color_replacement',
						'css',
					],
				],
			],
			// This is duplicate of The7 theme with different slug, but same partial filename.
			[
				'slug' => 'dt-the7',
				'name' => 'The7',
				'args' => [
					'partial_filename'  => 'the7.php',
					'docs_url'          => $this->theme_docs( 'the7-theme' ),
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
							'mobile_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'color_replacement',
						'css',
					],
				],
			],
			[
				'slug' => 'savoy',
				'name' => 'Savoy',
				'args' => [
					'docs_url'          => $this->theme_docs( 'savoy-theme' ),
					'main_breakpoint'   => 991,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'products_per_page',
						'off_canvas_position',
						'css',
					],
				],
			],
			[
				'slug' => 'wordpress-theme-atomion',
				'name' => 'WordPress Theme Atomion',
				'args' => [
					'docs_url'          => $this->theme_docs( 'atomion-theme' ),
					'main_breakpoint'   => 768,
					'overridden'        => [
						'general' => [
							'main_breakpoint',
						],
					],
					'integration_scope' => [
						'breakpoints',
						'css',
					],
				],
			],
			[
				'slug' => 'virtue',
				'name' => 'Virtue',
				'args' => [
					'docs_url'          => $this->theme_docs( 'virtue-theme' ),
					'main_breakpoint'   => 991,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'css',
					],
				],
			],
			[
				'slug' => 'partdo',
				'name' => 'Partdo',
				'args' => [
					'docs_url'          => $this->theme_docs( 'partdo-theme' ),
					'main_breakpoint'   => 1023,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'pagination_strategy',
						'css',
					],
				],
			],
			[
				'slug' => 'puca',
				'name' => 'Puca',
				'args' => [
					'docs_url'          => $this->theme_docs( 'puca-theme' ),
					'main_breakpoint'   => 1199,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'css',
					],
				],
			],
			[
				'slug' => 'claue',
				'name' => 'Claue',
				'args' => [
					'docs_url'          => $this->theme_docs( 'claue-theme' ),
					'main_breakpoint'   => 767,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'css',
					],
				],
			],
			[
				'slug' => 'neve',
				'name' => 'Neve',
				'args' => [
					'docs_url'          => $this->theme_docs( 'neve-theme' ),
					'main_breakpoint'   => 959,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						// 'pagination_strategy' - added in Themes\Neve class
					],
				],
			],
			[
				'slug' => 'uncode',
				'name' => 'Uncode',
				'args' => [
					'docs_url'          => $this->theme_docs( 'uncode-theme' ),
					'main_breakpoint'   => 959,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'css',
					],
				],
			],
			[
				'slug' => 'hestia',
				'name' => 'Hestia',
				'args' => [
					'partial_filename'  => 'hestia.php',
					'docs_url'          => $this->theme_docs( 'hestia-theme' ),
					'main_breakpoint'   => 991,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'css',
					],
				],
			],
			// This is duplicate of Hestia theme with different slug, but same partial filename.
			[
				'slug' => 'hestia-pro',
				'name' => 'Hestia',
				'args' => [
					'partial_filename'  => 'hestia.php',
					'docs_url'          => $this->theme_docs( 'hestia-theme' ),
					'main_breakpoint'   => 991,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'breakpoints',
						'pagination_strategy',
						'css',
					],
				],
			],
			[
				'slug' => 'porto',
				'name' => 'Porto',
				'args' => [
					'docs_url'          => $this->theme_docs( 'porto-theme' ),
					'main_breakpoint'   => 991,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'pagination_strategy',
						'breakpoints',
						'css',
					],
				],
			],
			[
				'slug' => 'shopkeeper',
				'name' => 'Shopkeeper',
				'args' => [
					'docs_url'          => $this->theme_docs( 'shopkeeper-theme' ),
					'main_breakpoint'   => 1024,
					'mobile_breakpoint' => 767,
					'overridden'        => [
						'general'    => [
							'main_breakpoint',
							'mobile_breakpoint',
						],
						'appearance' => [
							'base_color',
							'link_color',
							'pagination_strategy',
						],
					],
					'integration_scope' => [
						'color_replacement',
						'pagination_strategy',
						'breakpoints',
						'css',
					],
				],
			],
		];
	}

	/**
	 * Get extra guide steps for the theme integration
	 *
	 * We move this data to separate method to delay the execution of the code.
	 * Without this, notice "Translation loading for the <code>fibofilters</code> domain was triggered too early" is displayed.
	 *
	 * @param array  $extra_guide_steps Extra guide steps.
	 * @param string $theme_slug Theme slug.
	 */
	public function get_extra_guide_steps( array $extra_guide_steps = [], string $theme_slug = '' ): array {
		switch ( $theme_slug ) {
			case 'divi':
				return [
					/* translators: %s: URL address to the WordPress customizer view */
					sprintf( _x( 'Go to <code><a href="%s" target="_blank">Divi -> Theme Options -> General</a></code> and find an option "<b>Shop Page & Category Page Layout for WooCommerce</b>".', '[admin]', 'fibofilters' ), esc_html( admin_url( 'admin.php?page=et_divi_options' ) ) ),
					_x( 'Select <i>Left Sidebar</i> or <i>Right Sidebar</i> and publish changes.', '[admin]', 'fibofilters' ),
				];
			case 'storefront':
				return [
					/* translators: %s: URL address to the WordPress customizer view */
					sprintf( _x( 'Go to <code><a href="%s" target="_blank">Appearance -> Customize -> Layout</a> -> General Layout</code>.', '[admin]', 'fibofilters' ), Helpers::get_customizer_link( '', 'storefront_layout' ) ),
					_x( 'Select <i>Left</i> or <i>Right</i> sidebar and publish changes.', '[admin]', 'fibofilters' ),
				];
			case 'shoptimizer':
				return [
					/* translators: %s: URL address to the WordPress customizer view */
					sprintf( _x( 'Go to <code><a href="%s" target="_blank">Appearance -> Customize -> Layout -> Sidebars</a> -> WooCommerce Sidebar</code>.', '[admin]', 'fibofilters' ), Helpers::get_customizer_link( '', 'shoptimizer_layout_section_sidebars' ) ),
					_x( 'Select <i>Left</i> or <i>Right</i> sidebar and publish changes.', '[admin]', 'fibofilters' ),
				];
			case 'flatsome':
				return [
					/* translators: %s: URL address to the WordPress customizer view */
					sprintf( _x( 'Go to <code><a href="%s" target="_blank">Appearance -> Customize -> WooCommerce -> Product Catalog</a></code>.', '[admin]', 'fibofilters' ), Helpers::get_customizer_link( '', 'woocommerce_product_catalog' ) ),
					_x( 'Scroll to the option <b>Catalog Layout</b>, select <i>Left Sidebar</i> or <i>Right Sidebar</i> and publish changes.', '[admin]', 'fibofilters' ),
				];
			case 'rey':
				return [
					sprintf(
					/* translators: %s: URL address to the WordPress customizer view */
						_x( 'Go to <code><a href="%s" target="_blank">Appearance -> Customize -> WooCommerce -> Catalog Settings -> Grid Components</a></code> -> Sidebar and find an option "<b>Sidebar Position</b>".', '[admin]', 'fibofilters' ),
						Helpers::get_customizer_link( '', 'woo-catalog-grid-components' )
					),
					_x( 'Select <i>Right</i> or <i>Left</i> and publish changes.', '[admin]', 'fibofilters' ),
				];
		}

		return [];
	}

	/**
	 * Load class with compatibilities logic for current theme
	 */
	private function load_integration(): void {
		// Break early if "nofibofilters" = 1 || 2.
		if (
			isset( $_GET['nofibofilters'] ) && in_array( $_GET['nofibofilters'], [ '1', '2' ], true ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
			in_array( apply_filters( 'fibofilters/nofibofilters', '' ), [ '1', '2' ], true )
		) {
			return;
		}

		foreach ( $this->get_supported_themes() as $theme ) {
			if ( $theme['slug'] === $this->theme_slug ) {

				$args = isset( $theme['args'] ) && is_array( $theme['args'] ) ? $theme['args'] : [];

				if ( $this->is_white_label() ) {
					$args['white_label'] = true;
				}

				$args['theme_image'] = $this->get_theme_image_src();

				$alias = $this->container->has( 'themes.' . $theme['slug'] ) ? $theme['slug'] : 'generic_theme';

				$this->container->dich()->add_action( // @phpstan-ignore-line
					"fibofilters/integrations/themes/init/{$alias}",
					[ "themes.{$alias}", 'init' ],
					10,
					3
				);
				do_action( "fibofilters/integrations/themes/init/{$alias}", $theme['slug'], $theme['name'], $args );

				$this->current_integration = [
					'alias'   => $alias,
					'slug'    => $theme['slug'],
					'name'    => $theme['name'],
					'args'    => $args,
					'enabled' => (bool) get_option( 'fibofilters_general_enable_theme_integration_' . $theme['slug'] ),
				];

				break;
			}
		}
	}
}
