<?php
/**
 * File: TamiWooCommerceResponse.php
 * Year: 2023
 */
namespace Tami\WooCommerce;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if(!class_exists('\Tami\WooCommerce\Response')) {
	class Response {
		public static function json_output( $out ) {
			header( 'Content-Type: application/json' );
			die( wp_json_encode( $out ) );
		}

		public static function sendMessageToParent( $data, $redirectUrl = '' ) {
			header( 'Content-Type: text/html' );
			if ( ! $redirectUrl ) {
				$redirectUrl = wc_get_cart_url();
			}

			$template_name = 'response-send.php';
			$default_path  = TAMI_PLUGIN_PATH . '/checkout/views/';


			$args = [
				'data' => $data,
				'redirect_url' => $redirectUrl
			];

			wc_get_template( $template_name, $args, '', $default_path );
			exit;
		}

		public static function sendHtmlResult( $html ) {
			$template_name = 'response-send-raw.php';
			$default_path  = TAMI_PLUGIN_PATH . '/checkout/views/';
			wc_get_template( $template_name, [ 'data' => $html ], '', $default_path );
			exit;
		}
	}
}