<?php
if ( ! defined( 'ABSPATH' ) ) {
	die( 'Direct access is not allowed.' );
}
?>
		<?php if ( ! empty( $site_status['warnings'] ) ) : ?>
			<?php foreach ( $site_status['warnings'] as $warning ) : ?>
				<div class="notice notice-<?php echo esc_attr( $warning['type'] ); ?> finalpos-site-status-warning">
					<p><?php echo wp_kses_post( $warning['message'] ); ?></p>
				</div>
			<?php endforeach; ?>
		<?php endif; ?>

		<?php if ( ! empty( $disabled_webhooks ) ) : ?>
			<div class="notice notice-error finalpos-webhook-error">
				<p><strong><?php esc_html_e( 'Warning:', 'finalpos' ); ?></strong> <?php esc_html_e( 'One or more FinalPOS webhooks have been disabled.', 'finalpos' ); ?></p>
				<ul style="margin: 10px 0 0 20px;">
					<?php foreach ( $disabled_webhooks as $webhook_data ) : ?>
						<li style="margin-bottom: 8px;">
							<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks&edit-webhook=' . absint( $webhook_data['id'] ) ) ); ?>">
								<strong><?php echo esc_html( $webhook_data['name'] ); ?></strong>
							</a>
							<?php if ( ! empty( $webhook_data['topic'] ) ) : ?>
								(<?php echo esc_html( $webhook_data['topic'] ); ?>)
							<?php endif; ?>
							<?php if ( ! empty( $webhook_data['status'] ) ) : ?>
								- <span style="text-transform: capitalize;"><?php echo esc_html( $webhook_data['status'] ); ?></span>
							<?php endif; ?>
						</li>
					<?php endforeach; ?>
				</ul>
				<p style="margin-top: 10px;">
					<strong><?php esc_html_e( 'Important:', 'finalpos' ); ?></strong> <?php esc_html_e( 'After enabling webhooks, you need to run a resync in Hub.', 'finalpos' ); ?>
				</p>
				<p style="margin-top: 10px;">
					<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks' ) ); ?>" class="button button-primary">
						<?php esc_html_e( 'Manage All Webhooks', 'finalpos' ); ?>
					</a>
				</p>
			</div>
		<?php endif; ?>

		<?php if ( $has_error ) : ?>
			<p class="finalpos-error-message"><?php echo wp_kses_post( $error_message ); ?></p>
		<?php elseif ( $sync_status === null ) : ?>
			<p class="finalpos-error-message"><?php esc_html_e( 'Your store is not currently syncing with Final POS. No synchronization data available.', 'finalpos' ); ?></p>
		<?php else : ?>
			<div class="finalpos-woo-banner">
				<?php if ( ! empty( $company_name ) ) : ?>
					<h2><?php echo esc_html( $company_name ); ?></h2>
				<?php else : ?>
					<h2><?php esc_html_e( 'Woo-hoo! WooCommerce sync is connected.', 'finalpos' ); ?></h2>
				<?php endif; ?>
				<p><?php esc_html_e( 'View sync status and reconfigure your sync preferences anytime in Hub under Settings -> WooCommerce.', 'finalpos' ); ?></p>
				
				<div class="finalpos-sync-status">
					<?php
					$sync_categories = array( 'products', 'orders', 'customers' );

					foreach ( $sync_categories as $category ) {
						$status       = isset( $sync_status[ $category ] ) ? $sync_status[ $category ] : 'unknown';
						$status_text  = '';
						$status_class = '';

						switch ( $status ) {
							case 'done':
								$status_text  = esc_html__( 'Done', 'finalpos' );
								$status_class = 'sync-done';
								break;
							case 'in-progress':
								$status_text  = esc_html__( 'Syncing', 'finalpos' );
								$status_class = 'sync-progress';
								break;
							default:
								$status_text  = esc_html__( 'Unknown', 'finalpos' );
								$status_class = 'sync-unknown';
								break;
						}
						?>
						<div class="sync-item <?php echo $status_class; ?>">
							<span class="sync-category"><?php echo ucfirst( esc_html( $category ) ); ?>:</span>
							<span class="sync-status"><?php echo $status_text; ?></span>
						</div>
						<?php
					}
					?>
				</div>
			</div>
			
			<div class="finalpos-card-layout">
				<div class="finalpos-card">
					<h2 class="finalpos-card-title"><?php esc_html_e( 'Manage your POS account in Hub', 'finalpos' ); ?></h2>
					
					<div class="finalpos-card-content">
						<div class="finalpos-card-image">
							<img src="<?php echo FINALPOS_PLUGIN_URL; ?>assets/img/manage-hub.svg" alt="Manage Hub Dashboard">
						</div>
						<p class="finalpos-text"><?php esc_html_e( 'Set up your user profiles, payment settings, and more in Hub.', 'finalpos' ); ?></p>
					</div>
						
					<div class="finalpos-card-footer">
						<a href="https://hub.finalpos.com" target="_blank" class="finalpos-button"><?php esc_html_e( 'Open Hub', 'finalpos' ); ?></a>
					</div>
				</div>
				
				<div class="finalpos-card">
					<h2 class="finalpos-card-title"><?php esc_html_e( 'Sell with the Final POS native app', 'finalpos' ); ?></h2>
					
					<div class="finalpos-card-content">
						<div class="finalpos-card-image">
							<img src="<?php echo FINALPOS_PLUGIN_URL; ?>assets/img/manage-hub-app.svg" alt="Final POS Native App">
						</div>
						<p><?php esc_html_e( 'Install the Final POS native app to turn your device into a POS Station and start selling with your new checkout flow.', 'finalpos' ); ?></p>
					</div>
					
					<!-- <div class="finalpos-download-wrapper">
						<p class="finalpos-title-small"><?php esc_html_e( 'Download Final POS for Android, iOS, or Windows:', 'finalpos' ); ?></p>
						<div class="finalpos-app-downloads finalpos-card-footer">
							<a href="#" target="_blank" class="download-app-icon">
								<img src="<?php echo FINALPOS_PLUGIN_URL; ?>assets/img/stores/app-store-badge.svg" alt="Download on the App Store">
							</a>
							<a href="#" target="_blank" class="download-app-icon">
								<img src="<?php echo FINALPOS_PLUGIN_URL; ?>assets/img/stores/google-play-badge.svg" alt="Get it on Google Play">
							</a>
							<a href="#" target="_blank" class="download-app-icon">
								<img src="<?php echo FINALPOS_PLUGIN_URL; ?>assets/img/stores/ms-store-badge.svg" alt="Download for Windows">
							</a>
						</div>
					</div> -->
				</div>
			</div>
			
		<?php endif; ?>