<?php

namespace BSD_Split_Pay_Stripe_Connect_Woo\Inc\Admin;

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'BSD_Split_Pay_Stripe_Connect_Woo\Inc\Admin\bsd_scsp_admin_enqueue' ) ) {
	function bsd_scsp_admin_enqueue() {
		$wp_screen       = get_current_screen();
		$allowed_screens = array(
			'woocommerce_page_bsd-split-pay-stripe-connect-woo-settings',
			'toplevel_page_bsd-split-pay-stripe-connect-woo-settings',
			'product',
			'fluent-products',
			'pewc_group',
		);

		if ( $wp_screen && in_array( $wp_screen->id, $allowed_screens ) ) {
			wp_register_style( 'bsd_scsp_admin', plugins_url( '/includes/admin/assets/css/bsd-split-pay-stripe-connect-woo-admin.css', SPP_PLUGIN_URL ), array(), SPP_PLUGIN_VER );
			wp_enqueue_style( 'bsd_scsp_admin' );

			wp_register_style( 'bsd_scsp_data_tables', plugins_url( '/includes/vendor/jquery-data-tables/jquery.dataTables.min.css', SPP_PLUGIN_URL ) );
			wp_enqueue_style( 'bsd_scsp_data_tables' );

			wp_register_script( 'bsd_scsp_data_tables', plugins_url( '/includes/vendor/jquery-data-tables/jquery.dataTables.min.js', SPP_PLUGIN_URL ), '1.0.0', true );
			wp_enqueue_script( 'bsd_scsp_data_tables' );

			wp_register_style( 'bsd_select2_style', SPP_PLUGIN_URI . '/includes/vendor/select2/select2.min.css', array(), SPP_PLUGIN_VER );
			wp_enqueue_style( 'bsd_select2_style' );

			wp_register_script( 'bsd_select2_script', SPP_PLUGIN_URI . 'includes/vendor/select2/select2.min.js', array( 'jquery' ), SPP_PLUGIN_VER, true );
			wp_enqueue_script( 'bsd_select2_script' );

			wp_register_script( 'bsd_plugin_admin_script', SPP_PLUGIN_URI . 'includes/admin/assets/js/bsd-spscwa.js', array( 'jquery' ), SPP_PLUGIN_VER, true );
			wp_enqueue_script( 'bsd_plugin_admin_script' );

			wp_register_script( 'bsd_plugin_admin_build_script', SPP_PLUGIN_URI . 'includes/admin/assets/js/main.js', array( 'jquery' ), SPP_PLUGIN_VER, true );
			wp_enqueue_script( 'bsd_plugin_admin_build_script' );

			$bsd_admin_plugin_vars = array(
				'ajax_url'                 => admin_url( 'admin-ajax.php' ),
				'can_use_premium_code'     => \BSD_Split_Pay_Stripe_Connect_Woo\bsdwcscsp_fs()->can_use_premium_code(),
				'bsd_scsp_plugin_uri'      => SPP_PLUGIN_URI,
				'plugin_admin_setting_url' => admin_url( 'admin.php?page=bsd-split-pay-stripe-connect-woo-account' ),
				'security' => wp_create_nonce( 'ajax-security' ),
				// 3.7.5 a11y: accessible names for the per-row <select>s that JS adds at
				// runtime (the "add new account" cloners). Mirrors the aria-labels the
				// PHP partials set on the server-rendered rows. See bsd-spscwa.js.
				'a11y_labels' => array(
					'transfer_type'          => __( 'Transfer type', 'bsd-split-pay-stripe-connect-woo' ),
					'shipping_transfer_type' => __( 'Global shipping transfer type', 'bsd-split-pay-stripe-connect-woo' ),
					'connected_account'      => __( 'Connected Stripe account', 'bsd-split-pay-stripe-connect-woo' ),
					'filter_field'           => __( 'Filter field', 'bsd-split-pay-stripe-connect-woo' ),
					'filter_match_type'      => __( 'Match type', 'bsd-split-pay-stripe-connect-woo' ),
					'filter_categories'      => __( 'Product categories', 'bsd-split-pay-stripe-connect-woo' ),
					'filter_search_text'     => __( 'Search text', 'bsd-split-pay-stripe-connect-woo' ),
				),
			);

			wp_localize_script( 'bsd_plugin_admin_script', 'bsd_admin_plugin_vars', $bsd_admin_plugin_vars );
		}
	}
}
