<?php
/**
 * Marketplace Tab View
 *
 * Replaces the 4-step stepper with a 2-tab layout (Authorization | Sync Settings).
 *
 * @package    MOMCS_Sync
 * @subpackage MOMCS_Sync/views/src/common/pages/supplier/apps
 * @author     miniOrange
 */

declare(strict_types=1);

namespace MOMCS_Sync\Views\Src\Common\Pages\Supplier\Apps;

require_once dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'authorization' . DIRECTORY_SEPARATOR . 'interface-authorization-view.php';
require_once dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'attribute-mapping' . DIRECTORY_SEPARATOR . 'interface-mapping-view.php';
require_once dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'sync-settings' . DIRECTORY_SEPARATOR . 'interface-sync-settings-view.php';

use MOMCS_Sync\Views\Src\Common\Pages\Supplier\Authorization\Authorization_View_Interface;
use MOMCS_Sync\Views\Src\Common\Pages\Supplier\Attribute_Mapping\Mapping_View_Interface;
use MOMCS_Sync\Views\Src\Common\Pages\Supplier\Sync_Settings\Sync_Settings_View_Interface;
use MOMCS_Sync\Views\Src\Common\Pages\Supplier\Sync_Settings\Amazon_Sync_Settings_View;
use MOMCS_Sync\Includes\Common\Constants\Plugin_Constants;
use MOMCS_Sync\Includes\Common\Utils\Utils;

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

/**
 * Class for rendering the marketplace 2-tab layout view.
 */
class Marketplace_Tab_View {

	/**
	 * Authorization view.
	 *
	 * @var Authorization_View_Interface
	 */
	private $authorization_view;

	/**
	 * Mapping view.
	 *
	 * @var Mapping_View_Interface
	 */
	private $mapping_view;

	/**
	 * Sync Settings view.
	 *
	 * @var Sync_Settings_View_Interface
	 */
	private $sync_settings_view;

	/**
	 * Marketplace name.
	 *
	 * @var string
	 */
	private $marketplace_name;

	/**
	 * Active tab.
	 *
	 * @var string 'authorization' or 'sync'
	 */
	private $active_tab;

	/**
	 * Whether the channel is authorized.
	 *
	 * @var bool
	 */
	private $is_authorized;

	/**
	 * Channel UUID.
	 *
	 * @var string
	 */
	private $channel_uuid;

	/**
	 * Constructor.
	 *
	 * @param Authorization_View_Interface $authorization_view Authorization view.
	 * @param Mapping_View_Interface       $mapping_view       Mapping view.
	 * @param Sync_Settings_View_Interface $sync_settings_view Sync Settings view.
	 * @param string                       $marketplace_name   Marketplace name.
	 * @param string                       $active_tab         Active tab ('authorization' or 'sync').
	 * @param bool                         $is_authorized      Whether channel is authorized.
	 * @param string                       $channel_uuid       Channel UUID.
	 */
	public function __construct(
		Authorization_View_Interface $authorization_view,
		Mapping_View_Interface $mapping_view,
		Sync_Settings_View_Interface $sync_settings_view,
		string $marketplace_name,
		string $active_tab,
		bool $is_authorized,
		string $channel_uuid
	) {
		$this->authorization_view = $authorization_view;
		$this->mapping_view       = $mapping_view;
		$this->sync_settings_view = $sync_settings_view;
		$this->marketplace_name   = $marketplace_name;
		$this->active_tab         = $active_tab;
		$this->is_authorized      = $is_authorized;
		$this->channel_uuid       = $channel_uuid;
	}

	/**
	 * Render the tab view.
	 *
	 * @return void
	 */
	public function render(): void {
		$this->enqueue_assets();

		$marketplace_slug = strtolower( $this->marketplace_name );
		?>
		<div class="momcs-marketplace-tab-container">
			<?php $this->render_tab_header(); ?>

			<div class="momcs-tab-content">
				<?php
				if ( 'sync' === $this->active_tab && $this->is_authorized ) {
					$this->render_sync_tab();
				} else {
					$this->render_authorization_tab();
				}
				?>
			</div>
		</div>
		<?php
	}

