<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

if( !class_exists( 'HouseFixProCursor' ) ) {
    class HouseFixProCursor {

        private static $_instance = null;

        private $enable_cursor_effect = false;
        private $cursor_type = 'type-1';
        private $cursor_link_hover_effect = '';
        private $cursor_lightbox_hover_effect = '';

        public static function instance() {
            if ( is_null( self::$_instance ) ) {
                self::$_instance = new self();
            }

            return self::$_instance;
        }

        function __construct() {
            $this->enable_cursor_effect = housefix_customizer_settings( 'enable_cursor_effect' );
            $this->cursor_type = housefix_customizer_settings( 'cursor_type' );
            $this->cursor_link_hover_effect = housefix_customizer_settings( 'cursor_link_hover_effect' );
            $this->cursor_lightbox_hover_effect = housefix_customizer_settings( 'cursor_lightbox_hover_effect' );
            $this->load_modules();
            $this->frontend();
        }

        function load_modules() {
            include_once HOUSEFIX_PRO_DIR_PATH.'modules/cursor/customizer/index.php';
        }

        function frontend() {
            if($this->enable_cursor_effect) {
                add_action( 'housefix_after_main_css', array( $this, 'enqueue_assets' ) );
                add_action( 'housefix_hook_top', array( $this, 'load_template' ) );
            }
        }

        function enqueue_assets() {
            if($this->enable_cursor_effect) {
                wp_enqueue_style( 'housefix-cursor', HOUSEFIX_PRO_DIR_URL . 'modules/cursor/assets/css/cursor.css', false, HOUSEFIX_PRO_VERSION, 'all');
                wp_enqueue_script( 'housefix-cursor', HOUSEFIX_PRO_DIR_URL . 'modules/cursor/assets/js/cursor.js', array('jquery'), HOUSEFIX_PRO_VERSION, true );
                wp_localize_script('housefix-cursor', 'wdtCursorObjects', array (
                    'enableCursorEffect' => $this->enable_cursor_effect
                ));
            }
        }

        function load_template() {
            echo '<div class="wdt-cursor-wrapper '.esc_attr($this->cursor_type).' '.esc_attr($this->cursor_link_hover_effect).' '.esc_attr($this->cursor_lightbox_hover_effect).'">
                    <div class="wdt-cursor wdt-cursor-outer"></div>
                    <div class="wdt-cursor wdt-cursor-inner"></div>
                </div>';
        }

    }
}

HouseFixProCursor::instance();
