<?php
/**
 * Includes public assets.
 *
 * @package flo-sync
 */

namespace NMFS;

defined( 'ABSPATH' ) || exit;

/**
 * Class Assets
 */
class Assets {
	/**
	 * Assets constructor.
	 */
	public static function setup(): void {
		add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_admin_scripts' ) );
	}

	/**
	 * Enqueue scripts.
	 */
	public static function enqueue_scripts(): void {
		wp_enqueue_script(
			'nmf_sync_frontend_script',
			Shared::instance()->assets->get_package_assets_url() . 'js/northmill-sync-frontend.js',
			array( 'jquery' ),
			filemtime( Shared::instance()->assets->get_package_assets_path() . 'js/northmill-sync-frontend.js' ),
			true
		);

		$ajax = Shared::instance()->ajax->get_action( 'update_shipping_store' );
		wp_localize_script(
			'nmf_sync_frontend_script',
			'nmf_sync_frontend_script_vars',
			array(
				'ajax_url'                   => admin_url( 'admin-ajax.php' ),
				'shipping_store_update_ajax' => $ajax->get_data_for_js(),
			)
		);

		wp_enqueue_style(
			'nmf_sync_frontend_style',
			Shared::instance()->assets->get_package_assets_url() . 'css/northmill-sync-frontend.css',
			array(),
			filemtime( Shared::instance()->assets->get_package_assets_path() . 'css/northmill-sync-frontend.css' ),
		);
	}

	/**
	 * Enqueue admin scripts.
	 */
	public static function enqueue_admin_scripts(): void {
		wp_enqueue_script(
			'northmill-sync-script',
			Shared::instance()->assets->get_package_assets_url() . 'js/northmill-sync.js',
			array( 'jquery' ),
			filemtime( Shared::instance()->assets->get_package_assets_path() . 'js/northmill-sync.js' ),
			true
		);

		wp_localize_script(
			'northmill-sync-script',
			'mf_sync_script_vars',
			array(
				'sku_required'                => __( 'SKU must be set in the Inventory tab.', 'flo-sync' ),
				'title_required'              => __( 'Product name must be set.', 'flo-sync' ),
				'regular_price_required'      => __( 'Regular price must be set in the General tab.', 'flo-sync' ),
				'variants_sku_price_required' => __( 'SKU and Regular price must be set in all the variants.', 'flo-sync' ),
				'ajax_url'                    => admin_url( 'admin-ajax.php' ),
			)
		);
	}
}
