<?php

class Sage_AI_License_Page {

	function __construct() {
		add_action( 'admin_menu', array( $this, 'register_menu' ) );
		add_action( 'admin_init', array( $this, 'setting_fields' ) );
	}

	public function register_menu() {

		add_submenu_page( 'wp-ai-content-gen-settings', 'Licenses', 'Licenses', 'manage_options', 'sage_ai_licenses', array( &$this, 'license_settings' ) );
	}

	public function license_settings() {

		?>
			<!-- Create a header in the default WordPress 'wrap' container -->
	<div class="wrap">

		<!-- Make a call to the WordPress function for rendering errors when settings are saved. -->
		<?php settings_errors(); ?>
		<!-- Create the form that will be used to render our options -->
		<form method="post" action="options.php">
			<?php settings_fields( 'sage_ai_licenses' ); ?>
			<?php do_settings_sections( 'sage_ai_licenses' ); ?>
			<?php submit_button(); ?>
		</form>

	</div><!-- /.wrap -->
		<?php
	}


	function setting_fields() {
		// If settings don't exist, create them.
		if ( false == get_option( 'sage_ai_licenses' ) ) {
			add_option( 'sage_ai_licenses' );
		}

		add_settings_section(
			'sage_ai_licenses_section',
			'Add-On Licenses',
			array( $this, 'section_callback' ),
			'sage_ai_licenses'
		);

		do_action( 'sage_ai_license_fields', $this );

		// register settings
		register_setting( 'sage_ai_licenses', 'sage_ai_licenses' );
	}

	public function section_callback() {

		echo '<h4> Licence Fields will automatically appear once you install addons for \'Sage AI Writer\'. You can check all the available addons <a href="https://wpsageai.com/">here</a></h4>';
	}
}

new Sage_AI_License_Page();