	/**
	 * Render the tab header navigation.
	 *
	 * @return void
	 */
	private function render_tab_header(): void {
		$base_url = admin_url( 'admin.php?page=momcs-sync-dashboard&tab=connect&marketplace=' . rawurlencode( strtolower( $this->marketplace_name ) ) );
		if ( ! empty( $this->channel_uuid ) ) {
			$base_url .= '&uuid=' . rawurlencode( $this->channel_uuid ) . '&action=edit';
		}

		$auth_url = add_query_arg( 'config_tab', 'authorization', $base_url );
		$sync_url = add_query_arg( 'config_tab', 'sync', $base_url );
		?>
		<div class="momcs-tab-bar" role="tablist">
			<a href="<?php echo esc_url( $auth_url ); ?>"
			   class="momcs-tab-link <?php echo 'authorization' === $this->active_tab ? 'momcs-tab-link--active' : ''; ?>"
			   role="tab"
			   aria-selected="<?php echo 'authorization' === $this->active_tab ? 'true' : 'false'; ?>">
				<span class="momcs-tab-link-icon" aria-hidden="true">
					<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
				</span>
				<?php esc_html_e( 'Authorization', 'multi-channel-for-woocommerce' ); ?>
			</a>

			<?php if ( $this->is_authorized ) : ?>
				<a href="<?php echo esc_url( $sync_url ); ?>"
				   class="momcs-tab-link <?php echo 'sync' === $this->active_tab ? 'momcs-tab-link--active' : ''; ?>"
				   role="tab"
				   aria-selected="<?php echo 'sync' === $this->active_tab ? 'true' : 'false'; ?>">
					<span class="momcs-tab-link-icon" aria-hidden="true">
						<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
					</span>
					<?php esc_html_e( 'Sync Settings', 'multi-channel-for-woocommerce' ); ?>
				</a>
			<?php endif; ?>
		</div>
		<?php
	}

	/**
	 * Render the Authorization tab content.
	 *
	 * @return void
	 */
	private function render_authorization_tab(): void {
		if ( $this->is_authorized ) {
			// Returning user: show connected status with reauthorize option.
			$this->render_connected_status();
		} else {
			// Fresh: show the connect form.
			$this->authorization_view->render();
		}
	}

	/**
	 * Render the connected status card for returning authorized users.
	 *
	 * @return void
	 */
	private function render_connected_status(): void {
		$multichannels_model = new \MOMCS_Sync\Includes\Common\Models\Multichannels_Model();
		$channel             = $multichannels_model->get_channel_by_uuid( $this->channel_uuid );
		$connection_name     = $channel ? ( $channel['connection_name'] ?? '' ) : '';
		$region              = $channel ? ( $channel['region'] ?? '' ) : '';
		?>
		<div class="momcs-auth-connected-status">
			<div class="momcs-auth-connected-card">
				<div class="momcs-auth-connected-icon">
					<span class="dashicons dashicons-yes-alt"></span>
				</div>
				<div class="momcs-auth-connected-info">
					<h3><?php esc_html_e( 'Connected to Amazon Seller Central', 'multi-channel-for-woocommerce' ); ?></h3>
					<p class="momcs-auth-connected-details">
						<?php if ( $connection_name ) : ?>
							<span class="momcs-auth-connected-detail">
								<strong><?php esc_html_e( 'Connection:', 'multi-channel-for-woocommerce' ); ?></strong>
								<?php echo esc_html( $connection_name ); ?>
							</span>
						<?php endif; ?>
						<?php if ( $region ) : ?>
							<span class="momcs-auth-connected-detail">
								<strong><?php esc_html_e( 'Region:', 'multi-channel-for-woocommerce' ); ?></strong>
								<?php echo esc_html( $region ); ?>
							</span>
						<?php endif; ?>
					</p>
				</div>
			</div>
			<div class="momcs-auth-connected-actions">
				<button type="button" id="momcs-reauthorize-btn" class="button button-primary">
					<?php esc_html_e( 'Reauthorize', 'multi-channel-for-woocommerce' ); ?>
				</button>
			</div>
		</div>
		<!-- Hidden: connect form for reauthorize flow -->
		<div id="momcs-reauthorize-form-wrapper" style="display: none;">
			<?php $this->authorization_view->render(); ?>
		</div>
		<?php
	}

	/**
	 * Render the Sync Settings tab content.
	 *
	 * @return void
	 */
	private function render_sync_tab(): void {
		$is_premium_plan = ( Plugin_Constants::PLAN_NAME === 'premium' );

		// Enqueue sync settings assets.
		if ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
			$this->sync_settings_view->enqueue_assets();
		}

