<?php
/**
 * WooBooking! Content Management System
 *
 * Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace WpBookingEvent\Document;


use WpBookingEvent\Factory;
use WpBookingEvent\Utilities\Utility;

defined('_WPBOOKINGEVENT_EXEC') or die;



/**
 * Document class, provides an easy interface to parse and display a document
 *
 
 */
class Document
{
    /**
     * @var Document
     */
    private static $instance;
	/**
	 * Array of linked scripts
	 *
	 * @var    array
	 
	 */
	public $_scripts = array();

	/**
	 * Array of scripts placed in the header
	 *
	 * @var    array
	 
	 */
	public $_script = array();

	/**
	 * Array of linked style sheets
	 *
	 * @var    array
	 
	 */
	public $_styleSheets = array();
    /**
     * @var array
     */
    public $_lessStyleSheets = array();

	/**
	 * Array of included style declarations
	 *
	 * @var    array
	 
	 */
	public $_style = array();

    /**
     * Document constructor.
     * @param array $options
     */
    public function __construct($options = array())
	{

	}

    /**
     * @param $url
     */
    public function addScript($url)
	{
	    if(!in_array($url,$this->getScripts()))
        {
            $this->_scripts[]= $url;
        }
	}

    /**
     * @return array
     */
    public function getScripts(){
	    return $this->_scripts;
    }

    /**
     * @param string $selector
     * @param $function_name
     * @param $config
     */
    public function addScriptApplySelector($selector, $function_name, $config,$url)
	{
        ob_start();
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                $('<?php  echo ($selector) ?>').<?php  echo ($function_name) ?>(<?php echo (json_encode($config)) ?>);
            });
        </script>
        <?php
        $content=ob_get_clean();
        $content=Utility::remove_string_javascript($content);
        $this->_script[] = $content;
        $this->addScript($url);
    }

    /**
     * @param $content
     */
    public function addScriptDeclaration($content)
	{
        $this->_script[] = $content;
	}
    /**
     * @return array
     */
    public function getScript()
	{
        return $this->_script;
	}

    /**
     * @param $url
     */
    public function addStyleSheet($url)
	{
        $this->_styleSheets[]=$url;
	}

    /**
     * @return array
     */
    public function getStyleSheets(){
	    return $this->_styleSheets;
    }

    /**
     * @param $url
     */
    public function addLessStyleSheet($url)
	{
        $this->_lessStyleSheets[]=$url;
	}

    /**
     * @return array
     */
    public function getLessStyleSheets(){
	    return $this->_lessStyleSheets;
    }

    /**
     * @param $content
     */
    public function addStyleDeclaration($content)
	{
        $this->_style[] = $content;
	}


}
