<?php
namespace HideUpdateNotifications;

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

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

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

if ( ! isset( $module_id ) ) {
	$module_id = 'hide-update-notifications';
}
$default_settings = [
	'hide_plugin_updates'    => false,
	'hide_theme_updates'     => false,
	'hide_core_updates'      => false,
	'hide_php_update_notice' => false,
];

$settings = OptionStoreModuleSettingsRepository::forModule( $module_id )->all( [] );
if ( ! is_array( $settings ) ) {
	$settings = [];
}
$settings = array_merge( $default_settings, $settings );

$disable_all_updates_active = OptionStoreModuleSettingsRepository::isModuleEnabled( 'disable-all-updates' );

?>
<div class="wp-powersuite-module-settings">
	<p class="description">
		<?php esc_html_e( 'Hide update notifications for themes, plugins, core, and PHP update requirements. Select which notifications to hide.', 'wp-powersuite' ); ?>
	</p>
	<p class="description">
		<?php esc_html_e( 'This only hides reminders in the admin. Updates remain available under Dashboard → Updates, and WordPress can still check for new versions.', 'wp-powersuite' ); ?>
	</p>

	<?php if ( $disable_all_updates_active ) : ?>
		<div class="notice notice-warning inline" style="margin: 0 0 16px;">
			<p>
				<strong><?php esc_html_e( 'Note:', 'wp-powersuite' ); ?></strong>
				<?php esc_html_e( 'The "Disable All Updates" module is also active. It already blocks update checks and notifications, so this module is mostly redundant.', '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">
			<tbody>
				<tr>
					<th scope="row">
						<?php esc_html_e( 'Hide Plugin Update Notifications', 'wp-powersuite' ); ?>
					</th>
					<td>
						<label>
							<input type="checkbox"
								name="hide_plugin_updates"
								class="wp-powersuite-advanced-setting"
								data-setting-key="hide_plugin_updates"
								value="1"
								<?php checked( ! empty( $settings['hide_plugin_updates'] ) ); ?>
							/>
							<?php esc_html_e( 'Hide plugin update notifications and counts', 'wp-powersuite' ); ?>
						</label>
						<p class="description">
							<?php esc_html_e( 'Removes plugin update notifications, menu badges, and update counts from the admin area.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>

				<tr>
					<th scope="row">
						<?php esc_html_e( 'Hide Theme Update Notifications', 'wp-powersuite' ); ?>
					</th>
					<td>
						<label>
							<input type="checkbox"
								name="hide_theme_updates"
								class="wp-powersuite-advanced-setting"
								data-setting-key="hide_theme_updates"
								value="1"
								<?php checked( ! empty( $settings['hide_theme_updates'] ) ); ?>
							/>
							<?php esc_html_e( 'Hide theme update notifications and counts', 'wp-powersuite' ); ?>
						</label>
						<p class="description">
							<?php esc_html_e( 'Removes theme update notifications, menu badges, and update counts from the admin area.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>

				<tr>
					<th scope="row">
						<?php esc_html_e( 'Hide Core Update Notifications', 'wp-powersuite' ); ?>
					</th>
					<td>
						<label>
							<input type="checkbox"
								name="hide_core_updates"
								class="wp-powersuite-advanced-setting"
								data-setting-key="hide_core_updates"
								value="1"
								<?php checked( ! empty( $settings['hide_core_updates'] ) ); ?>
							/>
							<?php esc_html_e( 'Hide WordPress core update notifications', 'wp-powersuite' ); ?>
						</label>
						<p class="description">
							<?php esc_html_e( 'Removes WordPress core update notifications and maintenance mode warnings from the admin area.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>

				<tr>
					<th scope="row">
						<?php esc_html_e( 'Remove PHP Update Required Notice', 'wp-powersuite' ); ?>
					</th>
					<td>
						<label>
							<input type="checkbox"
								name="hide_php_update_notice"
								class="wp-powersuite-advanced-setting"
								data-setting-key="hide_php_update_notice"
								value="1"
								<?php checked( ! empty( $settings['hide_php_update_notice'] ) ); ?>
							/>
							<?php esc_html_e( 'Hide PHP update required notice', 'wp-powersuite' ); ?>
						</label>
						<p class="description">
							<?php esc_html_e( 'Removes the PHP update dashboard widget, related update-screen notices, and the PHP version Site Health test.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
