<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
add_action( 'admin_menu', 'pmthemes_admin_page' );
add_action( 'admin_init', 'pmthemes_register_settings' );

define('NICHE_GOLD', 'pmthemes');
function pmthemes_admin_page(  ) { 
    $icon_url = get_template_directory_uri() . '/images/pm.png';
	$position = 59.7307;
	add_menu_page( 'PMThemes', 'PMThemes', 'edit_theme_options', 'pmthemes', 'pmthemes_options_page', $icon_url, $position );
	$pmthemes_settings_page = add_submenu_page('pmthemes', 'PMThemes', 'Theme Settings', 'edit_theme_options', 'pmthemes', 'pmthemes_options_page');
	
	wp_enqueue_style( 'pmthemes-options', get_template_directory_uri() . '/css/admin.css');
	wp_enqueue_style( 'pmthemes-style-grid', get_template_directory_uri() . '/css/grid.css', false, PMTHEMES_VERSION, 'all' );
}
function pmthemes_register_settings(  ) {
    $theme_name = PMTHEMES_NAME;
    register_setting( 'barn_gold', 'pmthemes_theme_options' );
	add_settings_section(
		'pmthemes_general_section',
		''.$theme_name.' Theme Settings',
		'pmthemes_settings_section_callback',
		'barn_gold'
	);
	add_settings_field( 
		'pmthemes_theme_info',
		'Theme Info',
		'pmthemes_theme_info_render',
		'barn_gold',
		'pmthemes_general_section'
	);
	add_settings_field( 
		'pmthemes_header_settings',
		'Header Settings',
		'pmthemes_header_settings_render',
		'barn_gold',
		'pmthemes_general_section'
	);
	add_settings_field(
		'pmthemes_footer_settings',
		'Footer Settings',
		'pmthemes_footer_settings_render',
		'barn_gold',
		'pmthemes_general_section'
	);

}
function pmthemes_theme_info_render(  ) { 
	$options = get_option( 'pmthemes_theme_options');
	?>
		<div class="postbox pmthemes-metabox" id="pmthemes_theme_info">
			<h3 class="hndle">Theme Info</h3>
			<div class="inside">
				<p>Version: <strong><?php echo PMTHEMES_VERSION; ?></strong></p>
                <p><?php echo PMTHEMES_NAME; ?> is a modern WordPress theme that supports <a href="<?php echo admin_url('customize.php'); ?>">WordPress Theme Customizer</a>.</p>
			</div>
		</div>
	<?php }
function pmthemes_header_settings_render (  ) { 
	$options = get_option( 'pmthemes_theme_options' );
	?>
	<div class="postbox pmthemes-metabox" id="pmthemes_header_settings">
			<h3 class="hndle">Customizing <?php echo PMTHEMES_NAME; ?> Theme Settings</h3>
			<div class="inside">
				Please use the <a href="<?php echo admin_url('customize.php'); ?>"><strong>Customizer Window</strong></a> to edit/change <strong>colors</strong>, fonts, logo, background images, and other elements.<br /><br />
				The WordPress Theme Customizer allows you to preview changes to your site before publishing them. You can also navigate to different pages on your site to preview them.
			</div>
	</div>
	<?php }
function pmthemes_footer_settings_render (){
}
function pmthemes_settings_section_callback() {
}

function pmthemes_options_page(  ) { 
	?>
<div id="pmthemes">
<div class="wrap">
	<div class="metabox-holder">
		<div class="postbox-container">
			<div class="grid-container grid-parent">
				<div class="form-metabox grid-70">
                    <form action='options.php' method='post'>
                    <?php settings_fields( 'barn_gold' );
                    do_settings_sections( 'barn_gold' ); ?>
				</div>
			</form>
			</div>
		</div>
	</div>
</div>
</div>
<?php }