		// Localize sync settings with channel UUID.
		wp_localize_script(
			'momcs-sync-settings',
			'momcs_sync_settings',
			array(
				'ajax_url'       => admin_url( 'admin-ajax.php' ),
				'nonce_get_sync' => wp_create_nonce( 'momcs_sync_get_sync_settings_nonce' ),
				'channel_uuid'   => $this->channel_uuid,
			)
		);

		// Localize scheduled sync for premium.
		if ( $is_premium_plan ) {
			wp_localize_script(
				'momcs-scheduled-sync',
				'momcsScheduledSync',
				array(
					'ajaxUrl'      => admin_url( 'admin-ajax.php' ),
					'channel_uuid' => $this->channel_uuid,
					'nonce'        => wp_create_nonce( 'momcs_scheduled_sync_nonce' ),
					'actions'      => array(
						'getSettings'            => 'momcs_get_schedule_settings',
						'createSchedule'         => 'momcs_create_schedule_settings',
						'updateSchedule'         => 'momcs_update_schedule_settings',
						'deleteSchedule'         => 'momcs_delete_schedule_settings',
						'getAvailableAttributes' => 'momcs_get_available_attributes',
					),
					'messages'     => array(
						'scheduleCreated' => __( 'Schedule created successfully!', 'multi-channel-for-woocommerce' ),
						'scheduleUpdated' => __( 'Schedule updated successfully!', 'multi-channel-for-woocommerce' ),
						'scheduleDeleted' => __( 'Schedule deleted successfully!', 'multi-channel-for-woocommerce' ),
						'scheduleError'   => __( 'An error occurred while managing schedule', 'multi-channel-for-woocommerce' ),
						'confirmDelete'   => __( 'Are you sure you want to delete this schedule?', 'multi-channel-for-woocommerce' ),
						'loading'         => __( 'Loading...', 'multi-channel-for-woocommerce' ),
						'saving'          => __( 'Saving...', 'multi-channel-for-woocommerce' ),
					),
					'intervals'    => array(
						'hours'  => __( 'Hours', 'multi-channel-for-woocommerce' ),
						'days'   => __( 'Days', 'multi-channel-for-woocommerce' ),
						'months' => __( 'Months', 'multi-channel-for-woocommerce' ),
					),
				)
			);
		}

		?>
		<form id="momcs-sync-settings-form">
			<?php wp_nonce_field( 'momcs_sync_settings', 'momcs_sync_settings_nonce' ); ?>

			<!-- Sidebar + Content layout -->
			<div class="momcs-sync-layout">

				<!-- LEFT: Vertical sidebar navigation -->
				<nav class="momcs-sync-sidebar" aria-label="<?php esc_attr_e( 'Sync Settings Navigation', 'multi-channel-for-woocommerce' ); ?>">
					<ul class="momcs-sync-sidebar-nav" role="tablist" aria-orientation="vertical">

						<!-- Account Settings (default active) -->
						<li class="momcs-sync-sidebar-item momcs-sync-sidebar-item--active" data-panel="momcs-panel-account-settings">
							<a href="#momcs-panel-account-settings" class="momcs-sync-sidebar-link" role="tab" aria-selected="true" aria-controls="momcs-panel-account-settings">
								<span class="momcs-sync-sidebar-icon" aria-hidden="true">
									<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
								</span>
								<?php esc_html_e( 'Account Settings', 'multi-channel-for-woocommerce' ); ?>
							</a>
						</li>

						<!-- Product Sync Settings (free: same subnav; Template Mapping usable, Price/Schedule disabled) -->
						<li class="momcs-sync-sidebar-item" data-panel="momcs-panel-product-sync">
							<a href="#momcs-panel-product-sync" class="momcs-sync-sidebar-link" role="tab" aria-selected="false" aria-controls="momcs-panel-product-sync">
								<span class="momcs-sync-sidebar-icon" aria-hidden="true">
									<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13.744 17.736a6 6 0 1 1-7.48-7.48"/><path d="M15 6h1v4"/><path d="m6.134 14.768.866-.5 2 3.464"/><circle cx="16" cy="8" r="6"/></svg>
								</span>
								<?php esc_html_e( 'Product Sync Settings', 'multi-channel-for-woocommerce' ); ?>
							</a>
							<ul class="momcs-sync-sidebar-subnav">
								<li><a href="#momcs-section-price-margin" class="momcs-sync-sidebar-sublink" data-section="momcs-section-price-margin"><?php esc_html_e( 'Price Margin', 'multi-channel-for-woocommerce' ); ?></a></li>
								<li><a href="#momcs-section-template-mapping" class="momcs-sync-sidebar-sublink" data-section="momcs-section-template-mapping"><?php esc_html_e( 'Template Mapping', 'multi-channel-for-woocommerce' ); ?></a></li>
								<li><a href="#momcs-section-scheduling" class="momcs-sync-sidebar-sublink" data-section="momcs-section-scheduling"><?php esc_html_e( 'Scheduling Settings', 'multi-channel-for-woocommerce' ); ?></a></li>
							</ul>
						</li>

