<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

if ( ! isset( $module_id ) || empty( $module_id ) ) {
	$module_id = 'wider-admin-menu';
}

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

$menu_width = isset( $settings['menu_width'] ) ? absint( $settings['menu_width'] ) : 200;
if ( $menu_width < 160 ) {
	$menu_width = 160;
} elseif ( $menu_width > 300 ) {
	$menu_width = 300;
}
?>

<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="menu_width"><?php esc_html_e( 'Menu Width:', 'wp-powersuite' ); ?></label>
					</th>
					<td>
						<input
							type="number"
							id="menu_width"
							name="menu_width"
							value="<?php echo esc_attr( $menu_width ); ?>"
							min="160"
							max="300"
							step="1"
							class="small-text wp-powersuite-advanced-setting"
							data-setting-key="menu_width"
						/>
						<span class="description"><?php esc_html_e( 'px', 'wp-powersuite' ); ?></span>
						<p class="description">
							<?php esc_html_e( 'Set the width of the admin menu sidebar in pixels. Default is 200px. Minimum: 160px, Maximum: 300px.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
