<?php

/**
 * Renders all Hub account settings fields.
 *
 * @package northmill-online-shared
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Checkout;

/**
 * View arguments.
 *
 * @var array $params
 */
use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Abstracts\Hub_API\Hub_Accounts\Hub_Account_Setup;
\defined('ABSPATH') || exit;
?>
<table class="form-table" role="presentation">
	<tr>
		<th scope="row"><?php 
\esc_html_e('Environment', 'northmill-online-shared');
?></th>
		<td>
			<?php 
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $params['env_field'];
?>
		</td>
	</tr>
	<?php 
if ($params['is_stock_accounts_used']) {
    Hub_Account_Setup::render_backoffice_account_fields($field_iterators, null, '', \true);
}
Hub_Account_Setup::render_backoffice_account_fields($field_iterators, $params['test_main_account']);
if ($params['is_stock_accounts_used']) {
    ?>
		<tbody class="add-account-row test-row">
		<tr>
			<th colspan="2">
				<p>
					<?php 
    \esc_html_e('Any accounts connected below are listed in checkout to be ordered from, along with the main account. It is used to create orders, sync stock and retrieve bookkeeping information.', 'northmill-online-shared');
    ?>
				</p>
			</th>
		</tr>
		</tbody>
		<?php 
    foreach ($params['stock_accounts'] as $account_id => $account) {
        if ($account->is_test()) {
            Hub_Account_Setup::render_backoffice_account_fields($field_iterators, $account);
            unset($params['stock_accounts'][$account_id]);
        }
    }
    ?>
		<tbody class="add-account-row test-row">
			<tr>
				<th colspan="2"><a href="#" class="add-hub-account" data-env="test"><?php 
    \esc_html_e('Connect stock Hub account', 'northmill-online-shared');
    ?></a></th>
			</tr>
		</tbody>
		<?php 
}
Hub_Account_Setup::render_backoffice_account_fields($field_iterators, $params['prod_main_account'], 'prod');
if ($params['is_stock_accounts_used']) {
    ?>
		<tbody class="add-account-row prod-row">
			<tr>
				<th colspan="2"><p>
						<?php 
    \esc_html_e('Any accounts connected below are listed in checkout to be ordered from, along with the main account. It is used to create orders, sync stock and retrieve bookkeeping information.', 'northmill-online-shared');
    ?>
					</p></th>
			</tr>
		</tbody>
		<?php 
    foreach ($params['stock_accounts'] as $account) {
        Hub_Account_Setup::render_backoffice_account_fields($field_iterators, $account);
    }
    ?>
		<tbody class="add-account-row prod-row">
			<tr>
				<th colspan="2"><a href="#" class="add-hub-account" data-env="prod"><?php 
    \esc_html_e('Connect stock Hub account', 'northmill-online-shared');
    ?></a></th>
			</tr>
		</tbody>
		<?php 
}
?>
</table>
<script>
	let northmill_online_shared_api_iterators = {
		prod: <?php 
echo \esc_html($field_iterators['prod']);
?>,
		test: <?php 
echo \esc_html($field_iterators['test']);
?>
	};
</script>
<?php 
