<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Enqueues all necessary CSS and JavaScript assets for the Sifency Theme Builder module.
 */
class Sifency_Assets {

	public function __construct() {
		add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
	}

	public function enqueue_admin_assets( $hook ) {
		$screen = get_current_screen();

		// Load assets for all Sifency builder pages
		if ( ! $screen || strpos( $screen->id, 'sifency' ) === false ) {
			return;
		}

		wp_enqueue_style( 'select2', SIFENCY_TB_URL . 'assets/css/select2.min.css', [], '4.0.13' );
		wp_enqueue_script( 'select2', SIFENCY_TB_URL . 'assets/js/select2.min.js', [ 'jquery' ], '4.0.13', true );
		wp_enqueue_style( 'sifency-addons-admin-tb', SIFENCY_TB_URL . 'assets/css/admin.css', [], SIFENCY_TB_VERSION );
		wp_enqueue_script( 'sifency-addons-admin-tb', SIFENCY_TB_URL . 'assets/js/admin.js', [ 'jquery', 'select2' ], SIFENCY_TB_VERSION, true );

		wp_localize_script( 'sifency-addons-admin-tb', 'sifency_tb_admin', [
			'ajax_url' => admin_url( 'admin-ajax.php' ),
			'nonce'    => wp_create_nonce( 'sifency_admin_nonce' ),
			'i18n'     => [
				'loading' => __( 'Loading...', 'sifency-addons' ),
				'error'   => __( 'An error occurred.', 'sifency-addons' ),
				'saved'   => __( 'Saved!', 'sifency-addons' ),
			],
		]);
	}

}