<?php
/**
 * HVAC Community Events: Custom Login Form Template
 *
 * This template provides the structure for the custom login page,
 * integrating with the Astra theme's styling.
 *
 * @version 1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

// Get Astra theme layout settings if needed, e.g., container width
// $container_class = astra_get_content_layout(); // Example

?>

<div class="hvac-community-login-wrapper"> <?php // Custom wrapper for potential styling ?>
	<div class="ast-container"> <?php // Astra theme container ?>
		<div class="hvac-login-form-card"> <?php // Card styling based on design reference ?>

			<div class="hvac-login-form-header">
				<h2><?php esc_html_e('Trainer Login', 'hvac-community-events'); ?></h2>
				<p><?php esc_html_e('Sign in to access your trainer dashboard', 'hvac-community-events'); ?></p>
			</div>

			<?php
			// Display login errors if any
			if ( isset( $_GET['login'] ) && $_GET['login'] === 'failed' ) {
			    echo '<div class="login-error">Invalid username or password. Please try again.</div>';
			}
			if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] === 'true' ) {
			    echo '<div class="login-success">You have been successfully logged out.</div>';
			}
			?>

			<?php
			// Arguments for wp_login_form
			$args = array(
				'echo'           => true,
				// 'redirect' is handled by the 'login_redirect' filter in Login_Handler class
				'form_id'        => 'hvac_community_loginform',
				'label_username' => __( 'Username or Email Address', 'hvac-community-events' ),
				'label_password' => __( 'Password', 'hvac-community-events' ),
				'label_remember' => __( 'Remember Me', 'hvac-community-events' ), // Task 2.3
				'label_log_in'   => __( 'Log In', 'hvac-community-events' ),
				'id_username'    => 'user_login',
				'id_password'    => 'user_pass',
				'id_remember'    => 'rememberme',
				'id_submit'      => 'wp-submit',
				'remember'       => true, // Task 2.3
				'value_username' => '',
				'value_remember' => false, // Set to true to default the checkbox to checked
			);

			wp_login_form( $args );
			?>

			<div class="hvac-login-links">
				<?php if ( get_option( 'users_can_register' ) ) : ?>
					<a class="hvac-register-link" href="<?php echo esc_url( wp_registration_url() ); ?>">
						<?php esc_html_e( 'Register', 'hvac-community-events' ); ?>
					</a> |
				<?php endif; ?>
				<a class="hvac-lostpassword-link" href="<?php echo esc_url( wp_lostpassword_url() ); ?>">
					<?php esc_html_e( 'Lost your password?', 'hvac-community-events' ); // Task 2.4 ?>
				</a>
			</div>

		</div> <?php // .hvac-login-form-card ?>
	</div> <?php // .ast-container ?>
</div> <?php // .hvac-community-login-wrapper ?>