<?php defined('ABSPATH') || exit;

$iv1wpt_has_pro = iv1wpt_has_pro();

$wp_opts = get_option(IV1WPT_WPSETTINGS_OPTION, iv1wpt_default_wp_settings());
$fields  = iv1wpt_wp_settings_fields();
?>

<h2><span class="dashicons dashicons-wordpress-alt"></span>&nbsp;<?php esc_html_e('WordPress Hardening & Optimization', 'iv1-wp-tools'); ?></h2>
<p class="description"><?php esc_html_e('Enable or disable features to make WordPress more secure and faster.', 'iv1-wp-tools'); ?></p>

<div id="iv1wpt-settings-result" style="margin:15px 0;"></div>

<form method="post" action="<?php echo esc_url(admin_url('admin.php?page=iv1-wp-tools&tab=wpsettings')); ?>">
    <?php wp_nonce_field('iv1wpt_wpsettings_nonce'); ?>

    <table class="iv1wpt-settings-table">
        <?php foreach ($fields as $group => $items): ?>
            <tr class="iv1wpt-settings-group">
                <td colspan="2" style="background:#f6f7f7;font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.3px;color:#646970;padding:8px 12px!important;">
                    <?php echo esc_html($group); ?>
                </td>
            </tr>

            <?php foreach ($items as $key => $info): ?>
                <?php
                $is_pro_field = iv1wpt_wp_setting_is_pro($key);
                $is_locked    = $is_pro_field && !$iv1wpt_has_pro;
                ?>

                <tr class="<?php echo $is_locked ? 'iv1wpt-pro-locked-row' : ''; ?>">
                    <td style="width:50px;text-align:center;">
                        <label class="iv1wpt-toggle">
                            <input
                                type="checkbox"
                                name="<?php echo esc_attr($key); ?>"
                                value="1"
                                <?php checked(!empty($wp_opts[$key])); ?>
                                <?php disabled($is_locked); ?>
                            >
                            <span class="iv1wpt-toggle-slider"></span>
                        </label>
                    </td>

                    <td>
                        <div class="iv1wpt-settings-label">
                            <?php echo $is_locked ? '🔒 ' : ''; ?>
                            <?php echo esc_html($info[0]); ?>
                        </div>
                        <div class="iv1wpt-settings-desc"><?php echo esc_html($info[1]); ?></div>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endforeach; ?>
    </table>

    <p class="submit" style="margin-top:16px;">
        <input type="submit" name="iv1wpt_save_wpsettings" class="button button-primary" value="<?php esc_attr_e('Save settings', 'iv1-wp-tools'); ?>">
    </p>
</form>