<?php

namespace Brandy\WooCommerce;

use Brandy\Traits\SingletonTrait;

class LayoutLibrary {
	use SingletonTrait;

	public function __construct() {

		if ( ! is_admin() ) {
			return;
		}

		add_action( 'enqueue_block_assets', array( $this, 'enqueue_scripts' ) );
	}

	public function enqueue_scripts() {
		
		if ( ! is_wc_installed() ) {
			return;
		}

		wp_enqueue_script(
			'brandy-layout-library',
			BRANDY_TEMPLATE_URL . '/assets/lib/layout-library.js',
			array( 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-i18n', 'wp-edit-post' ),
			BRANDY_VERSION,
			true
		);
		wp_enqueue_style( 'brandy-layout-library', BRANDY_TEMPLATE_URL . '/assets/lib/layout-library.css', array(), BRANDY_VERSION );
		wp_localize_script(
			'brandy-layout-library',
			'brandyLayoutLibraryData',
			array(
				'ajax_url'        => admin_url( 'admin-ajax.php' ),
				'asset_url'       => BRANDY_TEMPLATE_URL . '/assets/',
				'nonce'           => wp_create_nonce( 'updates' ),
			)
		);
	}
}

LayoutLibrary::get_instance();