<?php

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

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

if ( ! \WP_PowerSuite\Core\NetworkScope::canManagePlugin() ) {
	return;
}

$module_id = $module_id ?? 'custom-body-class';

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

$classes = isset( $settings['classes'] ) ? (string) $settings['classes'] : '';
?>

<div class="wp-powersuite-module-settings" data-module-id="<?php echo esc_attr( $module_id ); ?>">
	<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">
						<label for="<?php echo esc_attr( $module_id ); ?>_classes"><?php esc_html_e( 'Body classes', 'wp-powersuite' ); ?></label>
					</th>
					<td>
						<input
							type="text"
							class="large-text wp-powersuite-advanced-setting"
							id="<?php echo esc_attr( $module_id ); ?>_classes"
							name="classes"
							data-setting-key="classes"
							value="<?php echo esc_attr( $classes ); ?>"
							autocomplete="off"
						/>
						<p class="description">
							<?php esc_html_e( 'Comma or space separated (e.g. dark-mode, promo-bar, landing-variant-a). Each token is sanitized as a CSS class.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
