<?php
namespace UserProfileClean;

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

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

if ( ! current_user_can( 'manage_options' ) ) {
	return;
}

if ( ! isset( $module_id ) ) {
	$module_id = 'user-profile-clean';
}

if ( ! class_exists( Module::class ) ) {
	$module_file = __DIR__ . '/module.php';
	if ( is_readable( $module_file ) ) {
		require_once $module_file;
	}
}

$defaults = class_exists( Module::class )
	? Module::getDefaultSettings()
	: [
		'remove_color_scheme'        => false,
		'remove_toolbar'             => false,
		'remove_biographical_info'   => false,
		'remove_keyboard_shortcuts'  => false,
		'remove_visual_editor'       => false,
		'remove_syntax_highlighting' => false,
		'remove_website'             => false,
		'remove_language'            => false,
	];

$raw_settings = OptionStoreModuleSettingsRepository::forModule( $module_id )->all( [] );
$raw_settings = is_array( $raw_settings ) ? $raw_settings : [];
$settings     = array_merge( $defaults, array_intersect_key( $raw_settings, $defaults ) );

$hide_admin_bar_enabled = OptionStoreModuleSettingsRepository::isModuleEnabled( 'hide-admin-bar' );

?>
<div class="wp-powersuite-module-settings">
	<p class="description">
		<?php esc_html_e( 'Hide unnecessary WordPress profile fields to reduce clutter. Selected fields are hidden on all user profile screens.', 'wp-powersuite' ); ?>
	</p>

	<?php if ( $hide_admin_bar_enabled ) : ?>
		<div class="notice notice-warning inline" style="margin: 12px 0;">
			<p>
				<?php esc_html_e( 'Hide Admin Bar is enabled and controls the frontend toolbar by role. Hiding the Toolbar checkbox here only removes that profile setting from view—it does not change Hide Admin Bar behavior.', 'wp-powersuite' ); ?>
			</p>
		</div>
	<?php endif; ?>

	<form class="wp-powersuite-module-settings-form" data-module-id="<?php echo esc_attr( $module_id ); ?>">
		<?php wp_nonce_field( 'wp_powersuite_save_module_settings_' . $module_id, 'wp_powersuite_nonce' ); ?>

		<table class="form-table" role="presentation">
			<tbody>
				<tr>
					<th scope="row"><?php esc_html_e( 'Remove Options', 'wp-powersuite' ); ?></th>
					<td>
						<fieldset>
							<legend class="screen-reader-text">
								<span><?php esc_html_e( 'Remove Options', 'wp-powersuite' ); ?></span>
							</legend>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_color_scheme"
									value="1"
									<?php checked( ! empty( $settings['remove_color_scheme'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_color_scheme"
								/>
								<?php esc_html_e( 'Admin Color Scheme', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_toolbar"
									value="1"
									<?php checked( ! empty( $settings['remove_toolbar'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_toolbar"
								/>
								<?php esc_html_e( 'Toolbar', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_language"
									value="1"
									<?php checked( ! empty( $settings['remove_language'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_language"
								/>
								<?php esc_html_e( 'Language', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_biographical_info"
									value="1"
									<?php checked( ! empty( $settings['remove_biographical_info'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_biographical_info"
								/>
								<?php esc_html_e( 'Biographical Info', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_keyboard_shortcuts"
									value="1"
									<?php checked( ! empty( $settings['remove_keyboard_shortcuts'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_keyboard_shortcuts"
								/>
								<?php esc_html_e( 'Keyboard Shortcuts', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_visual_editor"
									value="1"
									<?php checked( ! empty( $settings['remove_visual_editor'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_visual_editor"
								/>
								<?php esc_html_e( 'Visual Editor', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_syntax_highlighting"
									value="1"
									<?php checked( ! empty( $settings['remove_syntax_highlighting'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_syntax_highlighting"
								/>
								<?php esc_html_e( 'Syntax Highlighting', 'wp-powersuite' ); ?>
							</label>
							<label style="display: block; margin-bottom: 10px;">
								<input
									type="checkbox"
									name="remove_website"
									value="1"
									<?php checked( ! empty( $settings['remove_website'] ) ); ?>
									class="wp-powersuite-advanced-setting"
									data-setting-key="remove_website"
								/>
								<?php esc_html_e( 'Website', 'wp-powersuite' ); ?>
							</label>
						</fieldset>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
