<?php

defined( 'ABSPATH' ) or exit( 'Hey, what are you doing here? You silly human!' );
if ( !class_exists( 'Dusky_Analytics' ) ) {
    class Dusky_Analytics {
        private static $instance = null;

        public function __construct() {
            $is_analytics = dusky_get_settings( 'enableAnalytics', false );
            if ( dusky_fs()->is_free_plan() ) {
                add_action( 'dusky_add_submenu_page', [$this, 'add_analytics_menu'] );
            } elseif ( dusky_fs()->can_use_premium_code__premium_only() && $is_analytics ) {
                add_action( 'dusky_add_submenu_page', [$this, 'add_analytics_menu'] );
                add_action( 'wp_dashboard_setup', [$this, 'dashboard_widgets__premium_only'] );
                add_action( 'wp_ajax_dusky_filter_dashboard_usage', [$this, 'dusky_filter_dashboard_usage__premium_only'] );
                add_action( 'wp_ajax_nopriv_dusky_filter_dashboard_usage', [$this, 'dusky_filter_dashboard_usage__premium_only'] );
                add_action( 'wp_ajax_dusky_frontend_toggle', [$this, 'dusky_frontend_toggle__premium_only'] );
                add_action( 'wp_ajax_nopriv_dusky_frontend_toggle', [$this, 'dusky_frontend_toggle__premium_only'] );
                add_action( 'wp_ajax_dusky_get_analytics', [$this, 'dusky_get_analytics_data__premium_only'] );
                add_action( 'wp_ajax_nopriv_dusky_get_analytics', [$this, 'dusky_get_analytics_data__premium_only'] );
                add_action( 'wp', [$this, 'track_visitors__premium_only'] );
            }
        }

        public function add_analytics_menu( Dusky_Admin $admin ) {
            $admin->add_dusky_submenu(
                'analytics',
                'dusky-dark-mode',
                __( 'Analytics - Dusky Dark Mode', 'dusky-dark-mode' ),
                __( 'Analytics', 'dusky-dark-mode' ),
                'manage_options',
                'dusky-analytics',
                [$this, 'render_dusky_analytics']
            );
        }

        public function render_dusky_analytics() {
            echo '<div id="dusky-analytics-wrap"></div>';
        }

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

    }

}
Dusky_Analytics::instance();