<?php
/**
 * Advanced Tab
 *
 * @var array $settings
 * @var array|null $tenant_defaults
 */

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

$tenantGracePeriod = $tenant_defaults['grace_period'] ?? 'N/A';
?>

<h3><?php esc_html_e('Cancellation Settings', 'woocommerce-cloudxm-nfe'); ?></h3>
<p class="description"><?php esc_html_e('Configure limits and rules for NFe cancellation.', 'woocommerce-cloudxm-nfe'); ?></p>
<table class="form-table">
    <tr>
        <th scope="row"><label for="cloudxm_nfe_cancel_days_limit"><?php esc_html_e('Cancellation Days Limit', 'woocommerce-cloudxm-nfe'); ?></label></th>
        <td>
            <input type="number" id="cloudxm_nfe_cancel_days_limit" name="cloudxm_nfe_cancel_days_limit" value="<?php echo esc_attr($settings['cancel_days_limit'] ?? '5'); ?>" class="small-text" min="0" max="365">
            <p class="description">
                <?php esc_html_e('Maximum days after issuance where cancellation is allowed.', 'woocommerce-cloudxm-nfe'); ?>
                <br>
                <strong><?php esc_html_e('Server Default:', 'woocommerce-cloudxm-nfe'); ?></strong> <?php echo esc_html((string) $tenantGracePeriod); ?>
            </p>
        </td>
    </tr>
</table>

<h3><?php esc_html_e('Internal Settings', 'woocommerce-cloudxm-nfe'); ?></h3>
<p class="description"><?php esc_html_e('Advanced configuration options for specific use cases.', 'woocommerce-cloudxm-nfe'); ?></p>
<table class="form-table">
    <tr>
        <th scope="row"><label for="cloudxm_nfe_internal_contributor_code"><?php esc_html_e('Internal Contributor Code', 'woocommerce-cloudxm-nfe'); ?></label></th>
        <td>
            <input type="text" id="cloudxm_nfe_internal_contributor_code" name="cloudxm_nfe_internal_contributor_code" value="<?php echo esc_attr($settings['internal_contributor_code'] ?? ''); ?>" class="regular-text" maxlength="50">
            <p class="description"><?php esc_html_e('Internal identifier used in payload mapping (optional).', 'woocommerce-cloudxm-nfe'); ?></p>
        </td>
    </tr>
</table>

<h3><?php esc_html_e('Debug Mode', 'woocommerce-cloudxm-nfe'); ?></h3>
<p class="description"><?php esc_html_e('Enable detailed logging for troubleshooting. Recommended only in staging/sandbox environments.', 'woocommerce-cloudxm-nfe'); ?></p>
<table class="form-table">
    <tr>
        <th scope="row"><label for="cloudxm_nfe_debug_mode"><?php esc_html_e('Debug Mode', 'woocommerce-cloudxm-nfe'); ?></label></th>
        <td>
            <label>
                <input type="checkbox" id="cloudxm_nfe_debug_mode" name="cloudxm_nfe_debug_mode" value="1" <?php checked($settings['debug_mode'] ?? '0', '1'); ?>>
                <?php esc_html_e('Enable debug mode (recommended only in sandbox).', 'woocommerce-cloudxm-nfe'); ?>
            </label>
        </td>
    </tr>
</table>
