<?php
namespace KBT_SEO;

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

class Settings {

	public static function init() {
		add_action( 'admin_menu', array( __CLASS__, 'menu' ) );
		add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
	}

	public static function menu() {
		add_options_page(
			'KBT SEO Tools',
			'KBT SEO Tools',
			'manage_options',
			'kbt-seo-tools',
			array( __CLASS__, 'page' )
		);
	}

	public static function register_settings() {
		register_setting( 'kbt_seo_settings', 'kbt_seo_baca_juga_enabled' );
		register_setting( 'kbt_seo_settings', 'kbt_seo_baca_juga_first' );
		register_setting( 'kbt_seo_settings', 'kbt_seo_baca_juga_repeat' );
		register_setting( 'kbt_seo_settings', 'kbt_seo_baca_juga_max' );
	}

	public static function page() {
		?>
		<div class="wrap">
			<h1>KBT SEO Tools — Pengaturan</h1>
			<form method="post" action="options.php">
				<?php settings_fields( 'kbt_seo_settings' ); ?>
				<table class="form-table">
					<tr>
						<th scope="row">Auto "Baca Juga"</th>
						<td>
							<label>
								<input type="checkbox" name="kbt_seo_baca_juga_enabled" value="1"
									<?php checked( get_option( 'kbt_seo_baca_juga_enabled', '1' ), '1' ); ?> />
								Aktifkan auto "Baca Juga" di artikel
							</label>
						</td>
					</tr>
					<tr>
						<th scope="row">Sisipkan setelah paragraf ke-</th>
						<td>
							<input type="number" name="kbt_seo_baca_juga_first" min="1" max="10"
								   value="<?php echo esc_attr( get_option( 'kbt_seo_baca_juga_first', 2 ) ); ?>" />
							<p class="description">Box "Baca Juga" pertama akan muncul setelah paragraf ke berapa.</p>
						</td>
					</tr>
					<tr>
						<th scope="row">Ulangi setiap</th>
						<td>
							<input type="number" name="kbt_seo_baca_juga_repeat" min="2" max="20"
								   value="<?php echo esc_attr( get_option( 'kbt_seo_baca_juga_repeat', 4 ) ); ?>" />
							<span>paragraf</span>
							<p class="description">Setelah insert pertama, ulangi setiap N paragraf. Isi 0 untuk hanya 1 kali.</p>
						</td>
					</tr>
					<tr>
						<th scope="row">Maksimal "Baca Juga" per artikel</th>
						<td>
							<input type="number" name="kbt_seo_baca_juga_max" min="1" max="10"
								   value="<?php echo esc_attr( get_option( 'kbt_seo_baca_juga_max', 3 ) ); ?>" />
						</td>
					</tr>
				</table>
				<?php submit_button( 'Simpan Pengaturan' ); ?>
			</form>
		</div>
		<?php
	}
}
