<?php

namespace CustomerJourneyForWooCommerce;

/**
 * Customer Journey frontend related functionality.
 *
 * @since 1.0.0
 */
class Frontend {

	/**
	 * Initialize.
	 *
	 * @since 1.0.0
	 */
	public function init() {
		add_action( 'wp_head', array( $this, 'enqueues' ) );
	}

	/**
	 * Frontend enqueues.
	 *
	 * @since 1.0.0
	 */
	public function enqueues() {

		wp_enqueue_script(
			'customer-journey',
			plugins_url( 'assets/customer-journey.min.js', CUSTOMER_JOURNEY_FOR_WOOCOMMERCE_PLUGIN_FILE ),
			array(),
			CUSTOMER_JOURNEY_FOR_WOOCOMMERCE_VERSION
		);

		$data = array(
			'is_ssl' => is_ssl(),
		);

		if ( is_singular() ) {
			$data['page_id'] = get_the_ID();
		}

		wp_add_inline_script( 'customer-journey', 'const customer_journey = ' . json_encode( $data ), 'before' );
	}
}
