<?php
/**
 * This is a built-in template file. If you need to customize it, please,
 * DO NOT modify this file directly. Instead, copy it to your theme's directory
 * and then modify the code. If you modify this file directly, your changes
 * will be overwritten during next update of the plugin.
 */

/**
 * Make the post data and the pre-form message global
 */
global $post;

$submit        = get_permalink( wpas_get_option( 'ticket_list' ) );
$registration  = wpas_get_option( 'allow_registrations', 'allow' ); // Make sure registrations are open
$redirect_to   = get_permalink( $post->ID );
$wrapper_class = 'allow' !== $registration && 'moderated' !== $registration ? 'wpas-login-only' : 'wpas-login-register';
$allowed_html  = conikal_content_allowed_html();
?>

<div class="wpas <?php echo esc_attr($wrapper_class); ?>">
	<div class="ui grid">
		<div class="sixteen wide mobile eight wide tablet eight wide computer column">
			<div class="ui raised padded segment">
			<?php do_action('wpas_before_login_form'); ?>
			<form class="ui large form wpas-form" id="wpas_form_login" method="post" role="form" action="<?php echo wpas_get_login_url(); ?>">
				<h2 class="ui header"><?php _e( 'Log in', 'campoal' ); ?></h2>

				<?php
				/* Registrations are not allowed. */
				if ( 'disallow' === $registration ) {
					echo wpas_get_notification_markup( 'failure', __( 'Registrations are currently not allowed.', 'campoal' ) );
				} ?>

				<div class="field">
					<?php 
					$username = new WPAS_Custom_Field( 'log', array(
						'name' => 'log',
						'args' => array(
							'required'    => true,
							'field_type'  => 'text',
							'label'       => __( 'E-mail or username', 'campoal' ),
							'placeholder' => __( 'E-mail or username', 'campoal' ),
							'sanitize'    => 'sanitize_user'
						)
					) );
					
					$username = apply_filters( 'wpas_login_form_user_name', $username ) ;

					echo wp_kses($username->get_output(), $allowed_html); ?>
				</div>

				<div class="field">
					<?php 
					$password = new WPAS_Custom_Field( 'pwd', array(
						'name' => 'pwd',
						'args' => array(
							'required'    => true,
							'field_type'  => 'password',
							'label'       => __( 'Password', 'campoal' ),
							'placeholder' => __( 'Password', 'campoal' ),
							'sanitize'    => 'sanitize_text_field'
						)
					) );

					$password = apply_filters( 'wpas_login_form_password', $password ) ;
					
					echo wp_kses($password->get_output(), $allowed_html); ?>
				</div>

				<?php
				/**
				 * wpas_after_login_fields hook
				 */
				do_action( 'wpas_after_login_fields' ); ?>
				<div class="field">
					<div class="ui checkbox">
						<?php 
						$rememberme = new WPAS_Custom_Field( 'rememberme', array(
							'name' => 'rememberme',
							'args' => array(
								'required'   => true,
								'field_type' => 'checkbox',
								'sanitize'   => 'sanitize_text_field',
								'options'    => array( '1' => __( 'Remember Me', 'campoal' ) ),
							)
						) );

						$rememberme = apply_filters( 'wpas_login_form_rememberme', $rememberme ) ;
						echo wp_kses($rememberme->get_output(), $allowed_html); ?>
					</div>
				</div>
				<?php
				wpas_do_field( 'login', $redirect_to );
				wpas_make_button( __( 'Log in', 'campoal' ), array( 'class' => 'ui primary button', 'onsubmit' => __( 'Logging In...', 'campoal' ) ) );
				printf( '<a href="%1$s" class="ui tiny right floated header wpas-forgot-password-link">%2$s</a>', wp_lostpassword_url( wpas_get_tickets_list_page_url() ), esc_html( __( 'Forgot password?', 'campoal' ) ) ); ?>
			</form>
			</div>
		</div>
	
		<div class="sixteen wide mobile eight wide tablet eight wide computer column">
			<?php
			if ( 'allow' === $registration || 'moderated' === $registration ): ?>
			<div class="ui raised padded segment">
				<form class="ui large form wpas-form" id="wpas_form_registration" method="post" action="<?php echo get_permalink( $post->ID ); ?>">
					<h2 class="ui header"><?php _e( 'Register', 'campoal' ); ?></h2>

					<div class="field">
						<?php
						$first_name_desc = wpas_get_option( 'reg_first_name_desc', '' ) ;
						$first_name = new WPAS_Custom_Field( 'first_name', array(
							'name' => 'first_name',
							'args' => array(
								'required'    => true,
								'field_type'  => 'text',
								'label'       => __( 'First Name', 'campoal' ),
								'placeholder' => __( 'First Name', 'campoal' ),
								'sanitize'    => 'sanitize_text_field',
								'desc'		  => $first_name_desc,
							)
						) );

						$first_name = apply_filters( 'wpas_registration_form_first_name', $first_name ) ;			
						echo wp_kses($first_name->get_output(), $allowed_html); ?>
					</div>
				
					<div class="field">
					<?php 
					$last_name_desc = wpas_get_option( 'reg_last_name_desc', '' ) ;
					$last_name = new WPAS_Custom_Field( 'last_name', array(
						'name' => 'last_name',
						'args' => array(
							'required'    => true,
							'field_type'  => 'text',
							'label'       => __( 'Last Name', 'campoal' ),
							'placeholder' => __( 'Last Name', 'campoal' ),
							'sanitize'    => 'sanitize_text_field',
							'desc'		  => $last_name_desc,
						)
					) );

					$last_name = apply_filters( 'wpas_registration_form_last_name', $last_name ) ;						
					
					echo wp_kses($last_name->get_output(), $allowed_html); ?>
					</div>

					<div class="field">
						<?php 
						$email_desc = wpas_get_option( 'reg_email_desc', '' ) ;
						$email = new WPAS_Custom_Field( 'email', array(
							'name' => 'email',
							'args' => array(
								'required'    => true,
								'field_type'  => 'email',
								'label'       => __( 'Email', 'campoal' ),
								'placeholder' => __( 'Email', 'campoal' ),
								'sanitize'    => 'sanitize_text_field',
								'desc'		  => $email_desc,
							)
						) );

						$email = apply_filters( 'wpas_registration_form_email', $email ) ;						
						
						echo wp_kses($email->get_output(), $allowed_html); ?>
					</div>

					<div class="field">
						<?php
						$pwd = new WPAS_Custom_Field( 'password', array(
							'name' => 'password',
							'args' => array(
								'required'    => true,
								'field_type'  => 'password',
								'label'       => __( 'Enter a password', 'campoal' ),
								'placeholder' => __( 'Password', 'campoal' ),
								'sanitize'    => 'sanitize_text_field'
							)
						) );

						$pwd = apply_filters( 'wpas_registration_form_password', $pwd ) ;

						echo wp_kses($pwd->get_output(), $allowed_html); ?>
					</div>

					<div class="field">
						<div class="ui checkbox">
							<?php
							$showpwd = new WPAS_Custom_Field( 'pwdshow', array(
								'name' => 'pwdshow',
								'args' => array(
									'required'   => false,
									'field_type' => 'checkbox',
									'sanitize'   => 'sanitize_text_field',
									'options'    => array( '1' => _x( 'Show Password', 'Login form', 'campoal' ) ),
								)
							) );

							echo wp_kses($showpwd->get_output(), $allowed_html); ?>
						</div>
					</div>

					<?php 
					/**
					 * wpas_after_registration_fields hook
					 * 
					 * @Awesome_Support::terms_and_conditions_checkbox()
					 */
					do_action( 'wpas_after_registration_fields' );
					wpas_do_field( 'register', $redirect_to );
					wp_nonce_field( 'register', 'user_registration', false, true );
					wpas_make_button( __( 'Create Account', 'campoal' ), array( 'class' => 'ui primary button', 'onsubmit' => __( 'Creating Account...', 'campoal' ) ) );
					?>
				</form>
			</div>
			<?php endif; ?>
		</div>
	</div>
</div>
