<?php
namespace RemoveAdminNotices;

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

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

if ( ! function_exists( 'wp_powersuite_is_license_valid' ) || ! wp_powersuite_is_license_valid() ) {
	$license_page_url = admin_url( 'admin.php?page=powersuite-license' );
	?>
	<div class="wp-powersuite-module-settings wpps-settings-panel" data-module-id="<?php echo esc_attr( $module_id ?? 'remove-admin-notices' ); ?>">
		<div class="notice notice-warning inline" style="margin:0;">
			<p>
				<?php esc_html_e( 'Hide Admin Notices requires an active license. Activate your license to move admin notices into the toolbar panel.', 'wp-powersuite' ); ?>
				<a href="<?php echo esc_url( $license_page_url ); ?>"><?php esc_html_e( 'Activate license', 'wp-powersuite' ); ?></a>
			</p>
		</div>
	</div>
	<?php
	return;
}

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

if ( ! isset( $module_id ) ) {
	$module_id = 'remove-admin-notices';
}
$settings = OptionStoreModuleSettingsRepository::forModule( $module_id )->all( [] );
$settings = is_array( $settings ) ? $settings : [];
$settings = Module::normalizeSettings( $settings );

?>
<div class="wp-powersuite-module-settings">
	<p class="description">
		<?php esc_html_e( 'Clean up admin pages by moving notices into a separate panel easily accessible via the admin bar.', 'wp-powersuite' ); ?>
	</p>

	<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 Notices From:', 'wp-powersuite' ); ?></th>
					<td>
						<fieldset>
							<label style="display: block; margin-bottom: 15px;">
								<input type="checkbox"
									name="hide_core"
									class="wp-powersuite-advanced-setting"
									data-setting-key="hide_core"
									value="1"
									<?php checked( ! empty( $settings['hide_core'] ) ); ?>
								/>
								<?php esc_html_e( 'WordPress Core', 'wp-powersuite' ); ?>
							</label>

							<label style="display: block; margin-bottom: 15px;">
								<input type="checkbox"
									name="hide_plugins"
									class="wp-powersuite-advanced-setting"
									data-setting-key="hide_plugins"
									value="1"
									<?php checked( ! empty( $settings['hide_plugins'] ) ); ?>
								/>
								<?php esc_html_e( 'Plugins', 'wp-powersuite' ); ?>
							</label>

							<label style="display: block; margin-bottom: 15px;">
								<input type="checkbox"
									name="hide_themes"
									class="wp-powersuite-advanced-setting"
									data-setting-key="hide_themes"
									value="1"
									<?php checked( ! empty( $settings['hide_themes'] ) ); ?>
								/>
								<?php esc_html_e( 'Themes', 'wp-powersuite' ); ?>
							</label>

							<label style="display: block; margin-bottom: 15px; margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;">
								<input type="checkbox"
									name="hide_errors"
									class="wp-powersuite-advanced-setting"
									data-setting-key="hide_errors"
									value="1"
									<?php checked( ! empty( $settings['hide_errors'] ) ); ?>
								/>
								<?php esc_html_e( 'Also hide error notices', 'wp-powersuite' ); ?>
							</label>
							<p class="description" style="margin: 5px 0 0 24px;">
								<strong><?php esc_html_e( 'Warning: Use with caution.', 'wp-powersuite' ); ?></strong>
								<?php esc_html_e( 'Error notices indicate important issues like database failures, API errors, or critical plugin conflicts. Only enable this if you monitor errors through other means.', 'wp-powersuite' ); ?>
							</p>
						</fieldset>
						<p class="description" style="margin-top: 10px;">
							<?php esc_html_e( 'Select which types of admin notices to hide. Hidden notices will be moved to a collapsible panel accessible via the "Notices" menu in the admin bar.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
