/**
 * WooCommerce block checkout entry (Stripe-style).
 * Register the payment method synchronously when this script loads so WC can
 * include it in the first payment-methods pass after cart hydration.
 */
import { settingsDispatch } from '@greenpay/redux'
import { getBlocksSettingsSync, registerPayment } from '@greenpay/utils'
import { MOUNT } from '../data/constants'

import '../installHydrationGuard'
import '@greenpay/store'
import '../utils/eventEmitter'

// Classic shortcode checkout uses greenpay.js and #wc_greenpay_mount — do not register here.
if (document.getElementById(MOUNT)) {
	// greenpay.js handles this page.
} else {
	const settings = getBlocksSettingsSync()

	if (settings) {
		settingsDispatch().setSettings(settings)
		registerPayment(settings)
	} else {
		console.error('[GreenPay] Block checkout: greenmoney_data settings are not available')
	}
}
