<?php

use XTS\Modules\Layouts\Main;

if ( ! function_exists( 'wd_gutenberg_checkout_form' ) ) {
	function wd_gutenberg_checkout_form( $block_attributes, $content ) {
		if ( ! woodmart_woocommerce_installed() ) {
			return '';
		}

		$el_id = wd_get_gutenberg_element_id( $block_attributes );

		Main::setup_preview();

		ob_start();

		?>
			<?php if ( function_exists( 'WC' ) && ! WC()->checkout()->is_registration_enabled() && WC()->checkout()->is_registration_required() && ! is_user_logged_in() ) : ?>
				<?php echo wp_kses_post( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) ); ?>
			<?php else : ?>
				<form <?php echo $el_id ? 'id="' . esc_attr( $el_id ) . '" ' : ''; ?>name="checkout" method="post" class="checkout woocommerce-checkout wd-checkout-form<?php echo esc_attr( wd_get_gutenberg_element_classes( $block_attributes ) ); ?>" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data" aria-label="<?php echo esc_attr__( 'Checkout', 'woocommerce' ); ?>">
					<?php echo do_shortcode( $content ); ?>
				</form>
			<?php endif; ?>
		<?php
		Main::restore_preview();

		return ob_get_clean();
	}
}
