<?php
/**
 * Plugin Name: Video Reviews for WooCommerce – Willro Reviews
 * Plugin URI: https://willro.com
 * Description: Display Willro business reviews on your website using API with multiple templates
 * Version: 1.1.0
 * Requires at least: 6.0
 * Requires PHP: 7.4
 * Author: willro
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: willro-reviews
 */

defined('ABSPATH') || exit;

final class Willro_Reviews {

    const VERSION = '1.1.0';

    private static $instance = null;

    public static function instance() {
        if ( null === self::$instance ) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    private function __construct() {
        $this->define_constants();
        $this->includes();
        $this->init_hooks();
    }

    private function define_constants() {
        if ( ! defined( 'WILLRO_REVIEWS_PATH' ) ) {
            define( 'WILLRO_REVIEWS_PATH', plugin_dir_path( __FILE__ ) );
        }
        if ( ! defined( 'WILLRO_REVIEWS_URL' ) ) {
            define( 'WILLRO_REVIEWS_URL', plugin_dir_url( __FILE__ ) );
        }
        if ( ! defined( 'WILLRO_REVIEWS_VERSION' ) ) {
            define( 'WILLRO_REVIEWS_VERSION', self::VERSION );
        }
        if ( ! defined( 'WILLRO_REVIEWS_API_URL' ) ) {
            define(
                'WILLRO_REVIEWS_API_URL',
                'https://prod.willro.com/api/v1/integration/business-api'
            );
        }
    }

    private function includes() {
        // Core renderer (must be first)
        require_once WILLRO_REVIEWS_PATH . 'includes/class-renderer.php';

        require_once WILLRO_REVIEWS_PATH . 'includes/class-shortcode.php';
        require_once WILLRO_REVIEWS_PATH . 'includes/class-assets.php';
        require_once WILLRO_REVIEWS_PATH . 'includes/class-admin-menu.php';
        require_once WILLRO_REVIEWS_PATH . 'includes/block-willro-reviews.php';

        require_once WILLRO_REVIEWS_PATH . 'includes/class-willro-reviews-rest.php';
    }

    private function init_hooks() {
        new Willro_Reviews_Shortcode();
        new Willro_Reviews_Assets();
        new Willro_Reviews_Admin_Menu();
        new Willro_Reviews_REST();

        add_filter('safe_style_css', function($styles){
            $extra = [
                'align-content',
                'align-items',
                'background',
                'background-color',
                'border-radius',
                'bottom',
                'box-shadow',
                'color',
                'column-gap',
                'display',
                'flex',
                'flex-direction',
                'flex-wrap',
                'font-size',
                'font-weight',
                'gap',
                'grid-gap',
                'grid-template-columns',
                'height',
                'justify-content',
                'left',
                'line-height',
                'margin',
                'margin-bottom',
                'margin-left',
                'margin-right',
                'margin-top',
                'max-height',
                'max-width',
                'min-height',
                'min-width',
                'overflow',
                'padding',
                'padding-bottom',
                'padding-left',
                'padding-right',
                'padding-top',
                'position',
                'right',
                'row-gap',
                'text-align',
                'text-decoration',
                'top',
                'transform',
                'transition',
                'white-space',
                'width',
            ];

            return array_values(array_unique(array_merge($styles, $extra)));
        });

        // Elementor widget register
        add_action('elementor/widgets/register', function($widgets_manager){
            if(defined('ELEMENTOR_PATH') && class_exists('Elementor\Widget_Base')) {
                require_once WILLRO_REVIEWS_PATH . 'includes/class-elementor-widget.php';
                $widgets_manager->register(new \Willro_Reviews_Elementor());
            }
        });

    }
}

// Bootstrap plugin
Willro_Reviews::instance();
