<?php
/**
 * Handled all hooks related to EasyDigitalDownloads for Revio
 *
 * @package RVIOR
 */

namespace RVIOR;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit( 1 );


if ( ! class_exists( __NAMESPACE__ . '\EasyDigitalDownloads' ) ) {

	/**
	 * Handled all hooks related to EasyDigitalDownloads for Revio
	 *
	 * @package RVIOR
	 */
	class EasyDigitalDownloads extends \RVIOR\Base\Controller {

		// Use Utilities trait.
		use \RVIOR\Traits\Utilities;

		/**
		 * Register the hooks
		 *
		 * @return void
		 */
		public function register_hooks() {
			$this->init_extension();
			$this->add_actions();
			$this->add_filters();
		}

		/**
		 * Initialize the extension
		 *
		 * @return mixed
		 */
		public function init_extension() {
			require_once __DIR__ . '/class-easy-digital-downloads-extension.php';

			// Initialize the extension.
			\RVIOR\Extensions\EasyDigitalDownloads::init();
		}

		/**
		 * Add action hooks
		 *
		 * @return mixed
		 */
		public function add_actions() {
			// Check if the user has premium access.
			// Modifying this section will cause the plugin to break.
			if ( ! $this->client()->has_premium_access() ) {
				return false;
			}

			add_action('edd_payment_receipt_after', [ $this, 'add_recording_button' ], 12);
			add_action('edd_email_footer', [ $this, 'rvior_edd_email_footer' ], 12);
		}

		/**
		 * Add record button after the order complete page
		 *
		 * @return mixed
		 */
		public function add_recording_button() {
			$edd_option = (array) $this->option()->get('edd');

			if ( '1' !== $edd_option['order_complete_button'] ) {
				return false;
			}

			echo wp_kses_post(do_shortcode('[rvior-button folder="edd-review"]'));
		}


		/**
		 * Add record button to the email footer
		 *
		 * @return mixed
		 */
		public function rvior_edd_email_footer() {
			$edd_option = (array) $this->option()->get('edd');
			if ( '1' !== $edd_option['order_complete_email'] ) {
				return false;
			}

			echo wp_kses_post($this->globals()->get_email_append_message());
		}
	}

	// Initialize the class.
	EasyDigitalDownloads::init();
}
