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

    public $plugin_options = array();
    public $discounts = array();

    public function __construct() {

       $this->plugin_options = get_option( 'dspilot_options', [] );
       $this->discounts = $this->plugin_options['discounts'] ?? [];


        add_action( 'init', array( $this, 'init' ) );
        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_public_scripts' ) );
        add_action( 'plugins_loaded', array( $this, 'includes' ) );
        register_activation_hook( __FILE__, array( $this, 'activate' ) );
        register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
   
    }

    public function init() {
        // Initialize the plugin
    }

    public function activate() {
        // Code to run on plugin activation
    }

    public function deactivate() {
        // Code to run on plugin deactivation
    }

    // enqueue scripts and styles
    public function enqueue_admin_scripts() {
        wp_enqueue_style( 'discountpilot-dynamic-pricing-admin', plugin_dir_url( __FILE__ ) . 'admin/assets/css/admin.css', array(), '1.0.0' );
        wp_enqueue_script( 'discountpilot-dynamic-pricing-admin', plugin_dir_url( __FILE__ ) . 'admin/assets/js/admin.js', array( 'jquery','dspilot-plugins', 'discountpilot-dynamic-pricing' ), '1.0.0', true );
    
        // localize script
        wp_localize_script( 'discountpilot-dynamic-pricing-admin', 'dspilot_admin', array(    
            'ajax_url' => admin_url( 'admin-ajax.php' ),
            'nonce'    => wp_create_nonce( 'dspilot_admin_nonce' ),
            'settings' => $this->get_plugin_options(),
        ) );
    
    }

    // enqueue scripts and styles
    public function enqueue_public_scripts() {
        wp_enqueue_style( 'discountpilot-dynamic-pricing-public', plugin_dir_url( __FILE__ ) . 'public/assets/css/public.min.css', array(), '1.0.0' );
        wp_enqueue_script( 'discountpilot-dynamic-pricing-public', plugin_dir_url( __FILE__ ) . 'public/assets/js/public.js', array( 'jquery' ), '1.0.0', true );
    
        // localize script
        wp_localize_script( 'discountpilot-dynamic-pricing-public', 'dspilot_public', array(    
            'ajax_url' => admin_url( 'admin-ajax.php' ),
            'nonce'    => wp_create_nonce( 'dspilot_public_nonce' ),
            'settings' => $this->get_plugin_options(),
        ) );
    
    }

    public function includes () {
        // Include necessary files
        
        //include_once 'admin/admin-init.php';
        include 'admin/includes/framework/framework.php';
        include 'admin/includes/class.helper.php';
        include 'admin/includes/class.ajax.php';
        include 'admin/includes/admin.settings.php';
        include 'admin/includes/class.plugin.php';
        include 'admin/includes/class.coupon-discount.php';
        include 'admin/includes/class.pricing-discount.php';
        include 'admin/includes/class.view-single-product.php';
        
    }

    public function get_plugin_options() {
        // Get plugin options
        $options = get_option( 'dspilot_options' );
        if ( ! is_array( $options ) ) {
            $options = array();
        }
        $this->plugin_options = $options;
        return $this->plugin_options;
    }

}
new Dspilot_Dynamic_Pricing();