						<!-- Order Sync Settings (clickable for free so users can see disabled-state content) -->
						<li class="momcs-sync-sidebar-item" data-panel="momcs-panel-order-sync">
							<a href="#momcs-panel-order-sync" class="momcs-sync-sidebar-link" role="tab" aria-selected="false" aria-controls="momcs-panel-order-sync">
								<span class="momcs-sync-sidebar-icon" aria-hidden="true">
									<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 10a4 4 0 0 1-8 0"/><path d="M3.103 6.034h17.794"/><path d="M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z"/></svg>
								</span>
								<?php esc_html_e( 'Order Sync Settings', 'multi-channel-for-woocommerce' ); ?>
							</a>
						</li>

					</ul>

					<!-- Save button inside sidebar, below nav -->
					<div class="momcs-sidebar-save-bar">
						<button type="button" id="momcs-global-save-btn" class="button button-primary">
							<?php esc_html_e( 'Save Settings', 'multi-channel-for-woocommerce' ); ?>
						</button>
					</div>
				</nav>

				<!-- RIGHT: Content panels -->
				<div class="momcs-sync-content">

					<!-- Account Settings Panel (default visible) -->
					<div id="momcs-panel-account-settings" class="momcs-sync-content-panel momcs-sync-content-panel--active">
						<div class="momcs-sync-tab-account-settings">
							<?php
							if ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
								$this->sync_settings_view->render_account_settings_panel();
							}
							?>
						</div>
					</div>

					<!-- Product Sync Panel -->
					<div id="momcs-panel-product-sync" class="momcs-sync-content-panel">
						<?php $this->render_product_sync_panel_content( $is_premium_plan ); ?>
					</div>

					<!-- Order Sync Panel -->
					<div id="momcs-panel-order-sync" class="momcs-sync-content-panel">
						<?php $this->render_order_sync_panel_content( $is_premium_plan ); ?>
					</div>

				</div>

			</div><!-- .momcs-sync-layout -->
		</form>
		<?php
	}

	/**
	 * Render the Product Sync panel content.
	 *
	 * Contains: Pricing Margin + Field Mapping + Template Mapping + Product Schedule.
	 *
	 * @param bool $is_premium_plan Whether user is on premium plan.
	 * @return void
	 */
	private function render_product_sync_panel_content( bool $is_premium_plan ): void {
		if ( $is_premium_plan ) {
			?>
			<!-- Pricing Margin (shared markup with standalone Sync Settings page) -->
			<?php
			if ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
				$this->sync_settings_view->render_price_markup_block(
					array(
						'section_id' => 'momcs-section-price-margin',
					)
				);
			}
			?>

			<hr class="momcs-section-divider" />

			<!-- Field Mapping (Default + Template) -->
			<div id="momcs-section-template-mapping" class="momcs-sync-settings-section">
				<?php $this->mapping_view->render(); ?>
			</div>

			<hr class="momcs-section-divider" />

			<!-- Product Sync Schedule -->
			<div id="momcs-section-scheduling" class="momcs-sync-settings-section">
				<div class="momcs-section-header">
					<div class="momcs-section-header-icon">
						<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/></svg>
					</div>
					<h3><?php esc_html_e( 'Product Sync Schedule', 'multi-channel-for-woocommerce' ); ?></h3>
					<span class="momcs-field-tooltip-wrapper">
						<span class="dashicons dashicons-info-outline momcs-field-tooltip-icon"></span>
						<span class="momcs-field-tooltip"><?php esc_html_e( 'Schedule automatic synchronization of product attributes at regular intervals.', 'multi-channel-for-woocommerce' ); ?></span>
					</span>
				</div>
				<?php
				if ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
					$this->sync_settings_view->render_schedule_settings_panel( $this->channel_uuid );
				}
				?>
			</div>
			<?php
		} else {
			// Free: show Template Mapping (one template) plus disabled Price Markup and Scheduling.
			?>
			<!-- Price Margin (disabled for free) -->
			<div id="momcs-section-price-margin" class="momcs-sync-settings-section">
				<?php
				if ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
					$this->sync_settings_view->render_disabled_price_markup_section();
				}
				?>
			</div>

			<hr class="momcs-section-divider" />

			<!-- Template Mapping (one template for free) -->
			<div id="momcs-section-template-mapping" class="momcs-sync-settings-section">
				<?php $this->mapping_view->render(); ?>
			</div>

			<hr class="momcs-section-divider" />

			<!-- Scheduling (disabled for free) -->
			<div id="momcs-section-scheduling" class="momcs-sync-settings-section">
				<?php
				if ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
					$this->sync_settings_view->render_disabled_schedule_settings_panel();
				}
				?>
			</div>
			<?php
		}
	}

	/**
	 * Render the Order Sync panel content.
	 *
	 * Contains: Order Sync General + Order Scheduling.
	 *
	 * @param bool $is_premium_plan Whether user is on premium plan.
	 * @return void
	 */
	private function render_order_sync_panel_content( bool $is_premium_plan ): void {
		if ( $is_premium_plan && $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
			?>
			<div class="momcs-sync-settings-section">
				<div class="momcs-section-header">
					<div class="momcs-section-header-icon">
						<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 10a4 4 0 0 1-8 0"/><path d="M3.103 6.034h17.794"/><path d="M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z"/></svg>
					</div>
					<h3><?php esc_html_e( 'Order Sync Settings', 'multi-channel-for-woocommerce' ); ?></h3>
					<span class="momcs-field-tooltip-wrapper">
						<span class="dashicons dashicons-info-outline momcs-field-tooltip-icon"></span>
						<span class="momcs-field-tooltip"><?php esc_html_e( 'Configure automatic order synchronization and fulfillment options.', 'multi-channel-for-woocommerce' ); ?></span>
					</span>
				</div>
				<?php $this->sync_settings_view->render_order_schedule_settings_panel( $this->channel_uuid ); ?>
			</div>
			<?php
		} elseif ( $this->sync_settings_view instanceof Amazon_Sync_Settings_View ) {
			$this->sync_settings_view->render_disabled_order_schedule_settings_panel();
		}
	}

	/**
	 * Enqueue tab-specific assets and localize configuration.
	 *
	 * @return void
	 */
	private function enqueue_assets(): void {
		// Tab CSS.
		wp_enqueue_style(
			'momcs-marketplace-tabs',
			MOMCS_PLUGIN_URL . 'assets/css/marketplace-tabs.css',
			array( 'momcs-sync-admin' ),
			defined( 'MOMCS_VERSION' ) ? MOMCS_VERSION : '1.0.0'
		);

		// Tab JS.
		wp_enqueue_script(
			'momcs-marketplace-tabs',
			MOMCS_PLUGIN_URL . 'assets/js/marketplace-tabs.js',
			array( 'jquery' ),
			defined( 'MOMCS_VERSION' ) ? MOMCS_VERSION : '1.0.0',
			true
		);

		$is_premium = ( Plugin_Constants::PLAN_NAME === 'premium' );

		wp_localize_script(
			'momcs-marketplace-tabs',
			'momcs_marketplaceTabConfig',
			array(
				'activeTab'    => esc_js( $this->active_tab ),
				'channelUuid'  => esc_js( $this->channel_uuid ),
				'isAuthorized' => $this->is_authorized,
				'marketplace'  => esc_js( strtolower( $this->marketplace_name ) ),
				'nonces'       => array(
					'saveMapping'      => wp_create_nonce( 'momcs_sync_save_unified_mapping_nonce' ),
					'saveSyncSettings' => $is_premium ? wp_create_nonce( 'momcs_sync_save_sync_settings_nonce' ) : '',
				),
				'strings'      => array(
					'saving'           => esc_html__( 'Saving...', 'multi-channel-for-woocommerce' ),
					'saveSettings'     => esc_html__( 'Save Settings', 'multi-channel-for-woocommerce' ),
					'savedOk'          => esc_html__( 'Settings saved successfully.', 'multi-channel-for-woocommerce' ),
					'errorSaving'      => esc_html__( 'Error saving settings.', 'multi-channel-for-woocommerce' ),
					'errorSyncSave'    => esc_html__( 'Error saving sync settings: ', 'multi-channel-for-woocommerce' ),
					'errorMappingSave' => esc_html__( 'Error saving mapping: ', 'multi-channel-for-woocommerce' ),
				),
			)
		);
	}
}
