<?php
namespace PEVFSLite;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! trait_exists( __NAMESPACE__ . '\\Assets' ) ) {
	trait Assets {
		public function init_assets() {
			\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
		}

		public function enqueue_assets( $hook ) {
			$screen			= \get_current_screen();
			$is_plugin_page	= false;
			
			if ( $screen ) {
				$page = isset( $_GET['page'] ) ? $_GET['page'] : '';
				if ( $page === $this->slug || ( isset( $this->params['menu']['slug'] ) && $page === $this->params['menu']['slug'] ) ) {
					$is_plugin_page = true;
				}
			}

			if ( 'plugins.php' === $hook || $is_plugin_page || isset( $_GET['fs_connect'] ) ) {
				$version = $this->sdk_version;
				
				\wp_enqueue_style( 'fs-lite-style', $this->plugin_url . '/build/index.css', array(), $version );

				$assets_path = $this->plugin_path . '/build/index.asset.php';
				if ( \file_exists( $assets_path ) ) {
					$assets = require $assets_path;
					\wp_enqueue_style( 'dashicons' );
					\wp_enqueue_script( 
						'fs-lite-script', 
						$this->plugin_url . '/build/index.js', 
						\array_merge( $assets['dependencies'], array( 'wp-util' ) ), 
						$version, 
						true 
					);
				}
			}
		}

		public function add_standalone_body_class( $classes ) {
			return $classes . ' fs-standalone ';
		}
	}
}
