<?php
/**
 * Frontend passkey login button partial.
 *
 * @package GuardDog
 * @since 1.9.39
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$wrapper_class     = isset( $wrapper_class ) ? sanitize_text_field( $wrapper_class ) : 'guard-dog-passkey-login';
$button_class      = isset( $button_class ) ? sanitize_text_field( $button_class ) : 'button button-secondary guard-dog-passkey-login__button';
$status_class      = isset( $status_class ) ? sanitize_text_field( $status_class ) : 'guard-dog-passkey-login__status';
$show_icon         = isset( $show_icon ) ? (bool) $show_icon : true;
$button_id         = isset( $button_id ) ? sanitize_html_class( $button_id ) : wp_unique_id( 'guard-dog-passkey-login-btn-' );
$status_id         = isset( $status_id ) ? sanitize_html_class( $status_id ) : wp_unique_id( 'guard-dog-passkey-status-' );
$username_selector = isset( $username_selector ) && is_string( $username_selector ) ? sanitize_text_field( $username_selector ) : '#user_login';
$redirect_to       = isset( $redirect_to ) && is_string( $redirect_to ) ? esc_url_raw( $redirect_to ) : '';
?>

<div
	class="<?php echo esc_attr( $wrapper_class ); ?>"
	data-guard-dog-passkey-login="1"
	data-username-selector="<?php echo esc_attr( $username_selector ); ?>"
	data-redirect-to="<?php echo esc_attr( $redirect_to ); ?>"
>
	<button
		type="button"
		id="<?php echo esc_attr( $button_id ); ?>"
		class="<?php echo esc_attr( $button_class ); ?>"
		aria-describedby="<?php echo esc_attr( $status_id ); ?>"
		data-guard-dog-passkey-login-button
	>
		<?php if ( $show_icon ) : ?>
			<span class="dashicons dashicons-admin-network" aria-hidden="true"></span>
		<?php endif; ?>
		<span class="guard-dog-passkey-login__label" data-guard-dog-passkey-login-label>
			<?php esc_html_e( 'Sign in with Passkey', 'guard-dog' ); ?>
		</span>
	</button>
	<p
		id="<?php echo esc_attr( $status_id ); ?>"
		class="<?php echo esc_attr( $status_class ); ?>"
		style="display: none;"
		aria-live="polite"
		data-guard-dog-passkey-login-status
	></p>
</div>
