<?php

namespace Hecate\Customizer;

use Hecate\Components\ComponentsRepository;
use Hecate\Lodash;

class CustomizerJsData {

	private static $instance = null;



	protected function __construct() {
		add_action( 'customize_controls_enqueue_scripts', array( $this, 'export' ) );
       // add_action('wp_enqueue_scripts', array($this, 'export'));
	}


	public function export() {
		$data = $this->getCustomizerJsData();
		wp_localize_script( 'hecate-customizer-scripts', 'hecateCustomizerData', $data );

	}

	public function getCustomizerJsData() {
		$data = array(
			'rootComponents'             => ComponentsRepository::getInstance()->getRootComponents(),
			'dynamicComponentsStructure' => DynamicComponentsTemplate::getInstance()->exportToJs(),
		);

		return $data;

	}

	public static function init() {
		return self::getInstance();
	}

	public static function getInstance() {
		if ( ! self::$instance ) {
			self::$instance = new static();
		}

		return self::$instance;
	}
}
