<?php
/**
 * WooCommerce Blocks Support
 *
 * Registers payment methods for WooCommerce Block Checkout.
 *
 * @package FunnelKit_Square
 * @subpackage Blocks
 */

namespace FKWCSQ\Includes\Blocks;

use FKWCSQ\Includes\Traits\Instance;

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

/**
 * Blocks_Support class.
 *
 * Handles WooCommerce Blocks integration for Square payment methods.
 */
class Blocks_Support {
	use Instance;

	/**
	 * Initialize blocks support.
	 *
	 * @return void
	 */
	public static function init() {
		add_action( 'woocommerce_blocks_loaded', array( __CLASS__, 'register_blocks' ) );
	}

	/**
	 * Register payment method blocks.
	 *
	 * @return void
	 */
	public static function register_blocks() {
		if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
			return;
		}

		add_action(
			'woocommerce_blocks_payment_method_type_registration',
			array( __CLASS__, 'register_payment_methods' )
		);
	}

	/**
	 * Register individual payment methods.
	 *
	 * @param \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $registry Payment method registry.
	 * @return void
	 */
	public static function register_payment_methods( $registry ) {
		// Register payment methods (autoloaded).
		$registry->register( new Card_Block() );
		$registry->register( new Apple_Pay_Block() );
		$registry->register( new Google_Pay_Block() );
		$registry->register( new Cash_App_Block() );
		$registry->register( new ACH_Block() );
		$registry->register( new Afterpay_Block() );
		$registry->register( new Gift_Card_Block() );
	}
}
