<?php
/**
 * Prevent direct access to the file
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class WOSR_Upgrade
 *
 * Handles the "Upgrade to Pro" tab in the plugin settings.
 * Displays a feature list and call-to-action to purchase Pro.
 */
class WOSR_Upgrade {

	/**
	 * Constructor
	 *
	 * Hooks into WordPress to render this tab.
	 */
	public function __construct() {
		// Hook into the custom action for the upgrade tab
		add_action( 'wosr_render_tab_upgrade', array( $this, 'render_tab' ) );
	}

	/**
	 * Render the Upgrade tab content
	 */
	public function render_tab() {
    ?>
		<div class="wosr-upgrade-tab">

			<h2><?php esc_html_e( 'Upgrade to Pro for Full Control', 'order-role-manager-for-woocommerce' ); ?></h2>
			<p class="description">
				<?php esc_html_e( 'Unlock all advanced restrictions with Pro. Below you can preview each feature with its settings and how it looks when applied.', 'order-role-manager-for-woocommerce' ); ?>
			</p>

			<?php 
			// Define features for loop
			$features = [
				[
					'title' => __( 'Restrict order status update sequences', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Define which next order statuses are allowed from each current status. Create rules by user role or individual username, with username-specific rules taking preference.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'sequence-settings.png',
					'img2'  => 'sequence-applied.png',
				],
				[
					'title' => __( 'Restrict user roles from trashing orders', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'In Pro, you can prevent selected user roles from moving orders to trash. This helps protect sensitive order data.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'restrict-trash-settings.png',
					'img2'  => 'restrict-trash-applied.png',
				],
				[
					'title' => __( 'Restrict order notes deletion', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Control which user roles can delete order notes. Ensure order history integrity remains intact.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'order-notes-settings.png',
					'img2'  => 'order-notes-applied.png',
				],
				[
					'title' => __( 'Restrict order address fields (billing, shipping, payment)', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Hide or restrict editing of billing, shipping, and payment fields for selected user roles.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'address-settings.png',
					'img2'  => 'address-applied.png',
				],
				[
					'title' => __( 'Restrict order bulk actions', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Prevent unauthorized bulk updates on orders by limiting bulk actions for certain roles.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'bulk-settings.png',
					'img2'  => 'bulk-applied.png',
				],
				[
					'title' => __( 'Restrict changing customer name and order date', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Lock down critical order fields like customer name and order date from being changed by specific roles.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'customer-settings.png',
					'img2'  => 'address-applied.png',
				],
				[
					'title' => __( 'Restrict order screen elements (meta boxes)', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Choose which meta boxes appear on the order edit screen per user role.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'meta-settings.png',
					'img2'  => 'meta-applied.png',
				],
				[
					'title' => __( 'Restrict orders page columns', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Remove specific columns (like Actions, Customer, Date) from the Orders list table for selected roles.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'columns-settings.png',
					'img2'  => 'columns-applied.png',
				],
				[
					'title' => __( 'Restrict specific users by username (Pro Exclusive)', 'order-role-manager-for-woocommerce' ),
					'desc'  => __( 'Apply restrictions not just by role, but down to individual usernames for ultimate control.', 'order-role-manager-for-woocommerce' ),
					'img1'  => 'username-settings.png',
					'img2'  => 'username-applied.png',
				],
			];

			foreach ( $features as $feature ) : ?>
				<div class="wosr-feature-block">

					<!-- Heading + Upgrade Button inline -->
					<div class="wosr-feature-header">
						<h3><?php echo esc_html( $feature['title'] ); ?></h3>
						<a href="<?php echo esc_url( admin_url( 'admin.php?billing_cycle=annual&page=wosr-settings-pricing' ) ); ?>" target="_blank" class="button button-primary">
							<?php esc_html_e( 'Upgrade to Pro', 'order-role-manager-for-woocommerce' ); ?>
						</a>
					</div>

					<!-- Description -->
					<p class="wosr-feature-desc"><?php echo esc_html( $feature['desc'] ); ?></p>

					<!-- Images -->
					<div class="wosr-feature-images">
						<div class="wosr-feature-image">
							<h4><?php esc_html_e( 'Settings Page', 'order-role-manager-for-woocommerce' ); ?></h4>
							<img src="<?php echo esc_url( WOSR_PLUGIN_URL . 'assets/images/' . $feature['img1'] ); ?>" alt="<?php echo esc_attr( $feature['title'] ); ?>">
						</div>
						<div class="wosr-feature-image">
							<h4><?php esc_html_e( 'Restriction Applied', 'order-role-manager-for-woocommerce' ); ?></h4>
							<img src="<?php echo esc_url( WOSR_PLUGIN_URL . 'assets/images/' . $feature['img2'] ); ?>" alt="<?php echo esc_attr( $feature['title'] ); ?>">
						</div>
					</div>
				</div>
			<?php endforeach; ?>

			<!-- Upgrade Button -->
			<div class="upgrade-button">
				<a href="<?php echo esc_url( admin_url( 'admin.php?billing_cycle=annual&page=wosr-settings-pricing' ) ); ?>" target="_blank" class="button button-primary button-hero">
					<?php esc_html_e( 'Upgrade to Pro', 'order-role-manager-for-woocommerce' ); ?>
				</a>
			</div>

		</div>
		<?php
	}
}

// Initialize the class so it runs
new WOSR_Upgrade();
