<?php
/**
 * Sticky Elementor - Widget Loader
 *
 * Adds sticky controls to Elementor containers.
 *
 * @package StickyElementor
 */

use Elementor\Controls_Manager;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Wplta_Widget_Loader {

	private static $instance = null;

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

	public function __construct() {
		// Scripts सिर्फ backend में ही लोड होंगे
		add_action( 'admin_enqueue_scripts', array( $this, 'wplta_enqueue_scripts' ) );
	}

	public function wplta_enqueue_scripts( $page ) {
		// Permission check
		if ( ! current_user_can( 'manage_options' ) ) {
			return;
		}

		// सही page check
		if ( 'toplevel_page_wplta-dashboard' !== $page ) {
			return;
		}

		$current_user = wp_get_current_user();

		wp_enqueue_script(
			'wplta-db-build',
			WPLTA_PLUGIN_URL . 'build/index.js',
			array( 'wp-i18n', 'wp-element', 'wp-components' ),
			WPLTA_VERSION,
			true
		);

		wp_enqueue_style(
			'wplta-db-build',
			WPLTA_PLUGIN_URL . 'build/index.css',
			array(),
			WPLTA_VERSION
		);

		wp_localize_script(
			'wplta-db-build',
			'wplta_track_object',
			array(
				'ajax_url'            => admin_url( 'admin-ajax.php' ),
				'nonce'               => wp_create_nonce( 'wplta-db-nonce' ),
				'sptrack_wp_version'  => get_bloginfo( 'version' ),
				'sptrack_user_name'   => $current_user->display_name,
				'sptrack_user_avatar' => get_avatar_url( $current_user->ID ),
				'wplta_plugin_url'    => WPLTA_URL
			)
		);
	}
}


	Wplta_Widget_Loader::get_instance();

