<?php
/**
 * The file that defines the core plugin class
 *
 * @since      1.0.0
 *
 * @package    captain-widgets-kit
 * @subpackage captain-widgets-kit/hooks
 */

/**
 * Exit if accessed directly.
 *
 * @since 1.0.0
 * */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Main class to load Hooks Files
 *
 * @since 1.0.0
 * */
if ( ! class_exists( 'Captwiki_Hooks' ) ) {

	/**
	 * Captwiki_Hooks
	 *
	 * @since 1.0.0
	 */
	class Captwiki_Hooks {

		/**
		 * Member Variable
		 *
		 * @var instance
		 */
		private static $instance;

		/**
		 *  Initiator
		 */
		public static function get_instance() {
			if ( ! isset( self::$instance ) ) {
				self::$instance = new self();
			}

			return self::$instance;
		}

		/**
		 * Define the core functionality of the plugin.
		 */
		public function __construct() {
			add_action( 'captwiki_set_settings', array( $this, 'captwiki_set_settings' ), 10 );
		}

		/**
		 * Create Default setting data in db
		 *
		 * @since 1.0.0
		 */
		public function captwiki_set_settings() {

			$captwiki_settings = get_option( 'captwiki_settings', false );
			if ( empty( $captwiki_settings ) ) {
				$default_widgets    = $this->get_default_widgets();
				$default_extensions = $this->get_default_extensions();

				$settings_options = array(
					'captwiki_theme' => 'default',
					'cleanup_db'     => false,
					'storage'        => 'files',
					'widgets'        => $default_widgets,
					'extensions'     => $default_extensions,
				);

				add_option( 'captwiki_settings', $settings_options );
			}

			if ( false === get_option( 'captwiki_wp_extensions', false ) ) {
				add_option(
					'captwiki_wp_extensions',
					array(
						'extensions' => array(),
						'settings'   => array(),
					)
				);
			}
		}

		/**
		 * Get default widgets.
		 *
		 * @return array Default widgets.
		 */
		public function get_default_widgets() {
			return array(
				'captwiki-button',
				'captwiki-post-author',
				'captwiki-post-comments',
				'captwiki-post-content',
				'captwiki-post-title',
				'captwiki-separator',
				'captwiki-site-logo',
				'captwiki-dual-button',
			);
		}

		/**
		 * Get default extensions.
		 *
		 * @return array Default extensions.
		 */
		public function get_default_extensions() {
			return array(
				'Captwiki_Device_Type',
				'Captwiki_Browser_Compatibility',
				'Captwiki_Custom_Css',
				'Captwiki_Location',
				'Captwiki_Weekdays_Visibility',
				'Captwiki_Date_Time_Visibility',
				'Captwiki_Custom_JS',
				'Captwiki_Wrapper_Link',
				'Captwiki_Operating_System',
				'Captwiki_URL_Conditions',
			);
		}
	}

	Captwiki_Hooks::get_instance();
}
