<?php

/**
 * Status tab – Bookkeeping.
 *
 * @package northmill-online-shared
 *
 * @phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Checkout;

use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Abstracts\Hub_API\Hub_Accounts\Models\Hub_Account_Model;
use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Helpers\DB_Helpers;
\defined('ABSPATH') || exit;
/**
 * View parameters.
 *
 * @var array $params
 */
/**
 * Hub accounts.
 *
 * @var Hub_Account_Model[] $all_hub_accounts
 */
$all_hub_accounts = $params['all_hub_accounts'];
?>
<h2 id="income-account-codes"><?php 
\esc_html_e('Income Account Codes', 'northmill-online-shared');
?></h2>
<?php 
/**
 * Magic method allowed for WC()->payment_gateways.
 *
 * @noinspection PhpUndefinedFieldInspection
 */
$payment_gateways = \WC()->payment_gateways->payment_gateways();
?>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th><?php 
\esc_html_e('Hub account', 'northmill-online-shared');
?></th>
		<?php 
foreach ($payment_gateways as $payment_gateway) {
    echo '<th>' . \esc_html($payment_gateway->id) . '</th>';
}
?>
	</tr>
	</thead>
	<tbody>
	<?php 
foreach ($all_hub_accounts as $hub_account) {
    $income_account_codes = $hub_account->get_income_account_codes();
    echo '<tr>';
    echo '<td>' . \esc_html($hub_account->user) . '</td>';
    foreach ($payment_gateways as $payment_gateway) {
        echo '<td>' . (isset($income_account_codes[$payment_gateway->id]) ? \esc_html($income_account_codes[$payment_gateway->id]->get_account_code()) : '') . '</td>';
    }
    echo '</tr>';
}
?>
	</tbody>
</table>
<h2 id="vat-account-codes"><?php 
\esc_html_e('VAT Account Codes', 'northmill-online-shared');
?></h2>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th><?php 
\esc_html_e('Hub account', 'northmill-online-shared');
?></th>
		<th>0%</th>
		<th>6%</th>
		<th>12%</th>
		<th>25%</th>
	</tr>
	</thead>
	<tbody>
	<?php 
foreach ($all_hub_accounts as $hub_account) {
    $vat_account_codes = $hub_account->get_vat_account_codes();
    echo '<tr>';
    echo '<td>' . \esc_html($hub_account->user) . '</td>';
    echo '<td>' . \esc_html($hub_account->get_vat_account_code(0)) . '</td>';
    echo '<td>' . \esc_html($hub_account->get_vat_account_code(6)) . '</td>';
    echo '<td>' . \esc_html($hub_account->get_vat_account_code(12)) . '</td>';
    echo '<td>' . \esc_html($hub_account->get_vat_account_code(25)) . '</td>';
    echo '</tr>';
}
?>
	</tbody>
</table>
<h2 id="article-account-codes"><?php 
\esc_html_e('Article Account Codes', 'northmill-online-shared');
?></h2>
<h4 id="table-wc_tax_rate_classes">Table wc_tax_rate_classes</h4>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th>tax_rate_class_id</th>
		<th>name</th>
		<th>slug</th>
	</tr>
	</thead>
	<tbody>
	<?php 
$tax_rate_classes = DB_Helpers::get_all_rows_from_table('wc_tax_rate_classes');
foreach ($tax_rate_classes as $tax_rate_class) {
    echo '<tr>';
    echo '<td>' . \esc_html($tax_rate_class['tax_rate_class_id']) . '</td>';
    echo '<td>' . \esc_html($tax_rate_class['name']) . '</td>';
    echo '<td>' . \esc_html($tax_rate_class['slug']) . '</td>';
    echo '</tr>';
}
?>
	</tbody>
</table>
<h4 id="table-woocommerce_tax_rates">Table woocommerce_tax_rates</h4>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th>tax_rate_id</th>
		<th>tax_rate_country</th>
		<th>tax_rate_state</th>
		<th>tax_rate</th>
		<th>tax_rate_name</th>
		<th>tax_rate_priority</th>
		<th>tax_rate_compound</th>
		<th>tax_rate_shipping</th>
		<th>tax_rate_order</th>
		<th>tax_rate_class</th>
	</tr>
	</thead>
	<tbody>
	<?php 
$tax_rates = DB_Helpers::get_all_rows_from_table('woocommerce_tax_rates');
foreach ($tax_rates as $tax_rate) {
    echo '<tr>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_id']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_country']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_state']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_name']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_priority']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_compound']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_shipping']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_order']) . '</td>';
    echo '<td>' . \esc_html($tax_rate['tax_rate_class']) . '</td>';
    echo '</tr>';
}
?>
	</tbody>
</table>
<button id="nm-empty-woocommerce-tax-rates"><?php 
\esc_html_e('Empty table', 'northmill-online-shared');
?></button>
<br>
<button id="nm-remove-woocommerce-tax-rates-mf-rows">
	<?php 
echo \esc_html(\sprintf(
    // translators: %s is the prefix.
    \__('Delete rows where tax_rate_class starts with "%s"', 'northmill-online-shared'),
    $params['tax_rates_prefix']
));
?>
</button>
<?php 
