<?php
/**
 * Opalestate_Admin
 *
 * @package    opalestate
 * @author     Opal  Team <info@wpopal.com >
 * @copyright  Copyright (C) 2019 wpopal.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * @website  http://www.wpopal.com
 * @support  http://www.wpopal.com/support/forum.html
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

/**
 * @Class Wpopal_Core_Setup
 *
 * Entry point class to setup load all files and init working on frontend and process something logic in admin
 */
class Opalestate_Admin {
	/**
	 * Opalestate_Admin constructor.
	 */
	public function __construct() {
		add_action( 'init', [ $this, 'setup' ] );
		add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
	}

	/**
	 * enqueue editor.js for edit mode
	 */
	public function enqueue_scripts() {
		wp_enqueue_style( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/admin.css', [], '3.0.3' );

		$suffix = '';
		wp_enqueue_style( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/css/select2.min.css', null, '1.3' );
		wp_enqueue_script( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/js/select2.min.js', null, '1.3', true );

		wp_enqueue_script( 'opalestate-country-select', OPALESTATE_PLUGIN_URL . 'assets/js/country-select.js', [ 'jquery' ], null, true );
		wp_enqueue_script( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', [ 'jquery' ], null, true );
	}

	/**
	 * Include all files from supported plugins.
	 */
	public function setup() {
		$this->includes( [
			'cron-jobs-functions.php',
			'agent/class-agent.php',
			'property/class-property.php',
			'agency/class-agency.php',
			'rating/class-rating.php',
			'class-user.php',
		] );

		/// 
		$this->includes( [
			'settings/base.php',
			'settings/api_keys.php',
			'settings/email.php',
			'settings/3rd_party.php',
			'settings/searcharea.php',
			'settings/general.php',
			'settings/property.php',
		] );

		// 

		// Get it started
		$Opalestate_Settings = new Opalestate_Plugin_Settings();

	}

	/**
	 * Include list of collection files
	 *
	 * @var array $files
	 */
	public function includes( $files ) {
		foreach ( $files as $file ) {
			$this->_include( $file );
		}
	}

	/**
	 * include single file if found
	 *
	 * @var string $file
	 */
	private function _include( $file = '' ) {
		$file = OPALESTATE_PLUGIN_DIR . 'inc/admin/' . $file;
		if ( file_exists( $file ) ) {
			include_once $file;
		}
	}
}

new Opalestate_Admin();
