<?php
/**
 * Error view template for FinalPOS dashboard
 *
 * @package FinalPOS
 */

if ( ! defined( 'ABSPATH' ) ) {
	die( 'Direct access is not allowed.' );
}
?>

<div class="finalpos-error-container">
	<div class="notice notice-error">
		<p><?php echo wp_kses_post( $error_message ); ?></p>
	</div>

	<div class="finalpos-actions">
		<form method="post" action="" id="finalpos-disconnect-form">
			<?php wp_nonce_field( 'finalpos_disconnect', 'finalpos_disconnect_nonce' ); ?>
			<input type="hidden" name="action" value="finalpos_disconnect">
			<button type="button" class="button button-secondary" id="finalpos-disconnect-btn">
				<?php esc_html_e( 'Disconnect from FinalPOS', 'finalpos' ); ?>
			</button>
		</form>
	</div>
</div>

<style>
	.finalpos-error-container {
		margin: 20px 0;
	}

	.finalpos-actions {
		margin-top: 15px;
	}
</style>

<script>
	document.addEventListener('DOMContentLoaded', function() {
		const disconnectBtn = document.getElementById('finalpos-disconnect-btn');
		const disconnectForm = document.getElementById('finalpos-disconnect-form');

		disconnectBtn.addEventListener('click', function(e) {
			e.preventDefault();

			if (confirm('<?php echo esc_js( __( 'Are you sure you want to disconnect from FinalPOS? This will remove all plugin data and cannot be undone.', 'finalpos' ) ); ?>')) {
				disconnectForm.submit();
			}
		});
	});
</script>
