<?php
/**
 * PayPal Card fields gateway.
 *
 * @package PeachPay
 */

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

/**
 * .
 */
class PeachPay_PayPal_Card_Gateway extends PeachPay_PayPal_Payment_Gateway {
	/**
	 * .
	 */
	public function __construct() {
		$this->id                = 'peachpay_paypal_card';
		$this->icons             = array(
			'full'  => array(
				'clear' => PeachPay::get_asset_url( 'img/marks/paypal/cc-quad.svg' ),
			),
			'small' => array(
				'clear' => PeachPay::get_asset_url( 'img/marks/card-small.svg' ),
			),
		);
		$this->settings_priority = 0;

		$this->title        = 'Card via PayPal';
		$this->description  = 'Use your credit or debit card for a fast and secure checkout powered by PayPal.';
		$this->method_title = 'Card via PayPal (PeachPay)';

		$this->payment_method_family = __( 'Card', 'peachpay-for-woocommerce' );

		parent::__construct();
	}

	/**
	 * Renders payment fields.
	 */
	public function payment_method_form() {
		?>
			<div>
				<?php $this->display_fallback_currency_option_message(); ?>
				<p style="margin-bottom: 1rem;">
					<?php echo esc_html( $this->description ); ?>
				<p>
				<div id="pp-paypal-card-element" data-is-mounted="false" style="display:flex;flex-direction:column;gap:12px;">
					<div id="pp-paypal-card-number"></div>
					<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;">
						<div id="pp-paypal-card-expiry"></div>
						<div id="pp-paypal-card-cvv"></div>
					</div>
					<div id="pp-paypal-card-name"></div>
				</div>
				<div id="pp-paypal-card-status" class="hide" style="display:flex;align-items:center;justify-content:center;gap:4px;">
					<i class="pp-icon-info"></i>
					<span></span>
				</div>
			</div>
		<?php
	}

	/**
	 * Only expose this gateway on WooCommerce Blocks checkout.
	 *
	 * @param bool $skip_cart_check If true, the cart availability check will be skipped.
	 * @return bool
	 */
	// public function is_available( $skip_cart_check = false ) {
	// 	$is_available = parent::is_available( $skip_cart_check );
	// 	if ( ! $is_available ) {
	// 		return false;
	// 	}

	// 	if ( function_exists( 'is_checkout' ) && is_checkout() ) {
	// 		return $this->is_blocks_checkout_page();
	// 	}

	// 	return $is_available;
	// }

	// /**
	//  * Checks whether the checkout page is using the Blocks checkout.
	//  *
	//  * @return bool
	//  */
	// private function is_blocks_checkout_page() {
	// 	if ( ! function_exists( 'has_block' ) || ! function_exists( 'wc_get_page_id' ) ) {
	// 		return false;
	// 	}

	// 	$checkout_page_id = wc_get_page_id( 'checkout' );
	// 	if ( ! $checkout_page_id ) {
	// 		return false;
	// 	}

	// 	$checkout_post = get_post( $checkout_page_id );
	// 	if ( ! $checkout_post ) {
	// 		return false;
	// 	}

	// 	return has_block( 'woocommerce/checkout', $checkout_post );
	// }

	// /**
	//  * Returns data needed for WooCommerce Blocks registration.
	//  *
	//  * @return array
	//  */
	// public function get_blocks_data() {
	// 	return array(
	// 		'icon'               => $this->get_icon_url(),
	// 		'title'              => $this->get_title(),
	// 		'description'        => $this->description,
	// 		'supports'           => array_filter( $this->supports, array( $this, 'supports' ) ),
	// 		'client_id'          => PeachPay_PayPal_Integration::client_id(),
	// 		'mode'               => PeachPay_PayPal_Integration::mode(),
	// 		'currency'           => get_woocommerce_currency(),
	// 		'create_order_url'   => WC_AJAX::get_endpoint( 'pp-paypal-blocks-create-order' ),
	// 		'create_order_nonce' => wp_create_nonce( 'peachpay-paypal-blocks-create-order' ),
	// 		'capture_order_url'  => WC_AJAX::get_endpoint( 'pp-paypal-blocks-capture-order' ),
	// 	);
	// }
}
