<?php

/**
 * Display the login form.
 *
 * @param array $args {
 *     Optional. Array of arguments for customizing the form.
 *
 * @type string $message Message to display above the form. Default empty.
 * @type string $redirect_to URL to redirect after login. Default current page.
 * @type bool $hidden Whether the form should be hidden initially. Default false.
 * }
 * @return void
 * @since 1.0.0
 */
function radius_booking_login_form( $args = array() ) {
	$defaults = array(
		'message'             => '',
		'redirect_to'         => radius_booking_get_current_url(),
		'hidden'              => false,
		'registration_enable' => true
	);
	$args = wp_parse_args( $args, $defaults );

	// Extract variables for template.
	$message             = $args['message'];
	$redirect_to         = $args['redirect_to'];
	$hidden              = $args['hidden'];
	$registration_enable = $args['registration_enable'];

	rtrb_get_template( 'global/form-login.php', compact( 'message', 'redirect_to', 'hidden','registration_enable' ) );
}

/**
 * Display the signup form.
 *
 * @param array $args {
 *     Optional. Array of arguments for customizing the form.
 *
 * @type string $message Message to display above the form. Default empty.
 * @type string $redirect_to URL to redirect after signup. Default current page.
 * @type bool $hidden Whether the form should be hidden initially. Default false.
 * }
 * @return void
 * @since 1.0.0
 */
function radius_booking_signup_form( $args = array() ) {
	$defaults = array(
		'message'     => '',
		'redirect_to' => radius_booking_get_current_url(),
		'hidden'      => false,
	);

	$args = wp_parse_args( $args, $defaults );

	// Extract variables for template.
	$message     = $args['message'];
	$redirect_to = $args['redirect_to'];
	$hidden      = $args['hidden'];

	rtrb_get_template( 'global/form-signup.php', compact( 'message', 'redirect_to', 'hidden' ) );
}

/**
 * Get the current page URL.
 *
 * @return string Current page URL.
 * @since 1.0.0
 */
function radius_booking_get_current_url() {
	global $wp;

	return home_url( add_query_arg( array(), $wp->request ) );
}


/**
 * Check if marketing consent checkbox should be displayed.
 *
 * @return bool True if marketing consent is enabled, false otherwise.
 * @since 1.0.0
 */
function radius_booking_is_marketing_consent_enabled() {
	return (bool) get_option( 'radius_booking_show_marketing_consent', false );
}

/**
 * Get the terms and conditions page URL.
 *
 * @return string Terms page URL or empty string if not set.
 * @since 1.0.0
 */
function radius_booking_get_terms_page_url() {
	$terms_page_id = get_option( 'radius_booking_terms_page_id', 0 );

	if ( ! $terms_page_id ) {
		return '';
	}

	return get_permalink( $terms_page_id );
}