<?php
/**
 * Premium Addon List Class
 *
 * @package miniorange-sms-order-notification-otp-verification/helper
 * @since   1.0.0
 */

namespace WCSMSOTP\Helper;

use WCSMSOTP\Traits\Instance;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'PremiumAddonList' ) ) {

	/**
	 * Class PremiumAddonList
	 *
	 * Manages and provides information about premium add-ons for the plugin.
	 * Includes methods to retrieve the add-on list and add-on names.
	 *
	 * @package miniorange-sms-order-notification-otp-verification/helper
	 * @since   1.0.0
	 */
	final class PremiumAddonList {

		use Instance;

		/**
		 * Premium addon list array.
		 *
		 * @var array<string, array<string, mixed>>
		 */
		private $premium_addon;

		/**
		 * Addon name.
		 *
		 * @var string|null
		 */
		private $addon_name;

		/**
		 * Constructor.
		 *
		 * @return void
		 */
		private function __construct() {

			$translation_func = function_exists( 'mowc_' ) ? 'mowc_' : '__';
			$text_domain      = 'miniorange-sms-order-notification-otp-verification';

			$translate = function ( $text ) use ( $translation_func, $text_domain ) {
				return function_exists( $translation_func )
					? call_user_func( $translation_func, $text, $text_domain )
					: $text;
			};

			$sanitize_svg = function ( $svg ) {
				if ( ! is_string( $svg ) ) {
					return '';
				}

				return wp_kses(
					$svg,
					array(
						'svg'            => array(
							'width'   => true,
							'height'  => true,
							'viewbox' => true,
							'fill'    => true,
						),
						'g'              => array( 'id' => true ),
						'rect'           => array(
							'width'  => true,
							'height' => true,
							'rx'     => true,
							'fill'   => true,
						),
						'path'           => array(
							'd'         => true,
							'fill'      => true,
							'fill-rule' => true,
							'clip-rule' => true,
							'opacity'   => true,
							'id'        => true,
						),
						'defs'           => array(),
						'linearGradient' => array(
							'id'            => true,
							'x1'            => true,
							'x2'            => true,
							'y1'            => true,
							'y2'            => true,
							'gradientUnits' => true,
						),
						'stop'           => array(
							'stop-color' => true,
							'offset'     => true,
						),
					)
				);
			};

			$this->premium_addon = array(
				'reg_only_phone_addon' => array(
					'name'          => esc_html( $translate( 'Register Using Only Phone Number' ) ),
					'description'   => array(
						esc_html( $translate( 'Register with phone number and OTP' ) ),
						esc_html( $translate( 'No email required' ) ),
						esc_html( $translate( 'Register user on WooCommerce Registration form using Phone number only!' ) ),
					),
					'svg'           => $sanitize_svg(
						'<svg width="50" height="50" viewBox="0 0 100 100" fill="none"></svg>'
					),
					'price'         => esc_html( '$49' ),
					'guide_link'    => esc_url_raw( 'https://plugins.miniorange.com/how-to-configure-register-using-only-phone-addon' ),
					'purchase_link' => esc_url_raw( 'https://portal.miniorange.com/initializePayment?requestOrigin=wp_otp_register_with_phone_addon_plan' ),
					'support_msg'   => esc_html(
						$translate(
							'Hi I am interested in the Register Using Only Phone Number addon, could you please tell me more about this addon?'
						)
					),
				),
			);
		}

		/**
		 * Get addon name.
		 *
		 * @return string|null
		 */
		public function get_add_on_name() {
			return $this->addon_name;
		}

		/**
		 * Get premium addon list.
		 *
		 * @return array<string, array<string, mixed>>
		 */
		public function get_premium_add_on_list() {
			return is_array( $this->premium_addon ) ? $this->premium_addon : array();
		}
	}
}
