<?php

/**
 * Handles all the global functions for Revio
 *
 * @since 1.3.8
 * @package RVIOR
 */

// Namespace.
namespace RVIOR;

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


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

	/**
	 * Handles all the global functions for Revio
	 */
	class Globals extends \RVIOR\Base\Controller {

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

		/**
		 * Stores the instance of the class
		 *
		 * @var object
		 */
		private static $instance;

		/**
		 * Returns the instance of the class
		 *
		 * @return object
		 */
		public static function get_instance() {
			if ( ! isset( self::$instance ) ) {
				self::$instance = new self();
			}

			return self::$instance;
		}

		/**
		 * Returns the email append message
		 *
		 * @return string
		 */
		public function get_email_append_message() {
			$email         = $this->option()->get('email_template');
			$button        = $email['button'];
			$recorder_page = $this->option()->get('recording_page_id');

			$url = get_permalink($recorder_page) . '?folder=orders&source=email';

			$message = wp_sprintf( '
			<div style="padding-top:15px; font-family:"Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;">
				<div style="text-align: center;">
					<div style="text-align:center; padding-top: 8px; margin-top: 5px;">
						<a href="%s" target="_blank" style="background-color: %s; color: %s; font-size: %spx; padding: 10px 12px; border-radius: 5px; text-decoration: none;">
							%s
						</a>
					</div>
				</div>
			</div>', esc_url( $url ), esc_attr( $button['background'] ), esc_attr( $button['color'] ), esc_attr( $button['size'] ), esc_html( $button['text'] ) );

			return apply_filters('rvior_thankyou_email_html', $message);
		}
	}
}
