<?php
namespace NewsletterBridge\Admin\Tabs;

use NewsletterBridge\Config\DatabaseConfig;

/**
 * Tab Database per l'admin
 */
class DatabaseTab {
    
    public static function render() {
        // Usa DatabaseConfig per leggere i valori (gestisce correttamente multisite)
        $config = DatabaseConfig::getConfig();
        ?>
        <h2>Configurazione Database Storage</h2>
        <table class="form-table">
            <tr>
                <th scope="row">Dominio</th>
                <td>
                    <input type="text" name="db_domain" value="<?php echo esc_attr($config->domain); ?>" class="regular-text" />
                    <p class="description">Dominio per il database</p>
                </td>
            </tr>
            <tr>
                <th scope="row">Optin su registrazione</th>
                <td>
                    <label>
                        <input type="radio" name="db_optin" value="true" <?php checked($config->optin, true); ?> />
                        Sì
                    </label>
                    <label>
                        <input type="radio" name="db_optin" value="false" <?php checked($config->optin, false); ?> />
                        No
                    </label>
                    <p class="description">Optin su registrazione?</p>
                </td>
            </tr>
        </table>
        <?php
    }
    
    public static function save($data) {
        DatabaseConfig::saveConfig($data);
    }
}
