<?php
/**
 * General settings tab.
 *
 * @package Rsmspark_Content_Widgets
 *
 * @var array<string, mixed> $settings Plugin settings.
 */

defined( 'ABSPATH' ) || exit;

?>
<form method="post" action="<?php echo esc_url( Rsmspark_Content_Widgets_Admin::settings_url( 'general' ) ); ?>">
	<?php wp_nonce_field( 'rsmspark_content_widgets_save_settings', 'rsmspark_content_widgets_settings_nonce' ); ?>
	<input type="hidden" name="rsm_settings_tab" value="general" />

	<h2 class="rsm-settings-section-title"><?php esc_html_e( 'Bundle', 'rsm-content-widgets' ); ?></h2>
	<table class="form-table" role="presentation">
		<tr>
			<th scope="row"><?php esc_html_e( 'Enable plugin', 'rsm-content-widgets' ); ?></th>
			<td>
				<label>
					<input type="checkbox" name="rsmspark_content_widgets_enabled" value="1" <?php checked( ! empty( $settings['enabled'] ) ); ?> />
					<?php esc_html_e( 'Load content widgets on the front end', 'rsm-content-widgets' ); ?>
				</label>
				<p class="description"><?php esc_html_e( 'When disabled, widgets are not registered and assets are not loaded.', 'rsm-content-widgets' ); ?></p>
			</td>
		</tr>
	</table>

	<h2 class="rsm-settings-section-title"><?php esc_html_e( 'Output modes', 'rsm-content-widgets' ); ?></h2>
	<table class="form-table" role="presentation">
		<tr>
			<th scope="row"><?php esc_html_e( 'Rendering layers', 'rsm-content-widgets' ); ?></th>
			<td>
				<fieldset>
					<label>
						<input type="checkbox" name="rsmspark_content_widgets_output_shortcodes" value="1" <?php checked( ! empty( $settings['output_shortcodes'] ) ); ?> />
						<?php esc_html_e( 'Shortcodes (primary)', 'rsm-content-widgets' ); ?>
					</label><br />
					<label>
						<input type="checkbox" name="rsmspark_content_widgets_output_blocks" value="1" <?php checked( ! empty( $settings['output_blocks'] ) ); ?> />
						<?php esc_html_e( 'Gutenberg blocks', 'rsm-content-widgets' ); ?>
					</label><br />
					<label>
						<input type="checkbox" name="rsmspark_content_widgets_output_siteorigin" value="1" <?php checked( ! empty( $settings['output_siteorigin'] ) ); ?> />
						<?php esc_html_e( 'SiteOrigin Page Builder widgets (optional)', 'rsm-content-widgets' ); ?>
					</label>
				</fieldset>
				<p class="description"><?php esc_html_e( 'Shortcodes and blocks work without SiteOrigin. Disable SiteOrigin output if you only use Elementor, Bricks, or the block editor. Gutenberg blocks must be enabled to edit RSM block markup in the block editor (Starter Sites and Site Lab imports).', 'rsm-content-widgets' ); ?></p>
			</td>
		</tr>
	</table>

	<h2 class="rsm-settings-section-title"><?php esc_html_e( 'Default styling', 'rsm-content-widgets' ); ?></h2>
	<table class="form-table" role="presentation">
		<tr>
			<th scope="row">
				<label for="rsmspark_content_widgets_primary_color"><?php esc_html_e( 'Primary color', 'rsm-content-widgets' ); ?></label>
			</th>
			<td>
				<input type="color" name="rsmspark_content_widgets_primary_color" id="rsmspark_content_widgets_primary_color" value="<?php echo esc_attr( (string) ( $settings['primary_color'] ?? '#2563eb' ) ); ?>" />
				<p class="description"><?php esc_html_e( 'Used for buttons, accents, and links in widget output.', 'rsm-content-widgets' ); ?></p>
			</td>
		</tr>
		<tr>
			<th scope="row">
				<label for="rsmspark_content_widgets_border_radius"><?php esc_html_e( 'Border radius (px)', 'rsm-content-widgets' ); ?></label>
			</th>
			<td>
				<input type="number" class="small-text" name="rsmspark_content_widgets_border_radius" id="rsmspark_content_widgets_border_radius" value="<?php echo esc_attr( (string) ( $settings['border_radius'] ?? '8' ) ); ?>" min="0" max="48" step="1" />
			</td>
		</tr>
	</table>

	<h2 class="rsm-settings-section-title"><?php esc_html_e( 'Performance', 'rsm-content-widgets' ); ?></h2>
	<table class="form-table" role="presentation">
		<tr>
			<th scope="row"><?php esc_html_e( 'Asset loading', 'rsm-content-widgets' ); ?></th>
			<td>
				<fieldset>
					<?php
					$load = (string) ( $settings['load_assets'] ?? 'conditional' );
					$opts = array(
						'conditional' => __( 'Only when a widget is present on the page', 'rsm-content-widgets' ),
						'always'      => __( 'Always load widget styles and scripts', 'rsm-content-widgets' ),
						'never'       => __( 'Never load (for custom theme integration)', 'rsm-content-widgets' ),
					);
					foreach ( $opts as $value => $label ) :
						?>
						<label>
							<input type="radio" name="rsmspark_content_widgets_load_assets" value="<?php echo esc_attr( $value ); ?>" <?php checked( $load, $value ); ?> />
							<?php echo esc_html( $label ); ?>
						</label><br />
					<?php endforeach; ?>
				</fieldset>
			</td>
		</tr>
	</table>

	<?php submit_button(); ?>
</form>
