<?php 
namespace UltraAddons\Library\Demo;

use UltraAddons\Library\Demo_Library_Source;
use Elementor\Plugin;

defined('ABSPATH') || die();

/**
 * Theme Demo Controler Root Class
 * We will not actually use this Class directly
 * 
 * Actually I have added and extended class
 * inside base folder of UltraAddons Plugin
 * 
 * @since 1.1.0.9
 * @author Saiful Islam <codersaiful@gmail.com>
 * 
 * @package UltraAddons
 */
class Theme_Demo{

    public static $permalink_prefix = 'library';
    public static $templates_permalink = 'wp-json/%s/v2/templates';
    public static $template_permalink = 'wp-json/%s/v2/template/';
    private static $default_root_site = 'https://library.ultraaddons.com/';
    public static $root_site;
    
    public static $theme_demo_args;

    /**
	 * Instance for Main Class
	 * Called from actiovation instance
	 *
	 * @var Object
	 */
    public static $_instance;

    /**
	 * Instance
	 *
	 * Ensures only one instance of the class is loaded or can be loaded.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 * @static
	 *
	 * @return UltraElementor An instance of the class.
	 */
	public static function instance() {

		if ( is_null( self::$_instance ) ) {
			self::$_instance = new self();
		}
		return self::$_instance;

	}

    /**
     * Loading Library Manager from Theme Demo Control part 
     * Library Manager
     * 
     * 
     *
     * @return void
     */
    public static function load(){
        Demo_Library_Manager::init();
    }
    


    
    /**
     * Based on this method, We will handle
     *
     * @return array
     */
    public static function get_demo_info():array
    {
        
        if( ! is_array( self::$theme_demo_args ) ){
            self::$theme_demo_args = [];
        } 



        $default_args = [
            'root_site' => self::$default_root_site,
            'button' => [
                'text'	=> esc_html__( "Theme Demo", 'ultraaddons-elementor-lite' ),
                'icon'	=> 'uicon-ultraaddons',
                'position' => 999,
            ],
            'tabs' => [
                'section' => esc_html__( "Blocks", 'ultraaddons-elementor-lite' ),
                'page' => esc_html__( "Pages", 'ultraaddons-elementor-lite' ),
                'landing' => esc_html__( "Landing", 'ultraaddons-elementor-lite' ),
            ],
            'library_icon'      => 'eicon-gallery-grid',
            'library_title'     => esc_html__( "THEME DEMOS", 'ultraaddons-elementor-lite' ),
            'back_button_text' => esc_html__( 'Back to Library', 'ultraaddons-elementor-lite' ),
            'lern_more_message' => esc_html__( 'Learn more about UltraAddons Template Library.', 'ultraaddons-elementor-lite' ),
            'page_templates' => 'https://ultraaddons.com/templates/',

        ];
        $merrged_args = wp_parse_args( self::$theme_demo_args, $default_args );

        //Fixing root_site
        if( empty( $merrged_args['root_site'] ) ){
            $merrged_args['root_site'] = self::$default_root_site;
        }
        self::$root_site = $merrged_args['root_site'];
        $merrged_args['permalink'] = self::$permalink_prefix;
        $merrged_args['templates'] = self::$root_site . sprintf( self::$templates_permalink, self::$permalink_prefix );
        $merrged_args['template'] = self::$root_site . sprintf( self::$template_permalink, self::$permalink_prefix );

        self::$theme_demo_args = apply_filters( 'ultraaddons_eldm_theme_demo_args', $merrged_args );


        return self::$theme_demo_args;
    }

    /**
     * To set demo details infor
     * we can use this method
     *
     * @param array $ultraaddons_args
     * @return object
     */
    public static function set_demo_info( array $ultraaddons_args ) 
    {
        if( ! is_array( $ultraaddons_args ) ) return null;
        self::$theme_demo_args = $ultraaddons_args;
        return self::$_instance;
    }

    /**
     * To set Root site for your theme
     * 
     *
     * @param string $root_site_url
     * @return object
     */
    public static function setRootSite( string $root_site_url ) 
    {
        if( empty( $root_site_url ) || ! is_string( $root_site_url ) ) return null;
        self::$theme_demo_args['root_site'] = $root_site_url;
        return self::$_instance;
    }



}