<?php

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

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

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

if ( ! isset( $module_id ) ) {
	$module_id = 'content-report-widget';
}
$default_settings = [
	'show_empty_cpts' => false,
];

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

?>
<div class="wp-powersuite-module-settings">
	<p class="description">
		<?php esc_html_e( 'This module displays content statistics in a dashboard widget. Stats are cached for 5 minutes and refresh when content changes. Click any stat to go to that section.', '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( 'Custom Post Types', 'wp-powersuite' ); ?></th>
					<td>
						<label>
							<input type="checkbox"
								name="show_empty_cpts"
								class="wp-powersuite-advanced-setting"
								data-setting-key="show_empty_cpts"
								value="1"
								<?php checked( ! empty( $settings['show_empty_cpts'] ) ); ?>
							/>
							<?php esc_html_e( 'Show custom post types with zero items', 'wp-powersuite' ); ?>
						</label>
						<p class="description">
							<?php esc_html_e( 'By default, only CPTs with content are shown. Enable to display all registered custom post types including empty ones.', 'wp-powersuite' ); ?>
						</p>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
